支出合同结算表单插件工序分摊逻辑优化
This commit is contained in:
parent
ad460d8b80
commit
bdfb0c1658
|
@ -11,7 +11,10 @@ import kd.bos.form.control.events.ItemClickEvent;
|
||||||
import kd.bos.form.plugin.AbstractFormPlugin;
|
import kd.bos.form.plugin.AbstractFormPlugin;
|
||||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.EventObject;
|
import java.util.EventObject;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 使用插件注册位置:支出合同结算表单插件
|
* 使用插件注册位置:支出合同结算表单插件
|
||||||
|
@ -57,11 +60,12 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
|
||||||
newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额
|
newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额
|
||||||
newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率(%)-税率(%)
|
newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率(%)-税率(%)
|
||||||
newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额
|
newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额
|
||||||
newProcessAllocEntity.set("zcgj_pa_remark", listEntry.get("desc"));//费用说明-说明
|
|
||||||
processAllocEntityCollection.add(newProcessAllocEntity);
|
processAllocEntityCollection.add(newProcessAllocEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 添加合并逻辑:按工序和税率组合合并相同项
|
||||||
|
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
|
||||||
}
|
}
|
||||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||||
} else {
|
} else {
|
||||||
|
@ -124,14 +128,87 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
|
||||||
newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额
|
newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额
|
||||||
newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率(%)-税率(%)
|
newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率(%)-税率(%)
|
||||||
newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额
|
newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额
|
||||||
newProcessAllocEntity.set("zcgj_pa_remark", listEntry.get("desc"));//费用说明-说明
|
|
||||||
processAllocEntityCollection.add(newProcessAllocEntity);
|
processAllocEntityCollection.add(newProcessAllocEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 添加合并逻辑:按工序和税率组合合并相同项
|
||||||
|
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
|
||||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按工序和税率组合合并工序分摊条目
|
||||||
|
*
|
||||||
|
* @param processAllocEntityCollection 工序分摊集合
|
||||||
|
*/
|
||||||
|
private void mergeProcessAllocEntriesByProcessAndRate(DynamicObjectCollection processAllocEntityCollection) {
|
||||||
|
// 使用Map来存储已存在的工序+税率组合,避免嵌套循环
|
||||||
|
Map<String, DynamicObject> processRateMap = new HashMap<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < processAllocEntityCollection.size(); i++) {
|
||||||
|
DynamicObject currentEntry = processAllocEntityCollection.get(i);
|
||||||
|
Object currentProcess = currentEntry.get("zcgj_pa_process"); // 工序
|
||||||
|
Object currentRate = currentEntry.get("zcgj_rateval"); // 税率
|
||||||
|
|
||||||
|
// 创建唯一键值:工序ID + 税率值
|
||||||
|
String key = (currentProcess != null ? currentProcess.toString() : "null") +
|
||||||
|
"_" +
|
||||||
|
(currentRate != null ? currentRate.toString() : "null");
|
||||||
|
|
||||||
|
if (processRateMap.containsKey(key)) {
|
||||||
|
// 如果已存在相同组合,则合并数值
|
||||||
|
DynamicObject existingEntry = processRateMap.get(key);
|
||||||
|
|
||||||
|
// 合并价税合计
|
||||||
|
BigDecimal currentAmount = toBigDecimal(existingEntry.get("zcgj_pa_amount"));
|
||||||
|
BigDecimal nextAmount = toBigDecimal(currentEntry.get("zcgj_pa_amount"));
|
||||||
|
existingEntry.set("zcgj_pa_amount", currentAmount.add(nextAmount));
|
||||||
|
|
||||||
|
// 合并不含税金额
|
||||||
|
BigDecimal currentAmountNoTax = toBigDecimal(existingEntry.get("zcgj_amountnotax"));
|
||||||
|
BigDecimal nextAmountNoTax = toBigDecimal(currentEntry.get("zcgj_amountnotax"));
|
||||||
|
existingEntry.set("zcgj_amountnotax", currentAmountNoTax.add(nextAmountNoTax));
|
||||||
|
|
||||||
|
// 合并税额
|
||||||
|
BigDecimal currentTaxAmt = toBigDecimal(existingEntry.get("zcgj_taxamt"));
|
||||||
|
BigDecimal nextTaxAmt = toBigDecimal(currentEntry.get("zcgj_taxamt"));
|
||||||
|
existingEntry.set("zcgj_taxamt", currentTaxAmt.add(nextTaxAmt));
|
||||||
|
|
||||||
|
// 移除当前条目
|
||||||
|
processAllocEntityCollection.remove(i);
|
||||||
|
i--; // 调整索引
|
||||||
|
} else {
|
||||||
|
// 如果不存在相同组合,则添加到Map中
|
||||||
|
processRateMap.put(key, currentEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将对象转换为BigDecimal类型
|
||||||
|
*
|
||||||
|
* @param obj 待转换对象
|
||||||
|
* @return BigDecimal值
|
||||||
|
*/
|
||||||
|
private BigDecimal toBigDecimal(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj instanceof BigDecimal) {
|
||||||
|
return (BigDecimal) obj;
|
||||||
|
} else if (obj instanceof Number) {
|
||||||
|
return new BigDecimal(obj.toString());
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
return new BigDecimal(obj.toString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue