对公报销单提交操作插件:冲预付时预付单支付日期与开票日期和当前日期的对比校验

This commit is contained in:
xuhaihui 2025-08-04 16:15:14 +08:00
parent cfea1526f3
commit 8962e95bac
1 changed files with 68 additions and 5 deletions

View File

@ -7,6 +7,9 @@ import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
import java.text.ParseException;
@ -15,8 +18,8 @@ import java.util.Date;
import java.util.concurrent.TimeUnit;
/**
* 使用单据费用报销单差旅报销单对公报销单提交操作插件
* 校验逻辑开票日期与当前日期的对比校验
* 1校验逻辑开票日期与当前日期的对比校验 使用单据费用报销单差旅报销单对公报销单提交操作;
* 2校验逻辑冲预付时预付单支付日期与开票日期和当前日期的对比校验 使用单据对公报销单提交操作
*/
public class InvoiceDateValidatorSubOp extends AbstractOperationServicePlugIn {
@Override
@ -26,6 +29,9 @@ public class InvoiceDateValidatorSubOp extends AbstractOperationServicePlugIn {
e.getFieldKeys().add("zcgj_invoiceremark");//特殊说明
e.getFieldKeys().add("invoiceentry");//发票信息分录
e.getFieldKeys().add("invoicedate");//开票日期
e.getFieldKeys().add("writeoffmoney");//冲预付/借款分录
e.getFieldKeys().add("srcbilltype");//来源单据类型
e.getFieldKeys().add("loanbillnov1");//冲预付编码
}
@Override
@ -45,6 +51,7 @@ public class InvoiceDateValidatorSubOp extends AbstractOperationServicePlugIn {
Long companyId = costCompany.getLong("id");
if (OrgCheckUtils.isKS(companyId)) {
//仅针对矿山下组织下的逻辑
String dataEntityTypeName = dataEntity.getDataEntityType().getName();
String invoiceRemark = dataEntity.getString("zcgj_invoiceremark");//特殊说明
DynamicObjectCollection invoiceEntryCollection = dataEntity.getDynamicObjectCollection("invoiceentry");//发票信息分录
if (invoiceEntryCollection.size() > 0) {
@ -52,7 +59,8 @@ public class InvoiceDateValidatorSubOp extends AbstractOperationServicePlugIn {
for (int i = 0; i < invoiceEntryCollection.size(); i++) {
DynamicObject invoiceEntry = invoiceEntryCollection.get(i);
int i1 = i + 1;
Date currentDate = new Date();//当前日期
// Date currentDate = new Date();//当前日期
Date currentDate = invoiceEntry.getDate("zcgj_invoicedate");//当前日期
Date invoiceDate = invoiceEntry.getDate("invoicedate");//开票日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
@ -61,7 +69,7 @@ public class InvoiceDateValidatorSubOp extends AbstractOperationServicePlugIn {
// 校验1: 开票日期不能大于当前日期
if (invoiceDate.after(currentDateFormat)) {
this.addFatalErrorMessage(extendedDataEntity, "" + i1 + "开票日期大于当前日期!");
this.addFatalErrorMessage(extendedDataEntity, "发票信息" + i1 + "开票日期大于当前日期!");
return;
}
@ -90,12 +98,67 @@ public class InvoiceDateValidatorSubOp extends AbstractOperationServicePlugIn {
// 最终校验当前日期减去开票日期不能大于30天且不是特殊情况且特殊说明为空时则视为不合规
if (diffInDays > 30 && !isSpecialCase && "".equals(invoiceRemark)) {
this.addFatalErrorMessage(extendedDataEntity, "" + i1 + "发票开具日期至当前报销日的间隔时间,不得超过一个月(30天)。必须填写特殊说明才能提交!");
this.addFatalErrorMessage(extendedDataEntity, "发票信息" + i1 + "发票开具日期至当前报销日的间隔时间,不得超过一个月(30天)。必须填写特殊说明才能提交!");
return;
}
} catch (ParseException e) {
return;
}
// 对公报销单冲预付单独校验逻辑
if (dataEntityTypeName.equals("er_publicreimbursebill")) {
// 对公报销单
DynamicObjectCollection writeOffMoneyCollection = dataEntity.getDynamicObjectCollection("writeoffmoney");//冲预付/借款分录
if (writeOffMoneyCollection.size() > 0) {
for (int j = 0; j < writeOffMoneyCollection.size(); j++) {
int j1 = j + 1;
DynamicObject writeOffMoney = writeOffMoneyCollection.get(j);
String srcBillType = writeOffMoney.getString("srcbilltype");//冲预付分录-源单据类型
if (srcBillType.equals("er_prepaybill")) {
//冲预付
String loanBillNov1 = writeOffMoney.getString("loanbillnov1");//冲预付分录-单据编码
QFilter[] qFilter = new QFilter[]{new QFilter("billno", QCP.equals, loanBillNov1)};
DynamicObject er_prepayBill = BusinessDataServiceHelper.loadSingle("er_prepaybill",
"id,head_paydate", qFilter);//预付单
Date head_payDate = er_prepayBill.getDate("head_paydate");//预付单-付款日期
if (head_payDate != null) {
try {
Date currentDateFormat = sdf.parse(sdf.format(currentDate));//当前日期
Date invoiceDateFormat = sdf.parse(sdf.format(invoiceDate));//开票日期
Date headPayDateFormat = sdf.parse(sdf.format(head_payDate));//预付单付款日期
// 校验1付款日期不能大于当前日期或者开票日期
if (headPayDateFormat.after(currentDateFormat)) {
this.addFatalErrorMessage(extendedDataEntity, "发票信息第" + i1 + "行与冲预付/借款分录第" + j1 + "行:预付单付款日期不能大于当前日期!");
return;
}
if (headPayDateFormat.after(invoiceDateFormat)) {
this.addFatalErrorMessage(extendedDataEntity, "发票信息第" + i1 + "行与冲预付/借款分录第" + j1 + "行:预付单付款日期不能大于发票开票日期!");
return;
}
// 校验2: 发票开具时间减去预付单的付款日期必须小于等于15天
long diffInvoiceToPayMillis = Math.abs(invoiceDateFormat.getTime() - headPayDateFormat.getTime());
long diffInvoiceToPayDays = TimeUnit.DAYS.convert(diffInvoiceToPayMillis, TimeUnit.MILLISECONDS);
if (diffInvoiceToPayDays > 15 && "".equals(invoiceRemark)) {
this.addFatalErrorMessage(extendedDataEntity, "发票信息第" + i1 + "行与冲预付/借款分录第" + j1 + "发票开具日期至预付单的支付时间的间隔不得超过15天。必须填写特殊说明才能提交");
return;
}
// 校验3: 当前时间减去预付单的付款日期必须小于等于30天
long diffCurrentToPayMillis = Math.abs(currentDateFormat.getTime() - headPayDateFormat.getTime());
long diffCurrentToPayDays = TimeUnit.DAYS.convert(diffCurrentToPayMillis, TimeUnit.MILLISECONDS);
if (diffCurrentToPayDays > 30 && "".equals(invoiceRemark)) {
this.addFatalErrorMessage(extendedDataEntity, "发票信息第" + i1 + "行与冲预付/借款分录第" + j1 + "预付款支付日期至当前报销日的间隔时间不得超过30天。必须填写特殊说明才能提交");
return;
}
} catch (ParseException e) {
return;
}
}
}
}
}
}
}
}
}