| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047 |
- 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<String> sqllist = new ArrayList<>();
- Iterator<JSONObject> 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<String, PaoRemote> paomap = getPaoMap(tpromproductsSet, "fitemno");
- Iterator<JSONObject> 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<String, PaoRemote> saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid");
- /**
- * 用以判断是否需要将表体行删除
- */
- ArrayList<String> donotdeleteid = new ArrayList<>();
- JSONArray detailArray = content.getJSONArray("saorderdetail");
- Iterator<JSONObject> 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<JSONObject> 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<String, PaoRemote> saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid");
- /**
- * 用以判断是否需要将表体行删除
- */
- ArrayList<String> donotdeleteid = new ArrayList<>();
- JSONArray detailArray = content.getJSONArray("saorderdetail");
- Iterator<JSONObject> 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<String, PaoRemote> saorderdetailmap = getPaoMap(saorderdetailset, "saorderdetailid");
- JSONArray detailArray = content.getJSONArray("saorderdetail");
- Iterator<JSONObject> 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<String, Double[]> 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";
- }
- }
|