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"; } }
} if (isset($_POST['account_code'])) { $account_code = $_POST['account_code']; } if (isset($_POST['account_desc_short'])) { $account_desc_short = $_POST['account_desc_short']; } if (isset($_POST['account_desc_long'])) { $account_desc_long = $_POST['account_desc_long']; } //check if account code already exists 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; } $current_level = get_account_level($parent_account_id) + 1; $company_max_account_levels = get_max_coa_levels(); $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++; }