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