定期记账预提推送sap相关逻辑

This commit is contained in:
yuxueliang0813 2025-05-15 17:59:09 +08:00
parent 097d9fa234
commit bd25a6510b
8 changed files with 279 additions and 32 deletions

View File

@ -101,8 +101,8 @@ public class RecBillChangeListExtendPlugin extends AbstractListPlugin implements
}
// 清账状态判断
boolean isAutoCleared = "A".equals(qzState) || "D".equals(qzState);
boolean isToBeCleared = "B".equals(qzState);
boolean isAutoCleared = "A".equals(qzState) || "D".equals(qzState);//无需金蝶清账 反清账
boolean isToBeCleared = "B".equals(qzState);//待清账
boolean isClearBillCancelled = false;
if (isToBeCleared) {
@ -117,6 +117,9 @@ public class RecBillChangeListExtendPlugin extends AbstractListPlugin implements
break;
}
}
}else{
//未关联下游业务时,也允许变更
isClearBillCancelled = true;
}
// else {
//未关联下游业务时

View File

@ -559,7 +559,8 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
JSONObject zkitem = new JSONObject();
zkitem.put("HKONT", "1122020700");//科目编号
zkitem.put("KUNNR", customerCode);//客户编号
zkitem.put("DMBTR", deductionamount.toString());//账扣金额 正数对应借方负数对应贷方
zkitem.put("DMBTR", deductionamount.negate().toString());//账扣金额 正数对应借方负数对应贷方
//判断收款小于应收时分录本次核销金额的合计值大于0 就要传正数
IT_ITEM.add(zkitem);
}
if(diffamount != null && diffamount.signum() != 0){
@ -567,7 +568,8 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
JSONObject wcitem = new JSONObject();
wcitem.put("HKONT", "1122020100");//科目编号
wcitem.put("KUNNR", "1001226");//客户编号
wcitem.put("DMBTR", diffamount.toString());//尾差金额 正数对应借方负数对应贷方
wcitem.put("DMBTR", diffamount.negate().toString());//尾差金额 正数对应借方负数对应贷方
//判断收款小于应收时分录本次核销金额的合计值大于0 就要传正数
IT_ITEM.add(wcitem);
}
// customerCode = "1005004";//上海禾诗家化妆品有限公司 -- 仅测试
@ -583,7 +585,8 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
clear.put("GJAHR",entryinfo.getString("shjh_e_year"));//会计年度
clear.put("BUZEI",entryinfo.getString("shjh_e_pzhh"));//行编号
clear.put("KUNNR",customerCode);//客户编号
clear.put("HKONT",entryinfo.getString("shjh_e_account"));//总账科目
clear.put("HKONT",entryinfo.getString("shjh_e_account"));//总账科目编号
clear.put("UMSKZ", JhzjUtils.getUMSKZ(entryinfo.getString("shjh_e_account")));//特殊总账标识
clear.put("DMBTR1",entryinfo.getBigDecimal("shjh_e_cursettle").abs());//清账金额--sap接收的正数金额
IT_CLEAR.add(clear);
}

View File

@ -0,0 +1,43 @@
package shjh.jhzj7.fi.fi.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
/**
* 定期收益批量预提-单据审核操作插件-携带是否需要生成凭证标记
* shjh_cim_depositpreba_ext
* @author yuxueliang
*/
public class DepositprebatchAuditOperation extends AbstractOperationServicePlugIn implements Plugin {
private static final String updateVoucher = "update t_cfm_preinterestbill set fk_shjh_needvoucher=1 where fid=?;";
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
String eok = e.getOperationKey();
if("audit".equals(eok)){
DynamicObject[] dos = e.getDataEntities();
DynamicObject prinfo;//定期收益批量预提单
DynamicObjectCollection doc_entry;
for (int i = 0; i < dos.length; i++) {
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName());
if(prinfo.getBoolean("shjh_needvoucher")){
//将此字段值携带至定期预提记账处理单中
doc_entry = prinfo.getDynamicObjectCollection("entry");//结息分录集合
for (DynamicObject depositpreintinfo : doc_entry) {
DB.update(DBRoute.of("fi"), updateVoucher, new Object[]{depositpreintinfo.getLong("intbillid")});
}
}
}
}
}
}

View File

@ -0,0 +1,205 @@
package shjh.jhzj7.fi.fi.plugin.operate;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sap.db.jdbc.packet.ErrorLevel;
import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.entity.operate.result.OperateErrorInfo;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.sdk.plugin.Plugin;
import shjh.jhzj7.fi.fi.utils.ApiUtils;
import shjh.jhzj7.fi.fi.utils.JhzjUtils;
import shjh.jhzj7.fi.fi.utils.SapUtils;
import shjh.jhzj7.fi.fi.utils.domin.ResponseData;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
/**
* 定期预提记账处理 shjh_cim_depositprein_ext-单据推送sap操作插件
* @author yuxueliang
*/
public class DepositpreintSapOperation extends AbstractOperationServicePlugIn implements Plugin {
private static final String updateVoucherFlag = "update t_cfm_preinterestbill set fk_shjh_sendsap=1,fk_shjh_sappzh=? where fid=?;";
private static final String userName = "bos_user";//用户
private static final String voucherName = "gl_voucher";//凭证
private static final String pcName = "shjh_pc";//利润中心
private static final String ccName = "bos_costcenter";//成本中心
private static final String glbdName = "gl_assist_bd";//核算项目组合纵表
private final static Log logger = LogFactory.getLog(DepositpreintSapOperation.class);
@Override
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
super.beforeExecuteOperationTransaction(e);
String eok = e.getOperationKey();
if("sendvoucher".equals(eok)){
DynamicObject[] dos = e.getDataEntities();
DynamicObject prinfo;
for (int i = 0; i < dos.length; i++) {
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName());
//判断定期预提记账处理单是否已生成金蝶凭证
if(!prinfo.getBoolean("isvoucher")){
e.setCancelMessage(prinfo.getString("billno") + "未生成金蝶凭证无法推送SAP");
e.setCancel(true);
}else if(prinfo.getBoolean("shjh_sendsap")){
e.setCancelMessage(prinfo.getString("billno") + "已推送SAP无需再次推送");
e.setCancel(true);
}
}
}
}
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
String eok = e.getOperationKey();
if("sendvoucher".equals(eok)){
//推送sap凭证接口
DynamicObject[] dos = e.getDataEntities();
DynamicObject prinfo;//定期预提记账处理单
JSONObject sapReturnData;
ResponseData respdata;
for (int i = 0; i < dos.length; i++) {
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName());
if(prinfo.getBoolean("shjh_needvoucher") && !prinfo.getBoolean("shjh_sendsap")){
//如果定期预提记账处理单需要生成凭证且未推送sap的才推送sap
sapReturnData = sendVoucher(prinfo);
if(sapReturnData != null && "0".equals(sapReturnData.getString("code"))){
//解析sap凭证接口返回值
respdata = ApiUtils.getResponseData(sapReturnData);
if(respdata == null){
addErrorInfo(prinfo,"SAP凭证接口返回值为空详见接口日志");
continue;
}
//推送sap成功后反写已推送标记和sap凭证号至预提单中
DB.update(DBRoute.of("fi"), updateVoucherFlag, new Object[]{respdata.getNumber(),prinfo.getPkValue()});
this.operationResult.addSuccessPkId(prinfo.getPkValue());
}else if(sapReturnData != null){
addErrorInfo(prinfo,"推送SAP接口失败"+sapReturnData.getString("msg"));
}else{
addErrorInfo(prinfo,"推送SAP接口失败SAP返回值为空或者金蝶凭证未审核请检查");
}
}
}
}
}
private JSONObject sendVoucher(DynamicObject prinfo){
//SAP定期预提收益凭证接口入参组装和调用
JSONObject IS_HEADER = new JSONObject();//抬头
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//日期格式化工具
String companyCode = prinfo.getDynamicObject("org").getString("number");
IS_HEADER.put("BUKRS",companyCode);//公司代码
IS_HEADER.put("BLART","SA");//凭证类型-总账类凭证
IS_HEADER.put("BLDAT",sdf.format(prinfo.getDate("bizdate")));//凭证日期-业务日期
IS_HEADER.put("BUDAT",sdf.format(prinfo.getDate("expiredate")));//过账日期-预提日期
String isoCode = prinfo.getDynamicObject("currency").getString("number");
IS_HEADER.put("WAERS", JhzjUtils.getCurrencyCode(isoCode));//币种
IS_HEADER.put("XBLNR",prinfo.getString("billno"));//参考凭证号-单据编号 固定长度16位
IS_HEADER.put("BKTXT",prinfo.getString("productname"));//凭证抬头文本 产品名称
//添加用户名过滤条件-操作审核按钮的用户OA用户名
DynamicObject userinfo = BusinessDataServiceHelper.loadSingleFromCache(RequestContext.get().getCurrUserId(), userName);
String oauser = userinfo.getString("shjh_oauser");
if(JhzjUtils.isEmpty(oauser)){
IS_HEADER.put("USNAM","资金系统");//用户名
}else{
IS_HEADER.put("USNAM",oauser);//用户名
}
//----------------处理详细入参--获取对应金蝶凭证--------------------
JSONArray IT_ITEM = new JSONArray();//详细
QFilter voucherFilters = new QFilter("sourcebill", QCP.equals, prinfo.getPkValue());//凭证源单ID为预提单
voucherFilters.and(new QFilter("billstatus",QCP.equals,"C"));//凭证状态已审核
DynamicObject gl_voucher = BusinessDataServiceHelper.loadSingle(voucherName,
"id,description,sourcebill,entries,entries.account,entries.assgrp,entries.debitlocal,entries.creditlocal,entries.entrydc,vouchertype",
voucherFilters.toArray());
if (null != gl_voucher) {
IS_HEADER.put("BLART", gl_voucher.getString("vouchertype.number"));//根据金蝶凭证类型设置
if(!JhzjUtils.isEmpty(gl_voucher.getString("description"))){
IS_HEADER.put("BKTXT", gl_voucher.getString("description"));//凭证抬头文本-从金蝶凭证中获取
}
DynamicObjectCollection entries = gl_voucher.getDynamicObjectCollection("entries");
JSONObject item;
DynamicObject account;
BigDecimal creditlocal;
DynamicObject assgrpinfo;
String asstype;
DynamicObject glassistbd;
DynamicObject hsxminfo;
for (DynamicObject entry : entries) {
item = new JSONObject();
account = entry.getDynamicObject("account");//科目
if (null != account) {
item.put("HKONT", account.getString("number")); //总账科目_科目(凭证分录account)
item.put("UMSKZ", JhzjUtils.getUMSKZ(account.getString("number")));//特殊总账标识
}
//获取贷方金额
creditlocal = entry.getBigDecimal("creditlocal");//贷方
//获取分录借贷方向
String entrydc = (String) entry.get("entrydc");//分录方向(1.借方,-1.贷方)
if ("1".equals(entrydc)) {
//设置sap凭证借方金额
item.put("DMBTR", String.valueOf(entry.getBigDecimal("debitlocal")));
} else if ("-1".equals(entrydc)) {
//设置sap凭证贷方金额 sap通过负数体现贷方
item.put("DMBTR", String.valueOf(creditlocal.negate()));
}
assgrpinfo = entry.getDynamicObject("assgrp");//核算维度(弹性域)
if(assgrpinfo != null){
DynamicObjectCollection gl_assist_bd = QueryServiceHelper.query(glbdName, "asstype,assval",
new QFilter[]{new QFilter("hg.id", QCP.equals, assgrpinfo.getPkValue())});
for (int j = 0; j < gl_assist_bd.size(); j++) {
glassistbd = gl_assist_bd.get(j);
asstype = glassistbd.getString("asstype");//核算项目类型-对应核算维度的字段名
if("f000012".equals(asstype)){
//利润中心 f000012
hsxminfo = QueryServiceHelper.queryOne(pcName, "id,name,number",
new QFilter[]{new QFilter("id", QCP.equals, glassistbd.getLong("assval"))});//维度值
item.put("PRCTR",hsxminfo.getString("number"));//利润中心_利润中心
}else if("f000011".equals(asstype)){
//成本中心 f000011
hsxminfo = QueryServiceHelper.queryOne(ccName, "id,name,number",
new QFilter[]{new QFilter("id", QCP.equals, glassistbd.getLong("assval"))});//维度值
item.put("KOSTL",hsxminfo.getString("number"));//成本中心_成本中心
}
}
}
// item.put("RSTGR", "014");//原因代码_原因码
// item.put("SGTXT", SGTXT);//行项目文本_SAP会计科目行项目号
IT_ITEM.add(item);
}
}else{
String billNo = prinfo.getString("billno");
logger.error("无法获取定期预提记账处理单[" + billNo + "]关联的凭证信息,凭证不存在或未审核");
return null;
}
//组装参数调用推送sap凭证接口
JSONObject sapReturnData = SapUtils.sapTransactionAPI(IS_HEADER,IT_ITEM,null,prinfo.getString("billno"));
return sapReturnData;
}
private void addErrorInfo(DynamicObject bill, String errorMsg) {
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
operateErrorInfo.setMessage(bill.getString("billno") + errorMsg);
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
operateErrorInfo.setPkValue(bill.getPkValue());
this.operationResult.addErrorInfo(operateErrorInfo);
}
}

View File

@ -5,19 +5,18 @@ import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
/**
* 理财收益批量预提-单据操作插件
* 理财收益批量预提-单据审核操作插件-携带是否需要生成凭证标记
* shjh_cim_intbill_batc_ext
* @author yuxueliang
*/
public class IntBillBatchOperation extends AbstractOperationServicePlugIn implements Plugin {
private static final String destName = "cim_intbill_revenue";//预提记账处理
private static final String updateVoucher = "update t_cim_revenue set fk_shjh_needvoucher=1 where fid=?;";
private static final String updateVoucher = "update t_cim_revenue set fk_shjh_needvoucher=1 where fintbatchbillid=?;";
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
@ -26,20 +25,11 @@ public class IntBillBatchOperation extends AbstractOperationServicePlugIn implem
if("audit".equals(eok)){
DynamicObject[] dos = e.getDataEntities();
DynamicObject prinfo;//理财收益批量预提单
// DynamicObject destinfo;//预提记账处理单
QFilter qFilter;//预提记账处理单集合
DynamicObject[] ytjzdos;
for (int i = 0; i < dos.length; i++) {
prinfo = BusinessDataServiceHelper.loadSingle(dos[i].getPkValue(), dos[i].getDataEntityType().getName());
if(prinfo.getBoolean("shjh_needvoucher")){
//将此字段值携带至预提记账处理单中 intbatchbillid
qFilter = new QFilter("intbatchbillid", QCP.equals, prinfo.getLong("id"));
ytjzdos = BusinessDataServiceHelper.load(destName,"id",new QFilter[]{qFilter});
if(ytjzdos != null){
for (DynamicObject destinfo : ytjzdos){
DB.update(DBRoute.of("fi"), updateVoucher, new Object[]{destinfo.getLong("id")});
}
}
DB.update(DBRoute.of("fi"), updateVoucher, new Object[]{prinfo.getPkValue()});
}
}
}

View File

@ -28,7 +28,7 @@ import java.math.BigDecimal;
import java.text.SimpleDateFormat;
/**
* 预提记账处理 shjh_cim_intbill_reve_ext-单据操作插件
* 理财预提记账处理 shjh_cim_intbill_reve_ext-单据推送sap操作插件
* @author yuxueliang
*/
public class RevenueBillOperation extends AbstractOperationServicePlugIn implements Plugin {

View File

@ -23,7 +23,8 @@ public class VoucherAuditOperation extends AbstractOperationServicePlugIn implem
private static final String recbillName = "cas_recbill";//收款单
private static final String paybillName = "cas_paybill";//付款单
private static final String intbillName = "cim_intbill_revenue";//预提记账处理单
private static final String intbillName = "cim_intbill_revenue";//理财预提记账处理单
private static final String depositpreintName = "cim_depositpreint";//定期预提记账处理单
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
@ -44,6 +45,7 @@ public class VoucherAuditOperation extends AbstractOperationServicePlugIn implem
//同一个用户在多个界面操作同一张也不允许操作
operateOption.setVariableValue(OperateOptionConst.MUTEX_ISSTRICT, String.valueOf(true));
OperationResult operResult;//操作执行结果
List<OperateErrorInfo> allErrorInfo;
for (DynamicObject pzinfo : dos) {
//重新加载凭证对象
pzinfo = BusinessDataServiceHelper.loadSingle(pzinfo.getPkValue(), pzinfo.getDataEntityType().getName(), "id,billno,sourcebill,sourcebilltype");
@ -69,7 +71,7 @@ public class VoucherAuditOperation extends AbstractOperationServicePlugIn implem
//可以根据需要处理 operationResult例如检查是否成功获取返回值等
if (!operResult.isSuccess()){
logger.error(operResult.getMessage());
List<OperateErrorInfo> allErrorInfo = operResult.getAllErrorInfo();
allErrorInfo = operResult.getAllErrorInfo();
for (OperateErrorInfo errorInfo : allErrorInfo) {
this.operationResult.addErrorInfo(errorInfo);
}
@ -83,21 +85,21 @@ public class VoucherAuditOperation extends AbstractOperationServicePlugIn implem
logger.info("执行付款单 pushsap 成功,单据编号:" + bizbillinfo.getString("billno"));
} else {
logger.error(operResult.getMessage());
List<OperateErrorInfo> allErrorInfo = operResult.getAllErrorInfo();
allErrorInfo = operResult.getAllErrorInfo();
for (OperateErrorInfo errorInfo : allErrorInfo) {
this.operationResult.addErrorInfo(errorInfo);
}
}
}else if(intbillName.equals(sourcebilltype)){
bizbillinfo = BusinessDataServiceHelper.loadSingle(sourcebillid,intbillName);
//执行预提记账处理单推送sap操作并反馈操作执行结果
operResult = OperationServiceHelper.executeOperate("sendvoucher", intbillName, new DynamicObject[]{bizbillinfo}, operateOption);
}else if(intbillName.equals(sourcebilltype) || depositpreintName.equals(sourcebilltype)){
bizbillinfo = BusinessDataServiceHelper.loadSingle(sourcebillid,sourcebilltype);
//执行理财和定期预提记账处理单推送sap操作并反馈操作执行结果
operResult = OperationServiceHelper.executeOperate("sendvoucher", sourcebilltype, new DynamicObject[]{bizbillinfo}, operateOption);
// 可以根据需要处理 operationResult例如检查是否成功获取返回值等
if (operResult.isSuccess()) {
logger.info("执行预提记账处理单 sendvoucher 成功,单据编号:" + bizbillinfo.getString("billno"));
logger.info("执行理财或定期预提记账处理单 sendvoucher 成功,单据编号:" + bizbillinfo.getString("billno"));
} else {
logger.error(operResult.getMessage());
List<OperateErrorInfo> allErrorInfo = operResult.getAllErrorInfo();
allErrorInfo = operResult.getAllErrorInfo();
for (OperateErrorInfo errorInfo : allErrorInfo) {
this.operationResult.addErrorInfo(errorInfo);
}

View File

@ -10,7 +10,8 @@ public class VoucherBillOperation extends AbstractOperationServicePlugIn impleme
private static final String recbillName = "cas_recbill";//收款单
private static final String paybillName = "cas_paybill";//付款单
private static final String intbillName = "cim_intbill_revenue";//预提记账处理单
private static final String intbillName = "cim_intbill_revenue";//理财预提记账处理单
private static final String depositpreintName = "cim_depositpreint";//定期预提记账处理单
@Override
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
@ -39,8 +40,8 @@ public class VoucherBillOperation extends AbstractOperationServicePlugIn impleme
e.setCancel(true);
}
}else if(intbillName.equals(sourcebilltype)){
bizbillinfo = BusinessDataServiceHelper.loadSingle(sourcebillid,intbillName,"id,billno,shjh_sendsap");
}else if(intbillName.equals(sourcebilltype) || depositpreintName.equals(sourcebilltype)){
bizbillinfo = BusinessDataServiceHelper.loadSingle(sourcebillid,sourcebilltype,"id,billno,shjh_sendsap");
if(bizbillinfo.getBoolean("shjh_sendsap")){
e.setCancelMessage(pzinfo.getString("billno")+"对应的预提记账处理单"+bizbillinfo.getString("billno")+"已推送SAP不允许反审核");
e.setCancel(true);