+function delete_bank_account($id)
+{
+ $sql = "DELETE FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
+
+ db_query($sql,"could not delete bank account for $id");
+}
+
+
+//---------------------------------------------------------------------------------------------
+
+function get_bank_account($id)
+{
+ $sql = "SELECT * FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
+
+ $result = db_query($sql, "could not retreive bank account for $id");
+
+ return db_fetch($result);
+}
+
+//---------------------------------------------------------------------------------------------
+
+function get_bank_accounts($show_inactive=false)
+{
+ $sql = "SELECT account.*, gl_account.account_name
+ FROM ".TB_PREF."bank_accounts account, ".TB_PREF."chart_master gl_account
+ WHERE account.account_code = gl_account.account_code";
+ if (!$show_inactive) $sql .= " AND !account.inactive";
+ $sql .= " ORDER BY account_code, bank_curr_code";
+
+ return db_query($sql,"could not get bank accounts");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function get_bank_gl_account($id)
+{
+ $sql = "SELECT account_code FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
+
+ $result = db_query($sql, "could not retreive bank account for $id");
+
+ $bank_account = db_fetch($result);
+
+ return $bank_account['account_code'];
+}
+
+//---------------------------------------------------------------------------------------------
+
+function get_bank_charge_account($id)
+{
+ $sql = "SELECT bank_charge_act FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
+
+ $result = db_query($sql, "could not retreive bank account for $id");
+
+ $bank_account = db_fetch($result);
+
+ return $bank_account['bank_charge_act'];
+}
+
+//---------------------------------------------------------------------------------------------
+
+function add_quick_entry($description, $type, $base_amount, $base_desc, $bal_type, $usage)
+{
+ $sql = "INSERT INTO ".TB_PREF."quick_entries (description, type, base_amount, base_desc, bal_type, `usage`)
+ VALUES (".db_escape($description).", ".db_escape($type).", "
+ .db_escape($base_amount).", ".db_escape($base_desc).", ".db_escape($bal_type).", ".db_escape($usage).")";
+
+ db_query($sql, "could not insert quick entry for $description");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function update_quick_entry($selected_id, $description, $type, $base_amount, $base_desc, $bal_type, $usage)
+{
+ $sql = "UPDATE ".TB_PREF."quick_entries SET description = ".db_escape($description).",
+ type=".db_escape($type).", base_amount=".db_escape($base_amount)
+ .", base_desc=".db_escape($base_desc).", bal_type=".db_escape($bal_type).", `usage`=".db_escape($usage)."
+ WHERE id = ".db_escape($selected_id);
+
+ db_query($sql, "could not update quick entry for $selected_id");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function delete_quick_entry($selected_id)
+{
+ $sql = "DELETE FROM ".TB_PREF."quick_entries WHERE id=".db_escape($selected_id);
+
+ db_query($sql,"could not delete quick entry $selected_id");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function add_quick_entry_line($qid, $action, $dest_id, $amount, $dim, $dim2, $memo)
+{
+ $sql = "INSERT INTO ".TB_PREF."quick_entry_lines
+ (qid, action, dest_id, amount, dimension_id, dimension2_id, memo)
+ VALUES
+ (".db_escape($qid).", ".db_escape($action).",".db_escape($dest_id).",
+ ".db_escape($amount).", ".db_escape($dim).", ".db_escape($dim2).", ".db_escape($memo).")";
+
+ db_query($sql, "could not insert quick entry line for $qid");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function update_quick_entry_line($selected_id, $qid, $action, $dest_id, $amount, $dim, $dim2, $memo)
+{
+ $sql = "UPDATE ".TB_PREF."quick_entry_lines SET qid = ".db_escape($qid)
+ .", action=".db_escape($action).",
+ dest_id=".db_escape($dest_id).", amount=".db_escape($amount)
+ .", dimension_id=".db_escape($dim).", dimension2_id=".db_escape($dim2).", memo=".db_escape($memo)."
+ WHERE id = ".db_escape($selected_id);
+
+ db_query($sql, "could not update quick entry line for $selected_id");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function delete_quick_entry_line($selected_id)
+{
+ $sql = "DELETE FROM ".TB_PREF."quick_entry_lines WHERE id=".db_escape($selected_id);
+
+ db_query($sql,"could not delete quick entry line $selected_id");
+}
+//---------------------------------------------------------------------------------------------
+
+
+function has_quick_entries($type=null)
+{
+ $sql = "SELECT id FROM ".TB_PREF."quick_entries";
+ if ($type != null)
+ $sql .= " WHERE type=".db_escape($type);
+
+ $result = db_query($sql, "could not retreive quick entries");
+ return db_num_rows($result) > 0;
+}
+
+function get_quick_entries($type = null)
+{
+ $sql = "SELECT * FROM ".TB_PREF."quick_entries";
+ if ($type != null)
+ $sql .= " WHERE type=".db_escape($type);
+ $sql .= " ORDER BY description";
+
+ return db_query($sql, "could not retreive quick entries");
+}
+
+function get_quick_entry($selected_id)
+{
+ $sql = "SELECT * FROM ".TB_PREF."quick_entries WHERE id=".db_escape($selected_id);
+
+ $result = db_query($sql, "could not retreive quick entry $selected_id");
+
+ return db_fetch($result);
+}
+
+function get_quick_entry_lines($qid)
+{
+ $sql = "SELECT ".TB_PREF."quick_entry_lines.*, ".TB_PREF."chart_master.account_name,
+ ".TB_PREF."tax_types.name as tax_name
+ FROM ".TB_PREF."quick_entry_lines
+ LEFT JOIN ".TB_PREF."chart_master ON
+ ".TB_PREF."quick_entry_lines.dest_id = ".TB_PREF."chart_master.account_code
+ LEFT JOIN ".TB_PREF."tax_types ON
+ ".TB_PREF."quick_entry_lines.dest_id = ".TB_PREF."tax_types.id
+ WHERE
+ qid=".db_escape($qid)." ORDER by id";
+
+ return db_query($sql, "could not retreive quick entries");
+}
+
+function has_quick_entry_lines($qid)
+{
+ $sql = "SELECT id FROM ".TB_PREF."quick_entry_lines WHERE qid=".db_escape($qid);
+
+ $result = db_query($sql, "could not retreive quick entries");
+ return db_num_rows($result) > 0;
+}
+
+//---------------------------------------------------------------------------------------------
+
+function get_quick_entry_line($selected_id)
+{
+ $sql = "SELECT * FROM ".TB_PREF."quick_entry_lines WHERE id=".db_escape($selected_id);
+
+ $result = db_query($sql, "could not retreive quick entry for $selected_id");
+
+ return db_fetch($result);
+}
+
+//---------------------------------------------------------------------------------------------
+
+function get_max_reconciled($date, $bank_account)