+ begin_transaction();
+ hook_db_prevoid(ST_WORKORDER, $woid);
+
+ $work_order = get_work_order($woid);
+
+ if ($work_order['closed'])
+ reopen_work_order($woid);
+
+ if ($work_order['units_issued'])
+ {
+ $prods = get_work_order_productions($woid);
+ while ($prod = db_fetch($prods))
+ void_work_order_produce($prod['id']);
+ }
+
+ // void addtional material issues
+ $issues = get_work_order_issues($woid);
+ while($issue = db_fetch($issues))
+ void_work_order_issue($issue['issue_no']);
+
+ // void all related stock moves
+ void_stock_move(ST_WORKORDER, $woid);
+
+ // void any related costing records
+ void_wo_costing($woid);
+
+ // clear the requirements units received
+ void_wo_requirements($woid);
+
+ // close workorder
+ // FIXME: due to bug in 2.4 db scheme (conflicting wo_ref unique key) we have to fix wo_ref here:
+ $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0, wo_ref=CONCAT(wo_ref, ' ', '".uniqid()."') WHERE id = "
+ .db_escape($woid);
+ db_query($sql, "The work order couldn't be voided");
+
+ commit_transaction();
+}
+
+function get_sql_for_work_orders($outstanding_only, $stock_id, $location = ALL_TEXT, $order_no='', $order_ref = '', $overdue = false)
+{
+ $sql = "SELECT
+ workorder.id,
+ workorder.wo_ref,
+ workorder.type,
+ location.location_name,
+ item.description,
+ workorder.units_reqd,
+ workorder.units_issued,
+ workorder.date_,
+ workorder.required_by,
+ workorder.released_date,
+ workorder.closed,
+ workorder.released,
+ workorder.stock_id,
+ unit.decimals
+ FROM ".TB_PREF."workorders as workorder,"
+ .TB_PREF."stock_master as item,"
+ .TB_PREF."item_units as unit,"
+ .TB_PREF."locations as location
+ WHERE workorder.stock_id=item.stock_id
+ AND workorder.loc_code=location.loc_code
+ AND item.units=unit.abbr";
+
+ if (check_value('OpenOnly') || $outstanding_only != 0)
+ {
+ $sql .= " AND workorder.closed=0";
+ }
+
+ if ($location != ALL_TEXT)
+ {
+ $sql .= " AND workorder.loc_code=".db_escape($location);
+ }
+
+ if ($order_no != '')
+ {
+ $sql .= " AND workorder.id LIKE ".db_escape('%'.$order_no.'%');
+ }
+
+ if ($order_ref != '')