Feature 5388: Print Invoices (documents) list gets too long. Fixed by default 180...
[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 include_once($path_to_root . "/reporting/includes/reporting.inc");
20
21 $js = "";
22 if ($SysPrefs->use_popup_windows)
23         $js .= get_js_open_window(800, 500);
24 if (isset($_GET['outstanding_only']) && ($_GET['outstanding_only'] == true))
25 {
26 // curently outstanding simply means not closed
27         $outstanding_only = 1;
28         page(_($help_context = "Search Outstanding Work Orders"), false, false, "", $js);
29 }
30 else
31 {
32         $outstanding_only = 0;
33         page(_($help_context = "Search Work Orders"), false, false, "", $js);
34 }
35 //-----------------------------------------------------------------------------------
36 // Ajax updates
37 //
38 if (get_post('SearchOrders')) 
39 {
40         $Ajax->activate('orders_tbl');
41 } elseif (get_post('_OrderNumber_changed')) 
42 {
43         $disable = get_post('OrderNumber') !== '';
44
45         $Ajax->addDisable(true, 'StockLocation', $disable);
46         $Ajax->addDisable(true, 'OverdueOnly', $disable);
47         $Ajax->addDisable(true, 'OpenOnly', $disable);
48         $Ajax->addDisable(true, 'SelectedStockItem', $disable);
49
50         if ($disable) {
51                 set_focus('OrderNumber');
52         } else
53                 set_focus('StockLocation');
54
55         $Ajax->activate('orders_tbl');
56 }
57
58 //--------------------------------------------------------------------------------------
59
60 if (isset($_GET["stock_id"]))
61         $_POST['SelectedStockItem'] = $_GET["stock_id"];
62
63 //--------------------------------------------------------------------------------------
64
65 start_form(false, false, $_SERVER['PHP_SELF'] ."?outstanding_only=$outstanding_only");
66
67 start_table(TABLESTYLE_NOBORDER);
68 start_row();
69 ref_cells(_("#:"), 'OrderId', '',null, '', true);
70 ref_cells(_("Reference:"), 'OrderNumber', '',null, '', true);
71
72 locations_list_cells(_("at Location:"), 'StockLocation', null, true);
73
74 end_row();
75 end_table();
76 start_table(TABLESTYLE_NOBORDER);
77 start_row();
78
79 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
80
81 if ($outstanding_only==0)
82         check_cells( _("Only Open:"), 'OpenOnly', null);
83
84 stock_manufactured_items_list_cells(_("for item:"), 'SelectedStockItem', null, true);
85
86 submit_cells('SearchOrders', _("Search"),'',_('Select documents'),  'default');
87 end_row();
88 end_table();
89
90 //-----------------------------------------------------------------------------
91 function check_overdue($row)
92 {
93         return (!$row["closed"] 
94                 && date_diff2(Today(), sql2date($row["required_by"]), "d") > 0);
95 }
96
97 function view_link($dummy, $order_no)
98 {
99         return get_trans_view_str(ST_WORKORDER, $order_no);
100 }
101
102 function view_stock($row)
103 {
104         return view_stock_status($row["stock_id"], $row["description"], false);
105 }
106
107 function wo_type_name($dummy, $type)
108 {
109         global $wo_types_array;
110         
111         return $wo_types_array[$type];
112 }
113
114 function edit_link($row)
115 {
116         return  $row['closed'] ? '<i>'._('Closed').'</i>' :
117                 trans_editor_link(ST_WORKORDER, $row["id"]);
118 }
119
120 function release_link($row)
121 {
122         return $row["closed"] ? '' : 
123                 ($row["released"]==0 ?
124                 pager_link(_('Release'),
125                         "/manufacturing/work_order_release.php?trans_no=" . $row["id"])
126                 : 
127                 pager_link(_('Issue'),
128                         "/manufacturing/work_order_issue.php?trans_no=" .$row["id"]));
129 }
130
131 function produce_link($row)
132 {
133         return $row["closed"] || !$row["released"] ? '' :
134                 pager_link(_('Produce'),
135                         "/manufacturing/work_order_add_finished.php?trans_no=" .$row["id"]);
136 }
137
138 function costs_link($row)
139 {
140         return $row["closed"] || !$row["released"] ? '' :
141                 pager_link(_('Costs'),
142                         "/manufacturing/work_order_costs.php?trans_no=" .$row["id"]);
143 }
144
145 function view_gl_link($row)
146 {
147         return get_gl_view_str(ST_WORKORDER, $row['id']);
148 }
149
150 function prt_link($row)
151 {
152         return print_document_link($row['id'], _("Print"), true, ST_WORKORDER, ICON_PRINT);
153 }
154
155 function dec_amount($row, $amount)
156 {
157         return number_format2($amount, $row['decimals']);
158 }
159
160 $sql = get_sql_for_work_orders($outstanding_only, get_post('SelectedStockItem'), get_post('StockLocation'),
161         get_post('OrderId'), get_post('OrderNumber'), check_value('OverdueOnly'));
162
163 $cols = array(
164         _("#") => array('fun'=>'view_link', 'ord'=>''), 
165         _("Reference"), // viewlink 2 ?
166         _("Type") => array('fun'=>'wo_type_name'),
167         _("Location"), 
168         _("Item") => array('fun'=>'view_stock', 'ord'=>''),
169         _("Required") => array('fun'=>'dec_amount', 'align'=>'right'),
170         _("Manufactured") => array('fun'=>'dec_amount', 'align'=>'right'),
171         _("Date") => array('name'=>'date_', 'type'=>'date', 'ord'=>'desc'), 
172         _("Required By") => array('type'=>'date', 'ord'=>''),
173         array('insert'=>true, 'fun'=> 'view_gl_link'),
174         array('insert'=>true, 'fun'=> 'edit_link'),
175         array('insert'=>true, 'fun'=> 'release_link'),
176         array('insert'=>true, 'fun'=> 'costs_link'),
177         array('insert'=>true, 'fun'=> 'produce_link'),
178         array('insert'=>true, 'fun'=> 'prt_link')
179 );
180
181 $table =& new_db_pager('orders_tbl', $sql, $cols);
182 $table->set_marker('check_overdue', _("Marked orders are overdue."));
183
184 $table->width = "90%";
185
186 display_db_pager($table);
187
188 end_form();
189 end_page();