[0004212] Work Order Entry: fixed error when voided WO refence is reused.
[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 ($SysPrefs->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(_($help_context = "Search Outstanding Work Orders"), false, false, "", $js);
27 }
28 else
29 {
30         $outstanding_only = 0;
31         page(_($help_context = "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(TABLESTYLE_NOBORDER);
66 start_row();
67 ref_cells(_("#:"), 'OrderId', '',null, '', true);
68 ref_cells(_("Reference:"), 'OrderNumber', '',null, '', true);
69
70 locations_list_cells(_("at Location:"), 'StockLocation', null, true);
71
72 end_row();
73 end_table();
74 start_table(TABLESTYLE_NOBORDER);
75 start_row();
76
77 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
78
79 if ($outstanding_only==0)
80         check_cells( _("Only Open:"), 'OpenOnly', null);
81
82 stock_manufactured_items_list_cells(_("for item:"), 'SelectedStockItem', null, true);
83
84 submit_cells('SearchOrders', _("Search"),'',_('Select documents'),  'default');
85 end_row();
86 end_table();
87
88 //-----------------------------------------------------------------------------
89 function check_overdue($row)
90 {
91         return (!$row["closed"] 
92                 && date_diff2(Today(), sql2date($row["required_by"]), "d") > 0);
93 }
94
95 function view_link($dummy, $order_no)
96 {
97         return get_trans_view_str(ST_WORKORDER, $order_no);
98 }
99
100 function view_stock($row)
101 {
102         return view_stock_status($row["stock_id"], $row["description"], false);
103 }
104
105 function wo_type_name($dummy, $type)
106 {
107         global $wo_types_array;
108         
109         return $wo_types_array[$type];
110 }
111
112 function edit_link($row)
113 {
114         return  $row['closed'] ? '<i>'._('Closed').'</i>' :
115                 trans_editor_link(ST_WORKORDER, $row["id"]);
116 }
117
118 function release_link($row)
119 {
120         return $row["closed"] ? '' : 
121                 ($row["released"]==0 ?
122                 pager_link(_('Release'),
123                         "/manufacturing/work_order_release.php?trans_no=" . $row["id"])
124                 : 
125                 pager_link(_('Issue'),
126                         "/manufacturing/work_order_issue.php?trans_no=" .$row["id"]));
127 }
128
129 function produce_link($row)
130 {
131         return $row["closed"] || !$row["released"] ? '' :
132                 pager_link(_('Produce'),
133                         "/manufacturing/work_order_add_finished.php?trans_no=" .$row["id"]);
134 }
135
136 function costs_link($row)
137 {
138         return $row["closed"] || !$row["released"] ? '' :
139                 pager_link(_('Costs'),
140                         "/manufacturing/work_order_costs.php?trans_no=" .$row["id"]);
141 }
142
143 function view_gl_link($row)
144 {
145         return get_gl_view_str(ST_WORKORDER, $row['id']);
146 }
147
148 function dec_amount($row, $amount)
149 {
150         return number_format2($amount, $row['decimals']);
151 }
152
153 $sql = get_sql_for_work_orders($outstanding_only, get_post('SelectedStockItem'), get_post('StockLocation'),
154         get_post('OrderId'), get_post('OrderNumber'), check_value('OverdueOnly'));
155
156 $cols = array(
157         _("#") => array('fun'=>'view_link', 'ord'=>''), 
158         _("Reference"), // viewlink 2 ?
159         _("Type") => array('fun'=>'wo_type_name'),
160         _("Location"), 
161         _("Item") => array('fun'=>'view_stock', 'ord'=>''),
162         _("Required") => array('fun'=>'dec_amount', 'align'=>'right'),
163         _("Manufactured") => array('fun'=>'dec_amount', 'align'=>'right'),
164         _("Date") => array('name'=>'date_', 'type'=>'date', 'ord'=>'desc'), 
165         _("Required By") => array('type'=>'date', 'ord'=>''),
166         array('insert'=>true, 'fun'=> 'edit_link'),
167         array('insert'=>true, 'fun'=> 'release_link'),
168         array('insert'=>true, 'fun'=> 'costs_link'),
169         array('insert'=>true, 'fun'=> 'produce_link'),
170         array('insert'=>true, 'fun'=> 'view_gl_link')
171 );
172
173 $table =& new_db_pager('orders_tbl', $sql, $cols);
174 $table->set_marker('check_overdue', _("Marked orders are overdue."));
175
176 $table->width = "90%";
177
178 display_db_pager($table);
179
180 end_form();
181 end_page();