{
global $Refs;
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$args = func_get_args();
$args = (object)array_combine(array('woid', 'ref', 'to_work_order', 'items', 'location',
'workcentre', 'date_', 'memo_'), $args);
foreach ($items as $item)
{
-
- if ($to_work_order)
+ if ($to_work_order) // otherwise it is material return to inventory
$item->quantity = -$item->quantity;
- // Stamp the standard_cost
- $standard_cost = get_standard_cost($item->stock_id);
+ $unit_cost = get_unit_cost($item->stock_id);
// insert a -ve stock move for each item
add_stock_move(ST_MANUISSUE, $item->stock_id, $number,
- $location, $date_, $memo_, -$item->quantity, $standard_cost);
+ $location, $date_, $memo_, -$item->quantity, $unit_cost);
$sql = "INSERT INTO ".TB_PREF."wo_issue_items (issue_id, stock_id, qty_issued, unit_cost)
SELECT ".db_escape($number).",".db_escape($item->stock_id).",".db_escape($item->quantity).", material_cost
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;
+ $unit_cost = get_unit_cost($item->stock_id);
+ $issue_cost = $unit_cost * $item->quantity;
$stockitem = get_item($item->stock_id);
if (!is_service($stockitem["mb_flag"]))
$ivaccount = $stockitem["inventory_account"];
else
- $ivaccount = $stockitem["assembly_account"];
+ $ivaccount = $stockitem["cogs_account"];
- $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
+ $total_cost += add_gl_trans_std_cost(ST_MANUISSUE, $number, $date_, $ivaccount, 0, 0,
$date_.": "._("Issue of")." ".$stockitem["description"], -$issue_cost);
- $issue_total += $issue_cost;
}
- if ($issue_total != 0) // Apply cost to QOH as adjustment only
- add_issue_cost($wo['stock_id'], $wo['units_reqd'], $date_, $issue_total, true);
-
$stockitem = get_item($wo['stock_id']);
- $wip_account = get_company_pref('wip_act');
- if (!$wip_account) // backward compatibility
- $wip_account = $stockitem["inventory_account"];
+ $wip_account = $stockitem["wip_account"];
- add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $wip_account,
+ add_gl_trans_std_cost(ST_MANUISSUE, $number, $date_, $wip_account,
0, 0, $date_.": "._("Issue to")." ".$stockitem["description"], -$total_cost);
if ($memo_)
function get_additional_issues($woid)
{
- $sql = "SELECT issue.*, item.*
+ $sql = "SELECT issue.*, item.*, stock.mb_flag
FROM ".TB_PREF."wo_issues issue, "
.TB_PREF."wo_issue_items item
+ LEFT JOIN ".TB_PREF."stock_master stock ON stock.stock_id=item.stock_id
WHERE issue.issue_no=item.issue_id
AND issue.workorder_id=".db_escape($woid)
." ORDER BY item.id";
function get_work_order_issue($issue_no)
{
- $sql = "SELECT DISTINCT issue.*, wo.stock_id,
+ $sql = "SELECT DISTINCT issue.*, wo.stock_id, wo.closed,
item.description, loc.location_name, center.name AS WorkCentreName
FROM ".TB_PREF."wo_issues issue,"
.TB_PREF."workorders wo,"
//--------------------------------------------------------------------------------------
+function check_void_wo_issue($issue_no)
+{
+ $issue = get_work_order_issue($issue_no);
+
+ return $issue['closed'] ? $issue['workorder_id'] : 0;
+}
+
+//--------------------------------------------------------------------------------------
+
function void_work_order_issue($type_no)
{
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
hook_db_prevoid(ST_MANUISSUE, $type_no);
- //Chaitanya : Skip processing already voided entry i.e. explicitly voided
$void_entry = get_voided_entry(ST_MANUISSUE, $type_no);
if ($void_entry)
return;
+ if (check_void_wo_issue($type_no))
+ return;
+
+ // FIXME update issued material cost
+
// 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");
+ $sql = "UPDATE ".TB_PREF."wo_issue_items SET qty_issued = 0
+ WHERE issue_id=".db_escape($type_no);
- // Reverse the gl posting
- $issue = get_work_order_issue($type_no);
- $manf_stock_id = $issue["stock_id"];
- $date_ = sql2date($issue["issue_date"]);
- $woid = $issue["workorder_id"];
+ db_query($sql,"A work order issue item could not be voided");
- $result = get_stock_moves(ST_MANUISSUE, $type_no);
- $total_cost = 0;
- $issue_total = 0;
- while ($myrow = db_fetch($result))
- {
- $issue_cost = $myrow["qty"]*$myrow["standard_cost"];
- $issue = get_stock_gl_code($myrow["stock_id"]);
- $stockitem = get_item($myrow["stock_id"]);
+ void_gl_trans(ST_MANUISSUE, $type_no);
- // Compatibility for Service Items
- if (!is_service($issue["mb_flag"]))
- $ivaccount = $issue["inventory_account"];
- else
- $ivaccount = $issue["assembly_account"];
-
- if ($issue_cost != 0)
- {
- $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
- $date_.": "._("Reversed the issue of")." ".$stockitem["description"],
- -$issue_cost);
- $issue_total += $issue_cost;
- }
- }
- if ($issue_total != 0)
- // Revese cost effect on manfactured stock item as adjustment only
- add_issue_cost($manf_stock_id, 0, $date_, $issue_total, true);
- $issue = get_stock_gl_code($manf_stock_id);
- $stockitem = get_item($manf_stock_id);
- if ($total_cost != 0)
- add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $issue["inventory_account"],
- 0, 0, $date_.": "._("Reversed the issue to")." ".$stockitem["description"],
- -$total_cost);
-
- // Shifted below void all related stock moves
void_stock_move(ST_MANUISSUE, $type_no);
commit_transaction();
}
-
-
-//--------------------------------------------------------------------------------------
-