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