差旅报销单发票金额精确调整插件
This commit is contained in:
parent
19d0e21b5f
commit
912cf2b8ef
|
@ -0,0 +1,38 @@
|
||||||
|
package zcgj.zcdev.zcdev.fs.plugin.operate;
|
||||||
|
|
||||||
|
import kd.bos.context.RequestContext;
|
||||||
|
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||||
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
|
import kd.fi.er.opplugin.web.TripReimburseSubmitOp;
|
||||||
|
import kd.fi.er.validator.*;
|
||||||
|
import zcgj.zcdev.zcdev.fs.plugin.validator.TripReimSubmitCheckInvoiceValidatorExt;
|
||||||
|
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 差旅报销单发票金额精确调整插件
|
||||||
|
*/
|
||||||
|
public class TripReimburseSubmitOpExt extends TripReimburseSubmitOp {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||||
|
Long currentUserId = UserServiceHelper.getCurrentUserId();
|
||||||
|
// 当前用户所属组织
|
||||||
|
Long mainOrgId = UserServiceHelper.getUserMainOrgId(currentUserId);
|
||||||
|
//当前切换选择的组织
|
||||||
|
Long currentOrgId = RequestContext.get().getOrgId();
|
||||||
|
//当前所在的组织是属于矿山下的
|
||||||
|
if(OrgCheckUtils.isKS(currentOrgId)){
|
||||||
|
e.addValidator(new TripReimburseSubmitValidator());
|
||||||
|
e.addValidator(new TripReimburseLoanValidator());
|
||||||
|
e.addValidator(new TripStandardValidator());
|
||||||
|
e.addValidator(new ReverseBillSubmitValidator());
|
||||||
|
e.addValidator(new SameCurrencySubmitValidator());
|
||||||
|
e.addValidator(new TripNoReimburseOrderValidator());
|
||||||
|
e.addValidator(new TripDateControlValidator());
|
||||||
|
e.addValidator(new LoanAndAccountCurrencyUniqueValidator());
|
||||||
|
e.getValidators().add(new TripReimSubmitCheckInvoiceValidatorExt());
|
||||||
|
}else{
|
||||||
|
super.onAddValidators(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,147 @@
|
||||||
|
package zcgj.zcdev.zcdev.fs.plugin.validator;
|
||||||
|
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.dataentity.resource.ResManager;
|
||||||
|
import kd.bos.entity.ExtendedDataEntity;
|
||||||
|
import kd.bos.entity.validate.AbstractValidator;
|
||||||
|
import kd.bos.logging.Log;
|
||||||
|
import kd.bos.logging.LogFactory;
|
||||||
|
import kd.fi.er.business.image.ImageServiceHelper;
|
||||||
|
import kd.fi.er.business.utils.*;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class TripReimSubmitCheckInvoiceValidatorExt extends AbstractValidator {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(TripReimSubmitCheckInvoiceValidatorExt.class);
|
||||||
|
|
||||||
|
public void validate() {
|
||||||
|
ExtendedDataEntity[] dataEntities = this.getDataEntities();
|
||||||
|
|
||||||
|
for(ExtendedDataEntity dataEntity : dataEntities) {
|
||||||
|
DynamicObject bill = dataEntity.getDataEntity();
|
||||||
|
DynamicObject company = bill.getDynamicObject("company");
|
||||||
|
DynamicObject costcompany = bill.getDynamicObject("costcompany");
|
||||||
|
if (company == null || costcompany == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Long companyId = (Long)company.getPkValue();
|
||||||
|
this.chechInvoiceImageTemp(bill, dataEntity);
|
||||||
|
this.checkNoInvoice(bill, dataEntity);
|
||||||
|
if (ErStdConfig.getInvoiceMustWithExpense()) {
|
||||||
|
for(String result : InvoiceUtils.checkUnbindInvoice(bill, dataEntity)) {
|
||||||
|
this.addErrorMessage(dataEntity, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicObjectCollection invoiceItemEntryDOs = bill.getDynamicObjectCollection("invoiceitementry");
|
||||||
|
if (!invoiceItemEntryDOs.isEmpty()) {
|
||||||
|
Boolean mustCheck = SystemParamterUtil.isAmountOverInvoice(companyId);
|
||||||
|
if (!mustCheck) {
|
||||||
|
//如果是矿山下面的组织
|
||||||
|
long costcompanyId = costcompany.getLong("id");
|
||||||
|
if(OrgCheckUtils.isKS(costcompanyId)){
|
||||||
|
//修改位置,重写发票金额校验逻辑
|
||||||
|
for(String result : InvoiceUtilsExt.checkAmount(bill, InvoiceUtils.BillEntityType.TripReimburse)) {
|
||||||
|
this.addErrorMessage(dataEntity, result);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
for(String result : InvoiceUtils.checkAmount(bill, InvoiceUtils.BillEntityType.TripReimburse)) {
|
||||||
|
this.addErrorMessage(dataEntity, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicObject invoicOrgDO = bill.getDynamicObject("costcompany");
|
||||||
|
|
||||||
|
for(String result : InvoiceUtils.checkBuyerNameAndTaxNo(bill, ErCommonUtils.getPk(invoicOrgDO), false)) {
|
||||||
|
this.addErrorMessage(dataEntity, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkNoInvoice(DynamicObject bill, ExtendedDataEntity dataEntity) {
|
||||||
|
DynamicObject company = bill.getDynamicObject("company");
|
||||||
|
if (company != null) {
|
||||||
|
Long companyId = (Long)company.getPkValue();
|
||||||
|
Boolean invoiceIsMust = ReimburseControlUtils.invoiceIsMust(companyId);
|
||||||
|
if (invoiceIsMust) {
|
||||||
|
boolean supplementinvoice = bill.getBoolean("needsuppleinvoice");
|
||||||
|
if (!supplementinvoice) {
|
||||||
|
Boolean billHeadNoInvocie = bill.getBoolean("noinvoice");
|
||||||
|
if (!billHeadNoInvocie) {
|
||||||
|
Long invoiceCurrency = SystemParamterUtil.getInvoiceEntryCurrency(companyId);
|
||||||
|
DynamicObjectCollection tripEntries = bill.getDynamicObjectCollection("tripentry");
|
||||||
|
int tripLength = tripEntries.size();
|
||||||
|
|
||||||
|
for(int tripIndex = 0; tripIndex < tripLength; ++tripIndex) {
|
||||||
|
DynamicObject tripEntry = (DynamicObject)tripEntries.get(tripIndex);
|
||||||
|
DynamicObjectCollection entries = tripEntry.getDynamicObjectCollection("entryentity");
|
||||||
|
int entryLength = entries.size();
|
||||||
|
|
||||||
|
for(int entryIndex = 0; entryIndex < entryLength; ++entryIndex) {
|
||||||
|
DynamicObject entry = (DynamicObject)entries.get(entryIndex);
|
||||||
|
String orderId = entry.getString("orderformid");
|
||||||
|
if (!StringUtils.isNotBlank(orderId)) {
|
||||||
|
BigDecimal oriEntryAmount = entry.getBigDecimal("orientryamount");
|
||||||
|
if (oriEntryAmount.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
DynamicObject expenseItem = entry.getDynamicObject("expenseitem");
|
||||||
|
if (expenseItem != null && Objects.equals(invoiceCurrency, ErCommonUtils.getPk(entry.getDynamicObject("entrycurrency")))) {
|
||||||
|
Boolean itemInvoice = expenseItem.getBoolean("noinvoice");
|
||||||
|
if (!itemInvoice) {
|
||||||
|
String invoiceNo = entry.getString("invoiceno_entry");
|
||||||
|
if (StringUtils.isBlank(invoiceNo)) {
|
||||||
|
String fmt = String.format(ResManager.loadKDString("第%s行差旅明细需要导入发票或关联发票。", "TripReimSubmitCheckInvoiceValidator_1", "fi-er-opplugin", new Object[0]), entryIndex + 1);
|
||||||
|
if (tripLength > 1) {
|
||||||
|
String tripInfo = String.format(ResManager.loadKDString("第%s条行程,", "TripReimSubmitCheckInvoiceValidator_2", "fi-er-opplugin", new Object[0]), tripIndex + 1);
|
||||||
|
fmt = tripInfo.concat(fmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addErrorMessage(dataEntity, fmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void chechInvoiceImageTemp(DynamicObject bill, ExtendedDataEntity dataEntity) {
|
||||||
|
DynamicObjectCollection invoiceEntrys = bill.getDynamicObjectCollection("invoiceentry");
|
||||||
|
if (invoiceEntrys.size() <= 0) {
|
||||||
|
log.info("发票分录没有发票,不进行校验");
|
||||||
|
} else {
|
||||||
|
DynamicObject company = bill.getDynamicObject("company");
|
||||||
|
String mainEntityId = bill.getDataEntityType().getName();
|
||||||
|
Long companyId = 0L;
|
||||||
|
if (company == null) {
|
||||||
|
log.info("申请人公司为空,不进行校验");
|
||||||
|
} else {
|
||||||
|
companyId = (Long)company.getPkValue();
|
||||||
|
boolean isImageTemp = SystemParamterUtil.isMapInvoiceCloudImage(companyId);
|
||||||
|
if (isImageTemp) {
|
||||||
|
String configedPrintTemplateFormId = ImageServiceHelper.getConfigedPrintTplFormNumber(bill, mainEntityId, companyId);
|
||||||
|
if (StringUtils.isBlank(configedPrintTemplateFormId)) {
|
||||||
|
this.addErrorMessage(dataEntity, ResManager.loadKDString("未设置单据影像模板,请联系管理员设置!", "TripReimSubmitCheckInvoiceValidator_3", "fi-er-opplugin", new Object[0]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("没有集成发票云影像,不进行校验");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue