TripReqSectionEx.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. package kd.fi.er.formplugin.mobile;
  2. import java.math.BigDecimal;
  3. import java.time.LocalDate;
  4. import java.util.Date;
  5. import java.util.EventObject;
  6. import java.util.Iterator;
  7. import java.util.Map;
  8. import java.util.Objects;
  9. import java.util.TreeMap;
  10. import kd.bos.bill.AbstractMobBillPlugIn;
  11. import kd.bos.dataentity.entity.DynamicObject;
  12. import kd.bos.dataentity.entity.DynamicObjectCollection;
  13. import kd.bos.dataentity.resource.ResManager;
  14. import kd.bos.entity.cache.RedisModelCache;
  15. import kd.bos.entity.datamodel.IDataModel;
  16. import kd.bos.entity.datamodel.IRefrencedataProvider;
  17. import kd.bos.entity.datamodel.ListSelectedRowCollection;
  18. import kd.bos.entity.datamodel.events.AfterDeleteRowEventArgs;
  19. import kd.bos.entity.datamodel.events.ChangeData;
  20. import kd.bos.entity.datamodel.events.PropertyChangedArgs;
  21. import kd.bos.form.ConfirmCallBackListener;
  22. import kd.bos.form.FormShowParameter;
  23. import kd.bos.form.IFormView;
  24. import kd.bos.form.IMobileView;
  25. import kd.bos.form.MessageBoxOptions;
  26. import kd.bos.form.MessageBoxResult;
  27. import kd.bos.form.cardentry.CardEntry;
  28. import kd.bos.form.control.Control;
  29. import kd.bos.form.control.events.ClickListener;
  30. import kd.bos.form.events.AfterDoOperationEventArgs;
  31. import kd.bos.form.events.BeforeClosedEvent;
  32. import kd.bos.form.events.ClosedCallBackEvent;
  33. import kd.bos.form.events.MessageBoxClosedEvent;
  34. import kd.bos.form.field.DateTimeEdit;
  35. import kd.bos.form.field.FieldEdit;
  36. import kd.bos.form.field.MulBasedataEdit;
  37. import kd.fi.er.business.servicehelper.CommonServiceHelper;
  38. import kd.fi.er.business.utils.AmountUtils;
  39. import kd.fi.er.business.utils.ErCommonUtils;
  40. import kd.fi.er.business.utils.ErStdConfig;
  41. import kd.fi.er.business.utils.SystemParamterUtil;
  42. import kd.fi.er.business.utils.TripBillTravelerUtils;
  43. import kd.fi.er.common.ShowPageUtils;
  44. import kd.fi.er.formplugin.budget.BudgetCommonUtil;
  45. import org.apache.commons.lang.StringUtils;
  46. import org.apache.commons.lang3.ObjectUtils;
  47. public class TripReqSectionEx extends AbstractMobBillPlugIn implements ClickListener {
  48. public TripReqSectionEx() {
  49. }
  50. public void registerListener(EventObject e) {
  51. this.addClickListeners(new String[]{"btn_save", "btn_addsection"});
  52. IFormView view = this.getView();
  53. MulBasedataEdit travelersF7 = (MulBasedataEdit)this.getControl("travelers");
  54. DynamicObject company = (DynamicObject)view.getParentView().getModel().getValue("company");
  55. DynamicObject org = (DynamicObject)view.getParentView().getModel().getValue("org");
  56. TripBillTravelerUtils.getF7FilterInfo(company, org, travelersF7);
  57. }
  58. public void afterCreateNewData(EventObject e) {
  59. super.afterCreateNewData(e);
  60. FormShowParameter param = this.getView().getFormShowParameter();
  61. IDataModel model = this.getModel();
  62. IFormView parentView = this.getView().getParentView();
  63. IDataModel parentModel = parentView.getModel();
  64. model.setValue("currency", ErCommonUtils.getPk(parentModel.getValue("currency")));
  65. model.setValue("billstatus", parentModel.getValue("billstatus"));
  66. CoreBaseBillEdit coreBaseBillEdit = new CoreBaseBillEdit();
  67. Boolean isCurrency = coreBaseBillEdit.refreshIsCurrency(parentModel);
  68. model.setValue("iscurrency", isCurrency);
  69. model.setValue("istravelers", parentModel.getValue("istravelers"));
  70. model.setValue("isloan", parentModel.getValue("isloan"));
  71. model.setValue("ismulwayto", parentModel.getValue("ismulwayto"));
  72. model.setValue("bizdate", parentModel.getValue("bizdate"));
  73. CommonServiceHelper.setMulWayToVisible(parentModel, this.getView());
  74. if (param.getCustomParam("entryedit") != null) {
  75. this.getView().setVisible(false, new String[]{"btn_addsection"});
  76. int index = (Integer)param.getCustomParam("index");
  77. DynamicObject dobject = parentModel.getEntryRowEntity("tripentry", index);
  78. DynamicObjectCollection dc = model.getEntryEntity("tripentry");
  79. dc.add(dobject);
  80. model.setValue("index", index + 1, 0);
  81. } else {
  82. Long cityId = ((IMobileView)this.getView()).getCurrentCityId();
  83. int rowIndex = model.createNewEntryRow("tripentry");
  84. Object to = param.getCustomParam("to");
  85. Object date = param.getCustomParam("enddate");
  86. if (null != to) {
  87. cityId = Long.valueOf(to.toString());
  88. }
  89. if (null != date) {
  90. model.setValue("startdate", date, 0);
  91. }
  92. model.setValue("from", cityId, 0);
  93. int count = parentModel.getEntryRowCount("tripentry");
  94. model.setValue("index", count + 1, rowIndex);
  95. this.initTripEntryDefaultData(model, rowIndex);
  96. Object currencyId = ErCommonUtils.getPk(parentModel.getValue("currency"));
  97. model.setValue("rcurrency", currencyId, rowIndex);
  98. model.setValue("tripcurrency", currencyId, rowIndex);
  99. Long[] applierIds = new Long[]{ErCommonUtils.getPk(parentModel.getValue("applier"))};
  100. model.setValue("travelers", applierIds, rowIndex);
  101. model.setValue("entrycostdept", parentModel.getValue("costdept"), rowIndex);
  102. model.setValue("entrycostcompany", parentModel.getValue("costcompany"), rowIndex);
  103. model.setValue("std_entrycostcenter", parentModel.getValue("std_costcenter"), rowIndex);
  104. model.setValue("company", parentModel.getValue("company"), rowIndex);
  105. }
  106. }
  107. public void afterBindData(EventObject e) {
  108. super.afterBindData(e);
  109. FormShowParameter formShowParameter = this.getView().getFormShowParameter();
  110. Map<String, Object> customParams = formShowParameter.getCustomParams();
  111. boolean isQueryBudget = (Boolean)customParams.get("isquerybudget");
  112. BudgetCommonUtil.setIsQueryBudgetFlag(this.getPageCache(), isQueryBudget);
  113. Long companyId = ErCommonUtils.getPk(this.getView().getParentView().getModel().getValue("company"));
  114. this.setTripExpenseItemShow(companyId, 0);
  115. this.setBudgetShow(0);
  116. this.setVehicleVisible();
  117. if (Objects.nonNull(this.getModel().getDataEntityType().getProperty("costorgusemode"))) {
  118. this.getModel().setValue("costorgusemode", this.getView().getParentView().getModel().getValue("costorgusemode"));
  119. }
  120. ShowPageUtils.setMobilePageFormStatus(this.getView());
  121. if (StringUtils.equals("1", ErCommonUtils.getTripDateSelectRange(companyId))) {
  122. DateTimeEdit tripDate = (DateTimeEdit)this.getControl("startdate");
  123. tripDate.setMinDate(ErCommonUtils.getDateFromLocalDate(LocalDate.now()));
  124. tripDate = (DateTimeEdit)this.getControl("enddate");
  125. tripDate.setMinDate(ErCommonUtils.getDateFromLocalDate(LocalDate.now()));
  126. }
  127. }
  128. private void setVehicleVisible() {
  129. String vihicleKey = null;
  130. if (!this.readOnly() && this.getVihicleFromStdConfig()) {
  131. vihicleKey = "vehicles";
  132. } else {
  133. vihicleKey = "vehicle";
  134. }
  135. CardEntry tripentry = (CardEntry)this.getControl("tripentry");
  136. int tripentryLen = this.getModel().getEntryRowCount("tripentry");
  137. for(int i = 0; i < tripentryLen; ++i) {
  138. tripentry.setChildVisible(false, i, new String[]{vihicleKey});
  139. }
  140. }
  141. protected boolean readOnly() {
  142. IFormView parentView = this.getView().getParentView();
  143. return parentView != null && !"A".equals(parentView.getModel().getValue("billstatus")) && !"D".equals(parentView.getModel().getValue("billstatus"));
  144. }
  145. protected boolean getVihicleFromStdConfig() {
  146. return StringUtils.equals(ErStdConfig.get("notMultiVehicles"), "true");
  147. }
  148. public void propertyChanged(PropertyChangedArgs e) {
  149. super.propertyChanged(e);
  150. IDataModel model = this.getModel();
  151. String propName = e.getProperty().getName();
  152. ChangeData[] valueSet = e.getChangeSet();
  153. int rowIndex = valueSet[0].getRowIndex();
  154. Object propValue = valueSet[0].getNewValue();
  155. BigDecimal tripOriAmount;
  156. BigDecimal exchangeRate;
  157. String tripQuoteType;
  158. BigDecimal tripAmount;
  159. Date startDate;
  160. Date endDate;
  161. Long tripDays;
  162. switch (propName) {
  163. case "triporiamount":
  164. tripOriAmount = (BigDecimal)propValue;
  165. exchangeRate = (BigDecimal)ObjectUtils.defaultIfNull((BigDecimal)model.getValue("tripexchangerate", rowIndex), BigDecimal.ONE);
  166. tripQuoteType = (String)ObjectUtils.defaultIfNull((String)model.getValue("tripquotetype", rowIndex), "0");
  167. tripAmount = AmountUtils.getCurrencyAmount(tripOriAmount, exchangeRate, AmountUtils.getCurrencyPrecision(model, "currency"), tripQuoteType);
  168. model.setValue("tripamount", tripAmount, rowIndex);
  169. break;
  170. case "tripcurrency":
  171. IDataModel parentModel = this.getView().getParentView().getModel();
  172. DynamicObject tripCurrency = (DynamicObject)propValue;
  173. DynamicObject currency = (DynamicObject)parentModel.getValue("currency");
  174. if (tripCurrency != null && currency != null) {
  175. long sourceCurrencyId = tripCurrency.getLong("id");
  176. long targetCurrencyId = currency.getLong("id");
  177. long companyId = (Long)parentModel.getValue("company_Id");
  178. Object costCompany = parentModel.getValue("costcompany");
  179. Object bizdate = parentModel.getValue("bizdate");
  180. Map<String, Object> exchangeMap = CommonServiceHelper.getExchangeRateFromSysParams(companyId, costCompany, sourceCurrencyId, targetCurrencyId, bizdate);
  181. String quoteType = (String)ObjectUtils.defaultIfNull((String)exchangeMap.get("quoteType"), "0");
  182. exchangeRate = (BigDecimal)ObjectUtils.defaultIfNull((BigDecimal)exchangeMap.get("exchangeRate"), BigDecimal.ONE);
  183. if (this.getModel().getProperty("tripquotetype") != null) {
  184. this.getModel().setValue("tripquotetype", quoteType, rowIndex);
  185. }
  186. this.getModel().setValue("tripexchangerate", exchangeRate, rowIndex);
  187. }
  188. if (tripCurrency == null && valueSet[0].getOldValue() != null) {
  189. DynamicObject oldValue = (DynamicObject)valueSet[0].getOldValue();
  190. model.setValue("tripcurrency", ErCommonUtils.getPk(oldValue), rowIndex);
  191. }
  192. break;
  193. case "tripexchangerate":
  194. exchangeRate = (BigDecimal)ObjectUtils.defaultIfNull((BigDecimal)propValue, BigDecimal.ONE);
  195. tripOriAmount = (BigDecimal)model.getValue("triporiamount");
  196. if (tripOriAmount.compareTo(BigDecimal.ZERO) != 0) {
  197. tripQuoteType = (String)ObjectUtils.defaultIfNull((String)model.getValue("tripquotetype", rowIndex), "0");
  198. tripAmount = AmountUtils.getCurrencyAmount(tripOriAmount, exchangeRate, AmountUtils.getCurrencyPrecision(model, "currency"), tripQuoteType);
  199. model.setValue("tripamount", tripAmount, rowIndex);
  200. }
  201. break;
  202. case "startdate":
  203. startDate = (Date)propValue;
  204. endDate = (Date)model.getValue("enddate");
  205. tripDays = CommonServiceHelper.calcDays(startDate, endDate);
  206. model.setValue("tripday", tripDays, rowIndex);
  207. break;
  208. case "enddate":
  209. endDate = (Date)propValue;
  210. startDate = (Date)model.getValue("startdate");
  211. tripDays = CommonServiceHelper.calcDays(startDate, endDate);
  212. model.setValue("tripday", tripDays, rowIndex);
  213. break;
  214. case "tripexpenseitem":
  215. if (BudgetCommonUtil.getIsQueryBudgetFlag(this.getPageCache()) && propValue != null) {
  216. BudgetCommonUtil.buildBudgetAmountField(this.getView(), rowIndex);
  217. }
  218. break;
  219. case "std_project":
  220. if (BudgetCommonUtil.getIsQueryBudgetFlag(this.getPageCache())) {
  221. BudgetCommonUtil.buildBudgetAmountField(this.getView(), rowIndex);
  222. }
  223. break;
  224. case "vehicle":
  225. if (this.getVihicleFromStdConfig()) {
  226. this.getModel().setValue("vehicles", propValue);
  227. }
  228. }
  229. }
  230. public void click(EventObject evt) {
  231. Control source = (Control)evt.getSource();
  232. String key = source.getKey();
  233. IDataModel model = this.getModel();
  234. IDataModel parentModel = this.getView().getParentView().getModel();
  235. Long companyId = ErCommonUtils.getPk(parentModel.getValue("company"));
  236. switch (key) {
  237. case "btn_save":
  238. StringBuilder requireds = new StringBuilder();
  239. requireds.append("from,to,startdate,enddate,vehicles");
  240. Boolean isLoan = (Boolean)model.getValue("isloan");
  241. // if (isLoan || BudgetCommonUtil.getIsQueryBudgetFlag(this.getPageCache()) || BudgetCommonUtil.getIsQueryEASBudgetFlag(this.getPageCache()) || BudgetCommonUtil.getIsTripReqShowExpenseitemFlag(this.getPageCache()) || this.getModel().getDataEntity(true).getBoolean("istravelers") || SystemParamterUtil.getTripexpenseitemMustInput(companyId)) {
  242. // requireds.append(",tripexpenseitem");
  243. // }
  244. DynamicObject dataEntity = model.getDataEntity(true);
  245. DynamicObjectCollection tripentry = dataEntity.getDynamicObjectCollection("tripentry");
  246. Boolean confirm = Boolean.FALSE;
  247. Boolean istravelers = (Boolean)this.getModel().getValue("istravelers");
  248. Iterator var21 = tripentry.iterator();
  249. while(var21.hasNext()) {
  250. DynamicObject dobjet = (DynamicObject)var21.next();
  251. String vehicles = (String)model.getValue("vehicles");
  252. if (vehicles == null) {
  253. this.getView().showTipNotification(String.format(ResManager.loadKDString("请填写“交通工具”。", "CommonServiceHelper_1", "fi-er-business", new Object[0])));
  254. return;
  255. }
  256. String[] split = vehicles.split(",");
  257. if (split == null || split.length == 0) {
  258. this.getView().showTipNotification(String.format(ResManager.loadKDString("请填写“交通工具”。", "CommonServiceHelper_1", "fi-er-business", new Object[0])));
  259. return;
  260. }
  261. DynamicObjectCollection travelers = dobjet.getDynamicObjectCollection("travelers");
  262. if (istravelers && (travelers == null || travelers.size() == 0)) {
  263. this.getView().showTipNotification(String.format(ResManager.loadKDString("请填写“出差人”。", "TripReqSection_7", "fi-er-formplugin", new Object[0])));
  264. return;
  265. }
  266. if (!CommonServiceHelper.requireValidate(dobjet, requireds.toString().split(","), this)) {
  267. return;
  268. }
  269. Object from = dobjet.get("from");
  270. Object to = dobjet.get("to");
  271. if (from.equals(to)) {
  272. confirm = Boolean.TRUE;
  273. }
  274. dobjet.set("triporiaccappamount", dobjet.get("triporiamount"));
  275. dobjet.set("tripaccappamount", dobjet.get("tripamount"));
  276. dobjet.set("oriaccbalanceamount", dobjet.get("triporiamount"));
  277. dobjet.set("accbalanceamount", dobjet.get("tripamount"));
  278. }
  279. if (parentModel.getValue("istravelers") != null && !(Boolean)parentModel.getValue("istravelers")) {
  280. String error = this.validateTripDate(parentModel);
  281. if (StringUtils.isNotBlank(error)) {
  282. this.getView().showErrorNotification(error);
  283. return;
  284. }
  285. }
  286. if (confirm) {
  287. this.getView().showConfirm(ResManager.loadKDString("出发地与目的地相同,是否继续?", "TripReqSection_0", "fi-er-formplugin", new Object[0]), MessageBoxOptions.OKCancel, new ConfirmCallBackListener("ok", this));
  288. } else {
  289. this.clickOk(model, parentModel, dataEntity, tripentry);
  290. }
  291. break;
  292. case "btn_addsection":
  293. int tripentryCurIndex = model.getEntryCurrentRowIndex("tripentry");
  294. model.setValue("tripcurrency", ErCommonUtils.getPk(parentModel.getValue("currency")), tripentryCurIndex);
  295. Long[] applierIds = new Long[]{ErCommonUtils.getPk(parentModel.getValue("applier"))};
  296. model.setValue("travelers", applierIds, tripentryCurIndex);
  297. this.setTripExpenseItemShow(companyId, tripentryCurIndex);
  298. this.setBudgetShow(tripentryCurIndex);
  299. this.setVehicleVisible();
  300. }
  301. }
  302. private void clickOk(IDataModel model, IDataModel parentModel, DynamicObject dataEntity, DynamicObjectCollection tripentry) {
  303. if (tripentry != null && tripentry.size() >= 1) {
  304. long firstPageCurrencyId = ErCommonUtils.getPk(parentModel.getValue("currency"));
  305. long secondPageCurrencyId = ErCommonUtils.getPk(model.getValue("currency"));
  306. IFormView parentView = this.getView().getParentView();
  307. DynamicObject parentDataEntity = parentModel.getDataEntity(true);
  308. DynamicObjectCollection partripentry = parentDataEntity.getDynamicObjectCollection("tripentry");
  309. if (partripentry.isEmpty() && firstPageCurrencyId != secondPageCurrencyId) {
  310. parentView.updateView();
  311. this.getView().sendFormAction(parentView);
  312. this.getView().close();
  313. } else {
  314. FormShowParameter param = this.getView().getFormShowParameter();
  315. String pageId = parentView.getPageId();
  316. if (param.getCustomParam("entryedit") != null) {
  317. int index = (Integer)param.getCustomParam("index");
  318. partripentry.remove(index);
  319. partripentry.addAll(index, tripentry);
  320. } else {
  321. partripentry.addAll(tripentry);
  322. }
  323. RedisModelCache redisModelCache = new RedisModelCache((IRefrencedataProvider)null, model.getDataEntityType(), pageId);
  324. redisModelCache.storeAll(dataEntity);
  325. parentView.updateView();
  326. this.getView().sendFormAction(parentView);
  327. this.getView().close();
  328. }
  329. } else {
  330. this.getView().showTipNotification(ResManager.loadKDString("请填写行程信息。", "TripReqSection_5", "fi-er-formplugin", new Object[0]));
  331. }
  332. }
  333. private String validateTripDate(IDataModel parentModel) {
  334. DynamicObjectCollection parentTripEntry = parentModel.getEntryEntity("tripentry");
  335. int parentSize = parentTripEntry.size();
  336. DynamicObjectCollection curEntryEntity = this.getModel().getEntryEntity("tripentry");
  337. int curSize = curEntryEntity.size();
  338. Map<Integer, Object> sortMap = new TreeMap();
  339. if (curSize > 0) {
  340. curEntryEntity.forEach((entity) -> {
  341. sortMap.put(entity.getInt("index"), entity);
  342. });
  343. }
  344. if (parentSize > 0) {
  345. parentTripEntry.forEach((entity) -> {
  346. if (!sortMap.containsKey(entity.getInt("seq"))) {
  347. sortMap.put(entity.getInt("seq"), entity);
  348. }
  349. });
  350. }
  351. Date startDate = null;
  352. Date endDate = null;
  353. String tip = null;
  354. for(int i = 0; i < curEntryEntity.size(); ++i) {
  355. DynamicObject curTripEntry = (DynamicObject)curEntryEntity.get(i);
  356. int index = curTripEntry.getInt("index");
  357. DynamicObject lastTripEntry = (DynamicObject)sortMap.get(index - 1);
  358. if (lastTripEntry != null) {
  359. startDate = curTripEntry.getDate("startdate");
  360. endDate = lastTripEntry.getDate("enddate");
  361. if (startDate.before(endDate)) {
  362. tip = ResManager.loadKDString("第%1$s程行程期间不能早于第%2$s程行程期间。", "TripReqSection_2", "fi-er-formplugin", new Object[0]);
  363. return String.format(tip, index, index - 1);
  364. }
  365. }
  366. DynamicObject nextTripEntry = (DynamicObject)sortMap.get(index + 1);
  367. if (nextTripEntry != null) {
  368. endDate = curTripEntry.getDate("enddate");
  369. startDate = nextTripEntry.getDate("startdate");
  370. if (startDate.before(endDate)) {
  371. tip = ResManager.loadKDString("第%1$s程行程期间不能晚于第%2$s程行程期间。", "TripReqSection_4", "fi-er-formplugin", new Object[0]);
  372. return String.format(tip, index, index + 1);
  373. }
  374. }
  375. }
  376. return null;
  377. }
  378. private void setTripExpenseItemShow(Long companyId, int rowIndex) {
  379. Boolean isLoan = (Boolean)this.getModel().getValue("isloan");
  380. CardEntry tripCardEntry = (CardEntry)this.getControl("tripentry");
  381. if (!isLoan && !BudgetCommonUtil.getIsQueryBudgetFlag(this.getPageCache()) && !BudgetCommonUtil.getIsQueryEASBudgetFlag(this.getPageCache()) && !BudgetCommonUtil.getIsTripReqShowExpenseitemFlag(this.getPageCache()) && !this.getModel().getDataEntity(true).getBoolean("istravelers") && !SystemParamterUtil.getTripexpenseitemMustInput(companyId)) {
  382. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardtripexpenseitem", "tripexpenseitem"});
  383. } else {
  384. tripCardEntry.setChildVisible(true, rowIndex, new String[]{"cardtripexpenseitem", "tripexpenseitem"});
  385. FieldEdit editor = (FieldEdit)this.getView().getControl("tripexpenseitem");
  386. editor.setMustInput(false);
  387. }
  388. }
  389. private void setBudgetShow(int rowIndex) {
  390. CardEntry tripCardEntry = (CardEntry)this.getControl("tripentry");
  391. if (tripCardEntry != null) {
  392. if (!BudgetCommonUtil.getIsQueryBudgetFlag(this.getPageCache()) && !BudgetCommonUtil.getIsQueryEASBudgetFlag(this.getPageCache())) {
  393. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardbudget", "budgetamount"});
  394. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardbudget1", "budgetmsg"});
  395. } else {
  396. IFormView parentView = this.getView().getParentView();
  397. if (parentView != null) {
  398. String budgeMsgValue = (String)ErCommonUtils.getEMParameter(ErCommonUtils.getPk(parentView.getModel().getValue("company")), "budgeMsgControl");
  399. if (StringUtils.isNotEmpty(budgeMsgValue)) {
  400. if ("0".equals(budgeMsgValue)) {
  401. tripCardEntry.setChildVisible(true, rowIndex, new String[]{"cardbudget", "budgetamount"});
  402. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardbudget1", "budgetmsg"});
  403. } else if ("1".equals(budgeMsgValue)) {
  404. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardbudget", "budgetamount"});
  405. tripCardEntry.setChildVisible(true, rowIndex, new String[]{"cardbudget1", "budgetmsg"});
  406. }
  407. } else {
  408. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardbudget", "budgetamount"});
  409. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardbudget1", "budgetmsg"});
  410. }
  411. } else {
  412. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardbudget", "budgetamount"});
  413. tripCardEntry.setChildVisible(false, rowIndex, new String[]{"cardbudget1", "budgetmsg"});
  414. }
  415. }
  416. }
  417. }
  418. private void initTripEntryDefaultData(IDataModel model, int rowIndex) {
  419. model.setValue("tripexchangerate", BigDecimal.ONE, rowIndex);
  420. }
  421. public void afterDeleteRow(AfterDeleteRowEventArgs e) {
  422. super.afterDeleteRow(e);
  423. int[] rowIndexs = e.getRowIndexs();
  424. int rowIndex = rowIndexs[0];
  425. for(int tripEntrySize = this.getModel().getEntryRowCount("tripentry"); rowIndex < tripEntrySize; ++rowIndex) {
  426. int index = (Integer)this.getModel().getValue("index", rowIndex);
  427. this.getModel().setValue("index", index - 1, rowIndex);
  428. }
  429. }
  430. public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
  431. super.afterDoOperation(afterDoOperationEventArgs);
  432. IDataModel model = this.getModel();
  433. IDataModel paremodel = this.getView().getParentView().getModel();
  434. int rowIndex = model.getEntryCurrentRowIndex("tripentry");
  435. int thisCount = model.getEntryRowCount("tripentry");
  436. DynamicObjectCollection tripentryCol = model.getEntryEntity("tripentry");
  437. int tripenytryCount = tripentryCol.size();
  438. if (thisCount != 0) {
  439. int tripEntryRowCount;
  440. if ("newtripentry".equalsIgnoreCase(afterDoOperationEventArgs.getOperateKey())) {
  441. if (tripenytryCount > 1) {
  442. Object lastCity = ((DynamicObject)tripentryCol.get(tripenytryCount - 2)).get("to_Id");
  443. Object nextStartDate = ((DynamicObject)tripentryCol.get(tripenytryCount - 2)).get("enddate");
  444. if (lastCity != null) {
  445. model.setValue("from", lastCity, tripenytryCount - 1);
  446. }
  447. if (nextStartDate != null) {
  448. model.setValue("startdate", nextStartDate, tripenytryCount - 1);
  449. }
  450. }
  451. tripEntryRowCount = model.getEntryRowCount("tripentry") + paremodel.getEntryRowCount("tripentry");
  452. model.setValue("index", tripEntryRowCount, model.getEntryRowCount("tripentry") - 1);
  453. Object currencyId = ErCommonUtils.getPk(paremodel.getValue("currency"));
  454. model.setValue("rcurrency", currencyId, rowIndex);
  455. model.setValue("tripcurrency", currencyId, rowIndex);
  456. this.initTripEntryDefaultData(model, rowIndex);
  457. }
  458. tripEntryRowCount = model.getEntryRowCount("tripentry");
  459. int parentTripEntryRowCount = paremodel.getEntryRowCount("tripentry");
  460. if (Objects.equals(afterDoOperationEventArgs.getOperateKey(), "deletetripentry")) {
  461. for(int i = 0; i < tripEntryRowCount; ++i) {
  462. model.setValue("index", parentTripEntryRowCount + i + 1, i);
  463. }
  464. }
  465. }
  466. }
  467. public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) {
  468. super.confirmCallBack(messageBoxClosedEvent);
  469. if (MessageBoxResult.Yes.equals(messageBoxClosedEvent.getResult())) {
  470. IFormView parentView = this.getView().getParentView();
  471. IDataModel parentModel = parentView.getModel();
  472. DynamicObject dataEntity = this.getModel().getDataEntity(true);
  473. DynamicObjectCollection tripentry = dataEntity.getDynamicObjectCollection("tripentry");
  474. this.clickOk(this.getModel(), parentModel, dataEntity, tripentry);
  475. }
  476. }
  477. public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
  478. super.closedCallBack(closedCallBackEvent);
  479. if ("people_choose".equalsIgnoreCase(closedCallBackEvent.getActionId())) {
  480. ListSelectedRowCollection rowCollection = (ListSelectedRowCollection)closedCallBackEvent.getReturnData();
  481. int index = this.getModel().getEntryCurrentRowIndex("tripentry");
  482. Object[] users = null;
  483. if (rowCollection != null) {
  484. users = rowCollection.stream().map((v) -> {
  485. return v.getPrimaryKeyValue();
  486. }).toArray();
  487. } else {
  488. users = new Object[0];
  489. }
  490. this.getModel().setValue("travelers", users, index);
  491. }
  492. }
  493. public void beforeClosed(BeforeClosedEvent e) {
  494. e.setCheckDataChange(false);
  495. super.beforeClosed(e);
  496. }
  497. }