001: /*
002: * Copyright 2006-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.financial.web.struts.action;
017:
018: import javax.servlet.http.HttpServletRequest;
019: import javax.servlet.http.HttpServletResponse;
020:
021: import org.apache.struts.action.ActionForm;
022: import org.apache.struts.action.ActionForward;
023: import org.apache.struts.action.ActionMapping;
024: import org.kuali.core.util.GlobalVariables;
025: import org.kuali.kfs.KFSConstants;
026: import org.kuali.kfs.KFSPropertyConstants;
027: import org.kuali.kfs.web.struts.action.KualiAccountingDocumentActionBase;
028: import org.kuali.module.financial.bo.CreditCardDetail;
029: import org.kuali.module.financial.document.CreditCardReceiptDocument;
030: import org.kuali.module.financial.rules.CreditCardReceiptDocumentRuleUtil;
031: import org.kuali.module.financial.web.struts.form.CreditCardReceiptForm;
032:
033: /**
034: * This is the action class for the CreditCardReceiptDocument.
035: */
036: public class CreditCardReceiptAction extends
037: KualiAccountingDocumentActionBase {
038: /**
039: * Adds handling for credit card receipt amount updates.
040: *
041: * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm,
042: * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
043: */
044: public ActionForward execute(ActionMapping mapping,
045: ActionForm form, HttpServletRequest request,
046: HttpServletResponse response) throws Exception {
047: CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;
048:
049: if (ccrForm.hasDocumentId()) {
050: CreditCardReceiptDocument ccrDoc = ccrForm
051: .getCreditCardReceiptDocument();
052:
053: ccrDoc.setTotalCreditCardAmount(ccrDoc
054: .calculateCreditCardReceiptTotal()); // recalc b/c changes to the amounts could
055: // have happened
056: }
057:
058: // proceed as usual
059: return super .execute(mapping, form, request, response);
060: }
061:
062: /**
063: * Adds a CreditCardDetail instance created from the current "new creditCardReceipt" line to the document
064: *
065: * @param mapping
066: * @param form
067: * @param request
068: * @param response
069: * @return ActionForward
070: * @throws Exception
071: */
072: public ActionForward addCreditCardReceipt(ActionMapping mapping,
073: ActionForm form, HttpServletRequest request,
074: HttpServletResponse response) throws Exception {
075: CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;
076: CreditCardReceiptDocument ccrDoc = ccrForm
077: .getCreditCardReceiptDocument();
078:
079: CreditCardDetail newCreditCardReceipt = ccrForm
080: .getNewCreditCardReceipt();
081: ccrDoc.prepareNewCreditCardReceipt(newCreditCardReceipt);
082:
083: // creditCardReceipt business rules
084: boolean rulePassed = validateNewCreditCardReceipt(newCreditCardReceipt);
085: if (rulePassed) {
086: // add creditCardReceipt
087: ccrDoc.addCreditCardReceipt(newCreditCardReceipt);
088:
089: // clear the used creditCardReceipt
090: ccrForm.setNewCreditCardReceipt(new CreditCardDetail());
091: }
092:
093: return mapping.findForward(KFSConstants.MAPPING_BASIC);
094: }
095:
096: /**
097: * Deletes the selected creditCardReceipt (line) from the document
098: *
099: * @param mapping
100: * @param form
101: * @param request
102: * @param response
103: * @return ActionForward
104: * @throws Exception
105: */
106: public ActionForward deleteCreditCardReceipt(ActionMapping mapping,
107: ActionForm form, HttpServletRequest request,
108: HttpServletResponse response) throws Exception {
109: CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;
110: CreditCardReceiptDocument ccrDoc = ccrForm
111: .getCreditCardReceiptDocument();
112:
113: int deleteIndex = getLineToDelete(request);
114: // delete creditCardReceipt
115: ccrDoc.removeCreditCardReceipt(deleteIndex);
116:
117: return mapping.findForward(KFSConstants.MAPPING_BASIC);
118: }
119:
120: /**
121: * This method validates a new credit card receipt detail record.
122: *
123: * @param creditCardReceipt
124: * @return boolean
125: */
126: private boolean validateNewCreditCardReceipt(
127: CreditCardDetail creditCardReceipt) {
128: GlobalVariables.getErrorMap().addToErrorPath(
129: KFSPropertyConstants.NEW_CREDIT_CARD_RECEIPT);
130: boolean isValid = CreditCardReceiptDocumentRuleUtil
131: .validateCreditCardReceipt(creditCardReceipt);
132: GlobalVariables.getErrorMap().removeFromErrorPath(
133: KFSPropertyConstants.NEW_CREDIT_CARD_RECEIPT);
134: return isValid;
135: }
136: }
|