1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.web.struts;
17
18 import org.apache.commons.lang.StringEscapeUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.apache.commons.lang.time.DateUtils;
21 import org.apache.struts.action.ActionForm;
22 import org.apache.struts.action.ActionForward;
23 import org.apache.struts.action.ActionMapping;
24 import org.kuali.ole.DocumentUniqueIDPrefix;
25 import org.kuali.ole.coa.businessobject.Account;
26 import org.kuali.ole.coa.businessobject.OleFundCode;
27 import org.kuali.ole.coa.businessobject.OleFundCodeAccountingLine;
28 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
29 import org.kuali.ole.docstore.common.document.Bib;
30 import org.kuali.ole.module.purap.*;
31 import org.kuali.ole.module.purap.PurapConstants.PODocumentsStrings;
32 import org.kuali.ole.module.purap.PurapConstants.PurchaseOrderStatuses;
33 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
34 import org.kuali.ole.module.purap.businessobject.PurApItem;
35 import org.kuali.ole.module.purap.document.*;
36 import org.kuali.ole.module.purap.document.service.OlePurapService;
37 import org.kuali.ole.module.purap.document.service.PurapService;
38 import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
39 import org.kuali.ole.pojo.OleBibRecord;
40 import org.kuali.ole.pojo.OleEditorResponse;
41 import org.kuali.ole.select.OleSelectConstant;
42 import org.kuali.ole.select.bo.OLEDonor;
43 import org.kuali.ole.select.bo.OLEEditorResponse;
44 import org.kuali.ole.select.bo.OLELinkPurapDonor;
45 import org.kuali.ole.select.businessobject.*;
46 import org.kuali.ole.select.constants.OleSelectPropertyConstants;
47 import org.kuali.ole.select.document.OlePurchaseOrderAmendmentDocument;
48 import org.kuali.ole.select.document.OlePurchaseOrderDocument;
49 import org.kuali.ole.select.document.service.OleCopyHelperService;
50 import org.kuali.ole.select.document.service.OlePurchaseOrderService;
51 import org.kuali.ole.select.document.service.OleRequisitionDocumentService;
52 import org.kuali.ole.select.document.validation.event.CopiesPurchaseOrderEvent;
53 import org.kuali.ole.select.document.validation.event.DiscountPurchaseOrderEvent;
54 import org.kuali.ole.select.document.validation.event.ForeignCurrencyPOEvent;
55 import org.kuali.ole.select.document.validation.event.OlePurchaseOrderDescEvent;
56 import org.kuali.ole.sys.OLEConstants;
57 import org.kuali.ole.sys.OLEPropertyConstants;
58 import org.kuali.ole.sys.businessobject.AccountingLineBase;
59 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
60 import org.kuali.ole.sys.context.SpringContext;
61 import org.kuali.ole.sys.document.validation.event.AddAccountingLineEvent;
62 import org.kuali.ole.vnd.VendorConstants;
63 import org.kuali.ole.vnd.businessobject.*;
64 import org.kuali.ole.vnd.document.service.VendorService;
65 import org.kuali.rice.core.api.config.property.ConfigurationService;
66 import org.kuali.rice.core.api.util.RiceKeyConstants;
67 import org.kuali.rice.core.api.util.type.KualiDecimal;
68 import org.kuali.rice.core.api.util.type.KualiInteger;
69 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
70 import org.kuali.rice.kns.question.ConfirmationQuestion;
71 import org.kuali.rice.kns.util.KNSGlobalVariables;
72 import org.kuali.rice.kns.web.struts.form.BlankFormFile;
73 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
74 import org.kuali.rice.kns.web.struts.form.KualiForm;
75 import org.kuali.rice.kns.web.struts.form.pojo.PojoForm;
76 import org.kuali.rice.krad.bo.Note;
77 import org.kuali.rice.krad.document.Document;
78 import org.kuali.rice.krad.exception.ValidationException;
79 import org.kuali.rice.krad.service.*;
80 import org.kuali.rice.krad.util.GlobalVariables;
81 import org.kuali.rice.krad.util.KRADConstants;
82 import org.kuali.rice.krad.util.ObjectUtils;
83 import org.kuali.rice.krad.util.UrlFactory;
84
85 import javax.servlet.http.HttpServletRequest;
86 import javax.servlet.http.HttpServletResponse;
87 import java.io.ByteArrayOutputStream;
88 import java.math.BigDecimal;
89 import java.math.RoundingMode;
90 import java.util.*;
91
92
93
94
95 public class OlePurchaseOrderAction extends PurchaseOrderAction {
96 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurchaseOrderAction.class);
97 private final String UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING = "docAction=checkIn&stringContent=";
98 private final String CHECKOUT_DOCSTORE_RECORD_QUERY_STRING = "docAction=checkOut&uuid=";
99 private final String CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING = "docAction=ingestContent&stringContent=";
100 private static transient ConfigurationService kualiConfigurationService;
101 private DocstoreClientLocator docstoreClientLocator;
102 private boolean currencyTypeIndicator = true;
103
104 public DocstoreClientLocator getDocstoreClientLocator() {
105 if (docstoreClientLocator == null) {
106 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
107 }
108 return docstoreClientLocator;
109 }
110
111
112
113
114
115
116
117
118
119
120
121 public ActionForward performPRLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
122
123 ActionForward forward = super.performLookup(mapping, form, request, response);
124 String path = forward.getPath();
125 if (path.contains("kr/lookup.do")) {
126 path = path.replace("kr/lookup.do", "prlookup.do");
127
128 } else if (path.contains("lookup.do")) {
129 path = path.replace("lookup.do", "prlookup.do");
130
131 }
132 forward.setPath(path);
133
134 return forward;
135
136 }
137
138
139
140
141 @Override
142 public ActionForward calculate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
143
144 PurchasingAccountsPayableFormBase purchasingForm = (PurchasingAccountsPayableFormBase) form;
145 List<PurApItem> purApItems = ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems();
146 for(PurApItem purApItem:purApItems){
147 List<KualiDecimal> existingAmount=new ArrayList<>();
148 for(PurApAccountingLine oldSourceAccountingLine:purApItem.getSourceAccountingLines()) {
149 if(oldSourceAccountingLine instanceof OlePurchaseOrderAccount) {
150 if(((OlePurchaseOrderAccount)oldSourceAccountingLine).getExistingAmount()!=null){
151 existingAmount.add(((OlePurchaseOrderAccount)oldSourceAccountingLine).getExistingAmount());
152 }
153 }
154 }
155 int count=0;
156 for(PurApAccountingLine account:purApItem.getSourceAccountingLines()){
157
158 if (ObjectUtils.isNotNull(account.getAccountLinePercent()) || ObjectUtils.isNotNull(account.getAmount())) {
159 if (account.getAmount()!=null&&count<existingAmount.size()&&existingAmount.size() != 0 && !existingAmount.get(count).toString().equals(account.getAmount().toString())) {
160 KualiDecimal calculatedPercent = new KualiDecimal(account.getAmount().multiply(new KualiDecimal(100)).divide(purApItem.getTotalAmount()).toString());
161 account.setAccountLinePercent(calculatedPercent.bigDecimalValue().setScale(OLEConstants.BIG_DECIMAL_SCALE,BigDecimal.ROUND_CEILING));
162 }
163 else {
164 if(account.getAccountLinePercent().intValue()==100&&(account.getAmount()==null||account.getAccount()!=null)){
165 KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent().multiply(purApItem.getTotalAmount().bigDecimalValue()).divide(new BigDecimal(100)).toString());
166 account.setAmount(calculatedAmount);
167 }
168 else{
169 KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent().multiply(purApItem.getTotalAmount().bigDecimalValue()).divide(new BigDecimal(100)).toString());
170 account.setAmount(calculatedAmount);
171 }
172 }
173 }
174 count++;
175 }
176 for(PurApAccountingLine oldSourceAccountingLine:purApItem.getSourceAccountingLines()) {
177 if(oldSourceAccountingLine instanceof OlePurchaseOrderAccount) {
178 ((OlePurchaseOrderAccount)oldSourceAccountingLine).setExistingAmount(oldSourceAccountingLine.getAmount());
179 }
180 }
181 }
182 ActionForward forward = super.calculate(mapping, form, request, response);
183
184 purchasingForm = (PurchasingAccountsPayableFormBase) form;
185 PurchasingDocument purDoc = (PurchasingDocument) purchasingForm.getDocument();
186 PurchasingFormBase formBase = (PurchasingFormBase) form;
187
188 PurchaseOrderDocument purchaseDoc = (PurchaseOrderDocument) formBase.getDocument();
189 List<OlePurchaseOrderItem> purItem = purchaseDoc.getItems();
190 if (purchaseDoc.getVendorDetail().getCurrencyType()!=null){
191 if(purchaseDoc.getVendorDetail().getCurrencyType().getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){
192 currencyTypeIndicator=true;
193 }
194 else{
195 currencyTypeIndicator=false;
196 }
197 }
198 if (purDoc.getVendorDetail() == null || (purDoc.getVendorDetail() != null && currencyTypeIndicator)) {
199 for (int i = 0; purDoc.getItems().size() > i; i++) {
200 OlePurchaseOrderItem item = (OlePurchaseOrderItem) purDoc.getItem(i);
201 if ((item.getItemType().isQuantityBasedGeneralLedgerIndicator())) {
202 boolean rulePassed = getKualiRuleService().applyRules(new DiscountPurchaseOrderEvent(purchaseDoc, item));
203 if (rulePassed) {
204 item.setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(item).setScale(2, BigDecimal.ROUND_HALF_UP));
205 }
206 rulePassed = getKualiRuleService().applyRules(new CopiesPurchaseOrderEvent(purDoc, item));
207 }
208
209 }
210 } else {
211 LOG.debug("###########Foreign Currency Field Calculation in olepurchaseOrder action###########");
212 BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
213 for (int i = 0; purItem.size() > i; i++) {
214 OlePurchaseOrderItem items = (OlePurchaseOrderItem) purchaseDoc.getItem(i);
215 if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) {
216 boolean rulePassed = getKualiRuleService().applyRules(new ForeignCurrencyPOEvent(purchaseDoc, items));
217 if (rulePassed) {
218 SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(items);
219 Long id = purchaseDoc.getVendorDetail().getCurrencyType().getCurrencyTypeId();
220 Map currencyTypeMap = new HashMap();
221 currencyTypeMap.put(OleSelectConstant.CURRENCY_TYPE_ID, id);
222 List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy(OleExchangeRate.class, currencyTypeMap, OleSelectConstant.EXCHANGE_RATE_DATE, false);
223 Iterator iterator = exchangeRateList.iterator();
224 if (iterator.hasNext()) {
225 OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next();
226 String documentNumber = purchaseDoc.getDocumentNumber();
227 Map documentNumberMap = new HashMap();
228 documentNumberMap.put(OLEPropertyConstants.DOCUMENT_NUMBER, documentNumber);
229 List<OlePurchaseOrderItem> currenctExchangeRateList = (List) businessObjectService.findMatching(OlePurchaseOrderItem.class, documentNumberMap);
230 Iterator iterate = currenctExchangeRateList.iterator();
231 if (iterate.hasNext()) {
232 OlePurchaseOrderItem tempCurrentExchangeRate = (OlePurchaseOrderItem) iterate.next();
233 String poCurrencyType = null;
234 if (tempCurrentExchangeRate.getPurchaseOrder().getVendorDetail().getCurrencyType() != null) {
235 poCurrencyType = tempCurrentExchangeRate.getPurchaseOrder().getVendorDetail().getCurrencyType().getCurrencyType();
236 }
237 String poaCurrencyType = purchaseDoc.getVendorDetail().getCurrencyType().getCurrencyType();
238 if (poCurrencyType != null && (poCurrencyType.equalsIgnoreCase(poaCurrencyType)) && !items.isLatestExchangeRate() && !purchaseDoc.getIsPODoc() && ((purchaseDoc instanceof PurchaseOrderAmendmentDocument) || (purchaseDoc instanceof PurchaseOrderSplitDocument) || (purchaseDoc instanceof PurchaseOrderReopenDocument))) {
239 items.setItemExchangeRate(tempCurrentExchangeRate.getItemExchangeRate());
240 } else {
241 items.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate()));
242 }
243 }
244 if (items.getItemExchangeRate() != null && items.getItemForeignUnitCost() != null) {
245 items.setItemUnitCostUSD(new KualiDecimal(items.getItemForeignUnitCost().bigDecimalValue().divide(items.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP)));
246 items.setItemUnitPrice(items.getItemUnitCostUSD().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP));
247 items.setItemListPrice(items.getItemUnitCostUSD());
248 }
249 }
250 }
251 }
252 }
253 }
254
255 purchasingForm = (PurchasingAccountsPayableFormBase) form;
256 List<PurApItem> newpurApItems = ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems();
257 for(PurApItem purApItem:newpurApItems){
258 for(PurApAccountingLine account:purApItem.getSourceAccountingLines()){
259 KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent().multiply(purApItem.getTotalAmount().bigDecimalValue()).divide(new BigDecimal(100)).toString());
260 account.setAmount(calculatedAmount);
261 }
262 }
263 forward = super.calculate(mapping, form, request, response);
264
265
266
267
268
269 OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
270 .getBean("oleRequisitionDocumentService");
271 List<SourceAccountingLine> sourceAccountingLineList = purDoc.getSourceAccountingLines();
272 for (SourceAccountingLine accLine : sourceAccountingLineList) {
273 String notificationOption = null;
274 boolean sufficientFundCheck;
275 Map<String, Object> key = new HashMap<String, Object>();
276 String chartCode = accLine.getChartOfAccountsCode();
277 String accNo = accLine.getAccountNumber();
278 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
279 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
280 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
281 OleSufficientFundCheck.class, key);
282 if (account != null) {
283 notificationOption = account.getNotificationOption();
284 }
285 if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.BLOCK_USE)) {
286 sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine);
287 if (sufficientFundCheck) {
288 GlobalVariables.getMessageMap().putError(
289 OLEConstants.SufficientFundCheck.ERROR_MSG_FOR_INSUFF_FUND, RiceKeyConstants.ERROR_CUSTOM,
290 OLEConstants.SufficientFundCheck.INSUFF_FUND_POA + accLine.getAccountNumber());
291 }
292 }
293 }
294
295
296
297
298 if (LOG.isDebugEnabled()) {
299 LOG.debug("Inside the OlePurchaseOrderAction class Calculate" + formBase.getNewPurchasingItemLine().getItemUnitPrice());
300 }
301 return forward;
302 }
303
304
305
306
307 @Override
308 public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
309
310 LOG.debug("###########Inside AddItem in olePurchaseOrderAction ###########");
311 PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
312 OlePurchaseOrderItem purchaseOrderItem = (OlePurchaseOrderItem) purchasingForm.getNewPurchasingItemLine();
313 purchaseOrderItem.getNewSourceLine().setAccountLinePercent(new BigDecimal(100));
314
315 PurchaseOrderDocument document = (PurchaseOrderDocument) purchasingForm.getDocument();
316
317
318
319 OlePurchaseOrderForm oleForm = (OlePurchaseOrderForm) form;
320 PurchaseOrderDocument doc = (PurchaseOrderDocument) oleForm.getDocument();
321 Iterator itemIterator = doc.getItems().iterator();
322 int itemCounter = 0;
323 while (itemIterator.hasNext()) {
324 OlePurchaseOrderItem tempItem = (OlePurchaseOrderItem) itemIterator.next();
325 if (tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) || tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
326 itemCounter++;
327 }
328 }
329 String itemNo = String.valueOf(itemCounter);
330
331 HashMap<String, String> dataMap = new HashMap<String, String>();
332 BibInfoBean xmlBibInfoBean = new BibInfoBean();
333 if (purchaseOrderItem.getBibInfoBean() == null) {
334 purchaseOrderItem.setBibInfoBean(xmlBibInfoBean);
335 if (purchaseOrderItem.getBibInfoBean().getDocStoreOperation() == null) {
336 purchaseOrderItem.getBibInfoBean().setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_STAFF);
337 }
338 }
339 String fileName = document.getDocumentNumber() + "_" + itemNo;
340
341
342
343 setItemDescription(purchaseOrderItem, fileName);
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372 if (document.getVendorDetail().getCurrencyType()!=null){
373 if(document.getVendorDetail().getCurrencyType().getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){
374 currencyTypeIndicator=true;
375 }
376 else{
377 currencyTypeIndicator=false;
378 }
379 }
380 boolean ruleFlag = getKualiRuleService().applyRules(new OlePurchaseOrderDescEvent(document, purchaseOrderItem));
381 if (ruleFlag) {
382 if ((document.getVendorDetail() == null) || (document.getVendorDetail().getVendorName() != null && currencyTypeIndicator)) {
383 boolean rulePassed = getKualiRuleService().applyRules(new DiscountPurchaseOrderEvent(document, purchaseOrderItem));
384 if (rulePassed) {
385 purchasingForm.getNewPurchasingItemLine().setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(purchaseOrderItem).setScale(2, BigDecimal.ROUND_HALF_UP));
386 super.addItem(mapping, purchasingForm, request, response);
387 }
388 } else {
389 boolean rulePassed = getKualiRuleService().applyRules(new ForeignCurrencyPOEvent(document, purchaseOrderItem));
390 if (rulePassed) {
391 LOG.debug("###########Foreign Currency Field additem for purchase Order ###########");
392 SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(purchaseOrderItem);
393 Long id = document.getVendorDetail().getCurrencyType().getCurrencyTypeId();
394 Map documentNumberMap = new HashMap();
395 documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, id);
396 BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
397 List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy(OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false);
398 Iterator iterator = exchangeRateList.iterator();
399 if (iterator.hasNext()) {
400 OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next();
401 purchaseOrderItem.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate()));
402 }
403 if (purchaseOrderItem.getItemExchangeRate() != null && purchaseOrderItem.getItemForeignUnitCost() != null) {
404 purchaseOrderItem.setItemUnitCostUSD(new KualiDecimal(purchaseOrderItem.getItemForeignUnitCost().bigDecimalValue().divide(purchaseOrderItem.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP)));
405 purchaseOrderItem.setItemUnitPrice(purchaseOrderItem.getItemUnitCostUSD().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP));
406 purchaseOrderItem.setItemListPrice(purchaseOrderItem.getItemUnitCostUSD());
407 }
408 super.addItem(mapping, purchasingForm, request, response);
409 }
410 }
411 }
412 if(purchaseOrderItem.getClaimDate()==null){
413 VendorDetail vendorDetail =document.getVendorDetail();
414 if( vendorDetail!=null ){
415 String claimInterval = vendorDetail.getClaimInterval();
416 if (StringUtils.isNotBlank(claimInterval)) {
417 Integer actIntvl = Integer.parseInt(claimInterval);
418 purchaseOrderItem.setClaimDate(new java.sql.Date(DateUtils.addDays(new java.util.Date(), actIntvl).getTime()));
419 }
420 }
421 }
422 return mapping.findForward(OLEConstants.MAPPING_BASIC);
423 }
424
425
426
427
428
429
430
431
432
433
434
435
436 public ActionForward addNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
437 LOG.debug("Inside addNote Method of PurchaseOrderAction");
438 PurchaseOrderForm purchasingForm = (PurchaseOrderForm) form;
439 int line = this.getSelectedLine(request);
440 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItem(line);
441 OlePurchaseOrderNotes note = new OlePurchaseOrderNotes();
442 note.setNote(item.getNote());
443 note.setNoteTypeId(item.getNoteTypeId());
444 item.getNotes().add(note);
445 LOG.debug("Adding Note to PurchaseOrderItem");
446 item.setNote(null);
447 item.setNoteTypeId(null);
448 LOG.debug("Leaving addNote Method of PurchaseOrderAction");
449 return mapping.findForward(OLEConstants.MAPPING_BASIC);
450 }
451
452
453
454
455
456
457
458
459
460
461
462 public ActionForward deleteNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
463 LOG.debug("Inside deleteNote Method of PurchaseOrderAction");
464 PurchaseOrderForm purchasingForm = (PurchaseOrderForm) form;
465 String[] indexes = getSelectedLineForAccounts(request);
466 int itemIndex = Integer.parseInt(indexes[0]);
467 int noteIndex = Integer.parseInt(indexes[1]);
468 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItem((itemIndex));
469 item.getNotes().remove(noteIndex);
470 LOG.debug("Note deleted for the selected Item");
471 LOG.debug("Leaving deleteNote Method of PurchaseOrderAction");
472 return mapping.findForward(OLEConstants.MAPPING_BASIC);
473 }
474
475
476
477
478
479
480 @Override
481 public ActionForward createReceivingLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
482 LOG.debug("Inside createReceivingLine Method of OlePurchaseOrderAction");
483 PurchaseOrderForm poForm = (PurchaseOrderForm) form;
484 PurchaseOrderDocument document = (PurchaseOrderDocument) poForm.getDocument();
485
486 String basePath = getApplicationBaseUrl();
487 String methodToCallDocHandler = "continueReceivingLine";
488 String methodToCallReceivingLine = "initiate";
489
490
491 Properties parameters = new Properties();
492 parameters.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, methodToCallDocHandler);
493 parameters.put(OLEConstants.PARAMETER_COMMAND, methodToCallReceivingLine);
494 parameters.put(OLEConstants.DOCUMENT_TYPE_NAME, "OLE_RCVL");
495 parameters.put("purchaseOrderId", document.getPurapDocumentIdentifier().toString());
496
497
498
499 String receivingUrl = UrlFactory.parameterizeUrl(basePath + "/" + "selectOleLineItemReceiving.do", parameters);
500
501
502 ActionForward forward = new ActionForward(receivingUrl, true);
503 LOG.debug("Leaving createReceivingLine Method of OlePurchaseOrderAction");
504 return forward;
505 }
506
507
508
509
510
511
512
513
514
515 @Override
516 protected String getUrlForPrintPO(String basePath, String docId, String methodToCall) {
517 StringBuffer result = new StringBuffer(basePath);
518 result.append("/purapOlePurchaseOrder.do?methodToCall=");
519 result.append(methodToCall);
520 result.append("&docId=");
521 result.append(docId);
522 result.append("&command=displayDocSearchView");
523
524 return result.toString();
525 }
526
527 @Override
528 public ActionForward route(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
529 PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
530 PurchasingDocument purDoc = (PurchasingDocument) purchasingForm.getDocument();
531 if ((purchasingForm.getDocTypeName()).equalsIgnoreCase("OLE_POA")) {
532
533 }
534
535 if (requiresCalculate(purchasingForm)) {
536 GlobalVariables.getMessageMap().putError(OLEConstants.DOCUMENT_ERRORS, PurapKeyConstants.ERROR_PURCHASING_REQUIRES_CALCULATE);
537
538 return mapping.findForward(OLEConstants.MAPPING_BASIC);
539 }
540
541
542 SpringContext.getBean(PurapService.class).prorateForTradeInAndFullOrderDiscount(purDoc);
543 this.calculate(mapping, purchasingForm, request, response);
544 PurchaseOrderDocument purchaseDoc = (PurchaseOrderDocument) purchasingForm.getDocument();
545 List<OlePurchaseOrderItem> purItem = purchaseDoc.getItems();
546 for (int i = OLEConstants.ZERO; purDoc.getItems().size() > i; i++) {
547 OlePurchaseOrderItem item = (OlePurchaseOrderItem) purDoc.getItem(i);
548 if ((item.getItemType().isQuantityBasedGeneralLedgerIndicator())) {
549 if (item.getCopyList().size()==OLEConstants.ZERO && item.getItemQuantity() != null && item.getItemNoOfParts() != null && !item.getItemQuantity().isGreaterThan(OLEConstants.ONE.kualiDecimalValue())
550 && !item.getItemNoOfParts().isGreaterThan(OLEConstants.ONE) ) {
551 OleCopy oleCopy = new OleCopy();
552 oleCopy.setLocation(item.getItemLocation());
553 oleCopy.setBibId(item.getItemTitleId());
554 oleCopy.setCopyNumber(item.getSingleCopyNumber()!=null && !item.getSingleCopyNumber().isEmpty()?item.getSingleCopyNumber():null);
555 oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.NOT_RECEIVED_STATUS);
556 if (StringUtils.isNotBlank(item.getLinkToOrderOption()) && (item.getLinkToOrderOption().equals(OLEConstants.NB_PRINT) || item.getLinkToOrderOption().equals(OLEConstants.EB_PRINT))) {
557 oleCopy.setCopyNumber(item.getSingleCopyNumber() != null && !item.getSingleCopyNumber().isEmpty() ? item.getSingleCopyNumber() : null);
558 }
559 List<OleCopy> copyList = new ArrayList<>();
560 copyList.add(oleCopy);
561 item.setCopyList(copyList);
562 }
563 }
564 if (item.getItemIdentifier() != null && item.getItemQuantity() != null && item.getItemNoOfParts() != null && !item.getItemQuantity().isGreaterThan(OLEConstants.ONE.kualiDecimalValue())
565 && !item.getItemNoOfParts().isGreaterThan(OLEConstants.ONE)) {
566 Map<String, String> map = new HashMap<>();
567 map.put(OLEConstants.PO_ID, item.getItemIdentifier().toString());
568 List<OleCopy> oleCopyList = (List<OleCopy>) SpringContext.getBean(BusinessObjectService.class).findMatching(OleCopy.class, map);
569 if (oleCopyList.size() == 1) {
570 item.getCopyList().get(0).setCopyNumber(item.getSingleCopyNumber() != null && !item.getSingleCopyNumber().isEmpty() ? item.getSingleCopyNumber() : null);
571 }
572 }
573 if (item.getItemIdentifier() != null) {
574 Map map = new HashMap();
575 map.put(OLEConstants.PO_ID, item.getItemIdentifier().toString());
576 List<OLELinkPurapDonor> linkPurapDonors = (List<OLELinkPurapDonor>) getBusinessObjectService().findMatching(OLELinkPurapDonor.class, map);
577 if (linkPurapDonors != null && linkPurapDonors.size() > 0) {
578 getBusinessObjectService().delete(linkPurapDonors);
579 }
580 }
581 }
582 return super.route(mapping, form, request, response);
583
584 }
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617 public void setEnumerationToCopies(List<OlePurchaseOrderItem> purItem) {
618 String partEnumerationCopy = getConfigurationService().getPropertyValueAsString(
619 OLEConstants.PART_ENUMERATION_COPY);
620 String partEnumerationVolume = getConfigurationService().getPropertyValueAsString(
621 OLEConstants.PART_ENUMERATION_VOLUME);
622 for (int singleItem = 0; purItem.size() > singleItem; singleItem++) {
623 List<OleCopies> purItemCopies = purItem.get(singleItem).getCopies();
624 for (int copies = 0; copies < purItemCopies.size(); copies++) {
625 purItemCopies.get(copies).setParts(purItem.get(singleItem).getItemNoOfParts());
626 int startingCopyNumber = purItemCopies.get(copies).getStartingCopyNumber().intValue();
627 StringBuffer enumeration = new StringBuffer();
628 for (int noOfCopies = 0; noOfCopies < purItemCopies.get(copies).getItemCopies().intValue(); noOfCopies++) {
629 for (int noOfParts = 0; noOfParts < purItemCopies.get(copies).getParts().intValue(); noOfParts++) {
630 int newNoOfCopies = startingCopyNumber + noOfCopies;
631 int newNoOfParts = noOfParts + 1;
632 if (noOfCopies + 1 == purItemCopies.get(copies).getItemCopies().intValue()
633 && newNoOfParts == purItemCopies.get(copies).getParts().intValue()) {
634 enumeration = enumeration.append(
635 partEnumerationCopy + newNoOfCopies + OLEConstants.DOT_TO_SEPARATE_COPIES_PARTS).append(
636 partEnumerationVolume + newNoOfParts);
637 } else {
638 enumeration = enumeration.append(
639 partEnumerationCopy + newNoOfCopies + OLEConstants.DOT_TO_SEPARATE_COPIES_PARTS).append(
640 partEnumerationVolume + newNoOfParts + OLEConstants.COMMA_TO_SEPARATE_ENUMERATION);
641 }
642 }
643 }
644 purItemCopies.get(copies).setPartEnumeration(enumeration.toString());
645 }
646 }
647 }
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672 @Override
673 protected ActionForward askQuestionsAndPerformDocumentAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionType, String confirmType, String documentType, String notePrefix, String messageType, String operation) throws Exception {
674 LOG.debug("askQuestionsAndPerformDocumentAction started.");
675 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
676 PurchaseOrderDocument po = (PurchaseOrderDocument) kualiDocumentFormBase.getDocument();
677 Object question = request.getParameter(OLEConstants.QUESTION_INST_ATTRIBUTE_NAME);
678 String reason = request.getParameter(OLEConstants.QUESTION_REASON_ATTRIBUTE_NAME);
679 String noteText = "";
680 String noteOne = "";
681 String noteTwo = "";
682
683 try {
684 ConfigurationService kualiConfiguration = SpringContext.getBean(ConfigurationService.class);
685 String[] reasons = null;
686
687 if (ObjectUtils.isNull(question)) {
688 String message = "";
689 if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_SPLIT_DOCUMENT)) {
690 message = kualiConfiguration.getPropertyValueAsString(PurapKeyConstants.PURCHASE_ORDER_SPLIT_QUESTION_TEXT);
691 } else {
692 String key = kualiConfiguration.getPropertyValueAsString(PurapKeyConstants.PURCHASE_ORDER_QUESTION_DOCUMENT);
693 message = StringUtils.replace(key, "{0}", operation);
694 }
695
696 return this.performQuestionWithInput(mapping, form, request, response, questionType, message, OLEConstants.CONFIRMATION_QUESTION, questionType, "");
697 } else {
698 Object buttonClicked = request.getParameter(OLEConstants.QUESTION_CLICKED_BUTTON);
699 if (question.equals(questionType) && buttonClicked.equals(ConfirmationQuestion.NO)) {
700
701
702 return returnToPreviousPage(mapping, kualiDocumentFormBase);
703 } else if (question.equals(confirmType) && buttonClicked.equals(SingleConfirmationQuestion.OK)) {
704
705
706
707 return mapping.findForward(OLEConstants.MAPPING_PORTAL);
708 } else {
709
710 String introNoteMessage = notePrefix + OLEConstants.BLANK_SPACE;
711 int noteTextLength = 0;
712
713 if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT)) {
714 if (StringUtils.isNotBlank(reason)) {
715 reasons = reason.split("/");
716 noteOne = introNoteMessage + reasons[0];
717 if (!reasons[1].equalsIgnoreCase(null)) {
718 noteTwo = introNoteMessage + reasons[1];
719 noteTextLength = noteTwo.length();
720 }
721
722 }
723 } else {
724 noteText = introNoteMessage + reason;
725 noteTextLength = noteText.length();
726 }
727
728
729 int noteTextMaxLength = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class).getAttributeMaxLength(Note.class, OLEConstants.NOTE_TEXT_PROPERTY_NAME).intValue();
730
731 String message = "";
732 String key = kualiConfiguration.getPropertyValueAsString(PurapKeyConstants.PURCHASE_ORDER_QUESTION_DOCUMENT);
733 message = StringUtils.replace(key, "{0}", operation);
734
735 if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT)) {
736 if (reasons == null || (reasons[0].trim().equalsIgnoreCase("null") && (reasons[1].trim().equalsIgnoreCase("null")))) {
737 reason = "";
738 return this.performQuestionWithInputAgainBecauseOfErrors(mapping, form, request, response, questionType, message, OLEConstants.CONFIRMATION_QUESTION, questionType, "", reason, OLEConstants.ERROR_CANCELLATION_REASON_REQUIRED, OLEConstants.QUESTION_REASON_ATTRIBUTE_NAME, "");
739 } else if (!reasons[1].equalsIgnoreCase(null) && (noteTextLength > noteTextMaxLength)) {
740 reason = "";
741 return this.performQuestionWithInputAgainBecauseOfErrors(mapping, form, request, response, questionType, message, OLEConstants.CONFIRMATION_QUESTION, questionType, "", reason, OLEConstants.ERROR_REASON, OLEConstants.QUESTION_REASON_ATTRIBUTE_NAME, new Integer(noteTextMaxLength - noteTextLength).toString());
742 }
743 }
744
745 if (StringUtils.isBlank(reason) || (noteTextLength > noteTextMaxLength)) {
746
747 int reasonLimit = noteTextMaxLength - noteTextLength;
748
749 if (ObjectUtils.isNull(reason)) {
750
751 reason = "";
752 }
753
754 return this.performQuestionWithInputAgainBecauseOfErrors(mapping, form, request, response, questionType, message, OLEConstants.CONFIRMATION_QUESTION, questionType, "", reason, PurapKeyConstants.ERROR_PURCHASE_ORDER_REASON_REQUIRED, OLEConstants.QUESTION_REASON_ATTRIBUTE_NAME, new Integer(reasonLimit).toString());
755 }
756 }
757 }
758
759 ActionForward returnActionForward = null;
760 if (!po.isPendingActionIndicator()) {
761
762
763
764
765
766
767
768 if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_SPLIT_DOCUMENT)) {
769 po.setPendingSplit(true);
770
771 ((PurchaseOrderForm) kualiDocumentFormBase).setSplitNoteText(noteText);
772 returnActionForward = mapping.findForward(OLEConstants.MAPPING_BASIC);
773 } else {
774 String newStatus = null;
775 if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT)) {
776
777 newStatus = PurchaseOrderStatuses.APPDOC_AMENDMENT;
778 po = SpringContext.getBean(PurchaseOrderService.class).createAndSavePotentialChangeDocument(kualiDocumentFormBase.getDocument().getDocumentNumber(), documentType, newStatus);
779 returnActionForward = mapping.findForward(OLEConstants.MAPPING_BASIC);
780 } else if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REOPEN_DOCUMENT)) {
781 newStatus = PurchaseOrderStatuses.APPDOC_PENDING_REOPEN;
782 po = SpringContext.getBean(PurchaseOrderService.class).createAndSavePotentialChangeDocument(kualiDocumentFormBase.getDocument().getDocumentNumber(), documentType, newStatus);
783 } else {
784 if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_CLOSE_DOCUMENT)) {
785 newStatus = PurchaseOrderStatuses.APPDOC_PENDING_CLOSE;
786 }
787
788
789
790 else if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT)) {
791 newStatus = PurchaseOrderStatuses.APPDOC_PENDING_VOID;
792 } else if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_PAYMENT_HOLD_DOCUMENT)) {
793 newStatus = PurchaseOrderStatuses.APPDOC_PENDING_PAYMENT_HOLD;
794 } else if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REMOVE_HOLD_DOCUMENT)) {
795 newStatus = PurchaseOrderStatuses.APPDOC_PENDING_REMOVE_HOLD;
796 } else if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_RETRANSMIT_DOCUMENT)) {
797 newStatus = PurchaseOrderStatuses.APPDOC_PENDING_RETRANSMIT;
798 }
799 po = SpringContext.getBean(PurchaseOrderService.class).createAndRoutePotentialChangeDocument(kualiDocumentFormBase.getDocument().getDocumentNumber(), documentType, kualiDocumentFormBase.getAnnotation(), combineAdHocRecipients(kualiDocumentFormBase), newStatus);
800 }
801 if (!GlobalVariables.getMessageMap().hasNoErrors()) {
802 throw new ValidationException("errors occurred during new PO creation");
803 }
804
805 String previousDocumentId = kualiDocumentFormBase.getDocId();
806
807 kualiDocumentFormBase.setDocument(po);
808 kualiDocumentFormBase.setDocId(po.getDocumentNumber());
809 kualiDocumentFormBase.setDocTypeName(po.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
810 if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT)) {
811 Note noteObjOne = new Note();
812 noteObjOne.setNoteText(noteOne);
813 noteObjOne.setNoteTypeCode(OLEConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE.getCode());
814 kualiDocumentFormBase.setNewNote(noteObjOne);
815
816 kualiDocumentFormBase.setAttachmentFile(new BlankFormFile());
817
818 insertBONote(mapping, kualiDocumentFormBase, request, response);
819
820 if (!reasons[1].trim().equalsIgnoreCase("null")) {
821 Note noteObjTwo = new Note();
822 noteObjTwo.setNoteText(noteTwo);
823 noteObjTwo.setNoteTypeCode(OLEConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE.getCode());
824 kualiDocumentFormBase.setNewNote(noteObjTwo);
825
826 kualiDocumentFormBase.setAttachmentFile(new BlankFormFile());
827
828 insertBONote(mapping, kualiDocumentFormBase, request, response);
829 }
830 } else {
831 Note newNote = new Note();
832 if (documentType.equals(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT)) {
833 noteText = noteText + " (Previous Document Id is " + previousDocumentId + ")";
834 }
835 newNote.setNoteText(noteText);
836 newNote.setNoteTypeCode(OLEConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE.getCode());
837 kualiDocumentFormBase.setNewNote(newNote);
838 kualiDocumentFormBase.setAttachmentFile(new BlankFormFile());
839 insertBONote(mapping, kualiDocumentFormBase, request, response);
840 }
841 }
842 if (StringUtils.isNotEmpty(messageType)) {
843 KNSGlobalVariables.getMessageList().add(messageType);
844 }
845 }
846 if (ObjectUtils.isNotNull(returnActionForward)) {
847 return returnActionForward;
848 } else {
849
850 return this.performQuestionWithoutInput(mapping, form, request, response, confirmType, kualiConfiguration.getPropertyValueAsString(messageType), PODocumentsStrings.SINGLE_CONFIRMATION_QUESTION, questionType, "");
851 }
852 } catch (ValidationException ve) {
853 throw ve;
854 }
855 }
856
857 @Override
858 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
859 LOG.debug("<<<---------Inside OlePurchaseOrderAction Refresh------>>>");
860 ActionForward forward = super.refresh(mapping, form, request, response);
861 OlePurchaseOrderForm rqForm = (OlePurchaseOrderForm) form;
862 PurchaseOrderDocument document = (PurchaseOrderDocument) rqForm.getDocument();
863 OlePurchaseOrderItem item = (OlePurchaseOrderItem) rqForm.getNewPurchasingItemLine();
864
865 if (document.getVendorDetail().getCurrencyType()!=null){
866 if(document.getVendorDetail().getCurrencyType().getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){
867 currencyTypeIndicator=true;
868 }
869 else{
870 currencyTypeIndicator=false;
871 }
872 }
873
874 if (document.getVendorDetail() != null) {
875 if (document.getVendorDetail().getVendorTransmissionFormat().size() > 0) {
876 List<VendorTransmissionFormatDetail> vendorTransmissionFormat = document.getVendorDetail().getVendorTransmissionFormat();
877 for (VendorTransmissionFormatDetail iter : vendorTransmissionFormat) {
878 if (iter.isVendorPreferredTransmissionFormat()) {
879 if (iter.getVendorTransmissionFormat().getVendorTransmissionFormat() != null) {
880 if (iter.getVendorTransmissionFormat().getVendorTransmissionFormat().equalsIgnoreCase(OleSelectConstant.VENDOR_TRANSMISSION_FORMAT_EDI)) {
881 document.setPurchaseOrderTransmissionMethodCode(OleSelectConstant.METHOD_OF_PO_TRANSMISSION_NOPR);
882 } else {
883 document.setPurchaseOrderTransmissionMethodCode(SpringContext.getBean(ParameterService.class).getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.PURAP_DEFAULT_PO_TRANSMISSION_CODE));
884 }
885 }
886 }
887 }
888 } else {
889 document.setPurchaseOrderTransmissionMethodCode(SpringContext.getBean(ParameterService.class).getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.PURAP_DEFAULT_PO_TRANSMISSION_CODE));
890 }
891 if ( (!currencyTypeIndicator) && item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
892 Long currencyTypeId = document.getVendorDetail().getCurrencyType().getCurrencyTypeId();
893 Map documentNumberMap = new HashMap();
894 documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, currencyTypeId);
895 BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
896 List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy(OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false);
897 Iterator iterator = exchangeRateList.iterator();
898 if (iterator.hasNext()) {
899 OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next();
900 item.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate()));
901 }
902 }
903 }
904 return forward;
905 }
906
907 @Override
908 public ActionForward amendPo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
909
910 ActionForward findForward = super.amendPo(mapping, form, request, response);
911 OlePurchaseOrderForm rqForm = (OlePurchaseOrderForm) form;
912 OlePurchaseOrderAmendmentDocument olePurchaseOrderAmendmentDocument = new OlePurchaseOrderAmendmentDocument();
913 if ((rqForm.getDocTypeName()).equalsIgnoreCase("OLE_POA")) {
914 rqForm.getAndResetNewPurchasingItemLine();
915 }
916 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
917 Document document = kualiDocumentFormBase.getDocument();
918
919 kualiDocumentFormBase.setDocId(document.getDocumentNumber());
920 kualiDocumentFormBase.setCommand(DOCUMENT_LOAD_COMMANDS[1]);
921
922 docHandler(mapping, form, request, response);
923
924 return findForward;
925 }
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941 @Override
942 public ActionForward firstTransmitPrintPo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
943 PurchaseOrderDocument poa = (PurchaseOrderDocument) ((PurchaseOrderForm) form).getDocument();
944 String poDocId = ((PurchaseOrderForm) form).getDocId();
945 ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
946 try {
947 SpringContext.getBean(OlePurchaseOrderService.class).performPurchaseOrderFirstTransmitViaPrinting(poDocId, baosPDF);
948 } finally {
949 if (baosPDF != null) {
950 baosPDF.reset();
951 }
952 }
953 String basePath = getApplicationBaseUrl();
954 String docId = ((PurchaseOrderForm) form).getDocId();
955 String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly";
956 String methodToCallDocHandler = "docHandler";
957 String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintPurchaseOrderPDF);
958 String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler);
959 request.setAttribute("printPOPDFUrl", printPOPDFUrl);
960 request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl);
961 String label = "";
962 if (OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT.equalsIgnoreCase(poa.getDocumentHeader().getWorkflowDocument().getDocumentTypeName())) {
963 label = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class).getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT);
964 } else {
965 label = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class).getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER);
966 }
967 request.setAttribute("purchaseOrderLabel", label);
968
969 return mapping.findForward("printPurchaseOrderPDF");
970 }
971
972 public ActionForward printPo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
973 PurchaseOrderDocument poa = (PurchaseOrderDocument) ((PurchaseOrderForm) form).getDocument();
974 String poDocId = ((PurchaseOrderForm) form).getDocId();
975 ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
976 try {
977 SpringContext.getBean(OlePurchaseOrderService.class).performPurchaseOrderFirstTransmitViaPrinting(poDocId, baosPDF);
978
979
980 } finally {
981 if (baosPDF != null) {
982 baosPDF.reset();
983 }
984 }
985 String basePath = getApplicationBaseUrl();
986 String docId = ((PurchaseOrderForm) form).getDocId();
987 String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly";
988 String methodToCallDocHandler = "docHandler";
989 String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintPurchaseOrderPDF);
990 String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler);
991 request.setAttribute("printPOPDFUrl", printPOPDFUrl);
992 request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl);
993 String label = "";
994 if (OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT.equalsIgnoreCase(poa.getDocumentHeader().getWorkflowDocument().getDocumentTypeName())) {
995 label = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class).getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT);
996 } else {
997 label = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class).getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER);
998 }
999 request.setAttribute("purchaseOrderLabel", label);
1000
1001 return mapping.findForward("printPurchaseOrderPDF");
1002 }
1003
1004
1005
1006
1007
1008 @Override
1009 public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1010
1011 PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form;
1012
1013
1014 int itemIndex = getSelectedLine(request);
1015 PurApItem item = null;
1016
1017
1018 if (processCustomInsertAccountingLine(purapForm, request) == false) {
1019 String errorPrefix = null;
1020 PurApAccountingLine line = null;
1021
1022 boolean rulePassed = false;
1023 if (itemIndex >= 0) {
1024 item = ((PurchasingAccountsPayableDocument) purapForm.getDocument()).getItem((itemIndex));
1025
1026 PurApAccountingLine lineItem = item.getNewSourceLine();
1027 if (lineItem.getAccountLinePercent() != null) {
1028 BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100));
1029 lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent))));
1030 } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent() == null) {
1031 KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100));
1032 BigDecimal dollarToPercent = dollar.bigDecimalValue().divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR);
1033 lineItem.setAccountLinePercent(dollarToPercent);
1034 }
1035 line = (PurApAccountingLine) ObjectUtils.deepCopy(lineItem);
1036
1037
1038 errorPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + Integer.toString(itemIndex) + "]." + OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME;
1039 rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
1040 } else if (itemIndex == -2) {
1041
1042
1043 line = ((PurchasingFormBase) purapForm).getAccountDistributionnewSourceLine();
1044
1045 errorPrefix = PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE;
1046 rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
1047 }
1048 AccountingLineBase accountingLineBase = (AccountingLineBase) item.getNewSourceLine();
1049 if (accountingLineBase != null) {
1050 String accountNumber = accountingLineBase.getAccountNumber();
1051 String chartOfAccountsCode = accountingLineBase.getChartOfAccountsCode();
1052 Map<String, String> criteria = new HashMap<String, String>();
1053 criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
1054 criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
1055 Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class,
1056 criteria);
1057 rulePassed = checkForValidAccount(account);
1058 }
1059 if (rulePassed) {
1060
1061 SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line);
1062
1063 PurApAccountingLine newSourceLine = item.getNewSourceLine();
1064 List<PurApAccountingLine> existingSourceLine = item.getSourceAccountingLines();
1065
1066 BigDecimal initialValue = new BigDecimal(0);
1067
1068 for (PurApAccountingLine accountLine : existingSourceLine) {
1069 initialValue = initialValue.add(accountLine.getAccountLinePercent());
1070 }
1071 if (itemIndex >= 0) {
1072
1073 if ((newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED && newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.MAX_PERCENT.subtract(initialValue).intValue()) && newSourceLine.getAccountLinePercent().intValue() > OleSelectConstant.ZERO) {
1074 if (OleSelectConstant.MAX_PERCENT.subtract(initialValue).intValue() != OleSelectConstant.ZERO) {
1075 insertAccountingLine(purapForm, item, line);
1076 }
1077 }else {
1078 checkAccountingLinePercent(newSourceLine);
1079
1080 }
1081 for(PurApAccountingLine oldSourceAccountingLine:item.getSourceAccountingLines()) {
1082 if(oldSourceAccountingLine instanceof OlePurchaseOrderAccount) {
1083 ((OlePurchaseOrderAccount)oldSourceAccountingLine).setExistingAmount(oldSourceAccountingLine.getAmount());
1084 }
1085 }
1086 List<PurApAccountingLine> existingAccountingLine = item.getSourceAccountingLines();
1087 BigDecimal totalPercent = new BigDecimal(100);
1088 BigDecimal initialPercent = new BigDecimal(0);
1089 for (PurApAccountingLine purApAccountingLine : existingAccountingLine) {
1090 initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent());
1091
1092 }
1093 initialPercent = totalPercent.subtract(initialPercent);
1094 BigDecimal maxPercent = initialPercent.max(OleSelectConstant.ZERO_PERCENT);
1095 if (maxPercent.intValue() == OleSelectConstant.ZERO) {
1096 item.resetAccount(OleSelectConstant.ZERO_PERCENT);
1097
1098 } else {
1099 item.resetAccount(initialPercent);
1100
1101 }
1102 } else if (itemIndex == -2) {
1103
1104 ((PurchasingFormBase) purapForm).addAccountDistributionsourceAccountingLine(line);
1105 }
1106 }
1107 }
1108
1109 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1110 }
1111
1112 private void checkAccountingLinePercent(PurApAccountingLine newSourceLine) {
1113 if (newSourceLine.getAccountLinePercent().intValue() >= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED) {
1114 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1115 OleSelectPropertyConstants.ERROR_PERCENT_SHOULD_GREATER, OleSelectConstant.PERCENT);
1116 } else if (newSourceLine.getAccountLinePercent().intValue() == OleSelectConstant.ZERO) {
1117 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1118 OleSelectPropertyConstants.ERROR_PERCENT_ZERO, OleSelectConstant.PERCENT);
1119 } else {
1120
1121 }
1122
1123 }
1124
1125 private boolean checkForValidAccount(Account account) {
1126 boolean result = true;
1127 if (account != null) {
1128 String subFundGroupParameter = getParameterService().getParameterValueAsString(Account.class,
1129 OleSelectConstant.SUB_FUND_GRP_CD);
1130 if (account.getSubFundGroupCode().equalsIgnoreCase(subFundGroupParameter)) {
1131 GlobalVariables.getMessageMap()
1132 .putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1133 OleSelectPropertyConstants.ERROR_ACCOUNT_NUMBER,
1134 new String[]{OleSelectConstant.PURCHASE_ORDER});
1135 result = false;
1136 }
1137 }
1138 return result;
1139 }
1140
1141 private void setItemDescription(OlePurchaseOrderItem item, String fileName) throws Exception{
1142 if (OleDocstoreResponse.getInstance().getEditorResponse() != null) {
1143 Map<String, OLEEditorResponse> oleEditorResponses = OleDocstoreResponse.getInstance().getEditorResponse();
1144 OLEEditorResponse oleEditorResponse = oleEditorResponses.get(fileName);
1145 Bib bib = oleEditorResponse != null ? oleEditorResponse.getBib() : null;
1146 bib = (Bib) bib.deserializeContent(bib);
1147 if (bib != null) {
1148 String title = (bib.getTitle() != null&& !bib.getTitle().isEmpty()) ? bib.getTitle() + ", " : "";
1149 String author = (bib.getAuthor()!=null && !bib.getAuthor().isEmpty()) ? bib.getAuthor() + ", " : "";
1150 String publisher = (bib.getPublisher()!=null && !bib.getPublisher().isEmpty()) ? bib.getPublisher() + ", " : "";
1151 String isbn = (bib.getIsbn()!=null && !bib.getIsbn().isEmpty()) ? bib.getIsbn() + ", " : "";
1152 String description = title + author + publisher + isbn;
1153 item.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(bib.getId().toString()));
1154 item.setItemDescription(description.substring(0, (description.lastIndexOf(","))));
1155 }
1156 if (bib != null) {
1157 item.setBibUUID(bib.getId());
1158 item.setItemTitleId(bib.getId());
1159 item.setLinkToOrderOption(oleEditorResponse.getLinkToOrderOption());
1160 }
1161 OleDocstoreResponse.getInstance().getEditorResponse().remove(oleEditorResponse);
1162 }
1163 }
1164
1165
1166
1167 public ActionForward addCopy(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1168 HttpServletResponse response) throws Exception {
1169 LOG.debug("Inside addCopy Method of OleRequisitionAction");
1170 OlePurchaseOrderForm purchasingForm = (OlePurchaseOrderForm) form;
1171 OlePurchaseOrderAmendmentDocument purDocument = (OlePurchaseOrderAmendmentDocument) purchasingForm
1172 .getDocument();
1173 int line = this.getSelectedLine(request);
1174 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) purchasingForm
1175 .getDocument()).getItem(line);
1176 OleRequisitionCopies itemCopy = new OleRequisitionCopies();
1177 OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
1178 boolean isValid = true;
1179 List<String> volChar = new ArrayList<>();
1180 String[] volNumbers = item.getVolumeNumber() != null ? item.getVolumeNumber().split(",") : new String[0];
1181 for (String volStr : volNumbers) {
1182 volChar.add(volStr);
1183 }
1184 Integer itemCount = volChar.size();
1185 isValid = oleCopyHelperService.checkCopyEntry(
1186 item.getItemCopies(), item.getLocationCopies(), itemCount, item.getItemQuantity(), item.getItemNoOfParts(), item.getCopies(), item.getVolumeNumber(), false);
1187 if (isValid) {
1188 itemCopy.setItemCopies(item.getItemCopies());
1189 itemCopy.setLocationCopies(item.getLocationCopies());
1190 itemCopy.setParts(item.getItemNoOfParts());
1191 itemCopy.setStartingCopyNumber(item.getStartingCopyNumber());
1192 itemCopy.setCaption(item.getCaption());
1193 itemCopy.setVolumeNumber(item.getVolumeNumber());
1194 List<OleCopy> copyList = oleCopyHelperService.setCopyValues(itemCopy, item.getItemTitleId(), volChar);
1195
1196 if (StringUtils.isNotEmpty(item.getItemLocation())) {
1197 if (!item.getItemLocation().equalsIgnoreCase(item.getLocationCopies()) && !item.isLocationFlag() && item.getCopyList().size()==1) {
1198 KRADServiceLocator.getBusinessObjectService().delete(item.getCopyList().get(0));
1199 item.getCopyList().clear();
1200 item.getCopyList().addAll(copyList);
1201 item.setLocationFlag(true);
1202 }
1203 else {
1204 if (item.getCopyList().size() == 1) {
1205 KRADServiceLocator.getBusinessObjectService().delete(item.getCopyList().get(0));
1206 item.getCopyList().clear();
1207 }
1208 item.getCopyList().addAll(copyList);
1209 }
1210 }
1211 else {
1212 item.getCopyList().addAll(copyList);
1213 }
1214 item.getCopies().add(itemCopy);
1215 item.setParts(null);
1216 item.setItemCopies(null);
1217 item.setPartEnumeration(null);
1218 item.setLocationCopies(null);
1219 item.setCaption(null);
1220 item.setVolumeNumber(null);
1221
1222
1223
1224
1225
1226
1227
1228 }
1229
1230 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1231 }
1232
1233 public boolean checkForCopiesAndLocation(OlePurchaseOrderItem item) {
1234 boolean isValid = true;
1235 if (null == item.getItemCopies() || null == item.getLocationCopies()) {
1236 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1237 OLEConstants.ITEM_ITEMCOPIES_OR_LOCATIONCOPIES_SHOULDNOT_BE_NULL, new String[]{});
1238 isValid = false;
1239 }
1240 return isValid;
1241 }
1242
1243 public boolean checkForItemCopiesGreaterThanQuantity(OlePurchaseOrderItem item) {
1244 boolean isValid = true;
1245 if (item.getItemCopies().isGreaterThan(item.getItemQuantity())) {
1246 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1247 OLEConstants.ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
1248 isValid = false;
1249 }
1250 return isValid;
1251 }
1252
1253 public boolean checkForTotalCopiesGreaterThanQuantity(OlePurchaseOrderItem item) {
1254 boolean isValid = true;
1255 int copies = 0;
1256 if (item.getCopies().size() > 0) {
1257 for (int itemCopies = 0; itemCopies < item.getCopies().size(); itemCopies++) {
1258 copies = copies + item.getCopies().get(itemCopies).getItemCopies().intValue();
1259 }
1260 if (item.getItemQuantity().isLessThan(item.getItemCopies().add(new KualiDecimal(copies)))) {
1261 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1262 OLEConstants.TOTAL_OF_ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
1263 isValid = false;
1264 }
1265 }
1266 return isValid;
1267 }
1268
1269
1270
1271
1272
1273
1274
1275
1276 public OleRequisitionCopies setCopyValues(OlePurchaseOrderItem item) {
1277 OleRequisitionCopies itemCopy = new OleRequisitionCopies();
1278 itemCopy.setParts(item.getItemNoOfParts());
1279 itemCopy.setItemCopies(item.getItemCopies());
1280 StringBuffer enumeration = new StringBuffer();
1281 if (item.getStartingCopyNumber() != null && item.getStartingCopyNumber().isNonZero()) {
1282 itemCopy.setStartingCopyNumber(item.getStartingCopyNumber());
1283 } else {
1284 int startingCopies = 1;
1285 for (int copy = 0; copy < item.getCopies().size(); copy++) {
1286 startingCopies = startingCopies + item.getCopies().get(copy).getItemCopies().intValue();
1287 }
1288 itemCopy.setStartingCopyNumber(new KualiInteger(startingCopies));
1289 }
1290 String partEnumerationCopy = getConfigurationService().getPropertyValueAsString(
1291 OLEConstants.PART_ENUMERATION_COPY);
1292 String partEnumerationVolume = getConfigurationService().getPropertyValueAsString(
1293 OLEConstants.PART_ENUMERATION_VOLUME);
1294 int startingCopyNumber = itemCopy.getStartingCopyNumber().intValue();
1295 for (int noOfCopies = 0; noOfCopies < item.getItemCopies().intValue(); noOfCopies++) {
1296 for (int noOfParts = 0; noOfParts < item.getItemNoOfParts().intValue(); noOfParts++) {
1297 int newNoOfCopies = startingCopyNumber + noOfCopies;
1298 int newNoOfParts = noOfParts + 1;
1299 if (noOfCopies + 1 == item.getItemCopies().intValue()
1300 && newNoOfParts == item.getItemNoOfParts().intValue()) {
1301 enumeration = enumeration.append(
1302 partEnumerationCopy + newNoOfCopies + OLEConstants.DOT_TO_SEPARATE_COPIES_PARTS).append(
1303 partEnumerationVolume + newNoOfParts);
1304 } else {
1305 enumeration = enumeration.append(
1306 partEnumerationCopy + newNoOfCopies + OLEConstants.DOT_TO_SEPARATE_COPIES_PARTS).append(
1307 partEnumerationVolume + newNoOfParts + OLEConstants.COMMA_TO_SEPARATE_ENUMERATION);
1308 }
1309 }
1310 }
1311 itemCopy.setPartEnumeration(enumeration.toString());
1312 itemCopy.setLocationCopies(item.getLocationCopies());
1313 return itemCopy;
1314 }
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326 public ActionForward deleteCopy(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1327 HttpServletResponse response) throws Exception {
1328 LOG.debug("Inside deleteCopy Method of OleRequisitionAction");
1329 OlePurchaseOrderForm purchasingForm = (OlePurchaseOrderForm) form;
1330 String[] indexes = getSelectedLineForAccounts(request);
1331 int itemIndex = Integer.parseInt(indexes[0]);
1332 int copyIndex = Integer.parseInt(indexes[1]);
1333 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) purchasingForm
1334 .getDocument()).getItem((itemIndex));
1335 List<OleCopy> copyList = new ArrayList<>();
1336 for(int i=0;i<item.getCopyList().size();i++){
1337 OleCopy oleCopy = item.getCopyList().get(i);
1338 if(item.getCopies().get(copyIndex).getLocationCopies().equalsIgnoreCase(oleCopy.getLocation())){
1339 copyList.add(oleCopy);
1340 }
1341 }
1342 for(OleCopy copy : copyList){
1343 item.getCopyList().remove(copy);
1344 item.getDeletedCopiesList().add(copy);
1345 }
1346 item.getCopies().remove(copyIndex);
1347 LOG.debug("Selected Copy is Remove");
1348 LOG.debug("Leaving deleteCopy Method of OleRequisitionAction");
1349 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1350 }
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362 public ActionForward addPaymentHistory(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1363 HttpServletResponse response) throws Exception {
1364 OlePurchaseOrderForm purchasingForm = (OlePurchaseOrderForm) form;
1365 int line = this.getSelectedLine(request);
1366 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) purchasingForm
1367 .getDocument()).getItem(line);
1368 OleRequisitionPaymentHistory paymentHistory = new OleRequisitionPaymentHistory();
1369 paymentHistory.setPaymentHistory("");
1370 item.getRequisitionPaymentHistory().add(paymentHistory);
1371 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1372 }
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384 public ActionForward deletePaymentHistory(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1385 HttpServletResponse response) throws Exception {
1386
1387 OlePurchaseOrderForm purchasingForm = (OlePurchaseOrderForm) form;
1388 String[] indexes = getSelectedLineForAccounts(request);
1389 int itemIndex = Integer.parseInt(indexes[0]);
1390 int copyIndex = Integer.parseInt(indexes[1]);
1391 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) purchasingForm
1392 .getDocument()).getItem((itemIndex));
1393 item.getRequisitionPaymentHistory().remove(copyIndex);
1394 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1395 }
1396
1397 public static ConfigurationService getConfigurationService() {
1398 if (kualiConfigurationService == null) {
1399 kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
1400 }
1401 return kualiConfigurationService;
1402 }
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432 @Override
1433 public ActionForward blanketApprove(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1434 HttpServletResponse response) throws Exception {
1435 PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
1436 PurchasingDocument document = (PurchasingDocument) ((PurchasingFormBase) form).getDocument();
1437 this.calculate(mapping, purchasingForm, request, response);
1438 Iterator itemIterator = document.getItems().iterator();
1439 boolean rulePassed = true;
1440 while (itemIterator.hasNext()) {
1441 OlePurchaseOrderItem tempItem = (OlePurchaseOrderItem) itemIterator.next();
1442 if (tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)) {
1443 if (tempItem.getCopyList().size()==OLEConstants.ZERO && tempItem.getItemQuantity() != null && tempItem.getItemNoOfParts() != null && !tempItem.getItemQuantity().isGreaterThan(OLEConstants.ONE.kualiDecimalValue())
1444 && !tempItem.getItemNoOfParts().isGreaterThan(OLEConstants.ONE)) {
1445 OleCopy oleCopy = new OleCopy();
1446 oleCopy.setLocation(tempItem.getItemLocation());
1447 oleCopy.setBibId(tempItem.getItemTitleId());
1448 if (StringUtils.isNotBlank(tempItem.getLinkToOrderOption()) && (tempItem.getLinkToOrderOption().equals(OLEConstants.NB_PRINT) || tempItem.getLinkToOrderOption().equals(OLEConstants.EB_PRINT))) {
1449 oleCopy.setCopyNumber(tempItem.getSingleCopyNumber() != null && !tempItem.getSingleCopyNumber().isEmpty() ? tempItem.getSingleCopyNumber() : null);
1450 }
1451 oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.NOT_RECEIVED_STATUS);
1452 List<OleCopy> copyList = new ArrayList<>();
1453 copyList.add(oleCopy);
1454 tempItem.setCopyList(copyList);
1455 }
1456 if(tempItem.getItemIdentifier()!=null && tempItem.getItemQuantity() != null && tempItem.getItemNoOfParts() != null && !tempItem.getItemQuantity().isGreaterThan(OLEConstants.ONE.kualiDecimalValue())
1457 && !tempItem.getItemNoOfParts().isGreaterThan(OLEConstants.ONE)){
1458 Map<String,String> map=new HashMap<>();
1459 map.put(OLEConstants.PO_ID,tempItem.getItemIdentifier().toString());
1460 List<OleCopy> oleCopyList =(List<OleCopy>)SpringContext.getBean(BusinessObjectService.class).findMatching(OleCopy.class, map);
1461 if(oleCopyList.size()==1){
1462 tempItem.getCopyList().get(0).setCopyNumber(tempItem.getSingleCopyNumber()!=null && !tempItem.getSingleCopyNumber().isEmpty()?tempItem.getSingleCopyNumber():null);
1463 }
1464 }
1465 List<PurApAccountingLine> accountingLineBase = tempItem.getSourceAccountingLines();
1466 if (accountingLineBase != null) {
1467 for (int accountingLine = 0; accountingLine < accountingLineBase.size(); accountingLine++) {
1468 String accountNumber = accountingLineBase.get(accountingLine).getAccountNumber();
1469 String chartOfAccountsCode = accountingLineBase.get(accountingLine).getChartOfAccountsCode();
1470 Map<String, String> criteria = new HashMap<String, String>();
1471 criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
1472 criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
1473 Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
1474 Account.class, criteria);
1475 rulePassed = checkForValidAccount(account);
1476 if (!rulePassed) {
1477 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1478 }
1479 }
1480 }
1481 }
1482 if (tempItem.getItemIdentifier() != null) {
1483 Map map = new HashMap();
1484 map.put(OLEConstants.PO_ID, tempItem.getItemIdentifier().toString());
1485 List<OLELinkPurapDonor> linkPurapDonors = (List<OLELinkPurapDonor>) getBusinessObjectService().findMatching(OLELinkPurapDonor.class, map);
1486 if (linkPurapDonors != null && linkPurapDonors.size() > 0) {
1487 getBusinessObjectService().delete(linkPurapDonors);
1488 }
1489 }
1490 }
1491 return super.blanketApprove(mapping, form, request, response);
1492 }
1493
1494 public ActionForward selectVendor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1495 OlePurchaseOrderForm purchasingForm = (OlePurchaseOrderForm) form;
1496 OlePurchaseOrderAmendmentDocument document = (OlePurchaseOrderAmendmentDocument) purchasingForm.getDocument();
1497 if ((purchasingForm.getDocTypeName()).equalsIgnoreCase("OLE_POA")) {
1498 if (document.getVendorAliasName() != null && document.getVendorAliasName().length() > 0) {
1499
1500 Map vendorAliasMap = new HashMap();
1501 vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, document.getVendorAliasName());
1502 org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
1503 List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
1504 if (vendorAliasList != null && vendorAliasList.size() > 0) {
1505 Map vendorDetailMap = new HashMap();
1506 vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier());
1507 vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, vendorAliasList.get(0).getVendorDetailAssignedIdentifier());
1508 VendorDetail vendorDetail = businessObject.findByPrimaryKey(VendorDetail.class, vendorDetailMap);
1509 document.setVendorDetail(vendorDetail);
1510 document.setVendorHeaderGeneratedIdentifier(vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier());
1511 document.setVendorDetailAssignedIdentifier(vendorAliasList.get(0).getVendorDetailAssignedIdentifier());
1512 refreshVendor(mapping, form, request, response);
1513 } else {
1514 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
1515 }
1516 }
1517 }
1518 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1519 }
1520
1521 public ActionForward refreshVendor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1522 PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;
1523 PurchasingDocument document = (PurchasingDocument) baseForm.getDocument();
1524 if (StringUtils.equals(OLEConstants.REFRESH_VENDOR_CALLER, VendorConstants.VENDOR_LOOKUPABLE_IMPL) && document.getVendorDetailAssignedIdentifier() != null && document.getVendorHeaderGeneratedIdentifier() != null) {
1525 document.setVendorContractGeneratedIdentifier(null);
1526 document.refreshReferenceObject(OLEConstants.VENDOR_CONTRACT);
1527
1528
1529 document.refreshReferenceObject(OLEConstants.VENDOR_DETAILS);
1530 document.templateVendorDetail(document.getVendorDetail());
1531
1532
1533 VendorAddress defaultAddress = null;
1534 if(document.getVendorDetail()!=null && document.getVendorDetail().getVendorAddresses()!=null && document.getVendorDetail().getVendorHeader()!=null && document.getVendorDetail().getVendorHeader().getVendorType()!=null && document.getVendorDetail().getVendorHeader().getVendorType().getAddressType()!=null && document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode()!=null){
1535 defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), document.getDeliveryCampusCode());
1536 }
1537 document.templateVendorAddress(defaultAddress);
1538 }
1539 return super.refresh(mapping, form, request, response);
1540 }
1541
1542 private LookupService getLookupService() {
1543 return KRADServiceLocatorWeb.getLookupService();
1544 }
1545
1546 @Override
1547 public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1548 Object question = request.getParameter(OLEConstants.QUESTION_INST_ATTRIBUTE_NAME);
1549
1550 ConfigurationService kualiConfiguration = SpringContext.getBean(ConfigurationService.class);
1551
1552
1553 if (question == null) {
1554
1555
1556 return this.performQuestionWithoutInput(mapping, form, request, response, OLEConstants.DOCUMENT_CANCEL_QUESTION, kualiConfiguration.getPropertyValueAsString("document.question.cancel.text"), OLEConstants.CONFIRMATION_QUESTION, OLEConstants.MAPPING_CANCEL, "");
1557 } else {
1558 Object buttonClicked = request.getParameter(OLEConstants.QUESTION_CLICKED_BUTTON);
1559 if ((OLEConstants.DOCUMENT_CANCEL_QUESTION.equals(question)) && ConfirmationQuestion.NO.equals(buttonClicked)) {
1560
1561
1562 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1563 }
1564
1565 }
1566 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
1567 OlePurchaseOrderForm purchaseOrderForm = (OlePurchaseOrderForm) form;
1568 if ((purchaseOrderForm.getDocTypeName()).equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT)) {
1569 List<Note> noteList = new ArrayList<Note>();
1570
1571 if (kualiDocumentFormBase.getDocument().getNotes().size() > 0) {
1572 for (Note note : (List<Note>) kualiDocumentFormBase.getDocument().getNotes()) {
1573 noteList.add(note);
1574 getBusinessObjectService().delete(note);
1575 }
1576 }
1577 SpringContext.getBean(DocumentService.class).cancelDocument(kualiDocumentFormBase.getDocument(), kualiDocumentFormBase.getAnnotation());
1578 if (noteList.size() > 0) {
1579 getBusinessObjectService().save(noteList);
1580 }
1581
1582 return returnToSender(request, mapping, kualiDocumentFormBase);
1583 }
1584 return returnToSender(request, mapping, kualiDocumentFormBase);
1585 }
1586
1587 public ActionForward addDonor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1588 boolean flag = true;
1589 PurchaseOrderForm purchasingForm = (PurchaseOrderForm) form;
1590 int line = this.getSelectedLine(request);
1591 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItem(line);
1592 Map map = new HashMap();
1593 if (item.getDonorCode() != null) {
1594 map.put(OLEConstants.DONOR_CODE, item.getDonorCode());
1595 List<OLEDonor> oleDonorList = (List<OLEDonor>) getLookupService().findCollectionBySearch(OLEDonor.class, map);
1596 if (oleDonorList != null && oleDonorList.size() > 0) {
1597 OLEDonor oleDonor = oleDonorList.get(0);
1598 if (oleDonor != null) {
1599 for (OLELinkPurapDonor oleLinkPurapDonor : item.getOleDonors()) {
1600 if (oleLinkPurapDonor.getDonorCode().equalsIgnoreCase(item.getDonorCode())) {
1601 flag = false;
1602 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1603 OLEConstants.DONOR_CODE_EXISTS, new String[]{});
1604 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1605 }
1606 }
1607 if (flag) {
1608 OLELinkPurapDonor donor = new OLELinkPurapDonor();
1609 donor.setDonorId(oleDonor.getDonorId());
1610 donor.setDonorCode(oleDonor.getDonorCode());
1611 item.getOleDonors().add(donor);
1612 item.setDonorCode(null);
1613 }
1614 }
1615 } else {
1616 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1617 OLEConstants.ERROR_DONOR_CODE, new String[]{});
1618 }
1619 }
1620 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1621 }
1622
1623 public ActionForward deleteDonor(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1624 HttpServletResponse response) throws Exception {
1625 PurchaseOrderForm purchasingForm = (PurchaseOrderForm) form;
1626 String[] indexes = getSelectedLineForAccounts(request);
1627 int itemIndex = Integer.parseInt(indexes[0]);
1628 int donorIndex = Integer.parseInt(indexes[1]);
1629 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItem((itemIndex));
1630 item.getOleDonors().remove(donorIndex);
1631 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1632 }
1633
1634 @Override
1635 protected ActionForward performQuestionWithInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionId, String questionText, String questionType, String caller, String context) throws Exception {
1636 return performQuestion(mapping, form, request, response, questionId, questionText, questionType, caller, context, true, "", "", "", "");
1637 }
1638
1639
1640 private ActionForward performQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionId, String questionText, String questionType, String caller, String context, boolean showReasonField, String reason, String errorKey, String errorPropertyName, String errorParameter) throws Exception {
1641 Properties parameters = new Properties();
1642
1643 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start");
1644 parameters.put(KRADConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form));
1645 parameters.put(KRADConstants.CALLING_METHOD, caller);
1646 parameters.put(KRADConstants.QUESTION_INST_ATTRIBUTE_NAME, questionId);
1647 parameters.put(KRADConstants.QUESTION_IMPL_ATTRIBUTE_NAME, questionType);
1648
1649 parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation(request, mapping));
1650 parameters.put(KRADConstants.QUESTION_CONTEXT, context);
1651 parameters.put(KRADConstants.QUESTION_SHOW_REASON_FIELD, Boolean.toString(showReasonField));
1652 parameters.put(KRADConstants.QUESTION_REASON_ATTRIBUTE_NAME, reason);
1653 parameters.put(KRADConstants.QUESTION_ERROR_KEY, errorKey);
1654 parameters.put(KRADConstants.QUESTION_ERROR_PROPERTY_NAME, errorPropertyName);
1655 parameters.put(KRADConstants.QUESTION_ERROR_PARAMETER, errorParameter);
1656 parameters.put(KRADConstants.QUESTION_ANCHOR, form instanceof KualiForm ? org.apache.commons.lang.ObjectUtils.toString(((KualiForm) form).getAnchor()) : "");
1657 Object methodToCallAttribute = request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
1658 if (methodToCallAttribute != null) {
1659 parameters.put(KRADConstants.METHOD_TO_CALL_PATH, methodToCallAttribute);
1660 ((PojoForm) form).registerEditableProperty(String.valueOf(methodToCallAttribute));
1661 }
1662
1663 if (form instanceof KualiDocumentFormBase) {
1664 String docNum = ((KualiDocumentFormBase) form).getDocument().getDocumentNumber();
1665 if(docNum != null){
1666 parameters.put(KRADConstants.DOC_NUM, ((KualiDocumentFormBase) form)
1667 .getDocument().getDocumentNumber());
1668 }
1669 }
1670
1671
1672 String questionTextAttributeName = KRADConstants.QUESTION_TEXT_ATTRIBUTE_NAME + questionId;
1673 GlobalVariables.getUserSession().addObject(questionTextAttributeName, (Object)questionText);
1674 String questionUrl = null;
1675 if (questionId.equalsIgnoreCase(PODocumentsStrings.VOID_QUESTION)) {
1676 questionUrl = UrlFactory.parameterizeUrl(getApplicationBaseUrl() + OLEConstants.QUESTION_ACTION , parameters);
1677 } else {
1678 questionUrl = UrlFactory.parameterizeUrl(getApplicationBaseUrl() + "/kr/" + KRADConstants.QUESTION_ACTION, parameters);
1679 }
1680
1681 return new ActionForward(questionUrl, true);
1682 }
1683
1684 @Override
1685 protected ActionForward performQuestionWithInputAgainBecauseOfErrors(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String questionId, String questionText, String questionType, String caller, String context, String reason, String errorKey, String errorPropertyName, String errorParameter) throws Exception {
1686 return performQuestion(mapping, form, request, response, questionId, questionText, questionType, caller, context, true, reason, errorKey, errorPropertyName, errorParameter);
1687 }
1688
1689 public ActionForward populateAccountingLines(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1690 HttpServletResponse response) throws Exception {
1691
1692 OlePurchaseOrderForm olePurchaseOrderForm = (OlePurchaseOrderForm) form;
1693 int line = this.getSelectedLine(request);
1694 OlePurchaseOrderItem item = (OlePurchaseOrderItem) ((PurchasingAccountsPayableDocument) olePurchaseOrderForm.getDocument()).getItem(line);
1695 Map fundMap = new HashMap();
1696 if (item.getFundCode() != null && !item.getFundCode().trim().isEmpty()) {
1697 fundMap.put(org.kuali.ole.OLEConstants.OLEEResourceRecord.FUND_CODE, item.getFundCode());
1698 List<OleFundCode> oleFundCodes = (List<OleFundCode>) getLookupService().findCollectionBySearch(OleFundCode.class, fundMap);
1699 if (oleFundCodes != null && oleFundCodes.size() > 0) {
1700 OleFundCode oleFundCode = oleFundCodes.get(0);
1701 if (oleFundCode != null) {
1702 if (oleFundCode.getOleFundCodeAccountingLineList() != null) {
1703 OlePurchaseOrderAccount account = new OlePurchaseOrderAccount();
1704 List<PurApAccountingLine> accountingLines = new ArrayList<PurApAccountingLine>();
1705 for (OleFundCodeAccountingLine accountingLine : oleFundCode.getOleFundCodeAccountingLineList()) {
1706 if (accountingLine.getPercentage() != null) {
1707 account.setAccountLinePercent(accountingLine.getPercentage());
1708 }
1709 account.setChartOfAccountsCode(accountingLine.getChartCode());
1710 account.setAccountNumber(accountingLine.getAccountNumber());
1711 account.setSubAccountNumber(accountingLine.getSubAccount());
1712 account.setFinancialObjectCode(accountingLine.getObjectCode());
1713 account.setFinancialSubObjectCode(accountingLine.getSubObject());
1714 account.setProjectCode(accountingLine.getProject());
1715 account.setOrganizationReferenceId(accountingLine.getOrgRefId());
1716 accountingLines.add((PurApAccountingLine) account);
1717 }
1718 item.getSourceAccountingLines().addAll(accountingLines);
1719 }
1720 }
1721 } else {
1722 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1723 OLEConstants.ERROR_FUND_CODE, new String[]{});
1724 }
1725 }else{
1726 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1727 OLEConstants.EMPTY_FUND_CODE, new String[]{});
1728 }
1729 item.setFundCode(null);
1730 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1731 }
1732
1733 }
1734
1735