Smaller technical fixes.
[fa-stable.git] / sales / includes / sales_db.inc
index c350642ad05c605d792bf51bf0bfae1050c5a9d1..0503abd3c2a94e3a321800c14fc20814c2bf1ea6 100644 (file)
@@ -115,6 +115,23 @@ function get_price ($stock_id, $currency, $sales_type_id, $factor=null, $date=nu
            $prices[$myrow['sales_type_id']][$myrow['curr_abrev']] = $myrow['price'];
        }
        $price = false;
+       if (isset($prices[$sales_type_id][$currency])) 
+       {
+           $price = $prices[$sales_type_id][$currency];
+       }
+       elseif (isset($prices[$base_id][$currency])) 
+       {
+           $price = $prices[$base_id][$currency] * $factor;
+       }
+       elseif (isset($prices[$sales_type_id][$home_curr])) 
+       {
+           $price = $prices[$sales_type_id][$home_curr] / $rate;
+       }
+       elseif (isset($prices[$base_id][$home_curr])) 
+       {
+           $price = $prices[$base_id][$home_curr] * $factor / $rate;
+       }
+/*
        if (isset($prices[$sales_type_id][$home_curr])) 
        {
            $price = $prices[$sales_type_id][$home_curr] / $rate;
@@ -127,6 +144,7 @@ function get_price ($stock_id, $currency, $sales_type_id, $factor=null, $date=nu
        {
            $price = $prices[$base_id][$home_curr] * $factor / $rate;
        }
+*/     
        elseif ($num_rows == 0 && $add_pct != -1)
        {
                $price = get_calculated_price($stock_id, $add_pct);
@@ -221,14 +239,7 @@ function set_document_parent($cart)
 }
 
 //--------------------------------------------------------------------------------------------------
-function get_parent_type($type)
-{
-       $parent_types = array( ST_CUSTCREDIT => ST_SALESINVOICE, ST_SALESINVOICE => ST_CUSTDELIVERY, ST_CUSTDELIVERY => ST_SALESORDER );
-       return isset($parent_types[$type]) ?  $parent_types[$type] : 0;
-}
-
-//--------------------------------------------------------------------------------------------------
-function update_parent_line($doc_type, $line_id, $qty_dispatched)
+function update_parent_line($doc_type, $line_id, $qty_dispatched, $auto=false)
 {
        $doc_type = get_parent_type($doc_type);
 
@@ -237,9 +248,13 @@ function update_parent_line($doc_type, $line_id, $qty_dispatched)
                return false;
        else {
                if ($doc_type==ST_SALESORDER)
+               {
                        $sql = "UPDATE ".TB_PREF."sales_order_details
-                               SET qty_sent = qty_sent + $qty_dispatched
-                               WHERE id=".db_escape($line_id);
+                               SET qty_sent = qty_sent + $qty_dispatched";
+                       if ($auto)
+                               $sql .= ", quantity = quantity + $qty_dispatched";
+                       $sql .= " WHERE id=".db_escape($line_id);
+               }               
                else
                        $sql = "UPDATE ".TB_PREF."debtor_trans_details
                                SET qty_done = qty_done + $qty_dispatched
@@ -295,7 +310,7 @@ function read_sales_trans($doc_type, $trans_no, &$cart)
                        $myrow["curr_code"], $myrow["discount"], $myrow["payment_terms"]);
 
                $cart->set_branch($myrow["branch_code"], $myrow["tax_group_id"],
-                       $myrow["tax_group_name"],       $myrow["phone"], $myrow["email"]);
+                       $myrow["tax_group_name"]);
 
                $cart->reference = $myrow["reference"];
                $cart->order_no = $myrow["order_"];