! -> Note
$ -> Affected files
+06-Jun-2009
+# Overhead costs in Manufacturing/Assembling wasn't added to stock overhead cost
+$ /manufacturing/work_order_add_finished.php
+ /manufacturing/work_order_issue.php
+ /manufacturing/work_order_release.php
+ /manufacturing/includes/db/work_orders_db.inc
+ /manufacturing/includes/db/work_orders_quick_db.inc
+
05-Jun-2009 Joe Hunt
# Missing underscore in gettext string
$ /sales/create_recurrent_invoices.php
$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']);
+ $standard_cost = get_standard_cost($bom_item['component']);
+ $m_cost += ($bom_item['quantity'] * $standard_cost);
}
$sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id = '$stock_id'";
$result = db_query($sql);
db_query($sql,"The cost details for the inventory item could not be updated");
}
+function add_additional_cost($stock_id, $qty, $date_, $costs)
+{
+ if ($qty != 0)
+ $costs /= $qty;
+ $sql = "SELECT overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = '$stock_id'";
+ $result = db_query($sql);
+ $myrow = db_fetch($result);
+ $overhead_cost = $myrow['overhead_cost'];
+ $qoh = get_qoh_on_date($stock_id, null, $date_);
+ if ($qoh + $qty <= 0)
+ $overhead_cost = 0;
+ else
+ $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) / ($qoh + $qty);
+ $sql = "UPDATE ".TB_PREF."stock_master SET overhead_cost=$overhead_cost
+ WHERE stock_id='$stock_id'";
+ db_query($sql,"The cost details for the inventory item could not be updated");
+}
+
+function add_issue_cost($stock_id, $qty, $date_, $costs)
+{
+ if ($qty != 0)
+ $costs /= $qty;
+ $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 <= 0)
+ $material_cost = 0;
+ else
+ $material_cost = ($qoh * $material_cost + $qty * $costs) / $qoh;
+ $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_)
{
$date = date2sql($date_);
if (!isset($additional_costs) || ($additional_costs == ""))
$additional_costs = 0;
-
+ if ($additional_costs != 0)
+ add_additional_cost($stock_id, $units_reqd, $date_, $additional_costs);
+
$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 (".db_escape($wo_ref).", ".db_escape($loc_code).", $units_reqd, $units_reqd, '$stock_id',
{
// also take the additional issues
$res = get_additional_issues($woid);
+ $issue_total = 0;
while ($item = db_fetch($res))
{
$standard_cost = get_standard_cost($item['stock_id']);
$issue = get_stock_gl_code($item['stock_id']);
add_gl_trans_std_cost(systypes::work_order(), $woid, $date_, $issue["inventory_account"], 0, 0,
null, -$issue_cost);
- $total_cost += $issue_cost;
+ $issue_total += $issue_cost;
}
+ add_issue_cost($stock_id, $units_reqd, $date_, $issue_total);
+ $total_cost += $issue_total;
+ $pcost = 0; // fix bank payments as additional cost.
+ $result = get_bank_trans(null, null, payment_person_types::WorkOrder(), $woid);
+ while ($row = db_fetch($result))
+ $pcost += -$row['amount'];
+ if ($pcost != 0)
+ add_additional_cost($stock_id, $units_reqd, $date_, $pcost);
}
// credit additional costs
$item_accounts = get_stock_gl_code($stock_id);
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
+include_once($path_to_root . "/gl/includes/db/gl_db_bank_trans.inc");
include_once($path_to_root . "/includes/db/inventory_db.inc");
include_once($path_to_root . "/includes/manufacturing.inc");
if (isset($_GET['AddedID']))
{
- display_note(_("The manufacturing process has been entered."));
+ display_notification(_("The manufacturing process has been entered."));
hyperlink_no_params("search_work_orders.php", _("Select another &Work Order to Process"));
{
$wo_details = get_work_order($_POST['selected_id']);
- $qoh = get_qoh_on_date($wo_details["stock_id"], $wo_details["loc_code"], $date_);
+ $qoh = get_qoh_on_date($wo_details["stock_id"], $wo_details["loc_code"], $_POST['date_']);
if (-$_POST['quantity'] + $qoh < 0)
{
display_error(_("The unassembling cannot be processed because there is insufficient stock."));
{
if ($row['mb_flag'] == 'D') // service, non stock
continue;
- $qoh = get_qoh_on_date($row["stock_id"], $row["loc_code"], $date_);
+ $qoh = get_qoh_on_date($row["stock_id"], $row["loc_code"], $_POST['date_']);
if ($qoh - $row['units_req'] * $_POST['quantity'] < 0)
{
display_error( _("The production cannot be processed because a required item would cause a negative inventory balance :") .
//--------------------------------------------------------------------------------------------------
-if (isset($_POST['ProcessAndClose']) && can_process() == true)
+if ((isset($_POST['Process']) || isset($_POST['ProcessAndClose'])) && can_process() == true)
{
- $close_wo = 1;
+ $close_wo = 0;
+ if (isset($_POST['ProcessAndClose']) && ($_POST['ProcessAndClose']!=""))
+ $close_wo = 1;
+
// if unassembling, negate quantity
if ($_POST['ProductionType'] == 0)
$_POST['quantity'] = -$_POST['quantity'];
end_table(1);
-submit_center('ProcessAndClose', _("Process And Close Order"), true, '', true);
+submit_center_first('Process', _("Process"), '', 'default');
+submit_center_last('ProcessAndClose', _("Process And Close Order"), '', true);
end_form();
if (isset($_GET['AddedID']))
{
- echo "<center>" . _("The work order issue has been entered.");
- echo "<br>";
+ display_notification(_("The work order issue has been entered."));
+
hyperlink_no_params("search_work_orders.php", _("Select another &Work Order to Process"));
- echo "<br><br>";
+
display_footer_exit();
}
//--------------------------------------------------------------------------------------------------
{
release_work_order($selected_id, $_POST['released_date'], $_POST['memo_']);
- display_note(_("The work order has been released to manufacturing."));
+ display_notification(_("The work order has been released to manufacturing."));
hyperlink_no_params("search_work_orders.php", _("Select another &work order"));