Преглед на файлове

应收应付逻辑优化

wanwei преди 7 месеца
родител
ревизия
56c9c543f8

+ 76 - 21
src/main/java/fi/er/opplugin/FinapbillBeforeF7SelectSample.java

@@ -15,10 +15,8 @@ import kd.bos.orm.query.QFilter;
 import kd.bos.servicehelper.BusinessDataServiceHelper;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.EventObject;
-import java.util.List;
 
 public class FinapbillBeforeF7SelectSample extends AbstractFormPlugin implements BeforeF7SelectListener {
     private static String nckd_apfinapbill = "nckd_apfinapbill"; //应付挂账单字段
@@ -120,22 +118,44 @@ public class FinapbillBeforeF7SelectSample extends AbstractFormPlugin implements
                 Date bookdate = gzInfo.getDate("bookdate");
                 String remark = gzInfo.getString("remark");
                 BigDecimal pricetaxtotal = gzInfo.getBigDecimal("pricetaxtotal");
+                BigDecimal expeapproveamount = BigDecimal.ZERO;//核定金额
+                BigDecimal orireceiveamount = BigDecimal.ZERO;//收款金额
+
+
+                //费用明细分录
+                DynamicObjectCollection expenseentryentity = this.getModel().getEntryEntity("expenseentryentity");
+                for (DynamicObject object : expenseentryentity) {
+                     expeapproveamount = expeapproveamount.add(object.getBigDecimal("expeapproveamount"));
+                }
+
+                //收款信息分录
+                DynamicObjectCollection accountentry = this.getModel().getEntryEntity("accountentry");
+                for (DynamicObject object : accountentry) {
+                    orireceiveamount = orireceiveamount.add(object.getBigDecimal("orireceiveamount"));
+                }
+
+                //冲销金额
+                BigDecimal nckd_accloanamount = expeapproveamount.subtract(orireceiveamount);
+                //差额
+                BigDecimal nckd_sub_amount = pricetaxtotal.subtract(nckd_accloanamount);
                 //给冲预付借款赋值
-                int rowIndex = this.getModel().createNewEntryRow("writeoffmoney");
-
-                this.getModel().setValue("loanbillnov1",billno,rowIndex);
-                this.getModel().setValue("sourceentrycostdept",org,rowIndex);
-                this.getModel().setValue("sourceentrycostcompany",org,rowIndex);
-                this.getModel().setValue("sourceexpenseitem",expenseitem,rowIndex);
-                this.getModel().setValue("srcentrywlunit",receivingsupplierid,rowIndex);
-                this.getModel().setValue("loanapplydatev1",bookdate,rowIndex);
-                this.getModel().setValue("loandescriptionv1",remark,rowIndex);
-                this.getModel().setValue("loanamount",pricetaxtotal,rowIndex);
-                this.getModel().setValue("accloanamount",pricetaxtotal,rowIndex);
-                this.getModel().setValue("currloanamount",pricetaxtotal,rowIndex);
-                this.getModel().setValue("curraccloanamount",pricetaxtotal,rowIndex);
+                this.getModel().deleteEntryData("nckd_ap_finapbill_detail");
+                int rowIndex = this.getModel().createNewEntryRow("nckd_ap_finapbill_detail");
+
+                this.getModel().setValue("nckd_loanbillnov1",billno,rowIndex);
+                this.getModel().setValue("nckd_sourceentrycostdept",org,rowIndex);
+                this.getModel().setValue("nckd_sourceentrycostcompa",org,rowIndex);
+                this.getModel().setValue("nckd_sourceexpenseitem",expenseitem,rowIndex);
+//                this.getModel().setValue("nckd_srcentrywlunit",receivingsupplierid,rowIndex);
+                this.getModel().setValue("nckd_loanapplydatev1",bookdate,rowIndex);
+                this.getModel().setValue("nckd_loandescriptionv1",remark,rowIndex);
+                this.getModel().setValue("nckd_loanamount",pricetaxtotal,rowIndex);
+                this.getModel().setValue("nckd_currloanamount",pricetaxtotal,rowIndex);
+                this.getModel().setValue("nckd_accloanamount",nckd_accloanamount,rowIndex);
+                this.getModel().setValue("nckd_curraccloanamount",nckd_accloanamount,rowIndex);
+                this.getModel().setValue("nckd_sub_amount",nckd_sub_amount,rowIndex);
                 //刷新冲预付借款分录
-                this.getView().updateView("writeoffmoney");
+                this.getView().updateView("nckd_ap_finapbill_detail");
             }
         }//资产组织变更
         else if (StringUtils.equals("assetorg", fieldKey)) {
@@ -174,29 +194,32 @@ public class FinapbillBeforeF7SelectSample extends AbstractFormPlugin implements
         } else if (StringUtils.equals("expenseamount", fieldKey) || StringUtils.equals("nckd_amountfield3", fieldKey)) {
             String reimbursetype = (String) this.getModel().getValue("reimbursetype");
             if("asset".equals(reimbursetype)) {
+                if (this.getModel().getEntryEntity("assetentry").size() == 0) {
+                    int rowIndex = this.getModel().createNewEntryRow("assetentry");
+                }
                 ChangeData changeData = e.getChangeSet()[0];
                 BigDecimal expenseamount = (BigDecimal) changeData.getNewValue();
-                this.getModel().setValue("nckd_amountfield3", expenseamount);//含税单价
+                this.getModel().setValue("nckd_amountfield3", expenseamount, 0);//含税单价
 
                 //含税金额 = 含税单价*数量
                 BigDecimal asset_quantity = (BigDecimal) this.getModel().getValue("asset_quantity");
                 BigDecimal assetexpenseamount = expenseamount.multiply(asset_quantity);
-                this.getModel().setValue("assetexpenseamount", assetexpenseamount);
+                this.getModel().setValue("assetexpenseamount", assetexpenseamount, 0);
 
                 //不含税单价 = 含税单价/(1+税率)
                 BigDecimal assettaxrate = (BigDecimal) this.getModel().getValue("assettaxrate");
                 assettaxrate = assettaxrate.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
                 BigDecimal rate = assettaxrate.add(BigDecimal.ONE);
                 BigDecimal assetpricewithouttax = expenseamount.divide(rate, 2 , RoundingMode.HALF_UP);
-                this.getModel().setValue("assetpricewithouttax", assetpricewithouttax);
+                this.getModel().setValue("assetpricewithouttax", assetpricewithouttax, 0);
 
                 //不含税金额 = 不含税单价*数量
                 BigDecimal assetorientryamount = assetpricewithouttax.multiply(asset_quantity);
-                this.getModel().setValue("assetorientryamount", assetorientryamount);
+                this.getModel().setValue("assetorientryamount", assetorientryamount, 0);
 
                 //税额 = 含税金额-不含税金额
                 BigDecimal assettaxamount = assetexpenseamount.subtract(assetorientryamount);
-                this.getModel().setValue("assettaxamount", assettaxamount);
+                this.getModel().setValue("assettaxamount", assettaxamount, 0);
             }
         } else if (StringUtils.equals("taxrate", fieldKey) || StringUtils.equals("assettaxrate", fieldKey)) {
             ChangeData changeData = e.getChangeSet()[0];
@@ -222,6 +245,38 @@ public class FinapbillBeforeF7SelectSample extends AbstractFormPlugin implements
             //税额 = 含税金额-不含税金额
             BigDecimal assettaxamount = assetexpenseamount.subtract(assetorientryamount);
             this.getModel().setValue("assettaxamount", assettaxamount);
+        } else if (StringUtils.equals("expeapproveamount", fieldKey) || StringUtils.equals("orireceiveamount", fieldKey)) {
+            DynamicObjectCollection nckd_ap_finapbill_detail = this.getModel().getEntryEntity("nckd_ap_finapbill_detail");
+            if (nckd_ap_finapbill_detail.size() > 0) {
+                BigDecimal expeapproveamount = BigDecimal.ZERO;//核定金额
+                BigDecimal orireceiveamount = BigDecimal.ZERO;//收款金额
+                //费用明细分录
+                DynamicObjectCollection expenseentryentity = this.getModel().getEntryEntity("expenseentryentity");
+                for (DynamicObject object : expenseentryentity) {
+                    expeapproveamount = expeapproveamount.add(object.getBigDecimal("expeapproveamount"));
+                }
+
+                //收款信息分录
+                DynamicObjectCollection accountentry = this.getModel().getEntryEntity("accountentry");
+                for (DynamicObject object : accountentry) {
+                    orireceiveamount = orireceiveamount.add(object.getBigDecimal("orireceiveamount"));
+                }
+
+                //冲销金额
+                BigDecimal nckd_accloanamount = expeapproveamount.subtract(orireceiveamount);
+                //借款余额
+                BigDecimal nckd_loanamount = nckd_ap_finapbill_detail.get(0).getBigDecimal("nckd_loanamount");
+                //差额
+                BigDecimal nckd_sub_amount = nckd_loanamount.subtract(nckd_accloanamount);
+
+                this.getModel().setValue("nckd_loanamount",nckd_loanamount,0);
+                this.getModel().setValue("nckd_currloanamount",nckd_loanamount,0);
+                this.getModel().setValue("nckd_accloanamount",nckd_accloanamount,0);
+                this.getModel().setValue("nckd_curraccloanamount",nckd_accloanamount,0);
+                this.getModel().setValue("nckd_sub_amount",nckd_sub_amount,0);
+                //刷新冲预付借款分录
+                this.getView().updateView("nckd_ap_finapbill_detail");
+            }
         }
     }
 

+ 11 - 12
src/main/java/fi/er/opplugin/PublicreimburOpPlugin.java

@@ -44,13 +44,12 @@ public class PublicreimburOpPlugin extends AbstractOperationServicePlugIn {
                 info.set("nckd_settlestatus", SettlementStatusEnum.未结算.getValue());
 
                 //反写实物卡片清单
-                if (info.getDynamicObjectCollection("nckd_realcard_list") != null ) {
-                    List<String > codeList = new ArrayList<>();
-                    for (DynamicObject entryentity : info.getDynamicObjectCollection("nckd_realcard_list")) {
-                        //取当前循环付款明细分录的源单分录id
-                        String cardCode = entryentity.getString("nckd_card_code");
+                for (DynamicObject entryentity : info.getDynamicObjectCollection("assetentry")) {
+                    DynamicObjectCollection nckd_real_card = entryentity.getDynamicObjectCollection("nckd_real_card");
+                    for (DynamicObject object : nckd_real_card) {
+                        Long id = (Long) object.get(2);
                         //查询实物卡片分录数据,如果查询到数据则不能保存该报销单
-                        QFilter filter = new QFilter("number", QCP.equals,cardCode);
+                        QFilter filter = new QFilter("id", QCP.equals,id);
                         DynamicObject[] cardObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
                         for (int j = 0; j < cardObjects.length; j++) {
                             DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[i].getPkValue(), cardObjects[i].getDynamicObjectType().getName());
@@ -72,17 +71,17 @@ public class PublicreimburOpPlugin extends AbstractOperationServicePlugIn {
                 info.set("nckd_settlestatus", null);
 
                 //反审核反写实物卡片清单
-                if (info.getDynamicObjectCollection("nckd_realcard_list") != null ) {
-                    List<String > codeList = new ArrayList<>();
-                    for (DynamicObject entryentity : info.getDynamicObjectCollection("nckd_realcard_list")) {
-                        //取当前循环付款明细分录的源单分录id
-                        String cardCode = entryentity.getString("nckd_card_code");
+                for (DynamicObject entryentity : info.getDynamicObjectCollection("assetentry")) {
+                    DynamicObjectCollection nckd_real_card = entryentity.getDynamicObjectCollection("nckd_real_card");
+                    for (DynamicObject object : nckd_real_card) {
+                        Long id = (Long) object.get(2);
                         //查询实物卡片分录数据,如果查询到数据则不能保存该报销单
-                        QFilter filter = new QFilter("number", QCP.equals,cardCode);
+                        QFilter filter = new QFilter("id", QCP.equals,id);
                         DynamicObject[] cardObjects = BusinessDataServiceHelper.load("nckd_fa_card_real_list","id",new QFilter[] {filter});
                         for (int j = 0; j < cardObjects.length; j++) {
                             DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[i].getPkValue(), cardObjects[i].getDynamicObjectType().getName());
                             //资产报账单审核通过后,实物卡片清单标记为1
+                            //资产报账单审核通过后,实物卡片清单标记为1
                             cardInfo.set("nckd_flag", "0");
                             //星瀚实物卡片三个字段回写为空
                             cardInfo.set("nckd_card_real_org", null);

+ 2 - 0
src/main/java/fi/fa/opplugin/RealCardBillOpPlugin.java

@@ -33,6 +33,7 @@ public class RealCardBillOpPlugin extends AbstractOperationServicePlugIn {
                         for (DynamicObject object : nckd_real_card) {
                             DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(object.get(2), "nckd_fa_card_real_list");
                             //回写e卡片实物清单字段
+                            cardInfo.set("nckd_flag", "1");
                             cardInfo.set("nckd_card_real_org", orgName);
                             cardInfo.set("nckd_card_real_code", number);
                             cardInfo.set("nckd_card_real_name", name);
@@ -52,6 +53,7 @@ public class RealCardBillOpPlugin extends AbstractOperationServicePlugIn {
                     for (int j = 0; j < cardObjects.length; j++) {
                         DynamicObject cardInfo = BusinessDataServiceHelper.loadSingle(cardObjects[j].getPkValue(), cardObjects[j].getDynamicObjectType().getName());
                         //回写e卡片实物清单字段
+                        cardInfo.set("nckd_flag", "0");
                         cardInfo.set("nckd_card_real_org", null);
                         cardInfo.set("nckd_card_real_code", null);
                         cardInfo.set("nckd_card_real_name", null);