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     * Created on Aug 17, 2004
018     *
019     */
020    package org.kuali.kfs.pdp.businessobject;
021    
022    import java.util.LinkedHashMap;
023    
024    import org.apache.commons.lang.builder.EqualsBuilder;
025    import org.apache.commons.lang.builder.HashCodeBuilder;
026    import org.apache.commons.lang.builder.ToStringBuilder;
027    import org.kuali.kfs.pdp.PdpConstants;
028    import org.kuali.kfs.pdp.PdpPropertyConstants;
029    import org.kuali.kfs.pdp.service.PaymentGroupService;
030    import org.kuali.kfs.sys.context.SpringContext;
031    import org.kuali.rice.kns.bo.TransientBusinessObjectBase;
032    import org.kuali.rice.kns.util.KualiDecimal;
033    import org.kuali.rice.kns.util.KualiInteger;
034    
035    
036    /**
037     * 
038     */
039    public class FormatResult extends TransientBusinessObjectBase implements Comparable {
040        private Integer procId;
041        private boolean pymtAttachment;
042        private boolean pymtSpecialHandling;
043        private boolean processImmediate;
044        private CustomerProfile cust;
045        private int payments;
046        private KualiDecimal amount;
047        private DisbursementType disbursementType;
048        private int beginDisbursementNbr;
049        private int endDisbursementNbr;
050        private KualiInteger sortGroup;
051        
052    
053        public FormatResult() {
054            super();
055            amount = KualiDecimal.ZERO;
056            payments = 0;
057        }
058    
059        public FormatResult(Integer p, CustomerProfile c) {
060            procId = p;
061            cust = c;
062            amount = KualiDecimal.ZERO;
063            payments = 0;
064        }
065    
066        public KualiInteger getSortGroupId() {
067            
068            return sortGroup;
069        }
070    
071        public KualiInteger getSortGroupOverride() {
072            return sortGroup;
073        }
074    
075        public void setSortGroupOverride(KualiInteger sortGroup) {
076            this.sortGroup = sortGroup;
077        }
078    
079        public boolean isProcessImmediate() {
080            return processImmediate;
081        }
082    
083        public void setProcessImmediate(boolean processImmediate) {
084            this.processImmediate = processImmediate;
085        }
086    
087        public boolean isPymtAttachment() {
088            return pymtAttachment;
089        }
090    
091        public void setPymtAttachment(boolean pymtAttachment) {
092            this.pymtAttachment = pymtAttachment;
093        }
094    
095        public boolean isPymtSpecialHandling() {
096            return pymtSpecialHandling;
097        }
098    
099        public void setPymtSpecialHandling(boolean pymtSpecialHandling) {
100            this.pymtSpecialHandling = pymtSpecialHandling;
101        }
102    
103        public int getBeginDisbursementNbr() {
104            return beginDisbursementNbr;
105        }
106    
107        public void setBeginDisbursementNbr(int beginDisbursementNbr) {
108            this.beginDisbursementNbr = beginDisbursementNbr;
109        }
110    
111        public DisbursementType getDisbursementType() {
112            return disbursementType;
113        }
114    
115        public void setDisbursementType(DisbursementType disbursementType) {
116            this.disbursementType = disbursementType;
117        }
118    
119        public int getEndDisbursementNbr() {
120            return endDisbursementNbr;
121        }
122    
123        public void setEndDisbursementNbr(int endDisbursementNbr) {
124            this.endDisbursementNbr = endDisbursementNbr;
125        }
126    
127        public KualiDecimal getAmount() {
128            return amount;
129        }
130    
131        public void setAmount(KualiDecimal amount) {
132            this.amount = amount;
133        }
134    
135        public CustomerProfile getCust() {
136            return cust;
137        }
138    
139        public void setCust(CustomerProfile cust) {
140            this.cust = cust;
141        }
142    
143        public int getPayments() {
144            return payments;
145        }
146    
147        public void setPayments(int payments) {
148            this.payments = payments;
149        }
150    
151        public Integer getProcId() {
152            return procId;
153        }
154    
155        public void setProcId(Integer procId) {
156            this.procId = procId;
157        }
158    
159        public String getSortString() {
160            StringBuffer sb = new StringBuffer();
161            if (getDisbursementType() != null) {
162                if (PdpConstants.DisbursementTypeCodes.CHECK.equals(getDisbursementType().getCode())) {
163                    sb.append("B");
164                }
165                else {
166                    sb.append("A");
167                }
168            }
169            else {
170                sb.append("A");
171            }
172            sb.append(getSortGroupId());
173            sb.append(cust.getChartCode());
174            sb.append(cust.getUnitCode());
175            sb.append(cust.getSubUnitCode());
176            return sb.toString();
177        }
178    
179        public int compareTo(Object a) {
180            FormatResult f = (FormatResult) a;
181    
182            return this.getSortString().compareTo(f.getSortString());
183        }
184    
185        public boolean equals(Object obj) {
186            if (!(obj instanceof FormatResult)) {
187                return false;
188            }
189            FormatResult o = (FormatResult) obj;
190            return new EqualsBuilder().append(procId, o.getProcId()).append(getSortGroupId(), o.getSortGroupId()).append(cust, o.getCust()).isEquals();
191        }
192    
193        public int hashCode() {
194            return new HashCodeBuilder(7, 3).append(procId).append(getSortGroupId()).append(cust).toHashCode();
195        }
196    
197        public String toString() {
198            return new ToStringBuilder(this).append("procId", procId).append("sortGroupId", getSortGroupId()).append("cust", cust).toString();
199        }
200    
201        @Override
202        protected LinkedHashMap toStringMapper() {
203            LinkedHashMap m = new LinkedHashMap();
204            
205            m.put(PdpPropertyConstants.FormatResult.PROC_ID, this.procId);
206            
207            return m;
208        }
209        
210        public String getSortGroupName(){
211            PaymentGroupService paymentGroupService = SpringContext.getBean(PaymentGroupService.class);
212            String sortGroupName = paymentGroupService.getSortGroupName(sortGroup.intValue());
213            return sortGroupName;
214         }
215         
216         public void setSortGroupName(){
217             
218         }
219    }