入库单提交操作校验插件:校验存在发票时,发票分录中的金额税额和价税合计与入库单明细中的金额税额和价税合计是否一致

This commit is contained in:
xuhaihui 2025-09-28 14:53:15 +08:00
parent 3d242fe726
commit c74b3146dd
1 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,96 @@
package zcgj.zcdev.zcdev.pr.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.PreparePropertysEventArgs;
import kd.bos.entity.validate.AbstractValidator;
import java.math.BigDecimal;
/**
* 入库单提交操作校验插件
* 说明校验存在发票时发票分录中的金额税额和价税合计与入库单明细中的金额税额和价税合计是否一致
*/
public class MaterialInBillSubmitValidatorOp extends AbstractOperationServicePlugIn {
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
e.getFieldKeys().add("zcgj_entryentity");
e.getFieldKeys().add("entryentity");
e.getFieldKeys().add("zcgj_invoiceamount");
e.getFieldKeys().add("zcgj_invoicetax");
e.getFieldKeys().add("zcgj_oftaxinvoiceamount");
e.getFieldKeys().add("notaxamount");
e.getFieldKeys().add("taxamount");
e.getFieldKeys().add("oftaxamount");
}
@Override
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
e.getValidators().add(new ValidatorExt());
}
class ValidatorExt extends AbstractValidator {
@Override
public void validate() {
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
DynamicObject ecma_MaterialInBill = extendedDataEntity.getDataEntity();
DynamicObjectCollection entryEntityCollection = ecma_MaterialInBill.getDynamicObjectCollection("zcgj_entryentity");//合同进项发票信息
DynamicObjectCollection entryEntity2Collection = ecma_MaterialInBill.getDynamicObjectCollection("entryentity");//入库单分录
if (entryEntityCollection != null && entryEntityCollection.size() > 0 && entryEntity2Collection != null && entryEntity2Collection.size() > 0) {
BigDecimal totalInvoiceAmount = BigDecimal.ZERO; // 发票总金额
BigDecimal totalInvoiceTax = BigDecimal.ZERO; // 发票总税额
BigDecimal totalInvoiceTotal = BigDecimal.ZERO; // 发票总价税合计
BigDecimal totalEntryAmount = BigDecimal.ZERO; // 入库单总金额
BigDecimal totalEntryTax = BigDecimal.ZERO; // 入库单总税额
BigDecimal totalEntryTotal = BigDecimal.ZERO; // 入库单总价税合计
for (DynamicObject entryEntity : entryEntityCollection) {
BigDecimal invoiceAmount = entryEntity.getBigDecimal("zcgj_invoiceamount"); // 合同进项发票信息-金额
BigDecimal invoiceTax = entryEntity.getBigDecimal("zcgj_invoicetax"); // 合同进项发票信息-税额
BigDecimal invoiceTotal = entryEntity.getBigDecimal("zcgj_oftaxinvoiceamount"); // 合同进项发票信息-价税合计
if (invoiceAmount != null) {
totalInvoiceAmount = totalInvoiceAmount.add(invoiceAmount);
}
if (invoiceTax != null) {
totalInvoiceTax = totalInvoiceTax.add(invoiceTax);
}
if (invoiceTotal != null) {
totalInvoiceTotal = totalInvoiceTotal.add(invoiceTotal);
}
}
for (DynamicObject entryEntity2 : entryEntity2Collection) {
BigDecimal notaxAmount = entryEntity2.getBigDecimal("notaxamount"); // 入库单-金额
BigDecimal taxAmount = entryEntity2.getBigDecimal("taxamount"); // 入库单-税额
BigDecimal oftaxAmount = entryEntity2.getBigDecimal("oftaxamount"); // 入库单-含税金额
if (notaxAmount != null) {
totalEntryAmount = totalEntryAmount.add(notaxAmount);
}
if (taxAmount != null) {
totalEntryTax = totalEntryTax.add(taxAmount);
}
if (oftaxAmount != null) {
totalEntryTotal = totalEntryTotal.add(oftaxAmount);
}
}
if (totalInvoiceAmount.compareTo(totalEntryAmount) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库单明细金额汇总与合同进项发票信息金额汇总不匹配!");
}
if (totalInvoiceTax.compareTo(totalEntryTax) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库单明细税额汇总与合同进项发票信息税额汇总不匹配!");
}
if (totalInvoiceTotal.compareTo(totalEntryTotal) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库单明细含税金额汇总与合同进项发票信息价税合计汇总不匹配!");
}
}
}
}
}
}