Passing error message parameter err_msg to low level db functions from caller does...
[fa-stable.git] / manufacturing / includes / db / work_order_costing_db.inc
index 7a0bd413790ee03521969bc01d5b2472564d8894..3641d8f7465de7585959b69bc6de21d54b12a990 100644 (file)
@@ -48,8 +48,8 @@ function update_material_cost($stock_id, $qty, $unit_cost, $date)
 {
        global $Refs;
 
-       $product = get_item($stock_id);
-       $avg_cost =  $product['material_cost'];
+       $item = get_item($stock_id);
+       $avg_cost =  $item['material_cost'];
 
        $qoh = get_qoh_on_date($stock_id, null, $date);
 
@@ -103,12 +103,8 @@ function update_material_cost($stock_id, $qty, $unit_cost, $date)
                write_journal_entries($cart);
        }
 
-       if ($qty > 0 && ($qoh != -$qty)) {
-               if ($qoh == 0 && $avg_cost != 0)
-                       $avg_cost = ($avg_cost + ($unit_cost*$qty_new)/$qty)/2;
-               else
-                       $avg_cost = ($avg_cost*($qoh+$qty_delayed)+$unit_cost*$qty_new)/($qoh+$qty);
-       }
+       if ($qty > 0 && ($qoh != -$qty))
+            $avg_cost = ($avg_cost*($qoh+$qty_delayed)+$unit_cost*$qty_new)/($qoh+$qty);
 
        $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($avg_cost)."
                    WHERE stock_id=".db_escape($stock_id);
@@ -139,8 +135,7 @@ function add_wo_costs_journal($wo_id, $amount, $cost_type, $cr_acc, $date, $dim1
        if ($is_bank_to)
        {
                add_bank_trans(ST_JOURNAL, $journal_id, $is_bank_to, "",
-                       $date, -$amount, PT_WORKORDER, $wo_id, get_company_currency(),
-                       "Cannot insert a destination bank transaction");
+                       $date, -$amount, PT_WORKORDER, $wo_id, get_company_currency());
        }
        add_journal(ST_JOURNAL, $journal_id, $amount, $date, get_company_currency(), $ref, '', 1, $date, $date);