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.StringUtils;
19 import org.apache.struts.action.ActionForm;
20 import org.apache.struts.action.ActionForward;
21 import org.apache.struts.action.ActionMapping;
22 import org.kuali.ole.DocumentUniqueIDPrefix;
23 import org.kuali.ole.coa.businessobject.Account;
24 import org.kuali.ole.coa.businessobject.OleFundCode;
25 import org.kuali.ole.coa.businessobject.OleFundCodeAccountingLine;
26 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
27 import org.kuali.ole.docstore.common.document.Bib;
28 import org.kuali.ole.docstore.common.document.Holdings;
29 import org.kuali.ole.module.purap.PurapConstants;
30 import org.kuali.ole.module.purap.PurapKeyConstants;
31 import org.kuali.ole.module.purap.PurapParameterConstants;
32 import org.kuali.ole.module.purap.PurapPropertyConstants;
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.PurchasingAccountsPayableDocument;
36 import org.kuali.ole.module.purap.document.PurchasingDocument;
37 import org.kuali.ole.module.purap.document.RequisitionDocument;
38 import org.kuali.ole.module.purap.document.service.OlePurapService;
39 import org.kuali.ole.module.purap.document.service.PurapService;
40 import org.kuali.ole.pojo.OleBibRecord;
41 import org.kuali.ole.pojo.OleEditorResponse;
42 import org.kuali.ole.select.OleSelectConstant;
43 import org.kuali.ole.select.bo.OLEDonor;
44 import org.kuali.ole.select.bo.OLELinkPurapDonor;
45 import org.kuali.ole.select.bo.OLEEditorResponse;
46 import org.kuali.ole.select.businessobject.*;
47 import org.kuali.ole.select.constants.OleSelectPropertyConstants;
48 import org.kuali.ole.select.document.OleDefaultValueAssignment;
49 import org.kuali.ole.select.document.OleInvoiceDocument;
50 import org.kuali.ole.select.document.OleRequisitionDocument;
51 import org.kuali.ole.select.document.service.OleCopyHelperService;
52 import org.kuali.ole.select.document.service.OleDocstoreHelperService;
53 import org.kuali.ole.select.document.service.OleRequisitionDocumentService;
54 import org.kuali.ole.select.document.validation.event.CopiesRequisitionEvent;
55 import org.kuali.ole.select.document.validation.event.DiscountRequisitionEvent;
56 import org.kuali.ole.select.document.validation.event.ForeignCurrencyRequisitionEvent;
57 import org.kuali.ole.select.document.web.struts.OleRequisitionForm;
58 import org.kuali.ole.sys.OLEConstants;
59 import org.kuali.ole.sys.OLEPropertyConstants;
60 import org.kuali.ole.sys.businessobject.AccountingLineBase;
61 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
62 import org.kuali.ole.sys.context.SpringContext;
63 import org.kuali.ole.sys.document.validation.event.AddAccountingLineEvent;
64 import org.kuali.ole.vnd.VendorConstants;
65 import org.kuali.ole.vnd.businessobject.*;
66 import org.kuali.ole.vnd.document.service.VendorService;
67 import org.kuali.rice.core.api.config.property.ConfigurationService;
68 import org.kuali.rice.core.api.util.RiceKeyConstants;
69 import org.kuali.rice.core.api.util.type.KualiDecimal;
70 import org.kuali.rice.core.api.util.type.KualiInteger;
71 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
72 import org.kuali.rice.kew.api.exception.WorkflowException;
73 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
74 import org.kuali.rice.krad.service.*;
75 import org.kuali.rice.krad.util.GlobalVariables;
76 import org.kuali.rice.krad.util.KRADConstants;
77 import org.kuali.rice.krad.util.ObjectUtils;
78
79 import javax.servlet.http.HttpServletRequest;
80 import javax.servlet.http.HttpServletResponse;
81 import java.math.BigDecimal;
82 import java.math.RoundingMode;
83 import java.util.*;
84
85 public class OleRequisitionAction extends RequisitionAction {
86 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleRequisitionAction.class);
87 private static transient ConfigurationService kualiConfigurationService;
88 private boolean sufficientFundChecklag = true;
89 private DocstoreClientLocator docstoreClientLocator;
90 private static transient OlePurapService olePurapService;
91 private OleRequisitionDocumentService oleRequisitionDocumentService;
92
93 public DocstoreClientLocator getDocstoreClientLocator() {
94 if (docstoreClientLocator == null) {
95 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
96 }
97 return docstoreClientLocator;
98 }
99
100 public static OlePurapService getOlePurapService() {
101 if (olePurapService == null) {
102 olePurapService = SpringContext.getBean(OlePurapService.class);
103 }
104 return olePurapService;
105 }
106
107 public OleRequisitionDocumentService getOleRequisitionDocumentService() {
108 if(oleRequisitionDocumentService == null) {
109 return SpringContext.getBean(OleRequisitionDocumentService.class);
110 }
111
112 return oleRequisitionDocumentService;
113 }
114
115 public static void setOlePurapService(OlePurapService olePurapService) {
116 OleRequisitionAction.olePurapService = olePurapService;
117 }
118
119
120
121
122
123 @Override
124 protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
125 LOG.debug("Inside the OleRequisitionAction class Create Document");
126 super.createDocument(kualiDocumentFormBase);
127 OleRequisitionForm oleRequisitionForm = (OleRequisitionForm) kualiDocumentFormBase;
128 OleRequisitionItem oleRequisitionItem = (OleRequisitionItem) oleRequisitionForm.getNewPurchasingItemLine();
129 ((RequisitionDocument) kualiDocumentFormBase.getDocument()).initiateDocument();
130 RequisitionDocument requisitionDocument = (RequisitionDocument) kualiDocumentFormBase.getDocument();
131 requisitionDocument.setPaymentTypeCode(getOleRequisitionDocumentService().getParameter(OLEConstants.RECURRING_PAY_TYP));
132 requisitionDocument.setItemLocationForFixed(getOleRequisitionDocumentService().getParameter(OLEConstants.ITEM_LOCATION_FIRM_FIXD));
133 requisitionDocument.setItemLocationForApproval(getOleRequisitionDocumentService().getParameter(OLEConstants.ITEM_LOCATION_APPROVAL));
134 requisitionDocument.setItemStatusForFixed(getOleRequisitionDocumentService().getParameter(OLEConstants.ITEM_STATUS_FIRM_FIXD));
135 requisitionDocument.setItemStatusForApproval(getOleRequisitionDocumentService().getParameter(OLEConstants.ITEM_STATUS_APPROVAL));
136 requisitionDocument.setCopyNumber(getOleRequisitionDocumentService().getParameter(OLEConstants.COPY_NUMBER));
137 requisitionDocument.setOrderTypes(getOleRequisitionDocumentService().getPurchaseOrderTypes());
138 new OleDefaultValueAssignment(oleRequisitionForm.getDefaultDocumentTypeName(), oleRequisitionItem, requisitionDocument);
139 }
140
141
142
143
144
145
146
147
148
149
150
151
152 @Override
153 public ActionForward calculate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
154 LOG.debug("Inside the OleRequisitionAction class Calculate");
155 PurchasingAccountsPayableFormBase purchasingForm = (PurchasingAccountsPayableFormBase) form;
156 List<PurApItem> purApItems = ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems();
157 for(PurApItem purApItem:purApItems){
158 List<KualiDecimal> existingAmount=new ArrayList<>();
159 for(PurApAccountingLine oldSourceAccountingLine:purApItem.getSourceAccountingLines()) {
160 if(oldSourceAccountingLine instanceof OleRequisitionAccount) {
161 if(((OleRequisitionAccount)oldSourceAccountingLine).getExistingAmount()!=null){
162 existingAmount.add(((OleRequisitionAccount)oldSourceAccountingLine).getExistingAmount());
163 }
164 }
165 }
166 int count=0;
167 for(PurApAccountingLine account:purApItem.getSourceAccountingLines()){
168
169 if (ObjectUtils.isNotNull(account.getAccountLinePercent()) || ObjectUtils.isNotNull(account.getAmount())) {
170 if (account.getAmount()!=null&&count<existingAmount.size()&&existingAmount.size() != 0 && !existingAmount.get(count).toString().equals(account.getAmount().toString())) {
171 KualiDecimal calculatedPercent = new KualiDecimal(account.getAmount().multiply(new KualiDecimal(100)).divide(purApItem.getTotalAmount()).toString());
172 account.setAccountLinePercent(calculatedPercent.bigDecimalValue().setScale(OLEConstants.BIG_DECIMAL_SCALE,BigDecimal.ROUND_CEILING));
173 }
174 else {
175 if(account.getAccountLinePercent().intValue()==100&&(account.getAmount()==null||account.getAccount()!=null)){
176 KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent().multiply(purApItem.getTotalAmount().bigDecimalValue()).divide(new BigDecimal(100)).toString());
177 account.setAmount(calculatedAmount);
178 }
179 else{
180 KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent().multiply(purApItem.getTotalAmount().bigDecimalValue()).divide(new BigDecimal(100)).toString());
181 account.setAmount(calculatedAmount);
182 }
183 }
184 }
185 count++;
186 }
187 for(PurApAccountingLine oldSourceAccountingLine:purApItem.getSourceAccountingLines()) {
188 if(oldSourceAccountingLine instanceof OleRequisitionAccount) {
189 ((OleRequisitionAccount)oldSourceAccountingLine).setExistingAmount(oldSourceAccountingLine.getAmount());
190 }
191 }
192 }
193 ActionForward forward = super.calculate(mapping, form, request, response);
194 purchasingForm = (PurchasingAccountsPayableFormBase) form;
195 PurchasingDocument purDoc = (PurchasingDocument) purchasingForm.getDocument();
196 PurchasingFormBase formBase = (PurchasingFormBase) form;
197 OleRequisitionDocument reqDoc = (OleRequisitionDocument) formBase.getDocument();
198 boolean foreignCurrencyIndicator = false;
199
200 List<OleRequisitionItem> item = reqDoc.getItems();
201 if (purDoc.getVendorDetail()!=null) {
202 foreignCurrencyIndicator = isForeignCurrency(purDoc.getVendorDetail().getCurrencyType());
203 }
204 if (purDoc.getVendorDetail() == null || (purDoc.getVendorDetail() != null && (!foreignCurrencyIndicator))) {
205 for (int i = 0; purDoc.getItems().size() > i; i++) {
206 OleRequisitionItem items = (OleRequisitionItem) purDoc.getItem(i);
207 if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) {
208 boolean rulePassed = getKualiRuleService().applyRules(new DiscountRequisitionEvent(reqDoc, items));
209 if (rulePassed) {
210 items.setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(items).setScale(2, BigDecimal.ROUND_HALF_UP));
211 }
212 rulePassed = getKualiRuleService().applyRules(new CopiesRequisitionEvent(reqDoc, items));
213 }
214
215 }
216 } else {
217 LOG.debug("###########Foreign Currency Field Calculation###########");
218 for (int i = 0; item.size() > i; i++) {
219 OleRequisitionItem items = (OleRequisitionItem) reqDoc.getItem(i);
220 if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) {
221 boolean rulePassed = getKualiRuleService().applyRules(new ForeignCurrencyRequisitionEvent(reqDoc, items));
222 if (rulePassed) {
223 SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(items);
224 Long id = reqDoc.getVendorDetail().getCurrencyType().getCurrencyTypeId();
225 Map documentNumberMap = new HashMap();
226 documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, id);
227 BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
228 List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy(OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false);
229 Iterator iterator = exchangeRateList.iterator();
230 if (iterator.hasNext()) {
231 OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next();
232 items.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate()));
233 }
234 if (items.getItemExchangeRate() != null && items.getItemForeignUnitCost() != null) {
235 items.setItemUnitCostUSD(new KualiDecimal(items.getItemForeignUnitCost().bigDecimalValue().divide(items.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP)));
236 items.setItemUnitPrice(items.getItemUnitCostUSD().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP));
237 items.setItemListPrice(items.getItemUnitCostUSD());
238 items.setTotalAmount(items.getTotalAmount());
239 }
240 }
241 }
242 }
243 }
244 purchasingForm = (PurchasingAccountsPayableFormBase) form;
245 List<PurApItem> newpurApItems = ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems();
246 for(PurApItem purApItem:newpurApItems){
247 for(PurApAccountingLine account:purApItem.getSourceAccountingLines()){
248 KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent().multiply(purApItem.getTotalAmount().bigDecimalValue()).divide(new BigDecimal(100)).toString());
249 account.setAmount(calculatedAmount);
250 }
251 }
252 forward = super.calculate(mapping, form, request, response);
253
254
255
256 OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
257 .getBean("oleRequisitionDocumentService");
258 List<SourceAccountingLine> sourceAccountingLineList = reqDoc.getSourceAccountingLines();
259 for (SourceAccountingLine accLine : sourceAccountingLineList) {
260 String notificationOption = null;
261 boolean sufficientFundCheck;
262 Map<String, Object> key = new HashMap<String, Object>();
263 String chartCode = accLine.getChartOfAccountsCode();
264 String accNo = accLine.getAccountNumber();
265 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
266 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
267 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
268 OleSufficientFundCheck.class, key);
269 if (account != null) {
270 notificationOption = account.getNotificationOption();
271 }
272 if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.BLOCK_USE)) {
273 sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine);
274 if (sufficientFundCheck) {
275 GlobalVariables.getMessageMap().putError(
276 OLEConstants.SufficientFundCheck.ERROR_MSG_FOR_INSUFF_FUND, RiceKeyConstants.ERROR_CUSTOM,
277 OLEConstants.SufficientFundCheck.INSUFF_FUND_REQ + accLine.getAccountNumber());
278 }
279 }
280 }
281
282 if (LOG.isDebugEnabled()) {
283 LOG.debug("Inside the OleRequisitionAcrion class Calculate" + formBase.getNewPurchasingItemLine().getItemUnitPrice());
284 }
285 return forward;
286 }
287
288
289
290
291
292
293
294
295
296
297
298 @Override
299 public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
300 LOG.debug("###########Inside AddItem in oleRequisitionAction ###########");
301 PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
302 OleRequisitionItem item = (OleRequisitionItem) purchasingForm.getNewPurchasingItemLine();
303 OleRequisitionDocument document = (OleRequisitionDocument) purchasingForm.getDocument();
304 OleRequisitionForm oleForm = (OleRequisitionForm) form;
305 OleRequisitionDocument doc = (OleRequisitionDocument) oleForm.getDocument();
306 Iterator itemIterator = doc.getItems().iterator();
307 int itemCounter = 0;
308
309 document.setVendorEnterKeyEvent(false);
310 while (itemIterator.hasNext()) {
311 OleRequisitionItem tempItem = (OleRequisitionItem) itemIterator.next();
312 if (tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)) {
313 itemCounter++;
314 }
315 }
316 String itemNo = String.valueOf(itemCounter);
317 BibInfoBean xmlBibInfoBean = new BibInfoBean();
318 if (item.getBibInfoBean() == null) {
319 item.setBibInfoBean(xmlBibInfoBean);
320 if (item.getBibInfoBean().getDocStoreOperation() == null) {
321 item.getBibInfoBean().setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_STAFF);
322 }
323 } else {
324 if (item.getBibInfoBean().getDocStoreOperation() == null) {
325 item.getBibInfoBean().setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_STAFF);
326 }
327 }
328 String fileName = document.getDocumentNumber() + "_" + itemNo;
329
330
331 setItemDescription(item, fileName);
332 if (document.getVendorDetail().getVendorHeader().getVendorForeignIndicator() != null) {
333 if ((document.getVendorDetail() == null) || (document.getVendorDetail().getVendorName() != null && !document.getVendorDetail().getVendorHeader().getVendorForeignIndicator())) {
334 purchasingForm.getNewPurchasingItemLine().setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(item).setScale(2, BigDecimal.ROUND_HALF_UP));
335 super.addItem(mapping, purchasingForm, request, response);
336
337 } else {
338 LOG.debug("###########Foreign Currency Field Calculation for requisition###########");
339 SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(item);
340 Long currencyTypeId = document.getVendorDetail().getCurrencyType().getCurrencyTypeId();
341 Map documentNumberMap = new HashMap();
342 documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, currencyTypeId);
343 BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
344 List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy(OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false);
345 Iterator iterator = exchangeRateList.iterator();
346 if (iterator.hasNext()) {
347 OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next();
348 item.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate()));
349 }
350 if (item.getItemExchangeRate() != null && item.getItemForeignUnitCost() != null) {
351 item.setItemUnitCostUSD(new KualiDecimal(item.getItemForeignUnitCost().bigDecimalValue().divide(item.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP)));
352 item.setItemUnitPrice(item.getItemUnitCostUSD().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP));
353 item.setItemListPrice(item.getItemUnitCostUSD());
354 }
355 super.addItem(mapping, purchasingForm, request, response);
356 }
357 } else {
358 purchasingForm.getNewPurchasingItemLine().setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(item).setScale(2, BigDecimal.ROUND_HALF_UP));
359 super.addItem(mapping, purchasingForm, request, response);
360 }
361 if(item.getClaimDate()==null){
362 getOlePurapService().setClaimDateForReq(item,document.getVendorDetail());
363 }
364 if (GlobalVariables.getMessageMap().getErrorCount() == 0) {
365 String chartCode = SpringContext.getBean(ParameterService.class).getParameterValueAsString(RequisitionDocument.class, "DEFAULT_ACCOUNTINGLINE_CHART_CODE");
366 String objectCode = SpringContext.getBean(ParameterService.class).getParameterValueAsString(RequisitionDocument.class, "DEFAULT_ACCOUNTINGLINE_OBJECT_CODE");
367 if (null != item.getNewSourceLine()) {
368 item.getNewSourceLine().setChartOfAccountsCode(chartCode);
369 item.getNewSourceLine().setFinancialObjectCode(objectCode);
370 }
371
372 }
373
374 return mapping.findForward(OLEConstants.MAPPING_BASIC);
375 }
376
377
378
379
380
381
382
383
384
385
386
387 public ActionForward performPRLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
388 LOG.debug("Inside performPRLookup Method of OleRequisitionAction");
389 ActionForward forward = super.performLookup(mapping, form, request, response);
390 String path = forward.getPath();
391 if (path.contains("kr/" + KRADConstants.LOOKUP_ACTION)) {
392 path = path.replace("kr/" + KRADConstants.LOOKUP_ACTION, OLEConstants.PR_LOOKUP_ACTION);
393
394 } else if (path.contains(KRADConstants.LOOKUP_ACTION)) {
395 path = path.replace(KRADConstants.LOOKUP_ACTION, OLEConstants.PR_LOOKUP_ACTION);
396
397 }
398 forward.setPath(path);
399 LOG.debug("Leaving performPRLookup Method of OleRequisitionAction");
400 return forward;
401 }
402
403
404
405
406
407
408
409
410
411
412
413
414
415 public ActionForward addNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
416 LOG.debug("Inside addNote Method of OleRequisitionAction");
417 OleRequisitionForm purchasingForm = (OleRequisitionForm) form;
418 int line = this.getSelectedLine(request);
419 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItem(line);
420 OleRequisitionNotes note = new OleRequisitionNotes();
421 note.setNoteTypeId(item.getNoteTypeId());
422 note.setNote(item.getNote());
423 item.getNotes().add(note);
424 LOG.debug("Adding Note to the RequisitionItem");
425 item.setNoteTypeId(null);
426 item.setNote(null);
427 LOG.debug("Leaving addNote Method of OleRequisitionAction");
428 return mapping.findForward(OLEConstants.MAPPING_BASIC);
429 }
430
431
432
433
434
435
436
437
438
439
440
441 public ActionForward deleteNote(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
442 LOG.debug("Inside deleteNote Method of OleRequisitionAction");
443 OleRequisitionForm purchasingForm = (OleRequisitionForm) form;
444 String[] indexes = getSelectedLineForAccounts(request);
445 int itemIndex = Integer.parseInt(indexes[0]);
446 int noteIndex = Integer.parseInt(indexes[1]);
447 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItem((itemIndex));
448 item.getNotes().remove(noteIndex);
449 LOG.debug("Selected Note is Remove");
450 LOG.debug("Leaving deleteNote Method of OleRequisitionAction");
451 return mapping.findForward(OLEConstants.MAPPING_BASIC);
452 }
453
454 @Override
455 public ActionForward route(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
456 PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
457 PurchasingDocument purDoc = (PurchasingDocument) purchasingForm.getDocument();
458 PurchasingFormBase formBase = (PurchasingFormBase) form;
459 OleRequisitionDocument reqDoc = (OleRequisitionDocument) formBase.getDocument();
460 List<OleRequisitionItem> items = reqDoc.getItems();
461
462 if (requiresCalculate(purchasingForm)) {
463 GlobalVariables.getMessageMap().putError(OLEConstants.DOCUMENT_ERRORS, PurapKeyConstants.ERROR_PURCHASING_REQUIRES_CALCULATE);
464 return mapping.findForward(OLEConstants.MAPPING_BASIC);
465 }
466
467 SpringContext.getBean(PurapService.class).prorateForTradeInAndFullOrderDiscount(purDoc);
468 this.calculate(mapping, purchasingForm, request, response);
469 for (OleRequisitionItem item : items) {
470 if (null != item.getItemType() && item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
471 if (item.getItemQuantity() != null && item.getItemNoOfParts() != null && !item.getItemQuantity().isGreaterThan(new KualiDecimal(1))
472 && !item.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
473 OleCopy oleCopy = new OleCopy();
474 oleCopy.setLocation(item.getItemLocation());
475 oleCopy.setBibId(item.getItemTitleId());
476 if (StringUtils.isNotBlank(item.getLinkToOrderOption()) && (item.getLinkToOrderOption().equals(OLEConstants.NB_PRINT) || item.getLinkToOrderOption().equals(OLEConstants.EB_PRINT))) {
477 oleCopy.setCopyNumber(item.getSingleCopyNumber() != null && !item.getSingleCopyNumber().isEmpty() ? item.getSingleCopyNumber() : null);
478 }
479 oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.NOT_RECEIVED_STATUS);
480 List<OleCopy> copyList = new ArrayList<>();
481 copyList.add(oleCopy);
482 item.setCopyList(copyList);
483 }
484 }
485 }
486 if (sufficientFundChecklag) {
487 return super.route(mapping, form, request, response);
488 }
489 return mapping.findForward(OLEConstants.MAPPING_BASIC);
490 }
491
492
493
494
495
496
497
498 @Override
499 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
500 LOG.debug("<<<---------Inside OleRequisitionAction Refresh------>>>");
501 ActionForward forward = super.refresh(mapping, form, request, response);
502 OleRequisitionForm rqForm = (OleRequisitionForm) form;
503 OleRequisitionDocument document = (OleRequisitionDocument) rqForm.getDocument();
504 OleRequisitionItem item = (OleRequisitionItem) rqForm.getNewPurchasingItemLine();
505
506 document.setOrganizationAutomaticPurchaseOrderLimit(SpringContext.getBean(PurapService.class).getApoLimit(document.getVendorContractGeneratedIdentifier(), document.getChartOfAccountsCode(), document.getOrganizationCode()));
507
508 if (LOG.isInfoEnabled()) {
509 LOG.info("Currency Type on Requisition :" + document.getVendorDetail().getCurrencyType());
510 }
511 if (document.getVendorDetail() != null) {
512 if (document.getVendorDetail().getVendorTransmissionFormat().size() > 0) {
513 List<VendorTransmissionFormatDetail> vendorTransmissionFormat = document.getVendorDetail().getVendorTransmissionFormat();
514 for (VendorTransmissionFormatDetail iter : vendorTransmissionFormat) {
515 if (iter.isVendorPreferredTransmissionFormat()) {
516 if (iter.getVendorTransmissionFormat().getVendorTransmissionFormat() != null) {
517 if (iter.getVendorTransmissionFormat().getVendorTransmissionFormat().equalsIgnoreCase(OleSelectConstant.VENDOR_TRANSMISSION_FORMAT_EDI) ||
518 iter.getVendorTransmissionFormat().getVendorTransmissionFormat().equalsIgnoreCase(OleSelectConstant.VENDOR_TRANSMISSION_FORMAT_PDF)) {
519 document.setPurchaseOrderTransmissionMethodCode(OleSelectConstant.METHOD_OF_PO_TRANSMISSION_NOPR);
520 } else {
521 document.setPurchaseOrderTransmissionMethodCode(SpringContext.getBean(ParameterService.class).getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.PURAP_DEFAULT_PO_TRANSMISSION_CODE));
522 }
523 }
524 }
525 }
526 } else {
527 document.setPurchaseOrderTransmissionMethodCode(SpringContext.getBean(ParameterService.class).getParameterValueAsString(RequisitionDocument.class, PurapParameterConstants.PURAP_DEFAULT_PO_TRANSMISSION_CODE));
528 }
529 boolean foreignCurrencyIndicator = isForeignCurrency(document.getVendorDetail().getCurrencyType());
530
531 if ((!foreignCurrencyIndicator) && item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
532 if (document.getVendorDetail().getCurrencyType() != null) {
533 Long currencyTypeId = document.getVendorDetail().getCurrencyType().getCurrencyTypeId();
534 Map documentNumberMap = new HashMap();
535 documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, currencyTypeId);
536 BusinessObjectService businessObjectService = SpringContext.getBean(BusinessObjectService.class);
537 List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy(OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false);
538 Iterator iterator = exchangeRateList.iterator();
539 if (iterator.hasNext()) {
540 OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next();
541 item.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate()));
542 }
543 }
544 }
545
546 }
547 return forward;
548 }
549
550 public ActionForward refreshDocuments(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
551 LOG.debug("<<<---------Inside OleRequisitionAction refreshDocuments------>>>");
552 ActionForward forward = super.reload(mapping, form, request, response);
553 return forward;
554 }
555
556 private boolean isForeignCurrency(OleCurrencyType oleCurrencyType){
557 boolean foreignCurrencyIndicator = false;
558 if(oleCurrencyType!=null){
559 if(!oleCurrencyType.getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){
560 foreignCurrencyIndicator = true;
561 }
562 }
563 return foreignCurrencyIndicator;
564 }
565
566
567
568
569 @Override
570 public ActionForward clearVendor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
571
572 ActionForward forward = super.clearVendor(mapping, form, request, response);
573 OleRequisitionForm rqForm = (OleRequisitionForm) form;
574 OleRequisitionDocument document = (OleRequisitionDocument) rqForm.getDocument();
575 document.setPurchaseOrderTransmissionMethodCode(OleSelectConstant.METHOD_OF_PO_TRANSMISSION_NOPR);
576 document.setVendorEnterKeyEvent(false);
577 return forward;
578 }
579
580
581
582
583
584
585
586 @Override
587 public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
588
589 PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form;
590
591
592
593 int itemIndex = getSelectedLine(request);
594 PurApItem item = null;
595
596
597
598 if (processCustomInsertAccountingLine(purapForm, request) == false) {
599 String errorPrefix = null;
600 PurApAccountingLine line = null;
601
602 boolean rulePassed = false;
603 if (itemIndex >= 0) {
604 item = ((PurchasingAccountsPayableDocument) purapForm.getDocument()).getItem((itemIndex));
605
606 PurApAccountingLine lineItem = item.getNewSourceLine();
607 if (item.getTotalAmount() != null && !item.getTotalAmount().equals(KualiDecimal.ZERO)) {
608 if (lineItem.getAccountLinePercent() != null && (lineItem.getAmount() == null || lineItem.getAmount().equals(KualiDecimal.ZERO))) {
609 BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100));
610 lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent))));
611 } else if (lineItem.getAmount() != null && lineItem.getAmount().isNonZero() && lineItem.getAccountLinePercent() == null) {
612 KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100));
613 BigDecimal dollarToPercent = dollar.bigDecimalValue().divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR);
614 lineItem.setAccountLinePercent(dollarToPercent);
615 } else if (lineItem.getAmount() != null && lineItem.getAmount().isZero() && lineItem.getAccountLinePercent() == null) {
616 lineItem.setAccountLinePercent(new BigDecimal(0));
617 }
618 else if(lineItem.getAmount()!=null&& lineItem.getAccountLinePercent().intValue()== 100){
619 KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100));
620 BigDecimal dollarToPercent = dollar.bigDecimalValue().divide((item.getTotalAmount().bigDecimalValue()),0,RoundingMode.FLOOR);
621 lineItem.setAccountLinePercent(dollarToPercent);
622 }
623 else if(lineItem.getAmount()!=null&&lineItem.getAccountLinePercent() != null){
624 BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100));
625 lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent))));
626 }
627 } else {
628 lineItem.setAmount(new KualiDecimal(0));
629 }
630 line = (PurApAccountingLine) ObjectUtils.deepCopy(lineItem);
631
632
633 errorPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + Integer.toString(itemIndex) + "]." + OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME;
634 rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
635 } else if (itemIndex == -2) {
636
637
638 line = ((PurchasingFormBase) purapForm).getAccountDistributionnewSourceLine();
639
640 errorPrefix = PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE;
641 rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
642 }
643 if (rulePassed) {
644 AccountingLineBase accountingLineBase = (AccountingLineBase) item.getNewSourceLine();
645 if (accountingLineBase != null) {
646 String accountNumber = accountingLineBase.getAccountNumber();
647 String chartOfAccountsCode = accountingLineBase.getChartOfAccountsCode();
648 Map<String, String> criteria = new HashMap<String, String>();
649 criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
650 criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
651 Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class,criteria);
652 rulePassed = checkForValidAccount(account);
653 }
654 }
655 if (rulePassed) {
656
657 SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line);
658 PurApAccountingLine newSourceLine = item.getNewSourceLine();
659 List<PurApAccountingLine> existingSourceLine = item.getSourceAccountingLines();
660
661 BigDecimal initialValue = OleSelectConstant.ZERO_PERCENT;
662
663 for (PurApAccountingLine accountLine : existingSourceLine) {
664 initialValue = initialValue.add(accountLine.getAccountLinePercent());
665
666 }
667 if (itemIndex >= 0) {
668
669 if ((newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED && newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.MAX_PERCENT.subtract(initialValue).intValue()) && newSourceLine.getAccountLinePercent().intValue() > OleSelectConstant.ZERO) {
670 if (OleSelectConstant.MAX_PERCENT.subtract(initialValue).intValue() != OleSelectConstant.ZERO) {
671 insertAccountingLine(purapForm, item, line);
672 }
673 } else {
674 checkAccountingLinePercent(newSourceLine);
675
676 }
677 for(PurApAccountingLine oldSourceAccountingLine:item.getSourceAccountingLines()) {
678 if(oldSourceAccountingLine instanceof OleRequisitionAccount) {
679 ((OleRequisitionAccount)oldSourceAccountingLine).setExistingAmount(oldSourceAccountingLine.getAmount());
680 }
681 }
682 List<PurApAccountingLine> existingAccountingLine = item.getSourceAccountingLines();
683 BigDecimal totalPercent = new BigDecimal(100);
684 BigDecimal initialPercent = new BigDecimal(0);
685 for (PurApAccountingLine purApAccountingLine : existingAccountingLine) {
686 initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent());
687
688 }
689 initialPercent = totalPercent.subtract(initialPercent);
690 BigDecimal maxPercent = initialPercent.max(OleSelectConstant.ZERO_PERCENT);
691 if (maxPercent.intValue() == OleSelectConstant.ZERO) {
692 item.resetAccount(OleSelectConstant.ZERO_PERCENT);
693
694 } else {
695 item.resetAccount(initialPercent);
696
697 }
698 } else if (itemIndex == -2) {
699
700 ((PurchasingFormBase) purapForm).addAccountDistributionsourceAccountingLine(line);
701 }
702 }
703 }
704
705 return mapping.findForward(OLEConstants.MAPPING_BASIC);
706 }
707
708 private void checkAccountingLinePercent(PurApAccountingLine newSourceLine) {
709 if (newSourceLine.getAccountLinePercent().intValue() >= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED) {
710 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
711 OleSelectPropertyConstants.ERROR_PERCENT_SHOULD_GREATER, OleSelectConstant.PERCENT);
712 } else if (newSourceLine.getAccountLinePercent().intValue() == OleSelectConstant.ZERO) {
713 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
714 OleSelectPropertyConstants.ERROR_PERCENT_ZERO, OleSelectConstant.PERCENT);
715 } else {
716
717 }
718
719 }
720
721 private boolean checkForValidAccount(Account account) {
722 boolean result = true;
723 if (account != null) {
724 String subFundGroupParameter = getParameterService().getParameterValueAsString(Account.class,
725 OleSelectConstant.SUB_FUND_GRP_CD);
726 if (account.getSubFundGroupCode().equalsIgnoreCase(subFundGroupParameter)) {
727 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
728 OleSelectPropertyConstants.ERROR_ACCOUNT_NUMBER,
729 new String[]{OleSelectConstant.REQUISITION});
730 result = false;
731 }
732 }
733 return result;
734 }
735
736 private void setItemDescription(OleRequisitionItem item, String fileName) throws Exception{
737
738 if (OleDocstoreResponse.getInstance().getEditorResponse() != null) {
739 Map<String, OLEEditorResponse> oleEditorResponses = OleDocstoreResponse.getInstance().getEditorResponse();
740 OLEEditorResponse oleEditorResponse = oleEditorResponses.get(fileName);
741 Bib bib = oleEditorResponse != null ? oleEditorResponse.getBib() : null;
742 if (bib != null) {
743 String title = (bib.getTitle() != null&& !bib.getTitle().isEmpty()) ? bib.getTitle() + ", " : "";
744 String author = (bib.getAuthor()!=null && !bib.getAuthor().isEmpty()) ? bib.getAuthor() + ", " : "";
745 String publisher = (bib.getPublisher()!=null && !bib.getPublisher().isEmpty()) ? bib.getPublisher() + ", " : "";
746 String isbn = (bib.getIsbn()!=null && !bib.getIsbn().isEmpty()) ? bib.getIsbn() + ", " : "";
747 String description = title + author + publisher + isbn;
748 item.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(bib.getId().toString()));
749 item.setItemDescription(description.substring(0, (description.lastIndexOf(","))));
750 }
751 if (bib != null) {
752 item.setBibUUID(bib.getId());
753 item.setItemTitleId(bib.getId());
754 item.setLinkToOrderOption(oleEditorResponse.getLinkToOrderOption());
755 }
756 OleDocstoreResponse.getInstance().getEditorResponse().remove(oleEditorResponse);
757 }
758
759 }
760
761 public ActionForward addCopy(ActionMapping mapping, ActionForm form, HttpServletRequest request,
762 HttpServletResponse response) throws Exception {
763 LOG.debug("Inside addCopy Method of OleRequisitionAction");
764 OleRequisitionForm purchasingForm = (OleRequisitionForm) form;
765 int line = this.getSelectedLine(request);
766 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) purchasingForm
767 .getDocument()).getItem(line);
768 OleRequisitionCopies itemCopy = new OleRequisitionCopies();
769 OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
770 boolean isValid = true;
771 List<String> volChar = new ArrayList<>();
772 String[] volNumbers = item.getVolumeNumber() != null ? item.getVolumeNumber().split(",") : new String[0];
773 for (String volStr : volNumbers) {
774 volChar.add(volStr);
775 }
776 Integer itemCount = volChar.size();
777 isValid = oleCopyHelperService.checkCopyEntry(
778 item.getItemCopies(), item.getLocationCopies(), itemCount, item.getItemQuantity(), item.getItemNoOfParts(), item.getCopies(), item.getVolumeNumber(), false);
779 if (isValid) {
780 itemCopy.setItemCopies(item.getItemCopies());
781 itemCopy.setLocationCopies(item.getLocationCopies());
782 itemCopy.setParts(item.getItemNoOfParts());
783 itemCopy.setStartingCopyNumber(item.getStartingCopyNumber());
784 itemCopy.setCaption(item.getCaption());
785 itemCopy.setVolumeNumber(item.getVolumeNumber());
786 item.setOleRequisitionCopy(itemCopy);
787 List<OleCopy> copyList = oleCopyHelperService.setCopyValues(item.getOleRequisitionCopy(), item.getItemTitleId(), volChar);
788 item.getCopyList().addAll(copyList);
789 item.getCopies().add(itemCopy);
790 item.setParts(null);
791 item.setItemCopies(null);
792 item.setPartEnumeration(null);
793 item.setLocationCopies(null);
794 item.setCaption(null);
795 item.setVolumeNumber(null);
796 }
797 return mapping.findForward(OLEConstants.MAPPING_BASIC);
798 }
799
800 public boolean checkForCopiesAndLocation(OleRequisitionItem item) {
801 boolean isValid = true;
802 if (null == item.getItemCopies() || null == item.getLocationCopies()) {
803 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
804 OLEConstants.ITEM_ITEMCOPIES_OR_LOCATIONCOPIES_SHOULDNOT_BE_NULL, new String[]{});
805 isValid = false;
806 }
807 return isValid;
808 }
809
810 public boolean checkForItemCopiesGreaterThanQuantity(OleRequisitionItem item) {
811 boolean isValid = true;
812 if (item.getItemCopies().isGreaterThan(item.getItemQuantity())) {
813 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
814 OLEConstants.ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
815 isValid = false;
816 }
817 return isValid;
818 }
819
820 public boolean checkForTotalCopiesGreaterThanQuantity(OleRequisitionItem item) {
821 boolean isValid = true;
822 int copies = 0;
823 if (item.getCopies().size() > 0) {
824 for (int itemCopies = 0; itemCopies < item.getCopies().size(); itemCopies++) {
825 copies = copies + item.getCopies().get(itemCopies).getItemCopies().intValue();
826 }
827 if (item.getItemQuantity().isLessThan(item.getItemCopies().add(new KualiDecimal(copies)))) {
828 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
829 OLEConstants.TOTAL_OF_ITEM_COPIES_ITEMCOPIES_GREATERTHAN_ITEMCOPIESORDERED, new String[]{});
830 isValid = false;
831 }
832 }
833 return isValid;
834 }
835
836
837
838
839
840
841
842
843
844 public OleRequisitionCopies setCopyValues(OleRequisitionItem item) {
845 OleRequisitionCopies itemCopy = new OleRequisitionCopies();
846 itemCopy.setParts(item.getItemNoOfParts());
847 itemCopy.setItemCopies(item.getItemCopies());
848 StringBuffer enumeration = new StringBuffer();
849 if (item.getStartingCopyNumber() != null && item.getStartingCopyNumber().isNonZero()) {
850 itemCopy.setStartingCopyNumber(item.getStartingCopyNumber());
851 } else {
852 int startingCopies = 1;
853 for (int copy = 0; copy < item.getCopies().size(); copy++) {
854 startingCopies = startingCopies + item.getCopies().get(copy).getItemCopies().intValue();
855 }
856 itemCopy.setStartingCopyNumber(new KualiInteger(startingCopies));
857 }
858
859 String partEnumerationCopy = getConfigurationService().getPropertyValueAsString(
860 OLEConstants.PART_ENUMERATION_COPY);
861 String partEnumerationVolume = getConfigurationService().getPropertyValueAsString(
862 OLEConstants.PART_ENUMERATION_VOLUME);
863 int startingCopyNumber = itemCopy.getStartingCopyNumber().intValue();
864 for (int noOfCopies = 0; noOfCopies < item.getItemCopies().intValue(); noOfCopies++) {
865 for (int noOfParts = 0; noOfParts < item.getItemNoOfParts().intValue(); noOfParts++) {
866 int newNoOfCopies = startingCopyNumber + noOfCopies;
867 int newNoOfParts = noOfParts + 1;
868 if (noOfCopies + 1 == item.getItemCopies().intValue()
869 && newNoOfParts == item.getItemNoOfParts().intValue()) {
870 enumeration = enumeration.append(
871 partEnumerationCopy + newNoOfCopies + OLEConstants.DOT_TO_SEPARATE_COPIES_PARTS).append(
872 partEnumerationVolume + newNoOfParts);
873 } else {
874 enumeration = enumeration.append(
875 partEnumerationCopy + newNoOfCopies + OLEConstants.DOT_TO_SEPARATE_COPIES_PARTS).append(
876 partEnumerationVolume + newNoOfParts + OLEConstants.COMMA_TO_SEPARATE_ENUMERATION);
877 }
878 }
879 }
880 itemCopy.setPartEnumeration(enumeration.toString());
881 itemCopy.setLocationCopies(item.getLocationCopies());
882 return itemCopy;
883 }
884
885
886
887
888
889
890
891
892
893
894
895 public ActionForward deleteCopy(ActionMapping mapping, ActionForm form, HttpServletRequest request,
896 HttpServletResponse response) throws Exception {
897 LOG.debug("Inside deleteCopy Method of OleRequisitionAction");
898 OleRequisitionForm purchasingForm = (OleRequisitionForm) form;
899 String[] indexes = getSelectedLineForAccounts(request);
900 int itemIndex = Integer.parseInt(indexes[0]);
901 int copyIndex = Integer.parseInt(indexes[1]);
902 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) purchasingForm
903 .getDocument()).getItem((itemIndex));
904 List<OleCopy> copyList = new ArrayList<>();
905 for(int i=0;i<item.getCopyList().size();i++){
906 OleCopy oleCopy = item.getCopyList().get(i);
907 if(item.getCopies().get(copyIndex).getLocationCopies().equalsIgnoreCase(oleCopy.getLocation())){
908 copyList.add(oleCopy);
909 }
910 }
911 for(OleCopy copy : copyList){
912 item.getCopyList().remove(copy);
913 item.getDeletedCopiesList().add(copy);
914 }
915 item.getCopies().remove(copyIndex);
916 LOG.debug("Selected Copy is Remove");
917 LOG.debug("Leaving deleteCopy Method of OleRequisitionAction");
918 return mapping.findForward(OLEConstants.MAPPING_BASIC);
919 }
920
921
922
923
924
925
926
927
928
929
930
931 public ActionForward addPaymentHistory(ActionMapping mapping, ActionForm form, HttpServletRequest request,
932 HttpServletResponse response) throws Exception {
933 OleRequisitionForm purchasingForm = (OleRequisitionForm) form;
934 int line = this.getSelectedLine(request);
935 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) purchasingForm
936 .getDocument()).getItem(line);
937 OleRequisitionPaymentHistory paymentHistory = new OleRequisitionPaymentHistory();
938 paymentHistory.setPaymentHistory("");
939 item.getRequisitionPaymentHistory().add(paymentHistory);
940 return mapping.findForward(OLEConstants.MAPPING_BASIC);
941 }
942
943
944
945
946
947
948
949
950
951
952
953 public ActionForward deletePaymentHistory(ActionMapping mapping, ActionForm form, HttpServletRequest request,
954 HttpServletResponse response) throws Exception {
955
956 OleRequisitionForm purchasingForm = (OleRequisitionForm) form;
957 String[] indexes = getSelectedLineForAccounts(request);
958 int itemIndex = Integer.parseInt(indexes[0]);
959 int copyIndex = Integer.parseInt(indexes[1]);
960 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) purchasingForm
961 .getDocument()).getItem((itemIndex));
962 item.getRequisitionPaymentHistory().remove(copyIndex);
963 return mapping.findForward(OLEConstants.MAPPING_BASIC);
964 }
965
966 public static ConfigurationService getConfigurationService() {
967 if (kualiConfigurationService == null) {
968 kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
969 }
970 return kualiConfigurationService;
971 }
972
973 @Override
974 public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request,
975 HttpServletResponse response) throws Exception {
976 ActionForward actionForward = super.copy(mapping, form, request, response);
977
978 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
979 PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) kualiDocumentFormBase
980 .getDocument();
981 if(purapDocument.getIsReqsDoc()) {
982 OleRequisitionDocument oleRequisitionDocument = (OleRequisitionDocument)purapDocument;
983 oleRequisitionDocument.setOrderTypes(getOleRequisitionDocumentService().getPurchaseOrderTypes());
984 oleRequisitionDocument.setPaymentTypeCode(getOleRequisitionDocumentService().getParameter(OLEConstants.RECURRING_PAY_TYP));
985 oleRequisitionDocument.setItemLocationForFixed(getOleRequisitionDocumentService().getParameter(OLEConstants.ITEM_LOCATION_FIRM_FIXD));
986 oleRequisitionDocument.setItemLocationForApproval(getOleRequisitionDocumentService().getParameter(OLEConstants.ITEM_LOCATION_APPROVAL));
987 oleRequisitionDocument.setItemStatusForFixed(getOleRequisitionDocumentService().getParameter(OLEConstants.ITEM_STATUS_FIRM_FIXD));
988 oleRequisitionDocument.setItemStatusForApproval(getOleRequisitionDocumentService().getParameter(OLEConstants.ITEM_STATUS_APPROVAL));
989 oleRequisitionDocument.setCopyNumber(getOleRequisitionDocumentService().getParameter(OLEConstants.COPY_NUMBER));
990 if(oleRequisitionDocument.getRequisitionSource().getRequisitionSourceCode().equalsIgnoreCase(OleSelectConstant.REQUISITON_SRC_TYPE_AUTOINGEST)) {
991 ((OleRequisitionDocument) purapDocument).setRequisitionSourceCode(null);
992 }
993 }
994
995
996 List<PurApItem> items = purapDocument.getItems();
997
998 for (PurApItem item : items) {
999 OleRequisitionItem oleRequisitionItem = (OleRequisitionItem) item;
1000 oleRequisitionItem.setInvoiceDocuments(new ArrayList<OleInvoiceDocument>());
1001 oleRequisitionItem.setNoOfCopiesReceived("");
1002 oleRequisitionItem.setNoOfPartsReceived("");
1003 oleRequisitionItem.setReceiptStatusId(null);
1004 for (OleCopy oleCopy : ((OleRequisitionItem) item).getCopyList()) {
1005 oleCopy.setCopyId(null);
1006 oleCopy.setReqItemId(null);
1007 oleCopy.setPoDocNum(null);
1008 oleCopy.setPoItemId(null);
1009 oleCopy.setReceivingItemId(null);
1010 oleCopy.setCorrectionItemId(null);
1011 oleCopy.setSerialReceivingIdentifier(null);
1012 oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.NOT_RECEIVED_STATUS);
1013 }
1014 for (OLELinkPurapDonor oleLinkPurapDonor : ((OleRequisitionItem) item).getOleDonors()) {
1015 oleLinkPurapDonor.setLinkPurapDonorId(null);
1016 oleLinkPurapDonor.setCorrectionItemId(null);
1017 oleLinkPurapDonor.setReceivingItemId(null);
1018 oleLinkPurapDonor.setReqItemId(null);
1019 oleLinkPurapDonor.setPoDocNum(null);
1020 oleLinkPurapDonor.setPoItemId(null);
1021 }
1022 if(oleRequisitionItem.getItemQuantity().equals(new KualiDecimal("1")) && oleRequisitionItem.getItemNoOfParts().equals(new KualiInteger("1"))){
1023 oleRequisitionItem.setCopyList(new ArrayList<OleCopy>());
1024 oleRequisitionItem.setCopies(new ArrayList<OleCopies>());
1025 }
1026 }
1027
1028 return actionForward;
1029 }
1030
1031 @Override
1032 public ActionForward blanketApprove(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1033 HttpServletResponse response) throws Exception {
1034 OleRequisitionDocument document = (OleRequisitionDocument) ((PurchasingFormBase) form).getDocument();
1035 boolean budgetReviewRequired = isBudgetReviewRequired(document);
1036 if(budgetReviewRequired){
1037 route(mapping, form, request, response);
1038 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1039 }
1040 Iterator itemIterator = document.getItems().iterator();
1041 PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
1042 OleRequisitionDocument reqDoc = (OleRequisitionDocument) purchasingForm.getDocument();
1043 List<OleRequisitionItem> items = reqDoc.getItems();
1044 boolean rulePassed = true;
1045 while (itemIterator.hasNext()) {
1046 OleRequisitionItem tempItem = (OleRequisitionItem) itemIterator.next();
1047 if (tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)) {
1048 List<PurApAccountingLine> accountingLineBase = tempItem.getSourceAccountingLines();
1049 if (accountingLineBase != null) {
1050 for (int accountingLine = 0; accountingLine < accountingLineBase.size(); accountingLine++) {
1051 String accountNumber = accountingLineBase.get(accountingLine).getAccountNumber();
1052 String chartOfAccountsCode = accountingLineBase.get(accountingLine).getChartOfAccountsCode();
1053 Map<String, String> criteria = new HashMap<String, String>();
1054 criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
1055 criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
1056 Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
1057 Account.class, criteria);
1058 rulePassed = checkForValidAccount(account);
1059 if (!rulePassed) {
1060 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1061 }
1062 }
1063 }
1064 }
1065 }
1066 if (requiresCalculate(purchasingForm)) {
1067 GlobalVariables.getMessageMap().putError(OLEConstants.DOCUMENT_ERRORS,
1068 PurapKeyConstants.ERROR_PURCHASING_REQUIRES_CALCULATE);
1069 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1070 }
1071
1072 SpringContext.getBean(PurapService.class).prorateForTradeInAndFullOrderDiscount(document);
1073 this.calculate(mapping, purchasingForm, request, response);
1074 for (OleRequisitionItem item : items) {
1075 if (null != item.getItemType() && item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
1076 if (item.getItemQuantity() != null && item.getItemNoOfParts() != null && !item.getItemQuantity().isGreaterThan(new KualiDecimal(1))
1077 && !item.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
1078 OleCopy oleCopy = new OleCopy();
1079 oleCopy.setLocation(item.getItemLocation());
1080 oleCopy.setBibId(item.getItemTitleId());
1081 if (StringUtils.isNotBlank(item.getLinkToOrderOption()) && (item.getLinkToOrderOption().equals(OLEConstants.NB_PRINT) || item.getLinkToOrderOption().equals(OLEConstants.EB_PRINT))) {
1082 oleCopy.setCopyNumber(item.getSingleCopyNumber() != null && !item.getSingleCopyNumber().isEmpty() ? item.getSingleCopyNumber() : OLEConstants.ONE.toString());
1083 }
1084 oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.NOT_RECEIVED_STATUS);
1085 List<OleCopy> copyList = new ArrayList<>();
1086 copyList.add(oleCopy);
1087 item.setCopyList(copyList);
1088 }
1089 }
1090 }
1091 if (sufficientFundChecklag) {
1092 super.blanketApprove(mapping, form, request, response);
1093 }
1094 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1095 }
1096
1097 public ActionForward selectVendor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1098 OleRequisitionForm rqForm = (OleRequisitionForm) form;
1099 OleRequisitionDocument document = (OleRequisitionDocument) rqForm.getDocument();
1100 if (document.getVendorAliasName() != null && document.getVendorAliasName().length() > 0) {
1101
1102 Map vendorAliasMap = new HashMap();
1103 vendorAliasMap.put(OLEConstants.VENDOR_ALIAS_NAME, document.getVendorAliasName());
1104 org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
1105 List<VendorAlias> vendorAliasList = (List<VendorAlias>) getLookupService().findCollectionBySearchHelper(VendorAlias.class, vendorAliasMap, true);
1106 if (vendorAliasList != null && vendorAliasList.size() > 0) {
1107 Map vendorDetailMap = new HashMap();
1108 vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier());
1109 vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, vendorAliasList.get(0).getVendorDetailAssignedIdentifier());
1110 VendorDetail vendorDetail = businessObject.findByPrimaryKey(VendorDetail.class, vendorDetailMap);
1111 document.setVendorDetail(vendorDetail);
1112 document.setVendorHeaderGeneratedIdentifier(vendorAliasList.get(0).getVendorHeaderGeneratedIdentifier());
1113 document.setVendorDetailAssignedIdentifier(vendorAliasList.get(0).getVendorDetailAssignedIdentifier());
1114 refreshVendor(mapping, form, request, response);
1115 } else {
1116 GlobalVariables.getMessageMap().putError(PurapConstants.VENDOR_ERRORS, OLEConstants.VENDOR_NOT_FOUND);
1117 }
1118 }
1119 if (GlobalVariables.getMessageMap().getErrorCount() == 0) {
1120 document.setVendorEnterKeyEvent(true);
1121 }
1122 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1123 }
1124
1125
1126 public ActionForward refreshVendor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1127 PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;
1128
1129 PurchasingDocument document = (PurchasingDocument) baseForm.getDocument();
1130 if (StringUtils.equals(OLEConstants.REFRESH_VENDOR_CALLER, VendorConstants.VENDOR_LOOKUPABLE_IMPL) && document.getVendorDetailAssignedIdentifier() != null && document.getVendorHeaderGeneratedIdentifier() != null) {
1131 document.setVendorContractGeneratedIdentifier(null);
1132 document.refreshReferenceObject(OLEConstants.VENDOR_CONTRACT);
1133
1134
1135 document.refreshReferenceObject(OLEConstants.VENDOR_DETAILS);
1136 document.templateVendorDetail(document.getVendorDetail());
1137
1138
1139 VendorAddress defaultAddress = null;
1140 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){
1141 defaultAddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(document.getVendorDetail().getVendorAddresses(), document.getVendorDetail().getVendorHeader().getVendorType().getAddressType().getVendorAddressTypeCode(), document.getDeliveryCampusCode());
1142 }
1143 document.templateVendorAddress(defaultAddress);
1144 }
1145 return refresh(mapping, form, request, response);
1146 }
1147
1148 private LookupService getLookupService() {
1149 return KRADServiceLocatorWeb.getLookupService();
1150 }
1151
1152 public boolean isBudgetReviewRequired(OleRequisitionDocument document) {
1153 OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext
1154 .getBean("oleRequisitionDocumentService");
1155 List<SourceAccountingLine> sourceAccountingLineList = document.getSourceAccountingLines();
1156 boolean sufficientFundCheck = false;
1157 for (SourceAccountingLine accLine : sourceAccountingLineList) {
1158 String notificationOption = null;
1159 Map<String, Object> key = new HashMap<String, Object>();
1160 String chartCode = accLine.getChartOfAccountsCode();
1161 String accNo = accLine.getAccountNumber();
1162 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
1163 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
1164 OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
1165 OleSufficientFundCheck.class, key);
1166 if (account != null) {
1167 notificationOption = account.getNotificationOption();
1168 }
1169 if (notificationOption != null
1170 && (notificationOption.equals(OLEPropertyConstants.BUD_REVIEW))) {
1171 sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnBlanketApproveRequisition(accLine);
1172 if (sufficientFundCheck) {
1173 return sufficientFundCheck;
1174 }
1175
1176 }
1177 }
1178 return sufficientFundCheck;
1179 }
1180 public ActionForward addDonor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
1181 boolean flag = true;
1182 OleRequisitionForm purchasingForm = (OleRequisitionForm) form;
1183 int line = this.getSelectedLine(request);
1184 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItem(line);
1185 Map map = new HashMap();
1186 if (item.getDonorCode() != null) {
1187 map.put(OLEConstants.DONOR_CODE, item.getDonorCode());
1188 List<OLEDonor> oleDonorList = (List<OLEDonor>) getLookupService().findCollectionBySearch(OLEDonor.class, map);
1189 if (oleDonorList != null && oleDonorList.size() > 0) {
1190 OLEDonor oleDonor = oleDonorList.get(0);
1191 if (oleDonor != null) {
1192 for (OLELinkPurapDonor oleLinkPurapDonor : item.getOleDonors()) {
1193 if (oleLinkPurapDonor.getDonorCode().equalsIgnoreCase(item.getDonorCode())) {
1194 flag = false;
1195 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1196 OLEConstants.DONOR_CODE_EXISTS, new String[]{});
1197 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1198 }
1199 }
1200 if (flag) {
1201 OLELinkPurapDonor donor = new OLELinkPurapDonor();
1202 donor.setDonorId(oleDonor.getDonorId());
1203 donor.setDonorCode(oleDonor.getDonorCode());
1204 item.getOleDonors().add(donor);
1205 item.setDonorCode(null);
1206 }
1207 }
1208 } else {
1209 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1210 OLEConstants.ERROR_DONOR_CODE, new String[]{});
1211 }
1212 }
1213 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1214 }
1215
1216 public ActionForward deleteDonor(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1217 HttpServletResponse response) throws Exception {
1218 LOG.debug("Inside deleteDonor Method of OleRequisitionAction");
1219 OleRequisitionForm purchasingForm = (OleRequisitionForm) form;
1220 String[] indexes = getSelectedLineForAccounts(request);
1221 int itemIndex = Integer.parseInt(indexes[0]);
1222 int donorIndex = Integer.parseInt(indexes[1]);
1223 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItem((itemIndex));
1224 item.getOleDonors().remove(donorIndex);
1225 LOG.debug("Selected Donor is Remove");
1226 LOG.debug("Leaving deleteDonor Method of OleRequisitionAction");
1227 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1228 }
1229
1230 public ActionForward populateAccountingLines(ActionMapping mapping, ActionForm form, HttpServletRequest request,
1231 HttpServletResponse response) throws Exception {
1232
1233 OleRequisitionForm oleRequisitionForm = (OleRequisitionForm) form;
1234 int line = this.getSelectedLine(request);
1235 OleRequisitionItem item = (OleRequisitionItem) ((PurchasingAccountsPayableDocument) oleRequisitionForm.getDocument()).getItem(line);
1236 OleRequisitionDocument oleRequisitionDocument = (OleRequisitionDocument) oleRequisitionForm.getDocument();
1237 Map fundMap = new HashMap();
1238 if (item.getFundCode() != null && !item.getFundCode().trim().isEmpty()) {
1239 fundMap.put(org.kuali.ole.OLEConstants.OLEEResourceRecord.FUND_CODE, item.getFundCode());
1240 List<OleFundCode> oleFundCodes = (List<OleFundCode>) getLookupService().findCollectionBySearch(OleFundCode.class, fundMap);
1241 if (oleFundCodes != null && oleFundCodes.size() > 0) {
1242 OleFundCode oleFundCode = oleFundCodes.get(0);
1243 if (oleFundCode != null) {
1244 if (oleFundCode.getOleFundCodeAccountingLineList() != null) {
1245 List<PurApAccountingLine> accountingLines = new ArrayList<PurApAccountingLine>();
1246 for (OleFundCodeAccountingLine accountingLine : oleFundCode.getOleFundCodeAccountingLineList()) {
1247 OleRequisitionAccount account = new OleRequisitionAccount();
1248 if (accountingLine.getPercentage() != null) {
1249 account.setAccountLinePercent(accountingLine.getPercentage());
1250 }
1251 account.setChartOfAccountsCode(accountingLine.getChartCode());
1252 account.setAccountNumber(accountingLine.getAccountNumber());
1253 account.setSubAccountNumber(accountingLine.getSubAccount());
1254 account.setFinancialObjectCode(accountingLine.getObjectCode());
1255 account.setFinancialSubObjectCode(accountingLine.getSubObject());
1256 account.setProjectCode(accountingLine.getProject());
1257 account.setOrganizationReferenceId(accountingLine.getOrgRefId());
1258 accountingLines.add((PurApAccountingLine) account);
1259 }
1260 item.getSourceAccountingLines().addAll(accountingLines);
1261 }
1262 }
1263 } else {
1264 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1265 OLEConstants.ERROR_FUND_CODE, new String[]{});
1266 }
1267 }else{
1268 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
1269 OLEConstants.EMPTY_FUND_CODE, new String[]{});
1270 }
1271 item.setFundCode(null);
1272 return mapping.findForward(OLEConstants.MAPPING_BASIC);
1273 }
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409 }