When updating costs and no quantity on hand we got a db error (in newer mysql releases).
[fa-stable.git] / inventory / includes / db / items_trans_db.inc
index 78930e81d9bce8ca9dc4132646aa25fa9664ef0e..a7591dd3d30f66ebc4a7b4bd3857f1cc3319dfda 100644 (file)
@@ -41,7 +41,7 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co
                WHERE stock_id=".db_escape($stock_id);
        db_query($sql,"The cost details for the inventory item could not be updated");
 
-       $qoh = get_qoh_on_date($_POST['stock_id']);
+       $qoh = get_qoh_on_date($stock_id);
        
        $date_ = Today();
        if (!is_date_in_fiscalyear($date_))
@@ -57,7 +57,8 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co
                {
                        $stock_gl_code = get_stock_gl_code($stock_id);
                        $update_no = get_next_trans_no(ST_COSTUPDATE);
-                       $memo_ = "Cost was " . $last_cost . " changed to " . $new_cost . " x quantity on hand of $qoh";
+                       $memo_ = sprintf(_("Cost was %s changed to %s x quantity on hand for item '%s'"),
+                               number_format2($last_cost, 2), number_format2($new_cost, 2), $stock_id);
                        add_gl_trans_std_cost(ST_COSTUPDATE, $update_no, $date_, $stock_gl_code["adjustment_account"], 
                                $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], $memo_, (-$value_of_change));     
 
@@ -66,7 +67,8 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co
                }               
        }
 
-       add_audit_trail(ST_COSTUPDATE, $update_no, $date_);
+       if ($update_no != -1)
+               add_audit_trail(ST_COSTUPDATE, $update_no, $date_);
        commit_transaction();
 
        return $update_no;