+ $date = sql2date($work_order['date_']);
+ \r
+ //Chaitanya : Removed WO costing from here. Handled in void_stock_move\r
+ //Reason - if BOM is changed since WO was executed then add_material_cost will result in incorrect costing as it is based on current BOM for material cost.\r
+ //add_material_cost($work_order['stock_id'], -$work_order['units_reqd'], $date); // remove avg. cost for qty\r
+ \r
+ $result = get_work_order_productions($woid); // check the produced quantity
+ $qty = 0;
+ while ($row = db_fetch($result))
+ {
+ //Chaitanya : Use native function for voiding\r
+ void_work_order_produce($row['id']);\r
+ \r
+ //Post voided entry if not prevoided explicitly\r
+ $void_entry = get_voided_entry(ST_MANURECEIVE, $row['id']);\r
+ if ($void_entry)\r
+ continue;\r
+ $memo_ = _("Voiding Work Order Trans # ").$woid;\r
+ add_audit_trail(ST_MANURECEIVE, $row['id'], today(), _("Voided.")."\n".$memo_);\r
+ add_voided_entry(ST_MANURECEIVE, $row['id'], today(), $memo_); \r
+ \r
+ /*$qty += $row['quantity'];\r
+ // clear the production record
+ $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=".$row['id'];\r
+ db_query($sql, "Cannot void a wo production");
+
+ void_stock_move(ST_MANURECEIVE, $row['id']); // and void the stock moves; */\r
+ }
+ //Chaitanya : Get all work order issues\r
+ //$result = get_additional_issues($woid); // check the issued quantities\r
+ $result = get_work_order_issues($woid);\r
+ $cost = 0;
+ $issue_no = 0;
+ while ($row = db_fetch($result))
+ {
+ //Chaitanya : Use native function for voiding\r
+ void_work_order_issue($row['issue_no']);\r
+ \r
+ //Post voided entry if not prevoided explicitly\r
+ $void_entry = get_voided_entry(ST_MANUISSUE, $row['issue_no']);\r
+ if ($void_entry)\r
+ continue;\r
+ $memo_ = _("Voiding Work Order Trans # ").$woid;\r
+ add_audit_trail(ST_MANUISSUE, $row['issue_no'], today(), _("Voided.")."\n".$memo_);\r
+ add_voided_entry(ST_MANUISSUE, $row['issue_no'], today(), $memo_); \r
+ \r
+ /*$std_cost = get_standard_cost($row['stock_id']);\r
+ $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");*/ \r
+ }\r
+ \r
+ //Chaitaya : Voiding each issue handles the \r
+ //if ($issue_no != 0)\r
+ //void_stock_move(ST_MANUISSUE, $issue_no); // and void the stock moves \r
+ //if ($cost != 0)\r
+ //add_issue_cost($work_order['stock_id'], -$qty, $date, $cost);\r
+
+ //Chaitanya : Reverse the cost effects on $work_order['stock_id'] as adjustement\r
+ $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);\r
+ add_labour_cost($work_order['stock_id'], 1, $date, -$cost, true);\r
+ $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);\r
+ add_overhead_cost($work_order['stock_id'], 1, $date, -$cost, true);\r
+
+ $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 any related gl trans
+ void_gl_trans(ST_WORKORDER, $woid, true);
+
+ // clear the requirements units received
+ void_wo_requirements($woid);