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

119 lines
6.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.events.PropertyChangedArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* 采购订单
* 值改变事件现返、货返金额分摊付款比例不超过100%
*/
public class PuroderBillShareRefundPlugin extends AbstractBillPlugIn {
private final static Log logger = LogFactory.getLog(PuroderBillShareRefundPlugin.class);
@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){
BigDecimal totalallamount = dataEntity.getBigDecimal("totalallamount");//单头价税合计
DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry");
if(billentries != null && billentries.size() > 0){
BigDecimal remainRefundAmt = tqq9_hsxfsyje;//拆分后剩余的金额
for (int i = 0; i <= billentries.size() - 1; i++) {
DynamicObject billentry = billentries.get(i);
if(i == billentries.size() - 1){
//如果是最后一行
this.getModel().setValue("tqq9_xfamount", remainRefundAmt, i);//明细现返使用金额
}else{
//如果不是最后一行
BigDecimal amountandtax = billentry.getBigDecimal("amountandtax");//明细价税合计
BigDecimal tqq9_xfamount = tqq9_hsxfsyje.multiply(amountandtax).divide(totalallamount, 2, RoundingMode.HALF_UP);//分录行含税金额比例
this.getModel().setValue("tqq9_xfamount", tqq9_xfamount, i);//明细现返使用金额
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){
BigDecimal totalallamount = dataEntity.getBigDecimal("totalallamount");//单头价税合计
DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry");
if(billentries != null && billentries.size() > 0){
BigDecimal remainRefundAmt = tqq9_hshfsyje;//拆分后剩余的金额
for (int i = 0; i <= billentries.size() - 1; i++) {
DynamicObject billentry = billentries.get(i);
if(i == billentries.size() - 1){
//如果是最后一行
this.getModel().setValue("tqq9_hfamount", remainRefundAmt, i);//明细货返使用金额
}else{
//如果不是最后一行
BigDecimal amountandtax = billentry.getBigDecimal("amountandtax");//明细价税合计
BigDecimal tqq9_hfamount = tqq9_hshfsyje.multiply(amountandtax).divide(totalallamount, 2, RoundingMode.HALF_UP);//分录行含税金额比例
this.getModel().setValue("tqq9_hfamount", tqq9_hfamount, i);//明细货返使用金额
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){
BigDecimal totalallamount = dataEntity.getBigDecimal("totalallamount");//单头价税合计
DynamicObjectCollection billentries = dataEntity.getDynamicObjectCollection("billentry");
if(billentries != null && billentries.size() > 0){
BigDecimal remainRefundAmt = tqq9_discountamount;//拆分后剩余的金额
for (int i = 0; i <= billentries.size() - 1; i++) {
DynamicObject billentry = billentries.get(i);
if(i == billentries.size() - 1){
//如果是最后一行
this.getModel().setValue("tqq9_disamount", remainRefundAmt, i);//明细优惠金额
}else{
//如果不是最后一行
BigDecimal amountandtax = billentry.getBigDecimal("amountandtax");//明细价税合计
BigDecimal tqq9_disamount = tqq9_discountamount.multiply(amountandtax).divide(totalallamount, 2, RoundingMode.HALF_UP);//分录行含税金额比例
this.getModel().setValue("tqq9_disamount", tqq9_disamount, i);//明细优惠金额
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%,请修改");
}
}
}
}