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 static org.kuali.ole.sys.OLEConstants.EMPTY_STRING;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.sys.OLEConstants;
22 import org.kuali.ole.sys.OLEKeyConstants;
23 import org.kuali.ole.sys.OLEPropertyConstants;
24 import org.kuali.ole.sys.businessobject.AccountingLine;
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.businessobject.GeneralLedgerPendingEntrySourceDetail;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.document.AccountingDocumentBase;
31 import org.kuali.ole.sys.document.AmountTotaling;
32 import org.kuali.ole.sys.document.Correctable;
33 import org.kuali.ole.sys.document.service.AccountingDocumentRuleHelperService;
34 import org.kuali.ole.sys.document.service.DebitDeterminerService;
35 import org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE;
36 import org.kuali.ole.sys.service.BankService;
37 import org.kuali.ole.sys.service.GeneralLedgerPendingEntryService;
38 import org.kuali.rice.core.api.util.type.KualiDecimal;
39 import org.kuali.rice.krad.document.Copyable;
40 import org.kuali.rice.krad.util.KRADConstants;
41 import org.kuali.rice.krad.util.ObjectUtils;
42
43
44
45
46
47
48 public class NonCheckDisbursementDocument extends AccountingDocumentBase implements Copyable, Correctable, AmountTotaling {
49 protected String financialDocumentBankCode;
50
51 protected Bank bank;
52
53
54
55
56 public NonCheckDisbursementDocument() {
57 bank = new Bank();
58 }
59
60
61
62
63 public void setDefaultBankCode() {
64 Bank defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(this.getClass());
65 if (defaultBank != null) {
66 this.financialDocumentBankCode = defaultBank.getBankCode();
67 this.bank = defaultBank;
68 }
69 }
70
71
72
73
74
75
76 public String getFinancialDocumentBankCode() {
77 return financialDocumentBankCode;
78 }
79
80
81
82
83
84
85 public void setFinancialDocumentBankCode(String financialDocumentBankCode) {
86 this.financialDocumentBankCode = financialDocumentBankCode;
87 }
88
89
90
91
92
93
94 public Bank getBank() {
95 return bank;
96 }
97
98
99
100
101
102
103 public void setBank(Bank bank) {
104 this.bank = bank;
105 }
106
107
108
109
110
111
112 @Override
113 public String getSourceAccountingLinesSectionTitle() {
114 return EMPTY_STRING;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) throws IllegalStateException {
132 DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
133 return isDebitUtils.isDebitConsideringNothingPositiveOnly(this, (AccountingLine) postable);
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 @Override
150 public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) {
151 explicitEntry.setTransactionLedgerEntryDescription(buildTransactionLedgerEntryDescriptionUsingRefOriginAndRefDocNumber(postable));
152
153
154
155
156 explicitEntry.setReferenceFinancialDocumentNumber(null);
157 explicitEntry.setReferenceFinancialSystemOriginationCode(null);
158 explicitEntry.setReferenceFinancialDocumentTypeCode(null);
159 }
160
161
162
163
164 @Override
165 public boolean generateDocumentGeneralLedgerPendingEntries(GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
166 boolean success = true;
167
168 if (!SpringContext.getBean(BankService.class).isBankSpecificationEnabled()) {
169 return success;
170 }
171
172 this.refreshReferenceObject(OLEPropertyConstants.BANK);
173
174 if (!ObjectUtils.isNull(getBank())) {
175
176 GeneralLedgerPendingEntryService glpeService = SpringContext.getBean(GeneralLedgerPendingEntryService.class);
177
178 final KualiDecimal bankOffsetAmount = glpeService.getOffsetToCashAmount(this).negated();
179 GeneralLedgerPendingEntry bankOffsetEntry = new GeneralLedgerPendingEntry();
180 success &= glpeService.populateBankOffsetGeneralLedgerPendingEntry(getBank(), bankOffsetAmount, this, getPostingYear(), sequenceHelper, bankOffsetEntry, KRADConstants.DOCUMENT_PROPERTY_NAME + "." + OLEPropertyConstants.FINANCIAL_DOCUMENT_BANK_CODE);
181
182 if (success) {
183 AccountingDocumentRuleHelperService accountingDocumentRuleUtil = SpringContext.getBean(AccountingDocumentRuleHelperService.class);
184 bankOffsetEntry.setTransactionLedgerEntryDescription(accountingDocumentRuleUtil.formatProperty(OLEKeyConstants.Bank.DESCRIPTION_GLPE_BANK_OFFSET));
185 getGeneralLedgerPendingEntries().add(bankOffsetEntry);
186 sequenceHelper.increment();
187
188 GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(bankOffsetEntry);
189 success &= glpeService.populateOffsetGeneralLedgerPendingEntry(getPostingYear(), bankOffsetEntry, sequenceHelper, offsetEntry);
190 getGeneralLedgerPendingEntries().add(offsetEntry);
191 sequenceHelper.increment();
192 }
193 }
194
195 return success;
196 }
197
198
199
200
201
202
203
204
205
206 protected String buildTransactionLedgerEntryDescriptionUsingRefOriginAndRefDocNumber(GeneralLedgerPendingEntrySourceDetail postable) {
207 String description = "";
208 if (StringUtils.isBlank(postable.getReferenceNumber())) {
209 throw new IllegalStateException("Reference Document Number is required and should be validated before this point.");
210 }
211
212 description = OLEConstants.ORIGIN_CODE_KUALI + "-" + postable.getReferenceNumber();
213
214 if (StringUtils.isNotBlank(postable.getFinancialDocumentLineDescription())) {
215 description += ": " + postable.getFinancialDocumentLineDescription();
216 }
217 else {
218 description += ": " + getDocumentHeader().getDocumentDescription();
219 }
220
221 if (description.length() > GENERAL_LEDGER_PENDING_ENTRY_CODE.GLPE_DESCRIPTION_MAX_LENGTH) {
222 description = description.substring(0, GENERAL_LEDGER_PENDING_ENTRY_CODE.GLPE_DESCRIPTION_MAX_LENGTH - 3) + "...";
223 }
224
225 return description;
226 }
227 }