|
@@ -2,9 +2,11 @@ package nckd.jimin.jyyy.fi.webapi;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.kingdee.util.StringUtils;
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+import kd.bos.dataentity.entity.LocaleString;
|
|
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.logging.Log;
|
|
import kd.bos.logging.Log;
|
|
@@ -13,21 +15,24 @@ import kd.bos.openapi.common.custom.annotation.ApiController;
|
|
import kd.bos.openapi.common.custom.annotation.ApiParam;
|
|
import kd.bos.openapi.common.custom.annotation.ApiParam;
|
|
import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
|
|
import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
|
|
import kd.bos.openapi.common.result.CustomApiResult;
|
|
import kd.bos.openapi.common.result.CustomApiResult;
|
|
-import kd.bos.openapi.common.result.OpenApiResult;
|
|
|
|
-import kd.bos.openapi.common.util.OpenApiSdkUtil;
|
|
|
|
import kd.bos.orm.query.QCP;
|
|
import kd.bos.orm.query.QCP;
|
|
import kd.bos.orm.query.QFilter;
|
|
import kd.bos.orm.query.QFilter;
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
-import kd.bos.servicehelper.operation.OperationServiceHelper;
|
|
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
-
|
|
|
|
|
|
+import nckd.base.helper.CommonHelperUtils;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.ParseException;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * SRM系统调用,付款同步接口
|
|
|
|
+ * 描述:接口实现逻辑包含对公报销单同步、预付单同步,通过参数判断传的是对公报销还是预付
|
|
|
|
+ * bizAccountOutBills:对公报销单;dailyLoanBills:预付单,两个参数只有其中一个有值。
|
|
|
|
+ * @author wanghaiwu_kd
|
|
|
|
+ * @date 2025/05010
|
|
|
|
+ */
|
|
@ApiController(
|
|
@ApiController(
|
|
desc = "对接SRM预付款、付款",
|
|
desc = "对接SRM预付款、付款",
|
|
value = "SRM"
|
|
value = "SRM"
|
|
@@ -50,7 +55,6 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
int bizAcctOutBillSize = 0;
|
|
int bizAcctOutBillSize = 0;
|
|
int dailyLoanBillSize = 0;
|
|
int dailyLoanBillSize = 0;
|
|
|
|
|
|
-
|
|
|
|
if(bizAccountOutBills != null && bizAccountOutBills.size() > 0){
|
|
if(bizAccountOutBills != null && bizAccountOutBills.size() > 0){
|
|
bizAcctOutBillSize = bizAccountOutBills.size();
|
|
bizAcctOutBillSize = bizAccountOutBills.size();
|
|
}
|
|
}
|
|
@@ -69,7 +73,6 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
}
|
|
}
|
|
|
|
|
|
return returnResult("0", "成功", responseData);
|
|
return returnResult("0", "成功", responseData);
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -97,8 +100,8 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
*/
|
|
*/
|
|
private JSONObject saveBizAcctOutBillInfo (JSONObject inputData){
|
|
private JSONObject saveBizAcctOutBillInfo (JSONObject inputData){
|
|
JSONObject returnMap = new JSONObject();
|
|
JSONObject returnMap = new JSONObject();
|
|
-
|
|
|
|
- DynamicObject bizAcctOutBill = BusinessDataServiceHelper.newDynamicObject(ENTITY_PUBLICPAY);
|
|
|
|
|
|
+ String code = "1";
|
|
|
|
+ String returnMessage = "";
|
|
|
|
|
|
String billType = inputData.getString("billType");//单据类型
|
|
String billType = inputData.getString("billType");//单据类型
|
|
String srmBillNo = inputData.getString("SRMBillNo");//srm单据号
|
|
String srmBillNo = inputData.getString("SRMBillNo");//srm单据号
|
|
@@ -113,15 +116,102 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
String biller = inputData.getString("biller");//制单人工号
|
|
String biller = inputData.getString("biller");//制单人工号
|
|
String applier = inputData.getString("applier");//经办人工号
|
|
String applier = inputData.getString("applier");//经办人工号
|
|
|
|
|
|
- applier = "ID-000014";
|
|
|
|
|
|
+ if(StringUtils.isEmpty(srmBillNo) || StringUtils.isEmpty(srmUrl) || StringUtils.isEmpty(cause)
|
|
|
|
+ || StringUtils.isEmpty(orgUnit) || StringUtils.isEmpty(position) || StringUtils.isEmpty(biller) || StringUtils.isEmpty(applier)){
|
|
|
|
+ returnMessage = "请检查以下参数 SRM单号、srmUrl、事由、申请部门、申请人职位、制单人、经办人 是否为空!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ } else if("XM".equals(billType)){
|
|
|
|
+ if(StringUtils.isEmpty(project) || StringUtils.isEmpty(contract)){
|
|
|
|
+ returnMessage = "项目类付款,请检查以下参数 项目编码、合同编码 是否为空!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// DynamicObject projectInfo = CommonHelperUtils.queryDynamicObject("bd_project", "number", project);
|
|
|
|
+// if(projectInfo == null){
|
|
|
|
+// returnMessage = "项目(" + project + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+// return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ DynamicObject creatorInfo = CommonHelperUtils.queryBaseDynamicObject("bos_user", "number", biller);
|
|
|
|
+ if(creatorInfo == null){
|
|
|
|
+ returnMessage = "制单人(" + biller + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject applierInfo = CommonHelperUtils.queryBaseDynamicObject("bos_user", "number", applier);
|
|
|
|
+ if(applierInfo == null){
|
|
|
|
+ returnMessage = "经办人(" + applier + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject dept = CommonHelperUtils.queryBaseDynamicObject("bos_org", "number", orgUnit);
|
|
|
|
+ if(dept == null){
|
|
|
|
+ returnMessage = "行政组织(" + orgUnit + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject positionInfo = CommonHelperUtils.queryBaseDynamicObject("hbpm_positionhr", "number", position);
|
|
|
|
+ if(positionInfo == null){
|
|
|
|
+ returnMessage = "岗位(" + position + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+ LocaleString positionName = new LocaleString(positionInfo.getString("name"));
|
|
|
|
+
|
|
|
|
+ //申请人公司行政组织
|
|
|
|
+ DynamicObject adminCompany = CommonHelperUtils.getAdminCompany(dept);
|
|
|
|
+
|
|
|
|
+ QFilter qFilter = new QFilter("toorg", QCP.equals, dept.getPkValue());
|
|
|
|
+ DynamicObject relation = BusinessDataServiceHelper.loadSingle("bos_org_orgrelation_dept", qFilter.toArray());
|
|
|
|
+ if(relation == null){
|
|
|
|
+ returnMessage = "行政组织(" + dept.getString("number") + ", " + dept.getString("name") + ")在星瀚系统未维护委托业务单元!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+ //费用承担公司
|
|
|
|
+ DynamicObject costCompany = relation.getDynamicObject("fromorg");
|
|
|
|
+ //汇率表Id
|
|
|
|
+ Long exchangeTableId = CommonHelperUtils.getExchageTableId(costCompany.getLong("id"));
|
|
|
|
+
|
|
|
|
+ if(exchangeTableId == null){
|
|
|
|
+ returnMessage = "核算组织(" + costCompany.getString("name") + ")在星瀚系统匹配到汇率表!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
|
|
- bizAcctOutBill.set("bizdate", new Date());//申请日期
|
|
|
|
|
|
+ DynamicObject bizAcctOutBill = BusinessDataServiceHelper.newDynamicObject(ENTITY_PUBLICPAY);
|
|
|
|
+ Date bizDate = new Date();
|
|
|
|
+ try {
|
|
|
|
+ bizDate = CommonHelperUtils.getCurDateForm(new Date(), true);//申请日期
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
+// throw new RuntimeException(e);
|
|
|
|
+ returnMessage = e.getMessage();
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bizAcctOutBill.set("bizdate", bizDate);//申请日期
|
|
|
|
+ bizAcctOutBill.set("billstatus", "A");//单据状态
|
|
|
|
+ bizAcctOutBill.set("reimbursetype", "expense");//报账类型
|
|
|
|
+ bizAcctOutBill.set("nckd_srmbillno", srmBillNo);//srm单据号
|
|
|
|
+ bizAcctOutBill.set("nckd_srmurl", srmUrl);//srm单点url
|
|
|
|
+ bizAcctOutBill.set("contractsconn", contract);//合同号
|
|
bizAcctOutBill.set("description", cause);//事由
|
|
bizAcctOutBill.set("description", cause);//事由
|
|
- bizAcctOutBill.set("applier", getF7FieldValue("bos_user", "number", applier));//申请人
|
|
|
|
- bizAcctOutBill.set("org", getF7FieldValue("bos_org", "number", "20240612-0009"));//部门
|
|
|
|
- bizAcctOutBill.set("company", getF7FieldValue("bos_org", "number", "20240612-0009"));//公司行政组织
|
|
|
|
- bizAcctOutBill.set("costdept", getF7FieldValue("bos_org", "number", "20240612-0009"));//费用承担部门
|
|
|
|
- bizAcctOutBill.set("costcompany", getF7FieldValue("bos_org", "number", "3140"));//费用承担公司
|
|
|
|
|
|
+ bizAcctOutBill.set("applier", applierInfo);//申请人
|
|
|
|
+ bizAcctOutBill.set("applierpositionstr", positionName);//职位
|
|
|
|
+ bizAcctOutBill.set("org", dept);//申请人部门
|
|
|
|
+ bizAcctOutBill.set("company", adminCompany);//申请人公司
|
|
|
|
+ bizAcctOutBill.set("costdept", dept);//费用承担部门
|
|
|
|
+ bizAcctOutBill.set("costcompany", costCompany);//费用承担公司
|
|
|
|
+ bizAcctOutBill.set("paycompany", costCompany);//支付公司
|
|
|
|
+ bizAcctOutBill.set("creator", creatorInfo);//制单人
|
|
|
|
+ bizAcctOutBill.set("tel", applierInfo.get("phone"));//电话号码
|
|
|
|
+ bizAcctOutBill.set("formid", "er_publicreimbursebill");//表单id
|
|
|
|
+ bizAcctOutBill.set("iscrepayablebill", "0");//生成应付单
|
|
|
|
+ bizAcctOutBill.set("billpayertype", "bd_supplier");//往来类型
|
|
|
|
+ bizAcctOutBill.set("detailtype", "biztype_other");//关联业务
|
|
|
|
+ bizAcctOutBill.set("assettype", "newasset");//资产类型
|
|
|
|
+ bizAcctOutBill.set("abovequota", "0");//超额
|
|
|
|
+ bizAcctOutBill.set("ispush", "false");//合同下推生成
|
|
|
|
+
|
|
|
|
+ BigDecimal totalReimburseAmount = BigDecimal.ZERO;//报销金额合计
|
|
|
|
|
|
//费用明细
|
|
//费用明细
|
|
DynamicObjectCollection expenseEntry = bizAcctOutBill.getDynamicObjectCollection("expenseentryentity");
|
|
DynamicObjectCollection expenseEntry = bizAcctOutBill.getDynamicObjectCollection("expenseentryentity");
|
|
@@ -131,113 +221,199 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
for(int i = 0; i < bizAccountOutBillEntry.size(); i++){
|
|
for(int i = 0; i < bizAccountOutBillEntry.size(); i++){
|
|
JSONObject jsonData = bizAccountOutBillEntry.getJSONObject(i);
|
|
JSONObject jsonData = bizAccountOutBillEntry.getJSONObject(i);
|
|
|
|
|
|
- String xsproject = "FYXM01.26";//jsonData.getString("xsproject");//核算项目,项目编号
|
|
|
|
- String tax = jsonData.getString("tax");//税额
|
|
|
|
- String amountOriWithoutTax = jsonData.getString("amountOriWithoutTax");//原币不含税金额
|
|
|
|
- String taxRate = jsonData.getString("taxRate");//税率
|
|
|
|
|
|
+ String xsproject = jsonData.getString("xsproject");//核算项目,项目编号
|
|
String currencyType = jsonData.getString("currencyType");//币别
|
|
String currencyType = jsonData.getString("currencyType");//币别
|
|
- String amountOri = jsonData.getString("amountOri");//原币金额
|
|
|
|
|
|
+ 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"));//原币金额
|
|
|
|
+
|
|
|
|
+ DynamicObject currency = CommonHelperUtils.queryBaseDynamicObject("bd_currency", "number", currencyType);
|
|
|
|
+ if(currency == null){
|
|
|
|
+ returnMessage = "币别(" + orgUnit + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
|
|
DynamicObject entry = new DynamicObject(type);
|
|
DynamicObject entry = new DynamicObject(type);
|
|
|
|
|
|
- entry.set("expenseitem", getF7FieldValue("er_expenseitemedit", "number", "FYXM01.26"));
|
|
|
|
- entry.set("entrycurrency", getF7FieldValue("bd_currency", "number", "CNY"));
|
|
|
|
- entry.set("expenseamount", "100");
|
|
|
|
|
|
+ entry.set("seq", (i+1));
|
|
|
|
+ entry.set("happendate", bizDate);
|
|
|
|
+
|
|
|
|
+ if("XM".equals(billType)){
|
|
|
|
+ if(StringUtils.isEmpty(xsproject) ){
|
|
|
|
+ returnMessage = "项目类付款,请检查以下费用明细参数 项目编码 是否为空!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject projectInfo = CommonHelperUtils.queryBaseDynamicObject("bd_project", "number", project);
|
|
|
|
+ if(projectInfo == null){
|
|
|
|
+ returnMessage = "项目(" + project + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ entry.set("std_project", projectInfo);//分录项目
|
|
|
|
+ bizAcctOutBill.set("nckd_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);//核定不含税金额
|
|
|
|
+
|
|
|
|
+ BigDecimal exchangeRate = BigDecimal.ONE;
|
|
|
|
+ if(currency.getLong("id") != 1L){
|
|
|
|
+ exchangeRate = CommonHelperUtils.getExchangeRate(exchangeTableId, currency.getLong("id"), 1L, bizDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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("itemfrom", "0");//来源类型
|
|
|
|
+ entry.set("invoicetypeitem", "0");//发票类型
|
|
|
|
+ entry.set("iscrepayableentry", "1");//生成应付单
|
|
|
|
+// entry.set("expentrystatus", "");//单据状态
|
|
|
|
+ entry.set("settlestatus", "unsettle");//结算状态
|
|
|
|
+ entry.set("pubreimburser", applierInfo);//报销人
|
|
|
|
|
|
expenseEntry.add(entry);
|
|
expenseEntry.add(entry);
|
|
|
|
+
|
|
|
|
+ totalReimburseAmount = totalReimburseAmount.add(amountOri);
|
|
}
|
|
}
|
|
bizAcctOutBill.set("expenseentryentity", expenseEntry);
|
|
bizAcctOutBill.set("expenseentryentity", expenseEntry);
|
|
|
|
|
|
-// //收款明细
|
|
|
|
-// DynamicObjectCollection accountEntry = bizAcctOutBill.getDynamicObjectCollection("accountentry");
|
|
|
|
-// type = accountEntry.getDynamicObjectType();
|
|
|
|
-// JSONArray bizAccountOutBillAccountEntry = inputData.getJSONArray("bizAccountOutBillAccountEntry");
|
|
|
|
-//
|
|
|
|
-// for(int i = 0; i < bizAccountOutBillAccountEntry.size(); i++){
|
|
|
|
-// JSONObject jsonData = bizAccountOutBillAccountEntry.getJSONObject(i);
|
|
|
|
-//
|
|
|
|
-// String payerType = jsonData.getString("payerType");//收款人类型
|
|
|
|
-// String payerName = jsonData.getString("payerName");//原币社会信用码
|
|
|
|
-// String amountOri = jsonData.getString("amountOri");//原币金额
|
|
|
|
-// String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
-//
|
|
|
|
-// DynamicObject entry = new DynamicObject(type);
|
|
|
|
-//
|
|
|
|
-// accountEntry.add(entry);
|
|
|
|
-// }
|
|
|
|
-// bizAcctOutBill.set("accountentry", accountEntry);
|
|
|
|
-//
|
|
|
|
-// //冲预付/借款
|
|
|
|
-// DynamicObjectCollection writeoffmoney = bizAcctOutBill.getDynamicObjectCollection("writeoffmoney");
|
|
|
|
-// type = writeoffmoney.getDynamicObjectType();
|
|
|
|
-// JSONArray bizAccountOutBillLoanCheckEntry = inputData.getJSONArray("bizAccountOutBillLoanCheckEntry");
|
|
|
|
-//
|
|
|
|
-// for(int i = 0; i < bizAccountOutBillLoanCheckEntry.size(); i++){
|
|
|
|
-// JSONObject jsonData = bizAccountOutBillLoanCheckEntry.getJSONObject(i);
|
|
|
|
-//
|
|
|
|
-// String sourceBillNumber = jsonData.getString("sourceBillNumber");//源单编号(借款单)
|
|
|
|
-// String checkAmountOri = jsonData.getString("checkAmountOri");//冲账金额
|
|
|
|
-// String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
-// String srmseq = jsonData.getString("srmseq");//预付单行号
|
|
|
|
-//
|
|
|
|
-// DynamicObject entry = new DynamicObject(type);
|
|
|
|
-//
|
|
|
|
-// writeoffmoney.add(entry);
|
|
|
|
-// }
|
|
|
|
-// bizAcctOutBill.set("writeoffmoney", writeoffmoney);
|
|
|
|
-//
|
|
|
|
-// //发票信息
|
|
|
|
-// DynamicObjectCollection invoiceEntry = bizAcctOutBill.getDynamicObjectCollection("invoiceentry");
|
|
|
|
-// type = invoiceEntry.getDynamicObjectType();
|
|
|
|
-// JSONArray fpentry = inputData.getJSONArray("fpentry");
|
|
|
|
-//
|
|
|
|
-// for(int i = 0; i < fpentry.size(); i++){
|
|
|
|
-// JSONObject jsonData = fpentry.getJSONObject(i);
|
|
|
|
-//
|
|
|
|
-// String fpNumber = jsonData.getString("fpNumber");//发票号
|
|
|
|
-// String fpCode = jsonData.getString("fpCode");//发票代码
|
|
|
|
-// String taxAmount = jsonData.getString("taxAmount");//税额
|
|
|
|
-//
|
|
|
|
-// DynamicObject entry = new DynamicObject(type);
|
|
|
|
-//
|
|
|
|
-// invoiceEntry.add(entry);
|
|
|
|
-// }
|
|
|
|
-// bizAcctOutBill.set("invoiceentry", invoiceEntry);
|
|
|
|
|
|
+ //收款明细
|
|
|
|
+ DynamicObjectCollection accountEntry = bizAcctOutBill.getDynamicObjectCollection("accountentry");
|
|
|
|
+ type = accountEntry.getDynamicObjectType();
|
|
|
|
+ JSONArray bizAccountOutBillAccountEntry = inputData.getJSONArray("bizAccountOutBillAccountEntry");
|
|
|
|
|
|
-// try {
|
|
|
|
- JSONArray test = new JSONArray();
|
|
|
|
|
|
+ for(int i = 0; i < bizAccountOutBillAccountEntry.size(); i++){
|
|
|
|
+ JSONObject jsonData = bizAccountOutBillAccountEntry.getJSONObject(i);
|
|
|
|
|
|
- JSONObject testobj = new JSONObject();
|
|
|
|
-// testobj.put("billno", "testsdk");
|
|
|
|
- testobj.put("bizdate", "2022-08-29");
|
|
|
|
- testobj.put("description", "test");
|
|
|
|
- testobj.put("applier_number", "ID-000014");
|
|
|
|
- testobj.put("org_number", "20240612-0009");
|
|
|
|
- testobj.put("company_number", "20240612-0009");
|
|
|
|
- testobj.put("costdept_number", "20240612-0009");
|
|
|
|
- testobj.put("costcompany_number", "3140");
|
|
|
|
|
|
+ String payerType = jsonData.getString("payerType");//收款人类型
|
|
|
|
+ String payerName = jsonData.getString("payerName");//原币社会信用码
|
|
|
|
+ String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
+ BigDecimal amountOri = CommonHelperUtils.getBigDecimal(jsonData.getString("amountOri"));//原币金额
|
|
|
|
|
|
- JSONArray entryArray = new JSONArray();
|
|
|
|
|
|
+ if(StringUtils.isEmpty(payerType)){
|
|
|
|
+ returnMessage = "检查以下收款信息参数 收款人类型 是否为空!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+ if(!"20".equals(payerType)){
|
|
|
|
+ returnMessage = "收款人类型只支持供应商!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
|
|
- JSONObject entryObj = new JSONObject();
|
|
|
|
- entryObj.put("entrycurrency_number", "CNY");
|
|
|
|
- entryObj.put("expenseitem_number", "FYXM01.26");
|
|
|
|
- entryObj.put("expenseamount", "989.92");
|
|
|
|
|
|
+ DynamicObject supplier = CommonHelperUtils.queryBaseDynamicObject("bd_supplier", "societycreditcode", payerName);
|
|
|
|
+ if(supplier == null){
|
|
|
|
+ returnMessage = "供应商(" + payerName + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
|
|
- entryArray.add(entryObj);
|
|
|
|
|
|
+ DynamicObject currency = CommonHelperUtils.queryBaseDynamicObject("bd_currency", "number", currencyType);
|
|
|
|
+ if(currency == null){
|
|
|
|
+ returnMessage = "币别(" + orgUnit + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
|
|
- testobj.put("expenseentryentity", entryArray);
|
|
|
|
|
|
+ DynamicObject entry = new DynamicObject(type);
|
|
|
|
+ entry.set("payerType", "bd_supplier");//收款人类型
|
|
|
|
+ entry.set("supplier", supplier);//收款人
|
|
|
|
+ entry.set("accountcurrency", currency);//币别
|
|
|
|
+ entry.set("orireceiveamount", amountOri);//收款金额
|
|
|
|
+
|
|
|
|
+ BigDecimal exchangeRate = BigDecimal.ONE;
|
|
|
|
+ if(currency.getLong("id") != 1L){
|
|
|
|
+ exchangeRate = CommonHelperUtils.getExchangeRate(exchangeTableId, currency.getLong("id"), 1L, bizDate);
|
|
|
|
+ }
|
|
|
|
|
|
- test.add(testobj);
|
|
|
|
|
|
+ entry.set("receiveamount", amountOri.multiply(exchangeRate).setScale(4, BigDecimal.ROUND_HALF_UP));//收款金额本位币
|
|
|
|
|
|
- JSONObject requestDataJson = new JSONObject();
|
|
|
|
- requestDataJson.put("data", test);
|
|
|
|
|
|
+ accountEntry.add(entry);
|
|
|
|
|
|
- logger.info("srm测试:" + bizAcctOutBill.toString());
|
|
|
|
|
|
+ bizAcctOutBill.set("billpayerid", supplier);//表头往来单位
|
|
|
|
+ }
|
|
|
|
+ bizAcctOutBill.set("accountentry", accountEntry);
|
|
|
|
|
|
-// OpenApiResult result = OpenApiSdkUtil.invoke("/v2/em/er_publicreimbursebill/er_publicreimbursebill_save", requestDataJson, new HashMap<>());
|
|
|
|
|
|
+ BigDecimal totalLoanCheckAmount = BigDecimal.ZERO;//冲销金额合计
|
|
|
|
+ //冲预付/借款
|
|
|
|
+ DynamicObjectCollection writeoffmoney = bizAcctOutBill.getDynamicObjectCollection("writeoffmoney");
|
|
|
|
+ type = writeoffmoney.getDynamicObjectType();
|
|
|
|
+ JSONArray bizAccountOutBillLoanCheckEntry = inputData.getJSONArray("bizAccountOutBillLoanCheckEntry");
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < bizAccountOutBillLoanCheckEntry.size(); i++){
|
|
|
|
+ JSONObject jsonData = bizAccountOutBillLoanCheckEntry.getJSONObject(i);
|
|
|
|
+
|
|
|
|
+ String sourceBillNumber = jsonData.getString("sourceBillNumber");//SRM预付单编号
|
|
|
|
+ String currencyType = jsonData.getString("currencyType");//币别
|
|
|
|
+ String srmseq = jsonData.getString("srmseq");//预付单行号
|
|
|
|
+
|
|
|
|
+ BigDecimal checkAmountOri = CommonHelperUtils.getBigDecimal(jsonData.getString("checkAmountOri"));//冲账金额
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isEmpty(sourceBillNumber) || StringUtils.isEmpty(currencyType)){
|
|
|
|
+ returnMessage = "请检查冲预付参数 预付单号、币别 是否为空!";
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject prepayBillInfo = CommonHelperUtils.queryBillDynamicObject("er_prepaybill", "nckd_srmbillno", sourceBillNumber);
|
|
|
|
+ if(currency == null){
|
|
|
|
+ returnMessage = "预付单(" + sourceBillNumber + ")在星瀚系统中未匹配到数据!";
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject entry = new DynamicObject(type);
|
|
|
|
+
|
|
|
|
+ entry.set("loancurrency", currency);//币别
|
|
|
|
+ entry.set("accloanamount", checkAmountOri);//冲销金额
|
|
|
|
+ entry.set("sourcebillid", prepayBillInfo.getPkValue().toString());//源单id
|
|
|
|
+ entry.set("seq", srmseq);
|
|
|
|
+
|
|
|
|
+ writeoffmoney.add(entry);
|
|
|
|
+
|
|
|
|
+ totalLoanCheckAmount = totalLoanCheckAmount.add(checkAmountOri);
|
|
|
|
+ }
|
|
|
|
+ bizAcctOutBill.set("writeoffmoney", writeoffmoney);
|
|
|
|
+
|
|
|
|
+ bizAcctOutBill.set("reimburseamount", totalReimburseAmount);//报销金额
|
|
|
|
+ bizAcctOutBill.set("approveamount", totalReimburseAmount);//核定金额
|
|
|
|
+ bizAcctOutBill.set("payamount", totalReimburseAmount.subtract(totalLoanCheckAmount));//付现金额
|
|
|
|
+ bizAcctOutBill.set("notpayamount", totalReimburseAmount);//未付金额
|
|
|
|
+
|
|
|
|
+ //发票信息
|
|
|
|
+ DynamicObjectCollection invoiceEntry = bizAcctOutBill.getDynamicObjectCollection("invoiceentry");
|
|
|
|
+ type = invoiceEntry.getDynamicObjectType();
|
|
|
|
+ JSONArray fpentry = inputData.getJSONArray("fpentry");
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < fpentry.size(); i++){
|
|
|
|
+ JSONObject jsonData = fpentry.getJSONObject(i);
|
|
|
|
+
|
|
|
|
+ String fpNumber = jsonData.getString("fpNumber");//发票号
|
|
|
|
+ String fpCode = jsonData.getString("fpCode");//发票代码
|
|
|
|
+ String taxAmount = jsonData.getString("taxAmount");//税额
|
|
|
|
+
|
|
|
|
+ DynamicObject entry = new DynamicObject(type);
|
|
|
|
+ entry.set("invoiceno", fpNumber);//发票号
|
|
|
|
+ entry.set("invoicecode", fpCode);//发票代码
|
|
|
|
+ entry.set("taxamount_invoice", taxAmount);//税额
|
|
|
|
+
|
|
|
|
+ invoiceEntry.add(entry);
|
|
|
|
+ }
|
|
|
|
+ bizAcctOutBill.set("invoiceentry", invoiceEntry);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
|
|
-// String message = result.getMessage();
|
|
|
|
|
|
|
|
//新增保存供应商对象
|
|
//新增保存供应商对象
|
|
OperationResult resultSave = SaveServiceHelper.saveOperate(ENTITY_PUBLICPAY, new DynamicObject[]{bizAcctOutBill}, OperateOption.create());
|
|
OperationResult resultSave = SaveServiceHelper.saveOperate(ENTITY_PUBLICPAY, new DynamicObject[]{bizAcctOutBill}, OperateOption.create());
|
|
@@ -249,37 +425,18 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
err.append("/").append(message);
|
|
err.append("/").append(message);
|
|
}
|
|
}
|
|
|
|
|
|
- returnMap.put("code", "500");
|
|
|
|
- returnMap.put("msg", err.toString());
|
|
|
|
-
|
|
|
|
- return returnMap;
|
|
|
|
|
|
+ returnMessage = "失败" + err.toString();
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
}
|
|
}
|
|
|
|
|
|
-// } catch(Exception e){
|
|
|
|
-// String msg = e.getMessage();
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// DynamicObject customerObj = BusinessDataServiceHelper.loadSingle(supplierId, "bd_supplier");
|
|
|
|
-//
|
|
|
|
-// OperationServiceHelper.executeOperate("submit", ENTITY_SUPPLIER, new DynamicObject[]{customerObj}, OperateOption.create());
|
|
|
|
-// OperationServiceHelper.executeOperate("audit", ENTITY_SUPPLIER, new DynamicObject[]{customerObj}, OperateOption.create());
|
|
|
|
|
|
+ return buildReturnData("0", srmBillNo, "成功", resultSave.getSuccessPkIds().get(0).toString(), null, ENTITY_PREPAY);
|
|
|
|
|
|
- return returnMap;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private DynamicObject getF7FieldValue(String entityName, String type, String value){
|
|
|
|
- QFilter qFilter = new QFilter("status", QCP.equals, "C");
|
|
|
|
- qFilter.and(new QFilter("number", QCP.equals, value));
|
|
|
|
-
|
|
|
|
- DynamicObject objectInfo = BusinessDataServiceHelper.loadSingle(entityName, qFilter.toArray());
|
|
|
|
-
|
|
|
|
- return objectInfo;
|
|
|
|
|
|
+ } catch(Exception e){
|
|
|
|
+ returnMessage = "失败" + e.getMessage();
|
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 同步付款
|
|
* 同步付款
|
|
* @param dailyLoanBills
|
|
* @param dailyLoanBills
|
|
@@ -290,6 +447,33 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
return responseData;
|
|
return responseData;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 构造返回data参数
|
|
|
|
+ * @param status
|
|
|
|
+ * @param message
|
|
|
|
+ * @param fid
|
|
|
|
+ * @param number
|
|
|
|
+ * @param entityName
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public JSONObject buildReturnData(String status, String srmBillNO, String message, String fid, String number, String entityName){
|
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
|
+
|
|
|
|
+ data.put("status", status);
|
|
|
|
+ data.put("SRMBillNo", srmBillNO);
|
|
|
|
+ data.put("message", message);
|
|
|
|
+ if("0".equals(status)) {
|
|
|
|
+ data.put("fid", fid);
|
|
|
|
+ data.put("number", number);
|
|
|
|
+
|
|
|
|
+ String url = "";
|
|
|
|
+
|
|
|
|
+ data.put("url", url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 自定义返回data对象
|
|
* 自定义返回data对象
|
|
* @param code 编码
|
|
* @param code 编码
|