001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 Oct 12, 2005
018 *
019 */
020 package org.kuali.kfs.gl.batch.service.impl;
021
022 import java.util.Date;
023
024 import org.apache.ojb.broker.metadata.MetadataManager;
025 import org.kuali.kfs.gl.GeneralLedgerConstants;
026 import org.kuali.kfs.gl.batch.service.AccountingCycleCachingService;
027 import org.kuali.kfs.gl.batch.service.PostTransaction;
028 import org.kuali.kfs.gl.businessobject.ExpenditureTransaction;
029 import org.kuali.kfs.gl.businessobject.Reversal;
030 import org.kuali.kfs.gl.businessobject.Transaction;
031 import org.kuali.kfs.gl.dataaccess.ReversalDao;
032 import org.kuali.kfs.sys.service.ReportWriterService;
033 import org.kuali.rice.kns.service.PersistenceStructureService;
034 import org.springframework.transaction.annotation.Transactional;
035
036 /**
037 * An implementation of PostTransaction which posts any reversals that need to be created for the transaction
038 */
039 @Transactional
040 public class PostReversal implements PostTransaction {
041 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PostReversal.class);
042
043 private AccountingCycleCachingService accountingCycleCachingService;
044 private PersistenceStructureService persistenceStructureService;
045
046 /**
047 * Constructs a PostReversal instance
048 */
049 public PostReversal() {
050 super();
051 }
052
053 /**
054 * If the transaction has a reversal date, saves a new reversal based on the transaction
055 *
056 * @param t the transaction which is being posted
057 * @param mode the mode the poster is currently running in
058 * @param postDate the date this transaction should post to
059 * @param posterReportWriterService the writer service where the poster is writing its report
060 * @return the accomplished post type
061 * @see org.kuali.kfs.gl.batch.service.PostTransaction#post(org.kuali.kfs.gl.businessobject.Transaction, int, java.util.Date)
062 */
063 public String post(Transaction t, int mode, Date postDate, ReportWriterService posterReportWriterService) {
064 LOG.debug("post() started");
065
066 if (t.getFinancialDocumentReversalDate() == null) {
067 // No need to post this
068 return GeneralLedgerConstants.EMPTY_CODE;
069 }
070
071 Reversal re = new Reversal(t);
072
073 accountingCycleCachingService.insertReversal(re);
074
075 return GeneralLedgerConstants.INSERT_CODE;
076 }
077
078 /**
079 * @see org.kuali.kfs.gl.batch.service.PostTransaction#getDestinationName()
080 */
081 public String getDestinationName() {
082 return persistenceStructureService.getTableName(Reversal.class);
083 }
084
085 public void setAccountingCycleCachingService(AccountingCycleCachingService accountingCycleCachingService) {
086 this.accountingCycleCachingService = accountingCycleCachingService;
087 }
088
089 public void setPersistenceStructureService(PersistenceStructureService persistenceStructureService) {
090 this.persistenceStructureService = persistenceStructureService;
091 }
092 }