|
@@ -8,6 +8,7 @@ import kd.bos.dataentity.entity.DynamicObject;
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
import kd.bos.dataentity.entity.LocaleString;
|
|
|
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
|
|
+import kd.bos.db.DB;
|
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
|
import kd.bos.logging.Log;
|
|
|
import kd.bos.logging.LogFactory;
|
|
@@ -18,13 +19,17 @@ import kd.bos.openapi.common.result.CustomApiResult;
|
|
|
import kd.bos.orm.query.QCP;
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+import kd.bos.servicehelper.DispatchServiceHelper;
|
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
import nckd.base.helper.CommonHelperUtils;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.Serializable;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.ParseException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
* SRM系统调用,付款同步接口
|
|
@@ -239,6 +244,7 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
|
bizAcctOutBill.set("abovequota", "0");
|
|
|
bizAcctOutBill.set("ispush", "false");
|
|
|
bizAcctOutBill.set("nckd_srmstatus", "1");
|
|
|
+ bizAcctOutBill.set("nckd_duigong", "01");
|
|
|
|
|
|
BigDecimal totalReimburseAmount = BigDecimal.ZERO;
|
|
|
|
|
@@ -247,6 +253,8 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
|
DynamicObjectType type = expenseEntry.getDynamicObjectType();
|
|
|
JSONArray bizAccountOutBillEntry = inputData.getJSONArray("bizAccountOutBillEntry");
|
|
|
|
|
|
+ Long itemEntryId = DB.genLongId("er_publicreimbursebill.expenseentryentity");
|
|
|
+
|
|
|
for(int i = 0; i < bizAccountOutBillEntry.size(); i++){
|
|
|
JSONObject jsonData = bizAccountOutBillEntry.getJSONObject(i);
|
|
|
|
|
@@ -265,6 +273,10 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
|
|
|
|
DynamicObject entry = new DynamicObject(type);
|
|
|
|
|
|
+ if(i == 0){
|
|
|
+ entry.set("id", itemEntryId);
|
|
|
+ }
|
|
|
+
|
|
|
entry.set("seq", (i+1));
|
|
|
entry.set("happendate", bizDate);
|
|
|
|
|
@@ -374,7 +386,7 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
|
if(entryBanks.size() > 0){
|
|
|
for(DynamicObject entryBank : entryBanks){
|
|
|
if(entryBank.getBoolean("isdefault_bank")){
|
|
|
- entry.set("payeraccount", entryBank.getString("payeraccount"));
|
|
|
+ entry.set("payeraccount", entryBank.getString("bankaccount"));
|
|
|
entry.set("payeraccountname", entryBank.getString("accountname"));
|
|
|
entry.set("payerbank", entryBank.getDynamicObject("bank"));
|
|
|
|
|
@@ -455,20 +467,191 @@ public class SRMSynPayApiPlugin implements Serializable {
|
|
|
|
|
|
String fpNumber = jsonData.getString("fpNumber");
|
|
|
String fpCode = jsonData.getString("fpCode");
|
|
|
+ String serialNo = jsonData.getString("serialNo");
|
|
|
String taxAmount = jsonData.getString("taxAmount");
|
|
|
|
|
|
+ Long invoiceEntryId = DB.genLongId("er_publicreimbursebill.invoiceentry");
|
|
|
+
|
|
|
DynamicObject entry = new DynamicObject(type);
|
|
|
+ entry.set("id", invoiceEntryId);
|
|
|
+ entry.set("seq", (i + 1));
|
|
|
entry.set("invoiceno", fpNumber);
|
|
|
entry.set("invoicecode", fpCode);
|
|
|
- entry.set("taxamount_invoice", taxAmount);
|
|
|
+ entry.set("serialno", serialNo);
|
|
|
+
|
|
|
+ List<String> serialNoList = new ArrayList<String>();
|
|
|
+ serialNoList.add(serialNo);
|
|
|
+
|
|
|
+ Map<String, Object> invoiceMap = DispatchServiceHelper.invokeBizService("imc", "rim", "FpzsService", "query", serialNoList);
|
|
|
+
|
|
|
+ if(invoiceMap != null && invoiceMap.get("data") != null){
|
|
|
+ JSONArray invoiceArray = (JSONArray)invoiceMap.get("data");
|
|
|
+ for(int j = 0; j < invoiceArray.size(); j++) {
|
|
|
+
|
|
|
+ JSONObject invoiceObj = invoiceArray.getJSONObject(j);
|
|
|
+
|
|
|
+ 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");
|
|
|
+ String salerName = invoiceObj.getString("salerName");
|
|
|
+ String salerTaxNo = invoiceObj.getString("salerTaxNo");
|
|
|
+ String buyerName = invoiceObj.getString("buyerName");
|
|
|
+ String buyerTaxNo = invoiceObj.getString("buyerTaxNo");
|
|
|
+ DynamicObject invoiceTypeInfo = CommonHelperUtils.queryBaseDynamicObject("er_invoicetype", "number", invoiceObj.getString("invoiceType"));
|
|
|
+ BigDecimal taxAmountTotal = CommonHelperUtils.getBigDecimal(invoiceObj.getBigDecimal("totalTaxAmount"));
|
|
|
+ BigDecimal totalamount = CommonHelperUtils.getBigDecimal(invoiceObj.getBigDecimal("totalAmount"));
|
|
|
+ BigDecimal invoiceAmount = CommonHelperUtils.getBigDecimal(invoiceObj.getBigDecimal("invoiceAmount"));
|
|
|
+
|
|
|
+ DynamicObject salerInfo = CommonHelperUtils.queryBaseDynamicObject("bd_supplier", "societycreditcode", salerTaxNo);
|
|
|
+ if(salerInfo == null){
|
|
|
+ returnMessage = "供应商(" + salerTaxNo + ")在星瀚系统中未匹配到数据!";
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicObject buyer = BusinessDataServiceHelper.loadSingle("bdm_enterprise_baseinfo", (new QFilter("number", QCP.equals, buyerTaxNo)).toArray());
|
|
|
+
|
|
|
|
|
|
+ if(buyer == null){
|
|
|
+ returnMessage = "购方税号(" + buyerTaxNo + ")在星瀚系统中未匹配到企业信息!";
|
|
|
+ return buildReturnData(code, srmBillNo, returnMessage, null, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ entry.set("invoicetype", invoiceObj.getString("invoiceType"));
|
|
|
+ entry.set("invoiceno", invoiceObj.getString("invoiceNo"));
|
|
|
+ entry.set("invoicecode", invoiceObj.getString("invoiceNo"));
|
|
|
+ entry.set("serialno", invoiceObj.getString("serialNo"));
|
|
|
+ entry.set("invoicedate", invoiceDate);
|
|
|
+ entry.set("invexchangerate", "1");
|
|
|
+ entry.set("invexpquotetype", "0");
|
|
|
+ entry.set("totalamount", totalamount);
|
|
|
+ entry.set("currtotalamount", totalamount);
|
|
|
+
|
|
|
+ entry.set("taxamount_invoice", taxAmountTotal);
|
|
|
+ entry.set("invoicenotaxamount", invoiceAmount);
|
|
|
+ entry.set("validatemessage", invoiceObj.getString("validateMessage"));
|
|
|
+ entry.set("ie_validatest", invoiceObj.getString("checkStatus"));
|
|
|
+ entry.set("invoiceischange", "1");
|
|
|
+ entry.set("sequencenum", "2");
|
|
|
+ entry.set("billcreatetime", billCreateTime);
|
|
|
+ entry.set("buyerorgname", buyerName);
|
|
|
+ entry.set("buyertaxno", buyerTaxNo);
|
|
|
+ entry.set("makeoutcompname", salerName);
|
|
|
+ entry.set("salertaxno_h", salerTaxNo);
|
|
|
+ entry.set("count", 1);
|
|
|
+ entry.set("invoicefrom", "1");
|
|
|
+ entry.set("ismapexpense", "1");
|
|
|
+ entry.set("offset_invoice", invoiceObj.getString("deductionFlag"));
|
|
|
+ entry.set("offsetamount", CommonHelperUtils.getBigDecimal(invoiceObj.getString("effectiveTaxAmount")));
|
|
|
+ entry.set("buyerorg", buyer.getDynamicObject("org"));
|
|
|
+ entry.set("sellerorg", salerInfo);
|
|
|
+ entry.set("issupplement", "0");
|
|
|
+ entry.set("passverifybuyername", "1");
|
|
|
+ entry.set("passverifybuyertaxno", "1");
|
|
|
+ entry.set("personalinvoice", "0");
|
|
|
+ entry.set("isred", invoiceObj.getString("type"));
|
|
|
+ entry.set("invoicecurrency", 1L);
|
|
|
+ entry.set("invoicebuyeraddressphone", invoiceObj.getString("buyerAddressPhone"));
|
|
|
+ entry.set("oribalanceamount", CommonHelperUtils.getBigDecimal(invoiceObj.getBigDecimal("totalAmount")));
|
|
|
+ entry.set("poolreimburseamount", CommonHelperUtils.getBigDecimal(invoiceObj.getBigDecimal("totalAmount")));
|
|
|
+ entry.set("transportnote", "0");
|
|
|
+
|
|
|
+ String invoiceGoodsName = "";
|
|
|
+ List<String> invoiceGoodsCode = new ArrayList<>();
|
|
|
+ BigDecimal taxRate = BigDecimal.ZERO;
|
|
|
+ BigDecimal taxRate100 = BigDecimal.ZERO;
|
|
|
+ JSONArray itemArray = invoiceObj.getJSONArray("items");
|
|
|
+
|
|
|
+ if(itemArray != null && itemArray.size() > 0) {
|
|
|
+ DynamicObjectCollection invoiceitementry = bizAcctOutBill.getDynamicObjectCollection("invoiceitementry");
|
|
|
+ DynamicObjectType itemType = invoiceitementry.getDynamicObjectType();
|
|
|
+
|
|
|
+ for (int k = 0; k < itemArray.size(); k++) {
|
|
|
+
|
|
|
+ JSONObject itemObj = itemArray.getJSONObject(k);
|
|
|
+
|
|
|
+ String goodsCode = itemObj.getString("goodsCode");
|
|
|
+
|
|
|
+ DynamicObject goodsCodeInfo = CommonHelperUtils.queryBaseDynamicObject("er_taxclasscode", "mergecode", goodsCode);
|
|
|
+
|
|
|
+ String goodsName = itemObj.getString("goodsName");
|
|
|
+ String specModel = itemObj.getString("specModel");
|
|
|
+ String unit = itemObj.getString("unit");
|
|
|
+ BigDecimal unitPrice = CommonHelperUtils.getBigDecimal(itemObj.getString("unitPrice"));
|
|
|
+ BigDecimal num = CommonHelperUtils.getBigDecimal(itemObj.getString("num"));
|
|
|
+ BigDecimal taxAmountItem = CommonHelperUtils.getBigDecimal(itemObj.getString("taxAmount"));
|
|
|
+ taxRate = CommonHelperUtils.getBigDecimal(itemObj.getString("taxRate"));
|
|
|
+ taxRate100 = taxRate.multiply(new BigDecimal("100"));
|
|
|
+ BigDecimal detailAmount = CommonHelperUtils.getBigDecimal(itemObj.getString("detailAmount"));
|
|
|
+
|
|
|
+ invoiceGoodsName += (invoiceGoodsName.length() > 0 ? "," : "") + goodsName;
|
|
|
+
|
|
|
+ if(goodsCodeInfo != null && !invoiceGoodsCode.contains(goodsCodeInfo.getString("name"))){
|
|
|
+ invoiceGoodsCode.add(goodsCodeInfo.getString("name"));
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicObject itemEntry = new DynamicObject(itemType);
|
|
|
+
|
|
|
+ itemEntry.set("seq", (k+1));
|
|
|
+ itemEntry.set("itementryid", itemEntryId);
|
|
|
+ itemEntry.set("invoiceheadentryid", invoiceEntryId);
|
|
|
+ itemEntry.set("invoicetype_item", invoiceTypeInfo);
|
|
|
+ itemEntry.set("invoiceno_item", fpNumber);
|
|
|
+ itemEntry.set("invoicedate_item", invoiceDate);
|
|
|
+ itemEntry.set("invoicecurrency_item", 1L);
|
|
|
+ itemEntry.set("unit", unit);
|
|
|
+ itemEntry.set("num", num);
|
|
|
+ itemEntry.set("unitprice", unitPrice.setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ itemEntry.set("excludeamount", detailAmount);
|
|
|
+ itemEntry.set("invoiceitemtaxrate", taxRate);
|
|
|
+ itemEntry.set("invoiceitemtaxamout", taxAmountItem);
|
|
|
+ itemEntry.set("totalamount_item", totalamount);
|
|
|
+
|
|
|
+ itemEntry.set("invoicetaxamount_item", taxAmountTotal);
|
|
|
+ itemEntry.set("specmodel", specModel);
|
|
|
+ itemEntry.set("goodscode", goodsCode);
|
|
|
+ itemEntry.set("goodsname", goodsName);
|
|
|
+ itemEntry.set("invoicefrom1", "1");
|
|
|
+ itemEntry.set("invoiceitemoffset", invoiceObj.getString("deductionFlag"));
|
|
|
+ itemEntry.set("invoicecloudoffset", "1");
|
|
|
+ itemEntry.set("salertaxno", salerTaxNo);
|
|
|
+ itemEntry.set("invoiceitemisunbind", "0");
|
|
|
+ itemEntry.set("invoiceitemserialno", serialNo);
|
|
|
+
|
|
|
+
|
|
|
+ if(k == 0){
|
|
|
+ entry.set("unit_h", unit);
|
|
|
+ entry.set("alltaxrate", taxRate100);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ invoiceitementry.add(itemEntry);
|
|
|
+ }
|
|
|
+
|
|
|
+ bizAcctOutBill.set("invoiceitementry", invoiceitementry);
|
|
|
+
|
|
|
+ if(invoiceGoodsName.length() > 200){
|
|
|
+ invoiceGoodsName = invoiceGoodsName.substring(0, 200) + "...";
|
|
|
+ }
|
|
|
+ String invoiceGoodsCodeString = String.join(",", invoiceGoodsCode);
|
|
|
+ if(invoiceGoodsCodeString.length() > 200){
|
|
|
+ invoiceGoodsCodeString = invoiceGoodsCodeString.substring(0, 200) + "...";
|
|
|
+ }
|
|
|
+
|
|
|
+ entry.set("invoicegoodsname", invoiceGoodsName);
|
|
|
+ entry.set("invoicealltaxcode", invoiceGoodsCodeString);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
invoiceEntry.add(entry);
|
|
|
}
|
|
|
bizAcctOutBill.set("invoiceentry", invoiceEntry);
|
|
|
|
|
|
try {
|
|
|
-
|
|
|
-
|
|
|
|
|
|
OperationResult resultSave = SaveServiceHelper.saveOperate(ENTITY_PUBLICPAY, new DynamicObject[]{bizAcctOutBill}, OperateOption.create());
|
|
|
|