1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.web.struts;
17
18 import java.util.Iterator;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.apache.struts.action.ActionForm;
24 import org.apache.struts.action.ActionForward;
25 import org.apache.struts.action.ActionMapping;
26 import org.kuali.ole.fp.businessobject.AdvanceDepositDetail;
27 import org.kuali.ole.fp.document.AdvanceDepositDocument;
28 import org.kuali.ole.fp.document.validation.impl.AdvanceDepositDocumentRuleUtil;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.OLEPropertyConstants;
31 import org.kuali.rice.core.api.util.type.KualiDecimal;
32 import org.kuali.rice.krad.util.GlobalVariables;
33
34
35
36
37 public class AdvanceDepositAction extends CapitalAccountingLinesActionBase {
38
39
40
41
42
43
44
45 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
46 AdvanceDepositForm adForm = (AdvanceDepositForm) form;
47
48 if ( adForm != null && adForm.hasDocumentId()) {
49 AdvanceDepositDocument adDoc = adForm.getAdvanceDepositDocument();
50
51 adDoc.setTotalAdvanceDepositAmount(calculateAdvanceDepositTotal(adDoc));
52
53 }
54
55
56 return super.execute(mapping, form, request, response);
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 public ActionForward addAdvanceDeposit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
99 AdvanceDepositForm adForm = (AdvanceDepositForm) form;
100 AdvanceDepositDocument adDoc = adForm.getAdvanceDepositDocument();
101
102 AdvanceDepositDetail newAdvanceDeposit = adForm.getNewAdvanceDeposit();
103 adDoc.prepareNewAdvanceDeposit(newAdvanceDeposit);
104
105
106 boolean rulePassed = validateNewAdvanceDeposit(newAdvanceDeposit);
107 if (rulePassed) {
108
109 adDoc.addAdvanceDeposit(newAdvanceDeposit);
110
111
112 AdvanceDepositDetail advanceDepositDetail = new AdvanceDepositDetail();
113 advanceDepositDetail.setDefaultBankCode();
114 adForm.setNewAdvanceDeposit(advanceDepositDetail);
115 }
116
117 return mapping.findForward(OLEConstants.MAPPING_BASIC);
118 }
119
120
121
122
123
124
125
126
127
128
129
130 public ActionForward deleteAdvanceDeposit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
131 AdvanceDepositForm adForm = (AdvanceDepositForm) form;
132 AdvanceDepositDocument adDoc = adForm.getAdvanceDepositDocument();
133
134 int deleteIndex = getLineToDelete(request);
135
136 adDoc.removeAdvanceDeposit(deleteIndex);
137
138 return mapping.findForward(OLEConstants.MAPPING_BASIC);
139 }
140
141
142
143
144
145
146
147 protected boolean validateNewAdvanceDeposit(AdvanceDepositDetail advanceDeposit) {
148 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.NEW_ADVANCE_DEPOSIT);
149 boolean isValid = AdvanceDepositDocumentRuleUtil.validateAdvanceDeposit(advanceDeposit);
150 GlobalVariables.getMessageMap().removeFromErrorPath(OLEPropertyConstants.NEW_ADVANCE_DEPOSIT);
151 return isValid;
152 }
153
154
155
156
157
158
159 protected KualiDecimal calculateAdvanceDepositTotal(AdvanceDepositDocument advanceDepositDocument) {
160 KualiDecimal total = KualiDecimal.ZERO;
161 Iterator<AdvanceDepositDetail> deposits = advanceDepositDocument.getAdvanceDeposits().iterator();
162 while (deposits.hasNext()) {
163 AdvanceDepositDetail deposit = deposits.next();
164 total = total.add(deposit.getFinancialDocumentAdvanceDepositAmount());
165 }
166 return total;
167 }
168 }