1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.module.purap.PurapConstants;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
21 import org.kuali.ole.module.purap.service.PurapAccountingService;
22 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
23 import org.kuali.ole.sys.document.validation.GenericValidation;
24 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Set;
30
31 public class PurchasingAccountsPayableCheckNegativeAccountsValidation extends GenericValidation {
32
33 private PurapAccountingService purapAccountingService;
34
35 public boolean validate(AttributedDocumentEvent event) {
36 boolean valid = true;
37 PurchasingAccountsPayableDocument document = (PurchasingAccountsPayableDocument) event.getDocument();
38
39 GlobalVariables.getMessageMap().clearErrorPath();
40
41
42
43 purapAccountingService.updateAccountAmounts(document);
44
45
46 Set excludedItemTypeCodes = new HashSet();
47 excludedItemTypeCodes.add(PurapConstants.ItemTypeCodes.ITEM_TYPE_TRADE_IN_CODE);
48 List<SourceAccountingLine> sourceLines = purapAccountingService.generateSummaryExcludeItemTypes(document.getItems(), excludedItemTypeCodes);
49
50 for (SourceAccountingLine sourceAccountingLine : sourceLines) {
51
52 boolean isTaxAccount = purapAccountingService.isTaxAccount(document, sourceAccountingLine);
53
54
55 if (!isTaxAccount && sourceAccountingLine.getAmount().isNegative()) {
56
57 String subAccountNumber = (sourceAccountingLine.getSubAccountNumber() == null) ? "" : sourceAccountingLine.getSubAccountNumber();
58 String subObjectCode = (sourceAccountingLine.getFinancialSubObjectCode() == null) ? "" : sourceAccountingLine.getFinancialSubObjectCode();
59 String projCode = (sourceAccountingLine.getProjectCode() == null) ? "" : sourceAccountingLine.getProjectCode();
60 String orgRefId = (sourceAccountingLine.getOrganizationReferenceId() == null) ? "" : sourceAccountingLine.getOrganizationReferenceId();
61
62 String accountString = sourceAccountingLine.getChartOfAccountsCode() + " - " + sourceAccountingLine.getAccountNumber() + " - " + subAccountNumber + " - " + sourceAccountingLine.getFinancialObjectCode() + " - " + subObjectCode + " - " + projCode + " - " + orgRefId;
63 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ACCOUNT_AMOUNT_TOTAL, accountString, sourceAccountingLine.getAmount() + "");
64 valid &= false;
65 }
66 }
67
68 GlobalVariables.getMessageMap().clearErrorPath();
69 return valid;
70 }
71
72 public PurapAccountingService getPurapAccountingService() {
73 return purapAccountingService;
74 }
75
76 public void setPurapAccountingService(PurapAccountingService purapAccountingService) {
77 this.purapAccountingService = purapAccountingService;
78 }
79
80 }