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.Set;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.kuali.kfs.module.endow.EndowConstants;
022 import org.kuali.kfs.module.endow.EndowPropertyConstants;
023 import org.kuali.kfs.module.endow.businessobject.ClassCode;
024 import org.kuali.kfs.module.endow.businessobject.Security;
025 import org.kuali.kfs.module.endow.document.service.impl.FrequencyCodeServiceImpl;
026 import org.kuali.kfs.sys.context.SpringContext;
027 import org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentPresentationControllerBase;
028 import org.kuali.rice.kew.util.KEWConstants;
029 import org.kuali.rice.kns.bo.BusinessObject;
030 import org.kuali.rice.kns.document.MaintenanceDocument;
031 import org.kuali.rice.kns.util.KNSConstants;
032
033 public class SecurityDocumentPresentationController extends FinancialSystemMaintenanceDocumentPresentationControllerBase {
034
035 /**
036 * @see org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase#getConditionallyHiddenPropertyNames(org.kuali.rice.kns.bo.BusinessObject)
037 */
038 @Override
039 public Set<String> getConditionallyHiddenPropertyNames(BusinessObject businessObject) {
040 Set<String> fields = super.getConditionallyHiddenPropertyNames(businessObject);
041 MaintenanceDocument document = (MaintenanceDocument) businessObject;
042 Security security = (Security) document.getNewMaintainableObject().getBusinessObject();
043 String incomePayFrequencyCode = security.getIncomePayFrequency();
044
045 if (StringUtils.isNotEmpty(incomePayFrequencyCode)) {
046 FrequencyCodeServiceImpl frequencyCodeServiceImpl = (FrequencyCodeServiceImpl) SpringContext.getBean(FrequencyCodeServiceImpl.class);
047 security.setIncomeNextPayDate(frequencyCodeServiceImpl.calculateProcessDate(incomePayFrequencyCode));
048 }
049 //KFSMI-6674
050 //If SEC_INC_PAY_FREQ entered then the SEC_INC_NEXT_PAY_DT is
051 //automatically calculated.
052 //if class code type is stocks and SEC_DIV_PAY_DT is entered then
053 //copy the date value to SEC_INC_NEXT_PAY_DT.
054 //We do not want to overwrite the date if it already exists.
055 if (EndowConstants.ClassCodeTypes.STOCKS.equalsIgnoreCase(security.getClassCode().getClassCodeType())) {
056 if (security.getDividendPayDate() != null) {
057 security.setIncomeNextPayDate(security.getDividendPayDate());
058 }
059 }
060
061 // when we create or copy a new Security, only certain fields are displayed; the following code is used to hide the unwanted
062 // fields
063 if (KNSConstants.MAINTENANCE_NEW_ACTION.equals(document.getNewMaintainableObject().getMaintenanceAction()) || KNSConstants.MAINTENANCE_COPY_ACTION.equals(document.getNewMaintainableObject().getMaintenanceAction())) {
064
065 // the security ID hidded on creation and a dummy field is used for user input (userEnteredSecurityIDprefix)
066 String routeStatus = document.getDocumentHeader().getWorkflowDocument().getRouteHeader().getDocRouteStatus();
067 if (KEWConstants.ROUTE_HEADER_INITIATED_CD.equalsIgnoreCase(routeStatus) || KEWConstants.ROUTE_HEADER_SAVED_CD.equalsIgnoreCase(routeStatus)) {
068 fields.add(EndowPropertyConstants.SECURITY_ID);
069 }
070 else {
071 fields.add(EndowPropertyConstants.SECURITY_USER_ENTERED_ID_PREFIX);
072 }
073
074 fields.add(EndowPropertyConstants.SECURITY_UNIT_VALUE);
075 fields.add(EndowPropertyConstants.SECURITY_UNITS_HELD);
076 fields.add(EndowPropertyConstants.SECURITY_VALUATION_DATE);
077 fields.add(EndowPropertyConstants.SECURITY_UNIT_VALUE_SOURCE);
078 fields.add(EndowPropertyConstants.SECURITY_PREVIOUS_UNIT_VALUE);
079 fields.add(EndowPropertyConstants.SECURITY_PREVIOUS_UNIT_VALUE_DATE);
080 fields.add(EndowPropertyConstants.SECURITY_CARRY_VALUE);
081 fields.add(EndowPropertyConstants.SECURITY_MARKET_VALUE);
082 fields.add(EndowPropertyConstants.SECURITY_LAST_TRANSACTION_DATE);
083 fields.add(EndowPropertyConstants.SECURITY_INCOME_NEXT_PAY_DATE);
084 fields.add(EndowPropertyConstants.SECURITY_INCOME_CHANGE_DATE);
085 fields.add(EndowPropertyConstants.SECURITY_DIVIDEND_RECORD_DATE);
086 fields.add(EndowPropertyConstants.SECURITY_EX_DIVIDEND_DATE);
087 fields.add(EndowPropertyConstants.SECURITY_DIVIDEND_PAY_DATE);
088 fields.add(EndowPropertyConstants.SECURITY_DIVIDEND_AMOUNT);
089 fields.add(EndowPropertyConstants.REPORTING_GROUP_DESC);
090 fields.add(EndowPropertyConstants.ACCRUAL_METHOD_DESC);
091 fields.add(EndowPropertyConstants.SECURITY_NEXT_FISCAL_YEAR_DISTRIBUTION_AMOUNT);
092 fields.add(EndowPropertyConstants.SECURITY_VALUE_BY_MARKET);
093
094 }
095 // if action is not new or copy the userEnteredSecurityIDprefix shall not be displayed
096 else {
097 fields.add(EndowPropertyConstants.SECURITY_USER_ENTERED_ID_PREFIX);
098 }
099
100 return fields;
101 }
102
103 /**
104 * @see org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase#getConditionallyReadOnlyPropertyNames(org.kuali.rice.kns.document.MaintenanceDocument)
105 */
106 @Override
107 public Set<String> getConditionallyReadOnlyPropertyNames(MaintenanceDocument document) {
108
109 Set<String> fields = super.getConditionallyReadOnlyPropertyNames(document);
110 Security security = (Security) document.getNewMaintainableObject().getBusinessObject();
111 ClassCode classCode = security.getClassCode();
112
113 // If the class code type = "P" -- pooled investment:
114 // - the unit value and value date in the security can't be modified through editing that maintenance doc
115 // - END_SEC_T: SEC_RT should NOT be modified through edit that maintenance doc
116 if (classCode != null && EndowConstants.ClassCodeTypes.POOLED_INVESTMENT.equalsIgnoreCase(classCode.getClassCodeType()) && KNSConstants.MAINTENANCE_EDIT_ACTION.equals(document.getNewMaintainableObject().getMaintenanceAction())) {
117 fields.add(EndowPropertyConstants.SECURITY_UNIT_VALUE);
118 fields.add(EndowPropertyConstants.SECURITY_MARKET_VALUE);
119 fields.add(EndowPropertyConstants.SECURITY_VALUATION_DATE);
120 fields.add(EndowPropertyConstants.SECURITY_INCOME_RATE);
121 }
122
123 // The default unit value for a new security is 1 EXCEPT for Liabilities (CLS_CD_T: CLS_CD_TYP = L) which will be negative 1
124 // (-1). The unit value for these securities must remain -1. The unit value for these securities cannot be edited.
125 if (classCode != null && EndowConstants.ClassCodeTypes.LIABILITY.equalsIgnoreCase(classCode.getClassCodeType())) {
126 fields.add(EndowPropertyConstants.SECURITY_UNIT_VALUE);
127 }
128
129 return fields;
130 }
131
132 }