清账处理账扣和尾差

This commit is contained in:
yuxueliang0813 2025-05-09 18:29:22 +08:00
parent ed44d1f997
commit 4a58f7f3eb
4 changed files with 67 additions and 13 deletions

View File

@ -532,6 +532,7 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//日期格式化工具
String companyCode = prinfo.getDynamicObject("org").getString("number");
DynamicObject customerinfo = prinfo.getDynamicObject("shjh_customer");//客户对象
String customerCode = customerinfo.getString("number");
IS_HEADER.put("BUKRS",companyCode);//公司代码
IS_HEADER.put("BLART","AB");//凭证类型-清账凭证
//业务日期来源于收款单的流水交易日期如果日期为空则使用单据创建日期
@ -550,8 +551,25 @@ public class ClearAccountBillOperation extends AbstractOperationServicePlugIn im
DynamicObject userinfo = BusinessDataServiceHelper.loadSingleFromCache(RequestContext.get().getCurrUserId(), userName);
String oauser = userinfo.getString("shjh_oauser");
IS_HEADER.put("USNAM",oauser);//用户名
//----------------处理详细入参清账不需要items参数----------------------
String customerCode = customerinfo.getString("number");
//----------------处理详细入参有账扣或尾差需要items参数----------------------
BigDecimal deductionamount = prinfo.getBigDecimal("shjh_deductionamount");//账扣
BigDecimal diffamount = prinfo.getBigDecimal("shjh_diffamount");//尾差
if(deductionamount != null && deductionamount.signum() != 0){
//账扣1122020700应收账款-集团外-账扣费用带清账客户往来编码
JSONObject zkitem = new JSONObject();
zkitem.put("HKONT", "1122020700");//科目编号
zkitem.put("KUNNR", customerCode);//客户编号
zkitem.put("DMBTR", deductionamount.toString());//账扣金额 正数对应借方负数对应贷方
IT_ITEM.add(zkitem);
}
if(diffamount != null && diffamount.signum() != 0){
//尾差1122020100 应收账款-集团外-产品款带1001226客户编码
JSONObject wcitem = new JSONObject();
wcitem.put("HKONT", "1122020100");//科目编号
wcitem.put("KUNNR", "1001226");//客户编号
wcitem.put("DMBTR", diffamount.toString());//尾差金额 正数对应借方负数对应贷方
IT_ITEM.add(wcitem);
}
// customerCode = "1005004";//上海禾诗家化妆品有限公司 -- 仅测试
//----------------处理清账数据入参----------------------
DynamicObjectCollection docolls = prinfo.getDynamicObjectCollection("shjh_details");

View File

@ -65,7 +65,7 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp
// }
//校验本次核销金额填写是否有误防止在正数行填写负数在负数行中填写正数
if(checkEntryAmount(prinfo)){
e.setCancelMessage(billno+"分录本次核销金额填写有误合计等于0负数金额合计的绝对值小于等于未清金额才允许提交");
e.setCancelMessage(billno+"分录本次核销或账扣尾差金额填写有误合计等于0分录负数金额合计的绝对值小于等于未清金额,才允许提交");
e.setCancel(true);
}
//判断对应的清账单是否已提交如果是则不允许提交此明细单
@ -124,6 +124,14 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp
}
}
}
BigDecimal a2 = prinfo.getBigDecimal("shjh_deductionamount");//账扣金额
BigDecimal a3 = prinfo.getBigDecimal("shjh_diffamount");//尾差金额
if(a2 != null){
entrytotal = entrytotal.add(a2);
}
if(a3 != null){
entrytotal = entrytotal.add(a3);
}
if(entrytotal.signum() != 0){
return true;
}
@ -214,6 +222,15 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp
}
}
private DynamicObject getClearEntryInfo(DynamicObjectCollection cleardoc, String detailEntryId){
for (DynamicObject bankinfo : cleardoc) {
if(detailEntryId.equals(bankinfo.getString("shjh_e_detailentryid"))){
return bankinfo;
}
}
return null;
}
private String reWriteClearBill(DynamicObject detailBillInfo){
//根据清账明细单反写清账单-新增
String clearBillid = detailBillInfo.getString("shjh_clearbillid");
@ -230,11 +247,16 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp
DynamicObjectCollection detaildoc = detailBillInfo.getDynamicObjectCollection("shjh_details");
//清账单分录
DynamicObjectCollection cleardoc = clearBillInfo.getDynamicObjectCollection("shjh_details");
DynamicObject detailEntryInfo;
DynamicObject clearEntryInfo;
DynamicObject detailEntryInfo;//清账明细单分录对象
DynamicObject clearEntryInfo;//清账单分录对象
for (int i = 0; i < detaildoc.size(); i++) {
detailEntryInfo = detaildoc.get(i);
//先根据清账单分录集合查找清账单分录对象是否存在不存在则新增
clearEntryInfo = getClearEntryInfo(cleardoc,detailEntryInfo.getString("id"));
if(clearEntryInfo == null){
clearEntryInfo = cleardoc.addNew();
}
clearEntryInfo.set("shjh_e_pzh",detailEntryInfo.getString("shjh_e_pzh"));//凭证号
clearEntryInfo.set("shjh_e_pzlx",detailEntryInfo.getString("shjh_e_pzlx"));//凭证类型
clearEntryInfo.set("shjh_e_pzhh",detailEntryInfo.getString("shjh_e_pzhh"));//凭证行项目号
@ -264,7 +286,7 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp
detailBillInfo.getBigDecimal("shjh_diffamount"));
clearBillInfo.set("shjh_diffamount",q2);
//获取清账单收款金额
BigDecimal q3 =clearBillInfo.getBigDecimal("shjh_receamount");
BigDecimal q3 = clearBillInfo.getBigDecimal("shjh_receamount");
//获取清账单的本次核销金额合计
BigDecimal entrytotal = BigDecimal.ZERO;
BigDecimal entrynegatetotal = BigDecimal.ZERO;//获取清账单中对应的已认领收款金额
@ -281,7 +303,7 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp
// }
// //已认领收款金额=本次核销金额合计-账扣-尾差
// clearBillInfo.set("shjh_claimamount", entrytotal.subtract(q1).subtract(q2));
//已认领收款金额
//已认领收款金额=分录负数金额合计的绝对值
clearBillInfo.set("shjh_claimamount", entrynegatetotal.abs());
//未认领收款金额=收款金额-已认领收款金额
clearBillInfo.set("shjh_unclaimamount", q3.subtract(clearBillInfo.getBigDecimal("shjh_claimamount")));
@ -320,14 +342,18 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp
//清账单分录
DynamicObjectCollection cleardoc = clearBillInfo.getDynamicObjectCollection("shjh_details");
DynamicObject clearEntryInfo;
BigDecimal entrytotal = BigDecimal.ZERO;
// BigDecimal entrytotal = BigDecimal.ZERO;
BigDecimal entrynegatetotal = BigDecimal.ZERO;
for (int i = cleardoc.size()-1; i >=0; i--) {
clearEntryInfo = cleardoc.get(i);
if(idsets.contains(clearEntryInfo.getString("shjh_e_detailentryid"))){
cleardoc.remove(clearEntryInfo);
}else{
entrytotal = entrytotal.add(clearEntryInfo.getBigDecimal("shjh_e_cursettle"));//累计分录本次核销金额
}else if(clearEntryInfo.getBigDecimal("shjh_e_cursettle").signum() == -1){
entrynegatetotal = entrynegatetotal.add(clearEntryInfo.getBigDecimal("shjh_e_cursettle"));
}
// else{
// entrytotal = entrytotal.add(clearEntryInfo.getBigDecimal("shjh_e_cursettle"));//累计分录本次核销金额
// }
}
//处理清账单账扣
BigDecimal q1 = JhzjUtils.reduceTwoAmount(clearBillInfo.getBigDecimal("shjh_deductionamount"),
@ -338,7 +364,9 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp
detailBillInfo.getBigDecimal("shjh_diffamount"));
clearBillInfo.set("shjh_diffamount",q2);
//已认领收款金额=本次核销金额合计-账扣-尾差
clearBillInfo.set("shjh_claimamount", entrytotal.subtract(q1).subtract(q2));
// clearBillInfo.set("shjh_claimamount", entrytotal.subtract(q1).subtract(q2));
//已认领收款金额=分录负数金额合计的绝对值
clearBillInfo.set("shjh_claimamount", entrynegatetotal.abs());
//未认领收款金额=收款金额-已认领收款金额
clearBillInfo.set("shjh_unclaimamount", JhzjUtils.reduceTwoAmount(clearBillInfo.getBigDecimal("shjh_receamount"),
clearBillInfo.getBigDecimal("shjh_claimamount")));

View File

@ -7,7 +7,6 @@ import kd.bos.entity.operate.result.OperateErrorInfo;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.validate.ErrorLevel;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.servicehelper.BusinessDataServiceHelper;
@ -58,6 +57,10 @@ public class VoucherAuditOperation extends AbstractOperationServicePlugIn implem
logger.info("执行收款单 pushvoucher 成功,单据编号:" + bizbillinfo.getString("billno"));
} else {
logger.error(operResult.getMessage());
List<OperateErrorInfo> allErrorInfo = operResult.getAllErrorInfo();
for (OperateErrorInfo errorInfo : allErrorInfo) {
this.operationResult.addErrorInfo(errorInfo);
}
}
}else if(paybillName.equals(sourcebilltype)){
bizbillinfo = BusinessDataServiceHelper.loadSingle(sourcebillid,paybillName);
@ -82,6 +85,10 @@ public class VoucherAuditOperation extends AbstractOperationServicePlugIn implem
logger.info("执行预提记账处理单 sendvoucher 成功,单据编号:" + bizbillinfo.getString("billno"));
} else {
logger.error(operResult.getMessage());
List<OperateErrorInfo> allErrorInfo = operResult.getAllErrorInfo();
for (OperateErrorInfo errorInfo : allErrorInfo) {
this.operationResult.addErrorInfo(errorInfo);
}
}
}
}

View File

@ -79,6 +79,7 @@ public class PayreceiptQueryControler {
q1 = addFilterIfNotEmpty(q1, "shjh_fkentryid", fkEntryID);//费控单据分录ID
q1 = addFilterIfNotEmpty(q1, "entry.shjh_fkdjbh", fkBillNumber);//费控单据编号-外部系统单号
q1 = addFilterIfNotEmpty(q1, "shjh_credentialnum", voucherNum);//付款凭证号
q1 = addFilterIfNotEmpty(q1, "shjh_sapfiscalyear", voucherYear);//付款凭证年份
DynamicObject paybill = BusinessDataServiceHelper.loadSingle(paybillName, new QFilter[]{q1});
if (null == paybill) {
return handleErrorAndReturn("查询失败:付款单不存在", fkEntryID, jsonBodyString,apiResultExt);