Fixed amibiguity in few text messages to make translations easier, updated gettext...
[fa-stable.git] / purchasing / includes / db / grn_db.inc
index 7b85ef137449bc124fee9d1a8ec8276a88e3ad11..7604568f8947b4754bd852d20e99514167a102c1 100644 (file)
 //------------------- update average material cost ------------------------------------------ Joe Hunt Mar-03-2008
 function update_average_material_cost($supplier, $stock_id, $price, $qty, $date, $adj_only=false)
 {
-       //Handle if inventory will become negative
-    //8-OCT-2011 : Skip negative inventory adjustment for case of adjust_only
-    if (is_inventory_item($stock_id) && !$adj_only)
-        handle_negative_inventory($stock_id, $qty, $price, $date);     
-
        // probably this function should be optimized
        // passing transaction cart as argument. This would
        // save a couple of db calls like get_supplier()
@@ -40,6 +35,11 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date,
                $price_in_home_currency = $price;
 
        $price_in_home_currency_ = $price_in_home_currency;
+
+       //Handle if inventory will become negative
+    //8-OCT-2011 : Skip negative inventory adjustment for case of adjust_only
+    if (is_inventory_item($stock_id) && !$adj_only) 
+        handle_negative_inventory($stock_id, $qty, $price_in_home_currency, $date);
        
        $sql = "SELECT mb_flag, material_cost, labour_cost, overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id);
        $result = db_query($sql);
@@ -99,7 +99,14 @@ function add_grn(&$po)
        begin_transaction();
        hook_db_prewrite($po, ST_SUPPRECEIVE);
 
-       add_new_exchange_rate(get_supplier_currency($po->supplier_id), $date_, $po->ex_rate);
+       if (!is_company_currency($po->curr_code))
+       {
+               if (!$po->ex_rate)
+                       $po->ex_rate = get_date_exchange_rate($po->curr_code, $date_);
+               else
+                       add_new_exchange_rate($po->curr_code, $date_, $po->ex_rate);
+       } else
+               $po->ex_rate = 1;
 
        $grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_, $po->ex_rate);
 
@@ -145,8 +152,7 @@ function add_grn(&$po)
                        $po->line_items[$line_no]->grn_item_id = $grn_item;
                        /* Update location stock records - NB  a po cannot be entered for a service/kit parts done automatically */
                        add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "",
-                               $order_line->receive_qty, $order_line->standard_cost,
-                       $po->supplier_id, 1, $order_line->taxfree_charge_price($po));
+                               $order_line->receive_qty, $order_line->standard_cost, $order_line->taxfree_charge_price($po));
 
                } /*quantity received is != 0 */
        } /*end of order_line loop */
@@ -252,7 +258,7 @@ function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
        db_query($sql);
 
     add_stock_move(ST_SUPPCREDIT, $entered_grn->item_code, $transno, $myrow['loc_code'], $date, "",
-               $entered_grn->this_quantity_inv, $mcost, $supplier, 1, $entered_grn->chg_price);
+               $entered_grn->this_quantity_inv, $mcost, $entered_grn->chg_price);
 }
 
 function get_grn_items($grn_batch_id=0, $supplier_id="", $outstanding_only=false,
@@ -466,4 +472,3 @@ function void_grn($grn_batch)
 
 //----------------------------------------------------------------------------------------------------------
 
-?>
\ No newline at end of file