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: package org.kuali.module.pdp.action.paymentdetail;
017:
018: import java.util.ArrayList;
019: import java.util.Iterator;
020: import java.util.List;
021: import java.util.Map;
022:
023: import javax.servlet.http.HttpServletRequest;
024: import javax.servlet.http.HttpServletResponse;
025:
026: import org.apache.struts.action.ActionErrors;
027: import org.apache.struts.action.ActionForm;
028: import org.apache.struts.action.ActionForward;
029: import org.apache.struts.action.ActionMapping;
030: import org.apache.struts.action.ActionMessage;
031: import org.kuali.kfs.context.SpringContext;
032: import org.kuali.module.pdp.action.BaseAction;
033: import org.kuali.module.pdp.bo.PaymentDetail;
034: import org.kuali.module.pdp.bo.PaymentGroup;
035: import org.kuali.module.pdp.dao.PayeeTypeDao;
036: import org.kuali.module.pdp.service.PaymentDetailService;
037: import org.kuali.module.pdp.service.PaymentGroupService;
038: import org.kuali.module.pdp.utilities.GeneralUtilities;
039:
040: public class EpicPaymentDetailAction extends BaseAction {
041: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
042: .getLogger(EpicPaymentDetailAction.class);
043: private PaymentDetailService paymentDetailService;
044: private PaymentGroupService paymentGroupService;
045: private PayeeTypeDao payeeTypeDao;
046:
047: public EpicPaymentDetailAction() {
048: setPaymentDetailService(SpringContext
049: .getBean(PaymentDetailService.class));
050: setPaymentGroupService(SpringContext
051: .getBean(PaymentGroupService.class));
052: setPayeeTypeDao(SpringContext.getBean(PayeeTypeDao.class));
053: }
054:
055: protected ActionForward executeLogic(ActionMapping mapping,
056: ActionForm form, HttpServletRequest request,
057: HttpServletResponse response) throws Exception {
058: LOG.debug("executeLogic() started");
059:
060: String buttonPressed = GeneralUtilities
061: .whichButtonWasPressed(request);
062:
063: LOG.debug("executeLogic() btnPressed is " + buttonPressed);
064: String custPaymentDocNbr = null;
065: String fdocTypeCode = null;
066: ActionErrors errors = new ActionErrors();
067: PaymentDetail pd = (PaymentDetail) request.getSession()
068: .getAttribute("PaymentDetail");
069: List indivList = (List) request.getSession().getAttribute(
070: "indivSearchResults");
071: List batchIndivList = (List) request.getSession().getAttribute(
072: "batchIndivSearchResults");
073:
074: if ((request.getParameter("sourceDocNbr") == null)
075: && (request.getParameter("docTypeCode") == null)
076: && (GeneralUtilities.isStringEmpty(buttonPressed))) {
077: // No Source Doc Number given and no button pressed
078: request.setAttribute("title",
079: "No Source Document Number Error");
080: errors.add("error", new ActionMessage(
081: "paymentDetail.epic.noSourceDocGiven"));
082: saveErrors(request, errors);
083: return mapping.findForward("pdp_message");
084: } else if ((request.getParameter("sourceDocNbr") != null)
085: && (request.getParameter("docTypeCode") != null)) {
086: // Source Doc Number was passed - find payment Detail with the Sopurce Doc Number
087: LOG
088: .debug("executeLogic() Source Document Number passed in Parms: "
089: + request.getParameter("sourceDocNbr"));
090: LOG.debug("executeLogic() Doc Type passed in Parms: "
091: + request.getParameter("docTypeCode"));
092: custPaymentDocNbr = (String) request
093: .getParameter("sourceDocNbr");
094: fdocTypeCode = (String) request.getParameter("docTypeCode");
095: pd = paymentDetailService.getDetailForEpic(
096: custPaymentDocNbr, fdocTypeCode);
097:
098: if (pd != null) {
099: pd.setLastDisbursementActionDate(this
100: .getDisbursementActionExpirationDate(request));
101: getPayeeDescriptor(request, pd);
102: getDisbursementPaymentList(request, pd);
103: request.getSession().setAttribute(
104: "size",
105: new Integer(pd.getPaymentGroup()
106: .getPaymentDetails().size()));
107: request.getSession().setAttribute("PaymentDetail", pd);
108: } else {
109: // No PDP Payment for Epic Source Doc Number given
110: request.setAttribute("title", "No Payment Found Error");
111: errors.add("error", new ActionMessage(
112: "paymentDetail.epic.noPaymentFound",
113: custPaymentDocNbr));
114: saveErrors(request, errors);
115: return mapping.findForward("pdp_message");
116: }
117: } else {
118: if (pd == null) {
119: // Handle Session Expiration
120: return mapping.findForward("pdp_session_timeout");
121: } else if (buttonPressed.startsWith("btnUpdate")) {
122: // Update Payment Detail in Session after action has been performed
123: // (status might have changed)
124: Integer detailId = pd.getId();
125: pd = paymentDetailService.get(detailId);
126:
127: pd.setLastDisbursementActionDate(this
128: .getDisbursementActionExpirationDate(request));
129: getPayeeDescriptor(request, pd);
130: getDisbursementPaymentList(request, pd);
131: request.getSession().setAttribute(
132: "size",
133: new Integer(pd.getPaymentGroup()
134: .getPaymentDetails().size()));
135: request.getSession().setAttribute("PaymentDetail", pd);
136: }
137: }
138:
139: // Use of a default tab (Summary Tab)
140: if ((GeneralUtilities.isStringEmpty(buttonPressed))
141: || (buttonPressed.startsWith("btnUpdate"))) {
142: request.setAttribute("btnPressed", "btnSummaryTab");
143: } else {
144: request.setAttribute("btnPressed", buttonPressed);
145: }
146:
147: return mapping.findForward("display");
148: }
149:
150: public void getPayeeDescriptor(HttpServletRequest request,
151: PaymentDetail pd) {
152: // Get descriptor of Payee ID Type based on Code in DB
153: Map<String, String> payees = payeeTypeDao.getAll();
154: Iterator i = payees.keySet().iterator();
155: while (i.hasNext()) {
156: String key = (String) i.next();
157: if (pd != null) {
158: if (key.equals(pd.getPaymentGroup().getPayeeIdTypeCd())) {
159: request.getSession().setAttribute(
160: "payeeIdTypeDesc", payees.get(key));
161: }
162: if (key.equals(pd.getPaymentGroup()
163: .getAlternatePayeeIdTypeCd())) {
164: request.getSession()
165: .setAttribute("alternatePayeeIdTypeDesc",
166: payees.get(key));
167: }
168: }
169: }
170: }
171:
172: public void getDisbursementPaymentList(HttpServletRequest request,
173: PaymentDetail pd) {
174: List paymentDetailList = new ArrayList();
175: Integer disbNbr = pd.getPaymentGroup().getDisbursementNbr();
176: request.getSession().removeAttribute("disbNbrTotalPayments");
177: request.getSession().removeAttribute("disbursementDetailsList");
178:
179: if ((disbNbr != null) && (disbNbr != new Integer(0))) {
180: List paymentGroupList = paymentGroupService
181: .getByDisbursementNumber(disbNbr);
182: for (Iterator iter = paymentGroupList.iterator(); iter
183: .hasNext();) {
184: PaymentGroup elem = (PaymentGroup) iter.next();
185: paymentDetailList.addAll(elem.getPaymentDetails());
186: }
187: request.getSession().setAttribute("disbNbrTotalPayments",
188: new Integer(paymentDetailList.size()));
189: request.getSession().setAttribute(
190: "disbursementDetailsList", paymentDetailList);
191: }
192: }
193:
194: public void setPayeeTypeDao(PayeeTypeDao p) {
195: payeeTypeDao = p;
196: }
197:
198: public void setPaymentDetailService(PaymentDetailService p) {
199: paymentDetailService = p;
200: }
201:
202: public void setPaymentGroupService(PaymentGroupService p) {
203: paymentGroupService = p;
204: }
205: }
|