View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.ld.batch.service.impl;
20  
21  import java.util.Date;
22  
23  import org.kuali.kfs.gl.batch.service.PostTransaction;
24  import org.kuali.kfs.gl.businessobject.Transaction;
25  import org.kuali.kfs.module.ld.LaborConstants;
26  import org.kuali.kfs.module.ld.batch.service.LaborAccountingCycleCachingService;
27  import org.kuali.kfs.module.ld.businessobject.LaborTransaction;
28  import org.kuali.kfs.module.ld.businessobject.LedgerBalance;
29  import org.kuali.kfs.sys.KFSConstants;
30  import org.kuali.kfs.sys.service.ReportWriterService;
31  import org.kuali.rice.core.api.util.type.KualiDecimal;
32  import org.kuali.rice.krad.util.ObjectUtils;
33  import org.springframework.transaction.annotation.Transactional;
34  
35  /**
36   * This class is used to post a transaction into Labor Ledger Balance Table
37   */
38  @Transactional
39  public class LaborLedgerBalancePoster implements PostTransaction {
40      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborLedgerBalancePoster.class);
41  
42      private LaborAccountingCycleCachingService laborAccountingCycleCachingService;
43      /**
44       * @see org.kuali.kfs.gl.batch.service.PostTransaction#post(org.kuali.kfs.gl.businessobject.Transaction, int, java.util.Date)
45       */
46      public String post(Transaction transaction, int mode, Date postDate, ReportWriterService posterReportWriterService) {
47          String operationType = KFSConstants.OperationType.INSERT;
48          LedgerBalance ledgerBalance = new LedgerBalance((LaborTransaction) transaction);
49          // ObjectUtil.buildObject(ledgerBalance, transaction);
50  
51          LedgerBalance tempLedgerBalance = laborAccountingCycleCachingService.getLedgerBalance(ledgerBalance);
52          if (ObjectUtils.isNotNull(tempLedgerBalance)) {
53              ledgerBalance = tempLedgerBalance;
54              operationType = KFSConstants.OperationType.UPDATE;
55          }
56          KualiDecimal amount = transaction.getTransactionLedgerEntryAmount();
57          if (transaction.getBalanceType().isFinancialOffsetGenerationIndicator()) { 
58              if (!transaction.getTransactionDebitCreditCode().equals(transaction.getObjectType().getFinObjectTypeDebitcreditCd())) { 
59                  amount = amount.negated(); 
60              } 
61          } 
62  
63          ledgerBalance.addAmount(transaction.getUniversityFiscalPeriodCode(), amount);
64  
65          if (operationType.equals(KFSConstants.OperationType.INSERT)) {
66              laborAccountingCycleCachingService.insertLedgerBalance(ledgerBalance);
67          } else {
68              laborAccountingCycleCachingService.updateLedgerBalance(ledgerBalance);
69          }
70          return operationType;
71      }
72  
73      /**
74       * @see org.kuali.kfs.gl.batch.service.PostTransaction#getDestinationName()
75       */
76      public String getDestinationName() {
77          return LaborConstants.DestinationNames.LEDGER_BALANCE;
78      }
79  
80      public void setLaborAccountingCycleCachingService(LaborAccountingCycleCachingService laborAccountingCycleCachingService) {
81          this.laborAccountingCycleCachingService = laborAccountingCycleCachingService;
82      }
83  }