1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.web.struts;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.struts.action.ActionForm;
20 import org.apache.struts.action.ActionForward;
21 import org.apache.struts.action.ActionMapping;
22 import org.kuali.ole.module.purap.PurapKeyConstants;
23 import org.kuali.ole.module.purap.businessobject.DefaultPrincipalAddress;
24 import org.kuali.ole.module.purap.businessobject.RequisitionItem;
25 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
26 import org.kuali.ole.module.purap.document.RequisitionDocument;
27 import org.kuali.ole.module.purap.document.service.PurapService;
28 import org.kuali.ole.select.document.OleRequisitionDocument;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.context.SpringContext;
31 import org.kuali.rice.core.api.util.RiceConstants;
32 import org.kuali.rice.kew.api.exception.WorkflowException;
33 import org.kuali.rice.kns.util.KNSGlobalVariables;
34 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
35 import org.kuali.rice.krad.service.BusinessObjectService;
36 import org.kuali.rice.krad.service.PersistenceService;
37 import org.kuali.rice.krad.util.GlobalVariables;
38 import org.kuali.rice.krad.util.ObjectUtils;
39
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
42 import java.util.Map;
43
44
45
46
47 public class RequisitionAction extends PurchasingActionBase {
48 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RequisitionAction.class);
49
50
51
52
53
54
55 @Override
56 public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
57
58
59 ActionForward actionForward = super.save(mapping, form, request, response);
60
61
62
63 KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
64 PurchasingFormBase baseForm = (PurchasingFormBase) form;
65 PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) kualiDocumentFormBase.getDocument();
66
67 baseForm.setCalculated(false);
68 purapDocument.setCalculated(false);
69
70 return mapping.findForward(RiceConstants.MAPPING_BASIC);
71 }
72
73
74
75
76
77
78 @Override
79 protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
80 super.createDocument(kualiDocumentFormBase);
81 ((RequisitionDocument) kualiDocumentFormBase.getDocument()).initiateDocument();
82 }
83
84 public ActionForward setAsDefaultBuilding(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
85 RequisitionDocument req = (RequisitionDocument) ((RequisitionForm) form).getDocument();
86
87 if (ObjectUtils.isNotNull(req.getDeliveryCampusCode()) && ObjectUtils.isNotNull(req.getDeliveryBuildingCode())) {
88 DefaultPrincipalAddress defaultPrincipalAddress = new DefaultPrincipalAddress(GlobalVariables.getUserSession().getPerson().getPrincipalId());
89 Map addressKeys = SpringContext.getBean(PersistenceService.class).getPrimaryKeyFieldValues(defaultPrincipalAddress);
90 defaultPrincipalAddress = (DefaultPrincipalAddress) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(DefaultPrincipalAddress.class, addressKeys);
91
92 if (ObjectUtils.isNull(defaultPrincipalAddress)) {
93 defaultPrincipalAddress = new DefaultPrincipalAddress(GlobalVariables.getUserSession().getPerson().getPrincipalId());
94 }
95
96 defaultPrincipalAddress.setDefaultBuilding(req.getDeliveryCampusCode(), req.getDeliveryBuildingCode(), req.getDeliveryBuildingRoomNumber());
97 SpringContext.getBean(BusinessObjectService.class).save(defaultPrincipalAddress);
98 KNSGlobalVariables.getMessageList().add(PurapKeyConstants.DEFAULT_BUILDING_SAVED);
99 }
100
101 return mapping.findForward(OLEConstants.MAPPING_BASIC);
102 }
103
104
105
106
107
108 @Override
109 public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
110 ActionForward forward = super.refresh(mapping, form, request, response);
111 RequisitionForm rqForm = (RequisitionForm) form;
112 RequisitionDocument document = (RequisitionDocument) rqForm.getDocument();
113
114
115 document.setOrganizationAutomaticPurchaseOrderLimit(SpringContext.getBean(PurapService.class).getApoLimit(document.getVendorContractGeneratedIdentifier(), document.getChartOfAccountsCode(), document.getOrganizationCode()));
116
117 return forward;
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131 public ActionForward addAsset(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
132 RequisitionForm rqForm = (RequisitionForm) form;
133 RequisitionDocument document = (RequisitionDocument) rqForm.getDocument();
134 RequisitionItem item = (RequisitionItem) document.getItemByLineNumber(getSelectedLine(request) + 1);
135
136
137 return mapping.findForward(OLEConstants.MAPPING_BASIC);
138 }
139
140 public ActionForward displayB2BRequisition(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
141 RequisitionForm reqForm = (RequisitionForm) form;
142 reqForm.setDocId((String) request.getSession().getAttribute("docId"));
143 loadDocument(reqForm);
144 String multipleB2BReqs = (String) request.getSession().getAttribute("multipleB2BRequisitions");
145 if (StringUtils.isNotEmpty(multipleB2BReqs)) {
146 KNSGlobalVariables.getMessageList().add(PurapKeyConstants.B2B_MULTIPLE_REQUISITIONS);
147 }
148 request.getSession().removeAttribute("docId");
149 request.getSession().removeAttribute("multipleB2BRequisitions");
150 return mapping.findForward(OLEConstants.MAPPING_BASIC);
151 }
152
153
154
155
156
157
158
159
160
161
162
163 public ActionForward clearVendor(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
164 PurchasingFormBase baseForm = (PurchasingFormBase) form;
165 OleRequisitionDocument document = (OleRequisitionDocument) baseForm.getDocument();
166
167 document.setVendorHeaderGeneratedIdentifier(null);
168 document.setVendorDetailAssignedIdentifier(null);
169 document.setVendorDetail(null);
170 document.setVendorName("");
171 document.setVendorLine1Address("");
172 document.setVendorLine2Address("");
173 document.setVendorAddressInternationalProvinceName("");
174 document.setVendorCityName("");
175 document.setVendorStateCode("");
176 document.setVendorPostalCode("");
177 document.setVendorCountryCode("");
178 document.setVendorContractGeneratedIdentifier(null);
179 document.setVendorContract(null);
180 document.setVendorFaxNumber("");
181 document.setVendorCustomerNumber("");
182 document.setVendorAttentionName("");
183 document.setVendorAliasName("");
184 return mapping.findForward(OLEConstants.MAPPING_BASIC);
185 }
186
187
188
189
190
191
192
193
194 @Override
195 public ActionForward blanketApprove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
196 RequisitionDocument document = (RequisitionDocument) ((PurchasingFormBase) form).getDocument();
197 document.setBlanketApproveRequest(true);
198 return super.blanketApprove(mapping, form, request, response);
199 }
200 }