*** empty log message ***
[fa-stable.git] / manufacturing / search_work_orders.php
1 <?php
2
3 $page_security = 2;
4 $path_to_root="..";
5 include_once($path_to_root . "/includes/session.inc");
6
7 include_once($path_to_root . "/includes/date_functions.inc");
8 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
9 $js = "";
10 if ($use_popup_windows)
11         $js .= get_js_open_window(800, 500);
12 if (isset($_GET['outstanding_only'])) 
13 {
14         $outstanding_only = 1;
15         page(_("Search Outstanding Work Orders"), false, false, "", $js);
16
17 else 
18 {
19         $outstanding_only = 0;
20         page(_("Search Work Orders"), false, false, "", $js);
21 }
22
23
24 //--------------------------------------------------------------------------------------
25
26 if (isset($_GET["stock_id"]))
27         $_POST['SelectedStockItem'] = $_GET["stock_id"];
28
29 //--------------------------------------------------------------------------------------
30
31 start_form(false, false, $_SERVER['PHP_SELF'] ."?outstanding_only=" . $outstanding_only .SID);
32
33 start_table("class='tablestyle_noborder'");
34 start_row();
35 ref_cells(_("Reference:"), 'OrderNumber', null);
36
37 locations_list_cells(_("at Location:"), 'StockLocation', null, true);
38
39 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
40
41 check_cells( _("Only Open:"), 'OpenOnly', null);
42
43 stock_manufactured_items_list_cells(_("for item:"), 'SelectedStockItem', null, true);
44
45 submit_cells('SearchOrders', _("Search"));
46 end_row();
47 end_table();
48
49 end_form();
50
51 $sql = "SELECT ".TB_PREF."workorders.*, ".TB_PREF."stock_master.description,".TB_PREF."locations.location_name
52         FROM ".TB_PREF."workorders,".TB_PREF."stock_master,".TB_PREF."locations
53         WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id AND
54         ".TB_PREF."locations.loc_code=".TB_PREF."workorders.loc_code ";
55
56 if (check_value('OpenOnly')) 
57 {
58         $sql .= " AND ".TB_PREF."workorders.closed=0 ";
59 }
60
61 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items) 
62 {
63         $sql .= "AND ".TB_PREF."workorders.loc_code='" . $_POST['StockLocation'] . "' ";
64 }
65
66 if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "") 
67 {
68         $sql .= "AND ".TB_PREF."workorders.wo_ref LIKE '%". $_POST['OrderNumber'] . "%'";
69 }
70
71 if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items) 
72 {
73         $sql .= "AND ".TB_PREF."workorders.stock_id='". $_POST['SelectedStockItem'] . "'";
74 }
75
76 if (check_value('OverdueOnly')) 
77 {
78         $Today = date2sql(Today());
79
80         $sql .= "AND ".TB_PREF."workorders.required_by < '$Today' ";
81 }
82 $sql .= " ORDER BY ".TB_PREF."workorders.required_by";
83
84 $result = db_query($sql,"No orders were returned");
85
86 start_table("$table_style width=80%");
87
88 $th = array(_("#"), _("Reference"), _("Type"), _("Location"), _("Item"),
89         _("Required"), _("Manufactured"), _("Date"), _("Required By"), _("Closed"), "");
90 table_header($th);
91
92 $j = 1;
93 $k = 0;
94
95 while ($myrow = db_fetch($result)) 
96 {
97
98
99         // check if it's an overdue work order
100         if (!$myrow["closed"] && date_diff(Today(), sql2date($myrow["required_by"]), "d") > 0) 
101         {
102                 start_row("class='overduebg'");
103         }
104         else
105                 alt_table_row_color($k);
106
107         $modify_page = $path_to_root . "/manufacturing/work_order_entry.php?" . SID . "trans_no=" . $myrow["id"];
108         $release_page = $path_to_root . "/manufacturing/work_order_release.php?" . SID . "trans_no=" . $myrow["id"];
109         if ($myrow["closed"] == 0) 
110         {
111                 $issue = $path_to_root . "/manufacturing/work_order_issue.php?" . SID . "trans_no=" .$myrow["id"];
112                 $add_finished = $path_to_root . "/manufacturing/work_order_add_finished.php?" . SID . "trans_no=" .$myrow["id"];
113                 $costs = $path_to_root . "/gl/gl_payment.php?NewPayment=1&PayType=" . payment_person_types::WorkOrder(). "&PayPerson=" .$myrow["id"];
114                 $can_issue = $myrow["released"];
115                 $issue_link = $can_issue?("<a href=$issue>" . _("Issue") . "</a></td>
116                         <td><a href=$add_finished>" . _("Produce") . "</a></td>
117                         <td><a href=$costs>" . _("Costs") . "</a>"): _("Not Released");
118         } 
119         else 
120         {
121                 $issue_link = "";
122         }
123
124         label_cell(get_trans_view_str(systypes::work_order(), $myrow["id"]));
125         label_cell(get_trans_view_str(systypes::work_order(), $myrow["id"], $myrow["wo_ref"]));
126         label_cell(wo_types::name($myrow["type"]));
127         label_cell($myrow["location_name"]);
128         view_stock_status_cell($myrow["stock_id"], $myrow["description"]);
129         qty_cell($myrow["units_reqd"]);
130         qty_cell($myrow["units_issued"]);
131         label_cell(sql2date($myrow["date_"]));
132         label_cell(sql2date($myrow["required_by"]));
133         label_cell(($myrow["closed"]? _("Yes"):_("No")));
134         if ($issue_link != "")
135                 label_cell($issue_link);
136         if ($myrow["released"] == 0) 
137         {
138                 label_cell("<a href=$release_page>" . _("Release") . "</a>");
139         }
140         if ($myrow["closed"] == 0) 
141         {
142                 label_cell("<a href=$modify_page>" . _("Edit") . "</a>");
143         }
144
145         label_cell(get_gl_view_str(systypes::work_order(), $myrow["id"]));
146
147         end_row();
148
149         $j++;
150         If ($j == 12)
151         {
152                 $j = 1;
153                 table_header($th);
154         }
155         //end of page full new headings if
156 }
157 //end of while loop
158
159 end_table(1);
160
161 //---------------------------------------------------------------------------------
162
163 end_page();
164
165 ?>