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