public function action_accountcreate() { $account_create = new Beans_Account_Create($this->_beans_data_auth((object) array('parent_account_id' => $this->request->post('parent_account_id'), 'account_type_id' => $this->request->post('account_type_id'), 'name' => $this->request->post('name'), 'code' => substr(strtolower(str_replace(' ', '', $this->request->post('name'))), 0, 16), 'terms' => strlen($this->request->post('terms')) ? $this->request->post('terms') : NULL))); $account_create_result = $account_create->execute(); if (!$account_create_result->success) { return $this->_return_error($this->_beans_result_get_error($account_create_result)); } // Success! $this->_return_object->data->account = $account_create_result->data->account; }
private function _add_sub_accounts($beans_auth_array, $account_types, $parent_account_id, $accounts) { foreach ($accounts as $account) { if (!isset($account['name'])) { die("Fatal error encountered: corrupt internal data and could not create accounts."); } $beans_account_create = new Beans_Account_Create((object) array_merge($beans_auth_array, array('parent_account_id' => $parent_account_id, 'account_type_id' => $account_types[$account['type']], 'reserved' => isset($account['reserved']) ? $account['reserved'] : FALSE, 'name' => $account['name'], 'code' => substr(strtolower(str_replace(' ', '', $account['name'])), 0, 16), 'terms' => isset($account['terms']) ? $account['terms'] : NULL, 'writeoff' => isset($account['writeoff']) and $account['writeoff'] ? TRUE : FALSE))); $beans_account_create_result = $beans_account_create->execute(); if (!$beans_account_create_result->success) { if (Kohana::$is_cli) { echo "Error occurred creating account " . $account['name'] . " (" . $account['type'] . ") : " . $beans_account_create_result->error . "\n"; } } else { if (Kohana::$is_cli) { echo "Created account: " . $beans_account_create_result->data->account->name . "\n"; } if (isset($account['default_setting_account'])) { $settings = new stdClass(); if (is_array($account['default_setting_account'])) { foreach ($account['default_setting_account'] as $setting) { $settings->{$setting} = $beans_account_create_result->data->account->id; } } else { $settings->{$account['default_setting_account']} = $beans_account_create_result->data->account->id; } // Add as setting. $beans_company_update = new Beans_Setup_Company_Update((object) array_merge($beans_auth_array, array('settings' => $settings))); $beans_company_update_result = $beans_company_update->execute(); } if (isset($account['accounts']) and count($account['accounts'])) { $this->_add_sub_accounts($beans_auth_array, $account_types, $beans_account_create_result->data->account->id, $account['accounts']); } } } }