2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
13 $path_to_root="../..";
14 include_once($path_to_root . "/includes/session.inc");
16 if (isset($_GET['stock_id'])){
17 $_POST['stock_id'] = $_GET['stock_id'];
18 page(_("Inventory Item Status"), true);
20 page(_("Inventory Item Status"));
23 include_once($path_to_root . "/includes/date_functions.inc");
24 include_once($path_to_root . "/includes/ui.inc");
25 include_once($path_to_root . "/includes/manufacturing.inc");
26 include_once($path_to_root . "/includes/data_checks.inc");
28 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
30 if (list_updated('stock_id'))
31 $Ajax->activate('status_tbl');
32 //----------------------------------------------------------------------------------------------------
34 check_db_has_stock_items(_("There are no items defined in the system."));
38 if (!isset($_POST['stock_id']))
39 $_POST['stock_id'] = get_global_stock_item();
41 echo "<center> " . _("Item:"). " ";
42 stock_items_list('stock_id', $_POST['stock_id'], false, true);
47 set_global_stock_item($_POST['stock_id']);
49 $mb_flag = get_mb_flag($_POST['stock_id']);
50 $kitset_or_service = false;
52 div_start('status_tbl');
53 if (is_service($mb_flag))
55 display_note(_("This is a service and cannot have a stock holding, only the total quantity on outstanding sales orders is shown."), 0, 1);
56 $kitset_or_service = true;
59 $loc_details = get_loc_details($_POST['stock_id']);
61 start_table($table_style);
63 if ($kitset_or_service == true)
65 $th = array(_("Location"), _("Demand"));
69 $th = array(_("Location"), _("Quantity On Hand"), _("Re-Order Level"),
70 _("Demand"), _("Available"), _("On Order"));
73 $dec = get_qty_dec($_POST['stock_id']);
75 $k = 0; //row colour counter
77 while ($myrow = db_fetch($loc_details))
80 alt_table_row_color($k);
82 $sql = "SELECT Sum(".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent) AS DEM
83 FROM ".TB_PREF."sales_order_details, ".TB_PREF."sales_orders
84 WHERE ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no
85 AND ".TB_PREF."sales_orders.from_stk_loc='" . $myrow["loc_code"] . "'
86 AND ".TB_PREF."sales_order_details.qty_sent < ".TB_PREF."sales_order_details.quantity
87 AND ".TB_PREF."sales_order_details.stk_code='" . $_POST['stock_id'] . "'";
89 $demand_result = db_query($sql,"Could not retreive demand for item");
91 if (db_num_rows($demand_result) == 1)
93 $demand_row = db_fetch_row($demand_result);
94 $demand_qty = $demand_row[0];
102 $qoh = get_qoh_on_date($_POST['stock_id'], $myrow["loc_code"]);
104 if ($kitset_or_service == false)
106 $sql = "SELECT Sum(".TB_PREF."purch_order_details.quantity_ordered - ".TB_PREF."purch_order_details.quantity_received) AS qoo
107 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
108 WHERE ".TB_PREF."purch_orders.into_stock_location='" . $myrow["loc_code"] . "'
109 AND ".TB_PREF."purch_order_details.item_code='" . $_POST['stock_id'] . "'";
110 $qoo_result = db_query($sql,"could not receive quantity on order for item");
112 if (db_num_rows($qoo_result) == 1)
114 $qoo_row = db_fetch_row($qoo_result);
122 label_cell($myrow["location_name"]);
123 qty_cell($qoh, false, $dec);
124 qty_cell($myrow["reorder_level"], false, $dec);
125 qty_cell($demand_qty, false, $dec);
126 qty_cell($qoh - $demand_qty, false, $dec);
127 qty_cell($qoo, false, $dec);
133 /* It must be a service or kitset part */
134 label_cell($myrow["location_name"]);
135 qty_cell($demand_qty, false, $dec);