Global change in naming convention from std_cost to unit_cost.
[fa-stable.git] / sales / includes / db / cust_trans_details_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 get_customer_trans_details($debtor_trans_type, $debtor_trans_no)
15 {
16 if (!is_array($debtor_trans_no))
17         $debtor_trans_no = array( 0=>$debtor_trans_no );
18
19         $sql = "SELECT line.*,
20                 line.unit_price+line.unit_tax AS FullUnitPrice,
21         line.unit_price AS UnitPriceExTax,  
22                 line.description As StockDescription,
23                 item.units, item.mb_flag
24                 FROM "
25                         .TB_PREF."debtor_trans_details line,"
26                         .TB_PREF."stock_master item
27                 WHERE (";
28
29         $tr=array();
30         foreach ($debtor_trans_no as $trans_no)
31                 $tr[] = 'debtor_trans_no='.db_escape($trans_no);
32
33         $sql .= implode(' OR ', $tr);
34
35
36         $sql.=  ") AND debtor_trans_type=".db_escape($debtor_trans_type)."
37                 AND item.stock_id=line.stock_id
38                 ORDER BY id";
39         return db_query($sql, "The debtor transaction detail could not be queried");
40 }
41
42 //----------------------------------------------------------------------------------------
43
44 function void_customer_trans_details($type, $type_no)
45 {
46         $sql = "UPDATE ".TB_PREF."debtor_trans_details SET quantity=0, unit_price=0,
47                 unit_tax=0, discount_percent=0, unit_cost=0, src_id=0
48                 WHERE debtor_trans_no=".db_escape($type_no)."
49                 AND debtor_trans_type=".db_escape($type);
50
51         db_query($sql, "The debtor transaction details could not be voided");
52
53         // clear the stock move items
54         void_stock_move($type, $type_no);
55 }
56 //----------------------------------------------------------------------------------------
57
58 function write_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
59         $quantity, $unit_price, $unit_tax, $discount_percent, $unit_cost, $src_id, $line_id=0)
60 {
61         if ($line_id!=0)
62                 $sql = "UPDATE ".TB_PREF."debtor_trans_details SET
63                         stock_id=".db_escape($stock_id).",
64                         description=".db_escape($description).",
65                         quantity=$quantity,
66                         unit_price=$unit_price,
67                         unit_tax=$unit_tax,
68                         discount_percent=$discount_percent,
69                         unit_cost=$unit_cost,
70                         src_id=".db_escape($src_id)." WHERE
71                         id=".db_escape($line_id);
72         else
73                         $sql = "INSERT INTO ".TB_PREF."debtor_trans_details (debtor_trans_no,
74                                 debtor_trans_type, stock_id, description, quantity, unit_price,
75                                 unit_tax, discount_percent, unit_cost, src_id)
76                         VALUES (".db_escape($debtor_trans_no).", ".db_escape($debtor_trans_type).", ".db_escape($stock_id).
77                         ", ".db_escape($description).",
78                                 $quantity, $unit_price, $unit_tax, 
79                                 $discount_percent, $unit_cost,".db_escape($src_id).")";
80
81         db_query($sql, "The debtor transaction detail could not be written");
82 }
83