d7ddf2d1616792759fd302d8efebf06d3d942902
[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 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 //-------------------------------------------------------------------------------------------------------------
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_, $dim_id=0, $dim2_id=0)
16 {
17         $sql = "INSERT INTO ".TB_PREF."supp_invoice_items (supp_trans_type, supp_trans_no, stock_id, description, gl_code, unit_price, unit_tax, quantity,
18                 grn_item_id, po_detail_item_id, memo_, dimension_id, dimension2_id) ";
19         $sql .= "VALUES (".db_escape($supp_trans_type).", ".db_escape($supp_trans_no).", "
20                 .db_escape($stock_id).
21         ", ".db_escape($description).", ".db_escape($gl_code).", ".db_escape($unit_price)
22         .", ".db_escape($unit_tax).", ".db_escape($quantity).", ".db_escape($grn_item_id)
23         .", ".db_escape($po_detail_item_id).", ".db_escape($memo_)
24         .", ".db_escape($dim_id).", ".db_escape($dim2_id).")";
25
26         db_query($sql, "Cannot insert a supplier transaction detail record");
27
28         return db_insert_id();
29 }
30
31 //-------------------------------------------------------------------------------------------------------------
32
33 function add_supp_invoice_gl_item($supp_trans_type, $supp_trans_no, $gl_code, $amount, $memo_, $dim_id=0, $dim2_id=0)
34 {
35         return add_supp_invoice_item($supp_trans_type, $supp_trans_no,  "", "", $gl_code, $amount,
36                 0, 0, /*$grn_item_id*/-1, /*$po_detail_item_id*/0, $memo_, 0, $dim_id, $dim2_id);
37 }
38
39
40 function get_supp_invoice_items($supp_trans_type, $supp_trans_no)
41 {
42         $sql = "SELECT inv.*, grn.*, unit_price AS FullUnitPrice, 
43                 stock.units,
44                 tax_type.exempt,
45                 tax_type.name as tax_type_name
46                 FROM "
47                         .TB_PREF."supp_invoice_items inv LEFT JOIN ".TB_PREF."grn_items grn ON grn.id =inv.grn_item_id
48                                 LEFT JOIN ".TB_PREF."stock_master stock ON stock.stock_id=inv.stock_id
49                                 LEFT JOIN ".TB_PREF."item_tax_types tax_type ON stock.tax_type_id=tax_type.id
50                 WHERE supp_trans_type = ".db_escape($supp_trans_type)."
51                         AND supp_trans_no = ".db_escape($supp_trans_no)
52                         ." ORDER BY inv.id";
53         return db_query($sql, "Cannot retreive supplier transaction detail records");
54 }
55
56 function void_supp_invoice_items($type, $type_no)
57 {
58         $sql = "UPDATE ".TB_PREF."supp_invoice_items SET quantity=0, unit_price=0
59                 WHERE supp_trans_type = ".db_escape($type)." AND supp_trans_no=".db_escape($type_no);
60         db_query($sql, "could not void supptrans details");
61 }
62