1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.document.authorization;
17
18 import java.util.Set;
19
20 import org.joda.time.DateTime;
21 import org.kuali.ole.sys.OLEConstants;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.ole.sys.document.AmountTotaling;
24 import org.kuali.ole.sys.document.Correctable;
25 import org.kuali.ole.sys.document.FinancialSystemTransactionalDocument;
26 import org.kuali.ole.sys.document.LedgerPostingDocument;
27 import org.kuali.ole.sys.document.datadictionary.FinancialSystemTransactionalDocumentEntry;
28 import org.kuali.ole.sys.service.BankService;
29 import org.kuali.ole.sys.service.UniversityDateService;
30 import org.kuali.ole.sys.service.impl.OleParameterConstants;
31 import org.kuali.rice.core.api.parameter.ParameterEvaluator;
32 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
33 import org.kuali.rice.kew.api.WorkflowDocument;
34 import org.kuali.rice.kns.document.authorization.TransactionalDocumentPresentationControllerBase;
35 import org.kuali.rice.kns.service.DataDictionaryService;
36 import org.kuali.rice.krad.datadictionary.DocumentEntry;
37 import org.kuali.rice.krad.document.Document;
38 import org.springframework.util.ObjectUtils;
39
40
41
42
43 public class FinancialSystemTransactionalDocumentPresentationControllerBase extends TransactionalDocumentPresentationControllerBase implements FinancialSystemTransactionalDocumentPresentationController {
44 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(FinancialSystemTransactionalDocumentPresentationControllerBase.class);
45
46 private static ParameterEvaluatorService parameterEvaluatorService;
47 private static BankService bankService;
48 private static UniversityDateService universityDateService;
49 private static DataDictionaryService dataDictionaryService;
50
51
52
53
54
55
56
57 @Override
58 public boolean canErrorCorrect(FinancialSystemTransactionalDocument document) {
59 if (!(document instanceof Correctable)) {
60 return false;
61 }
62
63 if (!this.canCopy(document)) {
64 return false;
65 }
66 DocumentEntry documentEntry = getDataDictionaryService().getDataDictionary().getDocumentEntry(document.getClass().getName());
67
68
69 if ( !(documentEntry instanceof FinancialSystemTransactionalDocumentEntry)
70 || !((FinancialSystemTransactionalDocumentEntry)documentEntry).getAllowsErrorCorrection()) {
71 return false;
72 }
73
74 if (document.getFinancialSystemDocumentHeader().getCorrectedByDocumentId() != null) {
75 return false;
76 }
77
78 if (document.getFinancialSystemDocumentHeader().getFinancialDocumentInErrorNumber() != null) {
79 return false;
80 }
81
82 WorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
83 if (!isApprovalDateWithinFiscalYear(workflowDocument)) {
84 return false;
85 }
86
87 return workflowDocument.isApproved();
88 }
89
90 protected boolean isApprovalDateWithinFiscalYear(WorkflowDocument workflowDocument) {
91 if ( workflowDocument != null ) {
92 DateTime approvalDate = workflowDocument.getDateApproved();
93 if ( approvalDate != null ) {
94
95 Integer approvalYear = getUniversityDateService().getFiscalYear(approvalDate.toDate());
96 Integer currentFiscalYear = getUniversityDateService().getCurrentFiscalYear();
97 return ObjectUtils.nullSafeEquals(currentFiscalYear, approvalYear);
98 }
99 }
100 return true;
101 }
102
103
104
105
106 @Override
107 public Set<String> getDocumentActions(Document document) {
108 Set<String> documentActions = super.getDocumentActions(document);
109
110 if (document instanceof FinancialSystemTransactionalDocument) {
111 if (canErrorCorrect((FinancialSystemTransactionalDocument) document)) {
112 documentActions.add(OLEConstants.KFS_ACTION_CAN_ERROR_CORRECT);
113 }
114
115 if (canHaveBankEntry(document)) {
116 documentActions.add(OLEConstants.KFS_ACTION_CAN_EDIT_BANK);
117 }
118 }
119
120
121
122 if (document instanceof LedgerPostingDocument) {
123
124
125 boolean accountingPeriodEnabled = getParameterService().getParameterValueAsBoolean(OLEConstants.CoreModuleNamespaces.OLE, OleParameterConstants.YEAR_END_ACCOUNTING_PERIOD_PARAMETER_NAMES.DETAIL_PARAMETER_TYPE, OleParameterConstants.YEAR_END_ACCOUNTING_PERIOD_PARAMETER_NAMES.ENABLE_FISCAL_PERIOD_SELECTION_IND, false);
126 if ( accountingPeriodEnabled) {
127
128 String docType = document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
129
130 ParameterEvaluator evaluator = getParameterEvaluatorService().getParameterEvaluator(OLEConstants.CoreModuleNamespaces.OLE, OleParameterConstants.YEAR_END_ACCOUNTING_PERIOD_PARAMETER_NAMES.DETAIL_PARAMETER_TYPE, OleParameterConstants.YEAR_END_ACCOUNTING_PERIOD_PARAMETER_NAMES.FISCAL_PERIOD_SELECTION_DOCUMENT_TYPES, docType);
131 if (evaluator.evaluationSucceeds()) {
132 documentActions.add(OLEConstants.YEAR_END_ACCOUNTING_PERIOD_VIEW_DOCUMENT_ACTION);
133 }
134 }
135 }
136
137
138
139 return documentActions;
140 }
141
142
143
144
145 @Override
146 public Set<String> getEditModes(Document document) {
147 Set<String> editModes = super.getEditModes(document);
148
149 if (document instanceof AmountTotaling) {
150 editModes.add(OLEConstants.AMOUNT_TOTALING_EDITING_MODE);
151 }
152
153 if (this.canHaveBankEntry(document)) {
154 editModes.add(OLEConstants.BANK_ENTRY_VIEWABLE_EDITING_MODE);
155 }
156
157 return editModes;
158 }
159
160
161 protected boolean canHaveBankEntry(Document document) {
162 boolean bankSpecificationEnabled = getBankService().isBankSpecificationEnabled();
163
164 if (bankSpecificationEnabled) {
165 String documentTypeName = document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
166
167 return getBankService().isBankSpecificationEnabledForDocument(document.getClass());
168 }
169
170 return false;
171 }
172
173 protected ParameterEvaluatorService getParameterEvaluatorService() {
174 if (parameterEvaluatorService == null) {
175 parameterEvaluatorService = SpringContext.getBean(ParameterEvaluatorService.class);
176 }
177 return parameterEvaluatorService;
178 }
179
180 protected BankService getBankService() {
181 if (bankService == null) {
182 bankService = SpringContext.getBean(BankService.class);
183 }
184 return bankService;
185 }
186
187 public DataDictionaryService getDataDictionaryService() {
188 if (dataDictionaryService == null) {
189 dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
190 }
191 return dataDictionaryService;
192 }
193
194 public UniversityDateService getUniversityDateService() {
195 if (universityDateService == null) {
196 universityDateService = SpringContext.getBean(UniversityDateService.class);
197 }
198 return universityDateService;
199 }
200 }