View Javadoc
1   /*
2    * Copyright 2005-2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17   * Created on Oct 12, 2005
18   *
19   */
20  package org.kuali.ole.gl.batch.service.impl;
21  
22  import java.util.Date;
23  
24  import org.kuali.ole.gl.GeneralLedgerConstants;
25  import org.kuali.ole.gl.batch.service.AccountingCycleCachingService;
26  import org.kuali.ole.gl.batch.service.PostTransaction;
27  import org.kuali.ole.gl.businessobject.Reversal;
28  import org.kuali.ole.gl.businessobject.Transaction;
29  import org.kuali.ole.sys.service.ReportWriterService;
30  import org.kuali.rice.krad.service.PersistenceStructureService;
31  import org.springframework.transaction.annotation.Transactional;
32  
33  /**
34   * An implementation of PostTransaction which posts any reversals that need to be created for the transaction
35   */
36  @Transactional
37  public class PostReversal implements PostTransaction {
38      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PostReversal.class);
39  
40      private AccountingCycleCachingService accountingCycleCachingService;
41      private PersistenceStructureService persistenceStructureService;
42  
43      /**
44       * Constructs a PostReversal instance
45       */
46      public PostReversal() {
47          super();
48      }
49  
50      /**
51       * If the transaction has a reversal date, saves a new reversal based on the transaction
52       * 
53       * @param t the transaction which is being posted
54       * @param mode the mode the poster is currently running in
55       * @param postDate the date this transaction should post to
56       * @param posterReportWriterService the writer service where the poster is writing its report
57       * @return the accomplished post type
58       * @see org.kuali.ole.gl.batch.service.PostTransaction#post(org.kuali.ole.gl.businessobject.Transaction, int, java.util.Date)
59       */
60      public String post(Transaction t, int mode, Date postDate, ReportWriterService posterReportWriterService) {
61          LOG.debug("post() started");
62  
63          if (t.getFinancialDocumentReversalDate() == null) {
64              // No need to post this
65              return GeneralLedgerConstants.EMPTY_CODE;
66          }
67  
68          Reversal re = new Reversal(t);
69  
70          accountingCycleCachingService.insertReversal(re);
71  
72          return GeneralLedgerConstants.INSERT_CODE;
73      }
74  
75      /**
76       * @see org.kuali.ole.gl.batch.service.PostTransaction#getDestinationName()
77       */
78      public String getDestinationName() {
79          return persistenceStructureService.getTableName(Reversal.class);
80      }
81  
82      public void setAccountingCycleCachingService(AccountingCycleCachingService accountingCycleCachingService) {
83          this.accountingCycleCachingService = accountingCycleCachingService;
84      }
85  
86      public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) {
87          this.persistenceStructureService = persistenceStructureService;
88      }
89  }