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 //----------------------------------------------------------------------------------------
14 function get_customer_trans_details($debtor_trans_type, $debtor_trans_no)
16 if (!is_array($debtor_trans_no))
17 $debtor_trans_no = array( 0=>$debtor_trans_no );
19 $sql = "SELECT ".TB_PREF."debtor_trans_details.*,
20 ".TB_PREF."debtor_trans_details.unit_price+".TB_PREF."debtor_trans_details.unit_tax AS FullUnitPrice,
21 ".TB_PREF."debtor_trans_details.description As StockDescription,
22 ".TB_PREF."stock_master.units
23 FROM ".TB_PREF."debtor_trans_details,".TB_PREF."stock_master
27 foreach ($debtor_trans_no as $trans_no)
28 $tr[] = 'debtor_trans_no='.$trans_no;
30 $sql .= implode(' OR ', $tr);
33 $sql.= ") AND debtor_trans_type=$debtor_trans_type
34 AND ".TB_PREF."stock_master.stock_id=".TB_PREF."debtor_trans_details.stock_id
36 return db_query($sql, "The debtor transaction detail could not be queried");
39 //----------------------------------------------------------------------------------------
41 function void_customer_trans_details($type, $type_no)
43 $sql = "UPDATE ".TB_PREF."debtor_trans_details SET quantity=0, unit_price=0,
44 unit_tax=0, discount_percent=0, standard_cost=0
45 WHERE debtor_trans_no=$type_no
46 AND debtor_trans_type=$type";
48 db_query($sql, "The debtor transaction details could not be voided");
50 // clear the stock move items
51 void_stock_move($type, $type_no);
53 //----------------------------------------------------------------------------------------
55 function add_customer_trans_tax_detail_item($debtor_trans_type, $debtor_trans_no,
56 $tax_type_id, $rate, $included_in_price, $amount)
58 $sql = "INSERT INTO ".TB_PREF."debtor_trans_tax_details (debtor_trans_no, debtor_trans_type, tax_type_id, rate, included_in_price, amount)
59 VALUES ($debtor_trans_no, $debtor_trans_type, $tax_type_id, $rate, $included_in_price, $amount)";
61 db_query($sql, "The debtor transaction tax detail could not be added");
64 //----------------------------------------------------------------------------------------
66 function get_customer_trans_tax_details($debtor_trans_type, $debtor_trans_no)
68 $sql = "SELECT ".TB_PREF."debtor_trans_tax_details.*, ".TB_PREF."tax_types.name AS tax_type_name
69 FROM ".TB_PREF."debtor_trans_tax_details,".TB_PREF."tax_types
70 WHERE debtor_trans_no=$debtor_trans_no
71 AND debtor_trans_type=$debtor_trans_type
73 AND ".TB_PREF."tax_types.id = ".TB_PREF."debtor_trans_tax_details.tax_type_id";
75 return db_query($sql, "The debtor transaction tax details could not be queried");
78 //----------------------------------------------------------------------------------------
80 function void_customer_trans_tax_details($type, $type_no)
82 $sql = "UPDATE ".TB_PREF."debtor_trans_tax_details SET amount=0
83 WHERE debtor_trans_no=$type_no
84 AND debtor_trans_type=$type";
86 db_query($sql, "The debtor transaction tax details could not be voided");
89 //----------------------------------------------------------------------------------------
91 function write_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
92 $quantity, $unit_price, $unit_tax, $discount_percent, $std_cost, $line_id=0)
95 $sql = "UPDATE ".TB_PREF."debtor_trans_details SET
96 stock_id=".db_escape($stock_id).",
97 description=".db_escape($description).",
99 unit_price=$unit_price,
101 discount_percent=$discount_percent,
102 standard_cost=$std_cost WHERE
105 $sql = "INSERT INTO ".TB_PREF."debtor_trans_details (debtor_trans_no,
106 debtor_trans_type, stock_id, description, quantity, unit_price,
107 unit_tax, discount_percent, standard_cost)
108 VALUES ($debtor_trans_no, $debtor_trans_type, ".db_escape($stock_id).
109 ", ".db_escape($description).",
110 $quantity, $unit_price, $unit_tax, $discount_percent, $std_cost)";
112 db_query($sql, "The debtor transaction detail could not be written");