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: package org.kuali.module.pdp.service.impl;
017:
018: import java.sql.Date;
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.Iterator;
022:
023: import org.kuali.core.service.DateTimeService;
024: import org.kuali.module.gl.bo.OriginEntryGroup;
025: import org.kuali.module.gl.bo.OriginEntrySource;
026: import org.kuali.module.gl.service.OriginEntryGroupService;
027: import org.kuali.module.gl.service.OriginEntryService;
028: import org.kuali.module.gl.util.LedgerEntryHolder;
029: import org.kuali.module.gl.util.LedgerReport;
030: import org.kuali.module.pdp.bo.GlPendingTransaction;
031: import org.kuali.module.pdp.service.ExtractGlTransactionService;
032: import org.kuali.module.pdp.service.GlPendingTransactionService;
033: import org.springframework.transaction.annotation.Transactional;
034:
035: @Transactional
036: public class ExtractGlTransactionServiceImpl implements
037: ExtractGlTransactionService {
038: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(ExtractGlTransactionServiceImpl.class);
040:
041: private GlPendingTransactionService glPendingTransactionService;
042: private OriginEntryGroupService originEntryGroupService;
043: private OriginEntryService originEntryService;
044: private DateTimeService dateTimeService;
045: private String reportsDirectory;
046:
047: /**
048: * @see org.kuali.module.pdp.service.ExtractGlTransactionService#extractGlTransactions()
049: */
050: public void extractGlTransactions() {
051: LOG.debug("extractGlTransactions() started");
052:
053: Date processDate = dateTimeService.getCurrentSqlDate();
054: OriginEntryGroup oeg = null;
055: Iterator transactions = glPendingTransactionService
056: .getUnextractedTransactions();
057: while (transactions.hasNext()) {
058: GlPendingTransaction tran = (GlPendingTransaction) transactions
059: .next();
060:
061: // We only want to create the group if there are transactions in the group
062: if (oeg == null) {
063: oeg = originEntryGroupService.createGroup(processDate,
064: OriginEntrySource.PDP, true, true, true);
065: }
066:
067: originEntryService.createEntry(tran.getOriginEntry(), oeg);
068:
069: tran.setProcessInd("Y");
070: glPendingTransactionService.save(tran);
071: }
072:
073: if (oeg != null) {
074: // Run a report
075: Collection groups = new ArrayList();
076: groups.add(oeg);
077: LedgerEntryHolder ledgerEntries = originEntryService
078: .getSummaryByGroupId(groups);
079:
080: LedgerReport ledgerReport = new LedgerReport();
081: ledgerReport.generateReport(ledgerEntries, processDate,
082: "PDP Transactions", "pdp_ledger", reportsDirectory);
083: }
084: }
085:
086: public void setDateTimeService(DateTimeService dateTimeService) {
087: this .dateTimeService = dateTimeService;
088: }
089:
090: public void setGlPendingTransactionService(
091: GlPendingTransactionService glPendingTransactionService) {
092: this .glPendingTransactionService = glPendingTransactionService;
093: }
094:
095: public void setOriginEntryGroupService(
096: OriginEntryGroupService originEntryGroupService) {
097: this .originEntryGroupService = originEntryGroupService;
098: }
099:
100: public void setOriginEntryService(
101: OriginEntryService originEntryService) {
102: this .originEntryService = originEntryService;
103: }
104:
105: public void setReportsDirectory(String rd) {
106: this.reportsDirectory = rd;
107: }
108: }
|