Eliminated non-static method calls and other bulk fixes to fix php5 warnings
[fa-stable.git] / manufacturing / search_work_orders.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_MANUFTRANSVIEW';
13 $path_to_root = "..";
14 include($path_to_root . "/includes/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
16
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
19 $js = "";
20 if ($use_popup_windows)
21         $js .= get_js_open_window(800, 500);
22 if (isset($_GET['outstanding_only']) && ($_GET['outstanding_only'] == true))
23 {
24 // curently outstanding simply means not closed
25         $outstanding_only = 1;
26         page(_("Search Outstanding Work Orders"), false, false, "", $js);
27 }
28 else
29 {
30         $outstanding_only = 0;
31         page(_("Search Work Orders"), false, false, "", $js);
32 }
33 //-----------------------------------------------------------------------------------
34 // Ajax updates
35 //
36 if (get_post('SearchOrders')) 
37 {
38         $Ajax->activate('orders_tbl');
39 } elseif (get_post('_OrderNumber_changed')) 
40 {
41         $disable = get_post('OrderNumber') !== '';
42
43         $Ajax->addDisable(true, 'StockLocation', $disable);
44         $Ajax->addDisable(true, 'OverdueOnly', $disable);
45         $Ajax->addDisable(true, 'OpenOnly', $disable);
46         $Ajax->addDisable(true, 'SelectedStockItem', $disable);
47
48         if ($disable) {
49                 set_focus('OrderNumber');
50         } else
51                 set_focus('StockLocation');
52
53         $Ajax->activate('orders_tbl');
54 }
55
56 //--------------------------------------------------------------------------------------
57
58 if (isset($_GET["stock_id"]))
59         $_POST['SelectedStockItem'] = $_GET["stock_id"];
60
61 //--------------------------------------------------------------------------------------
62
63 start_form(false, false, $_SERVER['PHP_SELF'] ."?outstanding_only=$outstanding_only");
64
65 start_table("class='tablestyle_noborder'");
66 start_row();
67 ref_cells(_("Reference:"), 'OrderNumber', '',null, '', true);
68
69 locations_list_cells(_("at Location:"), 'StockLocation', null, true);
70
71 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
72
73 if ($outstanding_only==0)
74         check_cells( _("Only Open:"), 'OpenOnly', null);
75
76 stock_manufactured_items_list_cells(_("for item:"), 'SelectedStockItem', null, true);
77
78 submit_cells('SearchOrders', _("Search"),'',_('Select documents'),  'default');
79 end_row();
80 end_table();
81
82 end_form();
83
84 //-----------------------------------------------------------------------------
85 function check_overdue($row)
86 {
87         return (!$row["closed"] 
88                 && date_diff2(Today(), sql2date($row["required_by"]), "d") > 0);
89 }
90
91 function view_link($dummy, $order_no)
92 {
93         return get_trans_view_str(ST_WORKORDER, $order_no);
94 }
95
96 function view_stock($row)
97 {
98         return view_stock_status($row["stock_id"], $row["description"], false);
99 }
100
101 function wo_type_name($dummy, $type)
102 {
103         global $wo_types_array;
104         
105         return $wo_types_array[$type];
106 }
107
108 function edit_link($row)
109 {
110         return  $row['closed'] ? '<i>'._('Closed').'</i>' :
111                 pager_link(_("Edit"),
112                         "/manufacturing/work_order_entry.php?trans_no=" . $row["id"], ICON_EDIT);
113 }
114
115 function release_link($row)
116 {
117         return $row["closed"] ? '' : 
118                 ($row["released"]==0 ?
119                 pager_link(_('Release'),
120                         "/manufacturing/work_order_release.php?trans_no=" . $row["id"])
121                 : 
122                 pager_link(_('Issue'),
123                         "/manufacturing/work_order_issue.php?trans_no=" .$row["id"]));
124 }
125
126 function produce_link($row)
127 {
128         return $row["closed"] || !$row["released"] ? '' :
129                 pager_link(_('Produce'),
130                         "/manufacturing/work_order_add_finished.php?trans_no=" .$row["id"]);
131 }
132
133 function costs_link($row)
134 {
135 /*
136         return $row["closed"] || !$row["released"] ? '' :
137                 pager_link(_('Costs'),
138                         "/gl/gl_bank.php?NewPayment=1&PayType=" 
139                         .PT_WORKORDER. "&PayPerson=" .$row["id"]);
140 */                      
141         return $row["closed"] || !$row["released"] ? '' :
142                 pager_link(_('Costs'),
143                         "/manufacturing/work_order_costs.php?trans_no=" .$row["id"]);
144 }
145
146 function view_gl_link($row)
147 {
148         if ($row['closed'] == 0)
149                 return '';
150         return get_gl_view_str(ST_WORKORDER, $row['id']);
151 }
152
153 function dec_amount($row, $amount)
154 {
155         return number_format2($amount, $row['decimals']);
156 }
157
158 $sql = "SELECT
159         workorder.id,
160         workorder.wo_ref,
161         workorder.type,
162         location.location_name,
163         item.description,
164         workorder.units_reqd,
165         workorder.units_issued,
166         workorder.date_,
167         workorder.required_by,
168         workorder.released_date,
169         workorder.closed,
170         workorder.released,
171         workorder.stock_id,
172         unit.decimals
173         FROM ".TB_PREF."workorders as workorder,"
174                 .TB_PREF."stock_master as item,"
175                 .TB_PREF."item_units as unit,"
176                 .TB_PREF."locations as location
177         WHERE workorder.stock_id=item.stock_id 
178                 AND workorder.loc_code=location.loc_code
179                 AND item.units=unit.abbr";
180
181 if (check_value('OpenOnly') || $outstanding_only != 0)
182 {
183         $sql .= " AND workorder.closed=0";
184 }
185
186 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
187 {
188         $sql .= " AND workorder.loc_code='" . $_POST['StockLocation'] . "' ";
189 }
190
191 if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
192 {
193         $sql .= " AND workorder.wo_ref LIKE '%". $_POST['OrderNumber'] . "%'";
194 }
195
196 if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items)
197 {
198         $sql .= " AND workorder.stock_id='". $_POST['SelectedStockItem'] . "'";
199 }
200
201 if (check_value('OverdueOnly'))
202 {
203         $Today = date2sql(Today());
204
205         $sql .= " AND workorder.required_by < '$Today' ";
206 }
207
208 $cols = array(
209         _("#") => array('fun'=>'view_link'), 
210         _("Reference"), // viewlink 2 ?
211         _("Type") => array('fun'=>'wo_type_name'),
212         _("Location"), 
213         _("Item") => array('fun'=>'view_stock'),
214         _("Required") => array('fun'=>'dec_amount', 'align'=>'right'),
215         _("Manufactured") => array('fun'=>'dec_amount', 'align'=>'right'),
216         _("Date") => 'date', 
217         _("Required By") => array('type'=>'date', 'ord'=>''),
218         array('insert'=>true, 'fun'=> 'edit_link'),
219         array('insert'=>true, 'fun'=> 'release_link'),
220         array('insert'=>true, 'fun'=> 'produce_link'),
221         array('insert'=>true, 'fun'=> 'costs_link'),
222         array('insert'=>true, 'fun'=> 'view_gl_link')
223 );
224
225 $table =& new_db_pager('orders_tbl', $sql, $cols);
226 $table->set_marker('check_overdue', _("Marked orders are overdue."));
227
228 if (get_post('SearchOrders')) {
229         $table->set_sql($sql);
230         $table->set_columns($cols);
231 }
232 $table->width = "90%";
233 start_form();
234
235 display_db_pager($table);
236
237 end_form();
238 end_page();
239 ?>