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.vnd.document.authorization; 017 018 import java.util.Set; 019 020 import org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentPresentationControllerBase; 021 import org.kuali.kfs.vnd.VendorPropertyConstants; 022 import org.kuali.kfs.vnd.businessobject.VendorDetail; 023 import org.kuali.rice.kns.bo.BusinessObject; 024 import org.kuali.rice.kns.document.MaintenanceDocument; 025 import org.kuali.rice.kns.util.ObjectUtils; 026 027 public class VendorDocumentPresentationController extends FinancialSystemMaintenanceDocumentPresentationControllerBase { 028 029 @Override 030 public Set<String> getConditionallyReadOnlySectionIds(MaintenanceDocument document) { 031 Set<String> conditionallyReadOnlySectionIds = super.getConditionallyReadOnlySectionIds(document); 032 VendorDetail vendor = (VendorDetail)document.getNewMaintainableObject().getBusinessObject(); 033 034 if (!vendor.isVendorParentIndicator()) { 035 // make some sections read only, e.g. supplier diversity cause they're on the header 036 conditionallyReadOnlySectionIds.add(VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES); 037 } 038 039 return conditionallyReadOnlySectionIds; 040 } 041 042 @Override 043 public Set<String> getConditionallyReadOnlyPropertyNames(MaintenanceDocument document) { 044 Set<String> conditionallyReadonlyPropertyNames = super.getConditionallyReadOnlyPropertyNames(document); 045 VendorDetail vendor = (VendorDetail)document.getNewMaintainableObject().getBusinessObject(); 046 047 if (vendor.isVendorParentIndicator()) { 048 // Vendor Parent Indicator should be readOnly if the vendor is a parent. 049 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_PARENT_INDICATOR); 050 051 // For existing vendors, don't allow vendor type code to be changed if maint table indicates it shouldn't be changed 052 if (ObjectUtils.isNotNull(vendor.getVendorHeaderGeneratedIdentifier()) && 053 !vendor.getVendorHeader().getVendorType().isVendorTypeChangeAllowedIndicator()) { 054 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_TYPE_CODE); 055 } 056 } 057 058 // If the vendor is not a parent, there are certain fields that should be readOnly 059 else { 060 // All the fields in VendorHeader should be readOnly if the vendor is not a parent. 061 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_TYPE_CODE); 062 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_TAX_NUMBER); 063 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_TAX_TYPE_CODE); 064 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_OWNERSHIP_CODE); 065 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_OWNERSHIP_CATEGORY_CODE); 066 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_FEDERAL_WITHOLDING_TAX_BEGINNING_DATE); 067 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_FEDERAL_WITHOLDING_TAX_END_DATE); 068 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_W9_RECEIVED_INDICATOR); 069 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_W8_BEN_RECEIVED_INDICATOR); 070 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_DEBARRED_INDICATOR); 071 conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_FOREIGN_INDICATOR); 072 } 073 074 return conditionallyReadonlyPropertyNames; 075 } 076 077 @Override 078 public Set<String> getConditionallyHiddenPropertyNames(BusinessObject businessObject) { 079 Set<String> conditionallyHiddenPropertyNames = super.getConditionallyHiddenPropertyNames(businessObject); 080 MaintenanceDocument document = (MaintenanceDocument) businessObject; 081 VendorDetail vendor = (VendorDetail)document.getNewMaintainableObject().getBusinessObject(); 082 // If the vendor is a parent then the vendor parent name should be hidden. 083 if (vendor.isVendorParentIndicator()) { 084 conditionallyHiddenPropertyNames.add(VendorPropertyConstants.VENDOR_PARENT_NAME); 085 } 086 087 return conditionallyHiddenPropertyNames; 088 } 089 }