收入合同确认单优化计量汇总分录赋值逻辑
This commit is contained in:
parent
75f7112c7d
commit
d9967c2bb9
|
|
@ -6,6 +6,7 @@ import kd.bos.bill.OperationStatus;
|
|||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.datamodel.events.ChangeData;
|
||||
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||
|
|
@ -29,9 +30,7 @@ import kd.sdk.plugin.Plugin;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 收入合同确认单插件
|
||||
|
|
@ -94,15 +93,50 @@ public class InContractFinaceConfirmePlugin extends AbstractBillPlugIn implement
|
|||
item.set("zcgj_remark",dynamicObject.getString("remark"));
|
||||
}
|
||||
|
||||
DynamicObjectCollection meteringSummaryCollection1 = ecincontractsettle.getDynamicObjectCollection("zcgj_metering_summary");//计量汇总
|
||||
DynamicObjectCollection meteringSummaryCollection2 = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_metering_summary");//计量汇总
|
||||
meteringSummaryCollection2.clear();
|
||||
for (DynamicObject meteringSummary1 : meteringSummaryCollection1){
|
||||
DynamicObject newMeteringSummary = meteringSummaryCollection2.addNew();
|
||||
newMeteringSummary.set("zcgj_rateval",meteringSummary1.getBigDecimal("zcgj_rateval"));
|
||||
newMeteringSummary.set("zcgj_pa_amount",meteringSummary1.getBigDecimal("zcgj_pa_amount"));
|
||||
newMeteringSummary.set("zcgj_amountnotax",meteringSummary1.getBigDecimal("zcgj_amountnotax"));
|
||||
newMeteringSummary.set("zcgj_taxamt1",meteringSummary1.getBigDecimal("zcgj_taxamt"));
|
||||
DynamicObjectCollection payItemDetailEntryCollection = ecincontractsettle.getDynamicObjectCollection("payitemdetailentry");//合同支付项明细
|
||||
DynamicObjectCollection meteringSummaryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_metering_summary");//计量汇总
|
||||
meteringSummaryCollection.clear();
|
||||
DynamicObjectType meteringSummaryType = meteringSummaryCollection.getDynamicObjectType();
|
||||
|
||||
// 创建全局Map按税率分组存储合并数据,用于累计所有payitemdetailentry的数据
|
||||
Map<BigDecimal, Map<String, BigDecimal>> globalRateGroupMap = new HashMap<>();
|
||||
|
||||
for (DynamicObject payItemDetailEntry : payItemDetailEntryCollection) {
|
||||
String referBillNumber = payItemDetailEntry.getString("referbillnumber");//关联单据
|
||||
QFilter[] qFilters = new QFilter[]{new QFilter("billno", QCP.equals, referBillNumber)};
|
||||
DynamicObject ec_incontractmeasure = BusinessDataServiceHelper.loadSingle("ec_incontractmeasure", qFilters);//收入合同计量
|
||||
if (ec_incontractmeasure != null) {
|
||||
DynamicObjectCollection listModelEntryCollection = ec_incontractmeasure.getDynamicObjectCollection("listmodelentry");//模板分录
|
||||
DynamicObjectCollection listEntryCollection = listModelEntryCollection.get(0).getDynamicObjectCollection("listentry");//清单分录
|
||||
|
||||
// 遍历当前收入合同计量的清单分录
|
||||
for (DynamicObject listEntry : listEntryCollection) {
|
||||
BigDecimal entrytaxrate = listEntry.getBigDecimal("entrytaxrate");// 税率(%)
|
||||
BigDecimal thisamount = listEntry.getBigDecimal("thisamount");// 本期计量金额
|
||||
BigDecimal thistax = listEntry.getBigDecimal("thistax");// 本期税额
|
||||
BigDecimal thisoftaxmount = listEntry.getBigDecimal("thisoftaxmount");// 本期计量含税金额
|
||||
|
||||
// 使用全局Map按税率分组,累加各金额字段
|
||||
Map<String, BigDecimal> sumMap = globalRateGroupMap.computeIfAbsent(entrytaxrate, k -> new HashMap<>());
|
||||
sumMap.merge("thisamount", thisamount, BigDecimal::add);
|
||||
sumMap.merge("thistax", thistax, BigDecimal::add);
|
||||
sumMap.merge("thisoftaxmount", thisoftaxmount, BigDecimal::add);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 循环结束后,使用全局累计数据生成最终的计量汇总行
|
||||
for (Map.Entry<BigDecimal, Map<String, BigDecimal>> entry : globalRateGroupMap.entrySet()) {
|
||||
DynamicObject newEntry = new DynamicObject(meteringSummaryType);
|
||||
BigDecimal rate = entry.getKey();
|
||||
Map<String, BigDecimal> sumMap = entry.getValue();
|
||||
|
||||
// 设置合并后的值到新行
|
||||
newEntry.set("zcgj_rateval", rate); // 税率
|
||||
newEntry.set("zcgj_amountnotax", sumMap.get("thisamount")); // 不含税金额合计
|
||||
newEntry.set("zcgj_taxamt1", sumMap.get("thistax")); // 税额合计
|
||||
newEntry.set("zcgj_pa_amount", sumMap.get("thisoftaxmount")); // 含税金额合计
|
||||
meteringSummaryCollection.add(newEntry);
|
||||
}
|
||||
|
||||
this.getView().updateView("zcgj_itementry");
|
||||
|
|
|
|||
Loading…
Reference in New Issue