支出合同结算入库单分录增行删行赋值逻辑优化
This commit is contained in:
parent
f0e0f6f0c0
commit
04cccc019f
|
@ -29,90 +29,32 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
|
|||
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
|
||||
public void itemClick(ItemClickEvent evt) {
|
||||
super.itemClick(evt);
|
||||
String itemKey = evt.getItemKey();
|
||||
if (itemKey.equals("advconbaritemap3")) {
|
||||
//合同支付项明细删除按钮
|
||||
handleContractPaymentItemDelete();
|
||||
} 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 payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");//合同支付项明细
|
||||
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录
|
||||
|
||||
if (itemEntryCollection.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if (payItemDetailEntryCollection.size() > 0) {
|
||||
for (DynamicObject payItemDetailEntry : payItemDetailEntryCollection) {
|
||||
|
||||
if (materialInEntryCollection.size() > 0) {
|
||||
processMaterialInItems(itemEntryCollection.get(0), materialInEntryCollection);
|
||||
} 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");
|
||||
DynamicObject itemEntry = itemEntryCollection.get(0);
|
||||
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
|
||||
processAllocEntityCollection.clear();
|
||||
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);
|
||||
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");//模板分录-清单分录
|
||||
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"));//工序-成本分解结构
|
||||
|
@ -124,27 +66,34 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 按工序和税率组合合并相同项
|
||||
// 添加合并逻辑:按工序和税率组合合并相同项
|
||||
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理入库单数据
|
||||
*/
|
||||
private void processMaterialInItems(DynamicObject itemEntry, DynamicObjectCollection materialInEntryCollection) {
|
||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||
} else {
|
||||
DynamicObjectCollection processAllocEntityCollection = itemEntryCollection.get(0).getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊分录
|
||||
processAllocEntityCollection.clear();
|
||||
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");//工序分摊
|
||||
processAllocEntityCollection.clear();
|
||||
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
|
||||
|
||||
for (DynamicObject materialInEntry : materialInEntryCollection) {
|
||||
String matInNumber = materialInEntry.getString("matinnumber");//入库单分录-编码
|
||||
String matInNumber = materialInEntry.getString("matinnumber");//入库单编码
|
||||
QFilter qFilter = new QFilter("billno", QCP.equals, matInNumber);
|
||||
DynamicObject ecmaMaterialInBill = BusinessDataServiceHelper.loadSingle("ecma_materialinbill", new QFilter[]{qFilter});//入库单
|
||||
|
||||
if (ecmaMaterialInBill != null) {
|
||||
DynamicObjectCollection entryEntityCollection = ecmaMaterialInBill.getDynamicObjectCollection("entryentity");//入库单分录
|
||||
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"));//价税合计-含税金额
|
||||
|
@ -165,149 +114,159 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
// 按费用项目和税率组合合并相同项
|
||||
// 添加合并逻辑:按费用项目和税率组合合并相同项
|
||||
mergeProcessAllocEntriesByExpenseItemAndRate(processAllocEntityCollection);
|
||||
|
||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空工序分摊数据
|
||||
*/
|
||||
private void clearProcessAllocData(DynamicObject itemEntry) {
|
||||
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
|
||||
this.getView().updateView("zcgj_processallocatentity");//刷新工序分摊
|
||||
} else {
|
||||
DynamicObjectCollection processAllocEntityCollection = itemEntryCollection.get(0).getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊分录
|
||||
processAllocEntityCollection.clear();
|
||||
this.getView().updateView("itementry");//支付项分录
|
||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊分录
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理合同属性变更
|
||||
*/
|
||||
private void handleContractPropertyChange(PropertyChangedArgs e) {
|
||||
@Override
|
||||
public void propertyChanged(PropertyChangedArgs e) {
|
||||
super.propertyChanged(e);
|
||||
String name = e.getProperty().getName();
|
||||
if ("totalsettleoftaxamount".equals(name) || "contract".equals(name)) {
|
||||
//累计结算金额(含当期)(价税合计),合同名称
|
||||
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");//合同属性
|
||||
if (contattr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");//iseqsettle
|
||||
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");//按入库单结算
|
||||
if (contattr.getString("number").equals("ZCSX01") && issettlebymatin) {
|
||||
return;
|
||||
}
|
||||
|
||||
DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");//合同支付项明细
|
||||
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录
|
||||
if (itemEntryCollection.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
DynamicObject itemEntry = itemEntryCollection.get(0);
|
||||
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊分录
|
||||
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
|
||||
processAllocEntityCollection.clear();
|
||||
|
||||
if ("contract".equals(e.getProperty().getName())) {
|
||||
ChangeData changeData = e.getChangeSet()[0];
|
||||
Object newValue = changeData.getNewValue();
|
||||
if ("contract".equals(name)) {
|
||||
ChangeData changeData = e.getChangeSet()[0]; //修改值所在行
|
||||
Object newValue = changeData.getNewValue();//新值
|
||||
if (newValue == null) {
|
||||
this.getView().updateView("zcgj_processallocatentity");//刷新
|
||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Object contract = this.getModel().getValue("contract");// 合同
|
||||
Object contract = this.getModel().getValue("contract");
|
||||
if (contract == null) {
|
||||
this.getView().updateView("zcgj_processallocatentity");//刷新
|
||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||
return;
|
||||
}
|
||||
|
||||
DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");
|
||||
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
|
||||
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();
|
||||
|
||||
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");
|
||||
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");//合同属性
|
||||
if (contattr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");
|
||||
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");//按入库单结算
|
||||
if (!contattr.getString("number").equals("ZCSX01") && !issettlebymatin) {
|
||||
return;
|
||||
}
|
||||
|
||||
DynamicObject dataEntity = this.getModel().getDataEntity(true);
|
||||
DynamicObjectCollection materialInEntryCollection = dataEntity.getDynamicObjectCollection("materialinentry");
|
||||
DynamicObjectCollection itemEntryCollection = dataEntity.getDynamicObjectCollection("itementry");
|
||||
|
||||
DynamicObjectCollection materialInEntryCollection = dataEntity.getDynamicObjectCollection("materialinentry");//入库单明细
|
||||
DynamicObjectCollection itemEntryCollection = dataEntity.getDynamicObjectCollection("itementry");//支付项分录
|
||||
if (itemEntryCollection.size() == 0) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按工序和税率组合合并工序分摊条目
|
||||
*
|
||||
* @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");
|
||||
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");
|
||||
"_" +
|
||||
(currentRate != null ? currentRate.toString() : "null");
|
||||
|
||||
if (processRateMap.containsKey(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 nextAmount = toBigDecimal(currentEntry.get("zcgj_pa_amount"));
|
||||
|
@ -322,10 +281,22 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
|
|||
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) {
|
||||
|
@ -347,33 +318,42 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
|
|||
|
||||
/**
|
||||
* 根据资源编码获取对应的费用项目
|
||||
*
|
||||
* @param resource 资源对象
|
||||
* @return 对应的费用项目
|
||||
*/
|
||||
private DynamicObject getExpenseItemByResource(DynamicObject resource) {
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String resourceNumber = resource.getString("number");
|
||||
String resourceNumber = resource.getString("number");//资源编码-清单分类-编码
|
||||
|
||||
String expenseItemNumber;
|
||||
String expenseItemNumber = null;
|
||||
switch (resourceNumber) {
|
||||
case "ZCKS01":
|
||||
expenseItemNumber = "FYXM006.002.004"; //备品备件
|
||||
//备品备件
|
||||
expenseItemNumber = "FYXM006.002.004";
|
||||
break;
|
||||
case "ZCKS02":
|
||||
expenseItemNumber = "FYXM006.002.001"; //主材
|
||||
//主材
|
||||
expenseItemNumber = "FYXM006.002.001";
|
||||
break;
|
||||
case "ZCKS03":
|
||||
expenseItemNumber = "FYXM006.002.006"; //火工材料
|
||||
//火工材料
|
||||
expenseItemNumber = "FYXM006.002.006";
|
||||
break;
|
||||
case "ZCKS04":
|
||||
expenseItemNumber = "FYXM006.002.002"; //辅材
|
||||
//辅材
|
||||
expenseItemNumber = "FYXM006.002.002";
|
||||
break;
|
||||
case "ZCKS05":
|
||||
expenseItemNumber = "FYXM006.002.003"; //燃料及动力
|
||||
//燃料及动力
|
||||
expenseItemNumber = "FYXM006.002.003";
|
||||
break;
|
||||
case "ZCKS06":
|
||||
expenseItemNumber = "FYXM006.002.002"; //劳保用品类
|
||||
//劳保用品类
|
||||
expenseItemNumber = "FYXM006.002.002";
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
|
@ -382,4 +362,52 @@ public class CostAllocatorBillPlugin extends AbstractFormPlugin {
|
|||
return BusinessDataServiceHelper.loadSingle("er_expenseitemedit", "id",
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue