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.CashDrawer;
19 import org.kuali.ole.fp.businessobject.CoinDetail;
20 import org.kuali.ole.fp.businessobject.CurrencyDetail;
21 import org.kuali.ole.fp.document.CashReceiptDocument;
22 import org.kuali.ole.fp.document.CashReceiptFamilyBase;
23 import org.kuali.ole.fp.document.service.CashReceiptService;
24 import org.kuali.ole.fp.service.CashDrawerService;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEKeyConstants;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.sys.document.validation.GenericValidation;
29 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
30 import org.kuali.ole.sys.service.FinancialSystemWorkflowHelperService;
31 import org.kuali.rice.kew.api.WorkflowDocument;
32 import org.kuali.rice.krad.util.GlobalVariables;
33
34
35
36
37 public class CashReceiptCashDrawerOpenValidation extends GenericValidation {
38 private CashReceiptFamilyBase cashReceiptDocumentForValidation;
39 private CashReceiptService cashReceiptService;
40 private CashDrawerService cashDrawerService;
41
42
43
44
45
46
47 @Override
48 public boolean validate(AttributedDocumentEvent event) {
49
50 CashDrawer cd = getCashDrawerService().getByCampusCode(getCashReceiptDocumentForValidation().getCampusLocationCode());
51 if (cd == null) {
52 throw new IllegalStateException("There is no cash drawer associated with unitName '" + getCashReceiptDocumentForValidation().getCampusLocationCode() + "' from cash receipt " + getCashReceiptDocumentForValidation().getDocumentNumber());
53 }
54 WorkflowDocument workflowDocument = getCashReceiptDocumentForValidation().getDocumentHeader().getWorkflowDocument();
55 boolean isAdhocApproval = SpringContext.getBean(FinancialSystemWorkflowHelperService.class).isAdhocApprovalRequestedForPrincipal(workflowDocument, GlobalVariables.getUserSession().getPrincipalId());
56
57 if (cd.isClosed() && !isAdhocApproval) {
58 GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.CashReceipt.MSG_CASH_DRAWER_CLOSED_VERIFICATION_NOT_ALLOWED, cd.getCampusCode());
59 return false;
60 }
61
62
63 CashReceiptDocument crDoc = (CashReceiptDocument)cashReceiptDocumentForValidation;
64
65 if (crDoc.getChangeCurrencyDetail() != null && crDoc.getChangeCoinDetail() != null) {
66 return checkChangeRequestIsValid();
67 }
68 return true;
69 }
70
71
72
73
74
75
76
77 public boolean checkChangeRequestIsValid() {
78 CashDrawer cd = getCashDrawerService().getByCampusCode(getCashReceiptDocumentForValidation().getCampusLocationCode());
79 CurrencyDetail changeCurrency = ((CashReceiptDocument) getCashReceiptDocumentForValidation()).getChangeCurrencyDetail();
80 CoinDetail changeCoin = ((CashReceiptDocument) getCashReceiptDocumentForValidation()).getChangeCoinDetail();
81 CurrencyDetail confirmedCurrency = ((CashReceiptDocument) getCashReceiptDocumentForValidation()).getConfirmedCurrencyDetail();
82 CoinDetail confirmedCoin = ((CashReceiptDocument) getCashReceiptDocumentForValidation()).getConfirmedCoinDetail();
83
84 if(changeCurrency.getHundredDollarCount() > cd.getHundredDollarCount() + confirmedCurrency.getHundredDollarCount() ||
85 changeCurrency.getFiftyDollarCount() > cd.getFiftyDollarCount() + confirmedCurrency.getFiftyDollarCount() ||
86 changeCurrency.getTwentyDollarCount() > cd.getTwentyDollarCount() + confirmedCurrency.getTwentyDollarCount() ||
87 changeCurrency.getTenDollarCount() > cd.getTenDollarCount() + confirmedCurrency.getTenDollarCount() ||
88 changeCurrency.getFiveDollarCount() > cd.getFiveDollarCount() + confirmedCurrency.getFiveDollarCount() ||
89 changeCurrency.getTwoDollarCount() > cd.getTwoDollarCount() + confirmedCurrency.getTwoDollarCount() ||
90 changeCurrency.getOneDollarCount() > cd.getOneDollarCount() + confirmedCurrency.getOneDollarCount() ||
91 changeCoin.getHundredCentCount() > cd.getHundredCentCount() + confirmedCoin.getHundredCentCount() ||
92 changeCoin.getFiftyCentCount() > cd.getFiftyCentCount() + confirmedCoin.getFiftyCentCount() ||
93 changeCoin.getTwentyFiveCentCount() > cd.getTwentyFiveCentCount() + confirmedCoin.getTwentyFiveCentCount() ||
94 changeCoin.getTenCentCount() > cd.getTenCentCount() + confirmedCoin.getTenCentCount() ||
95 changeCoin.getFiveCentCount() > cd.getFiveCentCount() + confirmedCoin.getFiveCentCount() ||
96 changeCoin.getOneCentCount() > cd.getOneCentCount() + confirmedCoin.getOneCentCount()) {
97
98 GlobalVariables.getMessageMap().putError(OLEConstants.GLOBAL_ERRORS, OLEKeyConstants.CashReceipt.ERROR_CHANGE_REQUEST, "");
99 return false;
100 }
101
102 return true;
103 }
104
105
106
107
108
109 public CashReceiptFamilyBase getCashReceiptDocumentForValidation() {
110 return cashReceiptDocumentForValidation;
111 }
112
113
114
115
116
117 public void setCashReceiptDocumentForValidation(CashReceiptFamilyBase cashReceiptFamilyDocumentForValidation) {
118 this.cashReceiptDocumentForValidation = cashReceiptFamilyDocumentForValidation;
119 }
120
121
122
123
124
125 public CashDrawerService getCashDrawerService() {
126 return cashDrawerService;
127 }
128
129
130
131
132
133 public void setCashDrawerService(CashDrawerService cashDrawerService) {
134 this.cashDrawerService = cashDrawerService;
135 }
136
137
138
139
140
141 public CashReceiptService getCashReceiptService() {
142 return cashReceiptService;
143 }
144
145
146
147
148
149 public void setCashReceiptService(CashReceiptService cashReceiptService) {
150 this.cashReceiptService = cashReceiptService;
151 }
152 }