X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fdb%2Finventory_db.inc;h=9c9d2b2e3e68756b225184a06d9f74950c42bf5f;hb=7e8df3a179c05c51085349e139aac9ce88b9378d;hp=117e318d96d53b590c263407706206527da045ee;hpb=3fd7df0efa6893e784c538b996f7968cd6dcd4d0;p=fa-stable.git diff --git a/includes/db/inventory_db.inc b/includes/db/inventory_db.inc index 117e318d..9c9d2b2e 100644 --- a/includes/db/inventory_db.inc +++ b/includes/db/inventory_db.inc @@ -354,27 +354,21 @@ function handle_negative_inventory($stock_id, $quantity, $standard_cost, $date_) // $date_ - display / non-sql date // $std_cost - in HOME currency -// $price - in $person_id's currency +// $price - in transaction currency function add_stock_move($type, $stock_id, $trans_no, $location, - $date_, $reference, $quantity, $std_cost, $person_id=0, - $price=0, $discount_percent=0, $error_msg="") + $date_, $reference, $quantity, $std_cost, $price=0) { $date = date2sql($date_); $sql = "INSERT INTO ".TB_PREF."stock_moves (stock_id, trans_no, type, loc_code, - tran_date, person_id, reference, qty, standard_cost, price, - discount_percent) VALUES (".db_escape($stock_id) - .", ".db_escape($trans_no).", ".db_escape($type) - .", ".db_escape($location).", '$date', " - .db_escape($person_id).", ".db_escape($reference).", " - .db_escape($quantity).", ".db_escape($std_cost)."," - .db_escape($price).", ".db_escape($discount_percent).")"; + tran_date, reference, qty, standard_cost, price) VALUES (" + .db_escape($stock_id).", ".db_escape($trans_no).", " + .db_escape($type).", ".db_escape($location).", '$date', " + .db_escape($reference).", " + .db_escape($quantity).", ".db_escape($std_cost)."," .db_escape($price).")"; - if ($error_msg == "") - $error_msg = "The stock movement record cannot be inserted"; - - db_query($sql, $error_msg); + db_query($sql, "The stock movement record cannot be inserted"); return db_insert_id(); } @@ -409,7 +403,11 @@ function get_stock_moves($type, $type_no) function void_stock_move($type, $type_no) { - $sql = "SELECT * from ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no); + $sql = "SELECT move.*, supplier.supplier_id from ".TB_PREF."stock_moves move + LEFT JOIN ".TB_PREF."supp_trans credit ON credit.trans_no=move.trans_no AND credit.type=move.type + LEFT JOIN ".TB_PREF."grn_batch grn ON grn.id=move.trans_no AND 25=move.type + LEFT JOIN ".TB_PREF."suppliers supplier ON IFNULL(grn.supplier_id, credit.supplier_id)=supplier.supplier_id + WHERE move.type=".db_escape($type)." AND move.trans_no=".db_escape($type_no); $result = db_query($sql, "Could not void stock moves"); while ($row = db_fetch($result)) @@ -425,10 +423,9 @@ function void_stock_move($type, $type_no) else $unit_cost = $row["standard_cost"]; - update_average_material_cost($row["person_id"], $row["stock_id"], + update_average_material_cost($row["supplier_id"], $row["stock_id"], $unit_cost, -$row["qty"], sql2date($row["tran_date"])); } - } $sql = "DELETE FROM ".TB_PREF."stock_moves WHERE type=".db_escape($type) ." AND trans_no=".db_escape($type_no); @@ -452,3 +449,17 @@ function get_location_name($loc_code) display_db_error("could not retreive the location name for $loc_code", $sql, true); } + +function get_mb_flag($stock_id) +{ + $sql = "SELECT mb_flag FROM ".TB_PREF."stock_master WHERE stock_id = " + .db_escape($stock_id); + $result = db_query($sql, "retreive mb_flag from item"); + + if (db_num_rows($result) == 0) + return -1; + + $myrow = db_fetch_row($result); + return $myrow[0]; +} +