延迟报销发票提醒
This commit is contained in:
parent
75e5298a95
commit
5a5733a843
|
@ -0,0 +1,166 @@
|
||||||
|
package zcgj.zcdev.zcdev.fs.plugin.operate;
|
||||||
|
|
||||||
|
import kd.bos.algo.DataSet;
|
||||||
|
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.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.QueryServiceHelper;
|
||||||
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
|
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 费用报销单 发票延迟报销校验
|
||||||
|
*/
|
||||||
|
public class DailInvoiceOverdueRemindersOp extends AbstractOperationServicePlugIn {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||||
|
super.onPreparePropertys(e);
|
||||||
|
e.getFieldKeys().add("invoiceentry");
|
||||||
|
//e.getFieldKeys().add("zcgj_entryentity");
|
||||||
|
e.getFieldKeys().add("zcgj_attachmentcount_cq");
|
||||||
|
e.getFieldKeys().add("zcgj_is_cq");
|
||||||
|
e.getFieldKeys().add("costcompany");
|
||||||
|
e.getFieldKeys().add("expenseentryentity");
|
||||||
|
e.getFieldKeys().add("applier");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 DailInvoiceOverdueRemindersOp.ValidatorExt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ValidatorExt extends AbstractValidator {
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
|
||||||
|
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
|
||||||
|
int i =0;
|
||||||
|
Map<Long, Map<String,Object>> allMap = new HashMap<>();
|
||||||
|
//当前提交的探亲单据id集合
|
||||||
|
Map<Long, List<Long>> currentBillIdListMap = new HashMap<>();
|
||||||
|
//日常费用 FYXM002
|
||||||
|
//业务招待费 FYXM002.007
|
||||||
|
String rcNumber = "FYXM002";
|
||||||
|
|
||||||
|
String rcYwNumber = "FYXM002.007";
|
||||||
|
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");
|
||||||
|
int attachmentcountCq = dataEntity.getInt("zcgj_attachmentcount_cq"); //超期附件数
|
||||||
|
boolean isCq = dataEntity.getBoolean("zcgj_is_cq"); //超期附件数
|
||||||
|
|
||||||
|
if(costcompanyObj!=null){
|
||||||
|
DynamicObject costcompany = (DynamicObject)costcompanyObj;
|
||||||
|
long costcompanyId = costcompany.getLong("id");
|
||||||
|
if(OrgCheckUtils.isKS(costcompanyId)){
|
||||||
|
DynamicObjectCollection expenseentryentity = dataEntity.getDynamicObjectCollection("expenseentryentity");//费用明细
|
||||||
|
//1.判断费用项目中是否有包含日常费用的
|
||||||
|
boolean rc = false;
|
||||||
|
boolean yw = false;
|
||||||
|
for (DynamicObject dynamicObject : expenseentryentity) {
|
||||||
|
DynamicObject expenseitem = dynamicObject.getDynamicObject("expenseitem");
|
||||||
|
if(expenseitem!=null){
|
||||||
|
String itemNumber = expenseitem.getString("number");
|
||||||
|
if(itemNumber.startsWith(rcNumber)){
|
||||||
|
rc = true;
|
||||||
|
if(itemNumber.startsWith(rcYwNumber)){//如果有业务招待费报销
|
||||||
|
yw = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DynamicObject[] load = null;
|
||||||
|
if(yw){//如果是业务招待费报销,则需要判断是不是领导
|
||||||
|
QFilter[] filterArray = new QFilter[2];
|
||||||
|
//查询申请人下的今年的探亲差旅单据
|
||||||
|
filterArray[0] = new QFilter("zcgj_leadership.id", QCP.equals, applierId);
|
||||||
|
filterArray[1] = new QFilter("zcgj_is_latency", QCP.equals, true);
|
||||||
|
load = BusinessDataServiceHelper.load("zcgj_leadership_config",
|
||||||
|
"id",
|
||||||
|
filterArray);
|
||||||
|
/*dateSet = QueryServiceHelper.queryDataSet(
|
||||||
|
this.getClass().getName(),
|
||||||
|
"zcgj_leadership_config",
|
||||||
|
"id",
|
||||||
|
filterArray, null
|
||||||
|
);*/
|
||||||
|
}
|
||||||
|
if((load == null || load.length == 0)&& rc){ //如果不是领导,或领导的延迟报销未开启,则进行延时校验
|
||||||
|
// DynamicObjectCollection entryentity = dataEntity.getDynamicObjectCollection("zcgj_entryentity");//oa流程分录
|
||||||
|
DynamicObjectCollection entryentity = dataEntity.getDynamicObjectCollection("invoiceentry");//发票信息
|
||||||
|
List<LocalDate> dateList = new ArrayList<>();
|
||||||
|
for (DynamicObject dynamicObject : entryentity) {
|
||||||
|
Date invoicedate = dynamicObject.getDate("invoicedate");
|
||||||
|
//Date invoicedate = dynamicObject.getDate("zcgj_invoicedate");
|
||||||
|
if(invoicedate!=null){
|
||||||
|
dateList.add(dateToLocalDate(invoicedate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 找到最大的日期
|
||||||
|
LocalDate maxDate = dateList.stream()
|
||||||
|
.max(LocalDate::compareTo)
|
||||||
|
.orElse(null);
|
||||||
|
if (maxDate != null) {
|
||||||
|
// 获取当前日期
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
// 计算最大日期与当前日期之间的天数差
|
||||||
|
long daysBetween = ChronoUnit.DAYS.between(maxDate, currentDate);
|
||||||
|
// 判断是否超过90天
|
||||||
|
if (daysBetween > 30 &&(
|
||||||
|
!isCq || attachmentcountCq == 0)) {
|
||||||
|
if(yw){ //如果是业务招待,则进行强控
|
||||||
|
this.addFatalErrorMessage(extendedDataEntity, "本次报销已上传最近的发票日期与当前日期相隔超30天,请勾选超期报销,并上传超期说明附件!");
|
||||||
|
}else{//如果是日常费用的其他的项目,则只进行提醒
|
||||||
|
this.addWarningMessage(extendedDataEntity, "请注意:本次报销已上传最近的发票日期与当前日期相隔超30天。");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,131 @@
|
||||||
|
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.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.user.UserServiceHelper;
|
||||||
|
import zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 差旅报销单 发票延迟报销校验
|
||||||
|
*/
|
||||||
|
public class TravelInvoiceOverdueRemindersOp extends AbstractOperationServicePlugIn {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||||
|
super.onPreparePropertys(e);
|
||||||
|
e.getFieldKeys().add("invoiceentry");
|
||||||
|
e.getFieldKeys().add("zcgj_attachmentcount_cq");
|
||||||
|
e.getFieldKeys().add("zcgj_is_cq");
|
||||||
|
e.getFieldKeys().add("costcompany");
|
||||||
|
e.getFieldKeys().add("applier");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 TravelInvoiceOverdueRemindersOp.ValidatorExt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ValidatorExt extends AbstractValidator {
|
||||||
|
@Override
|
||||||
|
public void validate() {
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
|
||||||
|
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
|
||||||
|
int i =0;
|
||||||
|
Map<Long, Map<String,Object>> allMap = new HashMap<>();
|
||||||
|
//当前提交的探亲单据id集合
|
||||||
|
Map<Long, List<Long>> currentBillIdListMap = new HashMap<>();
|
||||||
|
|
||||||
|
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
||||||
|
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
||||||
|
long aLong = dataEntity.getLong("id");
|
||||||
|
Object costcompanyObj = dataEntity.get("costcompany");
|
||||||
|
int attachmentcountCq = dataEntity.getInt("zcgj_attachmentcount_cq"); //超期附件数
|
||||||
|
boolean isCq = dataEntity.getBoolean("zcgj_is_cq"); //超期附件数
|
||||||
|
|
||||||
|
if(costcompanyObj!=null){
|
||||||
|
DynamicObject costcompany = (DynamicObject)costcompanyObj;
|
||||||
|
long costcompanyId = costcompany.getLong("id");
|
||||||
|
if(OrgCheckUtils.isKS(costcompanyId)){
|
||||||
|
//获取报销人
|
||||||
|
DynamicObject applier = dataEntity.getDynamicObject("applier");
|
||||||
|
long applierId = applier.getLong("id");
|
||||||
|
QFilter[] filterArray = new QFilter[2];
|
||||||
|
//查询申请人下的今年的探亲差旅单据
|
||||||
|
filterArray[0] = new QFilter("zcgj_leadership.id", QCP.equals, applierId);
|
||||||
|
filterArray[1] = new QFilter("zcgj_is_latency", QCP.equals, true);
|
||||||
|
DynamicObject[] load = BusinessDataServiceHelper.load("zcgj_leadership_config",
|
||||||
|
"id",
|
||||||
|
filterArray);
|
||||||
|
|
||||||
|
if(load != null && load.length > 0){
|
||||||
|
DynamicObjectCollection entryentity = dataEntity.getDynamicObjectCollection("invoiceentry");//发票信息
|
||||||
|
List<LocalDate> dateList = new ArrayList<>();
|
||||||
|
for (DynamicObject dynamicObject : entryentity) {
|
||||||
|
Date invoicedate = dynamicObject.getDate("invoicedate");
|
||||||
|
if(invoicedate!=null){
|
||||||
|
dateList.add(dateToLocalDate(invoicedate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 找到最大的日期
|
||||||
|
LocalDate maxDate = dateList.stream()
|
||||||
|
.max(LocalDate::compareTo)
|
||||||
|
.orElse(null);
|
||||||
|
if (maxDate != null) {
|
||||||
|
// 获取当前日期
|
||||||
|
LocalDate currentDate = LocalDate.now();
|
||||||
|
|
||||||
|
// 计算最大日期与当前日期之间的时间差
|
||||||
|
//Period period = Period.between(maxDate, currentDate);
|
||||||
|
|
||||||
|
// 计算最大日期与当前日期之间的天数差
|
||||||
|
long daysBetween = ChronoUnit.DAYS.between(maxDate, currentDate);
|
||||||
|
// 判断是否超过90天
|
||||||
|
if (daysBetween > 30 &&(
|
||||||
|
!isCq || attachmentcountCq == 0)) {
|
||||||
|
this.addFatalErrorMessage(extendedDataEntity, "最近发票日期与当前日期相隔超30天,请勾选超期报销,并上传超期说明附件!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue