3 Commits 6436d46bcd ... 407f9fb3e6

Autore SHA1 Messaggio Data
  zhangtao 407f9fb3e6 Merge remote-tracking branch 'origin/master' 1 settimana fa
  zhangtao 8020b37f7b Merge remote-tracking branch 'origin/master' 1 settimana fa
  zhangtao 38a3ff2cc2 费用报销单:与申请单比较费用发生日期校验 1 settimana fa

+ 84 - 0
code/fi/nckd-xtpoc-fi/src/main/java/nckd/xtpoc/fi/app/plugin/validate/DailyReimBurseBillValidator.java

@@ -6,14 +6,18 @@ import kd.bos.entity.ExtendedDataEntity;
 import kd.bos.entity.validate.AbstractValidator;
 import kd.bos.orm.query.QCP;
 import kd.bos.orm.query.QFilter;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
 import kd.bos.servicehelper.QueryServiceHelper;
 import org.apache.commons.lang3.ObjectUtils;
 
+import java.util.Calendar;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
+
 /**
  * Tyx 费用报销单+付款单校验器
  */
@@ -36,9 +40,89 @@ public class DailyReimBurseBillValidator extends AbstractValidator {
                 String msg = "费用明细的供应商或车牌号与关联申请单不一致,不允许" + this.getOperationName();
                 this.addErrorMessage(dataEntity, msg);
             }
+
+            //判断申请单发生日期与本单发生日期是否一致
+            checkDateDiff(dataEntity, bill);
         }
     }
 
+    /**
+     * 检查报销单与申请单之间的日期差异
+     * @param dataEntity 扩展数据实体
+     * @param bill 动态对象,包含报销单信息
+     */
+    private void checkDateDiff(ExtendedDataEntity dataEntity, DynamicObject bill) {
+        //附件数
+        int attachmentCount = bill.getInt("attachmentcount");
+        //费用分录
+        DynamicObjectCollection expenseEntryEntity = bill.getDynamicObjectCollection("expenseentryentity");
+        if (expenseEntryEntity.isEmpty()) {
+            return;
+        }
+        //关联申请分录
+        DynamicObjectCollection writeOffApply = bill.getDynamicObjectCollection("writeoffapply");
+        if (writeOffApply.isEmpty()) {
+            return;
+        }
+        List<Long> sourceApplyBillId = writeOffApply.stream()
+                .map(e -> Long.valueOf(e.getString("sourceapplybillid")))
+                .collect(Collectors.toList());
+        //根据申请单id查询申请单
+        Map<Object, DynamicObject> erDailyApplyMap = BusinessDataServiceHelper.loadFromCache(sourceApplyBillId.toArray(new Long[0]), "er_dailyapplybil");
+
+
+        for (DynamicObject entry : expenseEntryEntity) {
+            Date entryDate = entry.getDate("happendate");
+            if(entryDate == null) {
+                continue;
+            }
+            //费用项目字段
+            String expenseItem = entry.getString("expenseitem.number");
+
+            //遍历查询关联申请分录
+            for (DynamicObject apply : writeOffApply) {
+                String expenseApply = apply.getString("expenseitemfield.number");
+                long sourceEntryId = apply.getLong("sourceapplyentryid");
+                Long sourceBillId = apply.getLong("sourceapplybillid");
+
+                //分录对象
+                List<DynamicObject> entryApply = erDailyApplyMap.get(sourceBillId)
+                        .getDynamicObjectCollection("expenseentryentity")
+                        .stream()
+                        .filter(e -> e.getLong("id") == sourceEntryId)
+                        .collect(Collectors.toList());
+                if(entryApply.isEmpty()) {
+                   continue;
+                }
+
+                //费用项目相同的分录比较
+                if(expenseApply.equals(expenseItem)) {
+                    Date applyDate = entryApply.get(0).getDate("happendate");
+                    if (applyDate == null) {
+                        continue;
+                    }
+                    //发生时间不同,并且附件数为0情况下
+                    if (!isSameDate(entryDate, applyDate) && attachmentCount == 0) {
+                        String msg = "报销单时间不等于申请单费用发生时间,请进行确认,并上传附件说明。";
+                        this.addErrorMessage(dataEntity, msg);
+                    }
+                }
+            }
+        }
+    }
+
+    private boolean isSameDate(Date date1, Date date2) {
+        if (date1 == null || date2 == null) return false;
+
+        Calendar cal1 = Calendar.getInstance();
+        cal1.setTime(date1);
+        Calendar cal2 = Calendar.getInstance();
+        cal2.setTime(date2);
+
+        return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
+                cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) &&
+                cal1.get(Calendar.DAY_OF_MONTH) == cal2.get(Calendar.DAY_OF_MONTH);
+    }
 
     /**
      * 根据时间判断是否存在关账的账期管理