1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.web.struts;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.apache.struts.action.ActionForm;
22 import org.apache.struts.action.ActionForward;
23 import org.apache.struts.action.ActionMapping;
24 import org.kuali.ole.fp.businessobject.CreditCardDetail;
25 import org.kuali.ole.fp.document.CreditCardReceiptDocument;
26 import org.kuali.ole.fp.document.validation.impl.CreditCardReceiptDocumentRuleUtil;
27 import org.kuali.ole.sys.OLEConstants;
28 import org.kuali.ole.sys.OLEPropertyConstants;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.service.BankService;
31 import org.kuali.rice.kew.api.exception.WorkflowException;
32 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
33 import org.kuali.rice.krad.util.GlobalVariables;
34
35
36
37
38 public class CreditCardReceiptAction extends CapitalAccountingLinesActionBase {
39
40
41
42
43
44
45 @Override
46 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
47 CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;
48
49 if (ccrForm.hasDocumentId()) {
50 CreditCardReceiptDocument ccrDoc = ccrForm.getCreditCardReceiptDocument();
51
52 ccrDoc.setTotalCreditCardAmount(ccrDoc.calculateCreditCardReceiptTotal());
53
54
55
56 ccrDoc.setBank(SpringContext.getBean(BankService.class).getByPrimaryId(ccrDoc.getCreditCardReceiptBankCode()));
57 }
58
59
60 return super.execute(mapping, form, request, response);
61 }
62
63
64
65
66
67
68
69
70
71
72
73 public ActionForward addCreditCardReceipt(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
74 CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;
75 CreditCardReceiptDocument ccrDoc = ccrForm.getCreditCardReceiptDocument();
76
77 CreditCardDetail newCreditCardReceipt = ccrForm.getNewCreditCardReceipt();
78 ccrDoc.prepareNewCreditCardReceipt(newCreditCardReceipt);
79
80
81 boolean rulePassed = validateNewCreditCardReceipt(newCreditCardReceipt);
82 if (rulePassed) {
83
84 ccrDoc.addCreditCardReceipt(newCreditCardReceipt);
85
86
87 ccrForm.setNewCreditCardReceipt(new CreditCardDetail());
88 }
89
90 return mapping.findForward(OLEConstants.MAPPING_BASIC);
91 }
92
93
94
95
96
97
98
99
100
101
102
103 public ActionForward deleteCreditCardReceipt(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
104 CreditCardReceiptForm ccrForm = (CreditCardReceiptForm) form;
105 CreditCardReceiptDocument ccrDoc = ccrForm.getCreditCardReceiptDocument();
106
107 int deleteIndex = getLineToDelete(request);
108
109 ccrDoc.removeCreditCardReceipt(deleteIndex);
110
111 return mapping.findForward(OLEConstants.MAPPING_BASIC);
112 }
113
114
115
116
117
118
119
120 protected boolean validateNewCreditCardReceipt(CreditCardDetail creditCardReceipt) {
121 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.NEW_CREDIT_CARD_RECEIPT);
122 boolean isValid = CreditCardReceiptDocumentRuleUtil.validateCreditCardReceipt(creditCardReceipt);
123 GlobalVariables.getMessageMap().removeFromErrorPath(OLEPropertyConstants.NEW_CREDIT_CARD_RECEIPT);
124 return isValid;
125 }
126
127
128
129
130
131
132 @Override
133 protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
134 super.createDocument(kualiDocumentFormBase);
135 ((CreditCardReceiptDocument) kualiDocumentFormBase.getDocument()).initiateDocument();
136 }
137 }