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.gl.businessobject;
017    
018    import java.util.LinkedHashMap;
019    
020    import org.apache.commons.lang.StringUtils;
021    import org.kuali.kfs.sys.KFSConstants;
022    import org.kuali.rice.kns.bo.TransientBusinessObjectBase;
023    import org.kuali.rice.kns.util.KualiDecimal;
024    
025    /**
026     * An OriginEntryInformation wrapper which helpfully summarizes data for the pending entry report
027     */
028    public class PendingEntrySummary extends TransientBusinessObjectBase {
029        private OriginEntryInformation originEntry;
030        private boolean suppress;
031        
032        /**
033         * @return the document number of the wrapped entry
034         */
035        public String getDocumentNumber() {
036            return (!suppress) ? getConstantDocumentNumber() : "";
037        }
038        
039        /**
040         * @return the document number of the wrapped entry - even if suppressed
041         */
042        public String getConstantDocumentNumber() {
043            return StringUtils.join(new String[] { originEntry.getFinancialSystemOriginationCode(),originEntry.getDocumentNumber()}, '-');
044        }
045        
046        /**
047         * @return the document type code of the wrapped entry
048         */
049        public String getDocumentTypeCode() {
050            return (!suppress) ? getConstantDocumentTypeCode() : "";
051        }
052        
053        /**
054         * @return the document type code, even if suppressed
055         */
056        public String getConstantDocumentTypeCode() {
057            return originEntry.getFinancialDocumentTypeCode();
058        }
059        
060        /**
061         * @return the balance type code of the wrapped entry
062         */
063        public String getBalanceTypeCode() {
064            return (!suppress) ? getConstantBalanceTypeCode() : "";
065        }
066        
067        /**
068         * @return the balance type code, even if suppressed
069         */
070        public String getConstantBalanceTypeCode() {
071            return originEntry.getFinancialBalanceTypeCode();
072        }
073        
074        /**
075         * @return the chart of accounts code of the wrapped entry
076         */
077        public String getChartOfAccountsCode() {
078            return originEntry.getChartOfAccountsCode();
079        }
080        
081        /**
082         * @return the account number of the wrapped entry
083         */
084        public String getAccountNumber() {
085            return originEntry.getAccountNumber();
086        }
087        
088        /**
089         * @return the financial object code of the wrapped entry
090         */
091        public String getFinancialObjectCode() {
092            return originEntry.getFinancialObjectCode();
093        }
094        
095        /**
096         * @return the amount of the wrapped entry, or null if the entry does not represent a credit
097         */
098        public KualiDecimal getCreditAmount() {
099            if (!StringUtils.isBlank(originEntry.getTransactionDebitCreditCode())) {
100                if (originEntry.getTransactionDebitCreditCode().equals(KFSConstants.GL_CREDIT_CODE)) {
101                    return originEntry.getTransactionLedgerEntryAmount(); 
102                }
103            }
104            return null;
105        }
106    
107        /**
108         * @return the amount of the wrapped entry, or null if the entry does not represent a debit
109         */
110        public KualiDecimal getDebitAmount() {
111            if (!StringUtils.isBlank(originEntry.getTransactionDebitCreditCode())) { 
112                if (originEntry.getTransactionDebitCreditCode().equals(KFSConstants.GL_DEBIT_CODE)) {
113                    return originEntry.getTransactionLedgerEntryAmount();
114                }
115            }
116            return null;
117        }
118    
119        /**
120         * @return the amount for the wrapped entry, or null if the entry represents either a debit or a credt
121         */
122        public KualiDecimal getBudgetAmount() {
123            return (originEntry.getTransactionDebitCreditCode() == null || originEntry.getTransactionDebitCreditCode().equals(KFSConstants.GL_BUDGET_CODE) || originEntry.getTransactionDebitCreditCode().equals(KFSConstants.EMPTY_STRING)) ? originEntry.getTransactionLedgerEntryAmount() : null;
124        }
125    
126        /**
127         * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
128         */
129        @Override
130        protected LinkedHashMap toStringMapper() {
131            LinkedHashMap<String, String> pkHashMap = new LinkedHashMap<String, String>();
132            pkHashMap.put("documentTypeCode", this.getDocumentTypeCode());
133            pkHashMap.put("documentNumber", this.getDocumentNumber());
134            pkHashMap.put("chartOfAccountsCode", this.getChartOfAccountsCode());
135            pkHashMap.put("accountNumber", this.getAccountNumber());
136            pkHashMap.put("balanceTypeCode", this.getBalanceTypeCode());
137            pkHashMap.put("financialObjectCode", this.getFinancialObjectCode());
138            return pkHashMap;
139        }
140        
141        /**
142         * @param originEntry sets the origin entry
143         */
144        public void setOriginEntry(OriginEntryInformation originEntry) {
145            this.originEntry = originEntry;
146            this.suppress = false;
147        }
148    
149        /**
150         * Sets the suppress attribute value.
151         * @param suppress The suppress to set.
152         */
153        public void suppressCommonFields(boolean suppress) {
154            this.suppress = suppress;
155        }
156    
157        /**
158         * @return a String representation of suppressable fields
159         */
160        public String getSuppressableFieldsAsKey() {
161            return StringUtils.join(new String[] {originEntry.getFinancialDocumentTypeCode(),originEntry.getFinancialSystemOriginationCode(),originEntry.getDocumentNumber(),originEntry.getFinancialBalanceTypeCode()}, ':');
162        }
163    }