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