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.ar.document.validation.impl;
017    
018    import org.kuali.kfs.module.ar.ArConstants;
019    import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceItemCode;
020    import org.kuali.kfs.module.ar.businessobject.OrganizationAccountingDefault;
021    import org.kuali.kfs.sys.businessobject.ChartOrgHolder;
022    import org.kuali.kfs.sys.context.SpringContext;
023    import org.kuali.kfs.sys.service.FinancialSystemUserService;
024    import org.kuali.rice.kim.bo.Person;
025    import org.kuali.rice.kns.document.Document;
026    import org.kuali.rice.kns.document.MaintenanceDocument;
027    import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
028    import org.kuali.rice.kns.util.GlobalVariables;
029    
030    /**
031     * This class is used to ensure that default values are set accordingly if blank
032     */
033    public class CustomerInvoiceItemCodePreRule extends PromptBeforeValidationBase { 
034    
035        @Override
036        public boolean doPrompts(Document document) {
037    
038            MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
039            CustomerInvoiceItemCode invoiceItemCode = (CustomerInvoiceItemCode) maintenanceDocument.getNewMaintainableObject().getBusinessObject();
040        
041            Person user = GlobalVariables.getUserSession().getPerson();
042            ChartOrgHolder chartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(user, ArConstants.AR_NAMESPACE_CODE);
043            
044            invoiceItemCode.setChartOfAccountsCode( chartOrg.getChartOfAccountsCode() );
045            invoiceItemCode.setOrganizationCode( chartOrg.getOrganizationCode() );
046            
047            OrganizationAccountingDefault orgAccDefault = new OrganizationAccountingDefault();
048            invoiceItemCode.setChartOfAccounts(orgAccDefault.getChartOfAccounts());
049            
050            
051            
052            return true;
053        }
054    }
055