1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.fp.document.validation.impl;
17  
18  import org.kuali.ole.fp.businessobject.BudgetAdjustmentAccountingLine;
19  import org.kuali.ole.sys.OLEKeyConstants;
20  import org.kuali.ole.sys.OLEPropertyConstants;
21  import org.kuali.ole.sys.document.AccountingDocument;
22  import org.kuali.ole.sys.document.service.DebitDeterminerService;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.core.api.util.type.KualiDecimal;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  
29  
30  
31  public class BudgetAdjustmentAccountingLineAmountValidation extends GenericValidation {
32      private BudgetAdjustmentAccountingLine accountingLineForValidation;
33      private AccountingDocument accountingDocumentForValidation;
34      private DebitDeterminerService debitDeterminerService;
35  
36      
37  
38  
39  
40  
41      public boolean validate(AttributedDocumentEvent event) {
42          boolean amountValid = true;
43  
44          
45          if (getAccountingLineForValidation().getCurrentBudgetAdjustmentAmount().isZero() && getAccountingLineForValidation().getBaseBudgetAdjustmentAmount().isZero()) {
46              GlobalVariables.getMessageMap().putError(OLEPropertyConstants.BASE_BUDGET_ADJUSTMENT_AMOUNT, OLEKeyConstants.ERROR_BA_AMOUNT_ZERO);
47              amountValid = false;
48          }
49  
50          
51          if (!debitDeterminerService.isErrorCorrection(getAccountingDocumentForValidation())) {
52              amountValid &= checkAmountSign(getAccountingLineForValidation().getCurrentBudgetAdjustmentAmount(), OLEPropertyConstants.CURRENT_BUDGET_ADJUSTMENT_AMOUNT, "Current");
53              amountValid &= checkAmountSign(getAccountingLineForValidation().getBaseBudgetAdjustmentAmount(), OLEPropertyConstants.BASE_BUDGET_ADJUSTMENT_AMOUNT, "Base");
54              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth1LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_1_LINE_AMOUNT, "Month 1");
55              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth2LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_2_LINE_AMOUNT, "Month 2");
56              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth3LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_3_LINE_AMOUNT, "Month 3");
57              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth4LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_4_LINE_AMOUNT, "Month 4");
58              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth5LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_5_LINE_AMOUNT, "Month 5");
59              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth6LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_6_LINE_AMOUNT, "Month 6");
60              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth7LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_7_LINE_AMOUNT, "Month 7");
61              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth8LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_8_LINE_AMOUNT, "Month 8");
62              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth8LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_9_LINE_AMOUNT, "Month 9");
63              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth10LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_10_LINE_AMOUNT, "Month 10");
64              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth10LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_11_LINE_AMOUNT, "Month 11");
65              amountValid &= checkAmountSign(getAccountingLineForValidation().getFinancialDocumentMonth12LineAmount(), OLEPropertyConstants.FINANCIAL_DOCUMENT_MONTH_12_LINE_AMOUNT, "Month 12");
66          }
67  
68          return amountValid;
69      }
70  
71      
72  
73  
74  
75  
76  
77  
78  
79      protected boolean checkAmountSign(KualiDecimal amount, String propertyName, String label) {
80          boolean correctSign = true;
81  
82          if (amount.isNegative()) {
83              GlobalVariables.getMessageMap().putError(propertyName, OLEKeyConstants.ERROR_BA_AMOUNT_NEGATIVE, label);
84              correctSign = false;
85          }
86  
87          return correctSign;
88      }
89  
90  
91      
92  
93  
94  
95      public BudgetAdjustmentAccountingLine getAccountingLineForValidation() {
96          return accountingLineForValidation;
97      }
98  
99      
100 
101 
102 
103     public void setAccountingLineForValidation(BudgetAdjustmentAccountingLine accountingLineForValidation) {
104         this.accountingLineForValidation = accountingLineForValidation;
105     }
106 
107     
108 
109 
110 
111     public AccountingDocument getAccountingDocumentForValidation() {
112         return accountingDocumentForValidation;
113     }
114 
115     
116 
117 
118 
119     public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
120         this.accountingDocumentForValidation = accountingDocumentForValidation;
121     }
122 
123     
124 
125 
126 
127     public DebitDeterminerService getDebitDeterminerService() {
128         return debitDeterminerService;
129     }
130 
131     
132 
133 
134 
135     public void setDebitDeterminerService(DebitDeterminerService debitDeterminerService) {
136         this.debitDeterminerService = debitDeterminerService;
137     }
138 }