SaorderTool.java 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. package openapi.restcontroller.wechatapp.saorder.tools;
  2. import net.sf.json.JSONArray;
  3. import net.sf.json.JSONException;
  4. import net.sf.json.JSONObject;
  5. import openapi.base.BaseClass;
  6. import openapi.base.data.db.DBConnect;
  7. import p2.pao.PaoRemote;
  8. import p2.pao.PaoSetRemote;
  9. import p2.util.P2Exception;
  10. import saorder.saorder;
  11. import titem.titem;
  12. import java.util.ArrayList;
  13. import java.util.HashMap;
  14. import java.util.Iterator;
  15. public class SaorderTool extends BaseClass {
  16. public String copy(JSONObject content, String hrid) throws Exception {
  17. PaoSetRemote saorderSet = null;
  18. String fsonum = "";
  19. try {
  20. String foldsonum = content.getString("fsonum");
  21. String ftype = content.getString("ftype");
  22. saorderSet = getP2ServerPaoSet("saorder", hrid);
  23. saorderSet.setWhere("fsonum='" + foldsonum + "'");
  24. saorderSet.reset();
  25. saorder saorder = (saorder) saorderSet.getPao(0);
  26. if ("标准订单".equals(ftype)) {
  27. saorderSet.setApp("SAORDER1");
  28. } else if ("定制订单".equals(ftype)) {
  29. saorderSet.setApp("SAORDER5");
  30. } else if ("工具订单".equals(ftype)) {
  31. saorderSet.setApp("SAORDER6");
  32. } else if ("工具借出单".equals(ftype)) {
  33. saorderSet.setApp("SAORDER7");
  34. } else if ("项目订单".equals(ftype)) {
  35. saorderSet.setApp("SAORDER9");
  36. }
  37. /**
  38. * 订单表头新增
  39. */
  40. PaoRemote newsaorder = saorder.duplicate();
  41. fsonum = newsaorder.getString("fsonum");
  42. saorderSet.save();
  43. } finally {
  44. if (saorderSet != null) {
  45. saorderSet.close();
  46. }
  47. }
  48. return fsonum;
  49. }
  50. /**
  51. * 标准订单新增
  52. */
  53. public String createsaorder(JSONObject content, String hrid) throws Exception {
  54. PaoSetRemote saorderSet = null;
  55. String fsonum = "";
  56. try {
  57. String fagentnum = content.getString("fagentnum");
  58. String ftype = content.getString("ftype");
  59. String fiswuliao = content.getString("fiswuliao");
  60. String fieldname = content.getString("fieldname");//领域
  61. String fbrand = content.getString("fbrand");//品牌
  62. String fprojectnum = "";
  63. if (content.containsKey("fprojectnum")) {
  64. fprojectnum = nullToStr(content.getString("fprojectnum"));//项目编号
  65. }
  66. String fpayagentnum = "";
  67. if (content.containsKey("fpayagentnum")) {
  68. fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户
  69. }
  70. if ("".equals(fpayagentnum)) {
  71. fpayagentnum = fagentnum;
  72. }
  73. String frecagentnum = "";
  74. if (content.containsKey("frecagentnum")) {
  75. frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户
  76. }
  77. if ("".equals(frecagentnum)) {
  78. frecagentnum = fagentnum;
  79. }
  80. JSONArray itemnos = content.getJSONArray("itemnos");
  81. saorderSet = getP2ServerPaoSet("saorder", hrid);
  82. if ("标准订单".equals(ftype)) {
  83. saorderSet.setApp("SAORDER1");
  84. } else if ("定制订单".equals(ftype)) {
  85. saorderSet.setApp("SAORDER5");
  86. } else if ("工具订单".equals(ftype)) {
  87. saorderSet.setApp("SAORDER6");
  88. } else if ("工具借出单".equals(ftype)) {
  89. saorderSet.setApp("SAORDER7");
  90. } else if ("项目订单".equals(ftype)) {
  91. saorderSet.setApp("SAORDER9");
  92. }
  93. /**
  94. * 订单表头新增
  95. */
  96. saorder saorder = (saorder) saorderSet.addAtEnd();
  97. fsonum = saorder.createSoNum();
  98. saorder.setValue("ftype", ftype, 11L);
  99. saorder.setValue("fsonum", fsonum, 11L);
  100. saorder.setValue("createby", hrid, 11L);
  101. saorder.setValue("fagentnum", fagentnum, 2L);
  102. saorder.setValue("fieldname", fieldname, 2L);
  103. saorder.setValue("fbrand", fbrand, 2L);
  104. saorder.setValue("fiswuliao", fiswuliao.equals("1"), 2L);
  105. saorder.setValue("fisusefl", !fiswuliao.equals("1"), 2L);
  106. saorder.setValue("fpayagentnum", fpayagentnum, 2L);
  107. saorder.setValue("frecagentnum", frecagentnum, 2L);
  108. saorder.setValue("fprojectnum", fprojectnum, 2L);
  109. if (content.containsKey("faccclsnum") && !"".equals(content.getString("faccclsnum")) && !"工具借出单".equals(ftype)) {
  110. saorder.setValue("faccclsnum", content.getString("faccclsnum"), 11L);
  111. }
  112. PaoSetRemote saorderdetailset = saorder.getPaoSet("saorderdetail_view");
  113. ArrayList<String> sqllist = new ArrayList<>();
  114. Iterator<JSONObject> it = itemnos.iterator();
  115. while (it.hasNext()) {
  116. JSONObject object = it.next();
  117. long tshoppingcartid = object.getLong("tshoppingcartid");
  118. /**
  119. * 订单行新增
  120. */
  121. PaoRemote newdetail = saorderdetailset.addAtEnd();
  122. newdetail.setValue("fitemno", object.getString("fitemno"), 2L);
  123. newdetail.setValue("fqty", object.getDouble("fqty"), 2L);
  124. /**
  125. * 入股是定制订单,则添加定制信息
  126. */
  127. if ("定制订单".equals(ftype) && newdetail.getPaoSet("saorder_customized").isEmpty()) {
  128. PaoSetRemote saorder_customizedset = newdetail.getPaoSet("saorder_customized");
  129. PaoSetRemote tshoppingcart_customized = newdetail.getPaoSet("$tshoppingcart_customized", "tshoppingcart_customized", "fparentid=" + tshoppingcartid);
  130. int i = 0;
  131. PaoRemote pao = null;
  132. while ((pao = tshoppingcart_customized.getPao(i)) != null) {
  133. PaoRemote saorder_customized = saorder_customizedset.addAtEnd();
  134. saorder_customized.setValue("titem_customizedid", pao.getLong("titem_customizedid"), 11L);
  135. saorder_customized.setValue("fitemno", pao.getString("fitemno"), 11L);
  136. saorder_customized.setValue("fname", pao.getString("fname"), 11L);
  137. saorder_customized.setValue("fnotes", pao.getString("fnotes"), 11L);
  138. saorder_customized.setValue("ftype", pao.getString("ftype"), 11L);
  139. saorder_customized.setValue("fvalue", pao.getString("fvalue"), 11L);
  140. i++;
  141. }
  142. }
  143. sqllist.add("delete from tshoppingcart where tshoppingcartid=" + tshoppingcartid);
  144. }
  145. saorderSet.save();
  146. new DBConnect().runSqlUpdate(sqllist);
  147. } finally {
  148. if (saorderSet != null) {
  149. saorderSet.close();
  150. }
  151. }
  152. return fsonum;
  153. }
  154. /**
  155. * 普通促销订单新增
  156. *
  157. * @param content
  158. * @return
  159. * @throws JSONException
  160. * @throws P2Exception
  161. */
  162. public String createsaorder_prom(JSONObject content, String hrid) throws Exception {
  163. PaoSetRemote saorderSet = null;
  164. String fsonum = "";
  165. try {
  166. String fagentnum = content.getString("fagentnum");
  167. String fpromnum = content.getString("fpromnum");
  168. String ftype = content.getString("ftype");
  169. String fpayagentnum = "";
  170. if (content.containsKey("fpayagentnum")) {
  171. fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户
  172. }
  173. if ("".equals(fpayagentnum)) {
  174. fpayagentnum = fagentnum;
  175. }
  176. String frecagentnum = "";
  177. if (content.containsKey("frecagentnum")) {
  178. frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户
  179. }
  180. if ("".equals(frecagentnum)) {
  181. frecagentnum = fagentnum;
  182. }
  183. JSONArray itemnos = content.getJSONArray("itemnos");
  184. saorderSet = getP2ServerPaoSet("saorder", hrid);
  185. saorderSet.setApp("SAORDER4");
  186. /**
  187. * 订单表头新增
  188. */
  189. saorder saorder = (saorder) saorderSet.addAtEnd();
  190. fsonum = saorder.createSoNum();
  191. saorder.setValue("ftype", ftype, 11L);
  192. saorder.setValue("fsonum", fsonum, 11L);
  193. saorder.setValue("createby", hrid, 11L);
  194. saorder.setValue("fagentnum", fagentnum, 2L);
  195. saorder.setValue("fpayagentnum", fpayagentnum, 2L);
  196. saorder.setValue("frecagentnum", frecagentnum, 2L);
  197. saorder.setValue("fpromnum", fpromnum, 2L);
  198. PaoSetRemote tpromproductsSet = saorder.getPaoSet("tpromproducts");
  199. HashMap<String, PaoRemote> paomap = getPaoMap(tpromproductsSet, "fitemno");
  200. Iterator<JSONObject> it = itemnos.iterator();
  201. while (it.hasNext()) {
  202. JSONObject object = it.next();
  203. String fitemno = object.getString("fitemno");
  204. double fqty = object.getDouble("fqty");
  205. if (paomap.containsKey(fitemno)) {
  206. PaoRemote pao = paomap.get(fitemno);
  207. pao.setValue("faddqty", fqty, 11L);
  208. pao.select();
  209. }
  210. // int i = 0;
  211. // while (tpromproductsSet.getPao(i) != null) {
  212. // if (fitemno.equals(tpromproductsSet.getPao(i).getString("fitemno"))) {
  213. // tpromproductsSet.getPao(i).setValue("faddqty", fqty, 11L);
  214. // tpromproductsSet.getPao(i).select();
  215. // break;
  216. // }
  217. // i++;
  218. // }
  219. }
  220. saorder.additems_prom(tpromproductsSet);
  221. saorderSet.save();
  222. } finally {
  223. if (saorderSet != null) {
  224. saorderSet.close();
  225. }
  226. }
  227. return fsonum;
  228. }
  229. /**
  230. * 打包促销订单新增
  231. *
  232. * @param content
  233. * @return
  234. * @throws JSONException
  235. * @throws P2Exception
  236. */
  237. public String createsaorder_packprom(JSONObject content, String hrid) throws Exception {
  238. PaoSetRemote saorderSet = null;
  239. String fsonum = "";
  240. try {
  241. String fagentnum = content.getString("fagentnum");
  242. String fpromnum = content.getString("fpromnum");
  243. int fpromqty = content.getInt("fpromqty");
  244. String ftype = content.getString("ftype");
  245. String fpayagentnum = "";
  246. if (content.containsKey("fpayagentnum")) {
  247. fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户
  248. }
  249. if ("".equals(fpayagentnum)) {
  250. fpayagentnum = fagentnum;
  251. }
  252. String frecagentnum = "";
  253. if (content.containsKey("frecagentnum")) {
  254. frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户
  255. }
  256. if ("".equals(frecagentnum)) {
  257. frecagentnum = fagentnum;
  258. }
  259. saorderSet = getP2ServerPaoSet("saorder", hrid);
  260. saorderSet.setApp("SAORDER4");
  261. /**
  262. * 订单表头新增
  263. */
  264. saorder saorder = (saorder) saorderSet.addAtEnd();
  265. fsonum = saorder.createSoNum();
  266. saorder.setValue("ftype", ftype, 11L);
  267. saorder.setValue("fsonum", fsonum, 11L);
  268. saorder.setValue("createby", hrid, 11L);
  269. saorder.setValue("fagentnum", fagentnum, 2L);
  270. saorder.setValue("fpayagentnum", fpayagentnum, 2L);
  271. saorder.setValue("frecagentnum", frecagentnum, 2L);
  272. saorder.setValue("fpromnum", fpromnum, 2L);
  273. saorder.setValue("fpromqty", fpromqty, 2L);
  274. saorderSet.save();
  275. } finally {
  276. if (saorderSet != null) {
  277. saorderSet.close();
  278. }
  279. }
  280. return fsonum;
  281. }
  282. /**
  283. * 更新标准订单
  284. *
  285. * @param content
  286. * @return
  287. * @throws JSONException
  288. * @throws P2Exception
  289. */
  290. public String updatesaorder(JSONObject content, String hrid) throws Exception {
  291. PaoSetRemote saorderSet = null;
  292. try {
  293. // 订单ID
  294. String saorderid = content.getString("saorderid");
  295. // 订单号
  296. String fsonum = content.getString("fsonum");
  297. // 经销商编号
  298. String fagentnum = content.getString("fagentnum");
  299. // 单据日期
  300. String fdate = nullToStr(content.getString("fdate"));
  301. if (fdate.length() > 10) {
  302. fdate = fdate.substring(0, 10);
  303. }
  304. // 扣款帐户
  305. String faccclsnum = nullToStr(content.getString("faccclsnum"));
  306. // 联系方式
  307. String fphonenumber = nullToStr(content.getString("fphonenumber"));
  308. // 收货人
  309. String fcontact = nullToStr(content.getString("fcontact"));
  310. // 省
  311. String fprovince = nullToStr(content.getString("fprovince"));
  312. // 市
  313. String fcity = nullToStr(content.getString("fcity"));
  314. // 县
  315. String fcounty = nullToStr(content.getString("fcounty"));
  316. // 收货地址
  317. String faddress = nullToStr(content.getString("faddress"));
  318. // 开票单位
  319. String finvoicename = nullToStr(content.getString("finvoicename"));
  320. // 税号
  321. String finvoicetaxnumber = nullToStr(content.getString("finvoicetaxnumber"));
  322. // 开票地址
  323. String finvoiceaddress = nullToStr(content.getString("finvoiceaddress"));
  324. // 备注
  325. String fnotes = nullToStr(content.getString("fnotes"));
  326. // 是否使用返利
  327. String fisusefl = nullToStr(content.getString("fisusefl"));
  328. //经销商使用返利金设定
  329. double fuseflamount = content.getDouble("fuseflamount");
  330. String fbrand = content.getString("fbrand");//品牌
  331. String fsignbacknum = content.getString("fsignbacknum");//回签单
  332. String fsaletype = "";
  333. if (content.containsKey("fsaletype") && !content.getString("fsaletype").equalsIgnoreCase("null")) {
  334. fsaletype = content.getString("fsaletype");
  335. }
  336. String fprojectnotes = "";
  337. if (content.containsKey("fprojectnotes") && !content.getString("fprojectnotes").equalsIgnoreCase("null")) {
  338. fprojectnotes = content.getString("fprojectnotes");
  339. }
  340. String fprojectnum = "";
  341. if (content.containsKey("fprojectnum") && !content.getString("fprojectnum").equalsIgnoreCase("null")) {
  342. fprojectnum = nullToStr(content.getString("fprojectnum"));//项目编号
  343. }
  344. String fpayagentnum = "";
  345. if (content.containsKey("fpayagentnum") && !content.getString("fpayagentnum").equalsIgnoreCase("null")) {
  346. fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户
  347. }
  348. if ("".equals(fpayagentnum)) {
  349. fpayagentnum = fagentnum;
  350. }
  351. String frecagentnum = "";
  352. if (content.containsKey("frecagentnum") && !content.getString("frecagentnum").equalsIgnoreCase("null")) {
  353. frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户
  354. }
  355. if ("".equals(frecagentnum)) {
  356. frecagentnum = fagentnum;
  357. }
  358. String fieldname = content.getString("fieldname");//领域
  359. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "' ");
  360. if (saorderSet.isEmpty()) {
  361. return "订单" + fsonum + "不存在!";
  362. }
  363. saorder saorder = (saorder) saorderSet.getPao(0);
  364. if (!"新建".equals(saorder.getString("fstatus"))) {
  365. return "非新建状态不可修改";
  366. }
  367. String ftype = saorder.getString("ftype");
  368. saorderSet.setApp("SAORDER1");
  369. /**
  370. * 修改表头字段信息
  371. */
  372. saorder.setValue("fieldname", fieldname, 2L);
  373. saorder.setValue("fdate", fdate, 11L);
  374. saorder.setValue("faccclsnum", faccclsnum, 2L);
  375. saorder.setValue("fphonenumber", fphonenumber, 11L);
  376. saorder.setValue("fcontact", fcontact, 11L);
  377. saorder.setValue("fprovince", fprovince, 11L);
  378. saorder.setValue("fcity", fcity, 11L);
  379. saorder.setValue("fcounty", fcounty, 11L);
  380. saorder.setValue("faddress", faddress, 11L);
  381. saorder.setValue("fnotes", fnotes, 11L);
  382. saorder.setValue("finvoicename", finvoicename, 11L);
  383. saorder.setValue("finvoicetaxnumber", finvoicetaxnumber, 11L);
  384. saorder.setValue("finvoiceaddress", finvoiceaddress, 11L);
  385. boolean fisusefl_old = saorder.getBoolean("fisusefl");
  386. saorder.setValue("fisusefl", fisusefl.equals("1"), 11L);
  387. saorder.setValue("fsaletype", fsaletype, 11L);
  388. saorder.setValue("fprojectnotes", fprojectnotes, 11L);
  389. saorder.setValue("fsignbacknum", fsignbacknum, 11L);
  390. if (fisusefl_old && fisusefl.equals("0")) {
  391. saorder.setValue("fagentuseflamount", 0, 11L);
  392. } else if (fuseflamount > 0) {
  393. saorder.setValue("fagentuseflamount", fuseflamount, 11L);
  394. }
  395. saorder.setValue("fpayagentnum", fpayagentnum, 11L);
  396. saorder.setValue("frecagentnum", frecagentnum, 11L);
  397. saorder.setValue("fprojectnum", fprojectnum, 2L);
  398. saorder.setValue("fbrand", fbrand, 2L);
  399. PaoSetRemote saorderdetailset = saorder.getPaoSet("saorderdetail_view");
  400. saorderdetailset.setOrderBy("frownum");
  401. saorderdetailset.reset();
  402. HashMap<String, PaoRemote> saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid");
  403. /**
  404. * 用以判断是否需要将表体行删除
  405. */
  406. ArrayList<String> donotdeleteid = new ArrayList<>();
  407. JSONArray detailArray = content.getJSONArray("saorderdetail");
  408. Iterator<JSONObject> it = detailArray.iterator();
  409. while (it.hasNext()) {
  410. JSONObject detailObject = it.next();
  411. String saorderdetailid = detailObject.getString("saorderdetailid");
  412. String fitemno = nullToStr(detailObject.getString("fitemno"));
  413. String fqty = detailObject.getString("fqty");
  414. String fdetailnotes = nullToStr(detailObject.getString("fnotes"));
  415. String fneeddate = nullToStr(detailObject.getString("fneeddate"));
  416. if (fneeddate.length() > 10) {
  417. fneeddate = fneeddate.substring(0, 10);
  418. }
  419. String fbackdate = "";
  420. if (detailObject.containsKey("fbackdate")) {
  421. fbackdate = nullToStr(detailObject.getString("fbackdate"));
  422. if (fbackdate.length() > 10) {
  423. fbackdate = fbackdate.substring(0, 10);
  424. }
  425. }
  426. //配送方案
  427. String frationnum = nullToStr(detailObject.getString("frationnum"));
  428. PaoRemote detailPao = null;
  429. if (saorderdetailmap.containsKey(saorderdetailid)) {
  430. donotdeleteid.add(saorderdetailid);
  431. detailPao = saorderdetailmap.get(saorderdetailid);
  432. } else if ("0".equals(saorderdetailid)) {
  433. /**
  434. * 如果id不为0表示该订单行本身不存在,需要增加行
  435. */
  436. detailPao = saorderdetailset.addAtEnd();
  437. detailPao.setValue("fitemno", fitemno, 2L);
  438. }
  439. if (detailPao != null) {
  440. if ("标准订单".equals(saorder.getString("ftype")) && detailObject.containsKey("fprice")) {
  441. double fchangeprice = detailObject.getDouble("fprice");
  442. PaoSetRemote titemset = detailPao.getPaoSet("titem");
  443. if (!titemset.isEmpty()) {
  444. titem titem = (titem) titemset.getPao(0);
  445. double fprice = titem.getAgentSalePrice(fagentnum);
  446. if (fchangeprice >= fprice) {
  447. detailPao.setValue("fprice", fchangeprice, 2L);
  448. detailPao.setValue("fpricechanged", true, 11L);
  449. } else {
  450. detailPao.setValue("fpricechanged", false, 11L);
  451. }
  452. }
  453. }
  454. detailPao.setValue("fqty", fqty, 2L);
  455. detailPao.setValue("frationnum", frationnum, 2L);
  456. detailPao.setValue("fnotes", fdetailnotes, 2L);
  457. detailPao.setValue("fneeddate", fneeddate, 2L);
  458. detailPao.setValue("fbackdate", fbackdate, 2L);
  459. }
  460. }
  461. /**
  462. * 删除多余的行
  463. */
  464. for (String id : saorderdetailmap.keySet()) {
  465. if (!donotdeleteid.contains(id)) {
  466. if (!saorderdetailmap.get(id).isModified()) {
  467. saorderdetailmap.get(id).delete();
  468. }
  469. }
  470. }
  471. /**
  472. * 行号重计算
  473. */
  474. int i = 0;
  475. int rownum = 1;
  476. while (saorderdetailset.getPao(i) != null) {
  477. if (!saorderdetailset.getPao(i).toBeDeleted()) {
  478. saorderdetailset.getPao(i).setValue("frownum", rownum++);
  479. }
  480. i++;
  481. }
  482. saorderSet.save();
  483. } finally {
  484. if (saorderSet != null) {
  485. saorderSet.close();
  486. }
  487. }
  488. return "true";
  489. }
  490. /**
  491. * 更新定制信息
  492. *
  493. * @param content
  494. * @return
  495. * @throws JSONException
  496. * @throws P2Exception
  497. */
  498. public String updateSaorderDetail_Customized(JSONObject content, String hrid) throws Exception {
  499. PaoSetRemote saorder_CustomizedSet = null;
  500. try {
  501. String saorderdetailid = content.getString("saorderdetailid");
  502. saorder_CustomizedSet = getP2ServerPaoSet("saorder_Customized", hrid, "fparentid='" + saorderdetailid + "'");
  503. JSONArray customizedsArray = content.getJSONArray("customizeds");
  504. Iterator<JSONObject> it = customizedsArray.iterator();
  505. while (it.hasNext()) {
  506. JSONObject customizedObject = it.next();
  507. // 订单定制信息行ID
  508. String titem_customizedid = customizedObject.getString("titem_customizedid");
  509. int i = 0;
  510. while (saorder_CustomizedSet.getPao(i) != null) {
  511. if (titem_customizedid.equals(saorder_CustomizedSet.getPao(i).getString("titem_customizedid"))) {
  512. saorder_CustomizedSet.getPao(i).setValue("fvalue", customizedObject.getString("fvalue"), 2L);
  513. saorder_CustomizedSet.getPao(i).setValue("remarks", customizedObject.getString("remarks"), 11L);
  514. }
  515. i++;
  516. }
  517. }
  518. saorder_CustomizedSet.save();
  519. } finally {
  520. if (saorder_CustomizedSet != null) {
  521. saorder_CustomizedSet.close();
  522. }
  523. }
  524. return "true";
  525. }
  526. /**
  527. * 更新普通促销订单
  528. *
  529. * @param content
  530. * @return
  531. * @throws JSONException
  532. * @throws P2Exception
  533. */
  534. public String updatesaorder_prom(JSONObject content, String hrid) throws Exception {
  535. PaoSetRemote saorderSet = null;
  536. try {
  537. // 订单ID
  538. String saorderid = content.getString("saorderid");
  539. // 订单号
  540. String fsonum = content.getString("fsonum");
  541. // 经销商编号
  542. String fagentnum = content.getString("fagentnum");
  543. // 单据日期
  544. String fdate = nullToStr(content.getString("fdate"));
  545. if (fdate.length() > 10) {
  546. fdate = fdate.substring(0, 10);
  547. }
  548. // 扣款帐户
  549. String faccclsnum = nullToStr(content.getString("faccclsnum"));
  550. // 联系方式
  551. String fphonenumber = nullToStr(content.getString("fphonenumber"));
  552. // 收货人
  553. String fcontact = nullToStr(content.getString("fcontact"));
  554. // 省
  555. String fprovince = nullToStr(content.getString("fprovince"));
  556. // 市
  557. String fcity = nullToStr(content.getString("fcity"));
  558. // 县
  559. String fcounty = nullToStr(content.getString("fcounty"));
  560. // 收货地址
  561. String faddress = nullToStr(content.getString("faddress"));
  562. // 开票单位
  563. String finvoicename = nullToStr(content.getString("finvoicename"));
  564. // 税号
  565. String finvoicetaxnumber = nullToStr(content.getString("finvoicetaxnumber"));
  566. // 开票地址
  567. String finvoiceaddress = nullToStr(content.getString("finvoiceaddress"));
  568. // 备注
  569. String fnotes = nullToStr(content.getString("fnotes"));
  570. String fpayagentnum = "";
  571. if (content.containsKey("fpayagentnum")) {
  572. fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户
  573. }
  574. if ("".equals(fpayagentnum)) {
  575. fpayagentnum = fagentnum;
  576. }
  577. String frecagentnum = "";
  578. if (content.containsKey("frecagentnum")) {
  579. frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户
  580. }
  581. if ("".equals(frecagentnum)) {
  582. frecagentnum = fagentnum;
  583. }
  584. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "' ");
  585. if (saorderSet.isEmpty()) {
  586. return "订单" + fsonum + "不存在!";
  587. }
  588. saorder saorder = (saorder) saorderSet.getPao(0);
  589. if (!"新建".equals(saorder.getString("fstatus"))) {
  590. return "非新建状态不可修改";
  591. }
  592. String ftype = saorder.getString("ftype");
  593. saorderSet.setApp("SAORDER4");
  594. saorder.setValue("fdate", fdate, 11L);
  595. saorder.setValue("faccclsnum", faccclsnum, 2L);
  596. saorder.setValue("fphonenumber", fphonenumber, 11L);
  597. saorder.setValue("fcontact", fcontact, 11L);
  598. saorder.setValue("fprovince", fprovince, 11L);
  599. saorder.setValue("fcity", fcity, 11L);
  600. saorder.setValue("fcounty", fcounty, 11L);
  601. saorder.setValue("faddress", faddress, 11L);
  602. saorder.setValue("fnotes", fnotes, 11L);
  603. saorder.setValue("finvoicename", finvoicename, 11L);
  604. saorder.setValue("finvoicetaxnumber", finvoicetaxnumber, 11L);
  605. saorder.setValue("finvoiceaddress", finvoiceaddress, 11L);
  606. saorder.setValue("fpayagentnum", fpayagentnum, 11L);
  607. saorder.setValue("frecagentnum", frecagentnum, 2L);
  608. PaoSetRemote saorderdetailset = saorder.getPaoSet("saorderdetail_view");
  609. saorderdetailset.setOrderBy("frownum");
  610. saorderdetailset.reset();
  611. HashMap<String, PaoRemote> saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid");
  612. /**
  613. * 用以判断是否需要将表体行删除
  614. */
  615. ArrayList<String> donotdeleteid = new ArrayList<>();
  616. JSONArray detailArray = content.getJSONArray("saorderdetail");
  617. Iterator<JSONObject> it = detailArray.iterator();
  618. while (it.hasNext()) {
  619. JSONObject detailObject = it.next();
  620. String saorderdetailid = detailObject.getString("saorderdetailid");
  621. String fitemno = nullToStr(detailObject.getString("fitemno"));
  622. String fqty = detailObject.getString("fqty");
  623. String fdetailnotes = nullToStr(detailObject.getString("fnotes"));
  624. //配送方案
  625. String frationnum = nullToStr(detailObject.getString("frationnum"));
  626. String fneeddate = nullToStr(detailObject.getString("fneeddate"));
  627. if (fneeddate.length() > 10) {
  628. fneeddate = fneeddate.substring(0, 10);
  629. }
  630. PaoRemote detailPao = null;
  631. if (saorderdetailmap.containsKey(saorderdetailid)) {
  632. donotdeleteid.add(saorderdetailid);
  633. detailPao = saorderdetailmap.get(saorderdetailid);
  634. } else if ("0".equals(saorderdetailid)) {
  635. PaoSetRemote tpromproductsSet = saorder.getPaoSet("tpromproducts");
  636. int i = 0;
  637. while (tpromproductsSet.getPao(i) != null) {
  638. if (fitemno.equals(tpromproductsSet.getPao(i).getString("fitemno"))) {
  639. tpromproductsSet.getPao(i).select();
  640. detailPao = saorder.additems_prom(tpromproductsSet.getPao(i));
  641. break;
  642. }
  643. i++;
  644. }
  645. }
  646. if (detailPao != null) {
  647. detailPao.setValue("fqty", fqty, 2L);
  648. detailPao.setValue("frationnum", frationnum, 2L);
  649. detailPao.setValue("fnotes", fdetailnotes, 2L);
  650. detailPao.setValue("fneeddate", fneeddate, 2L);
  651. }
  652. }
  653. for (String id : saorderdetailmap.keySet()) {
  654. if (!donotdeleteid.contains(id)) {
  655. if (!saorderdetailmap.get(id).isModified()) {
  656. saorderdetailmap.get(id).delete();
  657. }
  658. }
  659. }
  660. /*** 行号重计算 */
  661. int i = 0;
  662. int rownum = 1;
  663. while (saorderdetailset.getPao(i) != null) {
  664. if (!saorderdetailset.getPao(i).toBeDeleted()) {
  665. saorderdetailset.getPao(i).setValue("frownum", rownum++);
  666. }
  667. i++;
  668. }
  669. saorderSet.save();
  670. } finally {
  671. if (saorderSet != null) {
  672. saorderSet.close();
  673. }
  674. }
  675. return "true";
  676. }
  677. /**
  678. * 更新打包促销订单
  679. *
  680. * @param content
  681. * @return
  682. * @throws JSONException
  683. * @throws P2Exception
  684. */
  685. public String updatesaorder_packprom(JSONObject content, String hrid) throws Exception {
  686. PaoSetRemote saorderSet = null;
  687. try {
  688. // 订单ID
  689. String saorderid = content.getString("saorderid");
  690. // 订单号
  691. String fsonum = content.getString("fsonum");
  692. // 经销商编号
  693. String fagentnum = content.getString("fagentnum");
  694. //打包数量
  695. String fpromqty = content.getString("fpromqty");
  696. // 单据日期
  697. String fdate = nullToStr(content.getString("fdate"));
  698. if (fdate.length() > 10) {
  699. fdate = fdate.substring(0, 10);
  700. }
  701. // 扣款帐户
  702. String faccclsnum = nullToStr(content.getString("faccclsnum"));
  703. // 联系方式
  704. String fphonenumber = nullToStr(content.getString("fphonenumber"));
  705. // 收货人
  706. String fcontact = nullToStr(content.getString("fcontact"));
  707. // 省
  708. String fprovince = nullToStr(content.getString("fprovince"));
  709. // 市
  710. String fcity = nullToStr(content.getString("fcity"));
  711. // 县
  712. String fcounty = nullToStr(content.getString("fcounty"));
  713. // 收货地址
  714. String faddress = nullToStr(content.getString("faddress"));
  715. // 开票单位
  716. String finvoicename = nullToStr(content.getString("finvoicename"));
  717. // 税号
  718. String finvoicetaxnumber = nullToStr(content.getString("finvoicetaxnumber"));
  719. // 开票地址
  720. String finvoiceaddress = nullToStr(content.getString("finvoiceaddress"));
  721. // 备注
  722. String fnotes = nullToStr(content.getString("fnotes"));
  723. String fpayagentnum = "";
  724. if (content.containsKey("fpayagentnum")) {
  725. fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户
  726. }
  727. if ("".equals(fpayagentnum)) {
  728. fpayagentnum = fagentnum;
  729. }
  730. String frecagentnum = "";
  731. if (content.containsKey("frecagentnum")) {
  732. frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户
  733. }
  734. if ("".equals(frecagentnum)) {
  735. frecagentnum = fagentnum;
  736. }
  737. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "' ");
  738. if (saorderSet.isEmpty()) {
  739. return "订单" + fsonum + "不存在!";
  740. }
  741. saorder saorder = (saorder) saorderSet.getPao(0);
  742. if (!"新建".equals(saorder.getString("fstatus"))) {
  743. return "非新建状态不可修改";
  744. }
  745. String ftype = saorder.getString("ftype");
  746. saorderSet.setApp("SAORDER4");
  747. saorder.setValue("fdate", fdate, 11L);
  748. saorder.setValue("faccclsnum", faccclsnum, 2L);
  749. saorder.setValue("fphonenumber", fphonenumber, 11L);
  750. saorder.setValue("fcontact", fcontact, 11L);
  751. saorder.setValue("fprovince", fprovince, 11L);
  752. saorder.setValue("fcity", fcity, 11L);
  753. saorder.setValue("fcounty", fcounty, 11L);
  754. saorder.setValue("faddress", faddress, 11L);
  755. saorder.setValue("fnotes", fnotes, 11L);
  756. saorder.setValue("finvoicename", finvoicename, 11L);
  757. saorder.setValue("finvoicetaxnumber", finvoicetaxnumber, 11L);
  758. saorder.setValue("finvoiceaddress", finvoiceaddress, 11L);
  759. saorder.setValue("fpromqty", fpromqty, 2L);
  760. saorder.setValue("fpayagentnum", fpayagentnum, 2L);
  761. saorder.setValue("frecagentnum", frecagentnum, 2L);
  762. PaoSetRemote saorderdetailset = saorder.getPaoSet("saorderdetail_view");
  763. saorderdetailset.setOrderBy("frownum");
  764. saorderdetailset.reset();
  765. HashMap<String, PaoRemote> saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid");
  766. JSONArray detailArray = content.getJSONArray("saorderdetail");
  767. Iterator<JSONObject> it = detailArray.iterator();
  768. while (it.hasNext()) {
  769. JSONObject detailObject = it.next();
  770. String saorderdetailid = detailObject.getString("saorderdetailid");
  771. String fdetailnotes = nullToStr(detailObject.getString("fnotes"));
  772. //配送方案
  773. String frationnum = nullToStr(detailObject.getString("frationnum"));
  774. String fneeddate = nullToStr(detailObject.getString("fneeddate"));
  775. if (fneeddate.length() > 10) {
  776. fneeddate = fneeddate.substring(0, 10);
  777. }
  778. PaoRemote detailPao = null;
  779. if (saorderdetailmap.containsKey(saorderdetailid)) {
  780. detailPao = saorderdetailmap.get(saorderdetailid);
  781. }
  782. if (detailPao != null) {
  783. detailPao.setValue("frationnum", frationnum, 2L);
  784. detailPao.setValue("fnotes", fdetailnotes, 2L);
  785. detailPao.setValue("fneeddate", fneeddate, 11L);
  786. }
  787. }
  788. /*** 行号重计算 */
  789. int i = 0;
  790. int rownum = 1;
  791. while (saorderdetailset.getPao(i) != null) {
  792. if (!saorderdetailset.getPao(i).toBeDeleted()) {
  793. saorderdetailset.getPao(i).setValue("frownum", rownum++);
  794. }
  795. i++;
  796. }
  797. saorderSet.save();
  798. } finally {
  799. if (saorderSet != null) {
  800. saorderSet.close();
  801. }
  802. }
  803. return "true";
  804. }
  805. /**
  806. * 生成配送件
  807. *
  808. * @param content
  809. * @return
  810. */
  811. public String createration(JSONObject content, String hrid) throws Exception {
  812. PaoSetRemote saorderSet = null;
  813. try {
  814. // 订单号
  815. String fsonum = content.getString("fsonum");
  816. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'");
  817. if (!saorderSet.isEmpty()) {
  818. saorder saorder = (saorder) saorderSet.getPao(0);
  819. saorder.createrationvalidate();
  820. saorder.createration();
  821. saorderSet.save();
  822. } else {
  823. return "订单号:" + fsonum + "不存在";
  824. }
  825. } finally {
  826. if (saorderSet != null) {
  827. saorderSet.close();
  828. }
  829. }
  830. return "true";
  831. }
  832. /**
  833. * 清空配送件
  834. *
  835. * @param content
  836. * @return
  837. */
  838. public String deleteration(JSONObject content, String hrid) throws Exception {
  839. PaoSetRemote saorderSet = null;
  840. try {
  841. // 订单号
  842. String fsonum = content.getString("fsonum");
  843. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'");
  844. if (!saorderSet.isEmpty()) {
  845. saorder saorder = (saorder) saorderSet.getPao(0);
  846. saorder.deleterationvalidate();
  847. saorder.deleteration();
  848. saorderSet.save();
  849. } else {
  850. return "订单号:" + fsonum + "不存在";
  851. }
  852. } finally {
  853. if (saorderSet != null) {
  854. saorderSet.close();
  855. }
  856. }
  857. return "true";
  858. }
  859. public String deletesaorder(JSONObject content, String hrid) throws Exception {
  860. PaoSetRemote saorderSet = null;
  861. try {
  862. // 订单号
  863. String fsonum = content.getString("fsonum");
  864. // 经销商
  865. //String fagentnum = content.getString("fagentnum");
  866. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'");
  867. if (!saorderSet.isEmpty()) {
  868. saorder saorder = (saorder) saorderSet.getPao(0);
  869. saorder.delete(0L);
  870. saorderSet.save();
  871. } else {
  872. return "订单号:" + fsonum + "不存在";
  873. }
  874. } finally {
  875. if (saorderSet != null) {
  876. saorderSet.close();
  877. }
  878. }
  879. return "true";
  880. }
  881. public String submitsaorder(JSONObject content, String hrid) throws Exception {
  882. PaoSetRemote saorderSet = null;
  883. try {
  884. // 订单号
  885. String fsonum = content.getString("fsonum");
  886. // 经销商
  887. String fagentnum = content.getString("fagentnum");
  888. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'");
  889. if (!saorderSet.isEmpty()) {
  890. saorder saorder = (saorder) saorderSet.getPao(0);
  891. if ("标准订单".equals(saorder.getString("ftype"))) {
  892. saorderSet.setApp("SAORDER1");
  893. }
  894. HashMap<String, Double[]> map = saorder.checkitemprice();
  895. if (!map.isEmpty()) {
  896. StringBuffer msg = new StringBuffer();
  897. for (String fitemno : map.keySet()) {
  898. msg.append("商品编号" + fitemno + "销售价格已由" + map.get(fitemno)[0] + "调整为" + map.get(fitemno)[1] + ";");
  899. }
  900. return msg.toString();
  901. }
  902. saorder.ordercaculate(saorder.getPaoSet("saorderdetail_view"));
  903. saorder.submitvalidate(true);
  904. saorder.submit(true);
  905. saorderSet.save();
  906. } else {
  907. return "订单号:" + fsonum + "不存在";
  908. }
  909. } finally {
  910. if (saorderSet != null) {
  911. saorderSet.close();
  912. }
  913. }
  914. return "true";
  915. }
  916. public String updateitemprice(JSONObject content, String hrid) throws Exception {
  917. PaoSetRemote saorderSet = null;
  918. try {
  919. // 订单号
  920. String fsonum = content.getString("fsonum");
  921. // 经销商
  922. String fagentnum = content.getString("fagentnum");
  923. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'");
  924. if (!saorderSet.isEmpty()) {
  925. saorder saorder = (saorder) saorderSet.getPao(0);
  926. saorder.updateitemprice();
  927. saorderSet.save();
  928. } else {
  929. return "订单号:" + fsonum + "不存在";
  930. }
  931. } finally {
  932. if (saorderSet != null) {
  933. saorderSet.close();
  934. }
  935. }
  936. return "true";
  937. }
  938. public String needdateconfirm(JSONObject content, String hrid) throws Exception {
  939. PaoSetRemote saorderSet = null;
  940. try {
  941. // 订单号
  942. String fsonum = content.getString("fsonum");
  943. // 经销商
  944. String fagentnum = content.getString("fagentnum");
  945. saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'");
  946. if (!saorderSet.isEmpty()) {
  947. saorder saorder = (saorder) saorderSet.getPao(0);
  948. saorder.needdateconfirmvalidate(true);
  949. saorder.needdateconfirm(true);
  950. saorderSet.save();
  951. } else {
  952. return "订单号:" + fsonum + "不存在";
  953. }
  954. } finally {
  955. if (saorderSet != null) {
  956. saorderSet.close();
  957. }
  958. }
  959. return "true";
  960. }
  961. }