+ $date = sql2date($work_order['date_']);
+ add_material_cost($work_order['stock_id'], -$work_order['units_reqd'], $date); // remove avg. cost for qty
+ $result = get_work_order_productions($woid); // check the produced quantity
+ $qty = 0;
+ while ($row = db_fetch($result))
+ {
+ $qty += $row['quantity'];
+ // clear the production record
+ $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=".$$row['id'];
+ db_query($sql, "Cannot void a wo production");
+
+ void_stock_move(ST_MANURECEIVE, $row['id']); // and void the stock moves;
+ }
+ $result = get_additional_issues($woid); // check the issued quantities
+ $cost = 0;
+ $issue_no = 0;
+ while ($row = db_fetch($result))
+ {
+ $std_cost = get_standard_cost($row['stock_id']);
+ $icost = $std_cost * $row['qty_issued'];
+ $cost += $icost;
+ if ($issue_no == 0)
+ $issue_no = $row['issue_no'];
+ // void the actual issue items and their quantities
+ $sql = "UPDATE ".TB_PREF."wo_issue_items SET qty_issued = 0 WHERE issue_id="
+ .db_escape($row['id']);
+ db_query($sql,"A work order issue item could not be voided");
+ }
+ if ($issue_no != 0)
+ void_stock_move(ST_MANUISSUE, $issue_no); // and void the stock moves
+ if ($cost != 0)
+ add_issue_cost($work_order['stock_id'], -$qty, $date, $cost);
+
+ $cost = get_gl_wo_cost($woid, WO_LABOUR); // get the labour cost and reduce avg cost
+ if ($cost != 0)
+ add_labour_cost($work_order['stock_id'], -$qty, $date, $cost);
+ $cost = get_gl_wo_cost($woid, WO_OVERHEAD); // get the overhead cost and reduce avg cost
+ if ($cost != 0)
+ add_overhead_cost($work_order['stock_id'], -$qty, $date, $cost);
+
+ $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0 WHERE id = "
+ .db_escape($woid);
+ db_query($sql, "The work order couldn't be voided");
+
+ // void all related stock moves
+ void_stock_move(ST_WORKORDER, $woid);
+
+ void_wo_costing($wo);
+
+ // clear the requirements units received
+ void_wo_requirements($woid);
+ }
+ commit_transaction();
+}
+
+function get_sql_for_work_orders($outstanding_only, $all_items)
+{
+ $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 (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
+ {
+ $sql .= " AND workorder.loc_code=".db_escape($_POST['StockLocation']);
+ }
+
+ if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
+ {
+ $sql .= " AND workorder.wo_ref LIKE ".db_escape('%'.$_POST['OrderNumber'].'%');