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