|
|
|
|
@ -0,0 +1,104 @@
|
|
|
|
|
package zcgj.zcdev.zcdev.pr.plugin.form;
|
|
|
|
|
|
|
|
|
|
import kd.bos.bill.AbstractBillPlugIn;
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
|
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
|
|
|
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
|
|
|
|
import kd.bos.form.control.events.ItemClickEvent;
|
|
|
|
|
import kd.bos.orm.query.QCP;
|
|
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.EventObject;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 收入合同结算单表单插件
|
|
|
|
|
*/
|
|
|
|
|
public class EcInContractSettleFormPlugin extends AbstractBillPlugIn {
|
|
|
|
|
@Override
|
|
|
|
|
public void registerListener(EventObject e) {
|
|
|
|
|
super.registerListener(e);
|
|
|
|
|
this.addItemClickListeners("payitemdetaitoolap");//合同支付项明细工具栏
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void propertyChanged(PropertyChangedArgs e) {
|
|
|
|
|
super.propertyChanged(e);
|
|
|
|
|
String key = e.getProperty().getName();
|
|
|
|
|
if ("totalsettletaxamount".equals(key)) {
|
|
|
|
|
// 处理总税额变更事件,更新计量汇总数据
|
|
|
|
|
updateMeteringSummary();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void itemClick(ItemClickEvent evt) {
|
|
|
|
|
super.itemClick(evt);
|
|
|
|
|
String itemKey = evt.getItemKey();
|
|
|
|
|
if (itemKey.equals("advconbaritemap3")) {
|
|
|
|
|
// 处理工具栏按钮点击事件,更新计量汇总数据
|
|
|
|
|
updateMeteringSummary();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新计量汇总数据
|
|
|
|
|
* 根据合同支付项明细中的关联单据,获取对应的收入合同计量数据,
|
|
|
|
|
* 并按税率分组合并生成计量汇总信息
|
|
|
|
|
*/
|
|
|
|
|
private void updateMeteringSummary() {
|
|
|
|
|
// 获取合同支付项明细和计量汇总集合
|
|
|
|
|
DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).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 (int i = 0; i < payItemDetailEntryCollection.size(); i++) {
|
|
|
|
|
DynamicObject payItemDetailEntry = payItemDetailEntryCollection.get(i);
|
|
|
|
|
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 (int i1 = 0; i1 < listEntryCollection.size(); i1++) {
|
|
|
|
|
DynamicObject listEntry = listEntryCollection.get(i1);
|
|
|
|
|
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_taxamt", sumMap.get("thistax")); // 税额合计
|
|
|
|
|
newEntry.set("zcgj_pa_amount", sumMap.get("thisoftaxmount")); // 含税金额合计
|
|
|
|
|
meteringSummaryCollection.add(newEntry);
|
|
|
|
|
}
|
|
|
|
|
this.getView().updateView("zcgj_metering_summary");
|
|
|
|
|
}
|
|
|
|
|
}
|