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 ***********************************************************************/
14 include($path_to_root . "/includes/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
20 if ($use_popup_windows)
21 $js .= get_js_open_window(800, 500);
22 if (isset($_GET['outstanding_only']) && ($_GET['outstanding_only'] == true))
24 // curently outstanding simply means not closed
25 $outstanding_only = 1;
26 page(_("Search Outstanding Work Orders"), false, false, "", $js);
30 $outstanding_only = 0;
31 page(_("Search Work Orders"), false, false, "", $js);
33 //-----------------------------------------------------------------------------------
36 if (get_post('SearchOrders'))
38 $Ajax->activate('orders_tbl');
39 } elseif (get_post('_OrderNumber_changed'))
41 $disable = get_post('OrderNumber') !== '';
43 $Ajax->addDisable(true, 'StockLocation', $disable);
44 $Ajax->addDisable(true, 'OverdueOnly', $disable);
45 $Ajax->addDisable(true, 'OpenOnly', $disable);
46 $Ajax->addDisable(true, 'SelectedStockItem', $disable);
49 set_focus('OrderNumber');
51 set_focus('StockLocation');
53 $Ajax->activate('orders_tbl');
56 //--------------------------------------------------------------------------------------
58 if (isset($_GET["stock_id"]))
59 $_POST['SelectedStockItem'] = $_GET["stock_id"];
61 //--------------------------------------------------------------------------------------
63 start_form(false, false, $_SERVER['PHP_SELF'] ."?outstanding_only=" . $outstanding_only .SID);
65 start_table("class='tablestyle_noborder'");
67 ref_cells(_("Reference:"), 'OrderNumber', '',null, '', true);
69 locations_list_cells(_("at Location:"), 'StockLocation', null, true);
71 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
73 if ($outstanding_only==0)
74 check_cells( _("Only Open:"), 'OpenOnly', null);
76 stock_manufactured_items_list_cells(_("for item:"), 'SelectedStockItem', null, true);
78 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), true);
84 //-----------------------------------------------------------------------------
85 function check_overdue($row)
87 return (!$row["closed"]
88 && date_diff(Today(), sql2date($row["required_by"]), "d") > 0);
91 function view_link($dummy, $order_no)
93 return get_trans_view_str(systypes::work_order(), $order_no);
96 function view_stock($row)
98 return view_stock_status($row["stock_id"], $row["description"], false);
101 function wo_type_name($dummy, $type)
103 return wo_types::name($type);
106 function edit_link($row)
108 return $row['closed'] ? '<i>'._('Closed').'</i>' :
109 pager_link(_("Edit"),
110 "/manufacturing/work_order_entry.php?trans_no=" . $row["id"], ICON_EDIT);
113 function release_link($row)
115 return $row["closed"] ? '' :
116 ($row["released"]==0 ?
117 pager_link(_('Release'),
118 "/manufacturing/work_order_release.php?trans_no=" . $row["id"])
120 pager_link(_('Issue'),
121 "/manufacturing/work_order_issue.php?trans_no=" .$row["id"]));
124 function produce_link($row)
126 return $row["closed"] || !$row["released"] ? '' :
127 pager_link(_('Produce'),
128 "/manufacturing/work_order_add_finished.php?trans_no=" .$row["id"]);
131 function costs_link($row)
133 return $row["closed"] || !$row["released"] ? '' :
134 pager_link(_('Costs'),
135 "/gl/gl_bank.php?NewPayment=1&PayType="
136 .payment_person_types::WorkOrder(). "&PayPerson=" .$row["id"]);
139 function view_gl_link($row)
141 if ($row['closed'] == 0)
143 return get_gl_view_str(systypes::work_order(), $row['id']);
146 function dec_amount($row, $amount)
148 return number_format2($amount, $row['decimals']);
155 location.location_name,
157 workorder.units_reqd,
158 workorder.units_issued,
160 workorder.required_by,
161 workorder.released_date,
166 FROM ".TB_PREF."workorders as workorder,"
167 .TB_PREF."stock_master as item,"
168 .TB_PREF."item_units as unit,"
169 .TB_PREF."locations as location
170 WHERE workorder.stock_id=item.stock_id
171 AND workorder.loc_code=location.loc_code
172 AND item.units=unit.abbr";
174 if (check_value('OpenOnly') || $outstanding_only != 0)
176 $sql .= " AND workorder.closed=0";
179 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
181 $sql .= " AND workorder.loc_code='" . $_POST['StockLocation'] . "' ";
184 if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
186 $sql .= " AND workorder.wo_ref LIKE '%". $_POST['OrderNumber'] . "%'";
189 if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items)
191 $sql .= " AND workorder.stock_id='". $_POST['SelectedStockItem'] . "'";
194 if (check_value('OverdueOnly'))
196 $Today = date2sql(Today());
198 $sql .= " AND workorder.required_by < '$Today' ";
202 _("#") => array('fun'=>'view_link'),
203 _("Reference"), // viewlink 2 ?
204 _("Type") => array('fun'=>'wo_type_name'),
206 _("Item") => array('fun'=>'view_stock'),
207 _("Required") => array('fun'=>'dec_amount', 'align'=>'right'),
208 _("Manufactured") => array('fun'=>'dec_amount', 'align'=>'right'),
210 _("Required By") => array('type'=>'date', 'ord'=>''),
211 array('insert'=>true, 'fun'=> 'edit_link'),
212 array('insert'=>true, 'fun'=> 'release_link'),
213 array('insert'=>true, 'fun'=> 'produce_link'),
214 array('insert'=>true, 'fun'=> 'costs_link'),
215 array('insert'=>true, 'fun'=> 'view_gl_link')
218 $table =& new_db_pager('orders_tbl', $sql, $cols);
219 $table->set_marker('check_overdue', _("Marked orders are overdue."));
221 if (get_post('SearchOrders')) {
222 $table->set_sql($sql);
223 $table->set_columns($cols);
225 $table->width = "90%";
228 display_db_pager($table);