入库单优化提交校验逻辑

This commit is contained in:
xuhaihui 2025-11-03 17:03:36 +08:00
parent 8f1137f022
commit bb78e36319
1 changed files with 72 additions and 43 deletions

View File

@ -12,7 +12,7 @@ import java.math.BigDecimal;
/**
* 入库单提交操作校验插件
* 说明校验存在发票时发票分录中的金额税额和价税合计与入库单明细中的金额税额和含税金额是否一致
* 说明校验存在发票时看无运费发票按钮是否开启不开启校验含运费金额开启只校验金额
*/
public class MaterialInBillSubmitValidatorOp extends AbstractOperationServicePlugIn {
public void onPreparePropertys(PreparePropertysEventArgs e) {
@ -29,6 +29,11 @@ public class MaterialInBillSubmitValidatorOp extends AbstractOperationServicePlu
e.getFieldKeys().add("totaltaxamount");
e.getFieldKeys().add("totaloftaxamount");
e.getFieldKeys().add("zcgj_invoice_type");
e.getFieldKeys().add("zcgj_notraninvoice");
e.getFieldKeys().add("matoftaxamount");
e.getFieldKeys().add("matamount");
e.getFieldKeys().add("mataxamount");
e.getFieldKeys().add("zcgj_freight_invoice");
}
@Override
@ -45,57 +50,81 @@ public class MaterialInBillSubmitValidatorOp extends AbstractOperationServicePlu
DynamicObject ecma_MaterialInBill = extendedDataEntity.getDataEntity();
DynamicObjectCollection entryEntityCollection = ecma_MaterialInBill.getDynamicObjectCollection("zcgj_entryentity");//合同进项发票信息
DynamicObjectCollection entryEntity2Collection = ecma_MaterialInBill.getDynamicObjectCollection("entryentity");//入库单分录
String invoice_type = ecma_MaterialInBill.getString("zcgj_invoice_type");//发票类型
if (entryEntityCollection != null && entryEntityCollection.size() > 0 && entryEntity2Collection != null && entryEntity2Collection.size() > 0) {
String invoice_type = ecma_MaterialInBill.getString("zcgj_invoice_type");//发票类型
boolean zcgj_notraninvoice = ecma_MaterialInBill.getBoolean("zcgj_notraninvoice");//无运费发票
BigDecimal totalInvoiceAmount = BigDecimal.ZERO; // 发票总金额不含税
BigDecimal totalInvoiceTax = BigDecimal.ZERO; // 发票总税额
BigDecimal totalInvoiceTotal = BigDecimal.ZERO; // 发票总价税合计
if (!zcgj_notraninvoice) {
BigDecimal totalInvoiceTotal = BigDecimal.ZERO; // 发票总价税合计
BigDecimal totalInvoiceAmount = BigDecimal.ZERO; // 发票总金额不含税
BigDecimal totalInvoiceTax = BigDecimal.ZERO; // 发票总税额
BigDecimal totalEntryTotal = ecma_MaterialInBill.getBigDecimal("totaloftaxamount"); // 入库含税总金额
BigDecimal totalEntryAmount = ecma_MaterialInBill.getBigDecimal("totalamount"); // 入库总金额不含税
BigDecimal totalEntryTax = ecma_MaterialInBill.getBigDecimal("totaltaxamount"); // 入库单总税额
BigDecimal totalEntryAmount = ecma_MaterialInBill.getBigDecimal("totalamount"); // 入库总金额不含税
BigDecimal totalEntryTax = ecma_MaterialInBill.getBigDecimal("totaltaxamount"); // 入库单总税额
BigDecimal totalEntryTotal = ecma_MaterialInBill.getBigDecimal("totaloftaxamount"); // 入库含税总金额
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);
for (DynamicObject entryEntity : entryEntityCollection) {
BigDecimal invoiceTotal = entryEntity.getBigDecimal("zcgj_oftaxinvoiceamount"); // 合同进项发票信息-价税合计
BigDecimal invoiceAmount = entryEntity.getBigDecimal("zcgj_invoiceamount"); // 合同进项发票信息-金额
BigDecimal invoiceTax = entryEntity.getBigDecimal("zcgj_invoicetax"); // 合同进项发票信息-税额
if (invoiceTotal != null) {
totalInvoiceTotal = totalInvoiceTotal.add(invoiceTotal);
}
if (invoiceAmount != null) {
totalInvoiceAmount = totalInvoiceAmount.add(invoiceAmount);
}
if (invoiceTax != null) {
totalInvoiceTax = totalInvoiceTax.add(invoiceTax);
}
}
if (invoiceTax != null) {
totalInvoiceTax = totalInvoiceTax.add(invoiceTax);
if (totalInvoiceTotal.compareTo(totalEntryTotal) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库含税总金额与合同进项发票信息价税合计汇总不匹配!");
}
if (invoiceTotal != null) {
totalInvoiceTotal = totalInvoiceTotal.add(invoiceTotal);
if (invoice_type != null && invoice_type.equals("1")) {
return;
}
}
/* for (DynamicObject entryEntity2 : entryEntity2Collection) {
BigDecimal notaxAmount = entryEntity2.getBigDecimal("amount"); // 入库单-含运费金额不含税
BigDecimal taxAmount = entryEntity2.getBigDecimal("taxamount").add(entryEntity2.getBigDecimal("zcgj_transtaxamount")); // 入库单-税额+运费税额
BigDecimal oftaxAmount = entryEntity2.getBigDecimal("amount").add(entryEntity2.getBigDecimal("taxtransamount")); // 入库单-含税金额+含税运费
if (notaxAmount != null) {
totalEntryAmount = totalEntryAmount.add(notaxAmount);
if (totalInvoiceAmount.compareTo(totalEntryAmount) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库总金额与合同进项发票信息金额汇总不匹配!");
}
if (taxAmount != null) {
totalEntryTax = totalEntryTax.add(taxAmount);
if (totalInvoiceTax.compareTo(totalEntryTax) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "税额与合同进项发票信息税额汇总不匹配!");
}
if (oftaxAmount != null) {
totalEntryTotal = totalEntryTotal.add(oftaxAmount);
} else {
BigDecimal totalInvoiceTotal = BigDecimal.ZERO; // 发票总价税合计(不含运费发票
BigDecimal totalInvoiceAmount = BigDecimal.ZERO; // 发票总金额不含税(不含运费发票
BigDecimal totalInvoiceTax = BigDecimal.ZERO; // 发票总税额(不含运费发票
BigDecimal totalEntryTotal = ecma_MaterialInBill.getBigDecimal("matoftaxamount"); // 材料含税总金额
BigDecimal totalEntryAmount = ecma_MaterialInBill.getBigDecimal("matamount"); // 材料总金额
BigDecimal totalEntryTax = ecma_MaterialInBill.getBigDecimal("mataxamount"); // 材料总税额
for (DynamicObject entryEntity : entryEntityCollection) {
BigDecimal invoiceTotal = entryEntity.getBigDecimal("zcgj_oftaxinvoiceamount"); // 合同进项发票信息-价税合计
BigDecimal invoiceAmount = entryEntity.getBigDecimal("zcgj_invoiceamount"); // 合同进项发票信息-金额
BigDecimal invoiceTax = entryEntity.getBigDecimal("zcgj_invoicetax"); // 合同进项发票信息-税额
boolean zcgj_freight_invoice = entryEntity.getBoolean("zcgj_freight_invoice"); //运费发票
if (zcgj_freight_invoice) {
break;
}
if (invoiceTotal != null) {
totalInvoiceTotal = totalInvoiceTotal.add(invoiceTotal);
}
if (invoiceAmount != null) {
totalInvoiceAmount = totalInvoiceAmount.add(invoiceAmount);
}
if (invoiceTax != null) {
totalInvoiceTax = totalInvoiceTax.add(invoiceTax);
}
}
if (totalInvoiceTotal.compareTo(totalEntryTotal) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库含税总金额与合同进项发票信息价税合计汇总不匹配!");
}
if (invoice_type != null && invoice_type.equals("1")) {
return;
}
if (totalInvoiceAmount.compareTo(totalEntryAmount) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库总金额与合同进项发票信息金额汇总不匹配!");
}
if (totalInvoiceTax.compareTo(totalEntryTax) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "税额与合同进项发票信息税额汇总不匹配!");
}
}*/
if (totalInvoiceTotal.compareTo(totalEntryTotal) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库含税总金额与合同进项发票信息价税合计汇总不匹配!");
}
if (invoice_type != null && invoice_type.equals("1")) {
return;
}
if (totalInvoiceAmount.compareTo(totalEntryAmount) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库总金额与合同进项发票信息金额汇总不匹配!");
}
if (totalInvoiceTax.compareTo(totalEntryTax) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "税额与合同进项发票信息税额汇总不匹配!");
}
}
}