From 68118480967870cf8ed31ca28902a663c5f2499f Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Sat, 6 Jun 2009 01:55:05 +0000 Subject: [PATCH] Overhead costs in Manufacturing/Assembling wasn't added to stock overhead cost --- CHANGELOG.txt | 8 ++++ manufacturing/includes/db/work_orders_db.inc | 42 +++++++++++++++++-- .../includes/db/work_orders_quick_db.inc | 15 ++++++- manufacturing/work_order_add_finished.php | 17 +++++--- manufacturing/work_order_issue.php | 6 +-- manufacturing/work_order_release.php | 2 +- 6 files changed, 74 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9e35071f..b74d5796 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,14 @@ Legend: ! -> 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 diff --git a/manufacturing/includes/db/work_orders_db.inc b/manufacturing/includes/db/work_orders_db.inc index 5df4082b..31500161 100644 --- a/manufacturing/includes/db/work_orders_db.inc +++ b/manufacturing/includes/db/work_orders_db.inc @@ -17,10 +17,8 @@ function add_material_cost($stock_id, $qty, $date_) $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); @@ -36,6 +34,42 @@ function add_material_cost($stock_id, $qty, $date_) 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_) { diff --git a/manufacturing/includes/db/work_orders_quick_db.inc b/manufacturing/includes/db/work_orders_quick_db.inc index a2b3c124..8bd0de28 100644 --- a/manufacturing/includes/db/work_orders_quick_db.inc +++ b/manufacturing/includes/db/work_orders_quick_db.inc @@ -24,7 +24,9 @@ function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $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', @@ -108,6 +110,7 @@ function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $addition { // 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']); @@ -115,8 +118,16 @@ function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $addition $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); diff --git a/manufacturing/work_order_add_finished.php b/manufacturing/work_order_add_finished.php index 6248ed86..5afdd61f 100644 --- a/manufacturing/work_order_add_finished.php +++ b/manufacturing/work_order_add_finished.php @@ -14,6 +14,7 @@ $path_to_root=".."; 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"); @@ -37,7 +38,7 @@ if (isset($_GET['trans_no']) && $_GET['trans_no'] != "") 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")); @@ -106,7 +107,7 @@ function can_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.")); @@ -124,7 +125,7 @@ function can_process() { 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 :") . @@ -143,10 +144,13 @@ function can_process() //-------------------------------------------------------------------------------------------------- -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']; @@ -191,7 +195,8 @@ textarea_row(_("Memo:"), 'memo_', null, 40, 3); 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(); diff --git a/manufacturing/work_order_issue.php b/manufacturing/work_order_issue.php index 452c8215..c6afb08b 100644 --- a/manufacturing/work_order_issue.php +++ b/manufacturing/work_order_issue.php @@ -32,10 +32,10 @@ page(_("Issue Items to Work Order"), false, false, "", $js); if (isset($_GET['AddedID'])) { - echo "
" . _("The work order issue has been entered."); - echo "
"; + display_notification(_("The work order issue has been entered.")); + hyperlink_no_params("search_work_orders.php", _("Select another &Work Order to Process")); - echo "

"; + display_footer_exit(); } //-------------------------------------------------------------------------------------------------- diff --git a/manufacturing/work_order_release.php b/manufacturing/work_order_release.php index 9cb8e22e..e8efcfd8 100644 --- a/manufacturing/work_order_release.php +++ b/manufacturing/work_order_release.php @@ -65,7 +65,7 @@ if (isset($_POST['release'])) { 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")); -- 2.30.2