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.sql.Date;
019 import java.util.Set;
020
021 import org.kuali.kfs.module.endow.EndowPropertyConstants;
022 import org.kuali.kfs.module.endow.businessobject.PooledFundControl;
023 import org.kuali.kfs.module.endow.businessobject.PooledFundValue;
024 import org.kuali.kfs.module.endow.document.service.KEMService;
025 import org.kuali.kfs.module.endow.document.service.PooledFundControlService;
026 import org.kuali.kfs.sys.context.SpringContext;
027 import org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentPresentationControllerBase;
028 import org.kuali.rice.kns.document.MaintenanceDocument;
029 import org.kuali.rice.kns.util.KNSConstants;
030 import org.kuali.rice.kns.util.ObjectUtils;
031
032 public class PooledFundValueDocumentPresentationController extends FinancialSystemMaintenanceDocumentPresentationControllerBase {
033
034 /**
035 * @see org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase#getConditionallyReadOnlyPropertyNames(org.kuali.rice.kns.document.MaintenanceDocument)
036 */
037 @Override
038 public Set<String> getConditionallyReadOnlyPropertyNames(MaintenanceDocument document) {
039 Set<String> fields = super.getConditionallyReadOnlyPropertyNames(document);
040
041 PooledFundControlService pooledFundControlService = SpringContext.getBean(PooledFundControlService.class);
042
043 // Make Valuation Date gray out (can't edit) when editing a maintenance doc
044 if (KNSConstants.MAINTENANCE_EDIT_ACTION.equals(document.getNewMaintainableObject().getMaintenanceAction())) {
045 fields.add(EndowPropertyConstants.VALUATION_DATE);
046
047 PooledFundValue oldPooledFundValue = (PooledFundValue) document.getOldMaintainableObject().getBusinessObject();
048 String pooledSecurityID = oldPooledFundValue.getPooledSecurityID();
049 PooledFundControl theReferencePFC = pooledFundControlService.getByPrimaryKey(pooledSecurityID);
050 Boolean distributeGainsAndLossesIndicator = theReferencePFC.isDistributeGainsAndLossesIndicator();
051
052 /*
053 * Business Rule:If the date for the distribution is prior to the current system Process Date and the Process Complete
054 * flag is Yes, the distribution amount and date cannot be changed.
055 */
056 KEMService kemService = SpringContext.getBean(KEMService.class);
057 Date currentDate = kemService.getCurrentDate();
058 Date distributIncomeOnDate = oldPooledFundValue.getDistributeIncomeOnDate();
059
060 if (oldPooledFundValue.isIncomeDistributionComplete() && distributIncomeOnDate != null && distributIncomeOnDate.before(currentDate)) {
061 fields.add(EndowPropertyConstants.DISTRIBUTE_INCOME_ON_DATE);
062 fields.add(EndowPropertyConstants.INCOME_DISTRIBUTION_PER_UNIT);
063 }
064 /*
065 * Rule: If xx_ PROC_CMPLT is "Y", the corresponding amount and xx__PROC_ON_DT fields should be read only in edit mode.
066 * Rule: In the pooled fund control, if the Distribute Gains And Losses = "N", LT_GAIN_LOSS / LT_PROC_ON_DT and
067 * ST_GAIN_LOSS / ST_PROC_ON_DT fields in the PooledFundValue should be read only in the edit mode.
068 */
069 if (!distributeGainsAndLossesIndicator || oldPooledFundValue.isLongTermGainLossDistributionComplete()) {
070 fields.add(EndowPropertyConstants.LONG_TERM_GAIN_LOSS_DISTRIBUTION_PER_UNIT);
071 fields.add(EndowPropertyConstants.DISTRIBUTE_LONG_TERM_GAIN_LOSS_ON_DATE);
072 }
073 if (!distributeGainsAndLossesIndicator || oldPooledFundValue.isShortTermGainLossDistributionComplete()) {
074 fields.add(EndowPropertyConstants.SHORT_TERM_GAIN_LOSS_DISTRIBUTION_PER_UNIT);
075 fields.add(EndowPropertyConstants.DISTRIBUTE_SHORT_TERM_GAIN_LOSS_ON_DATE);
076 }
077
078 }
079
080 /*
081 * Rule: In the pooled fund control, if the Distribute Gains And Losses = "N", LT_GAIN_LOSS / LT_PROC_ON_DT and ST_GAIN_LOSS
082 * / ST_PROC_ON_DT fields in the PooledFundValue should be read only in the create/copy mode.
083 */
084 if (KNSConstants.MAINTENANCE_NEW_ACTION.equals(document.getNewMaintainableObject().getMaintenanceAction()) || KNSConstants.MAINTENANCE_COPY_ACTION.equals(document.getNewMaintainableObject().getMaintenanceAction())) {
085 PooledFundValue newPooledFundValue = (PooledFundValue) document.getNewMaintainableObject().getBusinessObject();
086 if (ObjectUtils.isNotNull(newPooledFundValue)) {
087 String pooledSecurityID = newPooledFundValue.getPooledSecurityID();
088 PooledFundControl theReferencePFC = pooledFundControlService.getByPrimaryKey(pooledSecurityID);
089 if (ObjectUtils.isNotNull(theReferencePFC)) {
090 Boolean distributeGainsAndLossesIndicator = theReferencePFC.isDistributeGainsAndLossesIndicator();
091 if (!distributeGainsAndLossesIndicator) {
092 fields.add(EndowPropertyConstants.LONG_TERM_GAIN_LOSS_DISTRIBUTION_PER_UNIT);
093 fields.add(EndowPropertyConstants.DISTRIBUTE_LONG_TERM_GAIN_LOSS_ON_DATE);
094 fields.add(EndowPropertyConstants.SHORT_TERM_GAIN_LOSS_DISTRIBUTION_PER_UNIT);
095 fields.add(EndowPropertyConstants.DISTRIBUTE_SHORT_TERM_GAIN_LOSS_ON_DATE);
096 }
097 }
098 }
099 }
100 return fields;
101 }
102 }