X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=inventory%2Fincludes%2Fdb%2Fitems_trans_db.inc;h=c0dff65cc34613e55d5dc0daa6274e908fb291f6;hb=f44132511cc91b83f20f91af0625d4b112b4c26e;hp=cf72ee342f727b48b2b87f7f74a8a6c8f8b9457f;hpb=fbf51ab0febfd0885620abcab8738339d156ff45;p=fa-stable.git diff --git a/inventory/includes/db/items_trans_db.inc b/inventory/includes/db/items_trans_db.inc index cf72ee34..c0dff65c 100644 --- a/inventory/includes/db/items_trans_db.inc +++ b/inventory/includes/db/items_trans_db.inc @@ -15,25 +15,24 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co $last_cost) { $mb_flag = get_mb_flag($stock_id); - + $update_no = -1; if (is_service($mb_flag)) { //display_db_error("Cannot do cost update for Service item : $stock_id", ""); - + //Chaitanya $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)." WHERE stock_id=".db_escape($stock_id); - + db_query($sql,"The cost details for the inventory item could not be updated"); - + return $update_no; - - } - + } + begin_transaction(); - + $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost).", labour_cost=".db_escape($labour_cost).", overhead_cost=".db_escape($overhead_cost).", @@ -42,7 +41,7 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co db_query($sql,"The cost details for the inventory item could not be updated"); $qoh = get_qoh_on_date($stock_id); - + $date_ = Today(); if (!is_date_in_fiscalyear($date_)) $date_ = end_fiscalyear(); @@ -51,26 +50,26 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co { $new_cost = $material_cost + $labour_cost + $overhead_cost; - $value_of_change = $qoh * ($new_cost - $last_cost); - - $memo_ = "Cost was " . $last_cost . " changed to " . $new_cost . " x quantity on hand of $qoh"; - 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)); - $value_of_change = round2($qoh * ($new_cost - $last_cost), user_price_dec()); if ($value_of_change != 0) { $stock_gl_code = get_stock_gl_code($stock_id); - $update_no = get_next_trans_no(ST_COSTUPDATE); - $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)); - add_gl_trans_std_cost(ST_COSTUPDATE, $update_no, $date_, $stock_gl_code["inventory_account"], 0, 0, $memo_, - $value_of_change); + $cart = new items_cart(ST_COSTUPDATE); + $cart->tran_date = $cart->doc_date = $cart->event_date = $date_; + if (!is_date_in_fiscalyear($cart->tran_date)) + $cart->tran_date = end_fiscalyear(); + $cart->reference = $Refs->get_next(ST_COSTUPDATE, null, $cart->tran_date, $date_); + + $cart->memo_ = sprintf(_("Cost was %s changed to %s x quantity on hand of %s"), + number_format2($last_cost, 2), number_format2($new_cost), $qoh); + + $cart->add_gl_item($stock_gl_code["adjustment_account"], + $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], -$value_of_change); + $cart->add_gl_item($stock_gl_code["inventory_account"], 0, 0, $value_of_change); + write_journal_entries($cart); change_stock_moves_std_cost($stock_id, $date_, $new_cost - $last_cost); } } @@ -91,4 +90,3 @@ function change_stock_moves_std_cost($stock_id, $date, $diff_cost) . db_escape($stock_id)." AND tran_date <= '$date' AND qty <> 0 AND standard_cost > 0.001 AND type <> ".ST_LOCTRANSFER; db_query($sql,"The stock moves cost details for the inventory item could not be updated"); } -?> \ No newline at end of file