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.purap.web.struts.action;
017:
018: import java.util.HashMap;
019:
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022:
023: import org.apache.struts.action.ActionForm;
024: import org.apache.struts.action.ActionForward;
025: import org.apache.struts.action.ActionMapping;
026: import org.kuali.core.question.ConfirmationQuestion;
027: import org.kuali.core.service.KualiRuleService;
028: import org.kuali.core.web.struts.form.KualiDocumentFormBase;
029: import org.kuali.kfs.KFSConstants;
030: import org.kuali.kfs.context.SpringContext;
031: import org.kuali.module.purap.PurapConstants;
032: import org.kuali.module.purap.PurapKeyConstants;
033: import org.kuali.module.purap.PurapConstants.PREQDocumentsStrings;
034: import org.kuali.module.purap.document.AccountsPayableDocument;
035: import org.kuali.module.purap.document.PaymentRequestDocument;
036: import org.kuali.module.purap.rule.event.CalculateAccountsPayableEvent;
037: import org.kuali.module.purap.service.PaymentRequestService;
038: import org.kuali.module.purap.service.PurapService;
039: import org.kuali.module.purap.util.PurQuestionCallback;
040: import org.kuali.module.purap.web.struts.form.PaymentRequestForm;
041:
042: import edu.iu.uis.eden.exception.WorkflowException;
043:
044: /**
045: * Struts Action for Payment Request document.
046: */
047: public class PaymentRequestAction extends AccountsPayableActionBase {
048: static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
049: .getLogger(PaymentRequestAction.class);
050:
051: /**
052: * Do initialization for a new payment request.
053: *
054: * @see org.kuali.core.web.struts.action.KualiDocumentActionBase#createDocument(org.kuali.core.web.struts.form.KualiDocumentFormBase)
055: */
056: @Override
057: protected void createDocument(
058: KualiDocumentFormBase kualiDocumentFormBase)
059: throws WorkflowException {
060: super .createDocument(kualiDocumentFormBase);
061: ((PaymentRequestDocument) kualiDocumentFormBase.getDocument())
062: .initiateDocument();
063: }
064:
065: /**
066: * @see org.kuali.core.web.struts.action.KualiAction#refresh(org.apache.struts.action.ActionMapping,
067: * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
068: */
069: @Override
070: public ActionForward refresh(ActionMapping mapping,
071: ActionForm form, HttpServletRequest request,
072: HttpServletResponse response) throws Exception {
073: PaymentRequestForm preqForm = (PaymentRequestForm) form;
074: PaymentRequestDocument document = (PaymentRequestDocument) preqForm
075: .getDocument();
076:
077: return super .refresh(mapping, form, request, response);
078: }
079:
080: /**
081: * Executes the continue action on a payment request. Populates and initializes the rest of the payment request besides what was
082: * shown on the init screen.
083: *
084: * @param mapping An ActionMapping
085: * @param form An ActionForm
086: * @param request The HttpServletRequest
087: * @param response The HttpServletResponse
088: * @throws Exception
089: * @return An ActionForward
090: */
091: public ActionForward continuePREQ(ActionMapping mapping,
092: ActionForm form, HttpServletRequest request,
093: HttpServletResponse response) throws Exception {
094: LOG.debug("continuePREQ() method");
095:
096: PaymentRequestForm preqForm = (PaymentRequestForm) form;
097: PaymentRequestDocument paymentRequestDocument = (PaymentRequestDocument) preqForm
098: .getDocument();
099:
100: // preform duplicate check which will forward to a question prompt if one is found
101: ActionForward forward = performDuplicatePaymentRequestCheck(
102: mapping, form, request, response,
103: paymentRequestDocument);
104: if (forward != null) {
105:
106: return forward;
107: }
108:
109: // If we are here either there was no duplicate or there was a duplicate and the user hits continue, in either case we need
110: // to validate the business rules
111: SpringContext.getBean(PaymentRequestService.class)
112: .populateAndSavePaymentRequest(paymentRequestDocument);
113:
114: // force calculation
115: preqForm.setCalculated(false);
116:
117: // sort below the line
118: SpringContext.getBean(PurapService.class).sortBelowTheLine(
119: paymentRequestDocument);
120:
121: // update the counts on the form
122: preqForm.updateItemCounts();
123:
124: return mapping.findForward(KFSConstants.MAPPING_BASIC);
125: }
126:
127: /**
128: * Clears the initial fields on the <code>PaymentRequestDocument</code> which should be accessible from the given form.
129: *
130: * @param mapping An ActionMapping
131: * @param form An ActionForm, which must be a PaymentRequestForm
132: * @param request The HttpServletRequest
133: * @param response The HttpServletResponse
134: * @throws Exception
135: * @return An ActionForward
136: */
137: public ActionForward clearInitFields(ActionMapping mapping,
138: ActionForm form, HttpServletRequest request,
139: HttpServletResponse response) throws Exception {
140: LOG.debug("clearInitValues() method");
141: PaymentRequestForm preqForm = (PaymentRequestForm) form;
142: PaymentRequestDocument paymentRequestDocument = (PaymentRequestDocument) preqForm
143: .getDocument();
144: paymentRequestDocument.clearInitFields();
145:
146: return super .refresh(mapping, form, request, response);
147: }
148:
149: /**
150: * Calls <code>PaymentRequestService</code> to perform the duplicate payment request check. If one is found, a question is
151: * setup and control is forwarded to the question action method. Coming back from the question prompt the button that was
152: * clicked is checked and if 'no' was selected they are forward back to the page still in init mode.
153: *
154: * @param mapping An ActionMapping
155: * @param form An ActionForm
156: * @param request The HttpServletRequest
157: * @param response The HttpServletResponse
158: * @param paymentRequestDocument The PaymentRequestDocument
159: * @throws Exception
160: * @return An ActionForward
161: * @see org.kuali.module.purap.service.PaymentRequestService
162: */
163: private ActionForward performDuplicatePaymentRequestCheck(
164: ActionMapping mapping, ActionForm form,
165: HttpServletRequest request, HttpServletResponse response,
166: PaymentRequestDocument paymentRequestDocument)
167: throws Exception {
168: ActionForward forward = null;
169: HashMap<String, String> duplicateMessages = SpringContext
170: .getBean(PaymentRequestService.class)
171: .paymentRequestDuplicateMessages(paymentRequestDocument);
172: if (!duplicateMessages.isEmpty()) {
173: Object question = request
174: .getParameter(KFSConstants.QUESTION_INST_ATTRIBUTE_NAME);
175: if (question == null) {
176:
177: return this
178: .performQuestionWithoutInput(
179: mapping,
180: form,
181: request,
182: response,
183: PREQDocumentsStrings.DUPLICATE_INVOICE_QUESTION,
184: duplicateMessages
185: .get(PREQDocumentsStrings.DUPLICATE_INVOICE_QUESTION),
186: KFSConstants.CONFIRMATION_QUESTION,
187: KFSConstants.ROUTE_METHOD, "");
188: }
189:
190: Object buttonClicked = request
191: .getParameter(KFSConstants.QUESTION_CLICKED_BUTTON);
192: if ((PurapConstants.PREQDocumentsStrings.DUPLICATE_INVOICE_QUESTION
193: .equals(question))
194: && ConfirmationQuestion.NO.equals(buttonClicked)) {
195: paymentRequestDocument
196: .setStatusCode(PurapConstants.PaymentRequestStatuses.INITIATE);
197: forward = mapping
198: .findForward(KFSConstants.MAPPING_BASIC);
199: }
200: }
201:
202: return forward;
203: }
204:
205: /**
206: * Puts a payment on hold, prompting for a reason beforehand. This stops further approvals or routing.
207: *
208: * @param mapping An ActionMapping
209: * @param form An ActionForm
210: * @param request The HttpServletRequest
211: * @param response The HttpServletResponse
212: * @throws Exception
213: * @return An ActionForward
214: */
215: public ActionForward addHoldOnPayment(ActionMapping mapping,
216: ActionForm form, HttpServletRequest request,
217: HttpServletResponse response) throws Exception {
218: String operation = "Hold ";
219:
220: PurQuestionCallback callback = new PurQuestionCallback() {
221: public void doPostQuestion(
222: AccountsPayableDocument document, String noteText)
223: throws Exception {
224: SpringContext.getBean(PaymentRequestService.class)
225: .addHoldOnPaymentRequest(
226: (PaymentRequestDocument) document,
227: noteText);
228: }
229: };
230:
231: return askQuestionWithInput(
232: mapping,
233: form,
234: request,
235: response,
236: PREQDocumentsStrings.HOLD_PREQ_QUESTION,
237: PREQDocumentsStrings.HOLD_NOTE_PREFIX,
238: operation,
239: PurapKeyConstants.PAYMENT_REQUEST_MESSAGE_HOLD_DOCUMENT,
240: callback);
241: }
242:
243: /**
244: * Removes a hold on the payment request.
245: *
246: * @param mapping An ActionMapping
247: * @param form An ActionForm
248: * @param request The HttpServletRequest
249: * @param response The HttpServletResponse
250: * @throws Exception
251: * @return An ActionForward
252: */
253: public ActionForward removeHoldFromPayment(ActionMapping mapping,
254: ActionForm form, HttpServletRequest request,
255: HttpServletResponse response) throws Exception {
256: String operation = "Remove ";
257:
258: PurQuestionCallback callback = new PurQuestionCallback() {
259: public void doPostQuestion(
260: AccountsPayableDocument document, String noteText)
261: throws Exception {
262: SpringContext.getBean(PaymentRequestService.class)
263: .removeHoldOnPaymentRequest(
264: (PaymentRequestDocument) document,
265: noteText);
266: }
267: };
268:
269: return askQuestionWithInput(
270: mapping,
271: form,
272: request,
273: response,
274: PREQDocumentsStrings.REMOVE_HOLD_PREQ_QUESTION,
275: PREQDocumentsStrings.REMOVE_HOLD_NOTE_PREFIX,
276: operation,
277: PurapKeyConstants.PAYMENT_REQUEST_MESSAGE_REMOVE_HOLD_DOCUMENT,
278: callback);
279: }
280:
281: /**
282: * This action requests a cancel on a preq, prompting for a reason before hand. This stops further approvals or routing.
283: *
284: * @param mapping An ActionMapping
285: * @param form An ActionForm
286: * @param request The HttpServletRequest
287: * @param response The HttpServletResponse
288: * @throws Exception
289: * @return An ActionForward
290: */
291: public ActionForward requestCancelOnPayment(ActionMapping mapping,
292: ActionForm form, HttpServletRequest request,
293: HttpServletResponse response) throws Exception {
294: String operation = "Cancel ";
295:
296: PurQuestionCallback callback = new PurQuestionCallback() {
297: public void doPostQuestion(
298: AccountsPayableDocument document, String noteText)
299: throws Exception {
300: SpringContext.getBean(PaymentRequestService.class)
301: .requestCancelOnPaymentRequest(
302: (PaymentRequestDocument) document,
303: noteText);
304: }
305: };
306:
307: return askQuestionWithInput(
308: mapping,
309: form,
310: request,
311: response,
312: PREQDocumentsStrings.CANCEL_PREQ_QUESTION,
313: PREQDocumentsStrings.CANCEL_NOTE_PREFIX,
314: operation,
315: PurapKeyConstants.PAYMENT_REQUEST_MESSAGE_CANCEL_DOCUMENT,
316: callback);
317: }
318:
319: /**
320: * @see org.kuali.module.purap.web.struts.action.AccountsPayableActionBase#cancelPOActionCallbackMethod()
321: */
322: @Override
323: protected PurQuestionCallback cancelPOActionCallbackMethod() {
324:
325: return new PurQuestionCallback() {
326: public void doPostQuestion(
327: AccountsPayableDocument document, String noteText)
328: throws Exception {
329: PaymentRequestDocument preqDocument = (PaymentRequestDocument) document;
330: preqDocument.setReopenPurchaseOrderIndicator(true);
331: }
332: };
333: }
334:
335: /**
336: * Removes a request for cancel on a payment request.
337: *
338: * @param mapping An ActionMapping
339: * @param form An ActionForm
340: * @param request The HttpServletRequest
341: * @param response The HttpServletResponse
342: * @throws Exception
343: * @return An ActionForward
344: */
345: public ActionForward removeCancelRequestFromPayment(
346: ActionMapping mapping, ActionForm form,
347: HttpServletRequest request, HttpServletResponse response)
348: throws Exception {
349: String operation = "Cancel ";
350:
351: PurQuestionCallback callback = new PurQuestionCallback() {
352: public void doPostQuestion(
353: AccountsPayableDocument document, String noteText)
354: throws Exception {
355: SpringContext.getBean(PaymentRequestService.class)
356: .removeRequestCancelOnPaymentRequest(
357: (PaymentRequestDocument) document,
358: noteText);
359: }
360: };
361:
362: return askQuestionWithInput(
363: mapping,
364: form,
365: request,
366: response,
367: PREQDocumentsStrings.REMOVE_CANCEL_PREQ_QUESTION,
368: PREQDocumentsStrings.REMOVE_CANCEL_NOTE_PREFIX,
369: operation,
370: PurapKeyConstants.PAYMENT_REQUEST_MESSAGE_REMOVE_CANCEL_DOCUMENT,
371: callback);
372: }
373:
374: /**
375: * Calls a service method to calculate for a payment request document.
376: *
377: * @param apDoc The AccountsPayableDocument
378: */
379: @Override
380: protected void customCalculate(AccountsPayableDocument apDoc) {
381: PaymentRequestDocument preqDoc = (PaymentRequestDocument) apDoc;
382: // set amounts on any empty
383: preqDoc.updateExtendedPriceOnItems();
384:
385: // notice we're ignoring whether the boolean, because these are just warnings they shouldn't halt anything
386: SpringContext.getBean(KualiRuleService.class).applyRules(
387: new CalculateAccountsPayableEvent(preqDoc));
388: SpringContext.getBean(PaymentRequestService.class)
389: .calculatePaymentRequest(preqDoc, true);
390: }
391:
392: /**
393: * @see org.kuali.module.purap.web.struts.action.AccountsPayableActionBase#getActionName()
394: */
395: @Override
396: public String getActionName() {
397: return PurapConstants.PAYMENT_REQUEST_ACTION_NAME;
398: }
399: }
|