|
@@ -12,11 +12,14 @@ import kd.bos.orm.query.QCP;
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
import kd.fi.er.business.utils.ErCommonUtils;
|
|
|
+import kd.fi.er.business.utils.ReimburseUpAppQfilterUtil;
|
|
|
import kd.fi.er.formplugin.botp.up.PublicReimburseBotpUpPlugin;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import kd.fi.er.formplugin.botp.up.service.BotpDrawServiceStdImpl;
|
|
|
+import kd.fi.er.formplugin.botp.up.service.IBotpDrawService;
|
|
|
+import kd.fi.er.formplugin.botp.up.service.ValidBillArg;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -34,25 +37,28 @@ public class ErDailyReimburseExtBotpUpPlugin extends PublicReimburseBotpUpPlugin
|
|
|
if("addapplycheck".equals(opKey)) {
|
|
|
DynamicObject item = (DynamicObject) this.getModel().getValue("nckd_expenseitem");
|
|
|
String fieldKey = "";
|
|
|
+ String fieldName = "";
|
|
|
|
|
|
if (item == null) {
|
|
|
this.getView().showTipNotification(ResManager.loadKDString("请先选择费用类型。", "PublicReimburseBotpUpPlugin_0", "fi-er-formplugin", new Object[0]));
|
|
|
args.setCancel(true);
|
|
|
- } else if (checkProject(item, fieldKey)) {
|
|
|
+ } else if (checkProject(item)) {
|
|
|
//item = BusinessDataServiceHelper.loadSingle(item.getPkValue(), item.getDynamicObjectType().getName());
|
|
|
String pjtype = item.getString("nckd_pjtype");
|
|
|
|
|
|
//标准项目
|
|
|
if ("project".equals(pjtype)) {
|
|
|
fieldKey = "nckd_project";
|
|
|
+ fieldName = "项目";
|
|
|
}
|
|
|
//核算项目
|
|
|
else if ("acctitem".equals(pjtype)) {
|
|
|
fieldKey = "nckd_acctitem";
|
|
|
+ fieldName = "核算项目";
|
|
|
}
|
|
|
|
|
|
if (this.getModel().getValue(fieldKey) == null) {
|
|
|
- this.getView().showTipNotification(ResManager.loadKDString("请先选择项目。", "PublicReimburseBotpUpPlugin_0", "fi-er-formplugin", new Object[0]));
|
|
|
+ this.getView().showTipNotification(ResManager.loadKDString("请先选择" + fieldName + "。", "PublicReimburseBotpUpPlugin_0", "fi-er-formplugin", new Object[0]));
|
|
|
args.setCancel(true);
|
|
|
} else {
|
|
|
super.beforeDoOperation(args);
|
|
@@ -69,7 +75,7 @@ public class ErDailyReimburseExtBotpUpPlugin extends PublicReimburseBotpUpPlugin
|
|
|
* 判断是否需要校验项目/核算项目必填
|
|
|
* @return
|
|
|
*/
|
|
|
- private boolean checkProject(DynamicObject item, String fieldKey){
|
|
|
+ private boolean checkProject(DynamicObject item){
|
|
|
boolean needCheck = false;
|
|
|
DynamicObject company = null;
|
|
|
if (this.getControl("company") != null) {
|
|
@@ -99,51 +105,33 @@ public class ErDailyReimburseExtBotpUpPlugin extends PublicReimburseBotpUpPlugin
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * @param includeApplierAndProjectOwer
|
|
|
- * @return
|
|
|
+ * 增加扩展过滤条件
|
|
|
+ * @param sFilter
|
|
|
*/
|
|
|
- @Override
|
|
|
- protected Object getBillList(boolean includeApplierAndProjectOwer) {
|
|
|
- Object billlists = super.getBillList(includeApplierAndProjectOwer);
|
|
|
-
|
|
|
- List<Map<String, Object>> billlists1 = (List<Map<String, Object>>) billlists;
|
|
|
- List<String> billNoList = new ArrayList<>();
|
|
|
-
|
|
|
- String entityName = "";
|
|
|
- for(Map<String, Object> map : billlists1){
|
|
|
- entityName = (String)map.get("formtype");
|
|
|
- billNoList.add((String)map.get("billno"));
|
|
|
- }
|
|
|
-
|
|
|
- if("er_dailyapplybill".equals(entityName)) {
|
|
|
- DynamicObjectCollection collection = (DynamicObjectCollection)this.getModel().getValue("nckd_payviewtypemul");
|
|
|
- List<Long> idList = (List)collection.stream().mapToLong((x) -> {
|
|
|
- return x.getLong("fbasedataid_id");
|
|
|
- }).boxed().collect(Collectors.toList());
|
|
|
-
|
|
|
- QFilter viewTypeFilter = new QFilter("nckd_payviewtype.id", QCP.in, idList);
|
|
|
+ private void addExtendFilter(QFilter sFilter){
|
|
|
+ DynamicObjectCollection collection = (DynamicObjectCollection)this.getModel().getValue("nckd_payviewtypemul");
|
|
|
+ List<Long> idList = (List)collection.stream().mapToLong((x) -> {
|
|
|
+ return x.getLong("fbasedataid_id");
|
|
|
+ }).boxed().collect(Collectors.toList());
|
|
|
|
|
|
- DynamicObject[] items = BusinessDataServiceHelper.load("er_expenseitemedit", "id", viewTypeFilter.toArray());
|
|
|
+ QFilter viewTypeFilter = new QFilter("nckd_payviewtype.id", QCP.in, idList);
|
|
|
|
|
|
- List<Long> itemIds = (List) Arrays.stream(items).map((o) -> {
|
|
|
- return o.getLong("id");
|
|
|
- }).collect(Collectors.toList());
|
|
|
+ DynamicObject[] items = BusinessDataServiceHelper.load("er_expenseitemedit", "id", viewTypeFilter.toArray());
|
|
|
|
|
|
- QFilter qFilter = new QFilter("billno", QCP.in, billNoList);
|
|
|
- String selectFileds = "billno, nckd_expenseitem, nckd_project, nckd_acctitem, nckd_isrelapj, nckd_payviewtypemul";
|
|
|
+ List<Long> itemIds = (List) Arrays.stream(items).map((o) -> {
|
|
|
+ return o.getLong("id");
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
|
- List<String> removeApplys = new ArrayList<>();
|
|
|
- DynamicObject[] applys = BusinessDataServiceHelper.load(entityName, selectFileds, qFilter.toArray());
|
|
|
+ //费用类型过滤
|
|
|
+ sFilter.and(new QFilter("nckd_expenseitem.id", QCP.in, itemIds));
|
|
|
|
|
|
- log.info("itemIds:" + itemIds.toString());
|
|
|
-
|
|
|
- DynamicObject item = (DynamicObject) this.getModel().getValue("nckd_expenseitem");
|
|
|
- String fieldKey = "";
|
|
|
- boolean checkProject = checkProject(item, fieldKey);
|
|
|
+ DynamicObject item = (DynamicObject) this.getModel().getValue("nckd_expenseitem");
|
|
|
+ boolean checkProject = checkProject(item);
|
|
|
|
|
|
+ if(checkProject) {
|
|
|
String pjtype = item.getString("nckd_pjtype");
|
|
|
|
|
|
+ String fieldKey = "";
|
|
|
//标准项目
|
|
|
if ("project".equals(pjtype)) {
|
|
|
fieldKey = "nckd_project";
|
|
@@ -153,50 +141,98 @@ public class ErDailyReimburseExtBotpUpPlugin extends PublicReimburseBotpUpPlugin
|
|
|
fieldKey = "nckd_acctitem";
|
|
|
}
|
|
|
|
|
|
- Long curProjectId = 0L;
|
|
|
- if(checkProject) {
|
|
|
- curProjectId = ((DynamicObject) this.getModel().getValue(fieldKey)).getLong("id");
|
|
|
- }
|
|
|
+ Long curProjectId = ((DynamicObject) this.getModel().getValue(fieldKey)).getLong("id");
|
|
|
+ //项目/核算项目过滤
|
|
|
+ sFilter.and(new QFilter(fieldKey + ".id", QCP.equals, curProjectId));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- for(DynamicObject apply : applys){
|
|
|
- boolean needRemove = false;
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param includeApplierAndProjectOwer
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ protected Object getBillList(boolean includeApplierAndProjectOwer) {
|
|
|
+ IBotpDrawService drawService = new BotpDrawServiceStdImpl(this.getModel(), this.getView());
|
|
|
+ String selectFieds = "id as billid,billno,applier,org,company,description,bizdate,expenseentryentity.expenseitem as expenseitem,expenseentryentity.entrycurrency as entrycurrency,expenseentryentity.exchangerate as exchangerate,expenseentryentity.orgiexpebalanceamount as orgiexpebalanceamount,expenseentryentity.expebalanceamount as expebalanceamount,expenseentryentity.id as entryid,expenseentryentity.entrycostdept as costdept,expenseentryentity.std_entrycostcenter as costcenter,expenseentryentity.entrycostcompany as costcompany";
|
|
|
+
|
|
|
+ //增加扩展字段
|
|
|
+ selectFieds += ", nckd_project, nckd_acctitem";
|
|
|
+
|
|
|
+ QFilter qFilter = new QFilter("billstatus", "=", "E");
|
|
|
+ qFilter.and(new QFilter("expenseentryentity.orgiexpebalanceamount", ">", BigDecimal.ZERO));
|
|
|
+ switch (ErCommonUtils.getEMParameter(this.getCompany(), "relatapplybillfilterrange").toString()) {
|
|
|
+ case "0":
|
|
|
+ if (includeApplierAndProjectOwer) {
|
|
|
+ qFilter.and((new QFilter("applier", "=", this.getApplier())).or("projectower.FBASEDATAID_id", "in", Collections.singletonList(this.getApplier())));
|
|
|
+ } else {
|
|
|
+ qFilter.and(new QFilter("applier", "=", this.getApplier()));
|
|
|
+ }
|
|
|
|
|
|
- Long itemId = apply.getDynamicObject("nckd_expenseitem").getLong("id");
|
|
|
+ qFilter.and(new QFilter("company", "=", this.getCompany()));
|
|
|
+ break;
|
|
|
+ case "1":
|
|
|
+ qFilter.and(new QFilter("org", "=", this.getDept()));
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ qFilter.and(new QFilter("company", "=", this.getCompany()));
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ if (includeApplierAndProjectOwer) {
|
|
|
+ qFilter.and((new QFilter("applier", "=", this.getApplier())).or("projectower.FBASEDATAID_id", "in", Collections.singletonList(this.getApplier())));
|
|
|
+ } else {
|
|
|
+ qFilter.and(new QFilter("applier", "=", this.getApplier()));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- log.info("itemId:" + itemId + "; billno:" + apply.getString("billno"));
|
|
|
+ qFilter.and(new QFilter("currency", "=", ErCommonUtils.getPk(this.getModel().getValue("currency"))));
|
|
|
+ Long currency;
|
|
|
+ if (this.getModel().getDataEntity().getDynamicObjectType().getProperties().containsKey("currency")) {
|
|
|
+ currency = ErCommonUtils.getPk(this.getView().getModel().getValue("currency"));
|
|
|
+ if (currency != null) {
|
|
|
+ qFilter.and(new QFilter("currency", "=", currency));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //过滤费用项目
|
|
|
- if(!itemIds.contains(itemId)){
|
|
|
- needRemove = true;
|
|
|
- }
|
|
|
+ currency = null;
|
|
|
+ if (this.getView().getModel().getProperty("reimbursetype") != null) {
|
|
|
+ String reimbursetype = (String)this.getModel().getValue("reimbursetype");
|
|
|
+ QFilter reimbursetypeQfilter;
|
|
|
+ if (!"expense".equals(reimbursetype) && !" ".equals(reimbursetype) && !"asset".equals(reimbursetype) && reimbursetype != null) {
|
|
|
+ reimbursetypeQfilter = new QFilter("reimbursetype", "=", this.getModel().getValue("reimbursetype"));
|
|
|
+ } else {
|
|
|
+ reimbursetypeQfilter = (new QFilter("reimbursetype", "=", "expense")).or("reimbursetype", "=", " ").or("reimbursetype", "=", "otherexpenses").or("reimbursetype", "=", (Object)null);
|
|
|
+ }
|
|
|
|
|
|
- //过滤项目/核算项目
|
|
|
- if(checkProject){
|
|
|
- Long projectid = apply.getDynamicObject(fieldKey) == null ? 0L : apply.getDynamicObject(fieldKey).getLong("id");
|
|
|
+ qFilter = ReimburseUpAppQfilterUtil.setBizitemFilter(this.getModel(), qFilter, reimbursetypeQfilter);
|
|
|
+ qFilter.and(reimbursetypeQfilter);
|
|
|
+ }
|
|
|
|
|
|
- if( projectid > 0 && curProjectId > 0 && projectid.compareTo(curProjectId) != 0) {
|
|
|
- needRemove = true;
|
|
|
- }
|
|
|
- }
|
|
|
+ //增加扩展过滤
|
|
|
+ addExtendFilter(qFilter);
|
|
|
|
|
|
- if(needRemove){
|
|
|
- removeApplys.add(apply.getString("billno"));
|
|
|
- }
|
|
|
- }
|
|
|
+ ValidBillArg arg = new ValidBillArg("er_dailyapplybill", selectFieds, new QFilter[]{qFilter});
|
|
|
+ return drawService.getValidBills(this.getExistPks(), new ValidBillArg[]{arg});
|
|
|
|
|
|
- log.info("removeApplys:" + removeApplys.toString());
|
|
|
|
|
|
- for(int i = billlists1.size()-1; i >= 0; i--){
|
|
|
- Map<String, Object> map = billlists1.get(i);
|
|
|
- String billno = (String)map.get("billno");
|
|
|
+ }
|
|
|
|
|
|
- if(removeApplys.contains(billno)){
|
|
|
- ((List<?>) billlists).remove(i);
|
|
|
- }
|
|
|
+ private Map<Long, List<Long>> getExistPks() {
|
|
|
+ Map<Long, List<Long>> result = new HashMap<Long, List<Long>>();
|
|
|
+ DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("writeoffapply");
|
|
|
+ if (entryEntity == null || entryEntity.size() < 1) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ for (DynamicObject row : entryEntity) {
|
|
|
+ long sourcebillid = row.getLong("sourceapplybillid");
|
|
|
+ List<Long> entryIds = result.get(sourcebillid);
|
|
|
+ if (entryIds == null) {
|
|
|
+ entryIds = new ArrayList<Long>();
|
|
|
+ result.put(sourcebillid, entryIds);
|
|
|
}
|
|
|
+ entryIds.add(row.getLong("sourceapplyentryid"));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- return billlists;
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|