001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * Created on Aug 30, 2004
018: *
019: */
020: package org.kuali.module.pdp.service.impl;
021:
022: import java.sql.Date;
023: import java.sql.Timestamp;
024: import java.util.ArrayList;
025: import java.util.Iterator;
026: import java.util.List;
027:
028: import org.kuali.core.document.Document;
029: import org.kuali.core.service.DocumentService;
030: import org.kuali.core.service.DocumentTypeService;
031: import org.kuali.kfs.KFSConstants;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.kfs.document.AccountingDocument;
034: import org.kuali.module.chart.bo.AccountingPeriod;
035: import org.kuali.module.chart.bo.Chart;
036: import org.kuali.module.chart.bo.OffsetDefinition;
037: import org.kuali.module.chart.service.AccountingPeriodService;
038: import org.kuali.module.chart.service.ChartService;
039: import org.kuali.module.chart.service.OffsetDefinitionService;
040: import org.kuali.module.financial.bo.OffsetAccount;
041: import org.kuali.module.financial.service.FlexibleOffsetAccountService;
042: import org.kuali.module.pdp.bo.GlPendingTransaction;
043: import org.kuali.module.pdp.bo.PaymentAccountDetail;
044: import org.kuali.module.pdp.bo.PaymentDetail;
045: import org.kuali.module.pdp.bo.PaymentGroup;
046: import org.kuali.module.pdp.dao.GlPendingTransactionDao;
047: import org.kuali.module.pdp.service.GlPendingTransactionService;
048: import org.kuali.module.pdp.utilities.GeneralUtilities;
049: import org.springframework.transaction.annotation.Transactional;
050:
051: import edu.iu.uis.eden.exception.WorkflowException;
052:
053: @Transactional
054: public class GlPendingTransactionServiceImpl implements
055: GlPendingTransactionService {
056: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
057: .getLogger(GlPendingTransactionServiceImpl.class);
058:
059: private static String FDOC_TYP_CD_PROCESS_ACH = "ACHD";
060: private static String FDOC_TYP_CD_PROCESS_CHECK = "CHKD";
061: private static String FDOC_TYP_CD_CANCEL_REISSUE_ACH = "ACHR";
062: private static String FDOC_TYP_CD_CANCEL_REISSUE_CHECK = "CHKR";
063: private static String FDOC_TYP_CD_CANCEL_ACH = "ACHC";
064: private static String FDOC_TYP_CD_CANCEL_CHECK = "CHKC";
065:
066: private GlPendingTransactionDao glPendingTransactionDao;
067: private ChartService chartService;
068: private AccountingPeriodService accountingPeriodService;
069:
070: // Inject
071: public void setGlPendingTransactionDao(GlPendingTransactionDao g) {
072: glPendingTransactionDao = g;
073: }
074:
075: // Inject
076: public void setAccountingPeriodService(AccountingPeriodService aps) {
077: this .accountingPeriodService = aps;
078: }
079:
080: // Inject
081: public void setChartService(ChartService c) {
082: chartService = c;
083: }
084:
085: public GlPendingTransactionServiceImpl() {
086: super ();
087: }
088:
089: /*
090: * GlPendingTransaction Fields not used: sequenceNbr // TRN_ENTR_SEQ_NBR NUMBER 5 unifaceVersion // U_VERSION VARCHAR2 1
091: * finObjTypCd // FIN_OBJ_TYP_CD VARCHAR2 2 fdocReversalDt // FDOC_REVERSAL_DT DATE 7 trnEncumUpdtCd // TRN_ENCUM_UPDT_CD
092: * VARCHAR2 1 fdocApprovedCd // FDOC_APPROVED_CD VARCHAR2 1 acctSfFinObjCd // ACCT_SF_FINOBJ_CD VARCHAR2 4 trnEntrOfstCd //
093: * TRN_ENTR_OFST_CD VARCHAR2 1 processInd // TRN_EXTRT_IND VARCHAR2 1
094: */
095:
096: /**
097: * @see org.kuali.module.pdp.service.GlPendingTransactionService#save(org.kuali.module.pdp.bo.GlPendingTransaction)
098: */
099: public void save(GlPendingTransaction tran) {
100: LOG.debug("save() started");
101:
102: glPendingTransactionDao.save(tran);
103: }
104:
105: /**
106: * @see org.kuali.module.pdp.service.GlPendingTransactionService#getUnextractedTransactions()
107: */
108: public Iterator getUnextractedTransactions() {
109: LOG.debug("getUnextractedTransactions() started");
110:
111: return glPendingTransactionDao.getUnextractedTransactions();
112: }
113:
114: /**
115: * @see org.kuali.module.pdp.service.GlPendingTransactionService#createProcessPaymentTransaction(org.kuali.module.pdp.bo.PaymentDetail, java.lang.Boolean)
116: */
117: public void createProcessPaymentTransaction(PaymentDetail pd,
118: Boolean relieveLiabilities) {
119:
120: List accountListings = pd.getAccountDetail();
121:
122: for (Iterator iter = accountListings.iterator(); iter.hasNext();) {
123: PaymentAccountDetail elem = (PaymentAccountDetail) iter
124: .next();
125:
126: GlPendingTransaction gpt = new GlPendingTransaction();
127: gpt.setFdocRefTypCd("PDP");
128: gpt.setFsRefOriginCd("PD");
129: gpt.setFsOriginCd("PD");
130: gpt.setFinancialBalanceTypeCode("AC");
131: Date d = new Date((new java.util.Date()).getTime());
132: gpt.setTransactionDt(new Timestamp(d.getTime()));
133: AccountingPeriod fiscalPeriod = accountingPeriodService
134: .getByDate(d);
135: gpt.setUniversityFiscalYear(fiscalPeriod
136: .getUniversityFiscalYear());
137: gpt.setUnivFiscalPrdCd(fiscalPeriod
138: .getUniversityFiscalPeriodCode());
139:
140: gpt.setAccountNumber(elem.getAccountNbr());
141: gpt.setSubAccountNumber(elem.getSubAccountNbr());
142: gpt.setChartOfAccountsCode(elem.getFinChartCode());
143:
144: if (pd.getPaymentGroup().getDisbursementType().getCode()
145: .equals("ACH")) {
146: gpt
147: .setFinancialDocumentTypeCode(FDOC_TYP_CD_PROCESS_ACH);
148: } else if (pd.getPaymentGroup().getDisbursementType()
149: .getCode().equals("CHCK")) {
150: gpt
151: .setFinancialDocumentTypeCode(FDOC_TYP_CD_PROCESS_CHECK);
152: }
153: gpt.setFdocNbr(pd.getPaymentGroup().getDisbursementNbr()
154: .toString());
155:
156: if ((relieveLiabilities != null)
157: && (relieveLiabilities.booleanValue())
158: && pd.getFinancialDocumentTypeCode() != null) {
159: OffsetDefinition offsetDefinition = SpringContext
160: .getBean(OffsetDefinitionService.class)
161: .getByPrimaryId(gpt.getUniversityFiscalYear(),
162: gpt.getChartOfAccountsCode(),
163: pd.getFinancialDocumentTypeCode(),
164: gpt.getFinancialBalanceTypeCode());
165: if (offsetDefinition != null) {
166: gpt.setFinancialObjectCode(offsetDefinition
167: .getFinancialObjectCode());
168: } else {
169: gpt.setFinancialObjectCode(elem.getFinObjectCode());
170: }
171: gpt.setFinancialSubObjectCode(KFSConstants
172: .getDashFinancialSubObjectCode());
173: } else {
174: gpt.setFinancialObjectCode(elem.getFinObjectCode());
175: gpt.setFinancialSubObjectCode(elem
176: .getFinSubObjectCode());
177: }
178: gpt.setProjectCd(elem.getProjectCode());
179: if (elem.getAccountNetAmount().signum() >= 0) {
180: gpt.setDebitCrdtCd("D");
181: } else {
182: gpt.setDebitCrdtCd("C");
183: }
184: gpt.setAmount(elem.getAccountNetAmount().abs());
185:
186: String trnDesc;
187: String payeeName = pd.getPaymentGroup().getPayeeName();
188: // removed 2/8/2006 per JIRA KULPDP-32
189: // if (payeeName.length() > 32) {
190: // trnDesc = payeeName.substring(0,32) + pd.getId();
191: // } else {
192: // String fill = "";
193: // int j = 32 - payeeName.length();
194: // for (int i = 0; i < j; i++) {
195: // fill = fill + " ";
196: // }
197: // trnDesc = payeeName + fill + pd.getId();
198: // }
199: if (payeeName.length() > 40) {
200: trnDesc = payeeName.substring(0, 40);
201: } else {
202: String fill = "";
203: int j = 40 - payeeName.length();
204: for (int i = 0; i < j; i++) {
205: fill = fill + " ";
206: }
207: trnDesc = payeeName + fill;
208: }
209: gpt.setDescription(trnDesc);
210:
211: gpt.setOrgDocNbr(pd.getOrganizationDocNbr());
212:
213: gpt.setOrgReferenceId(elem.getOrgReferenceId());
214: gpt.setFdocRefNbr(pd.getCustPaymentDocNbr());
215:
216: // update the offset account if necessary
217: SpringContext.getBean(FlexibleOffsetAccountService.class)
218: .updateOffset(gpt);
219:
220: glPendingTransactionDao.save(gpt);
221: }
222: }
223:
224: public void createCancellationTransaction(PaymentGroup pg) {
225: this .createCancellationEntries(pg, FDOC_TYP_CD_CANCEL_ACH,
226: FDOC_TYP_CD_CANCEL_CHECK);
227: }
228:
229: public void createCancelReissueTransaction(PaymentGroup pg) {
230: this .createCancellationEntries(pg,
231: FDOC_TYP_CD_CANCEL_REISSUE_ACH,
232: FDOC_TYP_CD_CANCEL_REISSUE_CHECK);
233: }
234:
235: private void createCancellationEntries(PaymentGroup pg,
236: String achFdocTypeCode, String checkFdocTypeCode) {
237: List accountListings = new ArrayList();
238: for (Iterator iter = pg.getPaymentDetails().iterator(); iter
239: .hasNext();) {
240: PaymentDetail elem = (PaymentDetail) iter.next();
241: accountListings.addAll(elem.getAccountDetail());
242: }
243:
244: for (Iterator iter = accountListings.iterator(); iter.hasNext();) {
245: PaymentAccountDetail elem = (PaymentAccountDetail) iter
246: .next();
247:
248: GlPendingTransaction gpt = new GlPendingTransaction();
249: gpt.setFdocRefTypCd("PDP");
250: gpt.setFsRefOriginCd("PD");
251: gpt.setFsOriginCd("PD");
252: gpt.setFinancialBalanceTypeCode("AC");
253: Date d = new Date((new java.util.Date()).getTime());
254: gpt.setTransactionDt(new Timestamp(d.getTime()));
255: AccountingPeriod fiscalPeriod = accountingPeriodService
256: .getByDate(d);
257: gpt.setUniversityFiscalYear(fiscalPeriod
258: .getUniversityFiscalYear());
259: gpt.setUnivFiscalPrdCd(fiscalPeriod
260: .getUniversityFiscalPeriodCode());
261:
262: gpt.setAccountNumber(elem.getAccountNbr());
263: gpt.setSubAccountNumber(elem.getSubAccountNbr());
264: gpt.setChartOfAccountsCode(elem.getFinChartCode());
265: Boolean relieveLiabilities = pg.getBatch()
266: .getCustomerProfile().getRelieveLiabilities();
267: if ((relieveLiabilities != null)
268: && (relieveLiabilities.booleanValue())
269: && elem.getPaymentDetail()
270: .getFinancialDocumentTypeCode() != null) {
271: OffsetDefinition offsetDefinition = SpringContext
272: .getBean(OffsetDefinitionService.class)
273: .getByPrimaryId(
274: gpt.getUniversityFiscalYear(),
275: gpt.getChartOfAccountsCode(),
276: elem.getPaymentDetail()
277: .getFinancialDocumentTypeCode(),
278: gpt.getFinancialBalanceTypeCode());
279: gpt.setFinancialObjectCode(offsetDefinition
280: .getFinancialObjectCode());
281: gpt.setFinancialSubObjectCode(KFSConstants
282: .getDashFinancialSubObjectCode());
283: } else {
284: gpt.setFinancialObjectCode(elem.getFinObjectCode());
285: gpt.setFinancialSubObjectCode(elem
286: .getFinSubObjectCode());
287: }
288: gpt.setProjectCd(elem.getProjectCode());
289: gpt.setOrgReferenceId(elem.getOrgReferenceId());
290: gpt.setAmount(elem.getAccountNetAmount().abs());
291: gpt.setFdocNbr(pg.getDisbursementNbr().toString());
292: if (elem.getAccountNetAmount().signum() >= 0) {
293: gpt.setDebitCrdtCd("C");
294: } else {
295: gpt.setDebitCrdtCd("D");
296: }
297: if (pg.getDisbursementType().getCode().equals("ACH")) {
298: gpt.setFinancialDocumentTypeCode(achFdocTypeCode);
299: } else if (pg.getDisbursementType().getCode()
300: .equals("CHCK")) {
301: gpt.setFinancialDocumentTypeCode(checkFdocTypeCode);
302: }
303:
304: PaymentDetail pd = elem.getPaymentDetail();
305: String trnDesc;
306: String payeeNameGL;
307: String poNbrGL = "";
308: String invoiceNbrGL = "";
309: if (pg.getPayeeName().length() > 15) {
310: payeeNameGL = pg.getPayeeName().substring(0, 15);
311: } else {
312: String fill = "";
313: int j = 15 - pg.getPayeeName().length();
314: for (int i = 0; i < j; i++) {
315: fill = fill + " ";
316: }
317: payeeNameGL = pg.getPayeeName() + fill;
318: }
319: String poNbr = pd.getPurchaseOrderNbr();
320: if (!(GeneralUtilities.isStringEmpty(poNbr))) {
321: if (poNbr.length() > 9) {
322: poNbrGL = poNbr.substring(0, 9);
323: } else {
324: String fill = "";
325: int j = 9 - poNbr.length();
326: for (int i = 0; i < j; i++) {
327: fill = fill + " ";
328: }
329: poNbrGL = poNbr + fill;
330: }
331: }
332: String invoiceNbr = pd.getInvoiceNbr();
333: if (!(GeneralUtilities.isStringEmpty(invoiceNbr))) {
334: if (invoiceNbr.length() > 14) {
335: invoiceNbrGL = invoiceNbr.substring(0, 14);
336: } else {
337: String fill = "";
338: int j = 14 - invoiceNbr.length();
339: for (int i = 0; i < j; i++) {
340: fill = fill + " ";
341: }
342: invoiceNbrGL = invoiceNbr + fill;
343: }
344: }
345: trnDesc = payeeNameGL + " " + poNbrGL + " " + invoiceNbrGL;
346: if (trnDesc.length() > 40) {
347: trnDesc = trnDesc.substring(0, 40);
348: }
349: gpt.setDescription(trnDesc);
350: gpt.setOrgDocNbr(pd.getOrganizationDocNbr());
351: gpt.setFdocRefNbr(pd.getCustPaymentDocNbr());
352:
353: // update the offset account if necessary
354: SpringContext.getBean(FlexibleOffsetAccountService.class)
355: .updateOffset(gpt);
356:
357: glPendingTransactionDao.save(gpt);
358: }
359: }
360: }
|