/* * The Kuali Financial System, a comprehensive financial management system for higher education. * * Copyright 2005-2014 The Kuali Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.kuali.kfs.fp.document; import static org.kuali.kfs.sys.KFSConstants.BALANCE_TYPE_PRE_ENCUMBRANCE; import java.util.ArrayList; import java.util.List; import org.kuali.kfs.sys.KFSConstants; import org.kuali.kfs.sys.businessobject.AccountingLine; import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry; import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail; import org.kuali.kfs.sys.businessobject.SufficientFundsItem; import org.kuali.kfs.sys.context.SpringContext; import org.kuali.kfs.sys.document.AccountingDocumentBase; import org.kuali.kfs.sys.document.AmountTotaling; import org.kuali.kfs.sys.document.service.DebitDeterminerService; import org.kuali.kfs.sys.service.HomeOriginationService; import org.kuali.rice.core.api.datetime.DateTimeService; import org.kuali.rice.kew.api.exception.WorkflowException; import org.kuali.rice.krad.document.Copyable; /** * The Pre-Encumbrance document provides the capability to record encumbrances independently of purchase orders, travel, or Physical * Plant work orders. These transactions are for the use of the account manager to earmark funds for which unofficial commitments * have already been made. */ public class PreEncumbranceDocument extends AccountingDocumentBase implements Copyable, AmountTotaling { protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PreEncumbranceDocument.class); protected java.sql.Date reversalDate; /** * Initializes the array lists and some basic info. */ public PreEncumbranceDocument() { super(); } /** * @see org.kuali.kfs.sys.document.AccountingDocumentBase#checkSufficientFunds() */ @Override public List<SufficientFundsItem> checkSufficientFunds() { LOG.debug("checkSufficientFunds() started"); // This document does not do sufficient funds checking return new ArrayList<SufficientFundsItem>(); } /** * @return Timestamp */ public java.sql.Date getReversalDate() { return reversalDate; } /** * @param reversalDate */ public void setReversalDate(java.sql.Date reversalDate) { this.reversalDate = reversalDate; } /** * Overrides the base implementation to return "Encumbrance". * * @see org.kuali.kfs.sys.document.AccountingDocument#getSourceAccountingLinesSectionTitle() */ @Override public String getSourceAccountingLinesSectionTitle() { return KFSConstants.ENCUMBRANCE; } /** * Overrides the base implementation to return "Disencumbrance". * * @see org.kuali.kfs.sys.document.AccountingDocument#getTargetAccountingLinesSectionTitle() */ @Override public String getTargetAccountingLinesSectionTitle() { return KFSConstants.DISENCUMBRANCE; } /** * This method limits valid debits to only income object type codes. Additionally, an * IllegalStateException will be thrown if the accounting line passed in is not an income, * is an error correction with a positive dollar amount or is not an error correction and * has a negative amount. * * @param transactionalDocument The document the accounting line being checked is located in. * @param accountingLine The accounting line being analyzed. * @return True if the accounting line given is a debit accounting line, false otherwise. * * @see IsDebitUtils#isDebitConsideringSection(FinancialDocumentRuleBase, FinancialDocument, AccountingLine) * @see org.kuali.rice.krad.rule.AccountingLineRule#isDebit(org.kuali.rice.krad.document.FinancialDocument, * org.kuali.rice.krad.bo.AccountingLine) */ @Override public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) { AccountingLine accountingLine = (AccountingLine)postable; DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class); if (isDebitUtils.isErrorCorrection(this) == accountingLine.getAmount().isPositive()) { throw new IllegalStateException(isDebitUtils.getDebitCalculationIllegalStateExceptionMessage()); } boolean isDebit = false; if(isDebitUtils.isIncome(postable)) { isDebit = isDebitUtils.isDebitConsideringSection(this, accountingLine); } else { isDebit = !isDebitUtils.isDebitConsideringSection(this, accountingLine); } return isDebit; } /** * This method contains PreEncumbrance document specific general ledger pending entry explicit entry * attribute assignments. These attributes include financial balance type code, reversal date and * transaction encumbrance update code. * * @param financialDocument The document which contains the explicit entry. * @param accountingLine The accounting line the explicit entry is generated from. * @param explicitEntry The explicit entry being updated. * * @see org.kuali.module.financial.rules.FinancialDocumentRuleBase#customizeExplicitGeneralLedgerPendingEntry(org.kuali.rice.krad.document.FinancialDocument, * org.kuali.rice.krad.bo.AccountingLine, org.kuali.module.gl.bo.GeneralLedgerPendingEntry) */ @Override public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) { explicitEntry.setFinancialBalanceTypeCode(BALANCE_TYPE_PRE_ENCUMBRANCE); AccountingLine accountingLine = (AccountingLine)postable; // set the reversal date to what was chosen by the user in the interface if (getReversalDate() != null) { explicitEntry.setFinancialDocumentReversalDate(getReversalDate()); } explicitEntry.setTransactionEntryProcessedTs(null); if (accountingLine.isSourceAccountingLine()) { explicitEntry.setTransactionEncumbranceUpdateCode(KFSConstants.ENCUMB_UPDT_DOCUMENT_CD); } else { explicitEntry.setTransactionEncumbranceUpdateCode(KFSConstants.ENCUMB_UPDT_REFERENCE_DOCUMENT_CD); explicitEntry.setReferenceFinancialSystemOriginationCode(SpringContext.getBean(HomeOriginationService.class).getHomeOrigination().getFinSystemHomeOriginationCode()); explicitEntry.setReferenceFinancialDocumentNumber(accountingLine.getReferenceNumber()); explicitEntry.setReferenceFinancialDocumentTypeCode(explicitEntry.getFinancialDocumentTypeCode()); // "PE" } } /** * @see org.kuali.kfs.sys.document.AccountingDocumentBase#toCopy() */ @Override public void toCopy() throws WorkflowException { super.toCopy(); refreshReversalDate(); } /** * If the reversal date on this document is in need of refreshing, refreshes the reveral date. THIS METHOD MAY CHANGE DOCUMENT STATE! * @return true if the reversal date ended up getting refreshed, false otherwise */ protected boolean refreshReversalDate() { boolean refreshed = false; if (getReversalDate() != null) { java.sql.Date today = SpringContext.getBean(DateTimeService.class).getCurrentSqlDateMidnight(); if (getReversalDate().before(today)) { // set the reversal date on the document setReversalDate(today); refreshed = true; } } return refreshed; } }