2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 //---------------------------------------------------------------------------------------------
14 function add_bank_account($account_code, $account_type, $bank_account_name, $bank_name, $bank_account_number,
15 $bank_address, $bank_curr_code)
17 $sql = "INSERT INTO ".TB_PREF."bank_accounts (account_code, account_type, bank_account_name, bank_name, bank_account_number, bank_address, bank_curr_code)
18 VALUES (".db_escape($account_code).", $account_type, ".db_escape($bank_account_name).", ".db_escape($bank_name).", ".db_escape($bank_account_number).",
19 ".db_escape($bank_address).", '$bank_curr_code')";
21 db_query($sql, "could not add a bank account for $account_code");
24 //---------------------------------------------------------------------------------------------
26 function update_bank_account($id, $account_code, $account_type, $bank_account_name, $bank_name, $bank_account_number,
27 $bank_address, $bank_curr_code)
29 $sql = "UPDATE ".TB_PREF."bank_accounts SET account_type = $account_type,
30 account_code=".db_escape($account_code).",
31 bank_account_name=".db_escape($bank_account_name).", bank_name=".db_escape($bank_name).",
32 bank_account_number=".db_escape($bank_account_number).", bank_curr_code='$bank_curr_code',
33 bank_address=".db_escape($bank_address)." WHERE id = '$id'";
35 db_query($sql, "could not update bank account for $account_code");
38 //---------------------------------------------------------------------------------------------
40 function delete_bank_account($id)
42 $sql = "DELETE FROM ".TB_PREF."bank_accounts WHERE id='$id'";
44 db_query($sql,"could not delete bank account for $id");
48 //---------------------------------------------------------------------------------------------
50 function get_bank_account($id)
52 $sql = "SELECT * FROM ".TB_PREF."bank_accounts WHERE id='$id'";
54 $result = db_query($sql, "could not retreive bank account for $id");
56 return db_fetch($result);
59 //---------------------------------------------------------------------------------------------
60 function get_bank_gl_account($id)
62 $sql = "SELECT account_code FROM ".TB_PREF."bank_accounts WHERE id='$id'";
64 $result = db_query($sql, "could not retreive bank account for $id");
66 $bank_account = db_fetch($result);
68 return $bank_account['account_code'];
71 //---------------------------------------------------------------------------------------------
73 function add_quick_entry($description, $type, $base_amount, $base_desc)
75 $sql = "INSERT INTO ".TB_PREF."quick_entries (description, type, base_amount, base_desc)
76 VALUES (".db_escape($description).", $type, "
77 .db_escape($base_amount).", ".db_escape($base_desc).")";
79 db_query($sql, "could not insert quick entry for $description");
82 //---------------------------------------------------------------------------------------------
84 function update_quick_entry($selected_id, $description, $type, $base_amount, $base_desc)
86 $sql = "UPDATE ".TB_PREF."quick_entries SET description = ".db_escape($description).",
87 type=$type, base_amount=".db_escape($base_amount).", base_desc=".db_escape($base_desc)."
88 WHERE id = $selected_id";
90 db_query($sql, "could not update quick entry for $selected_id");
93 //---------------------------------------------------------------------------------------------
95 function delete_quick_entry($selected_id)
97 $sql = "DELETE FROM ".TB_PREF."quick_entries WHERE id=$selected_id";
99 db_query($sql,"could not delete quick entry $selected_id");
102 //---------------------------------------------------------------------------------------------
104 function add_quick_entry_line($qid, $action, $dest_id, $amount, $dim, $dim2)
106 $sql = "INSERT INTO ".TB_PREF."quick_entry_lines
107 (qid, action, dest_id, amount, dimension_id, dimension2_id)
109 ($qid, ".db_escape($action).",".db_escape($dest_id).",
110 $amount, $dim, $dim2)";
112 db_query($sql, "could not insert quick entry line for $qid");
115 //---------------------------------------------------------------------------------------------
117 function update_quick_entry_line($selected_id, $qid, $action, $dest_id, $amount, $dim, $dim2)
119 $sql = "UPDATE ".TB_PREF."quick_entry_lines SET qid = $qid, action=".db_escape($action).",
120 dest_id=".db_escape($dest_id).", amount=$amount, dimension_id=$dim, dimension2_id=$dim2
121 WHERE id = $selected_id";
123 db_query($sql, "could not update quick entry line for $selected_id");
126 //---------------------------------------------------------------------------------------------
128 function delete_quick_entry_line($selected_id)
130 $sql = "DELETE FROM ".TB_PREF."quick_entry_lines WHERE id=$selected_id";
132 db_query($sql,"could not delete quick entry line $selected_id");
134 //---------------------------------------------------------------------------------------------
137 function has_quick_entries($type=null)
139 $sql = "SELECT id FROM ".TB_PREF."quick_entries";
141 $sql .= " WHERE type=$type";
143 $result = db_query($sql, "could not retreive quick entries");
144 return db_num_rows($result) > 0;
147 function get_quick_entries($type = null)
149 $sql = "SELECT * FROM ".TB_PREF."quick_entries";
151 $sql .= " WHERE type=$type";
152 $sql .= " ORDER BY description";
154 return db_query($sql, "could not retreive quick entries");
157 function get_quick_entry($selected_id)
159 $sql = "SELECT * FROM ".TB_PREF."quick_entries WHERE id=$selected_id";
161 $result = db_query($sql, "could not retreive quick entry $selected_id");
163 return db_fetch($result);
166 function get_quick_entry_lines($qid)
168 $sql = "SELECT ".TB_PREF."quick_entry_lines.*, ".TB_PREF."chart_master.account_name,
169 ".TB_PREF."item_tax_types.name as tax_name
170 FROM ".TB_PREF."quick_entry_lines
171 LEFT JOIN ".TB_PREF."chart_master ON
172 ".TB_PREF."quick_entry_lines.dest_id = ".TB_PREF."chart_master.account_code
173 LEFT JOIN ".TB_PREF."item_tax_types ON
174 ".TB_PREF."quick_entry_lines.dest_id = ".TB_PREF."item_tax_types.id
179 return db_query($sql, "could not retreive quick entries");
182 function has_quick_entry_lines($qid)
184 $sql = "SELECT id FROM ".TB_PREF."quick_entry_lines WHERE qid=$qid";
186 $result = db_query($sql, "could not retreive quick entries");
187 return db_num_rows($result) > 0;
190 //---------------------------------------------------------------------------------------------
192 function get_quick_entry_line($selected_id)
194 $sql = "SELECT * FROM ".TB_PREF."quick_entry_lines WHERE id=$selected_id";
196 $result = db_query($sql, "could not retreive quick entry for $selected_id");
198 return db_fetch($result);
201 //---------------------------------------------------------------------------------------------