View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.ar.document.authorization;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Set;
24  
25  import org.kuali.kfs.module.ar.ArConstants;
26  import org.kuali.kfs.module.ar.ArPropertyConstants;
27  import org.kuali.kfs.module.ar.businessobject.OrganizationOptions;
28  import org.kuali.kfs.sys.KFSConstants;
29  import org.kuali.kfs.sys.KFSPropertyConstants;
30  import org.kuali.kfs.sys.context.SpringContext;
31  import org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentPresentationControllerBase;
32  import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
33  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
34  import org.kuali.rice.kim.api.role.RoleService;
35  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36  import org.kuali.rice.kns.document.MaintenanceDocument;
37  import org.kuali.rice.krad.util.GlobalVariables;
38  
39  public class OrganizationOptionsPresentationController extends FinancialSystemMaintenanceDocumentPresentationControllerBase {
40  
41      protected static final String ACCOUNTS_RECEIVABLE_MANAGER_ROLE_NAME = "Accounts Receivable Manager";
42  
43      @Override
44      public Set<String> getConditionallyReadOnlySectionIds(MaintenanceDocument document) {
45          Set<String> readOnlySectionIds = super.getConditionallyReadOnlySectionIds(document);
46          setRemitToAddressSectionEditable(readOnlySectionIds);
47          return readOnlySectionIds;
48      }
49  
50      @Override
51      public Set<String> getConditionallyReadOnlyPropertyNames(MaintenanceDocument document) {
52          Set<String> readOnlyPropertyNames = super.getConditionallyReadOnlyPropertyNames(document);
53          setRemitToNameEditable(readOnlyPropertyNames);
54          setOrgPostalZipCodeEditable(readOnlyPropertyNames);
55          setBillingOrgFieldsEditable(readOnlyPropertyNames, document);
56          setProcessingOrgFieldsEditable(readOnlyPropertyNames, document);
57          return readOnlyPropertyNames;
58      }
59  
60      /**
61       *
62       * Billing Chart/Org are always read-only on an edit.  Always.
63       *
64       * They are editable on an Add, but only if KIM lets you in on an Add,
65       * but thats handled elsewhere.
66       *
67       * @param readOnlyPropertyNames
68       * @param document
69       */
70      protected void setBillingOrgFieldsEditable(Set<String> readOnlyPropertyNames, MaintenanceDocument document) {
71          if (document.isEdit()) {
72              readOnlyPropertyNames.add(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE);
73              readOnlyPropertyNames.add(KFSPropertyConstants.ORGANIZATION_CODE);
74          }
75      }
76  
77      /**
78       * Sets the processing Chart/Org code editable
79       *
80       * @param readOnlyPropertyNames
81       * @param document
82       */
83      protected void setProcessingOrgFieldsEditable(Set<String> readOnlyPropertyNames, MaintenanceDocument document) {
84  
85          if (document.isEdit()) {
86  
87              RoleService rms = KimApiServiceLocator.getRoleService();
88  
89              String principalId = GlobalVariables.getUserSession().getPrincipalId();
90  
91              List<String> roleIds = new ArrayList<String>();
92              roleIds.add(rms.getRoleIdByNamespaceCodeAndName(KFSConstants.CoreModuleNamespaces.KFS, ACCOUNTS_RECEIVABLE_MANAGER_ROLE_NAME));
93  
94              // editable only for the AR Manager role
95              if (!rms.principalHasRole(principalId, roleIds, null)) {
96                  readOnlyPropertyNames.add(KFSPropertyConstants.PROCESSING_CHART_OF_ACCT_CD);
97                  readOnlyPropertyNames.add(KFSPropertyConstants.PROCESSING_ORGANIZATION_CODE);
98              }
99          }
100     }
101 
102     /**
103      *
104      * Sets the Remit-To Name (ie, OrgCheckPayableToName) to read only if thats how the system parameters are
105      * configured, otherwise leave it read/write.
106      *
107      * @param readOnlyPropertyNames
108      */
109     protected void setRemitToNameEditable(Set<String> readOnlyPropertyNames) {
110         ParameterService parameterService = SpringContext.getBean(ParameterService.class);
111         if ( parameterService.getParameterValueAsBoolean(OrganizationOptions.class, ArConstants.REMIT_TO_NAME_EDITABLE_IND, Boolean.TRUE) ) { // defaulting to true to preserve prior behavior
112             readOnlyPropertyNames.add(ArPropertyConstants.OrganizationOptionsFields.ORGANIZATION_CHECK_PAYABLE_TO_NAME);
113         }
114     }
115 
116     /**
117      *
118      * Sets the OrgPostalZipCode to readonly if thats what the system parameters say, otherwise leave it
119      * read/write.
120      *
121      * @param readOnlyPropertyNames
122      */
123     protected void setOrgPostalZipCodeEditable(Set<String> readOnlyPropertyNames) {
124         ParameterService service = SpringContext.getBean(ParameterService.class);
125         if (!service.getParameterValueAsBoolean(KfsParameterConstants.ACCOUNTS_RECEIVABLE_DOCUMENT.class, ArConstants.ENABLE_SALES_TAX_IND, Boolean.FALSE ) ){
126             readOnlyPropertyNames.add(ArPropertyConstants.OrganizationOptionsFields.ORGANIZATION_POSTAL_ZIP_CODE);
127         }
128     }
129 
130     /**
131      *
132      * Sets the whole Remit-To Address section to read-only if thats what the system parameter says, otherwise leave
133      * it read/wrtie.
134      *
135      * @param readOnlySectionIds
136      */
137     protected void setRemitToAddressSectionEditable(Set<String> readOnlySectionIds) {
138         ParameterService service = SpringContext.getBean(ParameterService.class);
139         String addressEditable = service.getParameterValueAsString(OrganizationOptions.class, ArConstants.REMIT_TO_ADDRESS_EDITABLE_IND);
140         if ("N".equalsIgnoreCase(addressEditable)) {
141             readOnlySectionIds.add(ArConstants.OrganizationOptionsSections.EDIT_ORGANIZATION_REMIT_TO_ADDRESS);
142         }
143     }
144 
145 }