Example #1
0
 /**
  * Adds a few Beans_ calls to each view ( such as company settings ).
  */
 protected function _beans_default_calls()
 {
     // Get Version
     $b = new Beans();
     $this->_view->beansbooks_version = $b->get_version();
     // Only if logged in.
     if (!strlen(Session::instance()->get('auth_uid')) or !strlen(Session::instance()->get('auth_key')) or !strlen(Session::instance()->get('auth_expiration'))) {
         return FALSE;
     }
     $setup_company_list = new Beans_Setup_Company_List($this->_beans_data_auth());
     $setup_company_list_result = $setup_company_list->execute();
     if ($this->_beans_result_check($setup_company_list_result)) {
         $this->_view->setup_company_list_result = $setup_company_list_result;
     }
     $account_chart = new Beans_Account_Chart($this->_beans_data_auth());
     $account_chart_result = $account_chart->execute();
     if ($this->_beans_result_check($account_chart_result)) {
         $this->_view->account_chart_result = $account_chart_result;
     }
     $account_type_search = new Beans_Account_Type_Search($this->_beans_data_auth());
     $account_type_search_result = $account_type_search->execute();
     if ($this->_beans_result_check($account_type_search_result)) {
         $this->_view->account_type_search_result = $account_type_search_result;
     }
     // We don't want to override something set elsewhere - like in Controller_View_Setup -> action_taxes()
     if (!isset($this->_view->tax_search_result)) {
         $tax_search = new Beans_Tax_Search($this->_beans_data_auth((object) array('search_include_hidden' => TRUE)));
         $tax_search_result = $tax_search->execute();
         if ($this->_beans_result_check($tax_search_result)) {
             $this->_view->tax_search_result = $tax_search_result;
         }
     }
 }
Example #2
0
 protected function _execute()
 {
     // ONLY RUN ONCE.  If we have accounts / account_types / roles we quit
     if (ORM::Factory('account')->count_all() != 0 or ORM::Factory('account_type')->count_all() != 0 or ORM::Factory('role')->count_all() != 0) {
         throw new Exception("Database initialization can only be run once.");
     }
     if (!$this->_default_account_set) {
         throw new Exception("No default account set provided.");
     }
     if (!isset($this->_accounts_options[$this->_default_account_set])) {
         throw new Exception("Invalid default account set.  Available options are: " . implode(', ', array_keys($this->_accounts_options)));
     }
     // Roles
     foreach ($this->_default_roles as $default_role) {
         $role = ORM::Factory('role');
         foreach ($default_role as $key => $value) {
             $role->{$key} = $value;
         }
         $role->save();
     }
     // Account Types
     foreach ($this->_default_account_types as $default_account_type) {
         $account_type = ORM::Factory('account_type');
         foreach ($default_account_type as $key => $value) {
             $account_type->{$key} = $value;
         }
         $account_type->save();
     }
     // Accounts
     foreach ($this->_default_accounts as $default_account) {
         $account = ORM::Factory('account');
         foreach ($default_account as $key => $value) {
             $account->{$key} = $value;
         }
         $account->save();
     }
     // Settings
     foreach ($this->_default_settings as $default_setting) {
         $setting = ORM::Factory('setting');
         foreach ($default_setting as $key => $value) {
             $setting->{$key} = $value;
         }
         $setting->save();
     }
     $setting = ORM::Factory('setting')->where('key', '=', 'BEANS_VERSION')->find();
     if (!$setting->loaded()) {
         $setting = ORM::Factory('setting');
     }
     $setting->key = 'BEANS_VERSION';
     $setting->value = $this->_BEANS_VERSION;
     $setting->save();
     // Three laws - let it go.
     // Default Accounts
     // Grab all accounts.
     $beans_account_search = new Beans_Account_Search($this->_beans_data_auth());
     $beans_account_search_result = $beans_account_search->execute();
     $top_level_accounts = array();
     foreach ($beans_account_search_result->data->accounts as $account) {
         if (!$account->parent_account_id) {
             $top_level_accounts[$account->code] = $account->id;
         }
     }
     // Grab all account types.
     $beans_account_type_search = new Beans_Account_Type_Search($this->_beans_data_auth());
     $beans_account_type_search_result = $beans_account_type_search->execute();
     $account_types = array();
     foreach ($beans_account_type_search_result->data->account_types as $account_type) {
         $account_types[$account_type->code] = $account_type->id;
     }
     foreach ($this->_accounts_options[$this->_default_account_set]['accounts'] as $account_code => $default_accounts) {
         $this->_add_sub_accounts((array) $this->_beans_data_auth(), $account_types, $top_level_accounts[$account_code], $default_accounts);
     }
     return (object) array();
 }