1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.ole.fp.businessobject.CreditCardDetail;
22 import org.kuali.ole.sys.OLEConstants;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.OLEParameterKeyConstants;
25 import org.kuali.ole.sys.businessobject.Bank;
26 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
27 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper;
28 import org.kuali.ole.sys.context.SpringContext;
29 import org.kuali.ole.sys.document.AmountTotaling;
30 import org.kuali.ole.sys.document.service.AccountingDocumentRuleHelperService;
31 import org.kuali.ole.sys.service.BankService;
32 import org.kuali.ole.sys.service.GeneralLedgerPendingEntryService;
33 import org.kuali.rice.core.api.util.type.KualiDecimal;
34 import org.kuali.rice.core.web.format.CurrencyFormatter;
35 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
36 import org.kuali.rice.kns.service.DataDictionaryService;
37 import org.kuali.rice.krad.document.Copyable;
38 import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
39 import org.kuali.rice.krad.rules.rule.event.SaveDocumentEvent;
40 import org.kuali.rice.krad.util.GlobalVariables;
41 import org.kuali.rice.krad.util.ObjectUtils;
42
43
44
45
46
47
48
49 public class CreditCardReceiptDocument extends CashReceiptFamilyBase implements Copyable, AmountTotaling {
50 public static final String CREDIT_CARD_RECEIPT_DOCUMENT_TYPE_CODE = "CCR";
51
52
53 protected List<CreditCardDetail> creditCardReceipts = new ArrayList<CreditCardDetail>();
54
55
56 protected Integer nextCcCrLineNumber = new Integer(1);
57
58
59 protected KualiDecimal totalCreditCardAmount = KualiDecimal.ZERO;
60 protected String creditCardReceiptBankCode;
61 protected Bank bank;
62
63
64
65
66 public CreditCardReceiptDocument() {
67 super();
68
69 bank = new Bank();
70 }
71
72
73
74
75
76 public void setDefaultBankCode() {
77 Bank defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(this.getClass());
78 if (defaultBank != null) {
79 this.creditCardReceiptBankCode = defaultBank.getBankCode();
80 this.bank = defaultBank;
81 }
82 }
83
84 @Override
85 public boolean documentPerformsSufficientFundsCheck() {
86 return false;
87 }
88
89
90
91
92
93
94 public KualiDecimal getTotalCreditCardAmount() {
95 return totalCreditCardAmount;
96 }
97
98
99
100
101
102
103 public String getCurrencyFormattedTotalCreditCardAmount() {
104 return (String) new CurrencyFormatter().format(totalCreditCardAmount);
105 }
106
107
108
109
110
111
112 public void setTotalCreditCardAmount(KualiDecimal creditCardAmount) {
113 this.totalCreditCardAmount = creditCardAmount;
114 }
115
116
117
118
119
120
121 public List<CreditCardDetail> getCreditCardReceipts() {
122 return creditCardReceipts;
123 }
124
125
126
127
128
129
130 public void setCreditCardReceipts(List<CreditCardDetail> creditCardReceipts) {
131 this.creditCardReceipts = creditCardReceipts;
132 }
133
134
135
136
137
138
139 public void addCreditCardReceipt(CreditCardDetail creditCardReceiptDetail) {
140
141 prepareNewCreditCardReceipt(creditCardReceiptDetail);
142
143
144 this.creditCardReceipts.add(creditCardReceiptDetail);
145
146
147 this.nextCcCrLineNumber = new Integer(this.nextCcCrLineNumber.intValue() + 1);
148
149
150 this.totalCreditCardAmount = this.totalCreditCardAmount.add(creditCardReceiptDetail.getCreditCardAdvanceDepositAmount());
151 }
152
153
154
155
156
157
158
159 public final void prepareNewCreditCardReceipt(CreditCardDetail creditCardReceiptDetail) {
160 creditCardReceiptDetail.setFinancialDocumentLineNumber(this.nextCcCrLineNumber);
161 creditCardReceiptDetail.setDocumentNumber(this.getDocumentNumber());
162 creditCardReceiptDetail.setFinancialDocumentTypeCode(SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(this.getClass()));
163 }
164
165
166
167
168
169
170
171 public CreditCardDetail getCreditCardReceipt(int index) {
172 while (this.creditCardReceipts.size() <= index) {
173 creditCardReceipts.add(new CreditCardDetail());
174 }
175 return creditCardReceipts.get(index);
176 }
177
178
179
180
181
182
183 public void removeCreditCardReceipt(int index) {
184 CreditCardDetail creditCardReceiptDetail = creditCardReceipts.remove(index);
185 this.totalCreditCardAmount = this.totalCreditCardAmount.subtract(creditCardReceiptDetail.getCreditCardAdvanceDepositAmount());
186 }
187
188
189
190
191 public Integer getNextCcCrLineNumber() {
192 return nextCcCrLineNumber;
193 }
194
195
196
197
198 public void setNextCcCrLineNumber(Integer nextCcCrLineNumber) {
199 this.nextCcCrLineNumber = nextCcCrLineNumber;
200 }
201
202
203
204
205
206
207
208 @Override
209 public KualiDecimal getTotalDollarAmount() {
210 return this.totalCreditCardAmount;
211 }
212
213
214
215
216
217
218 public KualiDecimal calculateCreditCardReceiptTotal() {
219 KualiDecimal total = KualiDecimal.ZERO;
220 for (CreditCardDetail detail : getCreditCardReceipts()) {
221 if (null != detail.getCreditCardAdvanceDepositAmount()) {
222 total = total.add(detail.getCreditCardAdvanceDepositAmount());
223 }
224 }
225 return total;
226 }
227
228
229
230
231
232
233
234 @Override
235 public List buildListOfDeletionAwareLists() {
236 List managedLists = super.buildListOfDeletionAwareLists();
237 managedLists.add(getCreditCardReceipts());
238
239 return managedLists;
240 }
241
242
243
244
245
246
247
248
249
250
251 @Override
252 public boolean generateDocumentGeneralLedgerPendingEntries(GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
253 boolean success = true;
254
255 GeneralLedgerPendingEntryService glpeService = SpringContext.getBean(GeneralLedgerPendingEntryService.class);
256
257 if (SpringContext.getBean(BankService.class).isBankSpecificationEnabled()) {
258 final KualiDecimal bankOffsetAmount = glpeService.getOffsetToCashAmount(this).negated();
259 GeneralLedgerPendingEntry bankOffsetEntry = new GeneralLedgerPendingEntry();
260
261 Bank offsetBank = getOffsetBank();
262 if (ObjectUtils.isNull(offsetBank)) {
263 success = false;
264 GlobalVariables.getMessageMap().putError("newCreditCardReceipt.financialDocumentCreditCardTypeCode", OLEKeyConstants.CreditCardReceipt.ERROR_DOCUMENT_CREDIT_CARD_BANK_MUST_EXIST_WHEN_BANK_ENHANCEMENT_ENABLED, new String[] { OLEParameterKeyConstants.ENABLE_BANK_SPECIFICATION_IND, OLEParameterKeyConstants.DEFAULT_BANK_BY_DOCUMENT_TYPE });
265 }
266 else {
267 success &= glpeService.populateBankOffsetGeneralLedgerPendingEntry(offsetBank, bankOffsetAmount, this, getPostingYear(), sequenceHelper, bankOffsetEntry, OLEConstants.CREDIT_CARD_RECEIPTS_LINE_ERRORS);
268
269
270 if (success) {
271 AccountingDocumentRuleHelperService accountingDocumentRuleUtil = SpringContext.getBean(AccountingDocumentRuleHelperService.class);
272 bankOffsetEntry.setTransactionLedgerEntryDescription(accountingDocumentRuleUtil.formatProperty(OLEKeyConstants.Bank.DESCRIPTION_GLPE_BANK_OFFSET));
273 getGeneralLedgerPendingEntries().add(bankOffsetEntry);
274 sequenceHelper.increment();
275
276 GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(bankOffsetEntry);
277 success &= glpeService.populateOffsetGeneralLedgerPendingEntry(getPostingYear(), bankOffsetEntry, sequenceHelper, offsetEntry);
278 getGeneralLedgerPendingEntries().add(offsetEntry);
279 sequenceHelper.increment();
280 }
281 }
282 }
283
284 return success;
285 }
286
287
288
289
290 public void initiateDocument() {
291
292 Bank defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(this.getClass());
293 if (defaultBank != null) {
294 this.creditCardReceiptBankCode = defaultBank.getBankCode();
295 this.bank = defaultBank;
296 }
297 }
298
299
300
301
302 protected Bank getOffsetBank() {
303 return SpringContext.getBean(BankService.class).getByPrimaryId(creditCardReceiptBankCode);
304 }
305
306
307
308
309
310 public String getCreditCardReceiptBankCode() {
311 return creditCardReceiptBankCode;
312 }
313
314
315
316
317
318
319 public void setCreditCardReceiptBankCode(String creditCardReceiptBankCode) {
320 this.creditCardReceiptBankCode = creditCardReceiptBankCode;
321 }
322
323
324
325
326
327
328 public Bank getBank() {
329 return bank;
330 }
331
332
333
334
335
336
337 public void setBank(Bank bank) {
338 this.bank = bank;
339 }
340
341
342 @Override
343 public void postProcessSave(KualiDocumentEvent event) {
344 super.postProcessSave(event);
345 if (!(event instanceof SaveDocumentEvent)) {
346 String documentTypeName = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(this.getClass());
347 this.getCapitalAssetManagementModuleService().generateCapitalAssetLock(this,documentTypeName);
348 }
349 }
350
351 @Override
352 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
353 super.doRouteStatusChange(statusChangeEvent);
354 this.getCapitalAssetManagementModuleService().deleteDocumentAssetLocks(this);
355 }
356 }