diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/ReimbursementInvoiceTaxAmtCkOp.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/ReimbursementInvoiceTaxAmtCkOp.java new file mode 100644 index 0000000..d6a2cc6 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/ReimbursementInvoiceTaxAmtCkOp.java @@ -0,0 +1,90 @@ +package zcgj.zcdev.zcdev.fs.plugin.operate; + +import kd.bos.context.RequestContext; +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 kd.bos.servicehelper.user.UserServiceHelper; +import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +/** + * 对公报销单,费用报销单发票税额和报销税额差额校验 + */ +public class ReimbursementInvoiceTaxAmtCkOp extends AbstractOperationServicePlugIn { + + // 定义容差范围 + private static final BigDecimal TOLERANCE = new BigDecimal("0.05"); + + @Override + public void onPreparePropertys(PreparePropertysEventArgs e) { + super.onPreparePropertys(e); + e.getFieldKeys().add("costcompany"); + e.getFieldKeys().add("expenseentryentity"); + e.getFieldKeys().add("invoiceentry"); + } + + @Override + public void onAddValidators(AddValidatorsEventArgs e) { + super.onAddValidators(e); + Long currentUserId = UserServiceHelper.getCurrentUserId(); + // 当前用户所属组织 + Long mainOrgId = UserServiceHelper.getUserMainOrgId(currentUserId); + //当前切换选择的组织 + Long currentOrgId = RequestContext.get().getOrgId(); + //当前所在的组织是属于矿山下的 + //if(OrgCheckUtils.isKS(currentOrgId)){ + e.getValidators().add(new ValidatorExt()); + //} + } + + class ValidatorExt extends AbstractValidator { + @Override + public void validate() { + ExtendedDataEntity[] extendedDataEntities = this.getDataEntities(); + for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) { + DynamicObject dataEntity = extendedDataEntity.getDataEntity(); + long aLong = dataEntity.getLong("id"); + //获取报销人 + DynamicObject applier = dataEntity.getDynamicObject("applier"); + long applierId = applier.getLong("id"); + //获取申请日期 + Object costcompanyObj = dataEntity.get("costcompany"); + Object costdeptObj = dataEntity.get("costdept"); + if(costcompanyObj!=null && costdeptObj != null){ + DynamicObject costcompany = (DynamicObject)costcompanyObj; + long costcompanyId = costcompany.getLong("id"); + if(OrgCheckUtils.isKS(costcompanyId)){ + DynamicObjectCollection expenseentryentity = dataEntity.getDynamicObjectCollection("expenseentryentity");//费用明细 + DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry");//发票明细 + if(expenseentryentity!=null && !expenseentryentity.isEmpty() && invoiceentry!=null && !invoiceentry.isEmpty()){ + BigDecimal allTaxamount = BigDecimal.ZERO; + BigDecimal allTaxamountInvoice = BigDecimal.ZERO; + + for (DynamicObject dynamicObject : expenseentryentity) { + BigDecimal taxamount = dynamicObject.getBigDecimal("taxamount") != null?dynamicObject.getBigDecimal("taxamount"):BigDecimal.ZERO;//税额 + allTaxamount = allTaxamount.add(taxamount); + } + + for (DynamicObject dynamicObject : invoiceentry) { + BigDecimal taxamountInvoice = dynamicObject.getBigDecimal("taxamount_invoice") != null?dynamicObject.getBigDecimal("taxamount_invoice"):BigDecimal.ZERO;//发票税额 + allTaxamountInvoice = allTaxamountInvoice.add(taxamountInvoice); + } + + BigDecimal differAmount = allTaxamount.subtract(allTaxamountInvoice).abs(); + if (differAmount.compareTo(TOLERANCE) > 0) { + this.addFatalErrorMessage(extendedDataEntity, String.format("报销税额超出发票税额:%s",differAmount.setScale(2, RoundingMode.HALF_EVEN))); + } + } + } + } + } + } + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/TripreimbursebillInvoiceTaxAmtCkOp.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/TripreimbursebillInvoiceTaxAmtCkOp.java new file mode 100644 index 0000000..21ad3c7 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/operate/TripreimbursebillInvoiceTaxAmtCkOp.java @@ -0,0 +1,94 @@ +package zcgj.zcdev.zcdev.fs.plugin.operate; + +import kd.bos.context.RequestContext; +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 kd.bos.servicehelper.user.UserServiceHelper; +import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +/** + * 差旅报销单发票税额和报销税额差额校验 + */ +public class TripreimbursebillInvoiceTaxAmtCkOp extends AbstractOperationServicePlugIn { + + // 定义容差范围 + private static final BigDecimal TOLERANCE = new BigDecimal("0.05"); + + @Override + public void onPreparePropertys(PreparePropertysEventArgs e) { + super.onPreparePropertys(e); + e.getFieldKeys().add("costcompany"); + e.getFieldKeys().add("tripentry"); + e.getFieldKeys().add("invoiceentry"); + e.getFieldKeys().add("entryentity"); + } + + @Override + public void onAddValidators(AddValidatorsEventArgs e) { + super.onAddValidators(e); + Long currentUserId = UserServiceHelper.getCurrentUserId(); + // 当前用户所属组织 + Long mainOrgId = UserServiceHelper.getUserMainOrgId(currentUserId); + //当前切换选择的组织 + Long currentOrgId = RequestContext.get().getOrgId(); + //当前所在的组织是属于矿山下的 + //if(OrgCheckUtils.isKS(currentOrgId)){ + e.getValidators().add(new ValidatorExt()); + //} + } + + class ValidatorExt extends AbstractValidator { + @Override + public void validate() { + ExtendedDataEntity[] extendedDataEntities = this.getDataEntities(); + for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) { + DynamicObject dataEntity = extendedDataEntity.getDataEntity(); + long aLong = dataEntity.getLong("id"); + //获取报销人 + DynamicObject applier = dataEntity.getDynamicObject("applier"); + long applierId = applier.getLong("id"); + //获取申请日期 + Object costcompanyObj = dataEntity.get("costcompany"); + Object costdeptObj = dataEntity.get("costdept"); + if(costcompanyObj!=null && costdeptObj != null){ + DynamicObject costcompany = (DynamicObject)costcompanyObj; + long costcompanyId = costcompany.getLong("id"); + if(OrgCheckUtils.isKS(costcompanyId)){ + DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry");//发票明细 + DynamicObjectCollection tripentry = dataEntity.getDynamicObjectCollection("tripentry");//差旅明细 + if(tripentry!=null && !tripentry.isEmpty()){ + BigDecimal allTaxamount = BigDecimal.ZERO; + BigDecimal allTaxamountInvoice = BigDecimal.ZERO; + for (DynamicObject tripEntry : tripentry) { + DynamicObjectCollection dynamicObjectCollection = tripEntry.getDynamicObjectCollection("entryentity"); + for (DynamicObject dynamicObject : dynamicObjectCollection) { + BigDecimal taxamount = dynamicObject.getBigDecimal("taxamount") != null?dynamicObject.getBigDecimal("taxamount"):BigDecimal.ZERO;//税额 + allTaxamount = allTaxamount.add(taxamount); + } + } + + for (DynamicObject dynamicObject : invoiceentry) { + BigDecimal taxamountInvoice = dynamicObject.getBigDecimal("taxamount_invoice") != null?dynamicObject.getBigDecimal("taxamount_invoice"):BigDecimal.ZERO;//发票税额 + allTaxamountInvoice = allTaxamountInvoice.add(taxamountInvoice); + } + + BigDecimal differAmount = allTaxamount.subtract(allTaxamountInvoice).abs(); + if (differAmount.compareTo(TOLERANCE) > 0) { + this.addFatalErrorMessage(extendedDataEntity, String.format("报销税额超出发票税额:%s",differAmount.setScale(2, RoundingMode.HALF_EVEN))); + } + } + + } + } + } + } + } +}