Fixed item_codes table update on item creation.
[fa-stable.git] / inventory / includes / db / items_db.inc
1 <?php
2
3 function update_item($stock_id, $description, $long_description, $category_id, $tax_type_id,
4         $sales_account, $inventory_account, $cogs_account, $adjustment_account,
5         $assembly_account, $dimension_id, $dimension2_id)
6 {
7         $sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).",
8                 description=".db_escape($description).",
9                 category_id='$category_id',
10                 sales_account='$sales_account',
11                 inventory_account='$inventory_account',
12                 cogs_account='$cogs_account',
13                 adjustment_account='$adjustment_account',
14                 assembly_account='$assembly_account',
15                 dimension_id=$dimension_id,
16                 dimension2_id=$dimension2_id,
17                 tax_type_id=$tax_type_id
18                 WHERE stock_id='$stock_id'";
19
20         db_query($sql, "The item could not be updated");
21
22         update_item_code(-1, $stock_id, $stock_id, $description, $category_id, 1, 0);
23 }
24
25 function add_item($stock_id, $description, $long_description, $category_id, $tax_type_id, $units, $mb_flag,
26         $sales_account, $inventory_account, $cogs_account, $adjustment_account,
27         $assembly_account, $dimension_id, $dimension2_id)
28 {
29         $sql = "INSERT INTO ".TB_PREF."stock_master (stock_id, description, long_description, category_id,
30                 tax_type_id, units, mb_flag, sales_account, inventory_account, cogs_account,
31                 adjustment_account, assembly_account, dimension_id, dimension2_id)
32                 VALUES (".db_escape($stock_id).", ".db_escape($description).", ".db_escape($long_description).",
33                 '$category_id', $tax_type_id, '$units', '$mb_flag',
34                 '$sales_account', '$inventory_account', '$cogs_account',
35                 '$adjustment_account', '$assembly_account', $dimension_id, $dimension2_id)";
36
37         db_query($sql, "The item could not be added");
38
39         $sql = "INSERT INTO ".TB_PREF."loc_stock (loc_code, stock_id)
40                 SELECT ".TB_PREF."locations.loc_code, '$stock_id' FROM ".TB_PREF."locations";
41
42         db_query($sql, "The item locstock could not be added");
43
44         add_item_code($stock_id, $stock_id, $description, $category_id, 1, 0);
45 }
46
47 function delete_item($stock_id)
48 {
49         $sql="DELETE FROM ".TB_PREF."stock_master WHERE stock_id='$stock_id'";
50         db_query($sql, "could not delete stock item");
51
52         /*and cascade deletes in loc_stock */
53         $sql ="DELETE FROM ".TB_PREF."loc_stock WHERE stock_id='$stock_id'";
54         db_query($sql, "could not delete stock item loc stock");
55
56         /*and cascade deletes in purch_data */
57         $sql ="DELETE FROM ".TB_PREF."purch_data WHERE stock_id='$stock_id'";
58         db_query($sql, "could not delete stock item purch data");
59
60         /*and cascade deletes in prices */
61         $sql ="DELETE FROM ".TB_PREF."prices WHERE stock_id='$stock_id'";
62         db_query($sql, "could not delete stock item prices");
63
64         /*and cascade delete the bill of material if any */
65         $sql = "DELETE FROM ".TB_PREF."bom WHERE parent='$stock_id'";
66         db_query($sql, "could not delete stock item bom");
67
68         delete_item_kit($stock_id);
69 }
70
71 function get_item($stock_id)
72 {
73         $sql = "SELECT ".TB_PREF."stock_master.*,".TB_PREF."item_tax_types.name AS tax_type_name
74                 FROM ".TB_PREF."stock_master,".TB_PREF."item_tax_types
75                 WHERE ".TB_PREF."item_tax_types.id=".TB_PREF."stock_master.tax_type_id
76                 AND stock_id='$stock_id'";
77         $result = db_query($sql,"an item could not be retreived");
78
79         return db_fetch($result);
80 }
81
82 function get_items()
83 {
84         $sql = "SELECT * FROM ".TB_PREF."stock_master";
85         return db_query($sql,"items could not be retreived");
86 }
87
88 ?>