Compare commits

...

2 Commits

Author SHA1 Message Date
zhangzhiguo 1531ccff95 费用报销单发票日期和关联申请审核日期校验 2025-09-23 16:20:45 +08:00
zhangzhiguo 8e294bb1d0 差旅报销单发票日期和行程期间校验 2025-09-23 16:20:37 +08:00
2 changed files with 158 additions and 1 deletions

View File

@ -21,7 +21,7 @@ import java.util.List;
import java.util.Map;
/**
* 报销单发票日期和关联申请审核日期校验
* 费用报销单发票日期和关联申请审核日期校验
*/
public class ReimbursementInvoiceDateCkOp extends AbstractOperationServicePlugIn {

View File

@ -0,0 +1,157 @@
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.dataentity.utils.StringUtils;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
/**
* 差旅报销单发票日期和行程期间校验
*/
public class TripreimbursebillIsInvoiceDateCheckOp extends AbstractOperationServicePlugIn {
private static final Logger log = LoggerFactory.getLogger(TripreimbursebillIsInvoiceDateCheckOp.class);
@Override
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
e.getFieldKeys().add("costcompany");//费用承担公司
e.getFieldKeys().add("tripentry");//行程信息分录
e.getFieldKeys().add("startdate");//行程开始时间
e.getFieldKeys().add("enddate");//行程结束时间
e.getFieldKeys().add("invoiceentry");//发票信息
e.getFieldKeys().add("writeoffapply");//关联申请
}
@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() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
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)){
List<String> errorList = new ArrayList<>();
//行程明细会有多个明细
DynamicObjectCollection tripentry = dataEntity.getDynamicObjectCollection("tripentry");
//发票明细
DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry");
DynamicObjectCollection writeoffapply = dataEntity.getDynamicObjectCollection("writeoffapply");//关联的出差申请
Date earliestAuditDate = null;
for (DynamicObject dynamicObject : writeoffapply) {
Date auditDate = dynamicObject.getDate("zcgj_glsq_auditdate");
if (auditDate != null) {
if (earliestAuditDate == null || auditDate.before(earliestAuditDate)) {
earliestAuditDate = auditDate; // 保留最小审批日期
}
}
}
int i= 0;
// 遍历发票明细进行校验
for (DynamicObject invoice : invoiceentry) {
i++;
String invoicetype = invoice.getString("invoicetype");
if("9".equals(invoicetype) || "10".equals(invoicetype)){ // 火车/飞机发票
Date carrierDate = invoice.getDate("carrierdate"); // 乘车日期
// 校验1: 是否在行程时间范围内
boolean inTripRange = false;
for (DynamicObject trip : tripentry) {
Date startDate = trip.getDate("startdate");
Date endDate = trip.getDate("enddate");
if (carrierDate != null && startDate != null && endDate != null) {
if (!carrierDate.before(startDate) && !carrierDate.after(endDate)) {
inTripRange = true;
break;
}
}
}
if (!inTripRange) {
//throw new RuntimeException("乘车日期【" + carrierDate + "】不在任何行程时间范围内!");
this.addFatalErrorMessage(extendedDataEntity, String.format("发票信息中的第%d行乘车/机日期不在任何行程时间范围内!",i));
}
// 校验2: 必须在最早审批日期之后
if (earliestAuditDate != null && carrierDate != null) {
if (carrierDate.before(earliestAuditDate)) {
this.addFatalErrorMessage(extendedDataEntity, String.format("发票信息中的第%d行乘车/机日期早于关联申请最早审批日期!",i));
//throw new RuntimeException("乘车日期【" + carrierDate + "】早于出差申请最早审批日期【" + earliestAuditDate + "】!");
}
}
}
}
/*if(writeoffapply!=null&&writeoffapply.size()==1){
DynamicObject writeoffapplyObj = writeoffapply.get(0);
Date zcgjGlsqAuditdate = writeoffapplyObj.getDate("zcgj_glsq_auditdate");
DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry");
Map<String, LocalDate> invoiceDateMap = new HashMap<>();
for (DynamicObject invoiceentryObject : invoiceentry) {
if (invoiceentryObject.getDate("invoicedate") != null && invoiceentryObject.getString("invoiceno") != null &&
!StringUtils.isEmpty(invoiceentryObject.getString("invoiceno"))) {
invoiceDateMap.put(invoiceentryObject.getString("invoiceno"),dateToLocalDate(invoiceentryObject.getDate("invoicedate")));
}
}
for (String invoiceno : invoiceDateMap.keySet()) {
LocalDate invoiceDate = invoiceDateMap.get(invoiceno);
if (zcgjGlsqAuditdate!=null && invoiceDate.isBefore(dateToLocalDate(zcgjGlsqAuditdate))) {
// System.out.println("date1 比 date2 早");
this.addFatalErrorMessage(extendedDataEntity, String.format("发票号码为:%s的发票开票日期不能早于关联申请的审核时间",invoiceno));
}
}
}*/
}
}
}
}
}
/**
* java.util.Date 转换为 java.time.LocalDate
* @param date java.util.Date
* @return java.time.LocalDate
*/
public static LocalDate dateToLocalDate(Date date) {
return date.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
}
}