001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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 Sep 1, 2004
018: *
019: */
020: package org.kuali.module.pdp.service.impl;
021:
022: import java.math.BigDecimal;
023: import java.util.ArrayList;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import org.kuali.module.pdp.bo.PaymentGroup;
028: import org.kuali.module.pdp.bo.ProcessSummary;
029: import org.kuali.module.pdp.dao.ProcessSummaryDao;
030:
031: /**
032: * @author jsissom
033: */
034: public class PreFormatProcessSummary {
035: private static BigDecimal zero = new BigDecimal(0);
036: private List processSummary = new ArrayList();
037:
038: public PreFormatProcessSummary() {
039: super ();
040: }
041:
042: public List getProcessSummaryList() {
043: return processSummary;
044: }
045:
046: /**
047: * Add the paymentdetail info to our summary list
048: *
049: * @param pd
050: */
051: public void add(PaymentGroup pg) {
052: ProcessSummary ps = findProcessSummary(pg);
053:
054: // If it's not in our list, add it
055: if (ps == null) {
056: ps = new ProcessSummary();
057: ps.setBeginDisbursementNbr(new Integer(0));
058: ps.setCustomer(pg.getBatch().getCustomerProfile());
059: ps.setEndDisbursementNbr(new Integer(0));
060: ps.setProcess(pg.getProcess());
061: ps.setProcessTotalAmount(new BigDecimal(0));
062: ps.setProcessTotalCount(new Integer(0));
063: ps.setSortGroupId(pg.getSortGroupId());
064: processSummary.add(ps);
065: }
066:
067: // Update the total & count
068: ps.setProcessTotalAmount(ps.getProcessTotalAmount().add(
069: pg.getNetPaymentAmount()));
070: ps.setProcessTotalCount(new Integer(ps.getProcessTotalCount()
071: .intValue()
072: + pg.getPaymentDetails().size()));
073: }
074:
075: /**
076: * Save all the process summary records
077: *
078: * @param pdd
079: */
080: public void save(ProcessSummaryDao psd) {
081: for (Iterator iter = processSummary.iterator(); iter.hasNext();) {
082: ProcessSummary ps = (ProcessSummary) iter.next();
083: psd.save(ps);
084: }
085: }
086:
087: // See if we already have a summary record. If we do, return it,
088: // if not, return null;
089: private ProcessSummary findProcessSummary(PaymentGroup pg) {
090: for (Iterator iter = processSummary.iterator(); iter.hasNext();) {
091: ProcessSummary ps = (ProcessSummary) iter.next();
092:
093: if (ps.getCustomer().equals(
094: pg.getBatch().getCustomerProfile())
095: && ps.getSortGroupId().equals(pg.getSortGroupId())
096: && ps.getProcess().equals(pg.getProcess())) {
097: return ps;
098: }
099: }
100: return null;
101: }
102:
103: /**
104: * @param pg Update the disbursement number information
105: * @param range
106: */
107: public void setDisbursementNumber(PaymentGroup pg, Integer nbr) {
108: ProcessSummary ps = findProcessSummary(pg);
109: if (ps != null) {
110: if (ps.getBeginDisbursementNbr().intValue() == 0) {
111: ps.setBeginDisbursementNbr(nbr);
112: ps.setEndDisbursementNbr(nbr);
113: } else {
114: ps.setEndDisbursementNbr(nbr);
115: }
116: }
117: }
118: }
|