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

103 lines
5.8 KiB
Java

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.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
* 采购订单
* 现返、货返金额分摊
*/
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");
}
}
}