1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.authorization;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapAuthorizationConstants;
20 import org.kuali.ole.module.purap.PurapAuthorizationConstants.CreditMemoEditMode;
21 import org.kuali.ole.module.purap.PurapConstants;
22 import org.kuali.ole.module.purap.PurapConstants.CreditMemoStatuses;
23 import org.kuali.ole.module.purap.PurapParameterConstants;
24 import org.kuali.ole.module.purap.document.VendorCreditMemoDocument;
25 import org.kuali.ole.module.purap.document.service.PurapService;
26 import org.kuali.ole.sys.OLEConstants;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.sys.service.FinancialSystemWorkflowHelperService;
29 import org.kuali.ole.sys.service.impl.OleParameterConstants;
30 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
31 import org.kuali.rice.kew.api.WorkflowDocument;
32 import org.kuali.rice.krad.document.Document;
33 import org.kuali.rice.krad.util.GlobalVariables;
34 import org.kuali.rice.krad.util.ObjectUtils;
35
36 import java.util.Set;
37
38
39 public class VendorCreditMemoDocumentPresentationController extends PurchasingAccountsPayableDocumentPresentationController {
40
41 @Override
42 public boolean canSave(Document document) {
43 VendorCreditMemoDocument vendorCreditMemoDocument = (VendorCreditMemoDocument) document;
44
45 if (StringUtils.equals(vendorCreditMemoDocument.getApplicationDocumentStatus(), PurapConstants.CreditMemoStatuses.APPDOC_INITIATE)) {
46 return false;
47 }
48
49 if (canEditPreExtraction(vendorCreditMemoDocument)) {
50 return true;
51 }
52
53 return super.canSave(document);
54 }
55
56 @Override
57 public boolean canReload(Document document) {
58 VendorCreditMemoDocument vendorCreditMemoDocument = (VendorCreditMemoDocument) document;
59
60 if (StringUtils.equals(vendorCreditMemoDocument.getApplicationDocumentStatus(), PurapConstants.CreditMemoStatuses.APPDOC_INITIATE)) {
61 return false;
62 }
63
64 if (canEditPreExtraction(vendorCreditMemoDocument)) {
65 return true;
66 }
67
68 return super.canReload(document);
69 }
70
71 @Override
72 public boolean canCancel(Document document) {
73
74 return false;
75 }
76
77 @Override
78 public boolean canDisapprove(Document document) {
79
80 return false;
81 }
82
83
84
85
86 @Override
87 public boolean canEdit(Document document) {
88 if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted((VendorCreditMemoDocument) document)) {
89 return false;
90 }
91
92 return super.canEdit(document);
93 }
94
95
96
97
98 @Override
99 public Set<String> getEditModes(Document document) {
100 Set<String> editModes = super.getEditModes(document);
101
102 VendorCreditMemoDocument vendorCreditMemoDocument = (VendorCreditMemoDocument) document;
103 WorkflowDocument workflowDocument = vendorCreditMemoDocument.getFinancialSystemDocumentHeader().getWorkflowDocument();
104
105 if (canCancel(vendorCreditMemoDocument)) {
106 editModes.add(CreditMemoEditMode.ACCOUNTS_PAYABLE_PROCESSOR_CANCEL);
107 }
108
109 if (canHold(vendorCreditMemoDocument)) {
110 editModes.add(CreditMemoEditMode.HOLD);
111 }
112
113 if (canRemoveHold(vendorCreditMemoDocument)) {
114 editModes.add(CreditMemoEditMode.REMOVE_HOLD);
115 }
116
117 if (SpringContext.getBean(PurapService.class).isFullDocumentEntryCompleted(vendorCreditMemoDocument)) {
118 editModes.add(CreditMemoEditMode.FULL_DOCUMENT_ENTRY_COMPLETED);
119 } else {
120 if (ObjectUtils.isNotNull(vendorCreditMemoDocument.getPurchaseOrderDocument()) &&
121 !vendorCreditMemoDocument.isSourceVendor() &&
122 PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(vendorCreditMemoDocument.getPurchaseOrderDocument().getApplicationDocumentStatus())) {
123
124 editModes.add(CreditMemoEditMode.ALLOW_REOPEN_PURCHASE_ORDER);
125 }
126 }
127
128 if (StringUtils.equals(vendorCreditMemoDocument.getApplicationDocumentStatus(), PurapConstants.CreditMemoStatuses.APPDOC_INITIATE)) {
129 editModes.add(CreditMemoEditMode.DISPLAY_INIT_TAB);
130 }
131
132 if (canEditPreExtraction(vendorCreditMemoDocument)) {
133 editModes.add(CreditMemoEditMode.EDIT_PRE_EXTRACT);
134 }
135
136 if (!vendorCreditMemoDocument.isSourceDocumentPaymentRequest()) {
137 editModes.add(CreditMemoEditMode.LOCK_VENDOR_ENTRY);
138 }
139
140
141 boolean salesTaxInd = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.ENABLE_SALES_TAX_IND);
142 if (salesTaxInd) {
143 editModes.add(PurapAuthorizationConstants.PURAP_TAX_ENABLED);
144
145 if (vendorCreditMemoDocument.isUseTaxIndicator()) {
146
147 editModes.add(CreditMemoEditMode.LOCK_TAX_AMOUNT_ENTRY);
148 } else {
149
150 editModes.add(CreditMemoEditMode.CLEAR_ALL_TAXES);
151 }
152 }
153
154
155 if (vendorCreditMemoDocument.isExtracted()) {
156 editModes.remove(OLEConstants.BANK_ENTRY_EDITABLE_EDITING_MODE);
157 }
158
159 return editModes;
160 }
161
162
163
164
165
166
167
168
169 protected boolean canHold(VendorCreditMemoDocument cmDocument) {
170 return !cmDocument.isHoldIndicator() && !cmDocument.isExtracted() && !PurapConstants.CreditMemoStatuses.STATUSES_DISALLOWING_HOLD.contains(cmDocument.getApplicationDocumentStatus());
171 }
172
173
174
175
176
177
178
179 protected boolean canRemoveHold(VendorCreditMemoDocument cmDocument) {
180 return cmDocument.isHoldIndicator();
181 }
182
183
184
185
186
187
188
189
190 protected boolean canCancel(VendorCreditMemoDocument cmDocument) {
191 return !CreditMemoStatuses.CANCELLED_STATUSES.contains(cmDocument.getApplicationDocumentStatus()) && !cmDocument.isExtracted() && !cmDocument.isHoldIndicator();
192 }
193
194 protected boolean canEditPreExtraction(VendorCreditMemoDocument vendorCreditMemoDocument) {
195 return (!vendorCreditMemoDocument.isExtracted() &&
196 !SpringContext.getBean(FinancialSystemWorkflowHelperService.class).isAdhocApprovalRequestedForPrincipal(vendorCreditMemoDocument.getFinancialSystemDocumentHeader().getWorkflowDocument(), GlobalVariables.getUserSession().getPrincipalId()) &&
197 !PurapConstants.CreditMemoStatuses.CANCELLED_STATUSES.contains(vendorCreditMemoDocument.getApplicationDocumentStatus()));
198 }
199
200 }