1.票据付款时,根据票据号在金蝶中查找收票凭证号,将应收票据的收票凭证和对应的背书凭证进行清账,推送SAP
--s
This commit is contained in:
parent
abb4ce6f13
commit
68814180fd
|
|
@ -14,13 +14,16 @@ import kd.bos.orm.query.QFilter;
|
|||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.sdk.plugin.Plugin;
|
||||
import shjh.jhzj7.fi.fi.plugin.form.info.RecFieldsInfo;
|
||||
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
|
||||
import shjh.jhzj7.fi.fi.utils.SysUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static shjh.jhzj7.fi.fi.utils.SapUtils.*;
|
||||
|
||||
|
|
@ -71,10 +74,14 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
String shjhSourcesystem = bill.getString("shjh_sourcesystem");//来源系统
|
||||
//主动:{1.fk:不清帐,直传付款凭证给sap;2.SAP:要清账,都传} 被动:{不用传清账} FKZJ2025030040
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("IS_HEADER", getIS_HEADER(bill));//抬头
|
||||
//抬头
|
||||
data.put("IS_HEADER", getIS_HEADER(bill));
|
||||
//金蝶生成的凭证信息
|
||||
data.put("IT_ITEM", getIT_ITEM(bill));
|
||||
//来源系统SAP时,清账(SAP凭证数据)
|
||||
if ("A".equals(shjhSourcesystem)) {
|
||||
data.put("IT_CLEAR", getIT_CLEAR(bill));//清账数据,参考《IT_CLEAR》,仅清账需要输入
|
||||
//清账数据,参考《IT_CLEAR》,仅清账需要输入
|
||||
data.put("IT_CLEAR", getIT_CLEAR(bill));
|
||||
}
|
||||
//一次性供应商或客户信息(仅需要填写)
|
||||
String type = bill.getString("payeetype");
|
||||
|
|
@ -129,11 +136,12 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
|
||||
//客户(bd_customer)||供应商(bd_supplier) 收款人id:payee
|
||||
String payeetype = bill.getString("payeetype");//收款人类型
|
||||
String customerOrsupnum = getCustomerOrSupplierNumber(payeetype, bill);
|
||||
String customerOrsupnum = getCustomerOrSupplierNumber(payeetype, bill,"payee");
|
||||
|
||||
//原因码(付款明细)
|
||||
String RSTGR = "";
|
||||
String SGTXT = "";
|
||||
//SAP会计科目行项目号
|
||||
String SGTXT;
|
||||
DynamicObjectCollection entrys = bill.getDynamicObjectCollection("entry");
|
||||
if (!entrys.isEmpty()) {
|
||||
DynamicObject entry = entrys.get(0);
|
||||
|
|
@ -141,20 +149,20 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
if (null != shjhYym) {
|
||||
RSTGR = shjhYym.getString("number");
|
||||
}
|
||||
SGTXT = entry.getString("shjh_voucherentrynum");//SAP会计科目行项目号
|
||||
}
|
||||
SGTXT = entry.getString("shjh_voucherentrynum");
|
||||
} else {SGTXT = "";}
|
||||
//成本中心
|
||||
String KOSTL = "";
|
||||
String KOSTL;
|
||||
DynamicObject shjhCostcenter = bill.getDynamicObject("shjh_costcenter");
|
||||
if (null != shjhCostcenter) {
|
||||
KOSTL = shjhCostcenter.getString("number");//成本中心
|
||||
}
|
||||
} else {KOSTL = "";}
|
||||
//利润中心
|
||||
String PRCTR = "";
|
||||
String PRCTR;
|
||||
DynamicObject shjhPc = bill.getDynamicObject("shjh_pc");
|
||||
if (null != shjhPc) {
|
||||
PRCTR = shjhPc.getString("number");//利润中心
|
||||
}
|
||||
} else {PRCTR = "";}
|
||||
|
||||
JSONArray IT_ITEM = new JSONArray();
|
||||
DynamicObject gl_voucher = BusinessDataServiceHelper.loadSingle("gl_voucher",
|
||||
|
|
@ -163,7 +171,7 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
if (null != gl_voucher) {
|
||||
DynamicObjectCollection entries = gl_voucher.getDynamicObjectCollection("entries");
|
||||
if (!entries.isEmpty()) {
|
||||
for (DynamicObject entry : entries) {
|
||||
entries.forEach(entry -> {
|
||||
JSONObject IT_ITEMS = new JSONObject();
|
||||
switch (payeetype) {
|
||||
case "bd_customer":
|
||||
|
|
@ -211,7 +219,7 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
IT_ITEMS.put("DMBTR", String.valueOf(amountToPut));
|
||||
}
|
||||
IT_ITEM.add(IT_ITEMS);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return IT_ITEM;
|
||||
|
|
@ -219,16 +227,18 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
|
||||
private JSONArray getIT_CLEAR(DynamicObject bill) {
|
||||
JSONArray IT_CLEAR = new JSONArray();//清账数据,参考《IT_CLEAR》,仅清账需要输入
|
||||
//客户(bd_customer)||供应商(bd_supplier) 收款人id:payee
|
||||
String payeetype = bill.getString("payeetype");//收款人类型
|
||||
String customerOrsupnum = getCustomerOrSupplierNumber(payeetype, bill);
|
||||
DynamicObjectCollection entrys = bill.getDynamicObjectCollection("entry");
|
||||
for (DynamicObject entry : entrys) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String BUKRS = "";
|
||||
String BUKRS;
|
||||
if (null != bill.getDynamicObject("openorg")) {
|
||||
BUKRS = bill.getDynamicObject("openorg").getString("number");
|
||||
} else {
|
||||
BUKRS = "";
|
||||
}
|
||||
//客户(bd_customer)||供应商(bd_supplier) 收款人id:payee
|
||||
String payeetype = bill.getString("payeetype");//收款人类型
|
||||
AtomicReference<String> customerOrsupnum = new AtomicReference<>(getCustomerOrSupplierNumber(payeetype, bill, "payee"));
|
||||
DynamicObjectCollection entrys = bill.getDynamicObjectCollection("entry");
|
||||
entrys.forEach(entry -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("BUKRS", BUKRS);//公司代码
|
||||
jsonObject.put("BELNR", entry.getString("shjh_vouchernums"));//会计凭证编号
|
||||
jsonObject.put("GJAHR", entry.getString("shjh_voucheryear"));//会计年度
|
||||
|
|
@ -248,8 +258,60 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
}
|
||||
jsonObject.put("HKONT", HKONT);//总账科目
|
||||
jsonObject.put("UMSKZ", "");//todo:特殊总账标识
|
||||
jsonObject.put("DMBTR", entry.getBigDecimal("e_actamt"));//todo:未清金额_实付金额
|
||||
jsonObject.put("DMBTR", entry.getBigDecimal("e_actamt"));//未清金额_实付金额
|
||||
IT_CLEAR.add(jsonObject);
|
||||
});
|
||||
|
||||
// 票据信息
|
||||
DynamicObjectCollection casDraftinfos = bill.getDynamicObjectCollection("cas_draftinfo");
|
||||
if (!casDraftinfos.isEmpty()) {
|
||||
|
||||
// 缓存所有票据号码:draftbillno
|
||||
List<String> draftbillnos = casDraftinfos.stream()
|
||||
.map(d -> d.getString("draftbillno"))
|
||||
.collect(Collectors.toList());
|
||||
// 批量查询收款单:casRecbills
|
||||
QFilter q2 = new QFilter("openorg.number", QCP.equals, BUKRS);
|
||||
List<QFilter> allFilters = draftbillnos.stream()
|
||||
.map(d -> new QFilter("cas_draftinfo.draftbillno", QCP.equals, d))
|
||||
.collect(Collectors.toList());
|
||||
allFilters.add(q2);
|
||||
QFilter[] filtersArray = allFilters.toArray(new QFilter[0]);
|
||||
DynamicObject[] casRecbills = BusinessDataServiceHelper.load("cas_recbill",
|
||||
"id,cas_draftinfo,cas_draftinfo.draftbillno,openorg,shjh_vouchernum,shjh_sapfiscalyear,shjh_sapline" +
|
||||
"payertype,payer,entry,entry.shjh_accountsap,entry.e_actamt", filtersArray);
|
||||
// 1. 过滤出收款单, 2. 遍历收款单明细, 3. 组装IT_CLEAR数据
|
||||
Arrays.stream(casRecbills)
|
||||
.forEach(casRecbill -> {
|
||||
DynamicObjectCollection entryss = casRecbill.getDynamicObjectCollection("entry");
|
||||
entryss.forEach(entr -> {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
String payertype = casRecbill.getString("payertype");
|
||||
customerOrsupnum.set(getCustomerOrSupplierNumber(payertype, casRecbill, "payer"));
|
||||
jsonObject.put("BUKRS", BUKRS);
|
||||
jsonObject.put("BELNR", casRecbill.getString("shjh_vouchernum"));
|
||||
jsonObject.put("GJAHR", casRecbill.getString("shjh_sapfiscalyear"));
|
||||
jsonObject.put("BUZEI", casRecbill.getString("shjh_sapline"));
|
||||
switch (payertype) {
|
||||
case "bd_customer":
|
||||
jsonObject.put("KUNNR", customerOrsupnum);
|
||||
break;
|
||||
case "bd_supplier":
|
||||
jsonObject.put("LIFNR", customerOrsupnum);
|
||||
break;
|
||||
}
|
||||
String HKONT = "";
|
||||
DynamicObject shjhSapkjkm = entr.getDynamicObject("shjh_accountsap");
|
||||
if (shjhSapkjkm != null) {
|
||||
HKONT = shjhSapkjkm.getString("number");
|
||||
}
|
||||
jsonObject.put("HKONT", HKONT);
|
||||
jsonObject.put("UMSKZ", "");
|
||||
jsonObject.put("DMBTR", entr.getBigDecimal("e_actamt"));
|
||||
IT_CLEAR.add(jsonObject);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
return IT_CLEAR;
|
||||
}
|
||||
|
|
@ -272,25 +334,55 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
|||
}
|
||||
|
||||
/**
|
||||
* 根据收款人类型获取收款人编号
|
||||
* 根据收/付款人类型,获取收/付款人编号
|
||||
*/
|
||||
private String getCustomerOrSupplierNumber(String payeetype, DynamicObject bill) {
|
||||
private String getCustomerOrSupplierNumber(String payeetype, DynamicObject bill,String type) {
|
||||
String customerOrsupnum = "";
|
||||
String objectType = null;
|
||||
switch (payeetype) {
|
||||
case "bd_customer":
|
||||
objectType = "bd_customer";
|
||||
break;
|
||||
case "bd_supplier":
|
||||
objectType = "bd_supplier";
|
||||
break;
|
||||
}
|
||||
if (objectType != null) {
|
||||
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(Long.valueOf(bill.getString("payee")), objectType);
|
||||
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(Long.valueOf(bill.getString(type)), payeetype);
|
||||
if (dynamicObject != null) {
|
||||
customerOrsupnum = dynamicObject.getString("number");
|
||||
}
|
||||
}
|
||||
return customerOrsupnum;
|
||||
}
|
||||
}
|
||||
|
||||
// for (DynamicObject casDraftinfo : casDraftinfos) {
|
||||
// String draftbillno = casDraftinfo.getString("draftbillno");//票据号码
|
||||
// QFilter q1 = new QFilter("cas_draftinfo.draftbillno", QCP.equals, draftbillno);
|
||||
// QFilter q2 = new QFilter("openorg.number", QCP.equals, BUKRS);//公司代码
|
||||
// //获取收款单
|
||||
// DynamicObject[] casRecbills = BusinessDataServiceHelper.load("cas_recbill",
|
||||
// "id,cas_draftinfo,cas_draftinfo.draftbillno,openorg,shjh_vouchernum,shjh_sapfiscalyear,shjh_sapline" +
|
||||
// "payertype,payer,entry,entry.shjh_accountsap,entry.e_actamt", new QFilter[]{q1, q2});
|
||||
// for (DynamicObject casRecbill : casRecbills) {
|
||||
// //收款单明细
|
||||
// DynamicObjectCollection entryss = casRecbill.getDynamicObjectCollection("entry");
|
||||
// for (DynamicObject entr : entryss) {
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// //客户(bd_customer)||供应商(bd_supplier) 付款人id:payer
|
||||
// String payertype = casRecbill.getString("payertype");//付款人类型
|
||||
// customerOrsupnum = getCustomerOrSupplierNumber(payertype, casRecbill,"payer");
|
||||
// jsonObject.put("BUKRS", BUKRS);//公司代码
|
||||
// jsonObject.put("BELNR", casRecbill.getString("shjh_vouchernum"));//会计凭证编号
|
||||
// jsonObject.put("GJAHR", casRecbill.getString("shjh_sapfiscalyear"));//会计年度
|
||||
// jsonObject.put("BUZEI", casRecbill.getString("shjh_sapline"));//行编号
|
||||
// switch (payertype) {
|
||||
// case "bd_customer":
|
||||
// jsonObject.put("KUNNR", customerOrsupnum); // 供应商编号_付款人id(收款单payer)
|
||||
// break;
|
||||
// case "bd_supplier":
|
||||
// jsonObject.put("LIFNR", customerOrsupnum); // 客户编号_付款人id(收款单payer)
|
||||
// break;
|
||||
// }
|
||||
// String HKONT = "";
|
||||
// DynamicObject shjhSapkjkm = entr.getDynamicObject("shjh_accountsap");//sap会计科目
|
||||
// if (null != shjhSapkjkm) {
|
||||
// HKONT = shjhSapkjkm.getString("number");//SAP会计科目
|
||||
// }
|
||||
// jsonObject.put("HKONT", HKONT);//总账科目
|
||||
// jsonObject.put("UMSKZ", "");//todo:特殊总账标识
|
||||
// jsonObject.put("DMBTR", entr.getBigDecimal("e_actamt"));//未清金额_实收金额
|
||||
// IT_CLEAR.add(jsonObject);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Loading…
Reference in New Issue