From 57071d39c5c7cb57fcedfdc8519b4815ca8b46b0 Mon Sep 17 00:00:00 2001 From: xuhaihui <2098865055@qq.com> Date: Mon, 1 Sep 2025 10:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=BA=93=E5=8D=95=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=B4=B9=E7=94=A8=E6=B1=87=E6=80=BB=E5=88=86=E5=BD=95=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=B5=8B=E5=80=BC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/MaterialInbPurchaseApplyPlugin.java | 155 +++++++++++++++--- 1 file changed, 130 insertions(+), 25 deletions(-) diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbPurchaseApplyPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbPurchaseApplyPlugin.java index cbdc31a..4b9730c 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbPurchaseApplyPlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialInbPurchaseApplyPlugin.java @@ -1,22 +1,14 @@ package zcgj.zcdev.zcdev.pr.plugin.form; -import kd.bos.algo.DataSet; -import kd.bos.algo.JoinDataSet; -import kd.bos.algo.JoinType; -import kd.bos.algo.Row; import kd.bos.bill.AbstractBillPlugIn; -import kd.bos.context.RequestContext; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; +import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; import kd.bos.dataentity.resource.ResManager; -import kd.bos.dataentity.utils.StringUtils; -import kd.bos.entity.EntityMetadataCache; -import kd.bos.entity.datamodel.ListSelectedRowCollection; import kd.bos.entity.datamodel.events.ChangeData; import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.form.*; -import kd.bos.form.control.EntryGrid; -import kd.bos.form.events.AfterDoOperationEventArgs; +import kd.bos.form.control.events.ItemClickEvent; import kd.bos.form.events.BeforeDoOperationEventArgs; import kd.bos.form.events.ClosedCallBackEvent; import kd.bos.form.field.BasedataEdit; @@ -34,7 +26,6 @@ import kd.sdk.plugin.Plugin; import java.math.BigDecimal; import java.util.*; -import java.util.stream.Collectors; /** * 入库单表单插件 @@ -44,6 +35,7 @@ import java.util.stream.Collectors; * 4:申请人部门根据物资申请人过滤部门 * 5:申请人部门赋值逻辑 * 6:合同编码字段赋值 + * 7:费用汇总分录新增赋值逻辑 */ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implements Plugin, BeforeF7SelectListener { @Override @@ -53,6 +45,7 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement purchaseApply.addBeforeF7SelectListener(this); BasedataEdit zcgj_applidepart = getView().getControl("zcgj_applidepart");//申请人部门 zcgj_applidepart.addBeforeF7SelectListener(this); + this.addItemClickListeners("advcontoolbarap");//入库单明细工具栏 } @Override @@ -63,6 +56,16 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement this.getModel().setValue("zcgj_applidepart", mainOrgID);//申请人部门 } + @Override + public void itemClick(ItemClickEvent evt) { + super.itemClick(evt); + String itemKey = evt.getItemKey(); + if (itemKey.equals("delentry")) { + //入库单明细-删行 + setNewExpenseSummary(); + } + } + @Override public void propertyChanged(PropertyChangedArgs e) { super.propertyChanged(e); @@ -74,20 +77,6 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement Object newValue = changeData.getNewValue();//新值 Object oldValue = changeData.getOldValue();//旧值 if (newValue == null || !newValue.equals(oldValue)) { -// // 消息模板#{x}为超链接占位符,格式如“保存成功,#{0},单据详情,#{1}” -// String tempMsg = "更改采购申请单将自动清单入库单明细,您确定更改吗?"; -// List msglinks = new ArrayList(); -// // 消息框按钮类型 -// MessageBoxOptions options = MessageBoxOptions.OKCancel; -// // 确认提示类型 -// ConfirmTypes confirmTypes = ConfirmTypes.Default; -// // 确认框回调 -// ConfirmCallBackListener callBack = new ConfirmCallBackListener("CALLBACKID_DEMO2", this); -// // 按钮名称 -// Map btnNameMaps = new HashMap(); -// btnNameMaps.put(2, "按钮名称2"); -// btnNameMaps.put(6, "按钮名称6"); -// this.getView().showConfirm(tempMsg, msglinks, options, confirmTypes, callBack, btnNameMaps); DynamicObjectCollection entryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录 entryCollection.clear(); this.getView().updateView("entryentity");//刷新分录 @@ -137,6 +126,16 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement DynamicObject zcgj_reqperson = (DynamicObject) newValue;//物资申请人 long mainOrgID = UserServiceHelper.getUserMainOrgId((Long) zcgj_reqperson.getPkValue());//获取用户默认部门id this.getModel().setValue("zcgj_applidepart", mainOrgID);//申请人部门 + } else if ("totaloftaxamount".equals(key) || "taxamount".equals(key)) { + //入库含税总金额,税额 + if ("taxamount".equals(key)) { + //税额 + Boolean adjustamount = (Boolean) this.getModel().getValue("adjustamount");//微调金额 + if (!adjustamount) { + return; + } + } + setNewExpenseSummary(); } } @@ -279,4 +278,110 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement this.getView().showForm(formShowParameter); } } + + private void setNewExpenseSummary() { + DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录 + DynamicObjectCollection expenseSummaryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_expensesummary");//费用汇总分录 + expenseSummaryCollection.clear(); + DynamicObjectType expenseSummaryType = expenseSummaryCollection.getDynamicObjectType(); + for (DynamicObject entryEntity : entryEntityCollection) { + DynamicObject newExpenseSummaryEntity = new DynamicObject(expenseSummaryType); + newExpenseSummaryEntity.set("zcgj_pa_amount", entryEntity.get("oftaxamount"));//价税合计-含税金额 + newExpenseSummaryEntity.set("zcgj_amountnotax", entryEntity.get("notaxamount"));//不含税金额-金额 + DynamicObject entryTaxRate = entryEntity.getDynamicObject("entrytaxrate");//税率名称 + if (entryTaxRate != null) { + newExpenseSummaryEntity.set("zcgj_rateval", entryTaxRate.get("taxrate"));//税率(%)-税率名称(值 + } + newExpenseSummaryEntity.set("zcgj_taxamt", entryEntity.get("taxamount"));//税额-税额 + + DynamicObject expenseItem = null; + DynamicObject material = entryEntity.getDynamicObject("material");//入库单分录-资源编码 + if (material != null) { + DynamicObject resource = material.getDynamicObject("resource");//入库单分录-资源编码-清单分类 + if (resource != null) { + String resourceNumber = resource.getString("number");//资源编码-清单分类-编码 + DynamicObject ecbd_resource = BusinessDataServiceHelper.loadSingle("ecbd_resource", + "id,zcgj_expenseitem", new QFilter[]{new QFilter("number", QCP.equals, resourceNumber)});//清单分类 + expenseItem = ecbd_resource.getDynamicObject("zcgj_expenseitem");//费用项目 + } + } + newExpenseSummaryEntity.set("zcgj_expenseitem", expenseItem);//费用项目-对应费用项目 + + expenseSummaryCollection.add(newExpenseSummaryEntity); + } + mergeExpenseSummaryEntriesByExpenseItemAndRate(expenseSummaryCollection); + this.getView().updateView("zcgj_expensesummary");//刷新分录 + } + + /** + * 按费用项目和税率组合合并费用汇总条目 + * + * @param expenseSummaryCollection 费用汇总集合 + */ + private void mergeExpenseSummaryEntriesByExpenseItemAndRate(DynamicObjectCollection expenseSummaryCollection) { + // 使用Map来存储已存在的费用项目+税率组合,避免嵌套循环 + Map expenseItemRateMap = new HashMap<>(); + + for (int i = 0; i < expenseSummaryCollection.size(); i++) { + DynamicObject currentEntry = expenseSummaryCollection.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)); + + // 移除当前条目 + expenseSummaryCollection.remove(i); + i--; // 调整索引 + } else { + // 如果不存在相同组合,则添加到Map中 + expenseItemRateMap.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; + } + } + } }