From: Joe Hunt Date: Tue, 19 May 2009 23:23:45 +0000 (+0000) Subject: Fixed and optimized On Order in Inventory Items Status and reports X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=7006a6f3f9bb0197c4d353c1aaf4593e30cb4e32;p=textcart.git Fixed and optimized On Order in Inventory Items Status and reports --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 2f2ddb3..24088fa 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,14 @@ Legend: ! -> Note $ -> Affected files +20-May-2009 Joe Hunt +# Fixed and optimized On Order in Inventory Items Status and reports +$ /includes/db/manufacturing_db.inc + /inventory/inquiry/stock_status.php + /reporting/rep302.php + /reporting/rep303.php + /sales/includes/db/sales_order_db.inc + 18-May-2009 Joe Hunt # html header shown in backup downloads. $ /admin/backups.php diff --git a/includes/db/manufacturing_db.inc b/includes/db/manufacturing_db.inc index 622b682..6778cff 100644 --- a/includes/db/manufacturing_db.inc +++ b/includes/db/manufacturing_db.inc @@ -9,6 +9,109 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License here . ***********************************************************************/ +//---------------------------------------------------------------------------------------- +function get_demand_qty($stock_id, $location) +{ + $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS QtyDemand + 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 "; + if ($location != "") + $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND "; + $sql .= TB_PREF."sales_order_details.stk_code = '$stock_id'"; + + $result = db_query($sql,"No transactions were returned"); + $row = db_fetch($result); + return $row['QtyDemand']; +} + +function get_demand_asm_qty($stock_id, $location) +{ + $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity) + AS Dem + FROM ".TB_PREF."sales_order_details, + ".TB_PREF."sales_orders, + ".TB_PREF."bom, + ".TB_PREF."stock_master + WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND + ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND "; + if ($location != "") + $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND "; + $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND + ".TB_PREF."bom.component='$stock_id' AND + ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND + (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='A')"; + + $result = db_query($sql,"No transactions were returned"); + if (db_num_rows($result)==1) + { + $row = db_fetch_row($result); + $demand_qty = $row[0]; + } + else + $demand_qty = 0.0; + return $demand_qty; +} + +function get_on_porder_qty($stock_id, $location) +{ + $sql = "SELECT Sum(".TB_PREF."purch_order_details.quantity_ordered - ".TB_PREF."purch_order_details.quantity_received) AS qoo + FROM ".TB_PREF."purch_order_details INNER JOIN ".TB_PREF."purch_orders ON ".TB_PREF."purch_order_details.order_no=".TB_PREF."purch_orders.order_no + WHERE ".TB_PREF."purch_order_details.item_code='$stock_id' "; + if ($location != "") + $sql .= "AND ".TB_PREF."purch_orders.into_stock_location='$location' "; + $sql .= "AND ".TB_PREF."purch_order_details.item_code='$stock_id'"; + $qoo_result = db_query($sql,"could not receive quantity on order for item"); + + if (db_num_rows($qoo_result) == 1) + { + $qoo_row = db_fetch_row($qoo_result); + $qoo = $qoo_row[0]; + } + else + { + $qoo = 0; + } + return $qoo; +} + +function get_on_worder_qty($stock_id, $location) +{ + $sql = "SELECT Sum((".TB_PREF."workorders.units_reqd-".TB_PREF."workorders.units_issued) * + (".TB_PREF."wo_requirements.units_req-".TB_PREF."wo_requirements.units_issued)) AS qoo + FROM ".TB_PREF."wo_requirements INNER JOIN ".TB_PREF."workorders + ON ".TB_PREF."wo_requirements.workorder_id=".TB_PREF."workorders.id + WHERE ".TB_PREF."wo_requirements.stock_id='$stock_id' "; + if ($location != "") + $sql .= "AND ".TB_PREF."wo_requirements.loc_code='$location' "; + $sql .= "AND ".TB_PREF."workorders.released=1"; + $qoo_result = db_query($sql,"could not receive quantity on order for item"); + if (db_num_rows($qoo_result) == 1) + { + $qoo_row = db_fetch_row($qoo_result); + $qoo = $qoo_row[0]; + } + else + $qoo = 0.0; + $flag = get_mb_flag($stock_id); + if ($flag == 'A' || $flag == 'M') + { + $sql = "SELECT Sum((".TB_PREF."workorders.units_reqd-".TB_PREF."workorders.units_issued)) AS qoo + FROM ".TB_PREF."workorders + WHERE ".TB_PREF."workorders.stock_id='$stock_id' "; + if ($location != "") + $sql .= "AND ".TB_PREF."workorders.loc_code='$location' "; + $sql .= "AND ".TB_PREF."workorders.released=1"; + $qoo_result = db_query($sql,"could not receive quantity on order for item"); + if (db_num_rows($qoo_result) == 1) + { + $qoo_row = db_fetch_row($qoo_result); + $qoo += $qoo_row[0]; + } + } + return $qoo; +} + function get_mb_flag($stock_id) { $sql = "SELECT mb_flag FROM ".TB_PREF."stock_master WHERE stock_id = '" . $stock_id . "'"; diff --git a/inventory/inquiry/stock_status.php b/inventory/inquiry/stock_status.php index c683fa9..331ea38 100644 --- a/inventory/inquiry/stock_status.php +++ b/inventory/inquiry/stock_status.php @@ -79,77 +79,15 @@ while ($myrow = db_fetch($loc_details)) alt_table_row_color($k); - $sql = "SELECT Sum(".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent) AS DEM - FROM ".TB_PREF."sales_order_details, ".TB_PREF."sales_orders - WHERE ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no - AND ".TB_PREF."sales_orders.from_stk_loc='" . $myrow["loc_code"] . "' - AND ".TB_PREF."sales_order_details.qty_sent < ".TB_PREF."sales_order_details.quantity - AND ".TB_PREF."sales_order_details.stk_code='" . $_POST['stock_id'] . "'"; - - $demand_result = db_query($sql,"Could not retreive demand for item"); - - if (db_num_rows($demand_result) == 1) - { - $demand_row = db_fetch_row($demand_result); - $demand_qty = $demand_row[0]; - } - else - { - $demand_qty =0; - } - - $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity) - AS DemAsm - FROM ".TB_PREF."sales_order_details, - ".TB_PREF."sales_orders, - ".TB_PREF."bom, - ".TB_PREF."stock_master - WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent - AND ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no - AND ".TB_PREF."sales_orders.from_stk_loc ='" . $myrow["loc_code"] . "' - AND ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 - AND ".TB_PREF."bom.component='" . $_POST['stock_id'] . "' - AND ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent - AND (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='A')"; - - $result = db_query($sql,"No transactions were returned"); - if (db_num_rows($result)==1) - { - $demand_row = db_fetch_row($result); - $demand_qty += $demand_row[0]; - } + $demand_qty = get_demand_qty($_POST['stock_id'], $myrow["loc_code"]); + $demand_qty += get_demand_asm_qty($_POST['stock_id'], $myrow["loc_code"]); $qoh = get_qoh_on_date($_POST['stock_id'], $myrow["loc_code"]); if ($kitset_or_service == false) { - $sql = "SELECT Sum(".TB_PREF."purch_order_details.quantity_ordered - ".TB_PREF."purch_order_details.quantity_received) AS qoo - FROM ".TB_PREF."purch_order_details INNER JOIN ".TB_PREF."purch_orders ON ".TB_PREF."purch_order_details.order_no=".TB_PREF."purch_orders.order_no - WHERE ".TB_PREF."purch_orders.into_stock_location='" . $myrow["loc_code"] . "' - AND ".TB_PREF."purch_order_details.item_code='" . $_POST['stock_id'] . "'"; - $qoo_result = db_query($sql,"could not receive quantity on order for item"); - - if (db_num_rows($qoo_result) == 1) - { - $qoo_row = db_fetch_row($qoo_result); - $qoo = $qoo_row[0]; - } - else - { - $qoo = 0; - } - $sql = "SELECT Sum(".TB_PREF."workorders.units_reqd * ".TB_PREF."wo_requirements.units_req) AS qoo - FROM ".TB_PREF."wo_requirements INNER JOIN ".TB_PREF."workorders - ON ".TB_PREF."wo_requirements.workorder_id=".TB_PREF."workorders.id - WHERE ".TB_PREF."wo_requirements.loc_code='" . $myrow["loc_code"] . "' - AND ".TB_PREF."wo_requirements.stock_id='" . $_POST['stock_id'] . "' - AND ".TB_PREF."workorders.closed=0"; - $qoo_result = db_query($sql,"could not receive quantity on order for item"); - if (db_num_rows($qoo_result) == 1) - { - $qoo_row = db_fetch_row($qoo_result); - $qoo += $qoo_row[0]; - } + $qoo = get_on_porder_qty($_POST['stock_id'], $myrow["loc_code"]); + $qoo += get_on_worder_qty($_POST['stock_id'], $myrow["loc_code"]); label_cell($myrow["location_name"]); qty_cell($qoh, false, $dec); qty_cell($myrow["reorder_level"], false, $dec); diff --git a/reporting/rep302.php b/reporting/rep302.php index f2297d8..6806e4c 100644 --- a/reporting/rep302.php +++ b/reporting/rep302.php @@ -23,6 +23,7 @@ include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/data_checks.inc"); include_once($path_to_root . "/gl/includes/gl_db.inc"); include_once($path_to_root . "/inventory/includes/db/items_category_db.inc"); +include_once($path_to_root . "/includes/db/manufacturing_db.inc"); //---------------------------------------------------------------------------------------------------- @@ -57,65 +58,6 @@ function getTransactions($category, $location) } -function getCustQty($stockid, $location) -{ - $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS qty_demand - 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 "; - if ($location != "") - $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND "; - $sql .= TB_PREF."sales_order_details.stk_code = '$stockid'"; - - $TransResult = db_query($sql,"No transactions were returned"); - $DemandRow = db_fetch($TransResult); - return $DemandRow['qty_demand']; -} - -function getCustAsmQty($stockid, $location) -{ - $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity) - AS Dem - FROM ".TB_PREF."sales_order_details, - ".TB_PREF."sales_orders, - ".TB_PREF."bom, - ".TB_PREF."stock_master - WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND - ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND "; - if ($location != "") - $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND "; - $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND - ".TB_PREF."bom.component='$stockid' AND - ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND - (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='A')"; - - $TransResult = db_query($sql,"No transactions were returned"); - if (db_num_rows($TransResult) == 1) - { - $DemandRow = db_fetch_row($TransResult); - $DemandQty = $DemandRow[0]; - } - else - $DemandQty = 0.0; - - return $DemandQty; -} - -function getSuppQty($stockid, $location) -{ - $sql = "SELECT SUM(".TB_PREF."purch_order_details.quantity_ordered - ".TB_PREF."purch_order_details.quantity_received) AS QtyOnOrder - FROM ".TB_PREF."purch_order_details, - ".TB_PREF."purch_orders - WHERE ".TB_PREF."purch_order_details.order_no = ".TB_PREF."purch_orders.order_no - AND ".TB_PREF."purch_order_details.item_code = '$stockid'"; - if ($location != "") - $sql .= " AND ".TB_PREF."purch_orders.into_stock_location= '$location'"; - - $TransResult = db_query($sql,"No transactions were returned"); - $DemandRow = db_fetch($TransResult); - return $DemandRow['QtyOnOrder']; -} - function getPeriods($stockid, $location) { $date5 = date('Y-m-d'); @@ -213,9 +155,10 @@ function print_inventory_planning() $loc_code = ""; else $loc_code = $trans['loc_code']; - $custqty = getCustQty($trans['stock_id'], $loc_code); - $custqty += getCustAsmQty($trans['stock_id'], $loc_code); - $suppqty = getSuppQty($trans['stock_id'], $loc_code); + $custqty = get_demand_qty($trans['stock_id'], $loc_code); + $custqty += get_demand_asm_qty($trans['stock_id'], $loc_code); + $suppqty = get_on_porder_qty($trans['stock_id'], $loc_code); + $suppqty += get_on_worder_qty($trans['stock_id'], $loc_code); $period = getPeriods($trans['stock_id'], $trans['loc_code']); $rep->NewLine(); $dec = get_qty_dec($trans['stock_id']); diff --git a/reporting/rep303.php b/reporting/rep303.php index ffeb9b8..d697029 100644 --- a/reporting/rep303.php +++ b/reporting/rep303.php @@ -23,6 +23,7 @@ include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/data_checks.inc"); include_once($path_to_root . "/gl/includes/gl_db.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); +include_once($path_to_root . "/includes/db/manufacturing_db.inc"); //---------------------------------------------------------------------------------------------------- @@ -56,50 +57,6 @@ function getTransactions($category, $location) return db_query($sql,"No transactions were returned"); } -function getDemandQty($stockid, $location) -{ - $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS QtyDemand - 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 "; - if ($location != "") - $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND "; - $sql .= TB_PREF."sales_order_details.stk_code = '$stockid'"; - - $TransResult = db_query($sql,"No transactions were returned"); - $DemandRow = db_fetch($TransResult); - return $DemandRow['QtyDemand']; -} - -function getDemandAsmQty($stockid, $location) -{ - $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity) - AS Dem - FROM ".TB_PREF."sales_order_details, - ".TB_PREF."sales_orders, - ".TB_PREF."bom, - ".TB_PREF."stock_master - WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND - ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND "; - if ($location != "") - $sql .= TB_PREF."sales_orders.from_stk_loc ='$location' AND "; - $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND - ".TB_PREF."bom.component='$stockid' AND - ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND - (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='A')"; - - $TransResult = db_query($sql,"No transactions were returned"); - if (db_num_rows($TransResult)==1) - { - $DemandRow = db_fetch_row($TransResult); - $DemandQty = $DemandRow[0]; - } - else - $DemandQty = 0.0; - - return $DemandQty; -} - //---------------------------------------------------------------------------------------------------- function print_stock_check() @@ -180,8 +137,8 @@ function print_stock_check() $loc_code = ""; else $loc_code = $trans['loc_code']; - $demandqty = getDemandQty($trans['stock_id'], $loc_code); - $demandqty += getDemandAsmQty($trans['stock_id'], $loc_code); + $demandqty = get_demand_qty($trans['stock_id'], $loc_code); + $demandqty += get_demand_asm_qty($trans['stock_id'], $loc_code); $rep->NewLine(); $dec = get_qty_dec($trans['stock_id']); $rep->TextCol(0, 1, $trans['stock_id']); diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index bbaf970..f48cbcf 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -10,48 +10,6 @@ See the License here . ***********************************************************************/ //---------------------------------------------------------------------------------------- -function get_demand_qty($stockid, $location) -{ - $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent) AS QtyDemand - 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.from_stk_loc ='$location' AND - ".TB_PREF."sales_order_details.stk_code = '$stockid'"; - - $TransResult = db_query($sql,"No transactions were returned"); - $DemandRow = db_fetch($TransResult); - return $DemandRow['QtyDemand']; -} - -function get_demand_asm_qty($stockid, $location) -{ - $sql = "SELECT SUM((".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)*".TB_PREF."bom.quantity) - AS Dem - FROM ".TB_PREF."sales_order_details, - ".TB_PREF."sales_orders, - ".TB_PREF."bom, - ".TB_PREF."stock_master - WHERE ".TB_PREF."sales_order_details.stk_code=".TB_PREF."bom.parent AND - ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND - ".TB_PREF."sales_orders.from_stk_loc='$location' AND - ".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND - ".TB_PREF."bom.component='$stockid' AND - ".TB_PREF."stock_master.stock_id=".TB_PREF."bom.parent AND - (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='A')"; - - $TransResult = db_query($sql,"No transactions were returned"); - if (db_num_rows($TransResult)==1) - { - $DemandRow = db_fetch_row($TransResult); - $DemandQty = $DemandRow[0]; - } - else - $DemandQty = 0.0; - - return $DemandQty; -} - function add_sales_order(&$order) { global $loc_notification, $path_to_root;