001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.module.endow.document.authorization;
017
018 import java.util.List;
019 import java.util.Set;
020
021 import org.apache.commons.lang.StringUtils;
022 import org.kuali.kfs.module.endow.EndowConstants;
023 import org.kuali.kfs.module.endow.EndowPropertyConstants;
024 import org.kuali.kfs.module.endow.businessobject.FeeClassCode;
025 import org.kuali.kfs.module.endow.businessobject.FeeEndowmentTransactionCode;
026 import org.kuali.kfs.module.endow.businessobject.FeeMethod;
027 import org.kuali.kfs.module.endow.businessobject.FeePaymentType;
028 import org.kuali.kfs.module.endow.businessobject.FeeSecurity;
029 import org.kuali.kfs.module.endow.businessobject.FeeTransaction;
030 import org.kuali.kfs.module.endow.document.service.FeeMethodService;
031 import org.kuali.kfs.module.endow.document.service.impl.FrequencyCodeServiceImpl;
032 import org.kuali.kfs.sys.context.SpringContext;
033 import org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentPresentationControllerBase;
034 import org.kuali.rice.kns.document.MaintenanceDocument;
035 import org.kuali.rice.kns.util.KNSConstants;
036
037 public class FeeMethodDocumentPresentationController extends FinancialSystemMaintenanceDocumentPresentationControllerBase {
038
039 @Override
040 public Set<String> getConditionallyReadOnlyPropertyNames(MaintenanceDocument document) {
041 Set<String> readOnlyPropertyNames = super.getConditionallyReadOnlyPropertyNames(document);
042
043 FeeMethod feeMethod = (FeeMethod) document.getNewMaintainableObject().getBusinessObject();
044
045 String frequencyCode = feeMethod.getFeeFrequencyCode();
046 if (StringUtils.isNotEmpty(frequencyCode)) {
047 FrequencyCodeServiceImpl frequencyCodeServiceImpl = (FrequencyCodeServiceImpl) SpringContext.getBean(FrequencyCodeServiceImpl.class);
048 feeMethod.setFeeNextProcessDate(frequencyCodeServiceImpl.calculateProcessDate(frequencyCode));
049 }
050
051 String feeTypeCode = feeMethod.getFeeTypeCode();
052
053 if (EndowConstants.FeeMethod.FEE_TYPE_CODE_VALUE_FOR_PAYMENTS.equalsIgnoreCase(feeTypeCode)) {
054 // rule# 8: If fee type code is "P" then fee base code should be "I"
055 feeMethod.setFeeBaseCode(EndowConstants.FeeMethod.FEE_BASE_CD_VALUE);
056 readOnlyPropertyNames.add(EndowPropertyConstants.FEE_BASE_CD);
057 }
058
059 String feeMethodCode = feeMethod.getCode();
060 // the frequency code on a Fee Method cannot be changed if that Fee Method is used on at least one KEMID
061 if (KNSConstants.MAINTENANCE_EDIT_ACTION.equals(document.getNewMaintainableObject().getMaintenanceAction()) && StringUtils.isNotEmpty(feeMethodCode)) {
062 FeeMethodService feeMethodService = SpringContext.getBean(FeeMethodService.class);
063 if (feeMethodService.isFeeMethodUsedOnAnyKemid(feeMethodCode)) {
064 readOnlyPropertyNames.add(EndowPropertyConstants.FEE_METHOD_FREQUENCY_CODE);
065 }
066 }
067
068 return readOnlyPropertyNames;
069 }
070
071 /**
072 * @see org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase#getConditionallyReadOnlyPropertyNames(org.kuali.rice.kns.document.MaintenanceDocument)
073 */
074 @Override
075 public Set<String> getConditionallyReadOnlySectionIds(MaintenanceDocument document) {
076 Set<String> readOnlySectionIds = super.getConditionallyReadOnlySectionIds(document);
077
078 // make all the tabs read only to begin with
079 readOnlySectionIds.add(EndowConstants.FeeMethod.CLASS_CODES_TAB_ID);
080 readOnlySectionIds.add(EndowConstants.FeeMethod.SECURITY_TAB_ID);
081 readOnlySectionIds.add(EndowConstants.FeeMethod.PAYMENT_TYPES_TAB_ID);
082 readOnlySectionIds.add(EndowConstants.FeeMethod.TRANSACTION_TYPES_TAB_ID);
083 readOnlySectionIds.add(EndowConstants.FeeMethod.ENDOWMENT_TRANSACTION_CODES_TAB_ID);
084
085 FeeMethod feeMethod = (FeeMethod) document.getNewMaintainableObject().getBusinessObject();
086 FeeMethod oldFeeMethod = (FeeMethod) document.getOldMaintainableObject().getBusinessObject();
087
088 String feeTypeCode = feeMethod.getFeeTypeCode();
089
090 if (StringUtils.isEmpty(feeTypeCode)) {
091 return readOnlySectionIds;
092 }
093
094 // if Fee Type Code is T then valid tabs are Transaction Type and Endowment Transaction Type
095 // read only the rest of the tabs...
096 // also clear the old collection records
097 // also clear the read only tables collection records as they are no longer valid...
098 if (EndowConstants.FeeMethod.FEE_TYPE_CODE_VALUE_FOR_TRANSACTIONS.equalsIgnoreCase(feeTypeCode)) {
099 readOnlySectionIds.remove(EndowConstants.FeeMethod.TRANSACTION_TYPES_TAB_ID);
100 readOnlySectionIds.remove(EndowConstants.FeeMethod.ENDOWMENT_TRANSACTION_CODES_TAB_ID);
101 readOnlySectionIds.remove(EndowConstants.FeeMethod.PAYMENT_TYPES_TAB_ID);
102
103 List<FeeClassCode> feeClassCodes = (List<FeeClassCode>) feeMethod.getFeeClassCodes();
104 feeClassCodes.clear();
105
106 List<FeeClassCode> oldFeeClassCodes = (List<FeeClassCode>) oldFeeMethod.getFeeClassCodes();
107 oldFeeClassCodes.clear();
108
109 List<FeeSecurity> feeSecurity = (List<FeeSecurity>) feeMethod.getFeeSecurity();
110 feeSecurity.clear();
111
112 List<FeeSecurity> olFeeSecurity = (List<FeeSecurity>) oldFeeMethod.getFeeSecurity();
113 olFeeSecurity.clear();
114
115 // List<FeePaymentType> feePaymentTypes = (List<FeePaymentType>) feeMethod.getFeePaymentTypes();
116 // feePaymentTypes.clear();
117
118 // List<FeePaymentType> oldFeePaymentTypes = (List<FeePaymentType>) oldFeeMethod.getFeePaymentTypes();
119 // oldFeePaymentTypes.clear();
120
121 return readOnlySectionIds;
122 }
123
124 // if Fee Type Code is B then tabs Class Codes and Security are valid
125 // read only the rest of the tabs...
126 // also clear the old collection records
127 // also clear the read only tables collection records as they are not longer valid...
128 if (EndowConstants.FeeMethod.FEE_TYPE_CODE_VALUE_FOR_BALANCES.equalsIgnoreCase(feeTypeCode)) {
129 readOnlySectionIds.remove(EndowConstants.FeeMethod.CLASS_CODES_TAB_ID);
130 readOnlySectionIds.remove(EndowConstants.FeeMethod.SECURITY_TAB_ID);
131
132 List<FeePaymentType> feePaymentTypes = (List<FeePaymentType>) feeMethod.getFeePaymentTypes();
133 feePaymentTypes.clear();
134 List<FeePaymentType> oldFeePaymentTypes = (List<FeePaymentType>) oldFeeMethod.getFeePaymentTypes();
135 oldFeePaymentTypes.clear();
136
137 List<FeeTransaction> feeTransactions = (List<FeeTransaction>) feeMethod.getFeeTransactions();
138 feeTransactions.clear();
139 List<FeeTransaction> oldFeeTransactions = (List<FeeTransaction>) oldFeeMethod.getFeeTransactions();
140 oldFeeTransactions.clear();
141
142 List<FeeEndowmentTransactionCode> feeEndowmentTransactionCodes = (List<FeeEndowmentTransactionCode>) feeMethod.getFeeEndowmentTransactionCodes();
143 feeEndowmentTransactionCodes.clear();
144 List<FeeEndowmentTransactionCode> oldFeeEndowmentTransactionCodes = (List<FeeEndowmentTransactionCode>) oldFeeMethod.getFeeEndowmentTransactionCodes();
145 oldFeeEndowmentTransactionCodes.clear();
146
147 return readOnlySectionIds;
148 }
149
150 // if Fee Type Code is P then only Payment Type tab is valid
151 // also clear the read only tables collection records as they are not longer valid...
152 // also clear the old collection records
153 // read only the rest of the tabs...
154 if (EndowConstants.FeeMethod.FEE_TYPE_CODE_VALUE_FOR_PAYMENTS.equalsIgnoreCase(feeTypeCode)) {
155 readOnlySectionIds.remove(EndowConstants.FeeMethod.PAYMENT_TYPES_TAB_ID);
156
157 List<FeeClassCode> feeClassCodes = (List<FeeClassCode>) feeMethod.getFeeClassCodes();
158 feeClassCodes.clear();
159 List<FeeClassCode> oldFeeClassCodes = (List<FeeClassCode>) oldFeeMethod.getFeeClassCodes();
160 oldFeeClassCodes.clear();
161
162 List<FeeSecurity> feeSecurity = (List<FeeSecurity>) feeMethod.getFeeSecurity();
163 feeSecurity.clear();
164 List<FeeSecurity> olFeeSecurity = (List<FeeSecurity>) oldFeeMethod.getFeeSecurity();
165 olFeeSecurity.clear();
166
167 List<FeeTransaction> feeTransactions = (List<FeeTransaction>) feeMethod.getFeeTransactions();
168 feeTransactions.clear();
169 List<FeeTransaction> oldFeeTransactions = (List<FeeTransaction>) oldFeeMethod.getFeeTransactions();
170 oldFeeTransactions.clear();
171
172 List<FeeEndowmentTransactionCode> feeEndowmentTransactionCodes = (List<FeeEndowmentTransactionCode>) feeMethod.getFeeEndowmentTransactionCodes();
173 feeEndowmentTransactionCodes.clear();
174 List<FeeEndowmentTransactionCode> oldFeeEndowmentTransactionCodes = (List<FeeEndowmentTransactionCode>) oldFeeMethod.getFeeEndowmentTransactionCodes();
175 oldFeeEndowmentTransactionCodes.clear();
176
177 return readOnlySectionIds;
178 }
179
180 return readOnlySectionIds;
181 }
182 }