function add_coa($account_code, $account_group, $account_desc_short, $account_desc_long, $parent_account_id, $account_type) { $consolidate_only = 0; $activity_account = 0; $has_parent = 0; $has_children = 0; $coa_level = 1; $code_exists = 0; $desc_exists = 0; if ($parent_account_id != 0) { $has_parent = 1; } if ($has_parent == 1) { $coa_level = get_account_level($parent_account_id) + 1; } if ($account_type == "consolidate_only") { $consolidate_only = 1; } if ($account_type == "activity_account") { $activity_account = 1; } if (account_code_exists($account_code)) { $code_exists = 1; } //check if account desc already exists if (account_desc_exists($account_desc_short)) { $desc_exists = 1; } if ($code_exists != 1 and $desc_exists != 1) { $insert = DB::Insert(DB_PREFIX . $_SESSION['co_prefix'] . 'coa', array('account_code' => $account_code, 'account_group' => $account_group, 'account_desc_short' => $account_desc_short, 'account_desc_long' => $account_desc_long, 'activity_account' => $activity_account, 'consolidate_only' => $consolidate_only, 'has_parent' => $has_parent, 'coa_level' => $coa_level, 'has_children' => $has_children, 'parent_account_id' => $parent_account_id, 'last_modified_by' => $_SESSION['user_name'], 'last_modified_on' => getDateTime(date('now'), "mySQL"), 'created_by' => $_SESSION['user_name'], 'created_on' => getDateTime(date('now'), "mySQL"), 'account_status' => 'Active')); $new_coa_id = DB::insertId(); if ($new_coa_id > 0 and $has_parent == 1) { DB::update(DB_PREFIX . $_SESSION['co_prefix'] . 'coa', array('has_children' => 1), "account_id=%s", $parent_account_id); } return $new_coa_id; } else { return "0"; } }
<?php $group_id = ""; $parent_account_id = ""; if (isset($_POST['account_group'])) { $group_id = $_POST['account_group']; } if (isset($_POST['parent_account'])) { $parent_account_id = $_POST['parent_account']; } if (isset($_POST['account_type'])) { $account_type = $_POST['account_type']; } $current_level = get_account_level($parent_account_id) + 1; $company_max_account_levels = DB::queryFirstField("SELECT coa_levels FROM " . DB_PREFIX . "companies where company_id = " . $_SESSION['company_id']); $field = "coa_level_" . $current_level . "_length"; $current_level_length = DB::queryFirstField("SELECT " . $field . " FROM " . DB_PREFIX . "companies where company_id = " . $_SESSION['company_id']); $parent_code = DB::queryFirstField("SELECT account_code FROM " . DB_PREFIX . $_SESSION['co_prefix'] . "coa WHERE account_id =" . $parent_account_id); $company_max_coa_length = 0; $i = 1; while ($i <= $company_max_account_levels) { $col = "coa_level_" . $i . "_length"; $result = DB::queryFirstField("SELECT " . $col . " FROM " . DB_PREFIX . "companies where company_id = " . $_SESSION['company_id']); $company_max_coa_length += $result; $i++; } echo $company_max_coa_length; //echo $parent_code; $parent_level_length = strlen($parent_code); $remaining_length = $company_max_coa_length - $parent_level_length; echo $remaining_length;
function set_cookie_send_mail() { global $cookie, $current_page; // first set if (!isset($cookie->user_agent)) { $cookie->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; } if (!isset($cookie->referer)) { $cookie->referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; } if (!isset($cookie->from_count)) { $cookie->from_count = 1; } // fix:clear cookie and login not create customer if (!isset($cookie->customer_id) && isset($_SESSION['customer_id']) && (int) $_SESSION['customer_id'] > 0) { $cookie->customer_id = (int) $_SESSION['customer_id']; } $cookie->account_level = get_account_level(); $is_iphone = get_iphone(); if ($is_iphone == true) { if (!isset($cookie->send_email)) { // first $cookie->send_email = 1; } } if (!isset($cookie->send_email) && !allow_brower()) { $cookie->send_email = 0; } if (!isset($_SERVER['HTTP_REFERER']) || strstr($_SERVER['HTTP_REFERER'], get_host())) { if ($cookie->send_email == 1) { if ($cookie->customer_id) { // customer existing if (!check_can_send_customer($cookie->customer_id)) { $cookie->send_email = 0; } } } else { $cookie->send_email = 0; } // don't send email } else { $keyword = ''; // confirm from search $is_from_search = get_search_engine($keyword); if ($is_from_search) { // $_SERVER['HTTP_USER_AGENT'] // fix:multi search engine // first come if (!isset($cookie->send_email)) { $cookie->send_email = 1; } else { $cookie->from_count = (int) $cookie->from_count + 1; } // is search update it $cookie->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $cookie->referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $cookie->first_page = $_GET['main_page']; } $cookie->search_keyword = $keyword; } if ($cookie->send_email == 1) { filter_first(); } // FIX: can't send cookie $cookie->write(); }