费用报销单、差旅报销单、对公报销单提交操作插件:开票日期与当前日期的对比校验逻辑
This commit is contained in:
parent
5c4d04271f
commit
846145ee2f
|
@ -0,0 +1,106 @@
|
|||
package zcgj.zcdev.zcdev.fs.plugin.operate;
|
||||
|
||||
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 zcgj.zcdev.zcdev.fs.utils.OrgCheckUtils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 使用单据:费用报销单、差旅报销单、对公报销单提交操作插件
|
||||
* 校验逻辑:开票日期与当前日期的对比校验
|
||||
*/
|
||||
public class InvoiceDateValidatorSubOp extends AbstractOperationServicePlugIn {
|
||||
@Override
|
||||
public void onPreparePropertys(PreparePropertysEventArgs e) {
|
||||
super.onPreparePropertys(e);
|
||||
e.getFieldKeys().add("costcompany");//费用承担公司
|
||||
e.getFieldKeys().add("zcgj_invoiceremark");//特殊说明
|
||||
e.getFieldKeys().add("invoiceentry");//发票信息分录
|
||||
e.getFieldKeys().add("invoicedate");//开票日期
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddValidators(AddValidatorsEventArgs e) {
|
||||
super.onAddValidators(e);
|
||||
e.getValidators().add(new ValidatorExt());
|
||||
}
|
||||
|
||||
static class ValidatorExt extends AbstractValidator {
|
||||
@Override
|
||||
public void validate() {
|
||||
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
|
||||
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
|
||||
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
|
||||
DynamicObject costCompany = dataEntity.getDynamicObject("costcompany");//费用承担公司
|
||||
if (costCompany != null) {
|
||||
Long companyId = costCompany.getLong("id");
|
||||
if (OrgCheckUtils.isKS(companyId)) {
|
||||
//仅针对矿山下组织下的逻辑
|
||||
String invoiceRemark = dataEntity.getString("zcgj_invoiceremark");//特殊说明
|
||||
DynamicObjectCollection invoiceEntryCollection = dataEntity.getDynamicObjectCollection("invoiceentry");//发票信息分录
|
||||
if (invoiceEntryCollection.size() > 0) {
|
||||
//存在发票分录时才进行下列校验
|
||||
for (int i = 0; i < invoiceEntryCollection.size(); i++) {
|
||||
DynamicObject invoiceEntry = invoiceEntryCollection.get(i);
|
||||
int i1 = i + 1;
|
||||
Date currentDate = new Date();//当前日期
|
||||
Date invoiceDate = invoiceEntry.getDate("invoicedate");//开票日期
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
Date currentDateFormat = sdf.parse(sdf.format(currentDate));//当前日期
|
||||
Date invoiceDateFormat = sdf.parse(sdf.format(invoiceDate));//开票日期
|
||||
|
||||
// 校验1: 开票日期不能大于当前日期
|
||||
if (invoiceDate.after(currentDateFormat)) {
|
||||
this.addFatalErrorMessage(extendedDataEntity, "第" + i1 + "行,开票日期大于当前日期!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验2: 当前日期减去开票日期不能大于30天
|
||||
long diffInMillies = Math.abs(currentDateFormat.getTime() - invoiceDateFormat.getTime());
|
||||
long diffInDays = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
|
||||
// 校验3:如果发票是去年12月开具,且当前是今年1月31日前,则视为合规
|
||||
boolean isSpecialCase = false;
|
||||
java.util.Calendar currentCal = java.util.Calendar.getInstance();
|
||||
currentCal.setTime(currentDate);
|
||||
int currentYear = currentCal.get(java.util.Calendar.YEAR);//当前年份
|
||||
int currentMonth = currentCal.get(java.util.Calendar.MONTH);//当前月份
|
||||
int currentDay = currentCal.get(java.util.Calendar.DAY_OF_MONTH);//当前日期
|
||||
java.util.Calendar invoiceCal = java.util.Calendar.getInstance();
|
||||
invoiceCal.setTime(invoiceDate);
|
||||
int invoiceYear = invoiceCal.get(java.util.Calendar.YEAR);//发票年份
|
||||
int invoiceMonth = invoiceCal.get(java.util.Calendar.MONTH);//发票月份
|
||||
// 判断是否为特殊情况:发票为去年12月,当前为今年1月且日期<=31日的视为合理
|
||||
if (currentYear - invoiceYear == 1 &&
|
||||
invoiceMonth == java.util.Calendar.DECEMBER &&
|
||||
currentMonth == java.util.Calendar.JANUARY &&
|
||||
currentDay <= 31) {
|
||||
isSpecialCase = true;
|
||||
}
|
||||
|
||||
// 最终校验:当前日期减去开票日期不能大于30天且不是特殊情况且特殊说明为空时,则视为不合规
|
||||
if (diffInDays > 30 && !isSpecialCase && "".equals(invoiceRemark)) {
|
||||
this.addFatalErrorMessage(extendedDataEntity, "第" + i1 + "行,发票开具日期至当前报销日的间隔时间,不得超过一个月(30天)。必须填写特殊说明才能提交!");
|
||||
return;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue