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    package org.kuali.kfs.fp.document;
018    
019    import java.util.List;
020    
021    import org.kuali.kfs.fp.businessobject.CapitalAssetInformation;
022    import org.kuali.kfs.integration.cam.CapitalAssetManagementModuleService;
023    import org.kuali.kfs.sys.KFSConstants;
024    import org.kuali.kfs.sys.businessobject.AccountingLine;
025    import org.kuali.kfs.sys.businessobject.ElectronicPaymentClaim;
026    import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
027    import org.kuali.kfs.sys.context.SpringContext;
028    import org.kuali.kfs.sys.document.AccountingDocumentBase;
029    import org.kuali.kfs.sys.document.AmountTotaling;
030    import org.kuali.kfs.sys.document.Correctable;
031    import org.kuali.kfs.sys.document.ElectronicPaymentClaiming;
032    import org.kuali.kfs.sys.document.service.DebitDeterminerService;
033    import org.kuali.kfs.sys.service.ElectronicPaymentClaimingService;
034    import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO;
035    import org.kuali.rice.kns.document.Copyable;
036    import org.kuali.rice.kns.rule.event.KualiDocumentEvent;
037    import org.kuali.rice.kns.rule.event.SaveDocumentEvent;
038    import org.kuali.rice.kns.service.DataDictionaryService;
039    import org.kuali.rice.kns.util.ObjectUtils;
040    
041    /**
042     * The Distribution of Income and Expense (DI) document is used to distribute income or expense, or assets and liabilities. Amounts
043     * being distributed are usually the result of an accumulation of transactions that need to be divided up between various accounts.
044     */
045    public class DistributionOfIncomeAndExpenseDocument extends AccountingDocumentBase implements Copyable, Correctable, AmountTotaling, ElectronicPaymentClaiming, CapitalAssetEditable {
046        protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DistributionOfIncomeAndExpenseDocument.class);
047        protected List<ElectronicPaymentClaim> electronicPaymentClaims;
048    
049        protected transient CapitalAssetInformation capitalAssetInformation;
050        protected transient CapitalAssetManagementModuleService capitalAssetManagementModuleService;
051    
052    
053        /**
054         * Constructs a DistributionOfIncomeAndExpenseDocument.java.
055         */
056        public DistributionOfIncomeAndExpenseDocument() {
057            super();
058        }
059    
060    
061        /**
062         * @see org.kuali.kfs.sys.document.AccountingDocumentBase#buildListOfDeletionAwareLists()
063         */
064        @Override
065        public List buildListOfDeletionAwareLists() {
066            List<List> managedLists = super.buildListOfDeletionAwareLists();
067            if (ObjectUtils.isNotNull(getCapitalAssetInformation()) && ObjectUtils.isNotNull(getCapitalAssetInformation().getCapitalAssetInformationDetails())) {
068                managedLists.add(getCapitalAssetInformation().getCapitalAssetInformationDetails());
069            }
070            return managedLists;
071        }
072    
073        /**
074         * @see org.kuali.kfs.sys.document.AccountingDocument#getSourceAccountingLinesSectionTitle()
075         */
076        @Override
077        public String getSourceAccountingLinesSectionTitle() {
078            return KFSConstants.FROM;
079        }
080    
081        /**
082         * @see org.kuali.kfs.sys.document.AccountingDocument#getTargetAccountingLinesSectionTitle()
083         */
084        @Override
085        public String getTargetAccountingLinesSectionTitle() {
086            return KFSConstants.TO;
087        }
088    
089        /**
090         * Return true if account line is debit
091         * 
092         * @param financialDocument submitted accounting document
093         * @param accountingLine accounting line from accounting document
094         * @return true is account line is debit
095         * @see IsDebitUtils#isDebitConsideringSectionAndTypePositiveOnly(FinancialDocumentRuleBase, FinancialDocument, AccountingLine)
096         * @see org.kuali.rice.kns.rule.AccountingLineRule#isDebit(org.kuali.rice.kns.document.FinancialDocument,
097         *      org.kuali.rice.kns.bo.AccountingLine)
098         */
099        public boolean isDebit(GeneralLedgerPendingEntrySourceDetail postable) {
100            DebitDeterminerService isDebitUtils = SpringContext.getBean(DebitDeterminerService.class);
101            return isDebitUtils.isDebitConsideringSectionAndTypePositiveOnly(this, (AccountingLine) postable);
102        }
103    
104        /**
105         * @see org.kuali.kfs.sys.document.ElectronicPaymentClaiming#declaimElectronicPaymentClaims()
106         */
107        public void declaimElectronicPaymentClaims() {
108            SpringContext.getBean(ElectronicPaymentClaimingService.class).declaimElectronicPaymentClaimsForDocument(this);
109        }
110    
111        /**
112         * Gets the electronicPaymentClaims attribute.
113         * 
114         * @return Returns the electronicPaymentClaims.
115         */
116        public List<ElectronicPaymentClaim> getElectronicPaymentClaims() {
117            return electronicPaymentClaims;
118        }
119    
120        /**
121         * Sets the electronicPaymentClaims attribute value.
122         * 
123         * @param electronicPaymentClaims The electronicPaymentClaims to set.
124         * @deprecated
125         */
126        public void setElectronicPaymentClaims(List<ElectronicPaymentClaim> electronicPaymentClaims) {
127            this.electronicPaymentClaims = electronicPaymentClaims;
128        }
129    
130        /**
131         * Gets the capitalAssetInformation attribute.
132         * 
133         * @return Returns the capitalAssetInformation.
134         */
135        public CapitalAssetInformation getCapitalAssetInformation() {
136            return ObjectUtils.isNull(capitalAssetInformation) ? null : capitalAssetInformation;
137        }
138    
139        /**
140         * Sets the capitalAssetInformation attribute value.
141         * 
142         * @param capitalAssetInformation The capitalAssetInformation to set.
143         */
144        @Deprecated
145        public void setCapitalAssetInformation(CapitalAssetInformation capitalAssetInformation) {
146            this.capitalAssetInformation = capitalAssetInformation;
147        }
148    
149    
150        /**
151         * @see org.kuali.kfs.sys.document.GeneralLedgerPostingDocumentBase#doRouteStatusChange()
152         */
153        @Override
154        public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) {
155            super.doRouteStatusChange(statusChangeEvent);
156            this.getCapitalAssetManagementModuleService().deleteDocumentAssetLocks(this);
157        }
158    
159    
160        /**
161         * @see org.kuali.rice.kns.document.DocumentBase#postProcessSave(org.kuali.rice.kns.rule.event.KualiDocumentEvent)
162         */
163        @Override
164        public void postProcessSave(KualiDocumentEvent event) {
165            super.postProcessSave(event);
166            if (!(event instanceof SaveDocumentEvent)) { // don't lock until they route
167                String documentTypeName = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(this.getClass());
168                this.getCapitalAssetManagementModuleService().generateCapitalAssetLock(this, documentTypeName);
169            }
170        }
171    
172    
173        /**
174         * @return CapitalAssetManagementModuleService
175         */
176        CapitalAssetManagementModuleService getCapitalAssetManagementModuleService() {
177            if (capitalAssetManagementModuleService == null) {
178                capitalAssetManagementModuleService = SpringContext.getBean(CapitalAssetManagementModuleService.class);
179            }
180            return capitalAssetManagementModuleService;
181        }
182    }