package openapi.restcontroller.wechatapp.saorder.tools; import net.sf.json.JSONArray; import net.sf.json.JSONException; import net.sf.json.JSONObject; import openapi.base.BaseClass; import openapi.base.data.db.DBConnect; import p2.pao.PaoRemote; import p2.pao.PaoSetRemote; import p2.util.P2Exception; import saorder.saorder; import titem.titem; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; public class SaorderTool extends BaseClass { public String copy(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; String fsonum = ""; try { String foldsonum = content.getString("fsonum"); String ftype = content.getString("ftype"); saorderSet = getP2ServerPaoSet("saorder", hrid); saorderSet.setWhere("fsonum='" + foldsonum + "'"); saorderSet.reset(); saorder saorder = (saorder) saorderSet.getPao(0); if ("标准订单".equals(ftype)) { saorderSet.setApp("SAORDER1"); } else if ("定制订单".equals(ftype)) { saorderSet.setApp("SAORDER5"); } else if ("工具订单".equals(ftype)) { saorderSet.setApp("SAORDER6"); } else if ("工具借出单".equals(ftype)) { saorderSet.setApp("SAORDER7"); } else if ("项目订单".equals(ftype)) { saorderSet.setApp("SAORDER9"); } /** * 订单表头新增 */ PaoRemote newsaorder = saorder.duplicate(); fsonum = newsaorder.getString("fsonum"); saorderSet.save(); } finally { if (saorderSet != null) { saorderSet.close(); } } return fsonum; } /** * 标准订单新增 */ public String createsaorder(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; String fsonum = ""; try { String fagentnum = content.getString("fagentnum"); String ftype = content.getString("ftype"); String fiswuliao = content.getString("fiswuliao"); String fieldname = content.getString("fieldname");//领域 String fbrand = content.getString("fbrand");//品牌 String fprojectnum = ""; if (content.containsKey("fprojectnum")) { fprojectnum = nullToStr(content.getString("fprojectnum"));//项目编号 } String fpayagentnum = ""; if (content.containsKey("fpayagentnum")) { fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户 } if ("".equals(fpayagentnum)) { fpayagentnum = fagentnum; } String frecagentnum = ""; if (content.containsKey("frecagentnum")) { frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户 } if ("".equals(frecagentnum)) { frecagentnum = fagentnum; } JSONArray itemnos = content.getJSONArray("itemnos"); saorderSet = getP2ServerPaoSet("saorder", hrid); if ("标准订单".equals(ftype)) { saorderSet.setApp("SAORDER1"); } else if ("定制订单".equals(ftype)) { saorderSet.setApp("SAORDER5"); } else if ("工具订单".equals(ftype)) { saorderSet.setApp("SAORDER6"); } else if ("工具借出单".equals(ftype)) { saorderSet.setApp("SAORDER7"); } else if ("项目订单".equals(ftype)) { saorderSet.setApp("SAORDER9"); } /** * 订单表头新增 */ saorder saorder = (saorder) saorderSet.addAtEnd(); fsonum = saorder.createSoNum(); saorder.setValue("ftype", ftype, 11L); saorder.setValue("fsonum", fsonum, 11L); saorder.setValue("createby", hrid, 11L); saorder.setValue("fagentnum", fagentnum, 2L); saorder.setValue("fieldname", fieldname, 2L); saorder.setValue("fbrand", fbrand, 2L); saorder.setValue("fiswuliao", fiswuliao.equals("1"), 2L); saorder.setValue("fisusefl", !fiswuliao.equals("1"), 2L); saorder.setValue("fpayagentnum", fpayagentnum, 2L); saorder.setValue("frecagentnum", frecagentnum, 2L); saorder.setValue("fprojectnum", fprojectnum, 2L); if (content.containsKey("faccclsnum") && !"".equals(content.getString("faccclsnum")) && !"工具借出单".equals(ftype)) { saorder.setValue("faccclsnum", content.getString("faccclsnum"), 11L); } PaoSetRemote saorderdetailset = saorder.getPaoSet("saorderdetail_view"); ArrayList sqllist = new ArrayList<>(); Iterator it = itemnos.iterator(); while (it.hasNext()) { JSONObject object = it.next(); long tshoppingcartid = object.getLong("tshoppingcartid"); /** * 订单行新增 */ PaoRemote newdetail = saorderdetailset.addAtEnd(); newdetail.setValue("fitemno", object.getString("fitemno"), 2L); newdetail.setValue("fqty", object.getDouble("fqty"), 2L); /** * 入股是定制订单,则添加定制信息 */ if ("定制订单".equals(ftype) && newdetail.getPaoSet("saorder_customized").isEmpty()) { PaoSetRemote saorder_customizedset = newdetail.getPaoSet("saorder_customized"); PaoSetRemote tshoppingcart_customized = newdetail.getPaoSet("$tshoppingcart_customized", "tshoppingcart_customized", "fparentid=" + tshoppingcartid); int i = 0; PaoRemote pao = null; while ((pao = tshoppingcart_customized.getPao(i)) != null) { PaoRemote saorder_customized = saorder_customizedset.addAtEnd(); saorder_customized.setValue("titem_customizedid", pao.getLong("titem_customizedid"), 11L); saorder_customized.setValue("fitemno", pao.getString("fitemno"), 11L); saorder_customized.setValue("fname", pao.getString("fname"), 11L); saorder_customized.setValue("fnotes", pao.getString("fnotes"), 11L); saorder_customized.setValue("ftype", pao.getString("ftype"), 11L); saorder_customized.setValue("fvalue", pao.getString("fvalue"), 11L); i++; } } sqllist.add("delete from tshoppingcart where tshoppingcartid=" + tshoppingcartid); } saorderSet.save(); new DBConnect().runSqlUpdate(sqllist); } finally { if (saorderSet != null) { saorderSet.close(); } } return fsonum; } /** * 普通促销订单新增 * * @param content * @return * @throws JSONException * @throws P2Exception */ public String createsaorder_prom(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; String fsonum = ""; try { String fagentnum = content.getString("fagentnum"); String fpromnum = content.getString("fpromnum"); String ftype = content.getString("ftype"); String fpayagentnum = ""; if (content.containsKey("fpayagentnum")) { fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户 } if ("".equals(fpayagentnum)) { fpayagentnum = fagentnum; } String frecagentnum = ""; if (content.containsKey("frecagentnum")) { frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户 } if ("".equals(frecagentnum)) { frecagentnum = fagentnum; } JSONArray itemnos = content.getJSONArray("itemnos"); saorderSet = getP2ServerPaoSet("saorder", hrid); saorderSet.setApp("SAORDER4"); /** * 订单表头新增 */ saorder saorder = (saorder) saorderSet.addAtEnd(); fsonum = saorder.createSoNum(); saorder.setValue("ftype", ftype, 11L); saorder.setValue("fsonum", fsonum, 11L); saorder.setValue("createby", hrid, 11L); saorder.setValue("fagentnum", fagentnum, 2L); saorder.setValue("fpayagentnum", fpayagentnum, 2L); saorder.setValue("frecagentnum", frecagentnum, 2L); saorder.setValue("fpromnum", fpromnum, 2L); PaoSetRemote tpromproductsSet = saorder.getPaoSet("tpromproducts"); HashMap paomap = getPaoMap(tpromproductsSet, "fitemno"); Iterator it = itemnos.iterator(); while (it.hasNext()) { JSONObject object = it.next(); String fitemno = object.getString("fitemno"); double fqty = object.getDouble("fqty"); if (paomap.containsKey(fitemno)) { PaoRemote pao = paomap.get(fitemno); pao.setValue("faddqty", fqty, 11L); pao.select(); } // int i = 0; // while (tpromproductsSet.getPao(i) != null) { // if (fitemno.equals(tpromproductsSet.getPao(i).getString("fitemno"))) { // tpromproductsSet.getPao(i).setValue("faddqty", fqty, 11L); // tpromproductsSet.getPao(i).select(); // break; // } // i++; // } } saorder.additems_prom(tpromproductsSet); saorderSet.save(); } finally { if (saorderSet != null) { saorderSet.close(); } } return fsonum; } /** * 打包促销订单新增 * * @param content * @return * @throws JSONException * @throws P2Exception */ public String createsaorder_packprom(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; String fsonum = ""; try { String fagentnum = content.getString("fagentnum"); String fpromnum = content.getString("fpromnum"); int fpromqty = content.getInt("fpromqty"); String ftype = content.getString("ftype"); String fpayagentnum = ""; if (content.containsKey("fpayagentnum")) { fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户 } if ("".equals(fpayagentnum)) { fpayagentnum = fagentnum; } String frecagentnum = ""; if (content.containsKey("frecagentnum")) { frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户 } if ("".equals(frecagentnum)) { frecagentnum = fagentnum; } saorderSet = getP2ServerPaoSet("saorder", hrid); saorderSet.setApp("SAORDER4"); /** * 订单表头新增 */ saorder saorder = (saorder) saorderSet.addAtEnd(); fsonum = saorder.createSoNum(); saorder.setValue("ftype", ftype, 11L); saorder.setValue("fsonum", fsonum, 11L); saorder.setValue("createby", hrid, 11L); saorder.setValue("fagentnum", fagentnum, 2L); saorder.setValue("fpayagentnum", fpayagentnum, 2L); saorder.setValue("frecagentnum", frecagentnum, 2L); saorder.setValue("fpromnum", fpromnum, 2L); saorder.setValue("fpromqty", fpromqty, 2L); saorderSet.save(); } finally { if (saorderSet != null) { saorderSet.close(); } } return fsonum; } /** * 更新标准订单 * * @param content * @return * @throws JSONException * @throws P2Exception */ public String updatesaorder(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单ID String saorderid = content.getString("saorderid"); // 订单号 String fsonum = content.getString("fsonum"); // 经销商编号 String fagentnum = content.getString("fagentnum"); // 单据日期 String fdate = nullToStr(content.getString("fdate")); if (fdate.length() > 10) { fdate = fdate.substring(0, 10); } // 扣款帐户 String faccclsnum = nullToStr(content.getString("faccclsnum")); // 联系方式 String fphonenumber = nullToStr(content.getString("fphonenumber")); // 收货人 String fcontact = nullToStr(content.getString("fcontact")); // 省 String fprovince = nullToStr(content.getString("fprovince")); // 市 String fcity = nullToStr(content.getString("fcity")); // 县 String fcounty = nullToStr(content.getString("fcounty")); // 收货地址 String faddress = nullToStr(content.getString("faddress")); // 开票单位 String finvoicename = nullToStr(content.getString("finvoicename")); // 税号 String finvoicetaxnumber = nullToStr(content.getString("finvoicetaxnumber")); // 开票地址 String finvoiceaddress = nullToStr(content.getString("finvoiceaddress")); // 备注 String fnotes = nullToStr(content.getString("fnotes")); // 是否使用返利 String fisusefl = nullToStr(content.getString("fisusefl")); //经销商使用返利金设定 double fuseflamount = content.getDouble("fuseflamount"); String fbrand = content.getString("fbrand");//品牌 String fsignbacknum = content.getString("fsignbacknum");//回签单 String fsaletype = ""; if (content.containsKey("fsaletype") && !content.getString("fsaletype").equalsIgnoreCase("null")) { fsaletype = content.getString("fsaletype"); } String fprojectnotes = ""; if (content.containsKey("fprojectnotes") && !content.getString("fprojectnotes").equalsIgnoreCase("null")) { fprojectnotes = content.getString("fprojectnotes"); } String fprojectnum = ""; if (content.containsKey("fprojectnum") && !content.getString("fprojectnum").equalsIgnoreCase("null")) { fprojectnum = nullToStr(content.getString("fprojectnum"));//项目编号 } String fpayagentnum = ""; if (content.containsKey("fpayagentnum") && !content.getString("fpayagentnum").equalsIgnoreCase("null")) { fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户 } if ("".equals(fpayagentnum)) { fpayagentnum = fagentnum; } String frecagentnum = ""; if (content.containsKey("frecagentnum") && !content.getString("frecagentnum").equalsIgnoreCase("null")) { frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户 } if ("".equals(frecagentnum)) { frecagentnum = fagentnum; } String fieldname = content.getString("fieldname");//领域 saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "' "); if (saorderSet.isEmpty()) { return "订单" + fsonum + "不存在!"; } saorder saorder = (saorder) saorderSet.getPao(0); if (!"新建".equals(saorder.getString("fstatus"))) { return "非新建状态不可修改"; } String ftype = saorder.getString("ftype"); saorderSet.setApp("SAORDER1"); /** * 修改表头字段信息 */ saorder.setValue("fieldname", fieldname, 2L); saorder.setValue("fdate", fdate, 11L); saorder.setValue("faccclsnum", faccclsnum, 2L); saorder.setValue("fphonenumber", fphonenumber, 11L); saorder.setValue("fcontact", fcontact, 11L); saorder.setValue("fprovince", fprovince, 11L); saorder.setValue("fcity", fcity, 11L); saorder.setValue("fcounty", fcounty, 11L); saorder.setValue("faddress", faddress, 11L); saorder.setValue("fnotes", fnotes, 11L); saorder.setValue("finvoicename", finvoicename, 11L); saorder.setValue("finvoicetaxnumber", finvoicetaxnumber, 11L); saorder.setValue("finvoiceaddress", finvoiceaddress, 11L); boolean fisusefl_old = saorder.getBoolean("fisusefl"); saorder.setValue("fisusefl", fisusefl.equals("1"), 11L); saorder.setValue("fsaletype", fsaletype, 11L); saorder.setValue("fprojectnotes", fprojectnotes, 11L); saorder.setValue("fsignbacknum", fsignbacknum, 11L); if (fisusefl_old && fisusefl.equals("0")) { saorder.setValue("fagentuseflamount", 0, 11L); } else if (fuseflamount > 0) { saorder.setValue("fagentuseflamount", fuseflamount, 11L); } saorder.setValue("fpayagentnum", fpayagentnum, 11L); saorder.setValue("frecagentnum", frecagentnum, 11L); saorder.setValue("fprojectnum", fprojectnum, 2L); saorder.setValue("fbrand", fbrand, 2L); PaoSetRemote saorderdetailset = saorder.getPaoSet("saorderdetail_view"); saorderdetailset.setOrderBy("frownum"); saorderdetailset.reset(); HashMap saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid"); /** * 用以判断是否需要将表体行删除 */ ArrayList donotdeleteid = new ArrayList<>(); JSONArray detailArray = content.getJSONArray("saorderdetail"); Iterator it = detailArray.iterator(); while (it.hasNext()) { JSONObject detailObject = it.next(); String saorderdetailid = detailObject.getString("saorderdetailid"); String fitemno = nullToStr(detailObject.getString("fitemno")); String fqty = detailObject.getString("fqty"); String fdetailnotes = nullToStr(detailObject.getString("fnotes")); String fneeddate = nullToStr(detailObject.getString("fneeddate")); if (fneeddate.length() > 10) { fneeddate = fneeddate.substring(0, 10); } String fbackdate = ""; if (detailObject.containsKey("fbackdate")) { fbackdate = nullToStr(detailObject.getString("fbackdate")); if (fbackdate.length() > 10) { fbackdate = fbackdate.substring(0, 10); } } //配送方案 String frationnum = nullToStr(detailObject.getString("frationnum")); PaoRemote detailPao = null; if (saorderdetailmap.containsKey(saorderdetailid)) { donotdeleteid.add(saorderdetailid); detailPao = saorderdetailmap.get(saorderdetailid); } else if ("0".equals(saorderdetailid)) { /** * 如果id不为0表示该订单行本身不存在,需要增加行 */ detailPao = saorderdetailset.addAtEnd(); detailPao.setValue("fitemno", fitemno, 2L); } if (detailPao != null) { if ("标准订单".equals(saorder.getString("ftype")) && detailObject.containsKey("fprice")) { double fchangeprice = detailObject.getDouble("fprice"); PaoSetRemote titemset = detailPao.getPaoSet("titem"); if (!titemset.isEmpty()) { titem titem = (titem) titemset.getPao(0); double fprice = titem.getAgentSalePrice(fagentnum); if (fchangeprice >= fprice) { detailPao.setValue("fprice", fchangeprice, 2L); detailPao.setValue("fpricechanged", true, 11L); } else { detailPao.setValue("fpricechanged", false, 11L); } } } detailPao.setValue("fqty", fqty, 2L); detailPao.setValue("frationnum", frationnum, 2L); detailPao.setValue("fnotes", fdetailnotes, 2L); detailPao.setValue("fneeddate", fneeddate, 2L); detailPao.setValue("fbackdate", fbackdate, 2L); } } /** * 删除多余的行 */ for (String id : saorderdetailmap.keySet()) { if (!donotdeleteid.contains(id)) { if (!saorderdetailmap.get(id).isModified()) { saorderdetailmap.get(id).delete(); } } } /** * 行号重计算 */ int i = 0; int rownum = 1; while (saorderdetailset.getPao(i) != null) { if (!saorderdetailset.getPao(i).toBeDeleted()) { saorderdetailset.getPao(i).setValue("frownum", rownum++); } i++; } saorderSet.save(); } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } /** * 更新定制信息 * * @param content * @return * @throws JSONException * @throws P2Exception */ public String updateSaorderDetail_Customized(JSONObject content, String hrid) throws Exception { PaoSetRemote saorder_CustomizedSet = null; try { String saorderdetailid = content.getString("saorderdetailid"); saorder_CustomizedSet = getP2ServerPaoSet("saorder_Customized", hrid, "fparentid='" + saorderdetailid + "'"); JSONArray customizedsArray = content.getJSONArray("customizeds"); Iterator it = customizedsArray.iterator(); while (it.hasNext()) { JSONObject customizedObject = it.next(); // 订单定制信息行ID String titem_customizedid = customizedObject.getString("titem_customizedid"); int i = 0; while (saorder_CustomizedSet.getPao(i) != null) { if (titem_customizedid.equals(saorder_CustomizedSet.getPao(i).getString("titem_customizedid"))) { saorder_CustomizedSet.getPao(i).setValue("fvalue", customizedObject.getString("fvalue"), 2L); saorder_CustomizedSet.getPao(i).setValue("remarks", customizedObject.getString("remarks"), 11L); } i++; } } saorder_CustomizedSet.save(); } finally { if (saorder_CustomizedSet != null) { saorder_CustomizedSet.close(); } } return "true"; } /** * 更新普通促销订单 * * @param content * @return * @throws JSONException * @throws P2Exception */ public String updatesaorder_prom(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单ID String saorderid = content.getString("saorderid"); // 订单号 String fsonum = content.getString("fsonum"); // 经销商编号 String fagentnum = content.getString("fagentnum"); // 单据日期 String fdate = nullToStr(content.getString("fdate")); if (fdate.length() > 10) { fdate = fdate.substring(0, 10); } // 扣款帐户 String faccclsnum = nullToStr(content.getString("faccclsnum")); // 联系方式 String fphonenumber = nullToStr(content.getString("fphonenumber")); // 收货人 String fcontact = nullToStr(content.getString("fcontact")); // 省 String fprovince = nullToStr(content.getString("fprovince")); // 市 String fcity = nullToStr(content.getString("fcity")); // 县 String fcounty = nullToStr(content.getString("fcounty")); // 收货地址 String faddress = nullToStr(content.getString("faddress")); // 开票单位 String finvoicename = nullToStr(content.getString("finvoicename")); // 税号 String finvoicetaxnumber = nullToStr(content.getString("finvoicetaxnumber")); // 开票地址 String finvoiceaddress = nullToStr(content.getString("finvoiceaddress")); // 备注 String fnotes = nullToStr(content.getString("fnotes")); String fpayagentnum = ""; if (content.containsKey("fpayagentnum")) { fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户 } if ("".equals(fpayagentnum)) { fpayagentnum = fagentnum; } String frecagentnum = ""; if (content.containsKey("frecagentnum")) { frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户 } if ("".equals(frecagentnum)) { frecagentnum = fagentnum; } saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "' "); if (saorderSet.isEmpty()) { return "订单" + fsonum + "不存在!"; } saorder saorder = (saorder) saorderSet.getPao(0); if (!"新建".equals(saorder.getString("fstatus"))) { return "非新建状态不可修改"; } String ftype = saorder.getString("ftype"); saorderSet.setApp("SAORDER4"); saorder.setValue("fdate", fdate, 11L); saorder.setValue("faccclsnum", faccclsnum, 2L); saorder.setValue("fphonenumber", fphonenumber, 11L); saorder.setValue("fcontact", fcontact, 11L); saorder.setValue("fprovince", fprovince, 11L); saorder.setValue("fcity", fcity, 11L); saorder.setValue("fcounty", fcounty, 11L); saorder.setValue("faddress", faddress, 11L); saorder.setValue("fnotes", fnotes, 11L); saorder.setValue("finvoicename", finvoicename, 11L); saorder.setValue("finvoicetaxnumber", finvoicetaxnumber, 11L); saorder.setValue("finvoiceaddress", finvoiceaddress, 11L); saorder.setValue("fpayagentnum", fpayagentnum, 11L); saorder.setValue("frecagentnum", frecagentnum, 2L); PaoSetRemote saorderdetailset = saorder.getPaoSet("saorderdetail_view"); saorderdetailset.setOrderBy("frownum"); saorderdetailset.reset(); HashMap saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid"); /** * 用以判断是否需要将表体行删除 */ ArrayList donotdeleteid = new ArrayList<>(); JSONArray detailArray = content.getJSONArray("saorderdetail"); Iterator it = detailArray.iterator(); while (it.hasNext()) { JSONObject detailObject = it.next(); String saorderdetailid = detailObject.getString("saorderdetailid"); String fitemno = nullToStr(detailObject.getString("fitemno")); String fqty = detailObject.getString("fqty"); String fdetailnotes = nullToStr(detailObject.getString("fnotes")); //配送方案 String frationnum = nullToStr(detailObject.getString("frationnum")); String fneeddate = nullToStr(detailObject.getString("fneeddate")); if (fneeddate.length() > 10) { fneeddate = fneeddate.substring(0, 10); } PaoRemote detailPao = null; if (saorderdetailmap.containsKey(saorderdetailid)) { donotdeleteid.add(saorderdetailid); detailPao = saorderdetailmap.get(saorderdetailid); } else if ("0".equals(saorderdetailid)) { PaoSetRemote tpromproductsSet = saorder.getPaoSet("tpromproducts"); int i = 0; while (tpromproductsSet.getPao(i) != null) { if (fitemno.equals(tpromproductsSet.getPao(i).getString("fitemno"))) { tpromproductsSet.getPao(i).select(); detailPao = saorder.additems_prom(tpromproductsSet.getPao(i)); break; } i++; } } if (detailPao != null) { detailPao.setValue("fqty", fqty, 2L); detailPao.setValue("frationnum", frationnum, 2L); detailPao.setValue("fnotes", fdetailnotes, 2L); detailPao.setValue("fneeddate", fneeddate, 2L); } } for (String id : saorderdetailmap.keySet()) { if (!donotdeleteid.contains(id)) { if (!saorderdetailmap.get(id).isModified()) { saorderdetailmap.get(id).delete(); } } } /*** 行号重计算 */ int i = 0; int rownum = 1; while (saorderdetailset.getPao(i) != null) { if (!saorderdetailset.getPao(i).toBeDeleted()) { saorderdetailset.getPao(i).setValue("frownum", rownum++); } i++; } saorderSet.save(); } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } /** * 更新打包促销订单 * * @param content * @return * @throws JSONException * @throws P2Exception */ public String updatesaorder_packprom(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单ID String saorderid = content.getString("saorderid"); // 订单号 String fsonum = content.getString("fsonum"); // 经销商编号 String fagentnum = content.getString("fagentnum"); //打包数量 String fpromqty = content.getString("fpromqty"); // 单据日期 String fdate = nullToStr(content.getString("fdate")); if (fdate.length() > 10) { fdate = fdate.substring(0, 10); } // 扣款帐户 String faccclsnum = nullToStr(content.getString("faccclsnum")); // 联系方式 String fphonenumber = nullToStr(content.getString("fphonenumber")); // 收货人 String fcontact = nullToStr(content.getString("fcontact")); // 省 String fprovince = nullToStr(content.getString("fprovince")); // 市 String fcity = nullToStr(content.getString("fcity")); // 县 String fcounty = nullToStr(content.getString("fcounty")); // 收货地址 String faddress = nullToStr(content.getString("faddress")); // 开票单位 String finvoicename = nullToStr(content.getString("finvoicename")); // 税号 String finvoicetaxnumber = nullToStr(content.getString("finvoicetaxnumber")); // 开票地址 String finvoiceaddress = nullToStr(content.getString("finvoiceaddress")); // 备注 String fnotes = nullToStr(content.getString("fnotes")); String fpayagentnum = ""; if (content.containsKey("fpayagentnum")) { fpayagentnum = nullToStr(content.getString("fpayagentnum"));//结算客户 } if ("".equals(fpayagentnum)) { fpayagentnum = fagentnum; } String frecagentnum = ""; if (content.containsKey("frecagentnum")) { frecagentnum = nullToStr(content.getString("frecagentnum"));//收货客户 } if ("".equals(frecagentnum)) { frecagentnum = fagentnum; } saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "' "); if (saorderSet.isEmpty()) { return "订单" + fsonum + "不存在!"; } saorder saorder = (saorder) saorderSet.getPao(0); if (!"新建".equals(saorder.getString("fstatus"))) { return "非新建状态不可修改"; } String ftype = saorder.getString("ftype"); saorderSet.setApp("SAORDER4"); saorder.setValue("fdate", fdate, 11L); saorder.setValue("faccclsnum", faccclsnum, 2L); saorder.setValue("fphonenumber", fphonenumber, 11L); saorder.setValue("fcontact", fcontact, 11L); saorder.setValue("fprovince", fprovince, 11L); saorder.setValue("fcity", fcity, 11L); saorder.setValue("fcounty", fcounty, 11L); saorder.setValue("faddress", faddress, 11L); saorder.setValue("fnotes", fnotes, 11L); saorder.setValue("finvoicename", finvoicename, 11L); saorder.setValue("finvoicetaxnumber", finvoicetaxnumber, 11L); saorder.setValue("finvoiceaddress", finvoiceaddress, 11L); saorder.setValue("fpromqty", fpromqty, 2L); saorder.setValue("fpayagentnum", fpayagentnum, 2L); saorder.setValue("frecagentnum", frecagentnum, 2L); PaoSetRemote saorderdetailset = saorder.getPaoSet("saorderdetail_view"); saorderdetailset.setOrderBy("frownum"); saorderdetailset.reset(); HashMap saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid"); JSONArray detailArray = content.getJSONArray("saorderdetail"); Iterator it = detailArray.iterator(); while (it.hasNext()) { JSONObject detailObject = it.next(); String saorderdetailid = detailObject.getString("saorderdetailid"); String fdetailnotes = nullToStr(detailObject.getString("fnotes")); //配送方案 String frationnum = nullToStr(detailObject.getString("frationnum")); String fneeddate = nullToStr(detailObject.getString("fneeddate")); if (fneeddate.length() > 10) { fneeddate = fneeddate.substring(0, 10); } PaoRemote detailPao = null; if (saorderdetailmap.containsKey(saorderdetailid)) { detailPao = saorderdetailmap.get(saorderdetailid); } if (detailPao != null) { detailPao.setValue("frationnum", frationnum, 2L); detailPao.setValue("fnotes", fdetailnotes, 2L); detailPao.setValue("fneeddate", fneeddate, 11L); } } /*** 行号重计算 */ int i = 0; int rownum = 1; while (saorderdetailset.getPao(i) != null) { if (!saorderdetailset.getPao(i).toBeDeleted()) { saorderdetailset.getPao(i).setValue("frownum", rownum++); } i++; } saorderSet.save(); } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } /** * 生成配送件 * * @param content * @return */ public String createration(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单号 String fsonum = content.getString("fsonum"); saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'"); if (!saorderSet.isEmpty()) { saorder saorder = (saorder) saorderSet.getPao(0); saorder.createrationvalidate(); saorder.createration(); saorderSet.save(); } else { return "订单号:" + fsonum + "不存在"; } } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } /** * 清空配送件 * * @param content * @return */ public String deleteration(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单号 String fsonum = content.getString("fsonum"); saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'"); if (!saorderSet.isEmpty()) { saorder saorder = (saorder) saorderSet.getPao(0); saorder.deleterationvalidate(); saorder.deleteration(); saorderSet.save(); } else { return "订单号:" + fsonum + "不存在"; } } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } public String deletesaorder(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单号 String fsonum = content.getString("fsonum"); // 经销商 //String fagentnum = content.getString("fagentnum"); saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'"); if (!saorderSet.isEmpty()) { saorder saorder = (saorder) saorderSet.getPao(0); saorder.delete(0L); saorderSet.save(); } else { return "订单号:" + fsonum + "不存在"; } } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } public String submitsaorder(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单号 String fsonum = content.getString("fsonum"); // 经销商 String fagentnum = content.getString("fagentnum"); saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'"); if (!saorderSet.isEmpty()) { saorder saorder = (saorder) saorderSet.getPao(0); if ("标准订单".equals(saorder.getString("ftype"))) { saorderSet.setApp("SAORDER1"); } HashMap map = saorder.checkitemprice(); if (!map.isEmpty()) { StringBuffer msg = new StringBuffer(); for (String fitemno : map.keySet()) { msg.append("商品编号" + fitemno + "销售价格已由" + map.get(fitemno)[0] + "调整为" + map.get(fitemno)[1] + ";"); } return msg.toString(); } saorder.ordercaculate(saorder.getPaoSet("saorderdetail_view")); saorder.submitvalidate(true); saorder.submit(true); saorderSet.save(); } else { return "订单号:" + fsonum + "不存在"; } } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } public String updateitemprice(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单号 String fsonum = content.getString("fsonum"); // 经销商 String fagentnum = content.getString("fagentnum"); saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'"); if (!saorderSet.isEmpty()) { saorder saorder = (saorder) saorderSet.getPao(0); saorder.updateitemprice(); saorderSet.save(); } else { return "订单号:" + fsonum + "不存在"; } } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } public String needdateconfirm(JSONObject content, String hrid) throws Exception { PaoSetRemote saorderSet = null; try { // 订单号 String fsonum = content.getString("fsonum"); // 经销商 String fagentnum = content.getString("fagentnum"); saorderSet = getP2ServerPaoSet("saorder", hrid, "fsonum='" + fsonum + "'"); if (!saorderSet.isEmpty()) { saorder saorder = (saorder) saorderSet.getPao(0); saorder.needdateconfirmvalidate(true); saorder.needdateconfirm(true); saorderSet.save(); } else { return "订单号:" + fsonum + "不存在"; } } finally { if (saorderSet != null) { saorderSet.close(); } } return "true"; } }