package tqq9.lc123.cloud.app.plugin.form.pm; import com.google.gson.Gson; import kd.bos.bill.AbstractBillPlugIn; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.utils.StringUtils; import kd.bos.entity.datamodel.IDataModel; import kd.bos.entity.datamodel.RowDataEntity; import kd.bos.entity.datamodel.events.AfterAddRowEventArgs; import kd.bos.entity.datamodel.events.AfterDeleteRowEventArgs; import kd.bos.entity.datamodel.events.ChangeData; import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.form.events.BeforeDoOperationEventArgs; import kd.bos.form.operate.FormOperate; import kd.bos.logging.Log; import kd.bos.logging.LogFactory; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.sdk.scmc.im.utils.DateUtils; import tqq9.lc123.cloud.app.eip.iscb.LCLogService; import tqq9.lc123.cloud.app.eip.iscb.impl.LCLogServiceImpl; import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils; import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; /** * 采购订单 * 值改变事件:现返、货返金额分摊;付款比例不超过100% */ public class PuroderBillShareRefundPlugin extends AbstractBillPlugIn { private final static Log logger = LogFactory.getLog(PuroderBillShareRefundPlugin.class); private final static String ENTRYENTITY = "billentry"; private static String URL; private static String FLXT_TOKEN; static { DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name", new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Balance_Url")}); URL = url != null ? url.getString("name") : null; DynamicObject token = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name", new QFilter[]{new QFilter("number", QCP.equals, "FLXT_TOKEN")}); FLXT_TOKEN = token != null ? token.getString("name") : null; } @Override public void afterAddRow(AfterAddRowEventArgs e) { super.afterAddRow(e); if (StringUtils.equals(e.getEntryProp().getName(), ENTRYENTITY)) { BigDecimal tqq9_discountamount = (BigDecimal) this.getModel().getValue("tqq9_discountamount"); if (tqq9_discountamount.compareTo(BigDecimal.ZERO) > 0) { RowDataEntity[] rowDataEntities = e.getRowDataEntities(); for (RowDataEntity rowDataEntity : rowDataEntities) { int rowIndex = rowDataEntity.getRowIndex(); this.getModel().setValue("discounttype", "C", rowIndex); } } } } @Override public void afterDeleteRow(AfterDeleteRowEventArgs e) { super.afterDeleteRow(e); DynamicObject dataEntity = this.getModel().getDataEntity(true); BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//单头含税现返使用金额 if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) { DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry"); if (billentries != null && billentries.size() > 0) { BigDecimal remainRefundAmt = tqq9_hsxfsyje;//拆分后剩余的金额 List seqs = new ArrayList<>(); BigDecimal tqq9_totalamount = BigDecimal.ZERO; for (int i = 0; i <= billentries.size() - 1; i++) { DynamicObject billentry = billentries.get(i); BigDecimal tqq9_amount = billentry.getBigDecimal("tqq9_amount");//明细折扣前价税合计 tqq9_totalamount = tqq9_totalamount.add(tqq9_amount); if (tqq9_amount.compareTo(BigDecimal.ZERO) > 0) { seqs.add(i); } } for (int i = 0; i < seqs.size(); i++) { int seq = seqs.get(i); if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_xfamount", remainRefundAmt, seq);//明细现返使用金额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_xfamount", BigDecimal.ZERO, seq);//明细现返使用金额 } else { BigDecimal tqq9_xfamount = tqq9_hsxfsyje.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_xfamount", tqq9_xfamount, seq);//明细现返使用金额 remainRefundAmt = remainRefundAmt.subtract(tqq9_xfamount); } } } } } BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//单头含税货返使用金额 if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) { DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry"); if (billentries != null && billentries.size() > 0) { BigDecimal remainRefundAmt = tqq9_hshfsyje;//拆分后剩余的金额 List seqs = new ArrayList<>(); BigDecimal tqq9_totalamount = BigDecimal.ZERO; for (int i = 0; i <= billentries.size() - 1; i++) { DynamicObject billentry = billentries.get(i); BigDecimal tqq9_amount = billentry.getBigDecimal("tqq9_amount");//明细折扣前价税合计 tqq9_totalamount = tqq9_totalamount.add(tqq9_amount); if (tqq9_amount.compareTo(BigDecimal.ZERO) > 0) { seqs.add(i); } } for (int i = 0; i <= seqs.size() - 1; i++) { int seq = seqs.get(i); if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_hfamount", remainRefundAmt, seq);//明细货返使用金额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_hfamount", BigDecimal.ZERO, seq);//明细货返使用金额 } else { BigDecimal tqq9_hfamount = tqq9_hshfsyje.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_hfamount", tqq9_hfamount, seq);//明细货返使用金额 remainRefundAmt = remainRefundAmt.subtract(tqq9_hfamount); } } } } } BigDecimal tqq9_discountamount = dataEntity.getBigDecimal("tqq9_discountamount");//单头优惠金额 if (tqq9_discountamount.compareTo(BigDecimal.ZERO) > 0) { DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry"); if (billentries != null && billentries.size() > 0) { BigDecimal remainRefundAmt = tqq9_discountamount;//拆分后剩余的金额 List seqs = new ArrayList<>(); BigDecimal tqq9_totalamount = BigDecimal.ZERO; for (int i = 0; i <= billentries.size() - 1; i++) { DynamicObject billentry = billentries.get(i); BigDecimal tqq9_amount = billentry.getBigDecimal("tqq9_amount");//明细折扣前价税合计 tqq9_totalamount = tqq9_totalamount.add(tqq9_amount); if (tqq9_amount.compareTo(BigDecimal.ZERO) > 0) { seqs.add(i); } } for (int i = 0; i <= seqs.size() - 1; i++) { int seq = seqs.get(i); if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_disamount", remainRefundAmt, seq);//明细优惠金额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_disamount", BigDecimal.ZERO, seq);//明细优惠金额 } else { BigDecimal tqq9_disamount = tqq9_discountamount.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_disamount", tqq9_disamount, seq);//明细优惠金额 remainRefundAmt = remainRefundAmt.subtract(tqq9_disamount); } } } } } } @Override public void propertyChanged(PropertyChangedArgs e) { super.propertyChanged(e); String name = e.getProperty().getName(); DynamicObject dataEntity = this.getModel().getDataEntity(true); if ("tqq9_hsxfsyje".equals(name)) { //含税现返使用金额 BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal(name);//单头含税现返使用金额 if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) { DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry"); if (billentries != null && billentries.size() > 0) { BigDecimal remainRefundAmt = tqq9_hsxfsyje;//拆分后剩余的金额 List seqs = new ArrayList<>(); BigDecimal tqq9_totalamount = BigDecimal.ZERO; for (int i = 0; i <= billentries.size() - 1; i++) { DynamicObject billentry = billentries.get(i); BigDecimal tqq9_amount = billentry.getBigDecimal("tqq9_amount");//明细折扣前价税合计 tqq9_totalamount = tqq9_totalamount.add(tqq9_amount); if (tqq9_amount.compareTo(BigDecimal.ZERO) > 0) { seqs.add(i); } } for (int i = 0; i < seqs.size(); i++) { int seq = seqs.get(i); if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_xfamount", remainRefundAmt, seq);//明细现返使用金额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_xfamount", BigDecimal.ZERO, seq);//明细现返使用金额 } else { BigDecimal tqq9_xfamount = tqq9_hsxfsyje.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_xfamount", tqq9_xfamount, seq);//明细现返使用金额 remainRefundAmt = remainRefundAmt.subtract(tqq9_xfamount); } } } } } this.getView().updateView("billentry"); } if ("tqq9_hshfsyje".equals(name)) { //含税货返使用金额 BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal(name);//单头含税货返使用金额 if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) { DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry"); if (billentries != null && billentries.size() > 0) { BigDecimal remainRefundAmt = tqq9_hshfsyje;//拆分后剩余的金额 List seqs = new ArrayList<>(); BigDecimal tqq9_totalamount = BigDecimal.ZERO; for (int i = 0; i <= billentries.size() - 1; i++) { DynamicObject billentry = billentries.get(i); BigDecimal tqq9_amount = billentry.getBigDecimal("tqq9_amount");//明细折扣前价税合计 tqq9_totalamount = tqq9_totalamount.add(tqq9_amount); if (tqq9_amount.compareTo(BigDecimal.ZERO) > 0) { seqs.add(i); } } for (int i = 0; i <= seqs.size() - 1; i++) { int seq = seqs.get(i); if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_hfamount", remainRefundAmt, seq);//明细货返使用金额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_hfamount", BigDecimal.ZERO, seq);//明细货返使用金额 } else { BigDecimal tqq9_hfamount = tqq9_hshfsyje.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_hfamount", tqq9_hfamount, seq);//明细货返使用金额 remainRefundAmt = remainRefundAmt.subtract(tqq9_hfamount); } } } } } this.getView().updateView("billentry"); } if ("tqq9_discountamount".equals(name)) { //优惠金额 BigDecimal tqq9_discountamount = dataEntity.getBigDecimal(name);//单头优惠金额 if (tqq9_discountamount.compareTo(BigDecimal.ZERO) > 0) { DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry"); if (billentries != null && billentries.size() > 0) { BigDecimal remainRefundAmt = tqq9_discountamount;//拆分后剩余的金额 List seqs = new ArrayList<>(); BigDecimal tqq9_totalamount = BigDecimal.ZERO; for (int i = 0; i <= billentries.size() - 1; i++) { DynamicObject billentry = billentries.get(i); BigDecimal tqq9_amount = billentry.getBigDecimal("tqq9_amount");//明细折扣前价税合计 tqq9_totalamount = tqq9_totalamount.add(tqq9_amount); if (tqq9_amount.compareTo(BigDecimal.ZERO) > 0) { seqs.add(i); } } for (int i = 0; i <= seqs.size() - 1; i++) { int seq = seqs.get(i); if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_disamount", remainRefundAmt, seq);//明细优惠金额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_disamount", BigDecimal.ZERO, seq);//明细优惠金额 } else { BigDecimal tqq9_disamount = tqq9_discountamount.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_disamount", tqq9_disamount, seq);//明细优惠金额 remainRefundAmt = remainRefundAmt.subtract(tqq9_disamount); } } } } } this.getView().updateView("billentry"); } if (StringUtils.equals("payrate", name)) { //校验付款比例不能大于100% IDataModel model = this.getModel(); DynamicObject pm_purorderbill = model.getDataEntity(true);//采购订单 DynamicObjectCollection entries = pm_purorderbill.getDynamicObjectCollection("purbillentry_pay");//付款计划分录 BigDecimal zero = BigDecimal.ZERO; for (DynamicObject entry : entries) { BigDecimal payrate = entry.getBigDecimal("payrate"); zero = zero.add(payrate); } if (zero.compareTo(new BigDecimal(100)) > 0) { this.getView().showErrorNotification("付款计划付款比例总计大于100%,请修改"); } } if (StringUtils.equals("tqq9_amount", name)) { //单头金额下推 DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry"); if (billentries != null && billentries.size() > 0) { BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//单头含税现返使用金额 BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//单头含税货返使用金额 BigDecimal tqq9_discountamount = dataEntity.getBigDecimal("tqq9_discountamount");//单头优惠金额 BigDecimal remainRefundAmt_xf = tqq9_hsxfsyje;//拆分后剩余的金额-现返 BigDecimal remainRefundAmt_hf = tqq9_hshfsyje;//拆分后剩余的金额-货返 BigDecimal remainRefundAmt_yh = tqq9_discountamount;//拆分后剩余的金额-优惠 List seqs = new ArrayList<>(); BigDecimal tqq9_totalamount = BigDecimal.ZERO; for (int i = 0; i <= billentries.size() - 1; i++) { DynamicObject billentry = billentries.get(i); BigDecimal tqq9_amount = billentry.getBigDecimal("tqq9_amount");//明细折扣前价税合计 tqq9_totalamount = tqq9_totalamount.add(tqq9_amount); if (tqq9_amount.compareTo(BigDecimal.ZERO) > 0) { seqs.add(i); } } for (int i = 0; i <= seqs.size() - 1; i++) { Integer seq = seqs.get(i); //现返 if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) { if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_xfamount", remainRefundAmt_xf, seq);//明细现返使用金额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_xfamount", BigDecimal.ZERO, seq);//明细现返使用金额 } else { BigDecimal tqq9_xfamount = tqq9_hsxfsyje.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_xfamount", tqq9_xfamount, seq);//明细现返使用金额 remainRefundAmt_xf = remainRefundAmt_xf.subtract(tqq9_xfamount); } } } //货返 if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) { if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_hfamount", remainRefundAmt_hf, seq);//明细货返使用金额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_hfamount", BigDecimal.ZERO, seq);//明细货返使用金额 } else { BigDecimal tqq9_hfamount = tqq9_hshfsyje.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_hfamount", tqq9_hfamount, seq);//明细货返使用金额 remainRefundAmt_hf = remainRefundAmt_hf.subtract(tqq9_hfamount); } } } //优惠 if (tqq9_discountamount.compareTo(BigDecimal.ZERO) > 0) { if (i == seqs.size() - 1) { //如果是最后一行 this.getModel().setValue("tqq9_disamount", remainRefundAmt_yh, seq);//明细优惠金额 this.getModel().setValue("discountamount", remainRefundAmt_yh, seq);//明细折扣额 } else { //如果不是最后一行 BigDecimal tqq9_amount = (BigDecimal) this.getModel().getValue("tqq9_amount", seq);//明细折扣前价税合计 if (tqq9_amount.compareTo(BigDecimal.ZERO) == 0) { this.getModel().setValue("tqq9_disamount", BigDecimal.ZERO, seq);//明细优惠金额 this.getModel().setValue("discountamount", BigDecimal.ZERO, seq);// } else { BigDecimal tqq9_disamount = tqq9_discountamount.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例 this.getModel().setValue("tqq9_disamount", tqq9_disamount, seq);//明细优惠金额 this.getModel().setValue("discountamount", tqq9_disamount, seq);// remainRefundAmt_yh = remainRefundAmt_yh.subtract(tqq9_disamount); } } } } } this.getView().updateView("billentry"); } if (StringUtils.equals("material", name)) { ChangeData changeData = e.getChangeSet()[0]; int rowIndex = changeData.getRowIndex(); DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection(ENTRYENTITY); DynamicObject dynamicObject = dynamicObjectCollection.get(rowIndex); DynamicObject material = dynamicObject.getDynamicObject("material"); if (material != null) { DynamicObject masterid = material.getDynamicObject("masterid"); DynamicObject bd_material = BusinessDataServiceHelper.loadSingle(masterid.getLong("id"), "bd_material"); DynamicObject org = dataEntity.getDynamicObject("org"); //上海 if (StringUtils.equals("SHLC", org.getString("number"))) { BigDecimal tqq9_maxprice_sh = bd_material.getBigDecimal("tqq9_maxprice_sh"); if (tqq9_maxprice_sh.compareTo(BigDecimal.ZERO) > 0) { getModel().setValue("priceandtax", tqq9_maxprice_sh, rowIndex); getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_sh, rowIndex); } //北京 } else if (StringUtils.equals("BJLC", org.getString("number"))) { BigDecimal tqq9_maxprice_bj = bd_material.getBigDecimal("tqq9_maxprice_bj"); if (tqq9_maxprice_bj.compareTo(BigDecimal.ZERO) > 0) { getModel().setValue("priceandtax", tqq9_maxprice_bj, rowIndex); getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_bj, rowIndex); } //广州 } else if (StringUtils.equals("GZLC", org.getString("number"))) { BigDecimal tqq9_maxprice_gz = bd_material.getBigDecimal("tqq9_maxprice_gz"); if (tqq9_maxprice_gz.compareTo(BigDecimal.ZERO) > 0) { getModel().setValue("priceandtax", tqq9_maxprice_gz, rowIndex); getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_gz, rowIndex); } } //物料值改变事件,获取过去6个月事件内的最低成本单价 Date sixMonthsAgo = DateUtils.addMonth((Date) getModel().getValue("biztime"), -6); QFilter q1 = new QFilter("biztime", ">=", sixMonthsAgo);// 时间 大于等于 六个月 QFilter q2 = new QFilter("billentry.material.masterid.id", "=", bd_material.getPkValue());//物料与当前行的物料相同 QFilter q3 = new QFilter("billentry.tqq9_disandrefoundprice", "!=", 0);//明细-有优惠有返利单价不等于0 QFilter q4 = new QFilter("billentry.tqq9_hfamount", "=", 0);// 明细-的货返金额等于0 DynamicObjectCollection dymObjectCollerction = QueryServiceHelper.query("pm_purorderbill", "id,billentry,billentry.tqq9_disandrefoundprice,billentry.tqq9_hfamount,billentry.tqq9_disprice,billentry.material.id", new QFilter[]{q1,q2,q3,q4}, "billentry.tqq9_disprice asc", 1); List menuNotes = new ArrayList<>(); if(dymObjectCollerction != null && dymObjectCollerction.size() > 0){ DynamicObject doj = dymObjectCollerction.get(0); BigDecimal tqq9_disprice = doj.getBigDecimal("billentry.tqq9_disprice"); getModel().setValue("tqq9_costprice", tqq9_disprice, rowIndex); } // for (DynamicObject doj : dymObjectCollerction) { // if (doj.getBigDecimal("billentry.tqq9_disandrefoundprice").compareTo(BigDecimal.ZERO) != 0 // && doj.getBigDecimal("billentry.tqq9_hfamount").compareTo(BigDecimal.ZERO) == 0) { // menuNotes.add(doj); // } // } // // 冒泡排序升序排列 // for (int i = 0; i < menuNotes.size() - 1; i++) { // for (int j = 0; j < menuNotes.size() - 1 - i; j++) { // BigDecimal price1 = menuNotes.get(j).getBigDecimal("billentry.tqq9_disprice"); // BigDecimal price2 = menuNotes.get(j + 1).getBigDecimal("billentry.tqq9_disprice"); // if (price1 == null) price1 = BigDecimal.ZERO; // if (price2 == null) price2 = BigDecimal.ZERO; // if (price1.compareTo(price2) > 0) { // // 交换元素 // DynamicObject temp = menuNotes.get(j); // menuNotes.set(j, menuNotes.get(j + 1)); // menuNotes.set(j + 1, temp); // } // } // } // DynamicObject minPricesObj = menuNotes.get(0); // getModel().setValue("tqq9_costprice", minPricesObj.getBigDecimal("billentry.tqq9_disprice"), rowIndex); } } if (StringUtils.equals("priceandtax", name)) { ChangeData changeData = e.getChangeSet()[0]; int rowIndex = changeData.getRowIndex(); int seq = rowIndex; BigDecimal newValue = (BigDecimal) changeData.getNewValue(); BigDecimal tqq9_zgcgxj = (BigDecimal) getModel().getValue("tqq9_zgcgxj", seq); if (newValue.compareTo(tqq9_zgcgxj) > 0 && tqq9_zgcgxj.compareTo(BigDecimal.ZERO) > 0) { getModel().setValue("priceandtax", 0, seq); this.getView().showErrorNotification("物料明细分录行" + seq + "含税单价超过最高采购限价,请修改"); } } if (StringUtils.equals("supplier", name)) { LCLogService lcLogService = new LCLogServiceImpl(); HashMap tokenMap = new HashMap(); tokenMap.put("Authorization", FLXT_TOKEN); IDataModel model = this.getModel(); ChangeData changeData = e.getChangeSet()[0]; DynamicObject newValue = (DynamicObject) changeData.getNewValue();//供应商 DynamicObject org = (DynamicObject) model.getValue("org");//组织 if (newValue != null && org != null) { String number = org.getString("number"); DynamicObject org_fl = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name", new QFilter[]{new QFilter("number", QCP.equals, number)}); if (org_fl == null) { this.getView().showErrorNotification("组织选择错误"); } String orgid_fl = org_fl != null ? org_fl.getString("name") : null; HashMap queryMap = new HashMap<>(); String tqq9_ztsupplierid = newValue.getString("tqq9_ztsupplierid"); if (StringUtils.isBlank(tqq9_ztsupplierid)) { tqq9_ztsupplierid = "0"; } queryMap.put("supplierId", tqq9_ztsupplierid); queryMap.put("companyId", orgid_fl); Gson gson = new Gson(); try { String bodyString = HttpRequestUtils.doGet(URL, queryMap, tokenMap); HashMap map = gson.fromJson(bodyString, HashMap.class); ArrayList> data = (ArrayList) map.get("data"); if (data != null) { for (Map datum : data) { Map dataMap = datum; String type = dataMap.get("type").toString();//类型 BigDecimal totalMoney = new BigDecimal((Double) dataMap.get("totalMoney"));//剩余总金额 BigDecimal totalMoneyAvailable = new BigDecimal((Double) dataMap.get("totalMoneyAvailable"));//可使用金额 if (StringUtils.equals(type, "0.0")) { //货返 model.setValue("tqq9_hshfzje", totalMoney);//含税货返总金额 model.setValue("tqq9_hshfkyje", totalMoneyAvailable);//含税货返可用金额 } else if (StringUtils.equals(type, "1.0")) { //现返 model.setValue("tqq9_hsxfzje", totalMoney);//含税现返总金额 model.setValue("tqq9_hsxfkyje", totalMoneyAvailable);//含税现返可用金额 } } lcLogService.savelog("查询返利金额", URL, false, true, queryMap.toString(), bodyString); } } catch (IOException ex) { lcLogService.savelog("查询返利金额", URL, false, false, queryMap.toString(), "接口调用报错,无返回值"); throw new RuntimeException(ex + ",请求返利系统失败"); } getView().updateView(); } } } @Override public void beforeDoOperation(BeforeDoOperationEventArgs args) { super.beforeDoOperation(args); FormOperate formOperate = (FormOperate)args.getSource(); if ( StringUtils.equals("save", formOperate.getOperateKey())) { DynamicObject dataEntity = this.getModel().getDataEntity(true); BigDecimal tqq9_payamount = dataEntity.getBigDecimal("tqq9_payamount"); if (tqq9_payamount.compareTo(BigDecimal.ZERO) == 0) { DynamicObjectCollection purbillentry_pay = dataEntity.getDynamicObjectCollection("purbillentry_pay"); purbillentry_pay.clear(); SaveServiceHelper.save(new DynamicObject[]{dataEntity}); } } } }