d6fb61cdf90c63091f65860c863f5d3c129bd39d
[fa-stable.git] / purchasing / includes / db / invoice_items_db.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 //-------------------------------------------------------------------------------------------------------------
13
14 function add_supp_invoice_item($supp_trans_type, $supp_trans_no, $stock_id, $description,
15         $gl_code, $unit_price, $unit_tax, $quantity, $grn_item_id, $po_detail_item_id, $memo_,
16         $err_msg="")
17 {
18         $sql = "INSERT INTO ".TB_PREF."supp_invoice_items (supp_trans_type, supp_trans_no, stock_id, description, gl_code, unit_price, unit_tax, quantity,
19                 grn_item_id, po_detail_item_id, memo_) ";
20         $sql .= "VALUES ($supp_trans_type, $supp_trans_no, ".db_escape($stock_id).
21         ", ".db_escape($description).", ".db_escape($gl_code).", $unit_price, $unit_tax, $quantity,
22                 $grn_item_id, $po_detail_item_id, ".db_escape($memo_).")";
23
24         if ($err_msg == "")
25                 $err_msg = "Cannot insert a supplier transaction detail record";
26
27         db_query($sql, $err_msg);
28
29         return db_insert_id();
30 }
31
32 //-------------------------------------------------------------------------------------------------------------
33
34 function add_supp_invoice_gl_item($supp_trans_type, $supp_trans_no, $gl_code, $amount, $memo_, $err_msg="")
35 {
36         return add_supp_invoice_item($supp_trans_type, $supp_trans_no,  "", "", $gl_code, $amount,
37                 0, 0, /*$grn_item_id*/0, /*$po_detail_item_id*/0, $memo_, $err_msg);
38 }
39
40
41 //----------------------------------------------------------------------------------------
42
43 function get_supp_invoice_items($supp_trans_type, $supp_trans_no)
44 {
45         $sql = "SELECT *, unit_price AS FullUnitPrice FROM ".TB_PREF."supp_invoice_items
46                 WHERE supp_trans_type = $supp_trans_type
47                 AND supp_trans_no = $supp_trans_no ORDER BY id";
48         return db_query($sql, "Cannot retreive supplier transaction detail records");
49 }
50
51 //----------------------------------------------------------------------------------------
52
53 function void_supp_invoice_items($type, $type_no)
54 {
55         $sql = "UPDATE ".TB_PREF."supp_invoice_items SET quantity=0, unit_price=0
56                 WHERE supp_trans_type = $type AND supp_trans_no=$type_no";
57         db_query($sql, "could not void supptrans details");
58 }
59
60 //----------------------------------------------------------------------------------------
61
62 function add_supp_invoice_tax_item($supp_trans_type, $supp_trans_no, $tax_type_id,
63         $rate, $included_in_price, $amount)
64 {
65         $sql = "INSERT INTO ".TB_PREF."supp_invoice_tax_items (supp_trans_type, supp_trans_no, tax_type_id, rate, included_in_price, amount)
66                 VALUES ($supp_trans_type, $supp_trans_no, $tax_type_id, $rate, $included_in_price, $amount)";
67
68         db_query($sql, "The supplier transaction tax detail could not be added");
69 }
70
71 //----------------------------------------------------------------------------------------
72
73 function get_supp_invoice_tax_items($supp_trans_type, $supp_trans_no)
74 {
75         $sql = "SELECT ".TB_PREF."supp_invoice_tax_items.*, ".TB_PREF."tax_types.name AS tax_type_name
76                 FROM ".TB_PREF."supp_invoice_tax_items,".TB_PREF."tax_types
77                 WHERE supp_trans_type = $supp_trans_type
78                 AND supp_trans_no = $supp_trans_no
79                 AND ".TB_PREF."tax_types.id = ".TB_PREF."supp_invoice_tax_items.tax_type_id";
80
81         return db_query($sql, "The supplier transaction tax details could not be queried");
82 }
83
84 //----------------------------------------------------------------------------------------
85
86 function void_supp_invoice_tax_items($type, $type_no)
87 {
88         $sql = "UPDATE ".TB_PREF."supp_invoice_tax_items SET amount=0
89                 WHERE supp_trans_type = $type
90                 AND supp_trans_no=$type_no";
91
92         db_query($sql, "The supplier transaction tax details could not be voided");
93 }
94
95 ?>