Overhead costs in Manufacturing/Assembling wasn't added to stock overhead cost
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 6 Jun 2009 01:55:05 +0000 (01:55 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 6 Jun 2009 01:55:05 +0000 (01:55 +0000)
CHANGELOG.txt
manufacturing/includes/db/work_orders_db.inc
manufacturing/includes/db/work_orders_quick_db.inc
manufacturing/work_order_add_finished.php
manufacturing/work_order_issue.php
manufacturing/work_order_release.php

index 9e35071f0955475fcc48cb7334dc70a1b334004e..b74d579615560d5a76aea4f7b71044edd700f549 100644 (file)
@@ -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
index 5df4082ba5cf7c902f81c8da628e87e67a79c7b3..3150016165da215cb1d09dce07b8b7b3bbb631b7 100644 (file)
@@ -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_)
 {
index a2b3c1240a1b8fb759b7619f2d2eeb54278f4a68..8bd0de2869e8fb942350be55e6a7990a6cf55fff 100644 (file)
@@ -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);
index 6248ed866759c86f29505eed988033b523c0c311..5afdd61f5af6920f86e62fc024179328e12ff013 100644 (file)
@@ -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();
 
index 452c821510e23362317636d9750b1ec5b7651065..c6afb08b2ec7fa92e3ba06d4a8f6d89029376eff 100644 (file)
@@ -32,10 +32,10 @@ page(_("Issue Items to Work Order"), false, false, "", $js);
 
 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();
 }
 //--------------------------------------------------------------------------------------------------
index 9cb8e22ed0c068605ba2f436b18c6e02f8e5e18c..e8efcfd8b70ce222f3ac8d01f679784327be6bfc 100644 (file)
@@ -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"));