c68b42dfe43ecd3fdca0d3f8e08b4e67119b33f5
[fa-stable.git] / manufacturing / inquiry / where_used_inquiry.php
1 <?php
2
3 $page_security = 2;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("Inventory Item Where Used Inquiry"));
8
9 //include($path_to_root . "/includes/date_functions.inc");
10 include($path_to_root . "/includes/ui.inc");
11
12 check_db_has_stock_items(_("There are no items defined in the system."));
13
14 start_form(false, true);
15
16 if (!isset($_POST['stock_id']))
17         $_POST['stock_id'] = get_global_stock_item();
18
19 echo "<center>" . _("Select an item to display its parent item(s).") . "&nbsp;";
20 stock_items_list('stock_id', $_POST['stock_id'], false, true);
21 echo "<hr><center>";
22
23 set_global_stock_item($_POST['stock_id']);
24
25 if (isset($_POST['stock_id'])) 
26 {
27     $sql = "SELECT ".TB_PREF."bom.*,".TB_PREF."stock_master.description,".TB_PREF."workcentres.name As WorkCentreName, ".TB_PREF."locations.location_name
28                 FROM ".TB_PREF."bom, ".TB_PREF."stock_master, ".TB_PREF."workcentres, ".TB_PREF."locations
29                 WHERE ".TB_PREF."bom.parent = ".TB_PREF."stock_master.stock_id AND ".TB_PREF."bom.workcentre_added = ".TB_PREF."workcentres.id
30                 AND ".TB_PREF."bom.loc_code = ".TB_PREF."locations.loc_code
31                 AND ".TB_PREF."bom.component='" . $_POST['stock_id'] . "'";
32
33     $result = db_query($sql,"No parent items were returned");
34
35         if (db_num_rows($result) == 0) 
36         {
37                 display_note(_("The selected item is not used in any BOMs."));
38         } 
39         else 
40         {
41
42         start_table("$table_style width=80%");
43
44         $th = array(_("Parent Item"), _("Work Centre"), _("Location"), _("Quantity Required"));
45         table_header($th);
46
47                 $k = $j = 0;
48         while ($myrow = db_fetch($result)) 
49         {
50
51                         alt_table_row_color($k);
52
53                 $select_item = $path_to_root . "/manufacturing/manage/bom_edit.php?" . SID . "stock_id=" . $myrow["parent"];
54
55                 label_cell("<a href='$select_item'>" . $myrow["parent"]. " - " . $myrow["description"]. "</a>");
56                 label_cell($myrow["WorkCentreName"]);
57                 label_cell($myrow["location_name"]);
58                 label_cell(qty_format($myrow["quantity"]));
59                         end_row();
60                         
61                 $j++;
62                 If ($j == 12)
63                 {
64                         $j = 1;
65                         table_header($th);
66                 }
67         //end of page full new headings if
68         }
69
70         end_table();
71         }
72 }
73
74 end_form();
75 end_page();
76
77 ?>