function btn_save($id = '') { global $db, $messageStack, $coa_types_list; if ($this->security_id < 2) { $messageStack->add(ERROR_NO_PERMISSION, 'error'); return false; } $this->heading_only = $this->heading_only == 1 ? '1' : '0'; $this->account_inactive = $this->account_inactive == 1 ? '1' : '0'; if ($this->account_type == '') { $messageStack->add(ERROR_ACCT_TYPE_REQ, 'error'); $this->error = true; return false; } if (!$this->primary_acct_id == '') { $result = $db->Execute("select account_type from " . $this->db_table . " where id = '" . $this->primary_acct_id . "'"); if ($result->fields['account_type'] != $this->account_type) { $messageStack->add('set account_type to ' . $coa_types_list[$result->fields['account_type']]['text'] . ' this is the same as the parent', 'error'); $this->error = true; return false; } } if ($this->heading_only == 1 && $this->rowSeq != 0) { // see if this was a non-heading account converted to a heading account $sql = "select max(debit_amount) as debit, max(credit_amount) as credit, max(beginning_balance) as beg_bal \n\t\tfrom " . TABLE_CHART_OF_ACCOUNTS_HISTORY . " where account_id = '" . $this->id . "'"; $result = $db->Execute($sql); if ($result->fields['debit'] != 0 || $result->fields['credit'] != 0 || $result->fields['beg_bal'] != 0) { $messageStack->add(GL_ERROR_CANT_MAKE_HEADING, 'error'); $this->error = true; return false; } } $sql_data_array = array('description' => $this->description, 'heading_only' => $this->heading_only, 'primary_acct_id' => $this->primary_acct_id, 'account_type' => $this->account_type, 'account_inactive' => $this->account_inactive); if ($this->rowSeq != 0) { db_perform($this->db_table, $sql_data_array, 'update', "id = '" . $this->id . "'"); gen_add_audit_log(GL_LOG_CHART_OF_ACCOUNTS . TEXT_UPDATE, $this->id); } else { $sql_data_array['id'] = $this->id; db_perform($this->db_table, $sql_data_array); gen_add_audit_log(GL_LOG_CHART_OF_ACCOUNTS . TEXT_ADD, $this->id); } build_and_check_account_history_records(); // add/modify account to history table return true; }
function btn_save($id = '') { global $db, $messageStack; if ($this->security_id < 2) { $messageStack->add(ERROR_NO_PERMISSION, 'error'); return false; } $description = db_prepare_input($_POST['description']); $heading_only = isset($_POST['heading_only']) ? '1' : '0'; $primary_acct_id = db_prepare_input($_POST['primary_acct_id']); $account_type = db_prepare_input($_POST['account_type']); $account_inactive = isset($_POST['account_inactive']) ? '1' : '0'; if ($account_type == '') { $messageStack->add(ERROR_ACCT_TYPE_REQ, 'error'); return false; } if ($heading_only && $id) { // see if this was a non-heading account converted to a heading account $sql = "select max(debit_amount) as debit, max(credit_amount) as credit, max(beginning_balance) as beg_bal \r\n\t\tfrom " . TABLE_CHART_OF_ACCOUNTS_HISTORY . " where account_id = '" . $id . "'"; $result = $db->Execute($sql); if ($result->fields['debit'] != 0 || $result->fields['credit'] != 0 || $result->fields['beg_bal'] != 0) { $messageStack->add(GL_ERROR_CANT_MAKE_HEADING, 'error'); return false; } } $sql_data_array = array('description' => $description, 'heading_only' => $heading_only, 'primary_acct_id' => $primary_acct_id, 'account_type' => $account_type, 'account_inactive' => $account_inactive); if ($id) { db_perform($this->db_table, $sql_data_array, 'update', "id = '" . $id . "'"); gen_add_audit_log(GL_LOG_CHART_OF_ACCOUNTS . TEXT_UPDATE, $id); } else { $sql_data_array['id'] = db_prepare_input($_POST['id']); db_perform($this->db_table, $sql_data_array); gen_add_audit_log(GL_LOG_CHART_OF_ACCOUNTS . TEXT_ADD, $id); } build_and_check_account_history_records(); // add/modify account to history table return true; }
$fy_array = array('start_date' => $next_start_date); db_perform(TABLE_ACCOUNTING_PERIODS, $fy_array, 'update', 'period = ' . (int) $next_period); $messageStack->add(GL_ERROR_FISCAL_YEAR_SEQ, 'caution'); $fy++; } } gen_add_audit_log(GL_LOG_FY_UPDATE . TEXT_UPDATE); break; case 'new': validate_security($security_level, 2); $result = $db->Execute("select * from " . TABLE_ACCOUNTING_PERIODS . " where period = " . $highest_period); $next_fy = $result->fields['fiscal_year'] + 1; $next_period = $result->fields['period'] + 1; $next_start_date = date('Y-m-d', strtotime($result->fields['end_date']) + 60 * 60 * 24); $highest_period = validate_fiscal_year($next_fy, $next_period, $next_start_date); build_and_check_account_history_records(); // *************** roll account balances into next fiscal year ************************* $glEntry = new journal(); $result = $db->Execute("select id from " . TABLE_CHART_OF_ACCOUNTS); while (!$result->EOF) { $glEntry->affected_accounts[$result->fields['id']] = 1; $result->MoveNext(); } $glEntry->update_chart_history_periods(CURRENT_ACCOUNTING_PERIOD); // from current period through new fiscal year $fy = $next_fy; // set the pointer to open the fiscal year added gen_add_audit_log(GL_LOG_FY_UPDATE . TEXT_ADD); break; case "change": // retrieve the desired period and update the system default values.