package saorder; import baseclass.tools.GetFieldsName; import baseclass.tools.Math; import ficashbill.ficashbill; import icstockbill.icstockbill; import openapi.base.SQLFactory; import openapi.base.data.Row; import openapi.base.data.Rows; import openapi.base.data.db.DBConnect; import p2.pao.PaoRemote; import p2.pao.PaoSet; import p2.pao.PaoSetRemote; import p2.util.P2AppException; import p2.util.P2Exception; import sainvoice.sainvoice; import saorder.base.BaseSaorder; import saorderdetail.saorderdetail; import taccbal.taccbal; import titem.titem; import twriteoffbill.twriteoffbill_orderchange; import java.util.*; public class saorder extends BaseSaorder { public saorder(PaoSet arg0) { super(arg0); } @Override public void init() throws P2Exception { super.init(); try { if (!toBeAdded() && getThisPaoSet().getApp() != null) { if (!"新建".equals(getString("fstatus"))) { setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true); setFieldFlag(new String[]{"closereason"}, READONLY, false); if ("提交".equals(getString("fstatus"))) { setFieldFlag("freturnmsg", READONLY, false); setFieldFlag("fprojectnotes", READONLY, false); setFieldFlag("fsaletype", READONLY, false); setFieldFlag("fnotes", READONLY, false); setFieldFlag("freviewtype", READONLY, false); } if ("审核".equals(getString("fstatus"))) { setFieldFlag("fnotes", READONLY, false); } } else { if ("促销订单".equals(getString("ftype"))) { //新建状态下促销类型为打包促销且没有生成配送方案的前提下,打包数量可编辑,否则为只读 if ("打包促销".equals(getString("tpromotions.ftype")) && getPaoSet("saorderdetail_view2").isEmpty()) { setFieldFlag("fpromqty", READONLY, false); setFieldFlag("fpromqty", REQUIRED, true); } else { setFieldFlag("fpromqty", READONLY, true); setFieldFlag("fpromqty", REQUIRED, false); } } if ("02".equals(getString("faccclsnum"))) { setFieldFlag("fisusefl", READONLY, true); } if ("特殊订单".equals(getString("ftype"))) { setFieldFlag("ftypemx", READONLY, false); } else { setFieldFlag("ftypemx", READONLY, true); } if (!getPaoSet("saorderdetail_view").isEmpty()) { setFieldFlag(new String[]{"ftypemx", "fagentnum", "ftype", "fpromnum", "faccclsnum", "fprojectnum", "fbrand", "fborrowtype"}, READONLY, true); } } } } catch (Exception e) { e.printStackTrace(); } } @Override public void canDelete() throws P2Exception { super.canDelete(); if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "非新建状态下不可删除"); } if (getInt("fsourceid") > 0 && getOwner() == null) { throw new P2AppException("", "该订单由其他单据生成,不可删除"); } } public boolean tobedelete = false; @Override public void delete(long l) throws P2Exception { canDelete(); tobedelete = true; setValue("fstatus", "删除", 11L); setValue("description", "删除信息:" + getUserName() + "," + getDateTime_Str(), 11L); } @Override public void add() throws P2Exception { super.add(); setValue("fsonum", createSoNum(), 11L); try { String app = getThisPaoSet().getApp(); if ("SAORDER1".equalsIgnoreCase(app)) { setValue("ftype", "标准订单", 11L); } if ("SAORDER0".equalsIgnoreCase(app)) { setValue("ftype", "特殊订单", 11L); } if ("SAORDER01".equalsIgnoreCase(app)) { setValue("ftype", "工具订单", 11L); } if ("SAORDER02".equalsIgnoreCase(app)) { setValue("ftype", "项目订单", 11L); } if ("SAORDER2".equalsIgnoreCase(app)) { setValue("ftype", "特殊订单", 11L); } if ("SAORDER4".equalsIgnoreCase(app)) { setValue("ftype", "促销订单", 11L); } if ("SAORDER5".equalsIgnoreCase(app)) { setValue("ftype", "定制订单", 11L); } if ("SAORDER6".equalsIgnoreCase(app)) { setValue("ftype", "工具订单", 11L); } if ("SAORDER7".equalsIgnoreCase(app)) { setValue("ftype", "工具借出单", 11L); setValue("faccclsnum", "05", 11L); } if ("SAORDER8".equalsIgnoreCase(app)) { setValue("ftype", "工具借出单", 11L); setValue("faccclsnum", "05", 11L); } if ("SAORDER9".equalsIgnoreCase(app)) { setValue("ftype", "项目订单", 11L); } if ("SAORDER1".equalsIgnoreCase(app) || "SAORDER4".equalsIgnoreCase(app) || "SAORDER5".equalsIgnoreCase(app) || "SAORDER6".equalsIgnoreCase(app) || "SAORDER7".equalsIgnoreCase(app) || "SAORDER9".equalsIgnoreCase(app)) { String fagentnum = getAgentnumByHrid(getUserName()); if (fagentnum != null) { setValue("fagentnum", fagentnum); } } else { //工厂做的单子 setValue("createflag", true); } } catch (Exception e) { e.printStackTrace(); } } @Override public boolean toBeDeleted() { return super.toBeDeleted(); } @Override protected void save() throws P2Exception { super.save(); if (!toBeDeleted() && !tobedelete) { if ("".equals(getString("fagentnum"))) { throw new P2AppException("", "没有指定经销商"); } if (toBeAdded()) { if ("".equals(getString("fsonum"))) { setValue("fsonum", createSoNum(), 11L); } } PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view"); if ("".equals(getString("fpayagentnum"))) { setValue("fpayagentnum", getString("fagentnum"), 11L); } if ("".equals(getString("frecagentnum"))) { setValue("frecagentnum", getString("fagentnum"), 11L); } if (!toBeAdded() || (toBeAdded() && !saorderdetail_view.isEmpty())) { /** * 满减计算,满赠预计算 */ if ("新建".equals(getString("fstatus"))) { if (!"提交".equals(getPaoField("fstatus").getPreviousValue().asString())) { PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view"); ordercaculate(saorderdetail); /** * 是否免运费计算 */ isFreeFreightCaculate(); } } } } } public void ordercaculate(PaoSetRemote saorderdetail) throws P2Exception { //订单商品总金额 double ftotalamount = saorderdetail.sum("famount"); //满减计算 caculateMJ(saorderdetail); //订单满减后金额 ftotalamount = Math.sub(ftotalamount, saorderdetail.sum("fmjamount")); //开始将折后总金额分摊到商品折后金额中 if (ftotalamount > 0 && !"工具借出单".equals("ftype")) { //订单返利金使用金额 double fuseflamount = caculateUseFLAmount(ftotalamount); double fagentuseflamount = getDouble("fagentuseflamount");//经销商设置的返利金使用金额 if (fuseflamount > 0 && fagentuseflamount > 0 && fagentuseflamount < fuseflamount) { fuseflamount = fagentuseflamount; setValue("fuseflamount", fuseflamount, 11L); setValue("fuseflrate", fuseflamount / ftotalamount, 11L); } else { setValue("fuseflamount", fuseflamount, 11L); } shareCaculate(saorderdetail, ftotalamount, fuseflamount); } //满赠计算 caculateMZ_justcaculate(); } /** * 折后分摊计算 * * @throws P2Exception */ public void shareCaculate(PaoSetRemote saorderdetail, double ftotalamount, double fuseflamount) throws P2Exception { if (fuseflamount >= 0) { double frowflamount = 0; int n = 0; PaoRemote detailpao = null; PaoRemote lastdetailpao = null; while ((detailpao = saorderdetail.getPao(n)) != null) { if (!detailpao.toBeDeleted()) { double fqty = detailpao.getDouble("fqty"); if (fqty != 0) { double fdetailamount = detailpao.getDouble("famount"); double fmjamount = detailpao.getDouble("fmjamount"); double fdetailflamount = Math.mul(Math.div(Math.sub(fdetailamount, fmjamount), ftotalamount), fuseflamount, 2); detailpao.setValue("fflamount", fdetailflamount, 2L); frowflamount = Math.add(frowflamount, fdetailflamount); lastdetailpao = detailpao; } } n++; } /** * 余数计算,满减额度分配过程中如果出现余数,将此数在最后个匹配的行上进行补齐。 */ double yu = Math.sub(frowflamount, fuseflamount); if (yu != 0) { lastdetailpao.setValue("fflamount", Math.sub(lastdetailpao.getDouble("fflamount"), yu), 2L); } } } /** * 从物料档案添加物料 * * @param itemset 物料档案表 * @throws P2Exception */ public void additems(PaoSetRemote itemset) throws P2Exception { Vector v = itemset.getSelection(); if (v.size() > 100) { throw new P2AppException("", "商品添加,不可一次超过100件商品"); } PaoSetRemote SAORDERDETAIL = getPaoSet("saorderdetail_view"); String ftype = getString("ftype"); if ("标准订单".equals(ftype)) { Iterator it = v.iterator(); //开始遍历勾选的物料 while (it.hasNext()) { titem selectpao = (titem) it.next(); if (selectpao.getDouble("fsaleprice") <= 0) { //如果经销商端出现金额小于0 的情况,则直接跳过。 continue; } //添加数量,如果数量为0,则自动变为1 double faddqty = selectpao.getDouble("faddqty"); faddqty = faddqty == 0 ? 1 : faddqty; int i = 0; //isnotalreadyhave判断物料是否不存在 boolean isnotalreadyhave = true; PaoRemote detailpao = null; while ((detailpao = SAORDERDETAIL.getPao(i)) != null) { if (detailpao.getString("fitemno").equals( selectpao.getString("fitemno")) && !detailpao.toBeDeleted()) { //如果匹配上了,则表示物料已存在,将该值设为false isnotalreadyhave = false; double fqty = detailpao.getDouble("fqty"); double fnewqty = fqty + faddqty; detailpao.setValue("fqty", fnewqty); break; } i++; } //如果物料不存在,则新增订单行 if (isnotalreadyhave) { detailpao = SAORDERDETAIL.addAtEnd(); detailpao.setValue("fitemno", selectpao.getString("fitemno")); detailpao.setValue("fqty", selectpao.getDouble("faddqty")); } } } else if ("定制订单".equals(ftype)) { Iterator it = v.iterator(); //开始遍历勾选的物料 while (it.hasNext()) { PaoRemote selectpao = it.next(); if (selectpao.getDouble("fsaleprice") <= 0) { //如果经销商端出现金额小于0 的情况,则直接跳过。 continue; } //添加数量,如果数量为0,则自动变为1 double faddqty = selectpao.getDouble("faddqty"); faddqty = faddqty == 0 ? 1 : faddqty; int i = 0; //isnotalreadyhave判断物料是否不存在 boolean isnotalreadyhave = true; PaoRemote detailpao = null; while ((detailpao = SAORDERDETAIL.getPao(i)) != null) { if (detailpao.getString("fitemno").equals( selectpao.getString("fitemno"))) { //如果匹配上了,则表示物料已存在,将该值设为false isnotalreadyhave = false; double fqty = detailpao.getDouble("fqty"); double fnewqty = fqty + faddqty; detailpao.setValue("fqty", fnewqty); break; } i++; } //如果物料不存在,则新增订单行 if (isnotalreadyhave) { detailpao = SAORDERDETAIL.addAtEnd(); detailpao.setValue("fitemno", selectpao.getString("fitemno")); detailpao.setValue("fqty", selectpao.getDouble("faddqty")); detailpao.setValue("fprice", selectpao.getDouble("fsaleprice")); detailpao.setValue("foldprice", selectpao.getDouble("fsaleprice")); } } } else { String[] fromfields = {"fitemno", "faddqty"}; String[] tofields = {"fitemno", "fqty"}; BatchAdd(itemset, fromfields, SAORDERDETAIL, tofields, true); } this.getThisPaoSet().save(); } /** * 从促销方案添加物料 * * @param itemset 物料档案表 * @throws P2Exception */ public void additems_prom(PaoSetRemote itemset) throws P2Exception { Vector v = itemset.getSelection(); PaoSetRemote SAORDERDETAIL = getPaoSet("saorderdetail_view"); Iterator it = v.iterator(); //开始遍历勾选的物料 while (it.hasNext()) { PaoRemote selectpao = it.next(); if (selectpao.getDouble("fsaleprice") <= 0) { //如果经销商端出现金额小于0 的情况,则直接跳过。 continue; } //添加数量,如果数量为0,则自动变为1 double faddqty = selectpao.getDouble("faddqty"); faddqty = faddqty == 0 ? 1 : faddqty; int i = 0; //isnotalreadyhave判断物料是否不存在 boolean isnotalreadyhave = true; PaoRemote detailpao = null; while ((detailpao = SAORDERDETAIL.getPao(i)) != null) { if (detailpao.getString("fitemno").equals( selectpao.getString("fitemno")) && !detailpao.toBeDeleted()) { //如果匹配上了,则表示物料已存在,将该值设为false isnotalreadyhave = false; double fqty = detailpao.getDouble("fqty"); double fnewqty = 0; if ("打包促销".equals(getString("tpromotions.ftype"))) { fnewqty = faddqty; } else { fnewqty = fqty + faddqty; } detailpao.setValue("fqty", fnewqty, 2L); break; } i++; } //如果物料不存在,则新增订单行 if (isnotalreadyhave) { detailpao = SAORDERDETAIL.addAtEnd(); detailpao.setValue("fitemno", selectpao.getString("fitemno")); detailpao.setValue("fqty", selectpao.getDouble("faddqty"), 2L); detailpao.setValue("fprice", selectpao.getDouble("fsaleprice")); detailpao.setValue("foldprice", selectpao.getDouble("foldsaleprice")); } } } /** * 从促销方案添加物料 * * @param selectpao 物料档案表 * @throws P2Exception */ public PaoRemote additems_prom(PaoRemote selectpao) throws P2Exception { PaoSetRemote SAORDERDETAIL = getPaoSet("saorderdetail_view"); //开始遍历勾选的物料 if (selectpao.getDouble("fsaleprice") <= 0) { //如果经销商端出现金额小于0 的情况,则直接跳过。 return null; } //添加数量,如果数量为0,则自动变为1 double faddqty = selectpao.getDouble("faddqty"); faddqty = faddqty == 0 ? 1 : faddqty; int i = 0; //isnotalreadyhave判断物料是否不存在 boolean isnotalreadyhave = true; PaoRemote detailpao = null; while ((detailpao = SAORDERDETAIL.getPao(i)) != null) { if (detailpao.getString("fitemno").equals( selectpao.getString("fitemno")) && !detailpao.toBeDeleted()) { //如果匹配上了,则表示物料已存在,将该值设为false isnotalreadyhave = false; double fqty = detailpao.getDouble("fqty"); double fnewqty = 0; if ("打包促销".equals(getString("tpromotions.ftype"))) { fnewqty = faddqty; } else { fnewqty = fqty + faddqty; } detailpao.setValue("fqty", fnewqty, 2L); break; } i++; } //如果物料不存在,则新增订单行 if (isnotalreadyhave) { detailpao = SAORDERDETAIL.addAtEnd(); detailpao.setValue("fitemno", selectpao.getString("fitemno")); detailpao.setValue("fqty", selectpao.getDouble("faddqty"), 2L); detailpao.setValue("fprice", selectpao.getDouble("fsaleprice")); detailpao.setValue("foldprice", selectpao.getDouble("foldsaleprice")); } return detailpao; } // @Override // public void confirmvalidate(boolean isconfirm) throws P2Exception { // // super.confirmvalidate(isconfirm); // //订单表体,所有 // PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); // //订单表体,除配送件外 // PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view"); // //订单提交验证 // if (isconfirm) { // if (!"新建".equals(getString("fstatus"))) { // throw new P2AppException("", "新建状态才可进行订单确认"); // } // //经销商下单不允许出现金额为0的订单,配送件除外 // if (getPaoSet("saorderdetail_view").min("fprice") < 0) { // throw new P2AppException("", "商品单价小于0,请删除该商品后重新添加"); // } // if (saorderdetail.isEmpty()) { // throw new P2AppException("", "订单明细为空不可提交"); // } // //非赠品商品数量不可等于0 // if (saorderdetail_view.min("fqty") <= 0) { // throw new P2AppException("", "商品数量不可小于等于0"); // } // // //配送方案是否生成验证 // StringBuffer sql = new StringBuffer(""); // sql.append("select t2.frownum,t2.fitemno from saorder t1 "); // sql.append("inner join saorderdetail t2 on t1.saorderid=t2.fparentid "); // sql.append("inner join titem t3 on t2.fitemno=t3.fitemno "); // sql.append("inner join titem_ration t4 on t3.fitemno=t4.fitemno "); // sql.append("inner join tration t5 on t4.frationnum=t5.frationnum "); // sql.append("where t1.fsonum='" + getString("fsonum") + "' and t2.fisration=0 and t3.fisrationmag=1 "); // sql.append("and t5.fstatus='审核' "); // sql.append("and (t5.fagentauthors=1 or exists(select *from tagents_ration where frationnum=t5.frationnum and fagentnum=t1.fagentnum))"); // if ("标准订单".equals(getString("ftype"))) { // sql.append("and t5.fordertype1=1 "); // } else if ("特殊订单".equals(getString("ftype"))) { // sql.append("and t5.fordertype2=1 "); // } else if ("促销订单".equals(getString("ftype"))) { // sql.append("and t5.fordertype3=1 "); // } else if ("定制订单".equals(getString("ftype"))) { // sql.append("and t5.fordertype4=1 "); // } else { // sql.append("and 1=2"); // } // ArrayList> list = runQuerySQL(sql.toString()); // if (!list.isEmpty() && getPaoSet("saorderdetail_view2").isEmpty()) { // int frownum = (int) list.get(0).get("frownum"); // String fitemno = (String) list.get(0).get("fitemno"); // throw new P2AppException("", "行" + frownum + "商品编号:" + fitemno + "存在配送方案,请选择配送方案后生成生成配送明细"); // } // } else { // //订单退回验证 // if (!"确认".equals(getString("fstatus"))) { // throw new P2AppException("", "非确认状态下不可退回"); // } // } // // } // @Override // public void confirm(boolean isconfirm) throws P2Exception { // // super.confirm(isconfirm); // // if (isconfirm) { // /*单据状态变更*/ // setValue("fstatus", "确认", 11L); // setValue("confirmby", getUserName(), 11L); // setValue("confirmdate", getDateTime(), 11L); // // // //微信消息推送 // StringBuffer fcontent = new StringBuffer(); // fcontent.append("您好,您有订单号为:").append(getString("fsonum")).append("的特殊订单,订单总金额:").append( // getDouble("saorder_totalview.famount")).append("请前往系统订单应用进行提交操作"); // sendWechatMsg(getQyWechat(), fcontent.toString(), this); // // // } else { // /*单据状态变更*/ // setValue("fstatus", "新建", 11L); // setValue("confirmby", "", 11L); // setValue("confirmdate", "", 11L); // // // /*退回微信消息推送*/ // String fcontent = "尊敬的" + getString("fagentshortname") // + "经销商,您提交的订单号为" + getString("fsonum") // + "的特殊订单已被撤回。"; // sendWechatMsg(getQyWechat(), fcontent, this); // } // // } /** * 检查商品价格是否变动 */ public HashMap checkitemprice() throws P2Exception { HashMap map = new HashMap<>(); if (!"欠款发货".equals(getString("fborrowtype")) && !"特殊订单".equals(getString("ftype"))) { //订单表体,所有 PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); int i = 0; while (saorderdetail.getPao(i) != null) { double order_foldprice = saorderdetail.getPao(i).getDouble("foldprice"); double order_fsaleprice = saorderdetail.getPao(i).getDouble("fprice"); PaoSetRemote titemset = saorderdetail.getPao(i).getPaoSet("titem"); if (!titemset.isEmpty()) { titem titem = (titem) titemset.getPao(0); if (!saorderdetail.getPao(i).getBoolean("fpricechanged")) { //如果价格没有更改过,则进行价格判断 double fsaleprice = titem.getAgentSalePrice(getString("fagentnum")); if (order_fsaleprice != fsaleprice) { map.put(titem.getString("fitemno"), new Double[]{order_fsaleprice, fsaleprice}); } } if (!map.containsKey(titem.getString("fitemno"))) { /** * 销售价 */ double fprice = titem.getCardPriceByAagentnum(getString("fagentnum")); if (order_foldprice != fprice) { map.put(titem.getString("fitemno"), new Double[]{order_foldprice, fprice}); } } } i++; } } return map; } /** * 更新商品价格 */ public void updateitemprice() throws P2Exception { HashMap map = new HashMap<>(); //订单表体,所有 PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view"); int i = 0; while (saorderdetail.getPao(i) != null) { PaoSetRemote titemset = saorderdetail.getPao(i).getPaoSet("titem"); if (!titemset.isEmpty()) { titem titem = (titem) titemset.getPao(0); /** * 牌价 */ double foldprice = titem.getCardPriceByAagentnum(getString("fagentnum")); /** * 销售价 */ double fprice = titem.getAgentSalePrice(getString("fagentnum")); saorderdetail.getPao(i).setValue("fprice", fprice); saorderdetail.getPao(i).setValue("frateprice", fprice); saorderdetail.getPao(i).setValue("foldprice", foldprice, 11L); } i++; } } /** * 提交验证 * * @param issubmit 是否提交 true表示提交,false表示退回 * @throws P2Exception */ @Override public void submitvalidate(boolean issubmit) throws P2Exception { super.submitvalidate(issubmit); if ("".equals(getString("fsignbacknum"))) { if ("工具订单".equals(getString("ftype")) || "标准订单".equals(getString("ftype")) || "项目订单".equals(getString("ftype"))) { if(getSite().equals("HY")) { throw new P2AppException("", "回签单信息不可为空!"); } } } if ("工具借出单".equals(getString("ftype"))) { submitvalidate_tools(issubmit); return; } //订单表体,所有 PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); //订单表体,除配送件外 PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view"); //订单提交验证 if (issubmit) { if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "新建状态才可进行提交!"); } { if ("".equals(getString("fphonenumber"))) { throw new P2AppException("", "联系方式不能为空"); } if ("".equals(getString("fcontact"))) { throw new P2AppException("", "收货人不能为空"); } if ("".equals(getString("faddress"))) { throw new P2AppException("", "收货地址不能为空"); } if ("".equals(getString("finvoicename"))) { throw new P2AppException("", "开票单位不能为空"); } if ("".equals(getString("finvoicetaxnumber"))) { throw new P2AppException("", "税号不能为空"); } if ("".equals(getString("finvoiceaddress"))) { throw new P2AppException("", "开票地址不能为空"); } if (saorderdetail_view.sum("fflamount") != getDouble("fuseflamount")) { throw new P2AppException("", "返利分摊金额计算错误!"); } if (Math.sub(saorderdetail_view.sum("famount"), Math.add(saorderdetail_view.sum("fflamount"), saorderdetail_view.sum("fmjamount"))) != saorderdetail_view.sum("frateamount")) { throw new P2AppException("", "折后金额计算错误!"); } } if (saorderdetail.isEmpty()) { throw new P2AppException("", "请至少添加一个商品"); } //非赠品商品数量不可等于0 if (saorderdetail_view.min("fqty") <= 0) { throw new P2AppException("", "商品数量不可小于等于0"); } if ("标准订单".equals(getString("ftype")) && isLimitOrder()) { throw new P2AppException("", "您已被禁止订货"); } if ("促销订单".equals(getString("ftype")) && isLimitOrder()) { throw new P2AppException("", "您已被禁止订货"); } if ("项目订单".equals(getString("ftype"))) { if (getPaoSet("TPROJECT").isEmpty()) { throw new P2AppException("", "项目编号无效"); } if (!"审核".equals(getPaoSet("TPROJECT").getPao(0).getString("fstatus"))) { throw new P2AppException("", "项目不在审核状态不可提交"); } } //经销商下单不允许出现金额为0的订单,配送件除外 if ("标准订单".equals(getString("ftype")) && !getBoolean("createflag") && getPaoSet("saorderdetail_view").min("fprice") <= 0) { throw new P2AppException("", "商品单价小于等于0,请删除该商品后重新添加"); } //fissaleday int i = 0; while (saorderdetail.getPao(i) != null) { if (saorderdetail.getPao(i).getPaoSet("titem").getPao(0).getBoolean("fissaleday")) { if (saorderdetail.getPao(i).getString("fneeddate").equals("")) { throw new P2AppException("", "商品" + saorderdetail.getPao(i).getString("fitemname") + "交期管控,请填写交期"); } } if ("样品".equals(getString("ftypemx"))) { if ("".equals(saorderdetail.getPao(i).getString("warehouse"))) { throw new P2AppException("", "样品订单需指定商品出库仓库"); } } i++; } if ("促销订单".equals(getString("ftype"))) { PaoRemote tpromotion = getPaoSet("tpromotions").getPao(0); //活动结束日期 Date fenddate = tpromotion.getDate("fenddate"); //活动状态 String fstatus = tpromotion.getString("fstatus"); //活动起订量 double fsaleminqty = tpromotion.getDouble("fsaleminqty"); //活动起订金额 double fsaleminamount = tpromotion.getDouble("fsaleminamount"); if (fenddate.before(getDateTime())) { throw new P2AppException("", "促销活动已失效"); } if (!"发布".equals(fstatus)) { throw new P2AppException("", "促销活动不在发布状态"); } if ("打包促销".equals(getString("tpromotions.ftype")) && getDouble("fpromqty") <= 0) { throw new P2AppException("", "打包促销数量不可小于等于0"); } if (saorderdetail_view.sum("fqty") < fsaleminqty) { throw new P2AppException("", "促销活动设置了起订量" + fsaleminqty + ",当前订单总数量不满足活动起订量"); } if (saorderdetail_view.sum("famount") < fsaleminamount) { throw new P2AppException("", "促销活动设置了起订金额" + fsaleminamount + ",当前订单金额不满足活动起订金额"); } //限量订购商品检验 ArrayList> list = runQuerySQL("select t1.fitemno,t1.fqty,t2.fsurplusqty from saorderdetail t1 inner join tpromproducts t2 on t1.fpromnum=t2.fpromnum and t1.fitemno=t2.fitemno where t2.fislimit=1 and t2.fsurplusqty Math.sub(flimitvalue, flimitvalue1)) { throw new P2AppException("", "您的订单总金额" + ftotalamount + "已超过剩余可订购金额" + Math.sub(flimitvalue, flimitvalue1)); } } } } /*判断提交时是否需要进行扣款或账户冻结。如果需要则需进行账户可用余额的验证*/ String fupdatebaltime = getSysVars().getString("fupdatebaltime"); String fupdatfreeztime = getSysVars().getString("fupdatfreeztime"); if ("订单提交".equals(fupdatebaltime) || "订单提交".equals(fupdatfreeztime)) { // 订单折后总额 double frateamount = saorderdetail_view.sum("frateamount"); //由于返利金使用额度是提交时临时计算,故不需要专门验证返利金的账户余额 PaoSetRemote taccbal_view = getPaoSet("taccbal_view"); //账户可用余额 double fcanuseamount = taccbal_view.getPao(0).getDouble("fcanuseamount"); //如果可用余额小于当前订单金额,则提示账户余额不足 if (fcanuseamount < frateamount) { throw new P2AppException("", "账户可用余额不足"); } } boolean haveRation = false; //配送方案是否生成验证 StringBuffer sql = new StringBuffer(); sql.append("select t2.frownum,t2.fitemno from saorder t1 "); sql.append("inner join saorderdetail t2 on t1.saorderid=t2.fparentid "); sql.append("inner join titem t3 on t2.fitemno=t3.fitemno and t2.siteid=t3.siteid "); sql.append("inner join titem_ration t4 on t3.fitemno=t4.fitemno and t2.siteid and t4.siteid "); sql.append("inner join tration t5 on t4.frationnum=t5.frationnum and t4.siteid=t5.siteid "); sql.append("where t1.fsonum='" + getString("fsonum") + "' and t1.siteid='" + getString("siteid") + "' and t2.fisration=0 and t3.fisrationmag=1 "); sql.append("and t5.fstatus='审核' "); sql.append("and (t5.fagentauthors=1 or exists(select *from tagents_ration where frationnum=t5.frationnum and fagentnum=t1.fagentnum)) "); if ("标准订单".equals(getString("ftype"))) { sql.append("and t5.fordertype1=1 "); } else if ("特殊订单".equals(getString("ftype"))) { sql.append("and t5.fordertype2=1 "); } else if ("促销订单".equals(getString("ftype"))) { sql.append("and t5.fordertype3=1 "); } else if ("定制订单".equals(getString("ftype"))) { sql.append("and t5.fordertype4=1 "); } else { sql.append("and 1=2 "); } ArrayList> list = runQuerySQL(sql.toString()); if (!list.isEmpty() && getPaoSet("saorderdetail_view2").isEmpty()) { int frownum = (int) list.get(0).get("frownum"); String fitemno = (String) list.get(0).get("fitemno"); throw new P2AppException("", "行" + frownum + "商品编号:" + fitemno + "存在配送方案,请选择配送方案后生成生成配送明细"); } if (!getBoolean("createflag")) { //商品下架验证 StringBuffer sql2 = new StringBuffer(); sql2.append("select t2.frownum,t2.fitemno from saorder t1 "); sql2.append("inner join saorderdetail t2 on t1.saorderid=t2.fparentid "); sql2.append("inner join titem t3 on t2.fitemno=t3.fitemno and t2.siteid=t3.siteid "); sql2.append("where t1.fsonum='" + getString("fsonum") + "' and t1.siteid='" + getString("siteid") + "' and t3.fisonsale=0 and t1.ftype !='特殊订单'"); ArrayList> list2 = runQuerySQL(sql2.toString()); if (!list2.isEmpty()) { int frownum = (int) list2.get(0).get("frownum"); String fitemno = (String) list2.get(0).get("fitemno"); throw new P2AppException("", "行" + frownum + "商品编号:" + fitemno + "已下架!"); } } } else { //订单退回验证 if (!"提交".equals(getString("fstatus"))) { throw new P2AppException("", "非提交状态下不可退回"); } if ("SAORDER0".equalsIgnoreCase(getThisPaoSet().getApp()) && "".equals(getString("freturnmsg"))) { throw new P2AppException("", "退回原因不可为空"); } } } /** * 提交验证 * * @param issubmit 是否提交 true表示提交,false表示退回 * @throws P2Exception */ private void submitvalidate_tools(boolean issubmit) throws P2Exception { super.submitvalidate(issubmit); //订单表体,所有 PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); //订单表体,除配送件外 PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view"); //订单提交验证 if (issubmit) { if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "新建状态才可进行提交!"); } { if ("".equals(getString("fphonenumber"))) { throw new P2AppException("", "联系方式不能为空"); } if ("".equals(getString("fcontact"))) { throw new P2AppException("", "收货人不能为空"); } if ("".equals(getString("faddress"))) { throw new P2AppException("", "收货地址不能为空"); } } if (saorderdetail.isEmpty()) { throw new P2AppException("", "请至少添加一个商品"); } //非赠品商品数量不可等于0 if (saorderdetail_view.min("fqty") <= 0) { throw new P2AppException("", "商品数量不可小于等于0"); } if (isLimitOrder()) { throw new P2AppException("", "您已被禁止订货"); } } else { //订单退回验证 if (!"提交".equals(getString("fstatus"))) { throw new P2AppException("", "非提交状态下不可退回"); } if ("SAORDER0".equalsIgnoreCase(getThisPaoSet().getApp()) && "".equals(getString("freturnmsg"))) { throw new P2AppException("", "退回原因不可为空"); } } } public void changesalervalidate() throws P2Exception { } public void changesaler() throws P2Exception { setFieldFlag("fsaler", READONLY, false); } /** * 提交 * * @param issubmit * @throws P2Exception */ @Override public void submit(boolean issubmit) throws P2Exception { super.submit(issubmit); if ("工具借出单".equals(getString("ftype"))) { submit_tools(issubmit); return; } /** * 订单指定账户 */ taccbal taccbal = null; PaoSetRemote taccbalSet = getPaoSet("taccbal"); if (taccbalSet.isEmpty()) { taccbal = (taccbal) taccbalSet.addAtEnd(); taccbal.setfields(getString("fpayagentnum"), getString("faccclsnum")); } else { taccbal = (taccbal) taccbalSet.getPao(0); } /** * 订单指定账户 */ taccbal taccbal_fl = null; PaoSetRemote taccbalSet_fl = getPaoSet("taccbal_fl"); if (taccbalSet_fl.isEmpty()) { taccbal_fl = (taccbal) taccbalSet_fl.addAtEnd(); taccbal_fl.setfields(getString("fpayagentnum"), "02"); } else { taccbal_fl = (taccbal) taccbalSet_fl.getPao(0); } //系统参数表 PaoRemote sysVars = getSysVars(); /*获取系统参数*/ //总仓库存可销售量扣减时机, String fupdateavlqtytime = sysVars.getString("fupdateavlqtytime"); //订单扣款时机:订单提交、订单审核、销售出库单审核 String fupdatebaltime = sysVars.getString("fupdatebaltime"); //冻结金额时机:订单提交、订单审核 String fupdatfreeztime = sysVars.getString("fupdatfreeztime"); //订单提交自动审核的单据类型 String forderautochecktype = getSysVars().getString("forderautochecktype"); // 经销商参数是否需要提交自动审核 boolean fsaorderautocheck = getPaoSet("tagents").getPao(0).getBoolean("fsaorderautocheck"); //订单表体,包括辅材 PaoSetRemote saorderdetailSet = getPaoSet("saorderdetail_view"); // 订单指定账户扣款总额 double ftotalrateamount = saorderdetailSet.sum("frateamount"); // 订单使用返利总金额 double fuseflamount = saorderdetailSet.sum("fflamount"); //提交 if (issubmit) { if ("促销订单".equals(getString("ftype"))) { updatePromotion(true); } if ("订单提交".equals(fupdatebaltime)) { /*如果系统参数设为为提交时扣款,则提交时需要生成支出凭证*/ /*生成支出凭证*/ String fnotes = "该单由销售订单" + getString("fsonum") + "提交时自动生成"; /** * 生成返利支出凭证,如果返利金额为0,则不生成 */ createFicashbill_fl_Pay(taccbal_fl, fuseflamount, fnotes); /** * 生成账户支出凭证 */ createFicashbill_Pay(taccbal, ftotalrateamount, fnotes, true); } else if ("订单提交".equals(fupdatfreeztime)) { /*如果系统参数设为为提交时冻结金额,则提交时需要进行账户金额冻结*/ /*账户余额冻结*/ String fnotes = "由销售订单" + getString("fsonum") + "提交时冻结"; updateTaccbal_freez(taccbal, ftotalrateamount, fnotes); } //总仓库存可销售量扣减 if ("订单提交".equals(fupdateavlqtytime)) { //updateIcinvbal_total(false, false); } boolean isrowerr = getDistinctString(saorderdetailSet, "frownum", false).length != saorderdetailSet.count(); //遍历订单表体 int i = 0; saorderdetail detailpao = null; while ((detailpao = (saorderdetail) saorderdetailSet.getPao(i)) != null) { if (isrowerr) { detailpao.setValue("frownum", i + 1, 11L); } //重新计算产品的未发货数量 detailpao.setValue("fundeliqty", detailpao.getDouble("fqty"), 11L); //如果是定制订单,则根据定制项生成定制信息 if ("定制订单".equals(getString("ftype"))) { StringBuffer fcustomizedstr = new StringBuffer(); PaoSetRemote saorder_customizedSet = detailpao.getPaoSet("saorder_customized"); saorder_customizedSet.setOrderBy("SAORDER_CUSTOMIZID"); int n = 0; PaoRemote saorder_customized = null; while ((saorder_customized = saorder_customizedSet.getPao(n)) != null) { fcustomizedstr.append(saorder_customized.getString("fname")).append(":").append(saorder_customized.getString("fvalue")).append(";"); n++; } detailpao.setValue("fcustomizedstr", "{" + fcustomizedstr.toString() + "}", 11L); } i++; } /*单据状态变更*/ setValue("fstatus", "提交", 11L); setValue("submitby", getUserName(), 11L); setValue("submitdate", getDateTime(), 11L); setValue("submitcount", getInt("submitcount") + 1, 11L); // 判断提交是否自动审核 if (fsaorderautocheck && forderautochecktype.contains(getString("ftype"))) { boolean canCheck = true; if ("订单审核".equals(fupdatebaltime) || "订单审核".equals(fupdatfreeztime)) { // 如果系统参数设置订单审核扣款时,此时账户尚未进行扣款或冻结, // 审核前需验证账户余额是否充足,如账户余额不足,则不允许自动审核。 // 通过经销商账户余额查询视图获取账户可用余额 double fcanuseamount = getPaoSet("taccbal_view").getPao(0).getDouble("fcanuseamount"); if (fcanuseamount < ftotalrateamount) { //如果账户可用余额小于当前订单金额,则不允许自动审核。 canCheck = false; } } //如果已在订单提交时金扣款或冻结,或者账户余额充足,则当前订单自动审核 if (canCheck) { check(true); } } //微信消息推送 StringBuffer fcontent = new StringBuffer(); fcontent.append("您好,您的订单号为:").append(getString("fsonum")).append("的").append( getString("ftype")).append("已提交,订单总金额:").append( getDouble("saorder_totalview.famount")); sendWechatMsg(getQyWechat(), fcontent.toString(), this); /** * 如果是交期管控的,且库存不足的,则进行邮件提醒 */ if (issaleday() && !checkStockStatus()) { //交期回复提醒 sendEmail(getMailByHrGroup(getString("siteid") + "1005"), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交,需要进行交期回复", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待交期回复;订单号:" + getString("fsonum")); } //销管订单提交待审核邮件提醒 sendEmail(getMailByHrGroup(getString("siteid") + "1001"), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待审", "【订单领域】" + getString("fieldname") + ",【订单提交待审核】订单号:" + getString("fsonum") + "(订单客户:" + getString("FAGENTSHORTNAME") + ",备注:" + ("".equals(getString("fnotes")) ? "无" : getString("fnotes")) + ")已提交请审核;"); //任务箱提醒 createAssignment(getHrIdByHrGroup(getString("siteid") + "1001"), "SAORDER0", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待审", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待审;订单号:" + getString("fsonum")); } else { deleteAssignment(); if ("促销订单".equals(getString("ftype"))) { updatePromotion(false); } /*退回操作*/ /*资金账户计算*/ if ("订单提交".equals(fupdatebaltime)) { /*如果系统参数设为为提交时扣款,则退回时需要生成负数的支出凭证*/ /*生成支出凭证*/ String fnotes = "该单由销售订单" + getString("fsonum") + "退回时自动生成"; //PaoSetRemote ficashbillset = getPaoSet("$ficashbill_fl", "ficashbill", "ftypemx='返利金' and ftype='支出' and fstatus='审核' and fsourceobject='SAORDER' and fsourceid=" + getUniqueIDValue()); //返利不退 //createFicashbill_fl_Pay(taccbal_fl, -famount_fl, fnotes); //createFicashbill_Pay(taccbal, -(Math.sub(ftotalamount, fuseflamount)), fnotes, true); createFicashbill_fl_Pay(taccbal_fl, -fuseflamount, fnotes); createFicashbill_Pay(taccbal, -ftotalrateamount, fnotes, true); } else if ("订单提交".equals(fupdatfreeztime)) { /*如果系统参数设为为提交时冻结账户余额,则退回时需要进行账户余额的解冻*/ deleteTaccbal_freez(); } /*库存计算*/ //总仓库存可销售量扣减 if ("订单提交".equals(fupdateavlqtytime)) { //如果系统参数设为提交时进行可销售数量的扣减,则退回时需要将订单数量返回到库存的可销售数量中。 //updateIcinvbal_total(true, false); } /*单据状态变更*/ setValue("fstatus", "新建", 11L); setValue("submitby", "", 11L); setValue("submitdate", "", 11L); setValue("fnotes", getString("fnotes") + "----订单退回", 11L); /*退回微信消息推送*/ String fcontent = "尊敬的" + getString("fagentshortname") + "经销商,您提交的订单号为" + getString("fsonum") + "的订单审核不通过,请登录系统查询。"; sendWechatMsg(getQyWechat(), fcontent, this); } } /** * 工具借出申请单提交 * * @param issubmit * @throws P2Exception */ private void submit_tools(boolean issubmit) throws P2Exception { super.submit(issubmit); if (issubmit) { /*单据状态变更*/ setValue("fstatus", "提交", 11L); setValue("submitby", getUserName(), 11L); setValue("submitdate", getDateTime(), 11L); setValue("submitcount", getInt("submitcount") + 1, 11L); /** * 如果是交期管控的,且库存不足的,则进行邮件提醒 */ if (issaleday() && !checkStockStatus()) { //交期回复提醒 sendEmail(getMailByHrGroup(getString("siteid") + "1005"), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交,需要进行交期回复", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待交期回复;订单号:" + getString("fsonum")); } //销管订单提交待审核邮件提醒 sendEmail(getMailByHrGroup(getString("siteid") + "1001"), getString("fagentshortname") + "工具借出单提交待审", getString("FAGENTSHORTNAME") + "订单提交待审;订单号:" + getString("fsonum")); //任务箱提醒 createAssignment(getHrIdByHrGroup(getString("siteid") + "1001"), "SAORDER0", getString("FAGENTSHORTNAME") + "工具借出单提交待审", getString("FAGENTSHORTNAME") + "工具借出单提交待审;单号:" + getString("fsonum")); } else { deleteAssignment(); setValue("fstatus", "新建", 11L); setValue("submitby", "", 11L); setValue("submitdate", "", 11L); setValue("fnotes", getString("fnotes") + "----订单退回", 11L); } } /** * 交期回复验证 */ public void needdatereplyvalidate(boolean isneeddatereply) throws P2Exception { if (isneeddatereply) { if (!"提交".equals(getString("fstatus"))) { throw new P2AppException("", "非提交状态下不可进行交期回复"); } //订单表体,所有商品信息,包括辅材配件 if (issaleday()) { PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); int i = 0; PaoRemote pao = null; while ((pao = saorderdetail.getPao(i)) != null) { if (pao.getPaoSet("titem").getPao(0).getBoolean("fissaleday")) { if ("".equals(pao.getString("fplandate"))) { throw new P2AppException("", "行" + pao.getInt("frownum") + "商品" + pao.getString("fitemname") + "为交期管控,请填写回复交期!"); } } i++; } } else { throw new P2AppException("", "不存在交期管控的商品,无需进行交期回复,可直接进行订单审核"); } } else { if (!"交期待确认".equals(getString("fstatus"))) { throw new P2AppException("", "非交期待确认状态下不可撤销交期回复"); } } } /** * 交期回复 */ public void needdatereply(boolean isneeddatereply) throws P2Exception { if (isneeddatereply) { setValue("needdatereplydate", getDate(), 11L); setValue("needdatereplyby", getUserName(), 11L); setValue("fstatus", "交期待确认", 11L); { //业务员邮件提醒 sendEmail(getMailByHrId(getString("fsaler")), getString("FAGENTSHORTNAME") + "交期待确认", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期待确认;订单号:" + getString("fsonum")); } } else { setValue("needdatereplydate", "", 11L); setValue("needdatereplyby", "", 11L); setValue("fstatus", "提交", 11L); } } /** * 交期确认验证 */ public void needdateconfirmvalidate(boolean isneeddateconfirm) throws P2Exception { if (isneeddateconfirm) { if (!"交期待确认".equals(getString("fstatus"))) { throw new P2AppException("", "非交期待确认状态下不可进行交期确认"); } } else { if (!"交期确认".equals(getString("fstatus"))) { throw new P2AppException("", "非交期确认状态下不可撤销交期确认"); } } } /** * 交期确认 */ public void needdateconfirm(boolean isneeddateconfirm) throws P2Exception { if (isneeddateconfirm) { setValue("needdateconfirmdate", getDate(), 11L); setValue("needdateconfirmby", getUserName(), 11L); setValue("fstatus", "交期确认", 11L); //销管订单提交待审核邮件提醒 sendEmail(getMailByHrGroup(getString("siteid") + "1001"), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期确认待审", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期确认待审;订单号:" + getString("fsonum")); //任务箱提醒 createAssignment(getHrIdByHrGroup(getString("siteid") + "1001"), "SAORDER0", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期确认待审", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期确认待审;订单号:" + getString("fsonum")); } else { setValue("needdateconfirmdate", "", 11L); setValue("needdateconfirmby", "", 11L); setValue("fstatus", "交期待确认", 11L); } } /** * 检查订单是否需要交期管控 * * @return */ public boolean issaleday() throws P2Exception { PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); int i = 0; PaoRemote pao = null; while ((pao = saorderdetail.getPao(i)) != null) { if (pao.getPaoSet("titem").getPao(0).getBoolean("fissaleday")) { return true; } i++; } return false; } /** * 检查商品是否都上架 * * @return */ public String isnotonsaleitemnos() throws P2Exception { String fitemnos = ""; PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); int i = 0; PaoRemote pao = null; while ((pao = saorderdetail.getPao(i)) != null) { if (!pao.getPaoSet("titem").getPao(0).getBoolean("fisonsale")) { if (fitemnos.equals("")) { fitemnos = pao.getString("fitemno"); } else { fitemnos = fitemnos + "、" + pao.getString("fitemno"); } } i++; } return fitemnos; } /** * @param fischeck 审核、反审核 * @param fisman 是否人工审核 * @throws P2Exception */ public void checkvalidate(boolean fischeck, boolean fisman) throws P2Exception { if (fischeck) { DBConnect dbConnect = new DBConnect(); Rows rows = dbConnect.runSqlQuery("select fitemno,fitemname from saorderdetail where fparentid='" + getUniqueIDValue() + "' and fplandate= tagent.getDouble("fisfirstorderflamount") && tagent.getDate("fsigningtime") != null) { //当前签约开始时间 Calendar fsigningtime_beg = Calendar.getInstance(); fsigningtime_beg.setTime(tagent.getDate("fsigningtime")); fsigningtime_beg.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); //当前签约结束时间 Calendar fsigningtime_end = Calendar.getInstance(); fsigningtime_end.setTime(tagent.getDate("fsigningtime")); fsigningtime_end.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR) + 1); PaoSetRemote paoset = getPaoSet("$$saorder", "saorder"); paoset.setWhere("fisyearfirstorder_fl=1 and fagentnum='" + getString("fagentnum") + "' and ftype='标准订单' and convert(varchar(10),checkdate,120)>='" + getDate_Str(fsigningtime_beg.getTime()) + "' and convert(varchar(10),checkdate,120)<'" + getDate_Str(fsigningtime_end.getTime()) + "'"); paoset.reset(); if (paoset.isEmpty()) { setValue("fisyearfirstorder_fl", true, 11L); setValue("fisfl", true, 11L); } } return getBoolean("fisyearfirstorder_fl"); } /** * 是否年度首单计算 * * @param ftotalamount * @return * @throws P2Exception */ public boolean fisyearfirstorder_wl(double ftotalamount) throws P2Exception { if (!"标准订单".equals(getString("ftype"))) { return getBoolean("fisyearfirstorder_wl"); } PaoRemote tagent = getPaoSet("tagents").getPao(0); //签约时间 boolean fisfirstorder = tagent.getBoolean("fisfirstorder"); if (fisfirstorder && ftotalamount >= tagent.getDouble("fisfirstorderamount")) { //当前签约开始时间 Calendar fsigningtime_beg = Calendar.getInstance(); fsigningtime_beg.setTime(tagent.getDate("fsigningtime")); fsigningtime_beg.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR)); //当前签约结束时间 Calendar fsigningtime_end = Calendar.getInstance(); fsigningtime_end.setTime(tagent.getDate("fsigningtime")); fsigningtime_end.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR) + 1); PaoSetRemote paoset = getPaoSet("$$saorder", "saorder"); paoset.setWhere("fisyearfirstorder_wl=1 and fagentnum='" + getString("fagentnum") + "' and ftype='标准订单' and convert(varchar(10),checkdate,120)>='" + getDate_Str(fsigningtime_beg.getTime()) + "' and convert(varchar(10),checkdate,120)<'" + getDate_Str(fsigningtime_end.getTime()) + "'"); paoset.reset(); if (paoset.isEmpty()) { setValue("fisyearfirstorder_wl", true, 11L); } } return getBoolean("fisyearfirstorder_wl"); } @Override public int closevalidate(boolean isclose) throws P2Exception { //系统参数表 PaoRemote sysVars = getSysVars(); //是否启用发货单 boolean fissainvoice = sysVars.getBoolean("fissainvoice"); //订单表体 PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view"); Vector v = saorderdetail.getSelection(); if (isclose) { if (!"审核".equals(getString("fstatus"))) { throw new P2AppException("", "非审核状态下不可关闭"); } if (v.size() == 0) { throw new P2AppException("", "请勾选需要关闭的行再进行此操作"); } Iterator it = v.iterator(); while (it.hasNext()) { PaoRemote closepao = it.next(); int frownum = closepao.getInt("frownum"); if (closepao.getBoolean("fisclose")) { throw new P2AppException("", "行" + frownum + "已经关闭,不可重复关闭"); } if (closepao.getDouble("fundeliqty") == 0) { throw new P2AppException("", "行" + frownum + "已发货完毕,不可关闭"); } //校验是否存在未关闭的发货单 if (fissainvoice) { PaoSetRemote sainvoicedetail = closepao.getPaoSet("sainvoicedetail"); int i = 0; while (sainvoicedetail.getPao(i) != null) { PaoSetRemote sainvoice = sainvoicedetail.getPao(i) .getPaoSet("sainvoice"); if (!"关闭".equals(sainvoice.getPao(0).getString("fstatus"))) { throw new P2AppException("", "行" + frownum + "存在未关闭的发货单,不可关闭"); } i++; } } //校验是否存在新建的销售出库单 PaoSetRemote icstockbilldetail = closepao.getPaoSet("icstockbilldetail"); int i = 0; while (icstockbilldetail.getPao(i) != null) { PaoSetRemote icstockbill = icstockbilldetail.getPao(i) .getPaoSet("icstockbill"); if ("新建".equals(icstockbill.getPao(0).getString("fstatus"))) { throw new P2AppException("", "行" + frownum + "存在新建的销售出库单,不可关闭"); } i++; } } } else { if (v.size() == 0) { throw new P2AppException("", "请购选行再进行取消关闭操作"); } Iterator it = v.iterator(); while (it.hasNext()) { PaoRemote unclosepao = it.next(); int frownum = unclosepao.getInt("frownum"); if (!unclosepao.getBoolean("fisclose")) { throw new P2AppException("", "行" + frownum + "未关闭,不可取消关闭"); } if (unclosepao.getDouble("FUNDELIQTY") == 0) { throw new P2AppException("", "行" + frownum + "已发货完毕,不可取消关闭"); } } } return 1; } @Override public int close(boolean isclose) throws P2Exception { /** * 订单指定账户 */ taccbal taccbal = null; PaoSetRemote taccbalSet = getPaoSet("taccbal"); if (taccbalSet.isEmpty()) { taccbal = (taccbal) taccbalSet.addAtEnd(); taccbal.setfields(getString("fpayagentnum"), getString("faccclsnum")); } else { taccbal = (taccbal) taccbalSet.getPao(0); } /** * 订单指定账户 */ taccbal taccbal_fl = null; PaoSetRemote taccbalSet_fl = getPaoSet("taccbal_fl"); if (taccbalSet_fl.isEmpty()) { taccbal_fl = (taccbal) taccbalSet_fl.addAtEnd(); taccbal_fl.setfields(getString("fpayagentnum"), "02"); } else { taccbal_fl = (taccbal) taccbalSet_fl.getPao(0); } //系统参数表 PaoRemote sysVars = getSysVars(); //订单账户管控是否扣款 String fupdatebaltime = sysVars.getString("fupdatebaltime"); //订单账户管控是否冻结金额 String fupdatfreeztime = sysVars.getString("fupdatfreeztime"); //订单表体 PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view"); // 订单指出总额 double ftotalrateamount = saorderdetail.sum("frateamount"); //当前时间 Date date = getDateTime(); // 退还金额 double returnamount = 0; int i = 0; PaoRemote detailpao = null; while ((detailpao = saorderdetail.getPao(i)) != null) { if (detailpao.isSelected()) { // 订单金额 double frateamount = detailpao.getDouble("frateamount"); // 订单单价 // double fprice = detailpao.getDouble("fprice"); // 订单数量 double fqty = detailpao.getDouble("fqty"); // 订单未发货数量 double fundeliqty = detailpao.getDouble("fundeliqty"); /*计算订单关闭的退还金额*/ //已发货数量 double sendqty = Math.sub(fqty, fundeliqty); //订单单价 double frateprice = detailpao.getDouble("frateprice"); //已发货金额 double sendamount = Math.mul(sendqty, frateprice, 2); //未发货金额 double unsendamount = Math.sub(frateamount, sendamount); //退款金额 returnamount = returnamount + unsendamount; if (isclose) { detailpao.setValue("fisclose", true, 11L); detailpao.setValue("fclosedate", date, 11L); detailpao.setValue("fclosenum", getUserName(), 11L); detailpao.setValue("fclosereason", getString("closereason"), 11L); } else { detailpao.setValue("fisclose", false, 11L); detailpao.setValue("fclosedate", "", 11L); detailpao.setValue("fclosenum", "", 11L); detailpao.setValue("fclosereason", "", 11L); } //更新促销方案商品已订购数量 if ("促销订单".equals(getString("ftype"))) { PaoSetRemote tpromproducts = detailpao.getPaoSet("tpromproducts"); if (!tpromproducts.isEmpty()) { PaoRemote tpromproduct = tpromproducts.getPao(0); if (tpromproduct.getBoolean("fislimit")) { //可销售数量 double fsurplusqty = tpromproduct.getDouble("fsurplusqty"); //更新可销售量 tpromproduct.setValue("fsurplusqty", Math.add(fsurplusqty, fundeliqty), 11L); } } } } i++; } /*订单关闭账户余额更新*/ if ("订单提交".equals(fupdatebaltime) || "订单审核".equals(fupdatebaltime)) { //如果是账户余额扣减 if (isclose) { /*生成负数支出凭证*/ StringBuffer fnotes = new StringBuffer(); fnotes.append("该单由销售订单").append(getString("fsonum")).append("行关闭时自动生成;关闭原因:").append(getString("closereason")); //PaoSetRemote ficashbillset = getPaoSet("$ficashbill_fl", "ficashbill", "ftypemx='返利金'and fnotes not like'%行关闭%' and ftype='支出' and fstatus='审核' and fsourceobject='SAORDER' and fsourceid=" + getUniqueIDValue()); //返利金总额 // double fuseflamount = getDouble("fuseflamount"); // fuseflamount = fuseflamount * (returnamount / ftotalrateamount); //createFicashbill_fl_Pay(taccbal_fl, -famount_fl, fnotes.toString()); createFicashbill_Pay(taccbal, -returnamount, fnotes.toString(), true); } else { /*生成支出凭证*/ StringBuffer fnotes = new StringBuffer(); fnotes.append("该单由销售订单").append(getString("fsonum")).append("行反关闭时自动生成;反关闭原因:").append(getString("closereason")); PaoSetRemote ficashbillset = getPaoSet("$ficashbill_fl", "ficashbill", "ftypemx='返利金'and fnotes not like'%行关闭%' and ftype='支出' and fstatus='审核' and fsourceobject='SAORDER' and fsourceid=" + getUniqueIDValue()); //返利金总额 //double famount_fl = ficashbillset.sum("famount"); //famount_fl = famount_fl * (returnamount / ftotalrateamount); //createFicashbill_fl_Pay(taccbal_fl, famount_fl, fnotes.toString()); createFicashbill_Pay(taccbal, returnamount, fnotes.toString(), true); } } else if ("订单提交".equals(fupdatfreeztime) || "订单审核".equals(fupdatfreeztime)) { //如果是账户冻结金额 //冻结列表 PaoSetRemote taccbal_freez = getPaoSet("$TACCBAL_FREEZ", "taccbal_freez", "fsourceobject='" + getName() + "' and fsourceid='" + getUniqueIDValue() + "'"); if (!taccbal_freez.isEmpty()) { PaoRemote freezPao = taccbal_freez.getPao(0); // 冻结金额 double famount = freezPao.getDouble("famount"); freezPao.setValue("famount", Math.sub(famount, returnamount), 11L); if (freezPao.getDouble("famount") <= 0.1) { taccbal_freez.deleteAll(); } } } /*增加总仓可销售量 */ //updateIcinvbal_total(isclose, true); //更新促销方案经销商已订购金额 if ("促销订单".equals(getString("ftype"))) { PaoSetRemote tpromagents = getPaoSet("tpromagents"); if (!tpromagents.isEmpty()) { PaoRemote tpromagent = tpromagents.getPao(0); if (tpromagent.getBoolean("fislimit") && "金额".equals(tpromagent.getString("flimittype"))) { //已购量 double flimitvalue1 = tpromagent.getDouble("flimitvalue1"); //更新已购量 tpromagent.setValue("flimitvalue1", Math.sub(flimitvalue1, returnamount), 11L); } } } /* 注:所有行全部关闭后,表头单据状态将通过触发器自动进行更新*/ return 1; } /** * 订单结案验证 * * @throws P2Exception */ public void closeordervalidate() throws P2Exception { if (!"审核".equalsIgnoreCase(getString("fstatus"))) { throw new P2AppException("", "非审核状态下不可进行结案操作"); } if ("HY".equals(getString("siteid"))) { throw new P2AppException("", "当前站点不可执行订单结案操作"); } DBConnect dbConnect = new DBConnect("ORACLE_TZ"); Rows rows = dbConnect.runSqlQuery("select SO_LINE2,sum(QTY)as QTY from v_eso_shipped_qty where SO_NO2='" + getString("fsonum") + "' and ZT='" + (getString("siteid").equalsIgnoreCase("TZ") ? "IDCZJ10" : "IBPNB10") + "' group by SO_LINE2"); if (!"".equals(rows.errmsg)) { throw new P2AppException("", "erp连接失败"); } PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); saorderdetail.setOrderBy("frownum"); saorderdetail.reset(); for (Row row : rows) { int SO_LINE2 = row.getInteger("SO_LINE2");//erp订单行号 double QTY = row.getInteger("QTY");//erp已发货数量 int i = 0; while (saorderdetail.getPao(i) != null) { int frownum = saorderdetail.getPao(i).getInt("frownum");//订单行号 if (SO_LINE2 == frownum) { saorderdetail.getPao(i).setValue("FERPDELIQTY", QTY, 11L); break; } i++; } } { String str = ""; int i = 0; while (saorderdetail.getPao(i) != null) { int frownum = saorderdetail.getPao(i).getInt("frownum");//订单行号 double fsaininvoiceqty = Math.sub(saorderdetail.getPao(i).getInt("fqty"), saorderdetail.getPao(i).getInt("fundeliqty"));//订单已发货数量 double FERPDELIQTY = saorderdetail.getPao(i).getDouble("FERPDELIQTY");//erp已发货数量 if (fsaininvoiceqty != FERPDELIQTY) { str = str + "行" + frownum + "商品发货数量" + fsaininvoiceqty + "与erp发货数量" + FERPDELIQTY + "不一致,请检查;"; } i++; } if (!str.equalsIgnoreCase("")) { throw new P2AppException("", str); } } } /** * 订单结案 * * @throws P2Exception */ public PaoRemote closeorder() throws P2Exception { PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); int i = 0; while (saorderdetail.getPao(i) != null) { //double fundeliqty = saorderdetail.getPao(i).getInt("fundeliqty");//订单未发货数量 double fqty = saorderdetail.getPao(i).getInt("fqty");//订单数量 double FERPDELIQTY = saorderdetail.getPao(i).getDouble("FERPDELIQTY");//erp已发货数量 if (fqty > FERPDELIQTY) { saorderdetail.getPao(i).setValue("fchangenotes", "订单结案变更", 11L); saorderdetail.getPao(i).setValue("fchangeqty", FERPDELIQTY, 11L); } i++; } PaoRemote pao = changesaorder(saorderdetail); PaoSetRemote sainvoiceSet = getPaoSet("SAINVOICE"); int n = 0; while (sainvoiceSet.getPao(n) != null) { if (sainvoiceSet.getPao(n).getString("fstatus").equals("新建")) { sainvoiceSet.getPao(n).delete(); } n++; } setValue("fstatus", "关闭", 11L); setValue("closeby", getUserName(), 11L); setValue("closedate", getDate(), 11L); setValue("CLOSEREASON", "订单结案", 11L); return pao; } /** * 一键发货生成发货单或销售出库单验证 * * @throws P2Exception */ public void sendoutvalidate() throws P2Exception { if (!"审核".equals(getString("fstatus"))) { throw new P2AppException("", "非审核状态下不可发货"); } PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view"); if (saorderdetail.getSelection().isEmpty()) { throw new P2AppException("", "请购选行再进行发货操作"); } int i = 0; while (saorderdetail.getPao(i) != null) { if (saorderdetail.getPao(i).isSelected()) { int frownum = saorderdetail.getPao(i).getInt("frownum"); if (saorderdetail.getPao(i).getBoolean("fisclose")) { throw new P2AppException("", "行" + frownum + "已经关闭,不可发货"); } if (saorderdetail.getPao(i).getDouble("fundeliqty") == 0) { throw new P2AppException("", "行" + frownum + "已发货完毕,不可发货"); } } i++; } } /** * 一键发货生成发货单或销售出库单 * * @throws P2Exception */ public PaoRemote sendout(String foutplace) throws P2Exception { //系统参数表 PaoRemote sysVars = getSysVars(); //是否发货单管理。如果为true,则发货时生成发货单。否则直接生成销售出库单 boolean fissainvoice = sysVars.getBoolean("fissainvoice"); PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view"); if (fissainvoice) { // 生成发货单 PaoSetRemote sainvoiceset = getPaoSet("sainvoice"); sainvoiceset.setApp("SAINVOICE"); sainvoice sainvoice = (sainvoice) sainvoiceset.addAtEnd(); sainvoice.setValue("fsonum", getString("fsonum")); sainvoice.additemnos(saorderdetail_view); return sainvoice; } else { // 生成销售出库单 PaoSetRemote icstockbillset = getPaoSet("icstockbill"); icstockbillset.setWhere("fstatus='新建'"); icstockbillset.reset(); icstockbillset.setApp("STOCKBILL0"); icstockbill icstockbill = null; if (icstockbillset.isEmpty()) { icstockbill = (icstockbill) icstockbillset.addAtEnd(); icstockbill.setValue("fsourceid", getUniqueIDValue()); icstockbill.setValue("fsourceobject", getName()); icstockbill.setValue("fagentnum", getString("fagentnum")); icstockbill.setValue("fnotes", getString("fnotes")); icstockbill.setValue("foutplace", foutplace, 11L); icstockbill.setValue("faddress", getString("faddress")); icstockbill.setValue("fcontact", getString("fcontact")); icstockbill.setValue("fphonenumber", getString("fphonenumber")); icstockbill.setValue("finvoicename", getString("finvoicename"), 11L); icstockbill.setValue("finvoiceaddress", getString("finvoiceaddress"), 11L); icstockbill.setValue("finvoicetaxnumber", getString("finvoicetaxnumber"), 11L); } else { icstockbill = (icstockbill) icstockbillset.getPao(0); PaoSetRemote icstockbilldetail = icstockbill.getPaoSet("icstockbilldetail"); int i = 0; while (saorderdetail_view.getPao(i) != null) { if (saorderdetail_view.getPao(i).isSelected()) { long saorderdetailid = saorderdetail_view.getPao(i) .getUniqueIDValue(); int m = 0; while (icstockbilldetail.getPao(m) != null) { if (icstockbilldetail.getPao(m).getLong( "saorderdetailid") == saorderdetailid) { icstockbilldetail.getPao(m).setValue( "fqty", saorderdetail_view.getPao(i).getDouble( "fqty")); saorderdetail_view.getPao(i).unselect(); break; } m++; } } i++; } } icstockbill.addRowsFromSaorder(saorderdetail_view); icstockbill.setValue("fpayamount", icstockbill.getPaoSet("icstockbilldetail_view").sum( "ftaxamount"), 11L); return icstockbill; } } /** * 配送方案生成 * * @return * @throws P2Exception */ public void createrationvalidate() throws P2Exception { if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "非新建状态下不可生成配送方案"); } if (!getPaoSet("saorderdetail_view2").isEmpty()) { throw new P2AppException("", "已生成配送方案,不可重复生成"); } } /** * 配送方案生成 * * @return * @throws P2Exception */ public void createration() throws P2Exception { PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view"); ArrayList> list = runQuerySQL("exec [SAORDEROPENRATION]'" + getUniqueIDValue() + "'"); for (HashMap map : list) { String fitemno = map.get("fitemno") + ""; double fqty = new Double(map.get("fqty") + ""); double frationqty = new Double(map.get("frationqty") + ""); double fprice = new Double(map.get("fprice") + ""); double frationminqty = new Double(map.get("frationminqty") + ""); double frationismincaculate = new Double(map.get("frationismincaculate") + ""); long saorderdetailid = new Long(map.get("saorderdetailid") + ""); String frationnum = map.get("frationnum") + ""; String frationtype = map.get("frationtype") + ""; PaoRemote pao = saorderdetail_view.addAtEnd(); pao.setValue("fisration", true, 2L); pao.setValue("fitemno", fitemno, 2L); pao.setValue("fqty", fqty, 2L); pao.setValue("fprice", fprice, 2L); pao.setValue("frationnum", frationnum, 11L); pao.setValue("frationtype", frationtype, 11L); pao.setValue("fsaorderdetailid", saorderdetailid, 11L); pao.setValue("frationqty", frationqty, 11L); pao.setValue("frationminqty", frationminqty, 11L); pao.setValue("frationismincaculate", frationismincaculate, 11L); } if (!list.isEmpty()) { setValue("fisration", true, 11L); } } /** * 清空辅材方案验证 * * @throws P2Exception */ public void deleterationvalidate() throws P2Exception { if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "非新建状态下不可清空配送方案"); } } /** * 清空辅材方案 * * @throws P2Exception */ public void deleteration() throws P2Exception { getPaoSet("saorderdetail_view2").deleteAll(); setValue("fisration", false, 11L); } @Override public void fieldAction(Object paoField, String fieldname) throws P2Exception { super.fieldAction(paoField, fieldname); if ("FAGENTNUM".equals(fieldname)) { setValue("fpayagentnum", getString("fagentnum"), 11L); setValue("frecagentnum", getString("fagentnum"), 11L); PaoSetRemote tagents = getPaoSet("tagents"); if (!"".equals(getString("fagentnum")) && !tagents.isEmpty()) { if (!"促销订单".equals(getString("ftype")) && !"工具借出单".equals(getString("ftype"))) { setValue("faccclsnum", "01"); } PaoRemote agentpao = tagents.getPao(0); // // 设置业务员 // PaoSetRemote tsalearea = agentpao.getPaoSet( // "tsalearea"); // if (!tsalearea.isEmpty()) { // setValue("fsaler", tsalearea.getPao(0).getString("fsaler")); // } else { // setValue("fsaler", ""); // } // 默认收货地址设置 PaoSetRemote tagents_address = agentpao.getPaoSet( "tagents_address_default"); if (!tagents_address.isEmpty()) { PaoRemote address = tagents_address.getPao(0); setValue("fcontact", address.getString("fcontact")); setValue("fphonenumber", address.getString("fphonenumber")); setValue("faddress", address.getString("faddress")); setValue("fprovince", address.getString("fprovince"), 11L); setValue("fcity", address.getString("fcity"), 11L); setValue("fcounty", address.getString("fcounty"), 11L); } // 默认开票信息设置 PaoSetRemote tagents_invoice = agentpao.getPaoSet("tagents_invoice_default"); if (!tagents_invoice.isEmpty()) { PaoRemote invoice = tagents_invoice.getPao(0); setValue("finvoicename", invoice.getString("fname"), 11L); setValue("finvoicetaxnumber", invoice.getString("ftaxnumber"), 11L); setValue("finvoiceaddress", invoice.getString("faddress"), 11L); } PaoSetRemote tagents_field = agentpao.getPaoSet("tagents_field"); if (!tagents_field.isEmpty()) { setValue("fieldname", tagents_field.getPao(0).getString("fieldname"), 11L); setValue("fsaler", tagents_field.getPao(0).getString("hrid"), 11L); } PaoSetRemote tagents_brand = agentpao.getPaoSet("tagents_brand"); if (!tagents_brand.isEmpty()) { setValue("fbrand", tagents_brand.getPao(0).getString("fbrand"), 11L); } } else { setValue("faccclsnum", ""); setValue("fsaler", ""); setValue("fcontact", "", 11L); setValue("fphonenumber", "", 11L); setValue("faddress", "", 11L); setValue("finvoicename", "", 11L); setValue("finvoicetaxnumber", "", 11L); setValue("finvoiceaddress", "", 11L); setValue("fprovince", "", 11L); setValue("fcity", "", 11L); setValue("fcounty", "", 11L); } } else if ("FPROMNUM".equals(fieldname)) { if ("促销订单".equals(getString("ftype"))) { if ("打包促销".equals(getString("tpromotions.ftype"))) { setFieldFlag("fpromqty", READONLY, false); setFieldFlag("fpromqty", REQUIRED, true); } else { setFieldFlag("fpromqty", READONLY, true); setFieldFlag("fpromqty", REQUIRED, false); } } } else if ("FPROMQTY".equals(fieldname)) { double fpromqty = getDouble("fpromqty"); if (fpromqty == 0) { getPaoSet("saorderdetail_view").deleteAll(); getPaoSet("saorderdetail_view").deleteAndRemoveAll(); setFieldFlag("fpromnum", READONLY, false); } else { PaoSetRemote tpromproducts = getPaoSet("tpromproducts"); int i = 0; PaoRemote pao = null; while ((pao = tpromproducts.getPao(i)) != null) { //打包数量 double fpackingqty = pao.getDouble("fpackingqty"); pao.setValue("faddqty", fpromqty * fpackingqty); pao.select(); i++; } additems_prom(tpromproducts); setFieldFlag("fpromnum", READONLY, true); } } else if ("FACCCLSNUM".equals(fieldname)) { if ("02".equals(getString(fieldname))) { setValue("fisusefl", false, 11L); setFieldFlag("fisusefl", READONLY, true); } else { setFieldFlag("fisusefl", READONLY, false); } } else if ("FISUSEFL".equals(fieldname)) { //double ftotalamount = getPaoSet("saorderdetail_view").sum("famount"); //double fmjamount = caculateMJ(); //caculateUseFLAmount(Math.sub(ftotalamount, fmjamount)); } else if ("FTYPE".equals(fieldname)) { if ("特殊订单".equals(getString(fieldname))) { setFieldFlag("ftypemx", READONLY, false); } else { setValue("ftypemx", "普通", 11L); setFieldFlag("ftypemx", READONLY, true); } } else if ("FPLANDATE".equals(fieldname)) { //回复交期 PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view"); int i = 0; while (saorderdetail_view.getPao(i) != null) { if (saorderdetail_view.getPao(i).getPaoSet("titem").getPao(0).getBoolean("fissaleday")) { saorderdetail_view.getPao(i).setValue("fplandate", getDate(fieldname), 11L); } i++; } } else if ("FNEEDDATE".equals(fieldname)) { //回复交期 PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view"); int i = 0; while (saorderdetail_view.getPao(i) != null) { if (saorderdetail_view.getPao(i).getPaoSet("titem").getPao(0).getBoolean("fissaleday")) { saorderdetail_view.getPao(i).setValue("fneeddate", getDate(fieldname), 11L); } i++; } } } @Override public void fieldValidate(Object paoField, String fieldname) throws P2Exception { super.fieldValidate(paoField, fieldname); if ("FPROMQTY".equals(fieldname)) { double fpromqty = getDouble("fpromqty"); if (fpromqty < 0) { throw new P2AppException("", "数量不可小于0"); } } else if ("FPROJECTNOTES".equals(fieldname)) { PaoSetRemote tprojectSet = getPaoSet("$tproject", "tproject"); tprojectSet.setWhere("fstatus='审核' and fieldname='" + getString("fieldname") + "' and fprojectname like'%" + getString("fprojectnotes") + "%' and ((fbegdate<=tproject.fbegdate and fenddate>=tproject.fbegdate ) or (fbegdate<=tproject.fenddate and fenddate>=tproject.fenddate ))"); tprojectSet.reset(); if (!tprojectSet.isEmpty()) { ((PaoSet) getThisPaoSet()).addWarning(new P2AppException("", "当前项目有效期内已存在审核的项目报备")); } } } @Override public PaoSetRemote fieldGetlist(Object paoField, PaoSetRemote list, String fieldname) throws P2Exception { if ("FPAYAGENTNUM".equals(fieldname)) { PaoSetRemote tagentsSet = getPaoSet("tagents"); if (!tagentsSet.isEmpty()) { SQLFactory factory = new SQLFactory(this, "结算客户查询"); factory.addParameter("siteid", getInsertSite()); factory.addParameter("fagentnum", getString("fagentnum")); DBConnect dbConnect = new DBConnect(); Rows rows = dbConnect.runSqlQuery(factory.getSQL()); String where = rows.getInWhere("fagentnum"); list.setWhere("fagentnum in " + where); } else { list.setWhere("1=2"); } } return super.fieldGetlist(paoField, list, fieldname); } public void getStockStatus() throws P2Exception { PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); String[] fitemnos = getDistinctString(saorderdetail, "fitemno", false); String where = ""; for (String fitemno : fitemnos) { if ("".equals(where)) { where = "'" + fitemno + "'"; } else { where = where + ",'" + fitemno + "'"; } } if (!"".equals(where)) { PaoSetRemote titemSet = getPaoSet("$titem", "titem", "fitemno in (" + where + ")"); int i = 0; titem titem = null; while ((titem = (titem) titemSet.getPao(i)) != null) { titem.initStockMsg(); i++; } } } /** * 是否缺货检查 * * @throws P2Exception */ public boolean checkStockStatus() throws P2Exception { getStockStatus(); PaoSetRemote saorderdetail = getPaoSet("saorderdetail"); int i = 0; while (saorderdetail.getPao(i) != null) { if (saorderdetail.getPao(i).getDouble("fqty") > saorderdetail.getPao(i).getPaoSet("titem").getPao(0).getDouble("ficqty")) { return false; } i++; } return true; } public void changesaorder_validate(PaoSetRemote paoSetRemote) throws P2Exception { int i = 0; PaoRemote orderdetail = null; while ((orderdetail = paoSetRemote.getPao(i)) != null) { double fqty = orderdetail.getDouble("fqty"); double fchangeqty = orderdetail.getDouble("fchangeqty"); String fchangenotes = orderdetail.getString("fchangenotes"); if (fqty != fchangeqty && !orderdetail.getString("fchangeqty").equals("")) { if (fchangenotes.equals("")) { throw new P2AppException("", "修改备注不可为空"); } } i++; } } public PaoRemote changesaorder(PaoSetRemote paoSetRemote) throws P2Exception { changesaorder_validate(paoSetRemote); HashMap saorderdetailmap = new HashMap<>(); HashMap saorderdetailchangeamount = new HashMap<>(); PaoSetRemote saorderdetail_changeSet = getPaoSet("$saorderdetail_change", "saorderdetail_change"); HashMap map = new HashMap(); int i = 0; long id = 0; PaoRemote saorderdetail_changePao = null; PaoRemote orderdetail = null; while ((orderdetail = paoSetRemote.getPao(i)) != null) { double fqty = orderdetail.getDouble("fqty"); double fchangeqty = orderdetail.getDouble("fchangeqty"); String fchangenotes = orderdetail.getString("fchangenotes"); Long saorderdetailid = orderdetail.getUniqueIDValue(); if (fqty != fchangeqty && !orderdetail.getString("fchangeqty").equals("")) { PaoRemote saorderdetail_change = saorderdetail_changeSet.addAtEnd(); if (id == 0) { id = saorderdetail_change.getUniqueIDValue(); saorderdetail_changePao = saorderdetail_change; } saorderdetail_change.setValue("id", id); saorderdetail_change.setValue("foldqty", fqty); saorderdetail_change.setValue("fqty", fchangeqty); saorderdetail_change.setValue("fchangenotes", fchangenotes); saorderdetail_change.setValue("saorderdetailid", saorderdetailid); saorderdetail_change.setValue("saorderid", getUniqueIDValue()); saorderdetail_change.setValue("createby", getUserName()); saorderdetail_change.setValue("createdate", getDate()); map.put(saorderdetailid, fchangeqty); } i++; } PaoSetRemote saorderdetailSet = getPaoSet("saorderdetail"); double foldrateamount = saorderdetailSet.sum("frateamount"); int n = 0; while (saorderdetailSet.getPao(n) != null) { long detailid = saorderdetailSet.getPao(n).getUniqueIDValue(); if (map.containsKey(detailid)) { double fprice = saorderdetailSet.getPao(n).getDouble("fprice"); //double fmjamount = saorderdetailSet.getPao(n).getDouble("fmjamount");//行满减金额 //double fflamount = saorderdetailSet.getPao(n).getDouble("fflamount");//行返利金额 double fnewqty = map.get(detailid); double foldqty = saorderdetailSet.getPao(n).getDouble("fqty"); double foldundeliqty = saorderdetailSet.getPao(n).getDouble("fundeliqty"); double faddqty = fnewqty - foldqty;//新增的数量 saorderdetailSet.getPao(n).setValue("fqty", foldqty + faddqty, 11L); saorderdetailSet.getPao(n).setValue("fundeliqty", foldundeliqty + faddqty, 11L); saorderdetailSet.getPao(n).setValue("famount", map.get(detailid) * fprice, 11L); double famount = saorderdetailSet.getPao(n).getDouble("famount"); //saorderdetailSet.getPao(n).setValue("frateamount", Math.add(famount, Math.add(-fmjamount, -fflamount)), 11L); //saorderdetailSet.getPao(n).setValue("frateprice", saorderdetailSet.getPao(n).getDouble("frateamount") / saorderdetailSet.getPao(n).getDouble("fqty"), 11L); saorderdetailSet.getPao(n).setValue("frateamount", fnewqty * saorderdetailSet.getPao(n).getDouble("frateprice"), 11L); /** * 核销对冲计算 */ double fwriteoffamount = saorderdetailSet.getPao(n).getDouble("fwriteoffamount");//已核销金额 if (fwriteoffamount > 0 && saorderdetailSet.getPao(n).getDouble("frateamount") < fwriteoffamount) { //如果已核销金额大于0 且调整后折后金额小于已核销金额,则需要将差价进行回冲 saorderdetailmap.put(detailid, (saorderdetail) saorderdetailSet.getPao(n)); saorderdetailchangeamount.put(detailid, Math.sub(fwriteoffamount, saorderdetailSet.getPao(n).getDouble("frateamount"))); } } n++; } double fnewrateamount = saorderdetailSet.sum("frateamount"); double ce = Math.sub(fnewrateamount, foldrateamount); if (ce != 0) { /** * 订单指定账户 */ taccbal taccbal = null; PaoSetRemote taccbalSet = getPaoSet("taccbal"); if (taccbalSet.isEmpty()) { taccbal = (taccbal) taccbalSet.addAtEnd(); taccbal.setfields(getString("fpayagentnum"), getString("faccclsnum")); } else { taccbal = (taccbal) taccbalSet.getPao(0); } createFicashbill_Pay(taccbal, ce, "订单调整" + getString("fsonum"), true); // if (saorderdetail_changePao != null) {?// // boolean issuccess = new UploadDataToERP(saorderdetail_changePao, getUserInfo()).upload();?// // } } /** * 核销对冲 */ if (!saorderdetailmap.isEmpty()) { new twriteoffbill_orderchange(this, saorderdetailmap, saorderdetailchangeamount).hedging(); } return saorderdetail_changePao; } @Override public PaoRemote duplicate() throws P2Exception { PaoRemote pao = super.duplicate(); try { pao.setValue("createflag", getThisPaoSet().getApp().contains("管理"), 11L); } catch (Exception e) { e.printStackTrace(); } return pao; } }