支出合同结算入库单分录增行删行赋值逻辑优化
This commit is contained in:
parent
f0e0f6f0c0
commit
04cccc019f
|
@ -29,303 +29,274 @@ 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");//合同支付项明细
|
||||||
|
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录
|
||||||
|
if (itemEntryCollection.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (payItemDetailEntryCollection.size() > 0) {
|
||||||
|
for (DynamicObject payItemDetailEntry : payItemDetailEntryCollection) {
|
||||||
|
|
||||||
|
DynamicObject itemEntry = itemEntryCollection.get(0);
|
||||||
|
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
|
||||||
|
processAllocEntityCollection.clear();
|
||||||
|
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 添加合并逻辑:按工序和税率组合合并相同项
|
||||||
|
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
|
||||||
|
}
|
||||||
|
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")) {
|
} else if (itemKey.equals("removeline1")) {
|
||||||
//入库单明细删除按钮
|
//入库单明细删除按钮
|
||||||
handleMaterialInDelete();
|
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");//入库单编码
|
||||||
|
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"));//税额-税额
|
||||||
|
|
||||||
|
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");//刷新工序分摊
|
||||||
|
} else {
|
||||||
|
DynamicObjectCollection processAllocEntityCollection = itemEntryCollection.get(0).getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊分录
|
||||||
|
processAllocEntityCollection.clear();
|
||||||
|
this.getView().updateView("itementry");//支付项分录
|
||||||
|
this.getView().updateView("zcgj_processallocatentity");//工序分摊分录
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 处理合同支付项明细删除
|
public void propertyChanged(PropertyChangedArgs e) {
|
||||||
*/
|
super.propertyChanged(e);
|
||||||
private void handleContractPaymentItemDelete() {
|
String name = e.getProperty().getName();
|
||||||
DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");
|
if ("totalsettleoftaxamount".equals(name) || "contract".equals(name)) {
|
||||||
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");
|
//累计结算金额(含当期)(价税合计),合同名称
|
||||||
|
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");//合同属性
|
||||||
|
if (contattr == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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");//工序分摊
|
||||||
|
processAllocEntityCollection.clear();
|
||||||
|
if ("contract".equals(name)) {
|
||||||
|
ChangeData changeData = e.getChangeSet()[0]; //修改值所在行
|
||||||
|
Object newValue = changeData.getNewValue();//新值
|
||||||
|
if (newValue == null) {
|
||||||
|
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Object contract = this.getModel().getValue("contract");
|
||||||
|
if (contract == null) {
|
||||||
|
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
|
||||||
|
if (payItemDetailEntryCollection.size() > 0) {
|
||||||
|
for (DynamicObject payItemDetailEntry : payItemDetailEntryCollection) {
|
||||||
|
|
||||||
if (itemEntryCollection.size() == 0) {
|
long referBillId = payItemDetailEntry.getLong("referbillid");//关联单据id
|
||||||
return;
|
QFilter qFilter = new QFilter("id", QCP.equals, referBillId);
|
||||||
}
|
DynamicObject EcOutContractMeasure = BusinessDataServiceHelper.loadSingle("ec_outcontractmeasure", new QFilter[]{qFilter});//支出合同计量
|
||||||
|
if (EcOutContractMeasure != null) {
|
||||||
if (payItemDetailEntryCollection.size() > 0) {
|
DynamicObjectCollection ListModelEntryCollection = EcOutContractMeasure.getDynamicObjectCollection("listmodelentry");//模板分录
|
||||||
processContractPaymentItems(itemEntryCollection.get(0), payItemDetailEntryCollection);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 添加合并逻辑:按工序和税率组合合并相同项
|
||||||
|
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
|
||||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
||||||
} else {
|
} else if ("matinnumber".equals(name)) {
|
||||||
clearProcessAllocData(itemEntryCollection.get(0));
|
//入库单明细-编码
|
||||||
this.getView().updateView("itementry");//支付项分录
|
this.getModel().beginInit();
|
||||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");//合同属性
|
||||||
}
|
if (contattr == null) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
/**
|
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");//按入库单结算
|
||||||
* 处理入库单明细删除
|
if (!contattr.getString("number").equals("ZCSX01") && !issettlebymatin) {
|
||||||
*/
|
return;
|
||||||
private void handleMaterialInDelete() {
|
}
|
||||||
DynamicObjectCollection materialInEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("materialinentry");//入库单分录
|
DynamicObject dataEntity = this.getModel().getDataEntity(true);
|
||||||
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录
|
DynamicObjectCollection materialInEntryCollection = dataEntity.getDynamicObjectCollection("materialinentry");//入库单明细
|
||||||
|
DynamicObjectCollection itemEntryCollection = dataEntity.getDynamicObjectCollection("itementry");//支付项分录
|
||||||
if (itemEntryCollection.size() == 0) {
|
if (itemEntryCollection.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
DynamicObject itemEntry = itemEntryCollection.get(0);
|
||||||
if (materialInEntryCollection.size() > 0) {
|
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
|
||||||
processMaterialInItems(itemEntryCollection.get(0), materialInEntryCollection);
|
processAllocEntityCollection.clear();
|
||||||
} else {
|
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
|
||||||
clearProcessAllocData(itemEntryCollection.get(0));
|
for (DynamicObject materialInEntry : materialInEntryCollection) {
|
||||||
this.getView().updateView("itementry");//支付项分录
|
String matInNumber = materialInEntry.getString("matinnumber");//入库单编码
|
||||||
this.getView().updateView("zcgj_processallocatentity");//工序分摊
|
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) {
|
||||||
* 处理合同支付项数据
|
|
||||||
*/
|
|
||||||
private void processContractPaymentItems(DynamicObject itemEntry, DynamicObjectCollection payItemDetailEntryCollection) {
|
|
||||||
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");
|
|
||||||
processAllocEntityCollection.clear();
|
|
||||||
DynamicObjectType processAllocEntityType = processAllocEntityCollection.getDynamicObjectType();
|
|
||||||
|
|
||||||
for (DynamicObject payItemDetailEntry : payItemDetailEntryCollection) {
|
|
||||||
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);
|
DynamicObject newProcessAllocEntity = new DynamicObject(processAllocEntityType);
|
||||||
newProcessAllocEntity.set("zcgj_pa_process", listEntry.get("listcbs"));//工序-成本分解结构
|
newProcessAllocEntity.set("zcgj_pa_amount", entryEntity.get("oftaxamount"));//价税合计-含税金额
|
||||||
newProcessAllocEntity.set("zcgj_pa_amount", listEntry.get("thisoftaxmount"));//价税合计-本期计量含税金额
|
newProcessAllocEntity.set("zcgj_amountnotax", entryEntity.get("notaxamount"));//不含税金额-金额
|
||||||
newProcessAllocEntity.set("zcgj_amountnotax", listEntry.get("thisamount"));//不含税金额-本期计量金额
|
newProcessAllocEntity.set("zcgj_rateval", entryEntity.getDynamicObject("entrytaxrate").get("taxrate"));//税率(%)-税率名称(值
|
||||||
newProcessAllocEntity.set("zcgj_rateval", listEntry.get("entrytaxrate"));//税率(%)-税率(%)
|
newProcessAllocEntity.set("zcgj_taxamt", entryEntity.get("taxamount"));//税额-税额
|
||||||
newProcessAllocEntity.set("zcgj_taxamt", listEntry.get("thistax"));//税额-本期税额
|
|
||||||
|
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);
|
processAllocEntityCollection.add(newProcessAllocEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加合并逻辑:按费用项目和税率组合合并相同项
|
||||||
|
mergeProcessAllocEntriesByExpenseItemAndRate(processAllocEntityCollection);
|
||||||
|
|
||||||
|
this.getView().updateView("zcgj_processallocatentity");//刷新工序分摊
|
||||||
|
this.getModel().endInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按工序和税率组合合并相同项
|
|
||||||
mergeProcessAllocEntriesByProcessAndRate(processAllocEntityCollection);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理入库单数据
|
|
||||||
*/
|
|
||||||
private void processMaterialInItems(DynamicObject itemEntry, DynamicObjectCollection materialInEntryCollection) {
|
|
||||||
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 ecmaMaterialInBill = BusinessDataServiceHelper.loadSingle("ecma_materialinbill", new QFilter[]{qFilter});//入库单
|
|
||||||
|
|
||||||
if (ecmaMaterialInBill != null) {
|
|
||||||
DynamicObjectCollection entryEntityCollection = ecmaMaterialInBill.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"));//税额-税额
|
|
||||||
|
|
||||||
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");//工序分摊
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空工序分摊数据
|
|
||||||
*/
|
|
||||||
private void clearProcessAllocData(DynamicObject itemEntry) {
|
|
||||||
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊
|
|
||||||
processAllocEntityCollection.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理合同属性变更
|
|
||||||
*/
|
|
||||||
private void handleContractPropertyChange(PropertyChangedArgs e) {
|
|
||||||
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");//合同属性
|
|
||||||
if (contattr == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean issettlebymatin = (Boolean) this.getModel().getValue("issettlebymatin");//iseqsettle
|
|
||||||
if (contattr.getString("number").equals("ZCSX01") && issettlebymatin) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicObjectCollection itemEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("itementry");//支付项分录
|
|
||||||
if (itemEntryCollection.size() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicObject itemEntry = itemEntryCollection.get(0);
|
|
||||||
DynamicObjectCollection processAllocEntityCollection = itemEntry.getDynamicObjectCollection("zcgj_processallocatentity");//工序分摊分录
|
|
||||||
processAllocEntityCollection.clear();
|
|
||||||
|
|
||||||
if ("contract".equals(e.getProperty().getName())) {
|
|
||||||
ChangeData changeData = e.getChangeSet()[0];
|
|
||||||
Object newValue = changeData.getNewValue();
|
|
||||||
if (newValue == null) {
|
|
||||||
this.getView().updateView("zcgj_processallocatentity");//刷新
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object contract = this.getModel().getValue("contract");// 合同
|
|
||||||
if (contract == null) {
|
|
||||||
this.getView().updateView("zcgj_processallocatentity");//刷新
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicObjectCollection payItemDetailEntryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("payitemdetailentry");
|
|
||||||
if (payItemDetailEntryCollection.size() > 0) {
|
|
||||||
processContractPaymentItems(itemEntry, payItemDetailEntryCollection);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getView().updateView("zcgj_processallocatentity");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理入库单属性变更
|
|
||||||
*/
|
|
||||||
private void handleMaterialInPropertyChange() {
|
|
||||||
this.getModel().beginInit();
|
|
||||||
|
|
||||||
DynamicObject contattr = (DynamicObject) this.getModel().getValue("contattr");
|
|
||||||
if (contattr == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
if (itemEntryCollection.size() == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
processMaterialInItems(itemEntryCollection.get(0), materialInEntryCollection);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
// 合并价税合计
|
||||||
|
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);
|
processAllocEntityCollection.remove(i);
|
||||||
i--;
|
i--; // 调整索引
|
||||||
} else {
|
} else {
|
||||||
|
// 如果不存在相同组合,则添加到Map中
|
||||||
processRateMap.put(key, currentEntry);
|
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"));
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将对象转换为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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue