1.票据付款时,根据票据号在金蝶中查找收票凭证号,将应收票据的收票凭证和对应的背书凭证进行清账,推送SAP
2.排程任务池列表界面上增加一键合并按钮,点击后,将来源系统为sap的按照合并规则进行合并 --s
This commit is contained in:
parent
be2728441b
commit
3e84d58207
|
|
@ -73,6 +73,7 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
||||||
bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(), "cas_paybill");
|
bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(), "cas_paybill");
|
||||||
String shjhSourcesystem = bill.getString("shjh_sourcesystem");//来源系统
|
String shjhSourcesystem = bill.getString("shjh_sourcesystem");//来源系统
|
||||||
//主动:{1.fk:不清帐,直传付款凭证给sap;2.SAP:要清账,都传} 被动:{不用传清账} FKZJ2025030040
|
//主动:{1.fk:不清帐,直传付款凭证给sap;2.SAP:要清账,都传} 被动:{不用传清账} FKZJ2025030040
|
||||||
|
//todo:付款单是由票据直接生成,凭证如何推送
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
//抬头
|
//抬头
|
||||||
data.put("IS_HEADER", getIS_HEADER(bill));
|
data.put("IS_HEADER", getIS_HEADER(bill));
|
||||||
|
|
@ -80,6 +81,11 @@ public class PaybillPushSapOperation extends AbstractOperationServicePlugIn impl
|
||||||
data.put("IT_ITEM", getIT_ITEM(bill));
|
data.put("IT_ITEM", getIT_ITEM(bill));
|
||||||
//来源系统SAP时,清账(SAP凭证数据)
|
//来源系统SAP时,清账(SAP凭证数据)
|
||||||
if ("A".equals(shjhSourcesystem)) {
|
if ("A".equals(shjhSourcesystem)) {
|
||||||
|
// 票据信息
|
||||||
|
DynamicObjectCollection casDraftinfos = bill.getDynamicObjectCollection("cas_draftinfo");
|
||||||
|
if (!casDraftinfos.isEmpty()) {
|
||||||
|
data.put("IT_ITEM", null);
|
||||||
|
}
|
||||||
//清账数据,参考《IT_CLEAR》,仅清账需要输入
|
//清账数据,参考《IT_CLEAR》,仅清账需要输入
|
||||||
data.put("IT_CLEAR", getIT_CLEAR(bill));
|
data.put("IT_CLEAR", getIT_CLEAR(bill));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,178 @@
|
||||||
|
package shjh.jhzj7.fi.fi.plugin.operate;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||||
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||||
|
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
import kd.bos.logging.Log;
|
||||||
|
import kd.bos.logging.LogFactory;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import kd.sdk.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排程单据合并
|
||||||
|
* 元:shjh_psd_schedulebill_ext
|
||||||
|
* 操作标识:shjh_pcbillhb
|
||||||
|
*/
|
||||||
|
public class SchedulebillMergeOperation extends AbstractOperationServicePlugIn implements Plugin {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(SchedulebillMergeOperation.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||||
|
//限制条件:]付款排程单【排程状态】=已排程 and 【单据来源】=SAP and 【排程余额】=0 and 【合并批次号】=空 and【排票金额】=0,才允许点击此按钮。
|
||||||
|
super.onAddValidators(e);
|
||||||
|
e.addValidator(new AbstractValidator() {
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
String operateKey = this.getOperateKey();
|
||||||
|
if ("shjh_pcbillhb".equals(operateKey)) {
|
||||||
|
|
||||||
|
// DynamicObject single = BusinessDataServiceHelper.loadSingle("psd_schedulebill", new QFilter[]{new QFilter("billno", "=", "FKPC250401000002")});
|
||||||
|
// DynamicObject single1 = BusinessDataServiceHelper.loadSingle("psd_schedulebill", new QFilter[]{new QFilter("billno", "=", "FKPC250401000001")});
|
||||||
|
// DynamicObject single2 = BusinessDataServiceHelper.loadSingle("psd_schedulebill", new QFilter[]{new QFilter("billno", "=", "PSD-202503-000058")});
|
||||||
|
// DynamicObject single3 = BusinessDataServiceHelper.loadSingle("psd_schedulebill", new QFilter[]{new QFilter("billno", "=", "PSD-202502-000034")});
|
||||||
|
// single.set("batchnum","");single1.set("batchnum","");single2.set("batchnum","");single3.set("batchnum","");single3.set("shjh_sourcesystem","A");
|
||||||
|
// SaveServiceHelper.save(new DynamicObject[]{single});SaveServiceHelper.save(new DynamicObject[]{single1});SaveServiceHelper.save(new DynamicObject[]{single2});SaveServiceHelper.save(new DynamicObject[]{single3});
|
||||||
|
|
||||||
|
ExtendedDataEntity[] entities = this.getDataEntities();
|
||||||
|
for (ExtendedDataEntity entity : entities) {
|
||||||
|
DynamicObject bill = entity.getDataEntity();
|
||||||
|
bill = BusinessDataServiceHelper.loadSingle(bill.getPkValue(), "psd_schedulebill");
|
||||||
|
String schedulstatus = bill.getString("schedulstatus");//排程状态
|
||||||
|
if (!"yetschedule".equals(schedulstatus)) {
|
||||||
|
this.addErrorMessage(entity,"状态不是已排程");
|
||||||
|
}
|
||||||
|
String shjh_sourcesystem = bill.getString("shjh_sourcesystem");// 来源系统 SAP:A
|
||||||
|
if (!"A".equals(shjh_sourcesystem)) {
|
||||||
|
this.addErrorMessage(entity,"来源系统不是SAP");
|
||||||
|
}
|
||||||
|
BigDecimal balanceamt = bill.getBigDecimal("balanceamt");//排程余额
|
||||||
|
if (balanceamt.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
this.addErrorMessage(entity,"排程余额不为0");
|
||||||
|
}
|
||||||
|
String batchnum = bill.getString("batchnum");//合并批次号
|
||||||
|
if (!batchnum.isEmpty()) {
|
||||||
|
this.addErrorMessage(entity,"合并批次号不为空");
|
||||||
|
}
|
||||||
|
BigDecimal draftamt = bill.getBigDecimal("draftamt");//排票金额
|
||||||
|
if (draftamt.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
this.addErrorMessage(entity,"排票金额不为0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||||
|
super.afterExecuteOperationTransaction(e);
|
||||||
|
//排程任务池列表界面上增加一键合并按钮,点击后,将来源系统为sap的按照合并规则进行合并
|
||||||
|
String operationKey = e.getOperationKey();
|
||||||
|
if ("shjh_pcbillhb".equals(operationKey)) {
|
||||||
|
DynamicObject[] dataEntities = e.getDataEntities();
|
||||||
|
// 提前加载所有 bill 对象
|
||||||
|
DynamicObject[] loadedBills = loadAllBills(dataEntities);
|
||||||
|
Map<StringBuilder, List<DynamicObject>> map = new HashMap<>();
|
||||||
|
// 合并规则
|
||||||
|
DynamicObject sourcesystem = BusinessDataServiceHelper.loadSingle("psd_autocombinerule",
|
||||||
|
new QFilter[]{new QFilter("enable", "=", "1")});
|
||||||
|
if (sourcesystem != null) {
|
||||||
|
DynamicObjectCollection entryentity = sourcesystem.getDynamicObjectCollection("entryentity");
|
||||||
|
for (DynamicObject bill : loadedBills) {
|
||||||
|
// 合并,赋值排程批次号(batchnum)
|
||||||
|
StringBuilder rule = buildRule(bill, entryentity);
|
||||||
|
// 避免重复 key
|
||||||
|
boolean keyExists = false;
|
||||||
|
for (StringBuilder existingKey : map.keySet()) {
|
||||||
|
if (existingKey.toString().contentEquals(rule)) {
|
||||||
|
keyExists = true;
|
||||||
|
map.get(existingKey).add(bill);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!keyExists) {
|
||||||
|
map.computeIfAbsent(rule, k -> new ArrayList<>()).add(bill);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assignBatchNumbersAndSave(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载所有bill对象
|
||||||
|
*/
|
||||||
|
private static DynamicObject[] loadAllBills(DynamicObject[] dataEntities) {
|
||||||
|
DynamicObject[] loadedBills = new DynamicObject[dataEntities.length];
|
||||||
|
for (int i = 0; i < dataEntities.length; i++) {
|
||||||
|
loadedBills[i] = BusinessDataServiceHelper.loadSingle(dataEntities[i].getPkValue(), "psd_schedulebill");
|
||||||
|
}
|
||||||
|
return loadedBills;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按规则字段 构建合并规则key
|
||||||
|
*/
|
||||||
|
private static StringBuilder buildRule(DynamicObject bill, DynamicObjectCollection entryentity) {
|
||||||
|
StringBuilder rule = new StringBuilder();
|
||||||
|
for (DynamicObject entry : entryentity) {
|
||||||
|
String feildvalue = entry.getString("feildvalue");// 合并字段_标识
|
||||||
|
feildvalue = feildvalue.contains("e_") ? feildvalue.replaceFirst("e_", "") : feildvalue;
|
||||||
|
Object o = bill.get(feildvalue);// 根据标识获取值,并判断值类型,如果是动态对象,取number值,如果是字符串,直接取值
|
||||||
|
checkType(o, rule);
|
||||||
|
}
|
||||||
|
return rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并并赋值批次号保存
|
||||||
|
*/
|
||||||
|
private static void assignBatchNumbersAndSave(Map<StringBuilder, List<DynamicObject>> map) {
|
||||||
|
map.forEach((k, v) -> {
|
||||||
|
long l = System.currentTimeMillis();
|
||||||
|
for (DynamicObject bill : v) {
|
||||||
|
bill.set("batchnum", "" + l);
|
||||||
|
}
|
||||||
|
SaveServiceHelper.save(v.toArray(new DynamicObject[0]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断对象类型,并添加到rule中
|
||||||
|
*/
|
||||||
|
private static void checkType(Object o, StringBuilder rule) {
|
||||||
|
if (o instanceof DynamicObject) {
|
||||||
|
DynamicObject dy = (DynamicObject) o;
|
||||||
|
dy.getString("number");
|
||||||
|
rule.append(dy.getString("number"));
|
||||||
|
} else if (o instanceof String) {
|
||||||
|
String str = (String) o;
|
||||||
|
rule.append(str);
|
||||||
|
} else if (o instanceof BigDecimal) {
|
||||||
|
BigDecimal bigDecimal = (BigDecimal) o;
|
||||||
|
rule.append(bigDecimal);
|
||||||
|
} else if (o instanceof Date) {
|
||||||
|
long time = ((Date) o).getTime();
|
||||||
|
rule.append(time);
|
||||||
|
} else if (o instanceof Boolean) {
|
||||||
|
boolean bool = (Boolean) o;
|
||||||
|
rule.append(bool);
|
||||||
|
} else if (o instanceof Long) {
|
||||||
|
long longValue = (Long) o;
|
||||||
|
rule.append(longValue);
|
||||||
|
} else {
|
||||||
|
log.error("对象类型是其他类型");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue