|
@@ -1,4 +1,78 @@
|
|
|
package fi.em.opplugin;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
|
|
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
|
|
|
+import kd.bos.exception.KDBizException;
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
+import kd.bos.servicehelper.AttachmentServiceHelper;
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
//差旅费用报销单
|
|
|
-public class TravelExpensesOpPlugin {
|
|
|
+public class TravelExpensesOpPlugin extends AbstractOperationServicePlugIn {
|
|
|
+ private static String nckd_orgamount = "nckd_orgamount"; //组织金额标识
|
|
|
+ private static String attachmentpanel = "attachmentpanel";//附件标识
|
|
|
+ private static String er_tripreimbill_grid = "er_tripreimbill_grid";//差旅报销单标识
|
|
|
+ @Override
|
|
|
+ public void beginOperationTransaction(BeginOperationTransactionArgs e) {
|
|
|
+ //获取当前操作单据数组
|
|
|
+ DynamicObject[] dynamicObjects = e.getDataEntities();
|
|
|
+ for (int i = 0; i < dynamicObjects.length; i++) {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ //当前单头数据包
|
|
|
+ DynamicObject info = BusinessDataServiceHelper.loadSingle(dynamicObjects[i].getPkValue(), dynamicObjects[i].getDynamicObjectType().getName());
|
|
|
+ String billno = info.getString("billno");//报销单编号
|
|
|
+ //获取费用承担公司
|
|
|
+ DynamicObject costcompany = info.getDynamicObject("costcompany");
|
|
|
+ //公司编码
|
|
|
+ String number = costcompany.getString("number");
|
|
|
+ //公司id
|
|
|
+ long id = costcompany.getLong("id");
|
|
|
+ //循环费用明细分录
|
|
|
+ for (DynamicObject entryentity : info.getDynamicObjectCollection("expenseentryentity")) {
|
|
|
+ //取当前循环费用明细分录的报销金额
|
|
|
+ BigDecimal expenseamount = entryentity.getBigDecimal("expenseamount");
|
|
|
+ //金额标准查询条件
|
|
|
+ QFilter nckd_orgamountFilter = new QFilter("nckd_orgfield.number", QCP.equals,number);
|
|
|
+ nckd_orgamountFilter.and("nckd_combofield", QCP.equals,"B");
|
|
|
+ DynamicObject[] nckd_orgamountaccount = BusinessDataServiceHelper.load(nckd_orgamount,"id,nckd_orgfield,nckd_combofield",new QFilter[] {nckd_orgamountFilter});
|
|
|
+ //判断组织是否维护金额,没有则查询集团金额
|
|
|
+ if(nckd_orgamountaccount.length == 0){
|
|
|
+ nckd_orgamountFilter = new QFilter("nckd_orgfield.number", QCP.equals,"jxyh");
|
|
|
+ nckd_orgamountFilter.and("nckd_combofield", QCP.equals,"B");
|
|
|
+ nckd_orgamountaccount = BusinessDataServiceHelper.load(nckd_orgamount,"id,nckd_orgfield,nckd_combofield",new QFilter[] {nckd_orgamountFilter});
|
|
|
+ }
|
|
|
+ //循环数组获取组织金额标准数据包 默认取组织,没有取集团
|
|
|
+ for (int c=0;c<nckd_orgamountaccount.length;c++){
|
|
|
+ //组织金额标准数据包
|
|
|
+ DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(nckd_orgamountaccount[i].getPkValue(), nckd_orgamountaccount[i].getDynamicObjectType().getName());
|
|
|
+ //获取标准金额
|
|
|
+ BigDecimal nckdAmountfield = dynamicObject.getBigDecimal("nckd_amountfield");
|
|
|
+ //判断报销金额大于标准金额
|
|
|
+ if(expenseamount.compareTo(nckdAmountfield) == 1){
|
|
|
+ //获取单据信息,并查询单据中的附件字段
|
|
|
+ DynamicObject file =BusinessDataServiceHelper.loadSingle(er_tripreimbill_grid,attachmentpanel,new QFilter[]{new QFilter("billno", QFilter.equals, billno)});
|
|
|
+ //获取单据中附件面板信息
|
|
|
+ List<Map<String,Object>> atts= AttachmentServiceHelper.getAttachments(er_tripreimbill_grid,file.getPkValue().toString(),attachmentpanel);
|
|
|
+ boolean ispass=true;
|
|
|
+ //如关联申请页签为空或关联合同页签为空或者附件为空,则在提交时进行提醒:“请关联申请,或者关联合同,或者上传附件进行报销”。
|
|
|
+ if(atts.isEmpty()){ispass=false;}
|
|
|
+ DynamicObject contractentry = info.getDynamicObject("contractentry");
|
|
|
+ if(contractentry == null){ispass=false;}
|
|
|
+ DynamicObject writeoffapply = info.getDynamicObject("writeoffapply");
|
|
|
+ if(writeoffapply == null){ispass=false;}
|
|
|
+ if(ispass){}else{throw new KDBizException("请关联申请,或者关联合同,或者上传附件进行报销!");};
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|