- // clear the requirements units received
- void_wo_requirements($woid);
- }
- else
- {
- // void everything inside the work order : issues, productions, payments
- $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");