From 38efdbd6ad68523bca8481cc1b52a41037a39cff Mon Sep 17 00:00:00 2001 From: zengweihai Date: Tue, 27 Aug 2024 16:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E5=85=AC=E6=8A=A5=E9=94=80=E5=86=B2?= =?UTF-8?q?=E9=94=80=E8=AE=A1=E7=AE=97=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formplugin/GenerateSKClickPlugln.java | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/shkd-cosmic-debug/src/main/java/shkd/fi/er/plugin/formplugin/GenerateSKClickPlugln.java b/shkd-cosmic-debug/src/main/java/shkd/fi/er/plugin/formplugin/GenerateSKClickPlugln.java index 21593cd..56979cb 100644 --- a/shkd-cosmic-debug/src/main/java/shkd/fi/er/plugin/formplugin/GenerateSKClickPlugln.java +++ b/shkd-cosmic-debug/src/main/java/shkd/fi/er/plugin/formplugin/GenerateSKClickPlugln.java @@ -19,6 +19,7 @@ import java.math.BigDecimal; import java.util.EventObject; import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * 单据界面插件 @@ -89,6 +90,10 @@ public class GenerateSKClickPlugln extends AbstractBillPlugIn implements Plugin } } + /** + *计算冲销后金额 = 报销金额(费用明细) - 借款金额(冲预付) ps:根据成本中心+费用项目匹配 + * @param args + */ @Override public void beforeDoOperation(BeforeDoOperationEventArgs args) { super.beforeDoOperation(args); @@ -97,37 +102,44 @@ public class GenerateSKClickPlugln extends AbstractBillPlugIn implements Plugin if ("save".equals(operateKey) || "submit".equals(operateKey)){ DynamicObject shkd_billtypefield = this.getModel().getDataEntity().getDynamicObject("shkd_billtypefield"); if (!"er_publicreimbursebill_BT_03".equals(shkd_billtypefield.getString("number"))){ - DynamicObjectCollection writeoffmoney = this.getModel().getEntryEntity("writeoffmoney"); - if (writeoffmoney.size() > 0){ - DynamicObject dynamicObject = writeoffmoney.get(0); - BigDecimal accloanamount = dynamicObject.getBigDecimal("accloanamount");//获取冲销金额 - if (accloanamount != null){ - DynamicObjectCollection expenseentryentity = this.getModel().getEntryEntity("expenseentryentity"); - if (expenseentryentity.size() > 0){ - DynamicObject dynamicObject1 = expenseentryentity.get(0); - BigDecimal expenseamount = dynamicObject1.getBigDecimal("expenseamount");//获取报销金额 - if (expenseamount != null){ - dynamicObject1.set("shkd_verification",expenseamount.subtract(accloanamount)); - this.getView().updateView("expenseentryentity"); + DynamicObjectCollection expenseentryentity = this.getModel().getEntryEntity("expenseentryentity");//获取费用明细分录 + for (DynamicObject expenseentry : expenseentryentity) {//费用明细分录遍历获取成本中心和费用项目匹配后计算对应的冲销后金额 + DynamicObject std_entrycostcenter = expenseentry.getDynamicObject("std_entrycostcenter");//获取成本中心 + DynamicObject expenseitem = expenseentry.getDynamicObject("expenseitem");//获取费用项目 + BigDecimal expenseamount = expenseentry.getBigDecimal("expenseamount");//获取报销金额 + if (std_entrycostcenter != null && expenseitem != null){//当费用项目和成本中心不为空时 + long ex_centerId = std_entrycostcenter.getLong("id");//成本中心id + long ex_itemId = expenseitem.getLong("id");//费用项目id + boolean isSelf = true;//判断该明细是否不存在匹配预付 + DynamicObjectCollection writeoffmoney = this.getModel().getEntryEntity("writeoffmoney");//获取冲借款分录 + for (DynamicObject prepay : writeoffmoney) {//冲借款分录遍历 + long wr_centerId = prepay.getDynamicObject("std_srcentrycostcenter").getLong("id"); + long wr_itemId = prepay.getDynamicObject("sourceexpenseitem").getLong("id"); + if (Objects.equals(wr_centerId,ex_centerId) && Objects.equals(wr_itemId,ex_itemId)){//当成本中心和费用项目一致时。计算冲销后金额 + BigDecimal loanamount = prepay.getBigDecimal("loanamount");//获取冲销金额 + if (loanamount != null){ + int i = loanamount.compareTo(expenseamount); + if (i > 0){//若预付明细的借款余额大于报销金额,则冲销后金额为0 + expenseentry.set("shkd_verification",BigDecimal.ZERO); + }else {//冲销后金额 = 报销金额 - 借款金额 + BigDecimal subtract = expenseamount.subtract(loanamount); + expenseentry.set("shkd_verification",subtract); + } + }else {//若预付明细的借款余额为空则,冲销后金额为费用明细报销金额本身 + expenseentry.set("shkd_verification",expenseamount); + } + isSelf = false;//找到匹配预付 + break; } } - } - }else { - DynamicObjectCollection expenseentryentity = this.getModel().getEntryEntity("expenseentryentity"); - if (expenseentryentity.size() > 0){ - DynamicObject dynamicObject1 = expenseentryentity.get(0); - BigDecimal expenseamount = dynamicObject1.getBigDecimal("expenseamount");//获取报销金额 - if (expenseamount != null){ - dynamicObject1.set("shkd_verification",expenseamount); - this.getView().updateView("expenseentryentity"); + if (isSelf){//找不到匹配预付,则冲销后金额为费用明细报销金额本身 + expenseentry.set("shkd_verification",expenseamount); } } } + this.getView().updateView("expenseentryentity"); } - } - - } @Override