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 function add_item_category($description, $tax_type_id, $sales_account,
13 $cogs_account, $inventory_account, $adjustment_account, $wip_account,
14 $units, $mb_flag, $dim1, $dim2, $no_sale, $no_purchase, $vat_category)
16 begin_transaction(__FUNCTION__, func_get_args());
17 $sql = "INSERT INTO ".TB_PREF."stock_category (description, dflt_tax_type,
18 dflt_units, dflt_mb_flag, dflt_sales_act, dflt_cogs_act,
19 dflt_inventory_act, dflt_adjustment_act, dflt_wip_act,
20 dflt_dim1, dflt_dim2, dflt_no_sale, dflt_no_purchase, vat_category)
22 .db_escape($description).","
23 .db_escape($tax_type_id).","
24 .db_escape($units).","
25 .db_escape($mb_flag).","
26 .db_escape($sales_account).","
27 .db_escape($cogs_account).","
28 .db_escape($inventory_account).","
29 .db_escape($adjustment_account).","
30 .db_escape($wip_account).","
33 .db_escape($no_sale).","
34 .db_escape($no_purchase).","
35 .db_escape($vat_category).")";
37 db_query($sql,"an item category could not be added");
41 function update_item_category($id, $description, $tax_type_id,
42 $sales_account, $cogs_account, $inventory_account, $adjustment_account,
43 $wip_account, $units, $mb_flag, $dim1, $dim2, $no_sale, $no_purchase, $vat_category)
46 begin_transaction(__FUNCTION__, func_get_args());
47 $sql = "UPDATE ".TB_PREF."stock_category SET "
48 ."description = ".db_escape($description).","
49 ."dflt_tax_type = ".db_escape($tax_type_id).","
50 ."dflt_units = ".db_escape($units).","
51 ."dflt_mb_flag = ".db_escape($mb_flag).","
52 ."dflt_sales_act = ".db_escape($sales_account).","
53 ."dflt_cogs_act = ".db_escape($cogs_account).","
54 ."dflt_inventory_act = ".db_escape($inventory_account).","
55 ."dflt_adjustment_act = ".db_escape($adjustment_account).","
56 ."dflt_wip_act = ".db_escape($wip_account).","
57 ."dflt_dim1 = ".db_escape($dim1).","
58 ."dflt_dim2 = ".db_escape($dim2).","
59 ."dflt_no_sale = ".db_escape($no_sale).","
60 ."dflt_no_purchase = ".db_escape($no_purchase).","
61 ."vat_category = ".db_escape($vat_category)
62 ."WHERE category_id = ".db_escape($id);
64 db_query($sql,"an item category could not be updated");
68 function delete_item_category($id)
70 begin_transaction(__FUNCTION__, func_get_args());
71 $sql="DELETE FROM ".TB_PREF."stock_category WHERE category_id=".db_escape($id);
73 db_query($sql,"an item category could not be deleted");
77 function get_item_categories($show_inactive, $fixed_asset=false)
79 $sql = "SELECT c.*, t.name as tax_name FROM ".TB_PREF."stock_category c, "
80 .TB_PREF."item_tax_types t WHERE c.dflt_tax_type=t.id";
82 $sql .= " AND !c.inactive";
84 $sql .= " AND c.dflt_mb_flag='F'";
86 $sql .= " AND c.dflt_mb_flag!='F'";
88 $sql .= " ORDER by description";
90 return db_query($sql, "could not get stock categories");
93 function get_item_category($id)
95 $sql="SELECT * FROM ".TB_PREF."stock_category WHERE category_id=".db_escape($id);
97 $result = db_query($sql,"an item category could not be retrieved");
99 return db_fetch($result);
102 function get_category_name($id)
104 $sql = "SELECT description FROM ".TB_PREF."stock_category WHERE category_id=".db_escape($id);
106 $result = db_query($sql, "could not get sales type");
108 $row = db_fetch_row($result);