function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $workcentre,
$date_, $memo_)
{
+ global $Refs;
+
begin_transaction();
+ $args = func_get_args();
+ $args = (object)array_combine(array('woid', 'ref', 'to_work_order', 'items', 'location',
+ 'workcentre', 'date_', 'memo_'), $args);
+ $args->trans_no = 0;
+ hook_db_prewrite($args, ST_MANUISSUE);
$details = get_work_order($woid);
$number = db_insert_id();
+ $issue_total = $total_cost = 0;
+
foreach ($items as $item)
{
if ($to_work_order)
$item->quantity = -$item->quantity;
+ //Chaitanya: Stamp the standard_cost\r
+ $standard_cost = get_standard_cost($item->stock_id);\r
// insert a -ve stock move for each item
- add_stock_move(28, $item->stock_id, $number,
- $location, $date_, $memo_, -$item->quantity, 0);
+ add_stock_move(ST_MANUISSUE, $item->stock_id, $number,
+ $location, $date_, $memo_, -$item->quantity, $standard_cost);\r
$sql = "INSERT INTO ".TB_PREF."wo_issue_items (issue_id, stock_id, qty_issued)
VALUES (".db_escape($number).", ".db_escape($item->stock_id).", "
.db_escape($item->quantity).")";
db_query($sql,"A work order issue item could not be added");
- }
+
+ $standard_cost = get_standard_cost($item->stock_id);
+ $issue_cost = $standard_cost * $item->quantity;
+ $issue = get_stock_gl_code($item->stock_id);
+ $stockitem = get_item($item->stock_id);
+ \r
+ //Chaitanya : Compatibility for Service Items\r
+ if (!is_service($issue["mb_flag"]))\r
+ $ivaccount = $issue["inventory_account"];\r
+ else\r
+ $ivaccount = $issue["cogs_account"]; \r
+ \r
+ $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,\r
+ $date_.": "._("Issue of")." ".$stockitem["description"], -$issue_cost);
+ $issue_total += $issue_cost;
+ }
+ if ($issue_total != 0)
+ //Chaitanya : Apply cost to QOH as adjustment only\r
+ add_issue_cost($details['stock_id'], $details['units_reqd'], $date_, $issue_total, true);\r
+ $issue = get_stock_gl_code($details['stock_id']);
+ $stockitem = get_item($details['stock_id']);
+ add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $issue["inventory_account"],
+ 0, 0, $date_.": "._("Issue to")." ".$stockitem["description"], -$total_cost);
if ($memo_)
- add_comments(28, $number, $date_, $memo_);
+ add_comments(ST_MANUISSUE, $number, $date_, $memo_);
- references::save_last($ref, 28);
+ $Refs->save(ST_MANUISSUE, $number, $ref);
+ add_audit_trail(ST_MANUISSUE, $number, $date_);
+ $args->trans_no = $number;
+ hook_db_postwrite($args, ST_MANUISSUE);
commit_transaction();
}
function void_work_order_issue($type_no)
{
begin_transaction();
+ hook_db_prevoid(ST_MANUISSUE, $type_no);
+ \r
+ //Chaitanya : Skip processing already voided entry i.e. explicitly voided\r
+ $void_entry = get_voided_entry(ST_MANUISSUE, $type_no);\r
+ if ($void_entry)\r
+ return;\r
// void the actual issue items and their quantities
$sql = "UPDATE ".TB_PREF."wo_issue_items Set qty_issued = 0 WHERE issue_id="
.db_escape($type_no);
db_query($sql,"A work order issue item could not be voided");
- // void all related stock moves
- void_stock_move(28, $type_no);
-
- // void any related gl trans
- void_gl_trans(28, $type_no, true);
-
+ // void any related gl trans\r
+ //Chaitanya : Nothing happens due to next statement as all gl postings are done against WO\r
+ //void_gl_trans(ST_MANUISSUE, $type_no, true);\r
+ \r
+ //Chaitanya : Reverse the gl posting\r
+ $issue = get_work_order_issue($type_no);\r
+ $manf_stock_id = $issue["stock_id"];\r
+ $date_ = sql2date($issue["issue_date"]);\r
+ $woid = $issue["workorder_id"];\r
+ \r
+ $result = get_stock_moves(ST_MANUISSUE, $type_no);\r
+ $total_cost = 0;\r
+ $issue_total = 0;\r
+ while ($myrow = db_fetch($result))\r
+ {\r
+ $issue_cost = $myrow["qty"]*$myrow["standard_cost"];\r
+ $issue = get_stock_gl_code($myrow["stock_id"]);\r
+ $stockitem = get_item($myrow["stock_id"]);\r
+ \r
+ //Chaitanya : Compatibility for Service Items\r
+ if (!is_service($issue["mb_flag"]))\r
+ $ivaccount = $issue["inventory_account"];\r
+ else\r
+ $ivaccount = $issue["cogs_account"]; \r
+ \r
+ if ($issue_cost != 0)\r
+ {\r
+ $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,\r
+ $date_.": "._("Reversed the issue of")." ".$stockitem["description"],\r
+ -$issue_cost); \r
+ $issue_total += $issue_cost;\r
+ }\r
+ }\r
+ if ($issue_total != 0)\r
+ //Chaitanya : Revese cost effect on manfactured stock item as adjustment only\r
+ add_issue_cost($manf_stock_id, 0, $date_, $issue_total, true);\r
+ $issue = get_stock_gl_code($manf_stock_id);\r
+ $stockitem = get_item($manf_stock_id);\r
+ if ($total_cost != 0)\r
+ add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $issue["inventory_account"],\r
+ 0, 0, $date_.": "._("Reversed the issue to")." ".$stockitem["description"], \r
+ -$total_cost); \r
+ \r
+ //Chaitanya : Shifted below void all related stock moves\r
+ void_stock_move(ST_MANUISSUE, $type_no);
+ \r
commit_transaction();
}