|
@@ -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");//srm状态,1:SRM已推送;2:已退回SRM;3:已反写SRM;4:反写SRM失败
|
|
|
+ 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("taxdetails", "");//多税率信息
|
|
|
+ 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);//费用项目分录id
|
|
|
+ itemEntry.set("invoiceheadentryid", invoiceEntryId);//费用项目分录id
|
|
|
+ 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("invoicetaxrate_item", "");//单头税率
|
|
|
+ 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());
|
|
|
|