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.businessobject;
018    
019    import java.util.LinkedHashMap;
020    
021    import org.kuali.kfs.sys.KFSConstants;
022    import org.kuali.kfs.sys.KFSPropertyConstants;
023    import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
024    import org.kuali.rice.kns.util.KualiDecimal;
025    
026    /**
027     * This class contains the coin breakdown for coin inserted into a cash drawer
028     */
029    public class CoinDetail extends PersistableBusinessObjectBase {
030    
031        private String documentNumber;
032        private String financialDocumentTypeCode;
033        private String cashieringRecordSource;
034        private KualiDecimal financialDocumentFiftyCentAmount;
035        private KualiDecimal financialDocumentTwentyFiveCentAmount;
036        private KualiDecimal financialDocumentTenCentAmount;
037        private KualiDecimal financialDocumentFiveCentAmount;
038        private KualiDecimal financialDocumentOneCentAmount;
039        private KualiDecimal financialDocumentOtherCentAmount;
040        private KualiDecimal financialDocumentHundredCentAmount;
041    
042        /**
043         * Default constructor.
044         */
045        public CoinDetail() {
046        }
047    
048        /**
049         * Gets the documentNumber attribute.
050         * 
051         * @return Returns the documentNumber
052         */
053        public String getDocumentNumber() {
054            return documentNumber;
055        }
056    
057        /**
058         * Sets the documentNumber attribute.
059         * 
060         * @param documentNumber The documentNumber to set.
061         */
062        public void setDocumentNumber(String documentNumber) {
063            this.documentNumber = documentNumber;
064        }
065    
066    
067        /**
068         * Gets the financialDocumentTypeCode attribute.
069         * 
070         * @return Returns the financialDocumentTypeCode
071         */
072        public String getFinancialDocumentTypeCode() {
073            return financialDocumentTypeCode;
074        }
075    
076        /**
077         * Sets the financialDocumentTypeCode attribute.
078         * 
079         * @param financialDocumentTypeCode The financialDocumentTypeCode to set.
080         */
081        public void setFinancialDocumentTypeCode(String financialDocumentTypeCode) {
082            this.financialDocumentTypeCode = financialDocumentTypeCode;
083        }
084    
085    
086        /**
087         * Gets the cashieringRecordSource attribute.
088         * 
089         * @return Returns the cashieringRecordSource
090         */
091        public String getCashieringRecordSource() {
092            return cashieringRecordSource;
093        }
094    
095        /**
096         * Sets the cashieringRecordSource attribute.
097         * 
098         * @param cashieringRecordSource The cashieringRecordSource to set.
099         */
100        public void setCashieringRecordSource(String financialDocumentColumnTypeCode) {
101            this.cashieringRecordSource = financialDocumentColumnTypeCode;
102        }
103    
104        /**
105         * Gets the financialDocumentFiftyCentAmount attribute.
106         * 
107         * @return Returns the financialDocumentFiftyCentAmount
108         */
109        public KualiDecimal getFinancialDocumentFiftyCentAmount() {
110            return financialDocumentFiftyCentAmount;
111        }
112    
113        /**
114         * Sets the financialDocumentFiftyCentAmount attribute.
115         * 
116         * @param financialDocumentFiftyCentAmount The financialDocumentFiftyCentAmount to set.
117         */
118        public void setFinancialDocumentFiftyCentAmount(KualiDecimal financialDocumentFiftyCentAmount) {
119            this.financialDocumentFiftyCentAmount = financialDocumentFiftyCentAmount;
120        }
121    
122        /**
123         * Returns the number of half-cent coins in the drawer
124         * 
125         * @return the count of half cent coins in the drawer
126         */
127        public Integer getFiftyCentCount() {
128            return (financialDocumentFiftyCentAmount == null) ? new Integer(0) : new Integer(financialDocumentFiftyCentAmount.divide(KFSConstants.CoinTypeAmounts.FIFTY_CENT_AMOUNT).intValue());
129        }
130    
131        /**
132         * Sets the number of fifty cent coins in the drawer. This is useful if, you know, you're in da club, with, say a bottle full of
133         * "bub"
134         * 
135         * @param count the number of fifty cent coins present in the drawer
136         */
137        public void setFiftyCentCount(Integer count) {
138            if (count != null) {
139                financialDocumentFiftyCentAmount = new KualiDecimal(count.intValue()).multiply(KFSConstants.CoinTypeAmounts.FIFTY_CENT_AMOUNT);
140            }
141        }
142    
143        /**
144         * Gets the financialDocumentTwentyFiveCentAmount attribute.
145         * 
146         * @return Returns the financialDocumentTwentyFiveCentAmount
147         */
148        public KualiDecimal getFinancialDocumentTwentyFiveCentAmount() {
149            return financialDocumentTwentyFiveCentAmount;
150        }
151    
152        /**
153         * Sets the financialDocumentTwentyFiveCentAmount attribute.
154         * 
155         * @param financialDocumentTwentyFiveCentAmount The financialDocumentTwentyFiveCentAmount to set.
156         */
157        public void setFinancialDocumentTwentyFiveCentAmount(KualiDecimal financialDocumentTwentyFiveCentAmount) {
158            this.financialDocumentTwentyFiveCentAmount = financialDocumentTwentyFiveCentAmount;
159        }
160    
161        /**
162         * Returns the number of quarters in the drawer
163         * 
164         * @return the count of quarters in the drawer
165         */
166        public Integer getTwentyFiveCentCount() {
167            return (financialDocumentTwentyFiveCentAmount == null) ? new Integer(0) : new Integer(financialDocumentTwentyFiveCentAmount.divide(KFSConstants.CoinTypeAmounts.TWENTY_FIVE_CENT_AMOUNT).intValue());
168        }
169    
170        /**
171         * Sets the number of quarters in the drawer
172         * 
173         * @param count the number of quarters present in the drawer
174         */
175        public void setTwentyFiveCentCount(Integer count) {
176            if (count != null) {
177                financialDocumentTwentyFiveCentAmount = new KualiDecimal(count.intValue()).multiply(KFSConstants.CoinTypeAmounts.TWENTY_FIVE_CENT_AMOUNT);
178            }
179        }
180    
181        /**
182         * Gets the financialDocumentTenCentAmount attribute.
183         * 
184         * @return Returns the financialDocumentTenCentAmount
185         */
186        public KualiDecimal getFinancialDocumentTenCentAmount() {
187            return financialDocumentTenCentAmount;
188        }
189    
190        /**
191         * Sets the financialDocumentTenCentAmount attribute.
192         * 
193         * @param financialDocumentTenCentAmount The financialDocumentTenCentAmount to set.
194         */
195        public void setFinancialDocumentTenCentAmount(KualiDecimal financialDocumentTenCentAmount) {
196            this.financialDocumentTenCentAmount = financialDocumentTenCentAmount;
197        }
198    
199        /**
200         * Returns the number of dimes in the drawer
201         * 
202         * @return the count of dimes in the drawer
203         */
204        public Integer getTenCentCount() {
205            return (financialDocumentTenCentAmount == null) ? new Integer(0) : new Integer(financialDocumentTenCentAmount.divide(KFSConstants.CoinTypeAmounts.TEN_CENT_AMOUNT).intValue());
206        }
207    
208        /**
209         * Sets the number of dimes in the drawer
210         * 
211         * @param count the number of dimes present in the drawer
212         */
213        public void setTenCentCount(Integer count) {
214            if (count != null) {
215                financialDocumentTenCentAmount = new KualiDecimal(count.intValue()).multiply(KFSConstants.CoinTypeAmounts.TEN_CENT_AMOUNT);
216            }
217        }
218    
219        /**
220         * Gets the financialDocumentFiveCentAmount attribute.
221         * 
222         * @return Returns the financialDocumentFiveCentAmount
223         */
224        public KualiDecimal getFinancialDocumentFiveCentAmount() {
225            return financialDocumentFiveCentAmount;
226        }
227    
228        /**
229         * Sets the financialDocumentFiveCentAmount attribute.
230         * 
231         * @param financialDocumentFiveCentAmount The financialDocumentFiveCentAmount to set.
232         */
233        public void setFinancialDocumentFiveCentAmount(KualiDecimal financialDocumentFiveCentAmount) {
234            this.financialDocumentFiveCentAmount = financialDocumentFiveCentAmount;
235        }
236    
237        /**
238         * Returns the number of nickels in the drawer
239         * 
240         * @return the count of nickels in the drawer
241         */
242        public Integer getFiveCentCount() {
243            return (financialDocumentFiveCentAmount == null) ? new Integer(0) : new Integer(financialDocumentFiveCentAmount.divide(KFSConstants.CoinTypeAmounts.FIVE_CENT_AMOUNT).intValue());
244        }
245    
246        /**
247         * Sets the number of nickels in the drawer
248         * 
249         * @param count the number of nickels present in the drawer
250         */
251        public void setFiveCentCount(Integer count) {
252            if (count != null) {
253                financialDocumentFiveCentAmount = new KualiDecimal(count.intValue()).multiply(KFSConstants.CoinTypeAmounts.FIVE_CENT_AMOUNT);
254            }
255        }
256    
257        /**
258         * Gets the financialDocumentOneCentAmount attribute.
259         * 
260         * @return Returns the financialDocumentOneCentAmount
261         */
262        public KualiDecimal getFinancialDocumentOneCentAmount() {
263            return financialDocumentOneCentAmount;
264        }
265    
266        /**
267         * Sets the financialDocumentOneCentAmount attribute.
268         * 
269         * @param financialDocumentOneCentAmount The financialDocumentOneCentAmount to set.
270         */
271        public void setFinancialDocumentOneCentAmount(KualiDecimal financialDocumentOneCentAmount) {
272            this.financialDocumentOneCentAmount = financialDocumentOneCentAmount;
273        }
274    
275        /**
276         * Returns the number of pennies in the drawer
277         * 
278         * @return the count of pennies in the drawer
279         */
280        public Integer getOneCentCount() {
281            return (financialDocumentOneCentAmount == null) ? new Integer(0) : new Integer(financialDocumentOneCentAmount.divide(KFSConstants.CoinTypeAmounts.ONE_CENT_AMOUNT).intValue());
282        }
283    
284        /**
285         * Sets the number of pennies in the drawer
286         * 
287         * @param count the number of pennies present in the drawer
288         */
289        public void setOneCentCount(Integer count) {
290            if (count != null) {
291                financialDocumentOneCentAmount = new KualiDecimal(count).multiply(KFSConstants.CoinTypeAmounts.ONE_CENT_AMOUNT);
292            }
293        }
294    
295        /**
296         * Gets the financialDocumentOtherCentAmount attribute.
297         * 
298         * @return Returns the financialDocumentOtherCentAmount
299         */
300        public KualiDecimal getFinancialDocumentOtherCentAmount() {
301            return financialDocumentOtherCentAmount;
302        }
303    
304        /**
305         * Sets the financialDocumentOtherCentAmount attribute.
306         * 
307         * @param financialDocumentOtherCentAmount The financialDocumentOtherCentAmount to set.
308         */
309        public void setFinancialDocumentOtherCentAmount(KualiDecimal financialDocumentOtherCentAmount) {
310            this.financialDocumentOtherCentAmount = financialDocumentOtherCentAmount;
311        }
312    
313    
314        /**
315         * Gets the financialDocumentHundredCentAmount attribute.
316         * 
317         * @return Returns the financialDocumentHundredCentAmount
318         */
319        public KualiDecimal getFinancialDocumentHundredCentAmount() {
320            return financialDocumentHundredCentAmount;
321        }
322    
323        /**
324         * Sets the financialDocumentHundredCentAmount attribute.
325         * 
326         * @param financialDocumentHundredCentAmount The financialDocumentHundredCentAmount to set.
327         */
328        public void setFinancialDocumentHundredCentAmount(KualiDecimal financialDocumentHundredCentAmount) {
329            this.financialDocumentHundredCentAmount = financialDocumentHundredCentAmount;
330        }
331    
332        /**
333         * Returns the number of dollar coins--Sacajawea, Susan B. Anthony, or otherwise--in the drawer
334         * 
335         * @return the count of dollar coins in the drawer
336         */
337        public Integer getHundredCentCount() {
338            return (financialDocumentHundredCentAmount == null) ? new Integer(0) : new Integer(financialDocumentHundredCentAmount.divide(KFSConstants.CoinTypeAmounts.HUNDRED_CENT_AMOUNT).intValue());
339        }
340    
341        /**
342         * Sets the number of hundred cent coins in the drawer
343         * 
344         * @param count the number of hundred cent coins present in the drawer
345         */
346        public void setHundredCentCount(Integer count) {
347            if (count != null) {
348                financialDocumentHundredCentAmount = new KualiDecimal(count.intValue()).multiply(KFSConstants.CoinTypeAmounts.HUNDRED_CENT_AMOUNT);
349            }
350        }
351    
352        /**
353         * Returns the total amount represented by this coin detail record.
354         * 
355         * @return total amount of this detail
356         */
357        public KualiDecimal getTotalAmount() {
358            KualiDecimal result = KualiDecimal.ZERO;
359            if (this.financialDocumentHundredCentAmount != null) {
360                result = result.add(this.financialDocumentHundredCentAmount);
361            }
362            if (this.financialDocumentFiftyCentAmount != null) {
363                result = result.add(this.financialDocumentFiftyCentAmount);
364            }
365            if (this.financialDocumentTwentyFiveCentAmount != null) {
366                result = result.add(this.financialDocumentTwentyFiveCentAmount);
367            }
368            if (this.financialDocumentTenCentAmount != null) {
369                result = result.add(this.financialDocumentTenCentAmount);
370            }
371            if (this.financialDocumentFiveCentAmount != null) {
372                result = result.add(this.financialDocumentFiveCentAmount);
373            }
374            if (this.financialDocumentOneCentAmount != null) {
375                result = result.add(this.financialDocumentOneCentAmount);
376            }
377            if (this.financialDocumentOtherCentAmount != null) {
378                result = result.add(this.financialDocumentOtherCentAmount);
379            }
380            return result;
381        }
382    
383        /**
384         * This method sets all amounts in this record to zero
385         */
386        public void zeroOutAmounts() {
387            this.financialDocumentHundredCentAmount = KualiDecimal.ZERO;
388            this.financialDocumentFiftyCentAmount = KualiDecimal.ZERO;
389            this.financialDocumentTwentyFiveCentAmount = KualiDecimal.ZERO;
390            this.financialDocumentTenCentAmount = KualiDecimal.ZERO;
391            this.financialDocumentFiveCentAmount = KualiDecimal.ZERO;
392            this.financialDocumentOneCentAmount = KualiDecimal.ZERO;
393            this.financialDocumentOtherCentAmount = KualiDecimal.ZERO;
394        }
395    
396        /**
397         * This method sets all amounts that are null to zero
398         */
399        public void zeroOutUnpopulatedAmounts() {
400            if (this.financialDocumentHundredCentAmount == null) {
401                this.financialDocumentHundredCentAmount = KualiDecimal.ZERO;
402            }
403            if (this.financialDocumentFiftyCentAmount == null) {
404                this.financialDocumentFiftyCentAmount = KualiDecimal.ZERO;
405            }
406            if (this.financialDocumentTwentyFiveCentAmount == null) {
407                this.financialDocumentTwentyFiveCentAmount = KualiDecimal.ZERO;
408            }
409            if (this.financialDocumentTenCentAmount == null) {
410                this.financialDocumentTenCentAmount = KualiDecimal.ZERO;
411            }
412            if (this.financialDocumentFiveCentAmount == null) {
413                this.financialDocumentFiveCentAmount = KualiDecimal.ZERO;
414            }
415            if (this.financialDocumentOneCentAmount == null) {
416                this.financialDocumentOneCentAmount = KualiDecimal.ZERO;
417            }
418            if (this.financialDocumentOtherCentAmount == null) {
419                this.financialDocumentOtherCentAmount = KualiDecimal.ZERO;
420            }
421        }
422    
423        public void add(CoinDetail detail) {
424            if (detail.financialDocumentHundredCentAmount != null) {
425                if (this.financialDocumentHundredCentAmount == null) {
426                    this.financialDocumentHundredCentAmount = KualiDecimal.ZERO.add(detail.financialDocumentHundredCentAmount);
427                }
428                else {
429                    this.financialDocumentHundredCentAmount = this.financialDocumentHundredCentAmount.add(detail.financialDocumentHundredCentAmount);
430                }
431            }
432            if (detail.financialDocumentFiftyCentAmount != null) {
433                if (this.financialDocumentFiftyCentAmount == null) {
434                    this.financialDocumentFiftyCentAmount = KualiDecimal.ZERO.add(detail.financialDocumentFiftyCentAmount);
435                }
436                else {
437                    this.financialDocumentFiftyCentAmount = this.financialDocumentFiftyCentAmount.add(detail.financialDocumentFiftyCentAmount);
438                }
439            }
440            if (detail.financialDocumentTwentyFiveCentAmount != null) {
441                if (this.financialDocumentTwentyFiveCentAmount == null) {
442                    this.financialDocumentTwentyFiveCentAmount = KualiDecimal.ZERO.add(detail.financialDocumentTwentyFiveCentAmount);
443                }
444                else {
445                    this.financialDocumentTwentyFiveCentAmount = this.financialDocumentTwentyFiveCentAmount.add(detail.financialDocumentTwentyFiveCentAmount);
446                }
447            }
448            if (detail.financialDocumentTenCentAmount != null) {
449                if (this.financialDocumentTenCentAmount == null) {
450                    this.financialDocumentTenCentAmount = KualiDecimal.ZERO.add(detail.financialDocumentTenCentAmount);
451                }
452                else {
453                    this.financialDocumentTenCentAmount = this.financialDocumentTenCentAmount.add(detail.financialDocumentTenCentAmount);
454                }
455            }
456            if (detail.financialDocumentFiveCentAmount != null) {
457                if (this.financialDocumentFiveCentAmount == null) {
458                    this.financialDocumentFiveCentAmount = KualiDecimal.ZERO.add(detail.financialDocumentFiveCentAmount);
459                }
460                else {
461                    this.financialDocumentFiveCentAmount = this.financialDocumentFiveCentAmount.add(detail.financialDocumentFiveCentAmount);
462                }
463            }
464            if (detail.financialDocumentOneCentAmount != null) {
465                if (this.financialDocumentOneCentAmount == null) {
466                    this.financialDocumentOneCentAmount = KualiDecimal.ZERO.add(detail.financialDocumentOneCentAmount);
467                }
468                else {
469                    this.financialDocumentOneCentAmount = this.financialDocumentOneCentAmount.add(detail.financialDocumentOneCentAmount);
470                }
471            }
472            if (detail.financialDocumentOtherCentAmount != null) {
473                if (this.financialDocumentOtherCentAmount == null) {
474                    this.financialDocumentOtherCentAmount = KualiDecimal.ZERO.add(detail.financialDocumentOtherCentAmount);
475                }
476                else {
477                    this.financialDocumentOtherCentAmount = this.financialDocumentOtherCentAmount.add(detail.financialDocumentOtherCentAmount);
478                }
479            }
480        }
481    
482        public void subtract(CoinDetail detail) {
483            if (detail.financialDocumentHundredCentAmount != null) {
484                if (this.financialDocumentHundredCentAmount == null) {
485                    this.financialDocumentHundredCentAmount = KualiDecimal.ZERO.subtract(detail.financialDocumentHundredCentAmount);
486                }
487                else {
488                    this.financialDocumentHundredCentAmount = this.financialDocumentHundredCentAmount.subtract(detail.financialDocumentHundredCentAmount);
489                }
490            }
491            if (detail.financialDocumentFiftyCentAmount != null) {
492                if (this.financialDocumentFiftyCentAmount == null) {
493                    this.financialDocumentFiftyCentAmount = KualiDecimal.ZERO.subtract(detail.financialDocumentFiftyCentAmount);
494                }
495                else {
496                    this.financialDocumentFiftyCentAmount = this.financialDocumentFiftyCentAmount.subtract(detail.financialDocumentFiftyCentAmount);
497                }
498            }
499            if (detail.financialDocumentTwentyFiveCentAmount != null) {
500                if (this.financialDocumentTwentyFiveCentAmount == null) {
501                    this.financialDocumentTwentyFiveCentAmount = KualiDecimal.ZERO.subtract(detail.financialDocumentTwentyFiveCentAmount);
502                }
503                else {
504                    this.financialDocumentTwentyFiveCentAmount = this.financialDocumentTwentyFiveCentAmount.subtract(detail.financialDocumentTwentyFiveCentAmount);
505                }
506            }
507            if (detail.financialDocumentTenCentAmount != null) {
508                if (this.financialDocumentTenCentAmount == null) {
509                    this.financialDocumentTenCentAmount = KualiDecimal.ZERO.subtract(detail.financialDocumentTenCentAmount);
510                }
511                else {
512                    this.financialDocumentTenCentAmount = this.financialDocumentTenCentAmount.subtract(detail.financialDocumentTenCentAmount);
513                }
514            }
515            if (detail.financialDocumentFiveCentAmount != null) {
516                if (this.financialDocumentFiveCentAmount == null) {
517                    this.financialDocumentFiveCentAmount = KualiDecimal.ZERO.subtract(detail.financialDocumentFiveCentAmount);
518                }
519                else {
520                    this.financialDocumentFiveCentAmount = this.financialDocumentFiveCentAmount.subtract(detail.financialDocumentFiveCentAmount);
521                }
522            }
523            if (detail.financialDocumentOneCentAmount != null) {
524                if (this.financialDocumentOneCentAmount == null) {
525                    this.financialDocumentOneCentAmount = KualiDecimal.ZERO.subtract(detail.financialDocumentOneCentAmount);
526                }
527                else {
528                    this.financialDocumentOneCentAmount = this.financialDocumentOneCentAmount.subtract(detail.financialDocumentOneCentAmount);
529                }
530            }
531            if (detail.financialDocumentOtherCentAmount != null) {
532                if (this.financialDocumentOtherCentAmount == null) {
533                    this.financialDocumentOtherCentAmount = KualiDecimal.ZERO.subtract(detail.financialDocumentOtherCentAmount);
534                }
535                else {
536                    this.financialDocumentOtherCentAmount = this.financialDocumentOtherCentAmount.subtract(detail.financialDocumentOtherCentAmount);
537                }
538            }
539        }
540    
541        /**
542         * Is this coin detail empty of any value?
543         * 
544         * @return true if any field at all is neither null nor the amount is zero
545         */
546        public boolean isEmpty() {
547            return ((this.financialDocumentHundredCentAmount == null || this.financialDocumentHundredCentAmount.equals(KualiDecimal.ZERO)) && (this.financialDocumentFiftyCentAmount == null || this.financialDocumentFiftyCentAmount.equals(KualiDecimal.ZERO)) && (this.financialDocumentTwentyFiveCentAmount == null || this.financialDocumentTwentyFiveCentAmount.equals(KualiDecimal.ZERO)) && (this.financialDocumentTenCentAmount == null || this.financialDocumentTenCentAmount.equals(KualiDecimal.ZERO)) && (this.financialDocumentFiveCentAmount == null || this.financialDocumentFiveCentAmount.equals(KualiDecimal.ZERO)) && (this.financialDocumentOneCentAmount == null || this.financialDocumentOneCentAmount.equals(KualiDecimal.ZERO)) && (this.financialDocumentOtherCentAmount == null || this.financialDocumentOtherCentAmount.equals(KualiDecimal.ZERO)));
548        }
549    
550        /**
551         * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
552         */
553        protected LinkedHashMap toStringMapper() {
554            LinkedHashMap m = new LinkedHashMap();
555            m.put(KFSPropertyConstants.DOCUMENT_NUMBER, this.documentNumber);
556            m.put("financialDocumentTypeCode", this.financialDocumentTypeCode);
557            m.put("cashieringRecordSource", this.cashieringRecordSource);
558            return m;
559        }
560    }