支出合同结算入库单分录增行删行赋值逻辑优化

This commit is contained in:
xuhaihui 2025-08-26 17:16:00 +08:00
parent f0e0f6f0c0
commit 04cccc019f
1 changed files with 290 additions and 262 deletions

View File

@ -29,90 +29,32 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
this.addItemClickListeners("entrytoolbar1");//入库单明细工具栏 this.addItemClickListeners("entrytoolbar1");//入库单明细工具栏
} }
@Override
public void propertyChanged(PropertyChangedArgs e) {
super.propertyChanged(e);
String name = e.getProperty().getName();
if ("totalsettleoftaxamount".equals(name) || "contract".equals(name)) {
//累计结算金额含当期价税合计合同名称
handleContractPropertyChange(e);
} else if ("matinnumber".equals(name)) {
//入库单分录-编码
handleMaterialInPropertyChange();
}
}
@Override @Override
public void itemClick(ItemClickEvent evt) { public void itemClick(ItemClickEvent evt) {
super.itemClick(evt); super.itemClick(evt);
String itemKey = evt.getItemKey(); String itemKey = evt.getItemKey();
if (itemKey.equals("advconbaritemap3")) { if (itemKey.equals("advconbaritemap3")) {
//合同支付项明细删除按钮 //合同支付项明细删除按钮
handleContractPaymentItemDelete(); DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");//合同支付项明细
} else if (itemKey.equals("removeline1")) {
//入库单明细删除按钮
handleMaterialInDelete();
}
}
/**
* 处理合同支付项明细删除
*/
private void handleContractPaymentItemDelete() {
DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");
if (itemEntryCollection.size() == 0) {
return;
}
if (payItemDetailEntryCollection.size() > 0) {
processContractPaymentItems(itemEntryCollection.get(0), payItemDetailEntryCollection);
this.getView().updateView("zcgj_processallocatentity");//工序分摊
} else {
clearProcessAllocData(itemEntryCollection.get(0));
this.getView().updateView("itementry");//支付项分录
this.getView().updateView("zcgj_processallocatentity");//工序分摊
}
}
/**
* 处理入库单明细删除
*/
private void handleMaterialInDelete() {
DynamicObjectCollection materialInEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("materialinentry");//入库单分录
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录 DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录
if (itemEntryCollection.size() == 0) { if (itemEntryCollection.size() == 0) {
return; return;
} }
if (payItemDetailEntryCollection.size() > 0) {
for (DynamicObject payItemDetailEntry : payItemDetailEntryCollection) {
if (materialInEntryCollection.size() > 0) { DynamicObject itemEntry = itemEntryCollection.get(0);
processMaterialInItems(itemEntryCollection.get(0), materialInEntryCollection); DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
} else {
clearProcessAllocData(itemEntryCollection.get(0));
this.getView().updateView("itementry");//支付项分录
this.getView().updateView("zcgj_processallocatentity");//工序分摊
}
}
/**
* 处理合同支付项数据
*/
private void processContractPaymentItems(DynamicObject itemEntry, DynamicObjectCollection payItemDetailEntryCollection) {
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");
processAllocEntityCollection.clear(); processAllocEntityCollection.clear();
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType(); DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
for (DynamicObject payItemDetailEntry : payItemDetailEntryCollection) { long referBillId = payItemDetailEntry.getLong("referbillid");//关联单据id
long referBillId = payItemDetailEntry.getLong("referbillid");//合同支付项明细-关联单据id
QFilter qFilter = new QFilter("id", QCP.equals, referBillId); QFilter qFilter = new QFilter("id", QCP.equals, referBillId);
DynamicObject ecOutContractMeasure = BusinessDataServiceHelper.loadSingle("ec_outcontractmeasure", new QFilter[]{qFilter});//支出合同计量 DynamicObject EcOutContractMeasure = BusinessDataServiceHelper.loadSingle("ec_outcontractmeasure", new QFilter[]{qFilter});//支出合同计量
if (EcOutContractMeasure != null) {
if (ecOutContractMeasure != null) { DynamicObjectCollection ListModelEntryCollection = EcOutContractMeasure.getDynamicObjectCollection("listmodelentry");//模板分录
DynamicObjectCollection listModelEntryCollection = ecOutContractMeasure.getDynamicObjectCollection("listmodelentry");//模板分录 for (DynamicObject ListModelEntry : ListModelEntryCollection) {
for (DynamicObject listModelEntry : listModelEntryCollection) { DynamicObjectCollection listEntryCollection = ListModelEntry.getDynamicObjectCollection("listentry");//清单分录
DynamicObjectCollection listEntryCollection = listModelEntry.getDynamicObjectCollection("listentry");//模板分录-清单分录
for (DynamicObject listEntry : listEntryCollection) { for (DynamicObject listEntry : listEntryCollection) {
DynamicObject newProcessAllocEntity = new DynamicObject(processAllocEntityType); DynamicObject newProcessAllocEntity = new DynamicObject(processAllocEntityType);
newProcessAllocEntity.set("zcgj_pa_process", listEntry.get("listcbs"));//工序-成本分解结构 newProcessAllocEntity.set("zcgj_pa_process", listEntry.get("listcbs"));//工序-成本分解结构
@ -124,27 +66,34 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
} }
} }
} }
} // 添加合并逻辑按工序和税率组合合并相同项
// 按工序和税率组合合并相同项
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection); mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
} }
this.getView().updateView("zcgj_processallocatentity");//工序分摊
/** } else {
* 处理入库单数据 DynamicObjectCollection processAllocEntityCollection = itemEntryCollection.get(0).getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊分录
*/ processAllocEntityCollection.clear();
private void processMaterialInItems(DynamicObject itemEntry, DynamicObjectCollection materialInEntryCollection) { this.getView().updateView("itementry");//支付项分录
this.getView().updateView("zcgj_processallocatentity");//工序分摊分录
}
} else if (itemKey.equals("removeline1")) {
//入库单明细删除按钮
DynamicObjectCollection materialInEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("materialinentry");//入库单分录
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录
if (itemEntryCollection.size() == 0) {
return;
}
if (materialInEntryCollection.size() > 0) {
DynamicObject itemEntry = itemEntryCollection.get(0);
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊 DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
processAllocEntityCollection.clear(); processAllocEntityCollection.clear();
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType(); DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
for (DynamicObject materialInEntry : materialInEntryCollection) { for (DynamicObject materialInEntry : materialInEntryCollection) {
String matInNumber = materialInEntry.getString("matinnumber");//入库单分录-编码 String matInNumber = materialInEntry.getString("matinnumber");//入库单编码
QFilter qFilter = new QFilter("billno", QCP.equals, matInNumber); QFilter qFilter = new QFilter("billno", QCP.equals, matInNumber);
DynamicObject ecmaMaterialInBill = BusinessDataServiceHelper.loadSingle("ecma_materialinbill", new QFilter[]{qFilter});//入库单 DynamicObject ecma_materialInBill = BusinessDataServiceHelper.loadSingle("ecma_materialinbill", new QFilter[]{qFilter});//入库单
if (ecma_materialInBill != null) {
if (ecmaMaterialInBill != null) { DynamicObjectCollection entryEntityCollection = ecma_materialInBill.getDynamicObjectCollection("entryentity");//入库单分录
DynamicObjectCollection entryEntityCollection = ecmaMaterialInBill.getDynamicObjectCollection("entryentity");//入库单分录
for (DynamicObject entryEntity : entryEntityCollection) { for (DynamicObject entryEntity : entryEntityCollection) {
DynamicObject newProcessAllocEntity = new DynamicObject(processAllocEntityType); DynamicObject newProcessAllocEntity = new DynamicObject(processAllocEntityType);
newProcessAllocEntity.set("zcgj_pa_amount", entryEntity.get("oftaxamount"));//价税合计-含税金额 newProcessAllocEntity.set("zcgj_pa_amount", entryEntity.get("oftaxamount"));//价税合计-含税金额
@ -165,149 +114,159 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
} }
} }
// 按费用项目和税率组合合并相同项 // 添加合并逻辑按费用项目和税率组合合并相同项
mergeProcessAllocEntriesByExpenseItemAndRate(processAllocEntityCollection); mergeProcessAllocEntriesByExpenseItemAndRate(processAllocEntityCollection);
this.getView().updateView("zcgj_processallocatentity");//工序分摊 this.getView().updateView("zcgj_processallocatentity");//刷新工序分摊
} } else {
DynamicObjectCollection processAllocEntityCollection = itemEntryCollection.get(0).getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊分录
/**
* 清空工序分摊数据
*/
private void clearProcessAllocData(DynamicObject itemEntry) {
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
processAllocEntityCollection.clear(); processAllocEntityCollection.clear();
this.getView().updateView("itementry");//支付项分录
this.getView().updateView("zcgj_processallocatentity");//工序分摊分录
}
}
} }
/** @Override
* 处理合同属性变更 public void propertyChanged(PropertyChangedArgs e) {
*/ super.propertyChanged(e);
private void handleContractPropertyChange(PropertyChangedArgs e) { String name = e.getProperty().getName();
if ("totalsettleoftaxamount".equals(name) || "contract".equals(name)) {
//累计结算金额含当期价税合计,合同名称
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");//合同属性 DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");//合同属性
if (contattr == null) { if (contattr == null) {
return; return;
} }
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");//按入库单结算
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");//iseqsettle
if (contattr.getString("number").equals("ZCSX01") && issettlebymatin) { if (contattr.getString("number").equals("ZCSX01") && issettlebymatin) {
return; return;
} }
DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");//合同支付项明细
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录 DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录
if (itemEntryCollection.size() == 0) { if (itemEntryCollection.size() == 0) {
return; return;
} }
DynamicObject itemEntry = itemEntryCollection.get(0); DynamicObject itemEntry = itemEntryCollection.get(0);
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊分录 DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
processAllocEntityCollection.clear(); processAllocEntityCollection.clear();
if ("contract".equals(name)) {
if ("contract".equals(e.getProperty().getName())) { ChangeData changeData = e.getChangeSet()[0]; //修改值所在行
ChangeData changeData = e.getChangeSet()[0]; Object newValue = changeData.getNewValue();//新值
Object newValue = changeData.getNewValue();
if (newValue == null) { if (newValue == null) {
this.getView().updateView("zcgj_processallocatentity");//刷新 this.getView().updateView("zcgj_processallocatentity");//工序分摊
return; return;
} }
} }
Object contract = this.getModel().getValue("contract");
Object contract = this.getModel().getValue("contract");// 合同
if (contract == null) { if (contract == null) {
this.getView().updateView("zcgj_processallocatentity");//刷新 this.getView().updateView("zcgj_processallocatentity");//工序分摊
return; return;
} }
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");
if (payItemDetailEntryCollection.size() > 0) { if (payItemDetailEntryCollection.size() > 0) {
processContractPaymentItems(itemEntry, payItemDetailEntryCollection); for (DynamicObject payItemDetailEntry : payItemDetailEntryCollection) {
}
this.getView().updateView("zcgj_processallocatentity"); long referBillId = payItemDetailEntry.getLong("referbillid");//关联单据id
QFilter qFilter = new QFilter("id", QCP.equals, referBillId);
DynamicObject EcOutContractMeasure = BusinessDataServiceHelper.loadSingle("ec_outcontractmeasure", new QFilter[]{qFilter});//支出合同计量
if (EcOutContractMeasure != null) {
DynamicObjectCollection ListModelEntryCollection = EcOutContractMeasure.getDynamicObjectCollection("listmodelentry");//模板分录
for (DynamicObject ListModelEntry : ListModelEntryCollection) {
DynamicObjectCollection listEntryCollection = ListModelEntry.getDynamicObjectCollection("listentry");//清单分录
for (DynamicObject listEntry : listEntryCollection) {
DynamicObject newProcessAllocEntity = new DynamicObject(processAllocEntityType);
newProcessAllocEntity.set("zcgj_pa_process", listEntry.get("listcbs"));//工序-成本分解结构
newProcessAllocEntity.set("zcgj_pa_amount", listEntry.get("thisoftaxmount"));//价税合计-本期计量含税金额
newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额
newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率%-税率%
newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额
processAllocEntityCollection.add(newProcessAllocEntity);
} }
}
/** }
* 处理入库单属性变更 }
*/ }
private void handleMaterialInPropertyChange() { // 添加合并逻辑按工序和税率组合合并相同项
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
this.getView().updateView("zcgj_processallocatentity");//工序分摊
} else if ("matinnumber".equals(name)) {
//入库单明细-编码
this.getModel().beginInit(); this.getModel().beginInit();
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");//合同属性
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");
if (contattr == null) { if (contattr == null) {
return; return;
} }
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");//按入库单结算
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");
if (!contattr.getString("number").equals("ZCSX01") && !issettlebymatin) { if (!contattr.getString("number").equals("ZCSX01") && !issettlebymatin) {
return; return;
} }
DynamicObject dataEntity = this.getModel().getDataEntity(true); DynamicObject dataEntity = this.getModel().getDataEntity(true);
DynamicObjectCollection materialInEntryCollection = dataEntity.getDynamicObjectCollection("materialinentry"); DynamicObjectCollection materialInEntryCollection = dataEntity.getDynamicObjectCollection("materialinentry");//入库单明细
DynamicObjectCollection itemEntryCollection = dataEntity.getDynamicObjectCollection("itementry"); DynamicObjectCollection itemEntryCollection = dataEntity.getDynamicObjectCollection("itementry");//支付项分录
if (itemEntryCollection.size() == 0) { if (itemEntryCollection.size() == 0) {
return; return;
} }
DynamicObject itemEntry = itemEntryCollection.get(0);
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
processAllocEntityCollection.clear();
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
for (DynamicObject materialInEntry : materialInEntryCollection) {
String matInNumber = materialInEntry.getString("matinnumber");//入库单编码
QFilter qFilter = new QFilter("billno", QCP.equals, matInNumber);
DynamicObject ecma_materialInBill = BusinessDataServiceHelper.loadSingle("ecma_materialinbill", new QFilter[]{qFilter});//入库单
if (ecma_materialInBill != null) {
DynamicObjectCollection entryEntityCollection = ecma_materialInBill.getDynamicObjectCollection("entryentity");//入库单分录
for (DynamicObject entryEntity : entryEntityCollection) {
DynamicObject newProcessAllocEntity = new DynamicObject(processAllocEntityType);
newProcessAllocEntity.set("zcgj_pa_amount", entryEntity.get("oftaxamount"));//价税合计-含税金额
newProcessAllocEntity.set("zcgj_amountnotax", entryEntity.get("notaxamount"));//不含税金额-金额
newProcessAllocEntity.set("zcgj_rateval", entryEntity.getDynamicObject("entrytaxrate").get("taxrate"));//税率%-税率名称
newProcessAllocEntity.set("zcgj_taxamt", entryEntity.get("taxamount"));//税额-税额
processMaterialInItems(itemEntryCollection.get(0), materialInEntryCollection); DynamicObject expenseItem = null;
DynamicObject material = entryEntity.getDynamicObject("material");//入库单分录-资源编码
if (material != null) {
DynamicObject resource = material.getDynamicObject("resource");//入库单分录-资源编码-清单分类
expenseItem = getExpenseItemByResource(resource);
}
newProcessAllocEntity.set("zcgj_expenseitem", expenseItem);//费用项目-对应费用项目
processAllocEntityCollection.add(newProcessAllocEntity);
}
}
}
// 添加合并逻辑按费用项目和税率组合合并相同项
mergeProcessAllocEntriesByExpenseItemAndRate(processAllocEntityCollection);
this.getView().updateView("zcgj_processallocatentity");//刷新工序分摊
this.getModel().endInit(); this.getModel().endInit();
} }
}
/** /**
* 按工序和税率组合合并工序分摊条目 * 按工序和税率组合合并工序分摊条目
*
* @param processAllocEntityCollection 工序分摊集合
*/ */
private void mergeProcessAllocEntriesByProcessAndRate(DynamicObjectCollection processAllocEntityCollection) { private void mergeProcessAllocEntriesByProcessAndRate(DynamicObjectCollection processAllocEntityCollection) {
// 使用Map来存储已存在的工序+税率组合避免嵌套循环
Map<String, DynamicObject> processRateMap = new HashMap<>(); Map<String, DynamicObject> processRateMap = new HashMap<>();
for (int i = 0; i < processAllocEntityCollection.size(); i++) { for (int i = 0; i < processAllocEntityCollection.size(); i++) {
DynamicObject currentEntry = processAllocEntityCollection.get(i); DynamicObject currentEntry = processAllocEntityCollection.get(i);
Object currentProcess = currentEntry.get("zcgj_pa_process"); Object currentProcess = currentEntry.get("zcgj_pa_process"); // 工序
Object currentRate = currentEntry.get("zcgj_rateval"); Object currentRate = currentEntry.get("zcgj_rateval"); // 税率
// 创建唯一键值工序ID + 税率值
String key = (currentProcess != null ? currentProcess.toString() : "null") + String key = (currentProcess != null ? currentProcess.toString() : "null") +
"_" + (currentRate != null ? currentRate.toString() : "null"); "_" +
(currentRate != null ? currentRate.toString() : "null");
if (processRateMap.containsKey(key)) { if (processRateMap.containsKey(key)) {
// 如果已存在相同组合则合并数值
DynamicObject existingEntry = processRateMap.get(key); DynamicObject existingEntry = processRateMap.get(key);
mergeEntryAmounts(existingEntry, currentEntry);
processAllocEntityCollection.remove(i);
i--;
} else {
processRateMap.put(key, currentEntry);
}
}
}
/**
* 按费用项目和税率组合合并工序分摊条目
*/
private void mergeProcessAllocEntriesByExpenseItemAndRate(DynamicObjectCollection processAllocEntityCollection) {
Map<String, DynamicObject> expenseItemRateMap = new HashMap<>();
for (int i = 0; i < processAllocEntityCollection.size(); i++) {
DynamicObject currentEntry = processAllocEntityCollection.get(i);
Object currentExpenseItem = currentEntry.get("zcgj_expenseitem");
Object currentRate = currentEntry.get("zcgj_rateval");
String key = (currentExpenseItem != null ? currentExpenseItem.toString() : "null") +
"_" + (currentRate != null ? currentRate.toString() : "null");
if (expenseItemRateMap.containsKey(key)) {
DynamicObject existingEntry = expenseItemRateMap.get(key);
mergeEntryAmounts(existingEntry, currentEntry);
processAllocEntityCollection.remove(i);
i--;
} else {
expenseItemRateMap.put(key, currentEntry);
}
}
}
/**
* 合并两个条目的金额数据
*/
private void mergeEntryAmounts(DynamicObject existingEntry, DynamicObject currentEntry) {
// 合并价税合计 // 合并价税合计
BigDecimal currentAmount = toBigDecimal(existingEntry.get("zcgj_pa_amount")); BigDecimal currentAmount = toBigDecimal(existingEntry.get("zcgj_pa_amount"));
BigDecimal nextAmount = toBigDecimal(currentEntry.get("zcgj_pa_amount")); BigDecimal nextAmount = toBigDecimal(currentEntry.get("zcgj_pa_amount"));
@ -322,10 +281,22 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
BigDecimal currentTaxAmt = toBigDecimal(existingEntry.get("zcgj_taxamt")); BigDecimal currentTaxAmt = toBigDecimal(existingEntry.get("zcgj_taxamt"));
BigDecimal nextTaxAmt = toBigDecimal(currentEntry.get("zcgj_taxamt")); BigDecimal nextTaxAmt = toBigDecimal(currentEntry.get("zcgj_taxamt"));
existingEntry.set("zcgj_taxamt", currentTaxAmt.add(nextTaxAmt)); existingEntry.set("zcgj_taxamt", currentTaxAmt.add(nextTaxAmt));
// 移除当前条目
processAllocEntityCollection.remove(i);
i--; // 调整索引
} else {
// 如果不存在相同组合则添加到Map中
processRateMap.put(key, currentEntry);
}
}
} }
/** /**
* 将对象转换为BigDecimal类型 * 将对象转换为BigDecimal类型
*
* @param obj 待转换对象
* @return BigDecimal值
*/ */
private BigDecimal toBigDecimal(Object obj) { private BigDecimal toBigDecimal(Object obj) {
if (obj == null) { if (obj == null) {
@ -347,33 +318,42 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
/** /**
* 根据资源编码获取对应的费用项目 * 根据资源编码获取对应的费用项目
*
* @param resource 资源对象
* @return 对应的费用项目
*/ */
private DynamicObject getExpenseItemByResource(DynamicObject resource) { private DynamicObject getExpenseItemByResource(DynamicObject resource) {
if (resource == null) { if (resource == null) {
return null; return null;
} }
String resourceNumber = resource.getString("number"); String resourceNumber = resource.getString("number");//资源编码-清单分类-编码
String expenseItemNumber; String expenseItemNumber = null;
switch (resourceNumber) { switch (resourceNumber) {
case "ZCKS01": case "ZCKS01":
expenseItemNumber = "FYXM006.002.004"; //备品备件 //备品备件
expenseItemNumber = "FYXM006.002.004";
break; break;
case "ZCKS02": case "ZCKS02":
expenseItemNumber = "FYXM006.002.001"; //主材 //主材
expenseItemNumber = "FYXM006.002.001";
break; break;
case "ZCKS03": case "ZCKS03":
expenseItemNumber = "FYXM006.002.006"; //火工材料 //火工材料
expenseItemNumber = "FYXM006.002.006";
break; break;
case "ZCKS04": case "ZCKS04":
expenseItemNumber = "FYXM006.002.002"; //辅材 //辅材
expenseItemNumber = "FYXM006.002.002";
break; break;
case "ZCKS05": case "ZCKS05":
expenseItemNumber = "FYXM006.002.003"; //燃料及动力 //燃料及动力
expenseItemNumber = "FYXM006.002.003";
break; break;
case "ZCKS06": case "ZCKS06":
expenseItemNumber = "FYXM006.002.002"; //劳保用品类 //劳保用品类
expenseItemNumber = "FYXM006.002.002";
break; break;
default: default:
return null; return null;
@ -382,4 +362,52 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
return BusinessDataServiceHelper.loadSingle("er_expenseitemedit", "id", return BusinessDataServiceHelper.loadSingle("er_expenseitemedit", "id",
new QFilter[]{new QFilter("number", QCP.equals, expenseItemNumber)}); new QFilter[]{new QFilter("number", QCP.equals, expenseItemNumber)});
} }
/**
* 按费用项目和税率组合合并工序分摊条目
*
* @param processAllocEntityCollection 工序分摊集合
*/
private void mergeProcessAllocEntriesByExpenseItemAndRate(DynamicObjectCollection processAllocEntityCollection) {
// 使用Map来存储已存在的费用项目+税率组合避免嵌套循环
Map<String, DynamicObject> expenseItemRateMap = new HashMap<>();
for (int i = 0; i < processAllocEntityCollection.size(); i++) {
DynamicObject currentEntry = processAllocEntityCollection.get(i);
Object currentExpenseItem = currentEntry.get("zcgj_expenseitem"); // 费用项目
Object currentRate = currentEntry.get("zcgj_rateval"); // 税率
// 创建唯一键值费用项目ID + 税率值
String key = (currentExpenseItem != null ? currentExpenseItem.toString() : "null") +
"_" +
(currentRate != null ? currentRate.toString() : "null");
if (expenseItemRateMap.containsKey(key)) {
// 如果已存在相同组合则合并数值
DynamicObject existingEntry = expenseItemRateMap.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中
expenseItemRateMap.put(key, currentEntry);
}
}
}
} }