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 */
016package org.kuali.ole.fp.document;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.ole.sys.businessobject.AccountingLine;
020import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
021import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
022import org.kuali.ole.sys.context.SpringContext;
023import org.kuali.ole.sys.document.service.DebitDeterminerService;
024
025/**
026 * This is the business object that represents the ServiceBillingDocument in Kuali. See
027 * {@link org.kuali.ole.fp.document.validation.impl.ServiceBillingDocumentRule} for details on how it differs from
028 * {@link InternalBillingDocument}.
029 */
030public class ServiceBillingDocument extends InternalBillingDocument implements CapitalAssetEditable {
031
032    /**
033     * This method further restricts the valid accounting line types exclusively to those with income or expense object type codes
034     * only. This is done by calling isIncome() and isExpense() passing the accounting line.
035     * 
036     * @param financialDocument The document used to determine if the accounting line is a debit line.
037     * @param accountingLine The accounting line to be analyzed.
038     * @return True if the accounting line passed in is an expense or income accounting line and meets the rules defined by
039     *         super.isDebit() method.
040     * @see org.kuali.ole.fp.document.validation.impl.InternalBillingDocumentRule#isDebit(org.kuali.rice.krad.document.FinancialDocument,
041     *      org.kuali.rice.krad.bo.AccountingLine)
042     */
043    @Override
044    public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) {
045        AccountingLine accountingLine = (AccountingLine) postable;
046        DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
047        if (!isDebitUtils.isIncome(accountingLine) && !isDebitUtils.isExpense(accountingLine)) {
048            throw new IllegalStateException(isDebitUtils.getDebitCalculationIllegalStateExceptionMessage());
049        }
050
051        return super.isDebit(postable);
052    }
053
054    /**
055     * This method sets extra accounting line fields in explicit general ledger pending entries. Internal billing transactions don't
056     * have this field.
057     * 
058     * @param financialDocument The accounting document containing the general ledger pending entries being customized.
059     * @param accountingLine The accounting line the explicit general ledger pending entry was generated from.
060     * @param explicitEntry The explicit general ledger pending entry to be customized.
061     * @see FinancialDocumentRuleBase#customizeExplicitGeneralLedgerPendingEntry(FinancialDocument, AccountingLine,
062     *      GeneralLedgerPendingEntry)
063     */
064    @Override
065    public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) {
066        String description = postable.getFinancialDocumentLineDescription();
067        if (StringUtils.isNotBlank(description)) {
068            explicitEntry.setTransactionLedgerEntryDescription(description);
069        }
070    }
071}