$ /inventory/cost_update.php
/purchasing/includes/db/grn_db.inc and
/manufacturing/manage/bom_edit.php.
+ /manufacturing/includes/db/work_orders_db.inc
+ /manufacturing/includes/db/work_orders_quick_db.inc
+ /manufacturing/work_order_entry.php
21-Feb-2008 Joe Hunt
+ Added Print for documents in /admin/view_print_transaction.php (according to our new routines).
//--------------------------------------------------------------------------------------
-function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
+function add_material_cost($stock_id, $qty, $date_)
+{
+ $m_cost = 0;
+ $result = get_bom($stock_id);
+ while ($bom_item = db_fetch($result))
+ {
+ $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id = '".$bom_item['component']."'";
+ $res = db_query($sql);
+ $myrow = db_fetch($res);
+ $m_cost += ($bom_item['quantity'] * $myrow['material_cost']);
+ }
+ $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id = '$stock_id'";
+ $result = db_query($sql);
+ $myrow = db_fetch($result);
+ $material_cost = $myrow['material_cost'];
+ $qoh = get_qoh_on_date($stock_id, null, $date_);
+ if ($qoh + $qty <= 0)
+ $material_cost = 0;
+ else
+ $material_cost = ($qoh * $material_cost + $qty * $m_cost) / ($qoh + $qty);
+ $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost
+ WHERE stock_id='$stock_id'";
+ db_query($sql,"The cost details for the inventory item could not be updated");
+}
+
+function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
$type, $date_, $required_by, $costs, $memo_)
{
if (!($type == wo_types::advanced()))
return add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $costs, $memo_);
-
+
begin_transaction();
-
+
+ add_material_cost($stock_id, $units_reqd, $date_);
+
$date = date2sql($date_);
$required = date2sql($required_by);
-
- $sql = "INSERT INTO ".TB_PREF."workorders (wo_ref, loc_code, units_reqd, stock_id,
- type, date_, required_by)
- VALUES ('$wo_ref', '$loc_code', $units_reqd, '$stock_id',
+
+ $sql = "INSERT INTO ".TB_PREF."workorders (wo_ref, loc_code, units_reqd, stock_id,
+ type, date_, required_by)
+ VALUES ('$wo_ref', '$loc_code', $units_reqd, '$stock_id',
$type, '$date', '$required')";
db_query($sql, "could not add work order");
-
+
$woid = db_insert_id();
-
- add_comments(systypes::work_order(), $woid, $required_by, $memo_);
-
- add_forms_for_sys_type(systypes::work_order(), $woid);
-
- references::save_last($wo_ref, systypes::work_order());
-
- commit_transaction();
-
- return $woid;
+
+ add_comments(systypes::work_order(), $woid, $required_by, $memo_);
+
+ add_forms_for_sys_type(systypes::work_order(), $woid);
+
+ references::save_last($wo_ref, systypes::work_order());
+
+ commit_transaction();
+
+ return $woid;
}
//--------------------------------------------------------------------------------------
-function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
+function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
$date_, $required_by, $memo_)
{
begin_transaction();
-
+
+ add_material_cost($_POST['old_stk_id'], -$_POST['old_qty'], $date_);
+ add_material_cost($stock_id, $units_reqd, $date_);
+
$date = date2sql($date_);
$required = date2sql($required_by);
-
- $sql = "UPDATE ".TB_PREF."workorders SET loc_code='$loc_code',
+
+ $sql = "UPDATE ".TB_PREF."workorders SET loc_code='$loc_code',
units_reqd=$units_reqd, stock_id='$stock_id',
required_by='$required',
date_='$date'
- WHERE id = $woid";
+ WHERE id = $woid";
db_query($sql, "could not update work order");
-
- update_comments(systypes::work_order(), $woid, null, $memo_);
- commit_transaction();
+ update_comments(systypes::work_order(), $woid, null, $memo_);
+
+ commit_transaction();
}
function delete_work_order($woid)
{
begin_transaction();
-
+
+ add_material_cost($_POST['stock_id'], -$_POST['quantity'], $_POST['date_']);
+
// delete the work order requirements
delete_wo_requirements($woid);
-
+
// delete the actual work order
$sql = "DELETE FROM ".TB_PREF."workorders WHERE id=$woid";
db_query($sql,"The work order could not be deleted");
-
+
delete_comments(systypes::work_order(), $woid);
-
- delete_forms_for_systype(systypes::work_order(), $woid);
-
- commit_transaction();
+
+ delete_forms_for_systype(systypes::work_order(), $woid);
+
+ commit_transaction();
}
//--------------------------------------------------------------------------------------
{
$sql = "SELECT ".TB_PREF."workorders.*, ".TB_PREF."stock_master.description As StockItemName,
".TB_PREF."locations.location_name
- FROM ".TB_PREF."workorders, ".TB_PREF."stock_master, ".TB_PREF."locations
- WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id
- AND ".TB_PREF."locations.loc_code=".TB_PREF."workorders.loc_code
+ FROM ".TB_PREF."workorders, ".TB_PREF."stock_master, ".TB_PREF."locations
+ WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id
+ AND ".TB_PREF."locations.loc_code=".TB_PREF."workorders.loc_code
AND ".TB_PREF."workorders.id=$woid
GROUP BY ".TB_PREF."workorders.id";
-
+
$result = db_query($sql, "The work order issues could not be retrieved");
-
+
if (!$allow_null && db_num_rows($result) == 0)
display_db_error("Could not find work order $workOrder", $sql);
-
- return db_fetch($result);
+
+ return db_fetch($result);
}
//--------------------------------------------------------------------------------------
{
$sql = "SELECT COUNT(*) FROM ".TB_PREF."wo_manufacture WHERE workorder_id=$woid";
$result = db_query($sql, "query work order for productions");
-
+
$myrow = db_fetch_row($result);
return ($myrow[0] > 0);
}
{
$sql = "SELECT COUNT(*) FROM ".TB_PREF."wo_issues WHERE workorder_id=$woid";
$result = db_query($sql, "query work order for issues");
-
+
$myrow = db_fetch_row($result);
return ($myrow[0] > 0);
}
function release_work_order($woid, $releaseDate, $memo_)
{
- begin_transaction();
-
- $myrow = get_work_order($woid);
+ begin_transaction();
+
+ $myrow = get_work_order($woid);
$stock_id = $myrow["stock_id"];
-
+
$date = date2sql($releaseDate);
-
- $sql = "UPDATE ".TB_PREF."workorders SET released_date='$date',
- released=1 WHERE id = $woid";
+
+ $sql = "UPDATE ".TB_PREF."workorders SET released_date='$date',
+ released=1 WHERE id = $woid";
db_query($sql, "could not release work order");
-
+
// create Work Order Requirements based on the bom
create_wo_requirements($woid, $stock_id);
-
- add_comments(systypes::work_order(), $woid, $releaseDate, $memo_);
- commit_transaction();
+ add_comments(systypes::work_order(), $woid, $releaseDate, $memo_);
+
+ commit_transaction();
}
//--------------------------------------------------------------------------------------
function close_work_order($woid)
{
- $sql = "UPDATE ".TB_PREF."workorders SET closed=1 WHERE id = $woid";
+ $sql = "UPDATE ".TB_PREF."workorders SET closed=1 WHERE id = $woid";
db_query($sql, "could not close work order");
}
function work_order_is_closed($woid)
{
- $sql = "SELECT closed FROM ".TB_PREF."workorders WHERE id = $woid";
+ $sql = "SELECT closed FROM ".TB_PREF."workorders WHERE id = $woid";
$result = db_query($sql, "could not query work order");
$row = db_fetch_row($result);
- return ($row[0] > 0);
+ return ($row[0] > 0);
}
//--------------------------------------------------------------------------------------
$sql = "UPDATE ".TB_PREF."workorders SET units_issued = units_issued + $quantity,
closed = ((units_issued >= units_reqd) OR $force_close)
WHERE id = $woid";
-
+
db_query($sql, "The work order issued quantity couldn't be updated");
}
function void_work_order($woid)
{
- $work_order = get_work_order($woid);
-
- if (!($work_order["type"] == wo_types::advanced()))
+ $work_order = get_work_order($woid);
+
+ if (!($work_order["type"] == wo_types::advanced()))
{
- begin_transaction();
-
+ begin_transaction();
+
$sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_issued=0 WHERE id = $woid";
db_query($sql, "The work order couldn't be voided");
-
+
// void all related stock moves
- void_stock_move(systypes::work_order(), $woid);
-
+ void_stock_move(systypes::work_order(), $woid);
+
// void any related gl trans
void_gl_trans(systypes::work_order(), $woid, true);
-
+
// clear the requirements units received
void_wo_requirements($woid);
-
- commit_transaction();
- }
- else
+
+ commit_transaction();
+ }
+ else
{
// void everything inside the work order : issues, productions, payments
}
//--------------------------------------------------------------------------------------
-function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $additional_costs, $memo_)
+function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $additional_costs, $memo_)
{
begin_transaction();
-
+
// if unassembling, reverse the stock movements
if ($type == wo_types::unassemble())
$units_reqd = -$units_reqd;
-
+
+ add_material_cost($stock_id, $units_reqd, $date_);
+
$date = date2sql($date_);
if (!isset($additional_costs) || ($additional_costs == ""))
$additional_costs = 0;
-
- $sql = "INSERT INTO ".TB_PREF."workorders (wo_ref, loc_code, units_reqd, units_issued, stock_id,
- type, additional_costs, date_, released_date, required_by, released, closed)
- VALUES ('$wo_ref', '$loc_code', $units_reqd, $units_reqd, '$stock_id',
+
+ $sql = "INSERT INTO ".TB_PREF."workorders (wo_ref, loc_code, units_reqd, units_issued, stock_id,
+ type, additional_costs, date_, released_date, required_by, released, closed)
+ VALUES ('$wo_ref', '$loc_code', $units_reqd, $units_reqd, '$stock_id',
$type, $additional_costs, '$date', '$date', '$date', 1, 1)";
db_query($sql, "could not add work order");
-
+
$woid = db_insert_id();
-
+
//--------------------------------------------------------------------------
// create Work Order Requirements based on the bom
- $result = get_bom($stock_id);
-
- while ($bom_item = db_fetch($result))
+ $result = get_bom($stock_id);
+
+ while ($bom_item = db_fetch($result))
{
-
+
$unit_quantity = $bom_item["quantity"];
$item_quantity = $bom_item["quantity"] * $units_reqd;
-
-
+
+
$sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, units_issued, loc_code)
- VALUES ($woid, " . "'" . $bom_item["component"] . "'" . ",
- '". $bom_item["workcentre_added"] . "',
+ VALUES ($woid, " . "'" . $bom_item["component"] . "'" . ",
+ '". $bom_item["workcentre_added"] . "',
$unit_quantity, $item_quantity, '" . $bom_item["loc_code"] . "')";
-
+
db_query($sql, "The work order requirements could not be added");
-
+
// insert a -ve stock move for each item
- add_stock_move(systypes::work_order(), $bom_item["component"], $woid,
- $bom_item["loc_code"], $date_, $wo_ref, -$item_quantity, 0);
+ add_stock_move(systypes::work_order(), $bom_item["component"], $woid,
+ $bom_item["loc_code"], $date_, $wo_ref, -$item_quantity, 0);
}
// -------------------------------------------------------------------------
// insert a +ve stock move for the item being manufactured
- add_stock_move(systypes::work_order(), $stock_id, $woid, $loc_code, $date_,
- $wo_ref, $units_reqd, 0);
+ add_stock_move(systypes::work_order(), $stock_id, $woid, $loc_code, $date_,
+ $wo_ref, $units_reqd, 0);
// -------------------------------------------------------------------------
work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $additional_costs);
-
+
// -------------------------------------------------------------------------
- add_comments(systypes::work_order(), $woid, $date_, $memo_);
-
- add_forms_for_sys_type(systypes::work_order(), $woid, $type);
-
+ add_comments(systypes::work_order(), $woid, $date_, $memo_);
+
+ add_forms_for_sys_type(systypes::work_order(), $woid, $type);
+
references::save_last($wo_ref, systypes::work_order());
-
- commit_transaction();
+
+ commit_transaction();
return $woid;
}
function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $additional_costs)
{
$result = get_bom($stock_id);
-
+
// credit all the components
$total_cost = 0;
- while ($bom_item = db_fetch($result))
+ while ($bom_item = db_fetch($result))
{
-
+
$bom_accounts = get_stock_gl_code($bom_item["component"]);
-
- $bom_cost = $bom_item["standard_cost"] * $bom_item["quantity"] * $units_reqd;
-
+
+ $bom_cost = $bom_item["standard_cost"] * $bom_item["quantity"] * $units_reqd;
+
add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $bom_accounts["inventory_account"], 0, 0,
null, -$bom_cost);
-
+
$total_cost += $bom_cost;
- }
+ }
// credit additional costs
$item_accounts = get_stock_gl_code($stock_id);
- add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["assembly_account"],
+ add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["assembly_account"],
$item_accounts["dimension_id"], $item_accounts["dimension2_id"], null, -$additional_costs);
-
+
// debit total components + additional
- $total_cost += $additional_costs;
- add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["inventory_account"],
+ $total_cost += $additional_costs;
+ add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $item_accounts["inventory_account"],
0, 0, null, $total_cost);
-}
+}
//--------------------------------------------------------------------------------------
if (isset($_GET["NewItem"]))
{
$_POST['stock_id'] = $_GET["NewItem"];
- if (isset($_GET['item']) && isset($_GET['qty']))
- add_material_cost($_GET["NewItem"], $_GET['item'], $_GET['qty'], false);
-
}
if (isset($_GET['stock_id']))
{
$selected_component = $_POST["selected_component"];
}
-function add_material_cost($parent, $item, $n, $add=true)
-{
- $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id='$parent'";
- $result = db_query($sql);
- $myrow = db_fetch($result);
- $material_cost = $myrow['material_cost'];
- $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id='$item'";
- $result = db_query($sql);
- $myrow = db_fetch($result);
- $material_cost2 = $myrow['material_cost'];
- if ($add)
- $material_cost += ($material_cost2 * $n);
- else
- $material_cost -= ($material_cost2 * $n);
- $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost
- WHERE stock_id='$parent'";
- db_query($sql,"The cost details for the inventory item could not be updated");
-}
//--------------------------------------------------------------------------------------------------
label_cell($myrow["WorkCentreDescription"]);
label_cell($myrow["quantity"]);
label_cell($myrow["units"]);
- edit_link_cell(SID . "NewItem=$selected_parent&selected_component=" . $myrow["id"]."&item=".$myrow['component']."&qty=".$myrow['quantity']);
- delete_link_cell(SID . "delete=" . $myrow["id"]. "&stock_id=" . $_POST['stock_id']."&item=".$myrow['component']."&qty=".$myrow['quantity']);
+ edit_link_cell(SID . "NewItem=$selected_parent&selected_component=" . $myrow["id"]);
+ delete_link_cell(SID . "delete=" . $myrow["id"]. "&stock_id=" . $_POST['stock_id']);
end_row();
} //END WHILE LIST LOOP
AND id='" . $selected_component . "'";
check_db_error("Could not update this bom component", $sql);
- add_material_cost($selected_parent, $_POST['item'], $_POST['quantity'], true);
-
db_query($sql,"could not update bom");
}
db_query($sql,"check failed");
- add_material_cost($selected_parent, $_POST['component'], $_POST['quantity'], true);
//$msg = _("A new component part has been added to the bill of material for this item.");
}
if (isset($_GET['delete']))
{
- $sql = "DELETE FROM ".TB_PREF."bom WHERE id='".$_GET['delete']."'";
- db_query($sql,"Could not delete this bom components");
- add_material_cost($_GET['stock_id'], $_GET['item'], $_GET['qty'], false);
+ $sql = "DELETE FROM ".TB_PREF."bom WHERE id='" . $_GET['delete']. "'";
+ db_query($sql,"Could not delete this bom components");
display_note(_("The component item has been deleted from this bom."));
$_POST['workcentre_added'] = $myrow["workcentre_added"];
$_POST['quantity'] = $myrow["quantity"];
- hidden('item', $myrow["component"]);
hidden('selected_parent', $selected_parent);
hidden('selected_component', $selected_component);
label_row(_("Component:"), $myrow["component"] . " - " . $myrow["description"]);
if (isset($_GET['trans_no']))
{
$selected_id = $_GET['trans_no'];
-}
+}
elseif(isset($_POST['selected_id']))
{
$selected_id = $_POST['selected_id'];
//---------------------------------------------------------------------------------------
-if (isset($_GET['AddedID']))
+if (isset($_GET['AddedID']))
{
$id = $_GET['AddedID'];
//---------------------------------------------------------------------------------------
-if (isset($_GET['UpdatedID']))
+if (isset($_GET['UpdatedID']))
{
$id = $_GET['UpdatedID'];
//---------------------------------------------------------------------------------------
-if (isset($_GET['DeletedID']))
+if (isset($_GET['DeletedID']))
{
$id = $_GET['DeletedID'];
//---------------------------------------------------------------------------------------
-if (isset($_GET['ClosedID']))
+if (isset($_GET['ClosedID']))
{
$id = $_GET['ClosedID'];
$_POST['date_'] = Today();
if (!is_date_in_fiscalyear($_POST['date_']))
$_POST['date_'] = end_fiscalyear();
-}
+}
function can_process()
{
global $selected_id;
- if (!isset($selected_id))
+ if (!isset($selected_id))
{
- if (!references::is_valid($_POST['wo_ref']))
+ if (!references::is_valid($_POST['wo_ref']))
{
display_error(_("You must enter a reference."));
return false;
}
- if (!is_new_reference($_POST['wo_ref'], systypes::work_order()))
+ if (!is_new_reference($_POST['wo_ref'], systypes::work_order()))
{
display_error(_("The entered reference is already in use."));
return false;
{
display_error( _("The date entered is in an invalid format."));
return false;
- }
- elseif (!is_date_in_fiscalyear($_POST['date_']))
+ }
+ elseif (!is_date_in_fiscalyear($_POST['date_']))
{
display_error(_("The entered date is not in fiscal year."));
return false;
}
// only check bom and quantites if quick assembly
- if (!($_POST['type'] == wo_types::advanced()))
+ if (!($_POST['type'] == wo_types::advanced()))
{
- if (!has_bom($_POST['stock_id']))
+ if (!has_bom($_POST['stock_id']))
{
display_error(_("The selected item to manufacture does not have a bom."));
return false;
return false;
}
- if (!sys_prefs::allow_negative_stock())
+ if (!sys_prefs::allow_negative_stock())
{
- if ($_POST['type'] == wo_types::assemble())
+ if ($_POST['type'] == wo_types::assemble())
{
// check bom if assembling
$result = get_bom($_POST['stock_id']);
- while ($bom_item = db_fetch($result))
+ while ($bom_item = db_fetch($result))
{
- if (has_stock_holding($bom_item["ResourceType"]))
+ if (has_stock_holding($bom_item["ResourceType"]))
{
$quantity = $bom_item["quantity"] * $_POST['quantity'];
$qoh = get_qoh_on_date($bom_item["component"], $bom_item["loc_code"], $_POST['date_']);
- if (-$quantity + $qoh < 0)
+ if (-$quantity + $qoh < 0)
{
display_error(_("The work order cannot be processed because there is an insufficient quantity for component:") .
" " . $bom_item["component"] . " - " . $bom_item["description"] . ". " . _("Location:") . " " . $bom_item["location_name"]);
}
}
}
- }
- elseif ($_POST['type'] == wo_types::unassemble())
+ }
+ elseif ($_POST['type'] == wo_types::unassemble())
{
// if unassembling, check item to unassemble
$qoh = get_qoh_on_date($_POST['stock_id'], $_POST['StockLocation'], $_POST['date_']);
- if (-$_POST['quantity'] + $qoh < 0)
+ if (-$_POST['quantity'] + $qoh < 0)
{
display_error(_("The selected item cannot be unassembled because there is insufficient stock."));
return false;
}
}
}
- }
- else
+ }
+ else
{
if (!is_date($_POST['RequDate']))
{
display_error( _("The date entered is in an invalid format."));
return false;
- }
- //elseif (!is_date_in_fiscalyear($_POST['RequDate']))
+ }
+ //elseif (!is_date_in_fiscalyear($_POST['RequDate']))
//{
// display_error(_("The entered date is not in fiscal year."));
// return false;
//}
- if (isset($selected_id))
+ if (isset($selected_id))
{
$myrow = get_work_order($selected_id, true);
- if ($_POST['units_issued'] > $_POST['quantity'])
+ if ($_POST['units_issued'] > $_POST['quantity'])
{
display_error(_("The quantity cannot be changed to be less than the quantity already manufactured for this order."));
return false;
//-------------------------------------------------------------------------------------
-if (isset($_POST['ADD_ITEM']) && can_process())
+if (isset($_POST['ADD_ITEM']) && can_process())
{
$id = add_work_order($_POST['wo_ref'], $_POST['StockLocation'], $_POST['quantity'],
//-------------------------------------------------------------------------------------
-if (isset($_POST['UPDATE_ITEM']) && can_process())
+if (isset($_POST['UPDATE_ITEM']) && can_process())
{
update_work_order($selected_id, $_POST['StockLocation'], $_POST['quantity'],
//--------------------------------------------------------------------------------------
-if (isset($_POST['delete']))
+if (isset($_POST['delete']))
{
//the link to delete a selected record was clicked instead of the submit button
$cancel_delete = false;
// can't delete it there are productions or issues
- if (work_order_has_productions($selected_id) ||
- work_order_has_issues($selected_id) ||
+ if (work_order_has_productions($selected_id) ||
+ work_order_has_issues($selected_id) ||
work_order_has_payments($selected_id))
{
display_error(_("This work order cannot be deleted because it has already been processed."));
$cancel_delete = true;
}
- if ($cancel_delete == false)
+ if ($cancel_delete == false)
{ //ie not cancelled the delete as a result of above tests
// delete the actual work order
//-------------------------------------------------------------------------------------
-if (isset($_POST['close']))
+if (isset($_POST['close']))
{
// update the closed flag in the work order
{
$myrow = get_work_order($selected_id);
- if (strlen($myrow[0]) == 0)
+ if (strlen($myrow[0]) == 0)
{
echo _("The order number sent is not valid.");
safe_exit();
}
// if it's a closed work order can't edit it
- if ($myrow["closed"] == 1)
+ if ($myrow["closed"] == 1)
{
echo "<center>";
display_error(_("This work order is closed and cannot be edited."));
hidden('released', $_POST['released']);
hidden('released_date', $_POST['released_date']);
hidden('selected_id', $selected_id);
+ hidden('old_qty', $myrow["units_reqd"]);
+ hidden('old_stk_id', $myrow["stock_id"]);
label_row(_("Reference:"), $_POST['wo_ref']);
label_row(_("Type:"), wo_types::name($_POST['type']));
-}
-else
+}
+else
{
$_POST['units_issued'] = $_POST['released'] = 0;
ref_row(_("Reference:"), 'wo_ref', references::get_next(systypes::work_order()));
wo_types_list_row(_("Type:"), 'type', $_POST['type']);
}
-if ($_POST['released'] == true)
+if ($_POST['released'] == true)
{
hidden('stock_id', $_POST['stock_id']);
hidden('StockLocation', $_POST['StockLocation']);
label_row(_("Item:"), $myrow["StockItemName"]);
label_row(_("Destination Location:"), $myrow["location_name"]);
-}
-else
+}
+else
{
stock_manufactured_items_list_row(_("Item:"), 'stock_id', null);
if (!isset($_POST['quantity']))
$_POST['quantity'] = 1;
-if ($_POST['type'] == wo_types::advanced())
+if ($_POST['type'] == wo_types::advanced())
{
text_row_ex(_("Quantity Required:"), 'quantity', 12);
if ($_POST['released'])
date_row(_("Date") . ":", 'date_');
date_row(_("Date Required By") . ":", 'RequDate', null, sys_prefs::default_wo_required_by());
}
-else
+else
{
text_row_ex(_("Quantity:"), 'quantity', 12);
date_row(_("Date") . ":", 'date_');
submit_add_or_update_center(!isset($selected_id));
-if (isset($selected_id))
+if (isset($selected_id))
{
echo "<br><br><table align=center><tr>";
- if (isset($_POST['released']))
+ if (isset($_POST['released']))
{
submit_cells('close', _("Close This Work Order"));
}
submit_cells('delete', _("Delete This Work Order"));
-
+
echo "</tr></table>";
}
$myrow = db_fetch($result);
$material_cost = $myrow['material_cost'];
$qoh = get_qoh_on_date($order_line->stock_id, null, $date_);
- $material_cost = ($qoh * $material_cost + $order_line->receive_qty * $price_in_home_currency) /
- ($qoh + $order_line->receive_qty);
+ if ($qoh + $order_line->receive_qty <= 0)
+ $material_cost = 0;
+ else
+ $material_cost = ($qoh * $material_cost + $order_line->receive_qty * $price_in_home_currency) /
+ ($qoh + $order_line->receive_qty);
$sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost
WHERE stock_id='$order_line->stock_id'";
db_query($sql,"The cost details for the inventory item could not be updated");