Some more fixes related to ajax combos behaviour and usage
[fa-stable.git] / inventory / inquiry / stock_status.php
1 <?php
2
3 $page_security = 2;
4 $path_to_root="../..";
5 include_once($path_to_root . "/includes/session.inc");
6
7 if (isset($_GET['stock_id'])){
8         $_POST['stock_id'] = $_GET['stock_id'];
9         page(_("Inventory Item Status"), true);
10 } else {
11         page(_("Inventory Item Status"));
12 }
13
14 include_once($path_to_root . "/includes/date_functions.inc");
15 include_once($path_to_root . "/includes/ui.inc");
16 include_once($path_to_root . "/includes/manufacturing.inc");
17 include_once($path_to_root . "/includes/data_checks.inc");
18
19 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
20
21 if (isset($_POST['_stock_id_update']))
22         $Ajax->activate('status_tbl');
23 //----------------------------------------------------------------------------------------------------
24
25 check_db_has_stock_items(_("There are no items defined in the system."));
26
27 start_form(false, true);
28
29 if (!isset($_POST['stock_id']))
30         $_POST['stock_id'] = get_global_stock_item();
31
32 echo "<center> " . _("Item:"). " ";
33 stock_items_list('stock_id', $_POST['stock_id'], false, true);
34 echo "<br>";
35
36 echo "<hr></center>";
37
38 set_global_stock_item($_POST['stock_id']);
39
40 $mb_flag = get_mb_flag($_POST['stock_id']);
41 $kitset_or_service = false;
42
43 if (is_service($mb_flag))
44 {
45         display_note(_("This is a service and cannot have a stock holding, only the total quantity on outstanding sales orders is shown."));
46         $kitset_or_service = true;
47 }
48
49 $loc_details = get_loc_details($_POST['stock_id']);
50
51 div_start('status_tbl');
52 start_table($table_style);
53
54 if ($kitset_or_service == true)
55 {
56         $th = array(_("Location"), _("Demand"));
57 }
58 else
59 {
60         $th = array(_("Location"), _("Quantity On Hand"), _("Re-Order Level"),
61                 _("Demand"), _("Available"), _("On Order"));
62 }
63 table_header($th);
64 $j = 1;
65 $k = 0; //row colour counter
66
67 while ($myrow = db_fetch($loc_details))
68 {
69
70         alt_table_row_color($k);
71
72         $sql = "SELECT Sum(".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent) AS DEM
73                 FROM ".TB_PREF."sales_order_details, ".TB_PREF."sales_orders
74                 WHERE ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no
75                 AND ".TB_PREF."sales_orders.from_stk_loc='" . $myrow["loc_code"] . "'
76                 AND ".TB_PREF."sales_order_details.qty_sent < ".TB_PREF."sales_order_details.quantity
77                 AND ".TB_PREF."sales_order_details.stk_code='" . $_POST['stock_id'] . "'";
78
79         $demand_result = db_query($sql,"Could not retreive demand for item");
80
81         if (db_num_rows($demand_result) == 1)
82         {
83           $demand_row = db_fetch_row($demand_result);
84           $demand_qty =  $demand_row[0];
85         }
86         else
87         {
88           $demand_qty =0;
89         }
90
91
92         $qoh = get_qoh_on_date($_POST['stock_id'], $myrow["loc_code"]);
93
94         if ($kitset_or_service == false)
95         {
96                 $sql = "SELECT Sum(".TB_PREF."purch_order_details.quantity_ordered - ".TB_PREF."purch_order_details.quantity_received) AS qoo
97                         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
98                         WHERE ".TB_PREF."purch_orders.into_stock_location='" . $myrow["loc_code"] . "'
99                         AND ".TB_PREF."purch_order_details.item_code='" . $_POST['stock_id'] . "'";
100                 $qoo_result = db_query($sql,"could not receive quantity on order for item");
101
102                 if (db_num_rows($qoo_result) == 1)
103                 {
104                 $qoo_row = db_fetch_row($qoo_result);
105                 $qoo =  $qoo_row[0];
106                 }
107                 else
108                 {
109                         $qoo = 0;
110                 }
111
112                 label_cell($myrow["location_name"]);
113                 qty_cell($qoh);
114         qty_cell($myrow["reorder_level"]);
115         qty_cell($demand_qty);
116         qty_cell($qoh - $demand_qty);
117         qty_cell($qoo);
118         end_row();
119
120         }
121         else
122         {
123         /* It must be a service or kitset part */
124                 label_cell($myrow["location_name"]);
125                 qty_cell($demand_qty);
126                 end_row();
127
128         }
129         $j++;
130         If ($j == 12)
131         {
132                 $j = 1;
133                 table_header($th);
134         }
135 }
136
137 end_table();
138 div_end();
139 end_form();
140 end_page();
141
142 ?>