private function _dash_index_messages_closebooks($company_settings_result) { $account_closebooks_check = new Beans_Account_Closebooks_Check($this->_beans_data_auth()); $account_closebooks_check_result = $account_closebooks_check->execute(); if (!$account_closebooks_check_result->success || !$account_closebooks_check_result->data->ready || !$account_closebooks_check_result->data->fye_date) { return array(); } $fye_date = $account_closebooks_check_result->data->fye_date; // This is a really ugly / special use case. $text = ''; $text .= "You have now passed your fiscal year end. You close books\n\t\t\t\t\tafter completing tax preparation and entering end of year\n\t\t\t\t\tadjustments. Click Close Books when you're ready.\n\t\t\t\t"; /* $text .= '<div class="text-bold bump-down-more">Closing Date</div>'; $text .= '<div class="bump-down"><div class="select" style="width: 200px;"><select name="date">'; for( $i = 1; $i < 13; $i++ ) { $d = date("Y-m-t",strtotime($fye_date_next_day.' -'.$i.' Months')); $text .= '<option value='.$d.'>'.$d.'</option>'; } $text .= '</select></div></div>'; */ $account_search = new Beans_Account_Search($this->_beans_data_auth()); $account_search_result = $account_search->execute(); $text .= '<div class="clear"></div>'; $text .= '<div class="text-bold bump-down-more float-left" style="width: 180px;">Fiscal Year End:</div>'; $text .= '<div class="bump-down-more float-left" style="width: 215px;">' . $fye_date . '</div>'; $text .= '<div class="clear"></div>'; $text .= '<div class="text-bold bump-down-more float-left" style="width: 180px;">Equity Accounts to Close:</div>'; $text .= '<div class="bump-down float-left dash-index-close-books-include_accounts" style="width: 215px;"><div class="select" style="width: 200px;"><select class="dash-index-close-books-include_account_ids">'; $text .= '<option value=""> </option>'; foreach ($account_search_result->data->accounts as $account) { if (isset($account->type) and isset($account->type->type) and strtolower($account->type->type) == "equity") { $text .= '<option value="' . $account->id . '" ' . (stripos($account->name, 'owners distribution') !== FALSE ? 'selected="selected"' : '') . ' >' . $account->name . '</option>'; } } $text .= '</select></div></div>'; $text .= '<div class="clear"></div>'; $text .= '<div class="text-bold bump-down-more float-left" style="width: 180px;">Closing Transfer Account:</div>'; $text .= '<div class="bump-down float-left" style="width: 215px;"><div class="select" style="width: 200px;"><select name="transfer_account_id">'; foreach ($account_search_result->data->accounts as $account) { if (isset($account->type) and isset($account->type->type) and strtolower($account->type->type) == "equity") { $text .= '<option value="' . $account->id . '" ' . (stripos($account->name, 'retained') !== FALSE ? 'selected="selected"' : '') . ' >' . $account->name . '</option>'; } } $text .= '</select></div></div>'; $text .= '<div class="clear"></div>'; $text .= '<input type="hidden" name="date" value="' . $fye_date . '">'; $text .= '<input type="hidden" name="include_account_ids" value="">'; return array((object) array('title' => 'Year End - Close Books', 'text' => $text, 'actions' => array((object) array('text' => "Close Books", 'id' => "dash-index-close-books-submit")))); }
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(); }
function action_settings() { // Handle $_POST $data = new stdClass(); $data->settings = new stdClass(); if (count($this->request->post())) { // Update every account - THREE LAWS. $accounts_search = new Beans_Account_Search($this->_beans_data_auth()); $accounts_search_result = $accounts_search->execute(); if ($this->_beans_result_check($accounts_search_result)) { foreach ($accounts_search_result->data->accounts as $account) { if ($account->parent_account_id and !$account->reserved) { $account_update_result = FALSE; if (in_array($account->id, $this->request->post('writeoff_account_ids'))) { $account_update = new Beans_Account_Update($this->_beans_data_auth((object) array('id' => $account->id, 'writeoff' => TRUE))); $account_update_result = $account_update->execute(); } else { $account_update = new Beans_Account_Update($this->_beans_data_auth((object) array('id' => $account->id, 'writeoff' => FALSE))); $account_update_result = $account_update->execute(); } if (!$account_update_result) { $this->_view->send_error_message('An unexpected error occurred.'); } // We can ignore the return value - this will post the necessary error. $this->_beans_result_check($account_update_result); } } $data->settings->company_name = $this->request->post('company_name'); $data->settings->company_email = $this->request->post('company_email'); $data->settings->company_phone = $this->request->post('company_phone'); $data->settings->company_fax = $this->request->post('company_fax'); $data->settings->company_address_address1 = $this->request->post('company_address_address1'); $data->settings->company_address_address2 = $this->request->post('company_address_address2'); $data->settings->company_address_city = $this->request->post('company_address_city'); $data->settings->company_address_state = $this->request->post('company_address_state'); $data->settings->company_address_zip = $this->request->post('company_address_zip'); $data->settings->company_address_country = $this->request->post('company_address_country'); $data->settings->company_fye = $this->request->post('company_fye'); $data->settings->company_currency = $this->request->post('company_currency'); $data->settings->account_default_deposit = $this->request->post('account_default_deposit'); $data->settings->account_default_receivable = $this->request->post('account_default_receivable'); $data->settings->account_default_income = $this->request->post('account_default_income'); $data->settings->account_default_returns = $this->request->post('account_default_returns'); $data->settings->account_default_expense = $this->request->post('account_default_expense'); $data->settings->account_default_order = $this->request->post('account_default_order'); $data->settings->account_default_costofgoods = $this->request->post('account_default_costofgoods'); $data->settings->account_default_payable = $this->request->post('account_default_payable'); if (isset($_FILES['logo']) and $_FILES['logo']['error'] == UPLOAD_ERR_OK) { // Do some magic. $type = strtolower(substr($_FILES['logo']['type'], 1 + strpos($_FILES['logo']['type'], '/'))); if (substr($_FILES['logo']['type'], 0, strpos($_FILES['logo']['type'], '/')) == "image" and ($type == "gif" or $type == "png" or $type == "jpeg" or $type == "jpg")) { $image = FALSE; if ($type == "jpeg" or $type == "jpg") { $image = imagecreatefromjpeg($_FILES['logo']['tmp_name']); } else { if ($type == "gif") { $image = imagecreatefromgif($_FILES['logo']['tmp_name']); } else { if ($type == "png") { $image = imagecreatefrompng($_FILES['logo']['tmp_name']); imagealphablending($image, TRUE); imagesavealpha($image, TRUE); } } } if (!$image) { $this->_view->send_error_message("An error occurred when reading your image. Must be JPG/JPEG, PNG, or GIF."); } else { $width = imagesx($image); $height = imagesy($image); if ($width > 150 or $height > 50) { // Resize $new_width = 150; $new_height = 50; if ($width / $height > $new_width / $new_height) { $new_height = $new_width * ($height / $width); } else { $new_width = $new_height * ($width / $height); } $new_image = imagecreatetruecolor($new_width, $new_height); if (strtolower($type) == "png") { imagealphablending($new_image, false); imagesavealpha($new_image, true); $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127); imagefilledrectangle($new_image, 0, 0, $new_width, $new_height, $transparent); } imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $image = $new_image; } // Fancy trick to avoid writing to the filesystem. $logo_filename = "logo."; ob_start(); if ($type == "jpeg" or $type == "jpg") { $logo_filename .= "jpg"; imagejpeg($image, NULL, 95); } else { if ($type == "gif") { $logo_filename .= "gif"; imagegif($image); } else { if ($type == "png") { $logo_filename .= "png"; imagepng($image, NULL, 9); } } } $image_string = ob_get_contents(); ob_end_clean(); // Ensure "image/jpeg" if it's JPEG. $type = $type == "jpg" ? "jpeg" : $type; $data->settings->company_logo_data = base64_encode($image_string); $data->settings->company_logo_type = 'image/' . $type; // Not really necessary. $data->settings->company_logo_filename = $logo_filename; } } else { $this->_view->send_error_message("That logo was not an acceptable image format. Must be JPG/JPEG, PNG, or GIF."); } } else { if (isset($_FILES['logo']) and $_FILES['logo']['error'] != UPLOAD_ERR_NO_FILE) { $this->_view->send_error_message("An error occurred when receiving that logo. Please try again with a smaller file." . $_FILES['logo']['error']); } } } } $beans_company_update = new Beans_Setup_Company_Update($this->_beans_data_auth($data)); $beans_company_update_result = $beans_company_update->execute(); if ($this->_beans_result_check($beans_company_update_result)) { $this->_view->beans_company_update_result = $beans_company_update_result; } }