X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=includes%2Fdb%2Fmanufacturing_db.inc;h=bfd4070468eb004d0b5ef9ec29e82411c70cc051;hb=c164d1f25c5258939976042fa8796b71ac54c188;hp=14927475ed8ad206f406051bf239b6bde12d7320;hpb=e2fa1c1b9543dedb3cd0a3a36dc539c86f7ff473;p=fa-stable.git diff --git a/includes/db/manufacturing_db.inc b/includes/db/manufacturing_db.inc index 14927475..bfd40704 100644 --- a/includes/db/manufacturing_db.inc +++ b/includes/db/manufacturing_db.inc @@ -17,7 +17,8 @@ function get_demand_qty($stock_id, $location) FROM ".TB_PREF."sales_order_details, ".TB_PREF."sales_orders WHERE ".TB_PREF."sales_order_details.order_no=" - .TB_PREF."sales_orders.order_no AND "; + .TB_PREF."sales_orders.order_no AND ".TB_PREF."sales_orders.trans_type=".ST_SALESORDER." AND + ".TB_PREF."sales_orders.trans_type=".TB_PREF."sales_order_details.trans_type AND "; if ($location != "") $sql .= TB_PREF."sales_orders.from_stk_loc =".db_escape($location)." AND "; $sql .= TB_PREF."sales_order_details.stk_code = ".db_escape($stock_id); @@ -40,7 +41,7 @@ function load_stock_levels($location) $sql = "SELECT stock_id, SUM(qty) FROM ".TB_PREF."stock_moves WHERE tran_date <= '$date'"; if ($location != '') $sql .= " AND loc_code = ".db_escape($location); $sql .= " GROUP BY stock_id"; - $result = db_query($sql, "QOH calulcation failed"); + $result = db_query($sql, "QOH calculation failed"); while ($row = db_fetch($result)) { $qoh_stock[$row[0]] = $row[1]; } @@ -60,10 +61,10 @@ function stock_demand_manufacture($stock_id, $qty, $demand_id, $location, $level $qoh_stock = array(); load_stock_levels($location); } - $stock_qty = $qoh_stock[$stock_id]; - if ($stock_qty == NULL) $stock_qty = 0; + if (empty($qoh_stock[$stock_id])) $stock_qty = 0; + else $stock_qty = $qoh_stock[$stock_id]; if ($qty <= $stock_qty) return $demand; - $bom = $bom_list[$stock_id]; + $bom = @$bom_list[$stock_id]; if ($bom == NULL) { $sql = "SELECT parent, component, quantity FROM " .TB_PREF."bom WHERE parent = ".db_escape($stock_id); @@ -101,12 +102,14 @@ function get_demand_asm_qty($stock_id, $location) FROM ".TB_PREF."sales_order_details, ".TB_PREF."sales_orders, ".TB_PREF."stock_master - WHERE ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND "; + WHERE ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND + ".TB_PREF."sales_orders.trans_type=".ST_SALESORDER." AND + ".TB_PREF."sales_orders.trans_type=".TB_PREF."sales_order_details.trans_type AND "; if ($location != "") $sql .= TB_PREF."sales_orders.from_stk_loc =".db_escape($location)." AND "; $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND ".TB_PREF."stock_master.stock_id=".TB_PREF."sales_order_details.stk_code AND - (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='A') + ".TB_PREF."stock_master.mb_flag='M' GROUP BY ".TB_PREF."sales_order_details.stk_code"; $result = db_query($sql, "No transactions were returned"); while ($row = db_fetch_row($result)) { @@ -158,7 +161,7 @@ function get_on_worder_qty($stock_id, $location) else $qoo = 0.0; $flag = get_mb_flag($stock_id); - if ($flag == 'A' || $flag == 'M') + if ($flag == 'M') { $sql = "SELECT SUM((".TB_PREF."workorders.units_reqd-".TB_PREF."workorders.units_issued)) AS qoo FROM ".TB_PREF."workorders @@ -202,7 +205,7 @@ function add_bom($selected_parent, $component, $workcentre_added, $loc_code, $qu } //-------------------------------------------------------------------------------------- -function update_bom($selected_parent, $selected_component, $work_centre_added, $loc_code, $quantity) +function update_bom($selected_parent, $selected_component, $workcentre_added, $loc_code, $quantity) { $sql = "UPDATE ".TB_PREF."bom SET workcentre_added=".db_escape($workcentre_added) . ",loc_code=".db_escape($loc_code) . ",