Moving 2.0 development version to main trunk.
[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_update']))
26         $Ajax->activate('usage_table');
27
28 if (isset($_POST['stock_id']))
29 {
30     $sql = "SELECT ".TB_PREF."bom.*,".TB_PREF."stock_master.description,".TB_PREF."workcentres.name As WorkCentreName, ".TB_PREF."locations.location_name
31                 FROM ".TB_PREF."bom, ".TB_PREF."stock_master, ".TB_PREF."workcentres, ".TB_PREF."locations
32                 WHERE ".TB_PREF."bom.parent = ".TB_PREF."stock_master.stock_id AND ".TB_PREF."bom.workcentre_added = ".TB_PREF."workcentres.id
33                 AND ".TB_PREF."bom.loc_code = ".TB_PREF."locations.loc_code
34                 AND ".TB_PREF."bom.component='" . $_POST['stock_id'] . "'";
35
36     $result = db_query($sql,"No parent items were returned");
37
38         div_start('usage_table');
39         if (db_num_rows($result) == 0)
40         {
41                 display_note(_("The selected item is not used in any BOMs."));
42         }
43         else
44         {
45
46         start_table("$table_style width=80%");
47
48         $th = array(_("Parent Item"), _("Work Centre"), _("Location"), _("Quantity Required"));
49         table_header($th);
50
51                 $k = $j = 0;
52         while ($myrow = db_fetch($result))
53         {
54
55                         alt_table_row_color($k);
56
57                 $select_item = $path_to_root . "/manufacturing/manage/bom_edit.php?" . SID . "stock_id=" . $myrow["parent"];
58
59                 label_cell("<a href='$select_item'>" . $myrow["parent"]. " - " . $myrow["description"]. "</a>");
60                 label_cell($myrow["WorkCentreName"]);
61                 label_cell($myrow["location_name"]);
62                 qty_cell($myrow["quantity"], false, get_qty_dec($_POST['stock_id']));
63                         end_row();
64
65                 $j++;
66                 If ($j == 12)
67                 {
68                         $j = 1;
69                         table_header($th);
70                 }
71         //end of page full new headings if
72         }
73
74         end_table();
75         }
76         div_end();
77 }
78
79 end_form();
80 end_page();
81
82 ?>