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.PurapConstants;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
22 import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
23 import org.kuali.ole.module.purap.document.PurchaseOrderAmendmentDocument;
24 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
25 import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
26 import org.kuali.ole.select.OleSelectConstant;
27 import org.kuali.ole.sys.OLEPropertyConstants;
28 import org.kuali.ole.sys.businessobject.AccountingLine;
29 import org.kuali.ole.sys.document.AccountingDocument;
30 import org.kuali.rice.core.api.util.type.KualiDecimal;
31 import org.kuali.rice.kew.api.WorkflowDocument;
32 import org.kuali.rice.kim.api.identity.Person;
33
34 import java.util.List;
35 import java.util.Set;
36
37
38
39
40 public class PurchaseOrderAccountingLineAuthorizer extends PurapAccountingLineAuthorizer {
41 private static final String NEW_UNORDERED_ITEMS_NODE = "NewUnorderedItems";
42
43
44
45
46
47
48 @Override
49 public boolean renderNewLine(AccountingDocument accountingDocument, String accountingGroupProperty) {
50 WorkflowDocument workflowDocument = ((PurchasingAccountsPayableDocument) accountingDocument).getFinancialSystemDocumentHeader().getWorkflowDocument();
51
52 Set<String> currentRouteNodeName = workflowDocument.getCurrentNodeNames();
53
54
55 if (PurchaseOrderAccountingLineAuthorizer.NEW_UNORDERED_ITEMS_NODE.equals(currentRouteNodeName.toString())) {
56 return true;
57 }
58
59 if (PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT.equals(workflowDocument.getDocumentTypeName()) && StringUtils.isNotBlank(accountingGroupProperty) && accountingGroupProperty.contains(PurapPropertyConstants.ITEM)) {
60 int itemNumber = determineItemNumberFromGroupProperty(accountingGroupProperty);
61 PurchaseOrderAmendmentDocument poaDoc = (PurchaseOrderAmendmentDocument) accountingDocument;
62 List<PurchaseOrderItem> items = poaDoc.getItems();
63 PurchaseOrderItem item = items.get(itemNumber);
64 return item.isNewItemForAmendment() || item.getSourceAccountingLines().size() == 0;
65 }
66
67 return super.renderNewLine(accountingDocument, accountingGroupProperty);
68 }
69
70 private int determineItemNumberFromGroupProperty(String accountingGroupProperty) {
71 int openBracketPos = accountingGroupProperty.indexOf("[");
72 int closeBracketPos = accountingGroupProperty.indexOf("]");
73 String itemNumberString = accountingGroupProperty.substring(openBracketPos + 1, closeBracketPos);
74 int itemNumber = new Integer(itemNumberString).intValue();
75 return itemNumber;
76 }
77
78 @Override
79 protected boolean allowAccountingLinesAreEditable(AccountingDocument accountingDocument,
80 AccountingLine accountingLine) {
81 PurApAccountingLine purapAccount = (PurApAccountingLine) accountingLine;
82 PurchaseOrderItem poItem = (PurchaseOrderItem) purapAccount.getPurapItem();
83 PurchaseOrderDocument po = (PurchaseOrderDocument) accountingDocument;
84
85
86 if (poItem != null && !poItem.getItemType().isAdditionalChargeIndicator()) {
87 if (!poItem.isItemActiveIndicator()) {
88 return false;
89 }
90
91
92 if (poItem.getItemInvoicedTotalAmount() != null && poItem.getItemInvoicedTotalAmount().compareTo(new KualiDecimal(0)) != 0) {
93 return false;
94 }
95
96 if (po.getContainsUnpaidPaymentRequestsOrCreditMemos() && !poItem.isNewItemForAmendment()) {
97 return false;
98 }
99
100 }
101 return super.allowAccountingLinesAreEditable(accountingDocument, accountingLine);
102 }
103
104 @Override
105 public boolean determineEditPermissionOnLine(AccountingDocument accountingDocument, AccountingLine accountingLine, String accountingLineCollectionProperty, boolean currentUserIsDocumentInitiator, boolean pageIsEditable) {
106
107 if (accountingLine.getSequenceNumber() == null) {
108 return true;
109 }
110
111
112
113 WorkflowDocument workflowDocument = ((PurchasingAccountsPayableDocument) accountingDocument).getFinancialSystemDocumentHeader().getWorkflowDocument();
114 PurchaseOrderDocument poDocument = ((PurchaseOrderDocument) accountingDocument);
115
116 if (!poDocument.getApplicationDocumentStatus().equals(PurapConstants.PurchaseOrderStatuses.APPDOC_IN_PROCESS) && (workflowDocument.isInitiated() || workflowDocument.isSaved())) {
117 if (PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT.equals(workflowDocument.getDocumentTypeName())) {
118 PurApAccountingLine purapAccount = (PurApAccountingLine) accountingLine;
119 PurchaseOrderItem item = (PurchaseOrderItem) purapAccount.getPurapItem();
120
121 return item.isNewItemForAmendment() || item.getSourceAccountingLines().size() == OleSelectConstant.ONE;
122 } else {
123 return currentUserIsDocumentInitiator;
124 }
125 } else {
126 return true;
127 }
128 }
129
130
131
132
133 @Override
134 public Set<String> getUnviewableBlocks(AccountingDocument accountingDocument, AccountingLine accountingLine, boolean newLine, Person currentUser) {
135 Set<String> unviewableBlocks = super.getUnviewableBlocks(accountingDocument, accountingLine, newLine, currentUser);
136 unviewableBlocks.remove(OLEPropertyConstants.PERCENT);
137 unviewableBlocks.remove(OLEPropertyConstants.AMOUNT);
138
139 return unviewableBlocks;
140 }
141 }