Moving 2.0 development version to main trunk.
[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']) && ($_GET['outstanding_only'] == true))
13 {
14 // curently outstanding simply means not closed
15         $outstanding_only = 1;
16         page(_("Search Outstanding Work Orders"), false, false, "", $js);
17 }
18 else
19 {
20         $outstanding_only = 0;
21         page(_("Search Work Orders"), false, false, "", $js);
22 }
23 //-----------------------------------------------------------------------------------
24 // Ajax updates
25 //
26 if (get_post('SearchOrders')) 
27 {
28         $Ajax->activate('orders_tbl');
29 } elseif (get_post('_OrderNumber_changed')) 
30 {
31         $disable = get_post('OrderNumber') !== '';
32
33         $Ajax->addDisable(true, 'StockLocation', $disable);
34         $Ajax->addDisable(true, 'OverdueOnly', $disable);
35         $Ajax->addDisable(true, 'OpenOnly', $disable);
36         $Ajax->addDisable(true, 'SelectedStockItem', $disable);
37
38         if ($disable) {
39 //              $Ajax->addFocus(true, 'OrderNumber');
40                 set_focus('OrderNumber');
41         } else
42 //              $Ajax->addFocus(true, 'StockLocation');
43                 set_focus('StockLocation');
44
45         $Ajax->activate('orders_tbl');
46 }
47
48 //--------------------------------------------------------------------------------------
49
50 if (isset($_GET["stock_id"]))
51         $_POST['SelectedStockItem'] = $_GET["stock_id"];
52
53 //--------------------------------------------------------------------------------------
54
55 start_form(false, false, $_SERVER['PHP_SELF'] ."?outstanding_only=" . $outstanding_only .SID);
56
57 start_table("class='tablestyle_noborder'");
58 start_row();
59 ref_cells(_("Reference:"), 'OrderNumber', '',null, '', true);
60
61 locations_list_cells(_("at Location:"), 'StockLocation', null, true);
62
63 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
64
65 if ($outstanding_only==0)
66         check_cells( _("Only Open:"), 'OpenOnly', null);
67
68 stock_manufactured_items_list_cells(_("for item:"), 'SelectedStockItem', null, true);
69
70 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), true);
71 end_row();
72 end_table();
73
74 end_form();
75
76 $sql = "SELECT ".TB_PREF."workorders.*, ".TB_PREF."stock_master.description,".TB_PREF."locations.location_name
77         FROM ".TB_PREF."workorders,".TB_PREF."stock_master,".TB_PREF."locations
78         WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id AND
79         ".TB_PREF."locations.loc_code=".TB_PREF."workorders.loc_code ";
80
81 if (check_value('OpenOnly') || $outstanding_only != 0)
82 {
83         $sql .= " AND ".TB_PREF."workorders.closed=0 ";
84 }
85
86 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
87 {
88         $sql .= "AND ".TB_PREF."workorders.loc_code='" . $_POST['StockLocation'] . "' ";
89 }
90
91 if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
92 {
93         $sql .= "AND ".TB_PREF."workorders.wo_ref LIKE '%". $_POST['OrderNumber'] . "%'";
94 }
95
96 if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items)
97 {
98         $sql .= "AND ".TB_PREF."workorders.stock_id='". $_POST['SelectedStockItem'] . "'";
99 }
100
101 if (check_value('OverdueOnly'))
102 {
103         $Today = date2sql(Today());
104
105         $sql .= "AND ".TB_PREF."workorders.required_by < '$Today' ";
106 }
107 $sql .= " ORDER BY ".TB_PREF."workorders.required_by";
108
109 $result = db_query($sql,"No orders were returned");
110
111 div_start('orders_tbl');
112 start_table("$table_style width=80%");
113
114 $th = array(_("#"), _("Reference"), _("Type"), _("Location"), _("Item"),
115         _("Required"), _("Manufactured"), _("Date"), _("Required By"),
116         '', '', '', '', '');
117 table_header($th);
118
119 $j = 1;
120 $k = 0;
121
122 while ($myrow = db_fetch($result))
123 {
124
125
126         // check if it's an overdue work order
127         if (!$myrow["closed"] && date_diff(Today(), sql2date($myrow["required_by"]), "d") > 0)
128         {
129                 start_row("class='overduebg'");
130         }
131         else
132                 alt_table_row_color($k);
133
134         $dec = get_qty_dec($myrow["stock_id"]);
135         label_cell(get_trans_view_str(systypes::work_order(), $myrow["id"]));
136         label_cell(get_trans_view_str(systypes::work_order(), $myrow["id"], $myrow["wo_ref"]));
137         label_cell(wo_types::name($myrow["type"]));
138         label_cell($myrow["location_name"]);
139         view_stock_status_cell($myrow["stock_id"], $myrow["description"]);
140         qty_cell($myrow["units_reqd"], false, $dec);
141         qty_cell($myrow["units_issued"], false, $dec);
142         label_cell(sql2date($myrow["date_"]));
143         label_cell(sql2date($myrow["required_by"]));
144
145         $l1 = $l2 = $l3 = $l4 = '';
146         if ($myrow["closed"] == 0)
147         {
148                 $modify_page = $path_to_root . "/manufacturing/work_order_entry.php?" . SID . "trans_no=" . $myrow["id"];
149                 $l1 = "<a href=$modify_page>"._('Edit').'</a>';
150                 if ($myrow["released"] == 0) 
151                 {
152                         $release_page = $path_to_root . "/manufacturing/work_order_release.php?" . SID . "trans_no=" . $myrow["id"];
153                         $l2 = "<a href=$release_page>"._('Release').'</a>';
154                 } 
155                 else 
156                 {
157                         $issue = $path_to_root . "/manufacturing/work_order_issue.php?" . SID . "trans_no=" .$myrow["id"];
158                         $add_finished = $path_to_root . "/manufacturing/work_order_add_finished.php?" . SID . "trans_no=" .$myrow["id"];
159                         $costs = $path_to_root . "/gl/gl_bank.php?NewPayment=1&PayType=" . payment_person_types::WorkOrder(). "&PayPerson=" .$myrow["id"];
160                         $l2 = "<a href=$issue>" . _("Issue") . "</a>";
161                         $l3 = "<a href=$add_finished>" . _("Produce") . "</a>";
162                         $l4 = "<a href=$costs>" . _("Costs") . "</a>";
163                 }
164         }
165         else
166         {
167                 $l1 = "<i>"._('Closed')."</i>";
168         }
169         label_cell($l1);
170         label_cell($l2);
171         label_cell($l3);
172         label_cell($l4);
173         label_cell(get_gl_view_str(systypes::work_order(), $myrow["id"]));
174
175         end_row();
176
177         $j++;
178         If ($j == 12)
179         {
180                 $j = 1;
181                 table_header($th);
182         }
183         //end of page full new headings if
184 }
185 //end of while loop
186
187 end_table(1);
188 div_end();
189 //---------------------------------------------------------------------------------
190
191 end_page();
192
193 ?>