wanghaiwu 1 тиждень тому
батько
коміт
f8d87c320a

+ 95 - 62
code/jyyy/nckd-jimin-jyyy-fi/src/main/java/nckd/jimin/jyyy/fi/webapi/SRMSynPayApiPlugin.java

@@ -281,6 +281,8 @@ public class SRMSynPayApiPlugin implements Serializable {
         }
 
         String detailtype = "biztype_other";
+        boolean isframeworkcontract = false;
+
         //合同台账
         DynamicObject contractInfo = null;
         if(!StringUtils.isEmpty(contract)) {
@@ -291,6 +293,9 @@ public class SRMSynPayApiPlugin implements Serializable {
                 returnMessage = "合同(" + contract + ")在星瀚中未匹配到合同台账";
                 return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
             }
+            if(contractInfo.getBigDecimal("contractamount").compareTo(BigDecimal.ZERO) == 0){
+                isframeworkcontract = true;
+            }
 
             detailtype = "biztype_contract";
         }
@@ -354,15 +359,13 @@ public class SRMSynPayApiPlugin implements Serializable {
         bizAcctOutBill.set("sharemethod", "rate");//
         bizAcctOutBill.set("nckd_pageid", "nckd_er_publicsrmapply");//默认页面布局
         bizAcctOutBill.set("nckd_isrelapj", isRelapj);//是否关联项目
+        bizAcctOutBill.set("frameworkcontract", isframeworkcontract);//是否框架合同
 
         //单据类型
         if(bizAcctOutBill.getDynamicObjectType().getProperties().containsKey("nckd_billtypefield")) {
             bizAcctOutBill.set("nckd_billtypefield", billTypeInfo);
         }
 
-        BigDecimal totalReimburseAmount = BigDecimal.ZERO;//报销金额合计
-        BigDecimal totalCurrReimburseAmount = BigDecimal.ZERO;//报销金额合计本位币
-
         //费用明细
         DynamicObjectCollection expenseEntry  = bizAcctOutBill.getDynamicObjectCollection("expenseentryentity");
         DynamicObjectType type = expenseEntry.getDynamicObjectType();
@@ -370,77 +373,93 @@ public class SRMSynPayApiPlugin implements Serializable {
 
         Long itemEntryId = DB.genLongId("er_publicreimbursebill.expenseentryentity");
 
-        for(int i = 0; i < bizAccountOutBillEntry.size(); i++){
-            JSONObject jsonData = bizAccountOutBillEntry.getJSONObject(i);
+        BigDecimal totalReimburseAmount = BigDecimal.ZERO;//报销金额合计
+        BigDecimal totalCurrReimburseAmount = BigDecimal.ZERO;//报销金额合计本位币
 
-            String xsproject = jsonData.getString("xsproject");//核算项目,项目编号
-            String currencyType = jsonData.getString("currencyType");//币别
-            BigDecimal taxAmount = CommonHelperUtils.getBigDecimal(jsonData.getString("tax"));//税额
-            BigDecimal amountOriWithoutTax = CommonHelperUtils.getBigDecimal(jsonData.getString("amountOriWithoutTax"));//原币不含税金额
-            BigDecimal taxRate = CommonHelperUtils.getBigDecimal(jsonData.getString("taxRate"));//税率
-            BigDecimal amountOri = CommonHelperUtils.getBigDecimal(jsonData.getString("amountOri"));//原币金额
+        if(bizAccountOutBillEntry.size() > 0) {
+            DynamicObject currency = null;
+            BigDecimal exchangeRate = BigDecimal.ONE;
+            DynamicObject projectInfo = null;
+            BigDecimal taxRate = BigDecimal.ZERO;
+            BigDecimal totalTaxAmount = BigDecimal.ZERO;
+            BigDecimal totalAmountOriWithoutTax = BigDecimal.ZERO;
+            BigDecimal totalCurrAmountOriWithoutTax = BigDecimal.ZERO;
+
+            for (int i = 0; i < bizAccountOutBillEntry.size(); i++) {
+                JSONObject jsonData = bizAccountOutBillEntry.getJSONObject(i);
+
+                String xsproject = jsonData.getString("xsproject");//核算项目,项目编号
+                String currencyType = jsonData.getString("currencyType");//币别
+                BigDecimal taxAmount = CommonHelperUtils.getBigDecimal(jsonData.getString("tax"));//税额
+                BigDecimal amountOriWithoutTax = CommonHelperUtils.getBigDecimal(jsonData.getString("amountOriWithoutTax"));//原币不含税金额
+                taxRate = CommonHelperUtils.getBigDecimal(jsonData.getString("taxRate"));//税率
+                BigDecimal amountOri = CommonHelperUtils.getBigDecimal(jsonData.getString("amountOri"));//原币金额
+
+                currency = CommonHelperUtils.queryBaseDynamicObject("bd_currency", "number", currencyType);
+                if (currency == null) {
+                    returnMessage = "币别(" + orgUnit + ")在星瀚系统中未匹配到数据!";
+                    return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
+                }
 
-            DynamicObject currency = CommonHelperUtils.queryBaseDynamicObject("bd_currency", "number", currencyType);
-            if(currency == null){
-                returnMessage = "币别(" + orgUnit + ")在星瀚系统中未匹配到数据!";
-                return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
-            }
+                if ("XM".equals(billType)) {
+                    if (StringUtils.isEmpty(xsproject)) {
+                        returnMessage = "项目类付款,请检查以下费用明细参数 项目编码 是否为空!";
+                        return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
+                    }
 
-            DynamicObject entry = new DynamicObject(type);
+                    //替换连接符
+                    xsproject = xsproject.replace("-", ".");
 
-            if(i == 0){
-                entry.set("id", itemEntryId);
-            }
+                    QFilter projectFilter = new QFilter("status", QCP.equals, "C");
+                    projectFilter.and(new QFilter("enable", QCP.equals, "1"));
+                    projectFilter.and(new QFilter("number", QCP.equals, xsproject));
+                    projectFilter.and(new QFilter("createorg.id", QCP.equals, costCompany.getLong("id")));
 
-            entry.set("seq", (i+1));
-            entry.set("happendate", bizDate);
+                    projectInfo = BusinessDataServiceHelper.loadSingle("bd_project", projectFilter.toArray());
+                    if (projectInfo == null) {
+                        returnMessage = "项目(" + xsproject + ")在星瀚系统中未匹配到数据!";
+                        return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
+                    }
 
-            if("XM".equals(billType)){
-                if(StringUtils.isEmpty(xsproject) ){
-                    returnMessage = "项目类付款,请检查以下费用明细参数 项目编码 是否为空!";
-                    return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
+                    bizAcctOutBill.set("nckd_project", projectInfo);//项目,表头项目字段也取费用明细中的项目,一张付款单只会对应一个项目
                 }
 
-                //替换连接符
-                xsproject = xsproject.replace("-", ".");
+                if (currency.getLong("id") != 1L) {
+                    exchangeRate = CommonHelperUtils.getExchangeRate(exchangeTableId, currency.getLong("id"), 1L, bizDate);
+                }
 
-                QFilter projectFilter = new QFilter("status", QCP.equals, "C");
-                projectFilter.and(new QFilter("enable", QCP.equals, "1"));
-                projectFilter.and(new QFilter("number", QCP.equals, xsproject));
-                projectFilter.and(new QFilter("createorg.id", QCP.equals, costCompany.getLong("id")));
+                totalTaxAmount = totalTaxAmount.add(taxAmount);
+                totalAmountOriWithoutTax = totalAmountOriWithoutTax.add(amountOriWithoutTax);
 
-                DynamicObject projectInfo = BusinessDataServiceHelper.loadSingle("bd_project", projectFilter.toArray());
+                totalReimburseAmount = totalReimburseAmount.add(amountOri);
+                //报销金额本位币
+                totalCurrReimburseAmount = totalCurrReimburseAmount.add(amountOri.multiply(exchangeRate).setScale(4, BigDecimal.ROUND_HALF_UP));
+                totalCurrAmountOriWithoutTax = totalCurrAmountOriWithoutTax.add(amountOriWithoutTax.multiply(exchangeRate).setScale(4, BigDecimal.ROUND_HALF_UP));
+            }
 
-//                DynamicObject projectInfo = CommonHelperUtils.queryBaseDynamicObject("bd_project", "number", xsproject);
-                if(projectInfo == null){
-                    returnMessage = "项目(" + xsproject + ")在星瀚系统中未匹配到数据!";
-                    return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
-                }
+            DynamicObject entry = new DynamicObject(type);
 
-                entry.set("std_project", projectInfo);//分录项目
-                bizAcctOutBill.set("nckd_project", projectInfo);//项目,表头项目字段也取费用明细中的项目,一张付款单只会对应一个项目
-            }
+            entry.set("id", itemEntryId);
+            entry.set("seq", 1);
+            entry.set("happendate", bizDate);
+            entry.set("std_project", projectInfo);//分录项目
 
             entry.set("entrycostdept", dept);//费用承担部门
             entry.set("entrycostcompany", costCompany);//费用承担公司
             entry.set("entrycurrency", currency);//币别
             entry.set("taxRate", taxRate);//税率
-            entry.set("expenseamount", amountOri);//报销金额
-            entry.set("expeapproveamount", amountOri);//核定金额
-            entry.set("taxamount", taxAmount);//税额
-            entry.set("approvetax", taxAmount);//核定税额
-            entry.set("orientryamount", amountOriWithoutTax);//不含税金额
-            entry.set("price", amountOriWithoutTax);//核定不含税金额
+            entry.set("expenseamount", totalReimburseAmount);//报销金额
+            entry.set("expeapproveamount", totalReimburseAmount);//核定金额
+            entry.set("taxamount", totalTaxAmount);//税额
+            entry.set("approvetax", totalTaxAmount);//核定税额
+            entry.set("orientryamount", totalAmountOriWithoutTax);//不含税金额
+            entry.set("price", totalAmountOriWithoutTax);//核定不含税金额
 
-            BigDecimal exchangeRate = BigDecimal.ONE;
-            if(currency.getLong("id") != 1L){
-                exchangeRate = CommonHelperUtils.getExchangeRate(exchangeTableId, currency.getLong("id"), 1L, bizDate);
-            }
             entry.set("exchangerate", exchangeRate);//汇率
             entry.set("expquotetype", "0");//换算方式
-            entry.set("currexpenseamount", amountOri.multiply(exchangeRate).setScale(2, BigDecimal.ROUND_HALF_UP));//报销金额本位币
-            entry.set("expeapprovecurramount", amountOri.multiply(exchangeRate).setScale(2, BigDecimal.ROUND_HALF_UP));//核定金额本位币
-            entry.set("curprice", amountOriWithoutTax.multiply(exchangeRate).setScale(2, BigDecimal.ROUND_HALF_UP));//核定不含税金额本位币
+            entry.set("currexpenseamount", totalCurrReimburseAmount.setScale(2, BigDecimal.ROUND_HALF_UP));//报销金额本位币
+            entry.set("expeapprovecurramount", totalCurrReimburseAmount.setScale(2, BigDecimal.ROUND_HALF_UP));//核定金额本位币
+            entry.set("curprice", totalCurrAmountOriWithoutTax.setScale(2, BigDecimal.ROUND_HALF_UP));//核定不含税金额本位币
             entry.set("itemfrom", "0");//来源类型
             entry.set("invoicetypeitem", "0");//发票类型
             entry.set("iscrepayableentry", "1");//生成应付单
@@ -448,18 +467,15 @@ public class SRMSynPayApiPlugin implements Serializable {
             entry.set("settlestatus", "unsettle");//结算状态
             entry.set("pubreimburser", applierInfo);//报销人
 
-            if(contractInfo != null) {
+            if (contractInfo != null) {
                 entry.set("entrycontractno", contract);
                 entry.set("entrycontractname", contractInfo.getString("contractname"));
             }
 
             expenseEntry.add(entry);
 
-            totalReimburseAmount = totalReimburseAmount.add(amountOri);
-            //报销金额本位币
-            totalCurrReimburseAmount = totalCurrReimburseAmount.add(amountOri.multiply(exchangeRate).setScale(4, BigDecimal.ROUND_HALF_UP));
+            bizAcctOutBill.set("expenseentryentity", expenseEntry);
         }
-        bizAcctOutBill.set("expenseentryentity", expenseEntry);
 
         //报销金额本位币
         bizAcctOutBill.set("nckd_expenseamt", totalCurrReimburseAmount.setScale(2, BigDecimal.ROUND_HALF_UP));
@@ -654,6 +670,9 @@ public class SRMSynPayApiPlugin implements Serializable {
         type = invoiceEntry.getDynamicObjectType();
         JSONArray fpentry = inputData.getJSONArray("fpentry");
 
+        String invoiceCode = "";
+        String invoiceName = "";
+
         for(int i = 0; i < fpentry.size(); i++){
             JSONObject jsonData = fpentry.getJSONObject(i);
 
@@ -682,6 +701,8 @@ public class SRMSynPayApiPlugin implements Serializable {
                     //发票表头
                     JSONObject invoiceObj = invoiceArray.getJSONObject(j);
 
+                    invoiceCode += (invoiceCode.length() > 0 ? "," : "") + invoiceObj.getString("invoiceNo");
+
                     fpNumber = invoiceObj.getString("invoiceNo");
                     Date invoiceDate = CommonHelperUtils.getDateStringFormat(invoiceObj.getString("invoiceDate"), "yyyy-MM-dd");
                     Date billCreateTime = CommonHelperUtils.getDateStringFormat(invoiceObj.getString("billCreateTime"), "yyyy-MM-dd HH:mm:ss");
@@ -750,6 +771,7 @@ public class SRMSynPayApiPlugin implements Serializable {
                     entry.set("transportnote", "0");//运输票据
 
                     String invoiceGoodsName = "";
+
                     List<String> invoiceGoodsCode = new ArrayList<>();
                     BigDecimal taxRate = BigDecimal.ZERO;
                     BigDecimal taxRate100 = BigDecimal.ZERO;
@@ -778,6 +800,7 @@ public class SRMSynPayApiPlugin implements Serializable {
                             BigDecimal detailAmount = CommonHelperUtils.getBigDecimal(itemObj.getString("detailAmount"));//明细金额
 
                             invoiceGoodsName += (invoiceGoodsName.length() > 0 ? "," : "") + goodsName;
+                            invoiceName += (invoiceName.length() > 0 ? "," : "") + goodsName;
 
                             if(goodsCodeInfo != null && !invoiceGoodsCode.contains(goodsCodeInfo.getString("name"))){
                                 invoiceGoodsCode.add(goodsCodeInfo.getString("name"));
@@ -818,9 +841,9 @@ public class SRMSynPayApiPlugin implements Serializable {
                                 entry.set("num_h", num);//数量
                                 entry.set("unitprice_h", unitPrice.setScale(2, BigDecimal.ROUND_HALF_UP));//单价
 
-                                DynamicObjectCollection expenseEntrys = bizAcctOutBill.getDynamicObjectCollection("expenseentryentity");
-                                expenseEntrys.get(0).set("invoiceno_entry", invoiceObj.getString("invoiceNo"));
-                                expenseEntrys.get(0).set("expensegoodsname", goodsName);
+//                                DynamicObjectCollection expenseEntrys = bizAcctOutBill.getDynamicObjectCollection("expenseentryentity");
+//                                expenseEntrys.get(0).set("invoiceno_entry", invoiceObj.getString("invoiceNo"));
+//                                expenseEntrys.get(0).set("expensegoodsname", goodsName);
                             }
 
                             invoiceitementry.add(itemEntry);
@@ -845,7 +868,17 @@ public class SRMSynPayApiPlugin implements Serializable {
         }
         bizAcctOutBill.set("invoiceentry", invoiceEntry);
 
+        if(invoiceName.length() > 200){
+            invoiceName = invoiceName.substring(0, 200) + "...";
+        }
+
+        if(invoiceCode.length() > 200){
+            invoiceCode = invoiceCode.substring(0, 200) + "...";
+        }
 
+        DynamicObjectCollection expenseEntrys = bizAcctOutBill.getDynamicObjectCollection("expenseentryentity");
+        expenseEntrys.get(0).set("invoiceno_entry", invoiceCode);
+        expenseEntrys.get(0).set("expensegoodsname", invoiceName);
 
         //合同信息
         if(contractInfo != null){