lc/lc123/cloud/app/plugin/form/pm/PuroderBillShareRefundPlugi...

315 lines
18 KiB
Java
Raw Normal View History

2025-07-16 08:53:24 +00:00
package tqq9.lc123.cloud.app.plugin.form.pm;
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.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
/**
* 采购订单
* 值改变事件现返货返金额分摊付款比例不超过100%
*/
public class PuroderBillShareRefundPlugin extends AbstractBillPlugIn {
private final static Log logger = LogFactory.getLog(PuroderBillShareRefundPlugin.class);
private final static String ENTRYENTITY = "billentry";
@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();
2025-08-14 09:05:29 +00:00
this.getModel().setValue("discounttype", "C", rowIndex);
}
}
}
}
@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<Integer> 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);//明细现返使用金额
2025-08-14 09:05:29 +00:00
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<Integer> 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);//明细货返使用金额
2025-08-14 09:05:29 +00:00
remainRefundAmt = remainRefundAmt.subtract(tqq9_hfamount);
}
}
}
}
}
this.getView().updateView("billentry");
}
if ("tqq9_discountamount".equals(name)) {
//优惠金额
2025-07-31 10:07:09 +00:00
BigDecimal tqq9_discountamount = dataEntity.getBigDecimal(name);//单头优惠金额
if (tqq9_discountamount.compareTo(BigDecimal.ZERO) > 0) {
DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry");
if (billentries != null && billentries.size() > 0) {
2025-07-31 10:07:09 +00:00
BigDecimal remainRefundAmt = tqq9_discountamount;//拆分后剩余的金额
List<Integer> 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);//明细优惠金额
2025-08-14 09:05:29 +00:00
} else {
BigDecimal tqq9_disamount = tqq9_discountamount.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例
this.getModel().setValue("tqq9_disamount", tqq9_disamount, seq);//明细优惠金额
2025-08-14 09:05:29 +00:00
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<Integer> 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);//明细现返使用金额
2025-08-14 09:05:29 +00:00
} else {
BigDecimal tqq9_xfamount = tqq9_hsxfsyje.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例
this.getModel().setValue("tqq9_xfamount", tqq9_xfamount, seq);//明细现返使用金额
2025-08-14 09:05:29 +00:00
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);//明细货返使用金额
2025-08-14 09:05:29 +00:00
} else {
BigDecimal tqq9_hfamount = tqq9_hshfsyje.multiply(tqq9_amount).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例
this.getModel().setValue("tqq9_hfamount", tqq9_hfamount, seq);//明细货返使用金额
2025-08-14 09:05:29 +00:00
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);//
2025-08-14 09:05:29 +00:00
} 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);//
2025-08-14 09:05:29 +00:00
remainRefundAmt_yh = remainRefundAmt_yh.subtract(tqq9_disamount);
}
}
}
}
}
this.getView().updateView("billentry");
}
2025-08-14 09:05:29 +00:00
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");
DynamicObject masterid = material.getDynamicObject("masterid");
DynamicObject bd_material = BusinessDataServiceHelper.loadSingle(masterid.getLong("id"), "bd_material");
DynamicObject org = dataEntity.getDynamicObject("org");
//上海
2025-08-14 09:05:29 +00:00
if (StringUtils.equals("SHLC", org.getString("number"))) {
BigDecimal tqq9_maxprice_sh = bd_material.getBigDecimal("tqq9_maxprice_sh");
2025-08-14 09:05:29 +00:00
if (tqq9_maxprice_sh.compareTo(BigDecimal.ZERO) > 0) {
getModel().setValue("priceandtax", tqq9_maxprice_sh, rowIndex);
getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_sh, rowIndex);
}
2025-08-14 09:05:29 +00:00
//北京
} else if (StringUtils.equals("BJLC", org.getString("number"))) {
BigDecimal tqq9_maxprice_bj = bd_material.getBigDecimal("tqq9_maxprice_bj");
2025-08-14 09:05:29 +00:00
if (tqq9_maxprice_bj.compareTo(BigDecimal.ZERO) > 0) {
getModel().setValue("priceandtax", tqq9_maxprice_bj, rowIndex);
getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_bj, rowIndex);
}
2025-08-14 09:05:29 +00:00
//广州
} else if (StringUtils.equals("GZLC", org.getString("number"))) {
BigDecimal tqq9_maxprice_gz = bd_material.getBigDecimal("tqq9_maxprice_gz");
2025-08-14 09:05:29 +00:00
if (tqq9_maxprice_gz.compareTo(BigDecimal.ZERO) > 0) {
getModel().setValue("priceandtax", tqq9_maxprice_gz, rowIndex);
getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_gz, rowIndex);
}
}
}
2025-08-14 09:05:29 +00:00
if (StringUtils.equals("priceandtax", name)) {
ChangeData changeData = e.getChangeSet()[0];
int rowIndex = changeData.getRowIndex();
int seq = rowIndex;
2025-08-14 09:05:29 +00:00
BigDecimal newValue = (BigDecimal) changeData.getNewValue();
BigDecimal tqq9_zgcgxj = (BigDecimal) getModel().getValue("tqq9_zgcgxj",seq);
2025-08-14 09:05:29 +00:00
if (newValue.compareTo(tqq9_zgcgxj) > 0 && tqq9_zgcgxj.compareTo(BigDecimal.ZERO) > 0) {
getModel().setValue("priceandtax", 0,seq);
2025-08-14 09:05:29 +00:00
this.getView().showErrorNotification("物料明细分录行" + seq + "含税单价超过最高采购限价,请修改");
}
}
}
}