ae0764567c14fbde263f5cf1f7caa619755d4cbf
[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 $dec = get_qty_dec($_POST['stock_id']);
65 $j = 1;
66 $k = 0; //row colour counter
67
68 while ($myrow = db_fetch($loc_details))
69 {
70
71         alt_table_row_color($k);
72
73         $sql = "SELECT Sum(".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent) AS DEM
74                 FROM ".TB_PREF."sales_order_details, ".TB_PREF."sales_orders
75                 WHERE ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no
76                 AND ".TB_PREF."sales_orders.from_stk_loc='" . $myrow["loc_code"] . "'
77                 AND ".TB_PREF."sales_order_details.qty_sent < ".TB_PREF."sales_order_details.quantity
78                 AND ".TB_PREF."sales_order_details.stk_code='" . $_POST['stock_id'] . "'";
79
80         $demand_result = db_query($sql,"Could not retreive demand for item");
81
82         if (db_num_rows($demand_result) == 1)
83         {
84           $demand_row = db_fetch_row($demand_result);
85           $demand_qty =  $demand_row[0];
86         }
87         else
88         {
89           $demand_qty =0;
90         }
91
92
93         $qoh = get_qoh_on_date($_POST['stock_id'], $myrow["loc_code"]);
94
95         if ($kitset_or_service == false)
96         {
97                 $sql = "SELECT Sum(".TB_PREF."purch_order_details.quantity_ordered - ".TB_PREF."purch_order_details.quantity_received) AS qoo
98                         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
99                         WHERE ".TB_PREF."purch_orders.into_stock_location='" . $myrow["loc_code"] . "'
100                         AND ".TB_PREF."purch_order_details.item_code='" . $_POST['stock_id'] . "'";
101                 $qoo_result = db_query($sql,"could not receive quantity on order for item");
102
103                 if (db_num_rows($qoo_result) == 1)
104                 {
105                 $qoo_row = db_fetch_row($qoo_result);
106                 $qoo =  $qoo_row[0];
107                 }
108                 else
109                 {
110                         $qoo = 0;
111                 }
112
113                 label_cell($myrow["location_name"]);
114                 qty_cell($qoh, false, $dec);
115         qty_cell($myrow["reorder_level"], false, $dec);
116         qty_cell($demand_qty, false, $dec);
117         qty_cell($qoh - $demand_qty, false, $dec);
118         qty_cell($qoo, false, $dec);
119         end_row();
120
121         }
122         else
123         {
124         /* It must be a service or kitset part */
125                 label_cell($myrow["location_name"]);
126                 qty_cell($demand_qty, false, $dec);
127                 end_row();
128
129         }
130         $j++;
131         If ($j == 12)
132         {
133                 $j = 1;
134                 table_header($th);
135         }
136 }
137
138 end_table();
139 div_end();
140 end_form();
141 end_page();
142
143 ?>