Global change in naming convention from std_cost to unit_cost.
[fa-stable.git] / sales / includes / db / cust_trans_details_db.inc
index be04db16fb9d94eaa0d81683e75eafd107c838e1..fabcfe073961a7fe3b661208a9f9876fc296e442 100644 (file)
 <?php
-
-//----------------------------------------------------------------------------------------
-
-function add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description, $quantity, 
-       $unit_price, $unit_tax, $discount_percent, $standard_cost)
-{
-       $sql = "INSERT INTO ".TB_PREF."debtor_trans_details (debtor_trans_no, debtor_trans_type, stock_id, description, quantity, unit_price, unit_tax, discount_percent, standard_cost)
-               VALUES ($debtor_trans_no, $debtor_trans_type, '$stock_id', '$description', $quantity, $unit_price, $unit_tax, $discount_percent, $standard_cost)";
-                       
-       db_query($sql, "The debtor transaction detail could not be added");                     
-}
-
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
 //----------------------------------------------------------------------------------------
 
 function get_customer_trans_details($debtor_trans_type, $debtor_trans_no)
 {
-       $sql = "SELECT ".TB_PREF."debtor_trans_details.*, ".TB_PREF."debtor_trans_details.unit_price+".TB_PREF."debtor_trans_details.unit_tax AS FullUnitPrice, 
-               ".TB_PREF."debtor_trans_details.description As StockDescription,
-               ".TB_PREF."stock_master.units 
-               FROM ".TB_PREF."debtor_trans_details,".TB_PREF."stock_master 
-               WHERE debtor_trans_no=$debtor_trans_no
-               AND debtor_trans_type=$debtor_trans_type 
-               AND ".TB_PREF."stock_master.stock_id=".TB_PREF."debtor_trans_details.stock_id";
+if (!is_array($debtor_trans_no))
+       $debtor_trans_no = array( 0=>$debtor_trans_no );
 
-       return db_query($sql, "The debtor transaction detail could not be queried");
-}
+       $sql = "SELECT line.*,
+               line.unit_price+line.unit_tax AS FullUnitPrice,
+        line.unit_price AS UnitPriceExTax,  
+               line.description As StockDescription,
+               item.units, item.mb_flag
+               FROM "
+                       .TB_PREF."debtor_trans_details line,"
+                       .TB_PREF."stock_master item
+               WHERE (";
 
-//----------------------------------------------------------------------------------------
+       $tr=array();
+       foreach ($debtor_trans_no as $trans_no)
+               $tr[] = 'debtor_trans_no='.db_escape($trans_no);
 
-function void_customer_trans_details($type, $type_no)
-{
-       $sql = "UPDATE ".TB_PREF."debtor_trans_details SET quantity=0, unit_price=0, 
-               unit_tax=0, discount_percent=0, standard_cost=0
-               WHERE debtor_trans_no=$type_no
-               AND debtor_trans_type=$type";
-                               
-       db_query($sql, "The debtor transaction details could not be voided");
-                               
-       // clear the stock move items
-       void_stock_move($type, $type_no);       
-}
+       $sql .= implode(' OR ', $tr);
 
-//----------------------------------------------------------------------------------------
 
-function add_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
-       $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent, 
-       $reference,     $std_cost)
-{
-       add_customer_trans_detail_item_base($debtor_trans_type, $debtor_trans_no, $stock_id, $description, 
-               $quantity, $unit_price, $unit_tax, $discount_percent, $std_cost);
-       
-       add_stock_move_customer($debtor_trans_type, $stock_id, $debtor_trans_no, $Location,
-               $date_, $reference, $quantity, $std_cost, 1, $unit_price+$unit_tax, $discount_percent);
-       
-       return $std_cost;
+       $sql.=  ") AND debtor_trans_type=".db_escape($debtor_trans_type)."
+               AND item.stock_id=line.stock_id
+               ORDER BY id";
+       return db_query($sql, "The debtor transaction detail could not be queried");
 }
 
 //----------------------------------------------------------------------------------------
 
-function add_customer_trans_detail_item_writeoff($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
-       $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent, 
-       $reference, $std_cost)
-{
-       $retCost = add_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
-               $Location, $date_, $quantity, $unit_price, $unit_tax, $discount_percent, 
-               $reference,     $std_cost);
-                                                                                                                       
-       $reference = _("Write off") . " " . $reference;
-
-       add_stock_move_customer($debtor_trans_type, $stock_id, $debtor_trans_no, $Location,
-               $date_, $reference, -$quantity, $std_cost, 0, $unit_price+$unit_tax, $discount_percent);
-                                       
-       return $retCost;                                                                                                                                
-}                                                                                                                      
-
-//----------------------------------------------------------------------------------------
-
-function add_customer_trans_tax_detail_item($debtor_trans_type, $debtor_trans_no,  
-       $tax_type_id, $rate, $included_in_price, $amount)
+function void_customer_trans_details($type, $type_no)
 {
-       $sql = "INSERT INTO ".TB_PREF."debtor_trans_tax_details (debtor_trans_no, debtor_trans_type, tax_type_id, rate, included_in_price, amount)
-               VALUES ($debtor_trans_no, $debtor_trans_type, $tax_type_id, $rate, $included_in_price, $amount)";
-                       
-       db_query($sql, "The debtor transaction tax detail could not be added"); 
-}
+       $sql = "UPDATE ".TB_PREF."debtor_trans_details SET quantity=0, unit_price=0,
+               unit_tax=0, discount_percent=0, unit_cost=0, src_id=0
+               WHERE debtor_trans_no=".db_escape($type_no)."
+               AND debtor_trans_type=".db_escape($type);
 
-//----------------------------------------------------------------------------------------
-
-function get_customer_trans_tax_details($debtor_trans_type, $debtor_trans_no)
-{
-       $sql = "SELECT ".TB_PREF."debtor_trans_tax_details.*, ".TB_PREF."tax_types.name AS tax_type_name
-               FROM ".TB_PREF."debtor_trans_tax_details,".TB_PREF."tax_types 
-               WHERE debtor_trans_no=$debtor_trans_no
-               AND debtor_trans_type=$debtor_trans_type 
-               AND ".TB_PREF."tax_types.id = ".TB_PREF."debtor_trans_tax_details.tax_type_id";
+       db_query($sql, "The debtor transaction details could not be voided");
 
-       return db_query($sql, "The debtor transaction tax details could not be queried");
+       // clear the stock move items
+       void_stock_move($type, $type_no);
 }
-
 //----------------------------------------------------------------------------------------
 
-function void_customer_trans_tax_details($type, $type_no)
+function write_customer_trans_detail_item($debtor_trans_type, $debtor_trans_no, $stock_id, $description,
+       $quantity, $unit_price, $unit_tax, $discount_percent, $unit_cost, $src_id, $line_id=0)
 {
-       $sql = "UPDATE ".TB_PREF."debtor_trans_tax_details SET amount=0
-               WHERE debtor_trans_no=$type_no
-               AND debtor_trans_type=$type";
-                               
-       db_query($sql, "The debtor transaction tax details could not be voided");
+       if ($line_id!=0)
+               $sql = "UPDATE ".TB_PREF."debtor_trans_details SET
+                       stock_id=".db_escape($stock_id).",
+                       description=".db_escape($description).",
+                       quantity=$quantity,
+                       unit_price=$unit_price,
+                       unit_tax=$unit_tax,
+                       discount_percent=$discount_percent,
+                       unit_cost=$unit_cost,
+                       src_id=".db_escape($src_id)." WHERE
+                       id=".db_escape($line_id);
+       else
+                       $sql = "INSERT INTO ".TB_PREF."debtor_trans_details (debtor_trans_no,
+                               debtor_trans_type, stock_id, description, quantity, unit_price,
+                               unit_tax, discount_percent, unit_cost, src_id)
+                       VALUES (".db_escape($debtor_trans_no).", ".db_escape($debtor_trans_type).", ".db_escape($stock_id).
+                       ", ".db_escape($description).",
+                               $quantity, $unit_price, $unit_tax, 
+                               $discount_percent, $unit_cost,".db_escape($src_id).")";
+
+       db_query($sql, "The debtor transaction detail could not be written");
 }
 
-//----------------------------------------------------------------------------------------
-
-?>
\ No newline at end of file