From ca1c54c3799287e551d596a52d85ff026c49c2ae Mon Sep 17 00:00:00 2001 From: xuhaihui <2098865055@qq.com> Date: Thu, 23 Oct 2025 17:43:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=BA=93=E5=8D=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pr/plugin/form/MaterialOutBillPlugin.java | 104 +++++++++++++++--- 1 file changed, 87 insertions(+), 17 deletions(-) diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutBillPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutBillPlugin.java index 2ffd973..16c4fd7 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutBillPlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/zcgj/zcdev/zcdev/pr/plugin/form/MaterialOutBillPlugin.java @@ -21,6 +21,7 @@ import java.math.RoundingMode; import java.util.ArrayList; import java.util.EventObject; import java.util.List; +import java.util.Objects; /** * 出库单表单插件 @@ -152,6 +153,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF DynamicObject transType = (DynamicObject) this.getModel().getValue("transtype");//事务类型 DynamicObject org = (DynamicObject) this.getModel().getValue("org");//事务类型 DynamicObject material = dataEntity.getDynamicObject("material");//资源编码 + String modelnum1 = dataEntity.getString("modelnum");//规格型号 if (warehouse != null && transType != null && "REDUCE".equals(transType.getString("type")) && org != null && material != null) { DynamicObject warehouse1 = (DynamicObject) warehouse;//发货仓库 DynamicObject project = warehouse1.getDynamicObject("project");//发货仓库-项目 @@ -161,7 +163,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF } qFilters.and(new QFilter("org", QCP.equals, org.getPkValue()));//即时库存-所属组织 qFilters.and(new QFilter("material", QCP.equals, material.getPkValue()));//即时库存-资源名称 - qFilters.and(new QFilter("modelnum", QCP.equals, dataEntity.getString("modelnum")));//即时库存-规格型号 + qFilters.and(new QFilter("modelnum", QCP.equals, modelnum1));//即时库存-规格型号 DynamicObject ecma_matinventory = BusinessDataServiceHelper.loadSingle("ecma_matinventory", new QFilter[]{qFilters});//即时库存 if (ecma_matinventory != null) { BigDecimal qty = ecma_matinventory.getBigDecimal("qty");//即时库存-可用数量 @@ -172,6 +174,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF for (int i = 0; i < entryEntityCollection.size(); i++) { DynamicObject entryEntity = entryEntityCollection.get(i); DynamicObject material1 = entryEntity.getDynamicObject("material");//出库单分录-资源编码 + String modelnum = entryEntity.getString("modelnum");//出库单分录-规格型号 BigDecimal qty1 = entryEntity.getBigDecimal("qty");//出库单分录-数量 BigDecimal amount = entryEntity.getBigDecimal("amount");//出库单分录-金额 if (material1 == null) { @@ -180,6 +183,9 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF if (!material.getPkValue().equals(material1.getPkValue())) { continue; } + if (!Objects.equals(modelnum, modelnum1)) { + continue; + } totalQty = totalQty.add(qty1); if (rowIndex == i) { continue; @@ -189,7 +195,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF if (totalQty.compareTo(qty) == 0) { BigDecimal amount = ecma_matinventory.getBigDecimal("amount").subtract(totalAmount); this.getModel().setValue("amount", amount, rowIndex);//金额 - BigDecimal price1 = amount.divide(qty, 2, RoundingMode.HALF_UP); + BigDecimal price1 = amount.divide(newValue, 2, RoundingMode.HALF_UP); this.getModel().setValue("price", price1, rowIndex);//单价(不含税) } else { this.getModel().setValue("price", price2, rowIndex);//单价(不含税) @@ -205,22 +211,86 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF public void itemClick(ItemClickEvent evt) { super.itemClick(evt); String itemKey = evt.getItemKey(); -// if (itemKey.equals("deleteentry")) { + if (itemKey.equals("deleteentry")) { // //出库单明细删除按钮 -// DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//出库单分录 -// boolean hasFL001 = false; -// for (DynamicObject entryEntity : entryEntityCollection) { -// DynamicObject accountType = entryEntity.getDynamicObject("zcgj_accounttype");//科目属性 -// if (accountType != null && "FL001".equals(accountType.getString("number"))) { -// //科目属性-为生成成本时 -// hasFL001 = true; -// break; -// } -// } -// BasedataEdit edit = this.getView().getControl("procbs");//工作分解结构 -// edit.setMustInput(hasFL001);// 设置必录 -// this.getView().updateView("entryentity");//刷新分录 -// } + DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//出库单分录 + for (int rowIndex = 0; rowIndex < entryEntityCollection.size(); rowIndex++) { + DynamicObject dataEntity = entryEntityCollection.get(rowIndex); + BigDecimal newValue = dataEntity.getBigDecimal("qty");//数量 + BigDecimal price = dataEntity.getBigDecimal("price");//单价(不含税) + BigDecimal result = newValue.multiply(price).setScale(2, RoundingMode.HALF_UP); + BigDecimal settleprice = dataEntity.getBigDecimal("settleprice");//结算单价 + this.getModel().setValue("amount", result, rowIndex);//金额 + this.getModel().setValue("settleamount", newValue.multiply(settleprice), rowIndex);//结算金额 + Object warehouse = this.getModel().getValue("warehouse");//发货仓库 + DynamicObject transType = (DynamicObject) this.getModel().getValue("transtype");//事务类型 + DynamicObject org = (DynamicObject) this.getModel().getValue("org");//事务类型 + DynamicObject material = dataEntity.getDynamicObject("material");//资源编码 + String modelnum1 = dataEntity.getString("modelnum");//规格型号 + if (warehouse != null && transType != null && "REDUCE".equals(transType.getString("type")) && org != null && material != null) { + DynamicObject warehouse1 = (DynamicObject) warehouse;//发货仓库 + DynamicObject project = warehouse1.getDynamicObject("project");//发货仓库-项目 + QFilter qFilters = new QFilter("warehouse", QCP.equals, warehouse1.getPkValue()); + if (project != null) { + qFilters.and(new QFilter("project", QCP.equals, project.getPkValue()));//即时库存-项目 + } + qFilters.and(new QFilter("org", QCP.equals, org.getPkValue()));//即时库存-所属组织 + qFilters.and(new QFilter("material", QCP.equals, material.getPkValue()));//即时库存-资源名称 + qFilters.and(new QFilter("modelnum", QCP.equals, modelnum1));//即时库存-规格型号 + DynamicObject ecma_matinventory = BusinessDataServiceHelper.loadSingle("ecma_matinventory", new QFilter[]{qFilters});//即时库存 + if (ecma_matinventory != null) { + BigDecimal qty = ecma_matinventory.getBigDecimal("qty");//即时库存-可用数量 + BigDecimal price2 = ecma_matinventory.getBigDecimal("price");//即时库存-当前成本单价 + DynamicObjectCollection entryEntityCollection1 = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//出库单分录 + BigDecimal totalQty = BigDecimal.ZERO;//修改行相同的资源编码数量 + BigDecimal totalAmount = BigDecimal.ZERO;//修改行不相同的资源编码数量 + for (int i = 0; i < entryEntityCollection1.size(); i++) { + DynamicObject entryEntity = entryEntityCollection1.get(i); + DynamicObject material1 = entryEntity.getDynamicObject("material");//出库单分录-资源编码 + String modelnum = entryEntity.getString("modelnum");//出库单分录-规格型号 + BigDecimal qty1 = entryEntity.getBigDecimal("qty");//出库单分录-数量 + BigDecimal amount = entryEntity.getBigDecimal("amount");//出库单分录-金额 + if (material1 == null) { + continue; + } + if (!material.getPkValue().equals(material1.getPkValue())) { + continue; + } + if (!Objects.equals(modelnum, modelnum1)) { + continue; + } + totalQty = totalQty.add(qty1); + if (rowIndex == i) { + continue; + } + totalAmount = totalAmount.add(amount); + } + if (totalQty.compareTo(qty) == 0) { + BigDecimal amount = ecma_matinventory.getBigDecimal("amount").subtract(totalAmount); + this.getModel().setValue("amount", amount, rowIndex);//金额 + BigDecimal price1 = amount.divide(newValue, 2, RoundingMode.HALF_UP); + this.getModel().setValue("price", price1, rowIndex);//单价(不含税) + } else { + this.getModel().setValue("price", price2, rowIndex);//单价(不含税) + BigDecimal result1 = newValue.multiply(price2).setScale(2, RoundingMode.HALF_UP); + this.getModel().setValue("amount", result1, rowIndex);//金额 + } + } + } + } +/* boolean hasFL001 = false; + for (DynamicObject entryEntity : entryEntityCollection) { + DynamicObject accountType = entryEntity.getDynamicObject("zcgj_accounttype");//科目属性 + if (accountType != null && "FL001".equals(accountType.getString("number"))) { + //科目属性-为生成成本时 + hasFL001 = true; + break; + } + } + BasedataEdit edit = this.getView().getControl("procbs");//工作分解结构 + edit.setMustInput(hasFL001);// 设置必录 + this.getView().updateView("entryentity");//刷新分录*/ + } } @Override