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.kuali.ole.module.purap.PurapAuthorizationConstants;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.PurapParameterConstants;
21 import org.kuali.ole.module.purap.businessobject.LineItemReceivingItem;
22 import org.kuali.ole.module.purap.document.LineItemReceivingDocument;
23 import org.kuali.ole.module.purap.document.service.ReceivingService;
24 import org.kuali.ole.sys.OLEConstants;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
27 import org.kuali.rice.kew.api.WorkflowDocument;
28 import org.kuali.rice.kim.api.identity.Person;
29 import org.kuali.rice.kns.document.authorization.DocumentAuthorizer;
30 import org.kuali.rice.kns.service.DocumentHelperService;
31 import org.kuali.rice.kns.web.ui.ExtraButton;
32 import org.kuali.rice.kns.web.ui.HeaderField;
33 import org.kuali.rice.krad.util.GlobalVariables;
34 import org.kuali.rice.krad.util.ObjectUtils;
35
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39
40 public class LineItemReceivingForm extends ReceivingFormBase {
41
42 protected Integer purchaseOrderId;
43 protected LineItemReceivingItem newLineItemReceivingItemLine;
44 protected boolean fromPurchaseOrder = false;
45 protected Boolean hideAddUnorderedItem = true;
46
47
48
49
50 public LineItemReceivingForm() {
51 super();
52
53 this.setNewLineItemReceivingItemLine(setupNewLineItemReceivingItemLine());
54 newLineItemReceivingItemLine.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE);
55 }
56
57 @Override
58 protected String getDefaultDocumentTypeName() {
59 return "OLE_RCVL";
60 }
61
62 public LineItemReceivingDocument getLineItemReceivingDocument() {
63 return (LineItemReceivingDocument) getDocument();
64 }
65
66 public void setLineItemReceivingDocument(LineItemReceivingDocument lineItemReceivingDocument) {
67 setDocument(lineItemReceivingDocument);
68 }
69
70 public Integer getPurchaseOrderId() {
71 return purchaseOrderId;
72 }
73
74 public void setPurchaseOrderId(Integer purchaseOrderId) {
75 this.purchaseOrderId = purchaseOrderId;
76 }
77
78 public LineItemReceivingItem setupNewLineItemReceivingItemLine() {
79 return new LineItemReceivingItem();
80 }
81
82 public LineItemReceivingItem getNewLineItemReceivingItemLine() {
83 return newLineItemReceivingItemLine;
84 }
85
86 public void setNewLineItemReceivingItemLine(LineItemReceivingItem newLineItemReceivingItemLine) {
87 this.newLineItemReceivingItemLine = newLineItemReceivingItemLine;
88 }
89
90 @Override
91 public void populateHeaderFields(WorkflowDocument workflowDocument) {
92 super.populateHeaderFields(workflowDocument);
93
94
95 getDocInfo().add(new HeaderField());
96
97 String applicationDocumentStatus = PurapConstants.PURAP_APPLICATION_DOCUMENT_STATUS_NOT_AVAILABLE;
98
99 if (ObjectUtils.isNotNull(this.getLineItemReceivingDocument().getAppDocStatus())) {
100 applicationDocumentStatus = workflowDocument.getApplicationDocumentStatus();
101 }
102
103 getDocInfo().add(new HeaderField("DataDictionary.LineItemReceivingDocument.attributes.applicationDocumentStatus", applicationDocumentStatus));
104 }
105
106
107
108
109
110
111 @Override
112 public List<ExtraButton> getExtraButtons() {
113 extraButtons.clear();
114 Map buttonsMap = createButtonsMap();
115
116 String displayInitTab = (String) getEditingMode().get(PurapAuthorizationConstants.LineItemReceivingEditMode.DISPLAY_INIT_TAB);
117 if (ObjectUtils.isNotNull(displayInitTab) && displayInitTab.equalsIgnoreCase("true")) {
118 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.continueReceivingLine"));
119 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.clearInitFields"));
120 } else {
121 if (canCreateCorrection()) {
122 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.createReceivingCorrection"));
123 }
124 }
125
126 return extraButtons;
127 }
128
129 protected boolean canCreateCorrection() {
130 Person user = GlobalVariables.getUserSession().getPerson();
131 DocumentAuthorizer documentAuthorizer = SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING);
132 boolean isUserAuthorized = documentAuthorizer.canInitiate(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING, user);
133 return SpringContext.getBean(ReceivingService.class).canCreateCorrectionReceivingDocument(getLineItemReceivingDocument()) && isUserAuthorized;
134 }
135
136
137
138
139
140
141 protected Map<String, ExtraButton> createButtonsMap() {
142 HashMap<String, ExtraButton> result = new HashMap<String, ExtraButton>();
143
144
145 ExtraButton continueButton = new ExtraButton();
146 continueButton.setExtraButtonProperty("methodToCall.continueReceivingLine");
147 continueButton.setExtraButtonSource("${" + OLEConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_continue.gif");
148 continueButton.setExtraButtonAltText("Continue");
149 result.put(continueButton.getExtraButtonProperty(), continueButton);
150
151
152 ExtraButton clearButton = new ExtraButton();
153 clearButton.setExtraButtonProperty("methodToCall.clearInitFields");
154 clearButton.setExtraButtonSource("${" + OLEConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_clear.gif");
155 clearButton.setExtraButtonAltText("Clear");
156 result.put(clearButton.getExtraButtonProperty(), clearButton);
157
158
159 ExtraButton correctionButton = new ExtraButton();
160 correctionButton.setExtraButtonProperty("methodToCall.createReceivingCorrection");
161 correctionButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_correction.gif");
162 correctionButton.setExtraButtonAltText("Correction");
163 result.put(correctionButton.getExtraButtonProperty(), correctionButton);
164
165 return result;
166 }
167
168
169
170
171
172
173 public LineItemReceivingItem getAndResetNewReceivingItemLine() {
174 LineItemReceivingItem receivingItemLine = getNewLineItemReceivingItemLine();
175 setNewLineItemReceivingItemLine(setupNewReceivingItemLine());
176 return receivingItemLine;
177 }
178
179
180
181
182 public LineItemReceivingItem setupNewReceivingItemLine() {
183 LineItemReceivingItem lineItemReceivingItem = new LineItemReceivingItem((LineItemReceivingDocument) getDocument());
184 newLineItemReceivingItemLine.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE);
185 return lineItemReceivingItem;
186 }
187
188
189
190
191
192
193
194 public boolean isAbleToShowClearAndLoadQtyButtons() {
195 return SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(LineItemReceivingDocument.class, PurapParameterConstants.SHOW_CLEAR_AND_LOAD_QTY_BUTTONS);
196 }
197
198
199
200
201
202
203 public boolean shouldGiveAddUnorderedItemWarning() {
204 return SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(LineItemReceivingDocument.class, PurapParameterConstants.UNORDERED_ITEM_WARNING_IND);
205 }
206
207 public boolean isFromPurchaseOrder() {
208 return fromPurchaseOrder;
209 }
210
211 public void setFromPurchaseOrder(boolean fromPurchaseOrder) {
212 this.fromPurchaseOrder = fromPurchaseOrder;
213 }
214
215 public Boolean getHideAddUnorderedItem() {
216 return hideAddUnorderedItem;
217 }
218
219 public void setHideAddUnorderedItem(Boolean hideAddUnorderedItem) {
220 this.hideAddUnorderedItem = hideAddUnorderedItem;
221 }
222
223 }