diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/InvoiceDateValidatorSubOp.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/InvoiceDateValidatorSubOp.java index 8837d6d..e4c1f2a 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/InvoiceDateValidatorSubOp.java +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/InvoiceDateValidatorSubOp.java @@ -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; + } + } + } + } + } + } } } }