Overhead and labour cost changed to define standard costs.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 2 Jan 2016 10:08:32 +0000 (11:08 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 9 Jan 2016 10:57:28 +0000 (11:57 +0100)
30 files changed:
gl/includes/db/gl_db_trans.inc
includes/db/inventory_db.inc
includes/db/manufacturing_db.inc
includes/ui/ui_view.inc
inventory/cost_update.php
inventory/includes/db/items_trans_db.inc
inventory/includes/item_adjustments_ui.inc
manufacturing/includes/db/work_order_costing_db.inc
manufacturing/includes/db/work_order_issues_db.inc
manufacturing/includes/db/work_order_produce_items_db.inc
manufacturing/includes/db/work_order_requirements_db.inc
manufacturing/includes/db/work_orders_db.inc
manufacturing/includes/db/work_orders_quick_db.inc [deleted file]
manufacturing/includes/manufacturing_db.inc
manufacturing/includes/manufacturing_ui.inc
manufacturing/includes/work_order_issue_ui.inc
manufacturing/view/wo_costs_view.php
manufacturing/work_order_costs.php
manufacturing/work_order_entry.php
purchasing/includes/db/grn_db.inc
purchasing/includes/purchasing_db.inc
reporting/rep104.php
reporting/rep301.php
reporting/rep304.php
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_delivery_db.inc
sales/includes/db/sales_order_db.inc
sales/includes/sales_db.inc
sales/sales_order_entry.php
sql/alter2.4rc1.sql

index daac59ad062fcaddd2ed6c8be7016f56f690e553..b2560f75b1779ca2932adf6948cf5d6b40de3344 100644 (file)
@@ -79,6 +79,7 @@ function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension
 function add_gl_trans_std_cost($type, $trans_id, $date_, $account, $dimension, $dimension2,
        $memo_, $amount, $person_type_id=null, $person_id=null, $err_msg="")
 {
+
        if ($amount != 0)
                return add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_,
                        $amount, null, $person_type_id, $person_id, $err_msg);
@@ -204,9 +205,10 @@ function get_gl_trans($type, $trans_id)
 
 //--------------------------------------------------------------------------------
 
-function get_gl_wo_cost_trans($trans_id, $cost_type=-1)
+function get_gl_wo_cost_trans($trans_id, $cost_type=-1, $all_gl=false)
 {
-       $sql = "SELECT costing.*, gl.*, chart.account_name, com.memo_ FROM "
+       $sql = "SELECT costing.*, gl.*, chart.account_name, com.memo_
+               FROM "
                .TB_PREF."wo_costing costing, "
                .TB_PREF."gl_trans gl LEFT JOIN ".TB_PREF."comments com ON gl.type=com.type     AND gl.type_no=com.id,"
                .TB_PREF."chart_master chart
@@ -217,10 +219,48 @@ function get_gl_wo_cost_trans($trans_id, $cost_type=-1)
                        AND gl.type_no=costing.trans_no";
        if ($cost_type != -1)
                $sql .= " AND costing.cost_type=".db_escape($cost_type);
-       $sql .= " AND amount < 0";
-       
+       $sql .= $all_gl ? " AND amount != 0" : " AND amount < 0";
+
        return db_query($sql, "The gl transactions could not be retrieved");
 }
+
+function get_gl_wo_issue_trans($trans_id, $person_id=-1, $all_gl=false)
+{
+       $sql = "SELECT issue.*, gl.*, chart.account_name, com.memo_
+               FROM "
+                       .TB_PREF."wo_issues issue,"
+                       .TB_PREF."gl_trans gl LEFT JOIN ".TB_PREF."comments com ON gl.type=com.type     AND gl.type_no=com.id,"
+                       .TB_PREF."chart_master chart
+               WHERE issue.workorder_id=".db_escape($trans_id)
+                ." AND chart.account_code=gl.account
+                       AND gl.type=".ST_MANUISSUE." AND gl.type_no=issue.issue_no";
+//                     ." AND gl.person_type_id=".PT_WORKORDER;
+       if ($person_id != -1)
+               $sql .= " AND gl.person_id=".db_escape($person_id);
+       $sql .= $all_gl ? " AND amount != 0" : " AND amount < 0";
+       $sql .= " ORDER BY type, type_no";
+       return db_query($sql, "The gl transactions could not be retrieved");
+}
+
+function get_gl_wo_productions($trans_id, $all_gl=false)
+{
+       $sql = "SELECT rcv.*, gl.*, chart.account_name, com.memo_
+               FROM "
+               .TB_PREF."wo_manufacture rcv, "
+               .TB_PREF."gl_trans gl LEFT JOIN ".TB_PREF."comments com ON gl.type=com.type     AND gl.type_no=com.id,"
+               .TB_PREF."chart_master chart
+               WHERE 
+                       rcv.workorder_id=".db_escape($trans_id)
+               ."      AND chart.account_code=gl.account
+                       AND gl.type=".ST_MANURECEIVE."
+                       AND gl.type_no=rcv.id
+                       AND amount != 0 "
+               .($all_gl ? " AND amount != 0" : " AND amount < 0")
+               ." ORDER BY type, type_no";
+
+       return db_query($sql, "The gl transactions could not be retrieved");
+}
+
 function get_gl_balance_from_to($from_date, $to_date, $account, $dimension=0, $dimension2=0)
 {
        $from = date2sql($from_date);
index 6d562cf852b89bbc641d94d6669bdd82ccccab6d..19f54f2b9802d08cafeba64bc362d9266433cad1 100644 (file)
@@ -86,10 +86,11 @@ function check_negative_stock($stock_id, $delta_qty, $location=null, $date=null)
 
 function get_item_edit_info($stock_id)
 {
-       $sql = "SELECT material_cost + labour_cost + overhead_cost AS standard_cost, units, decimals
-               FROM ".TB_PREF."stock_master,".TB_PREF."item_units
+       $sql = "SELECT item.material_cost, item.units, unit.decimals
+               FROM ".TB_PREF."stock_master item,"
+                       .TB_PREF."item_units unit
                WHERE stock_id=".db_escape($stock_id)
-               ." AND ".TB_PREF."stock_master.units=".TB_PREF."item_units.abbr";
+               ." AND item.units=unit.abbr";
        $result = db_query($sql, "The standard cost cannot be retrieved");
 
        return db_fetch($result);
@@ -97,10 +98,11 @@ function get_item_edit_info($stock_id)
 
 //--------------------------------------------------------------------------------------
 
-function get_standard_cost($stock_id)
+function get_unit_cost($stock_id)
 {
-       $sql = "SELECT (material_cost + labour_cost + overhead_cost) AS std_cost
-               FROM ".TB_PREF."stock_master s WHERE stock_id=".db_escape($stock_id);
+       $sql = "SELECT material_cost
+               FROM ".TB_PREF."stock_master
+               WHERE stock_id=".db_escape($stock_id);
        $result = db_query($sql, "The standard cost cannot be retrieved");
 
        $myrow = db_fetch_row($result);
@@ -112,7 +114,8 @@ function get_standard_cost($stock_id)
 
 function is_inventory_item($stock_id)
 {
-       $sql = "SELECT stock_id FROM ".TB_PREF."stock_master
+       $sql = "SELECT stock_id FROM "
+               .TB_PREF."stock_master
                WHERE stock_id=".db_escape($stock_id)." AND mb_flag <> 'D'";
        $result = db_query($sql, "Cannot query is inventory item or not");
 
@@ -153,8 +156,8 @@ function get_already_delivered($stock_id, $location, $trans_no)
        return $row[0];
 }
 /*
-       FIXME: $to ? 
        Returns start move_id in latest negative status period for $stock_id
+       FIXME: $to ? 
 */
 function last_negative_stock_trans_id($stock_id, $to)
 {
@@ -352,7 +355,7 @@ function handle_negative_inventory($stock_id, $quantity, $standard_cost, $date_)
 
                $id = get_next_trans_no(ST_JOURNAL);
                $ref = $Refs->get_next(ST_JOURNAL, null, $date_);
-               $diff = round($qoh*get_standard_cost($stock_id) + $quantity*$standard_cost, user_price_dec());
+               $diff = round($qoh*get_unit_cost($stock_id) + $quantity*$standard_cost, user_price_dec());
 
                if ($diff != 0)
                {
@@ -417,8 +420,7 @@ function update_stock_move($type, $trans_no, $stock_id, $cost)
 
 function get_stock_moves($type, $type_no)
 {
-       $sql = "SELECT move.*, item.description, item.mb_flag, item.units, stock.location_name,
-               item.material_cost + item.labour_cost + item.overhead_cost AS FixedStandardCost
+       $sql = "SELECT move.*, item.description, item.mb_flag, item.units, stock.location_name
                FROM ".TB_PREF."stock_moves move,"
                        .TB_PREF."locations stock,"
                        .TB_PREF."stock_master item
index 0a4035f0ab2144a9b36321c41634ecaad5751367..dc635c3a9ec333e2a1b8613a28fff75c865eaa1d 100644 (file)
@@ -222,8 +222,8 @@ function get_bom($item)
        $sql = "SELECT bom.*, loc.location_name,
                centre.name AS WorkCentreDescription,
        item.description, item.mb_flag AS ResourceType, 
-       item.material_cost+item.labour_cost+item.overhead_cost AS standard_cost, units,
-       bom.quantity * (item.material_cost+ item.labour_cost+ item.overhead_cost) AS ComponentCost 
+       item.material_cost AS ProductCost, units,
+       bom.quantity * item.material_cost AS ComponentCost 
        FROM ".TB_PREF."workcentres centre,
                ".TB_PREF."locations loc,
                ".TB_PREF."bom bom
index 1284a918667466fe0155bffff67d304006d41b3f..389ea5302d389acb3a17b12996edd409656ade79 100644 (file)
@@ -51,7 +51,7 @@ function get_gl_view_str($type, $trans_no, $label="", $force=false, $class='', $
                $label = _("GL");
                $icon = ICON_GL;
        }
-       $url = ($type == ST_WORKORDER && !work_order_is_closed($trans_no)) ? "manufacturing/view/wo_costs_view.php?trans_no=$trans_no"
+       $url = ($type == ST_WORKORDER) ? "manufacturing/view/wo_costs_view.php?trans_no=$trans_no"
                : "gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no";
 
        return viewer_link($label, $url, $class, $id, $icon);
index 6fa3a01947ed023df115ff5af047f5dde2f1e66b..35347000c7eaa2b570a5aeec9328cc566bd58dd3 100644 (file)
@@ -52,8 +52,7 @@ if (isset($_GET['stock_id']))
 $should_update = false;
 if (isset($_POST['UpdateData']))
 {
-
-       $old_cost = get_standard_cost($_POST['stock_id']);
+       $old_cost = get_unit_cost($_POST['stock_id']);
 
        $new_cost = input_num('material_cost') + input_num('labour_cost')
             + input_num('overhead_cost');
@@ -131,7 +130,7 @@ $_POST['material_cost'] = price_decimal_format($myrow["material_cost"], $dec1);
 $_POST['labour_cost'] = price_decimal_format($myrow["labour_cost"], $dec2);
 $_POST['overhead_cost'] = price_decimal_format($myrow["overhead_cost"], $dec3);
 
-amount_row(_("Standard Material Cost Per Unit"), "material_cost", null, "class='tableheader2'", null, $dec1);
+amount_row(_("Unit cost"), "material_cost", null, "class='tableheader2'", null, $dec1);
 
 if ($myrow["mb_flag"]=='M')
 {
index 84ba75ae43db78de6c211572de1f318d3f8cf729..58d7722ddb70f1b8c2d23222dd15fa02d451d182 100644 (file)
@@ -31,8 +31,8 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co
        begin_transaction();
 
        $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost).", 
-               labour_cost=".db_escape($labour_cost).", 
-               overhead_cost=".db_escape($overhead_cost)."
+               labour_cost=".db_escape($labour_cost).",
+               overhead_cost=".db_escape($overhead_cost)."
                WHERE stock_id=".db_escape($stock_id);
        db_query($sql,"The cost details for the inventory item could not be updated");
 
index e2f585b6951b7658f672ebcd28f57e05141f94d1..66223fb4a4d20b482b4d219db5d3799908666294 100644 (file)
@@ -160,8 +160,7 @@ function adjustment_edit_item_controls(&$order, $line_no=-1)
        $item_info = get_item_edit_info($_POST['stock_id']);
                $dec = $item_info['decimals'];
                $_POST['qty'] = number_format2(0, $dec);
-               //$_POST['std_cost'] = price_format($item_info["standard_cost"]);
-               $_POST['std_cost'] = price_decimal_format($item_info["standard_cost"], $dec2);
+               $_POST['std_cost'] = price_decimal_format($item_info["material_cost"], $dec2);
                $_POST['units'] = $item_info["units"];
        }
 
index efc6f405b08e48f9541de997976190882fe833b0..2502be7640281964d3833c885518da0010d0c9e5 100644 (file)
@@ -35,64 +35,6 @@ function delete_wo_costing($trans_type, $trans_no)
 
        db_query($sql, "could not delete work order costing");
 }
-//--------------------------------------------------------------------------------------
-
-function add_material_cost($stock_id, $qty, $date_, $advanced=false, $woid=0)
-{
-       $m_cost = 0;
-    $result = get_bom($stock_id);
-       while ($bom_item = db_fetch($result))
-       {
-               $standard_cost = get_standard_cost($bom_item['component']);
-               $m_cost += ($bom_item['quantity'] * $standard_cost);
-       }
-       $bom_cost = $m_cost;
-       $i_cost = 0;
-       if ($woid != 0 && work_order_has_issues($woid))
-       {
-               $res = get_additional_issues($woid);
-               while ($issue = db_fetch($res))
-               {
-                       $standard_cost = get_standard_cost($issue['stock_id']);
-                       $i_cost += ($issue['qty_issued'] * $standard_cost) / $qty;
-               }
-       }
-       $sql = "SELECT material_cost, labour_cost, overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
-               .db_escape($stock_id);
-       $result = db_query($sql);
-       $myrow = db_fetch($result);
-       $material_cost =  $myrow['material_cost'];
-       $m_cost += $i_cost;
-       /*      
-       if ($advanced)
-       {
-               //reduce overhead_cost and labour_cost from price as those will remain as is
-               $m_cost = $m_cost - $myrow['labour_cost'] - $myrow['overhead_cost'];
-       }
-       */      
-       $qoh = get_qoh_on_date($stock_id);
-       $cost_adjust = false;
-       if ($qoh < 0)
-       {
-               if ($qoh + $qty >= 0)
-                       $cost_adjust = true;
-               $qoh = 0;
-       }
-       if ($qoh + $qty != 0)
-       {
-               if ($qoh == 0)
-                       $material_cost = $m_cost;
-               else
-                       $material_cost = ($qoh * $material_cost + $qty * $m_cost) /     ($qoh + $qty);
-       }
-
-       if ($advanced && $cost_adjust)
-               adjust_deliveries($stock_id, $bom_cost, $date_);
-
-       $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."
-                   WHERE stock_id=".db_escape($stock_id);
-       db_query($sql,"The cost details for the inventory item could not be updated");
-}
 
 /*
        Updates average material cost for item.
@@ -164,124 +106,6 @@ function update_material_cost($stock_id, $qty, $unit_cost, $date)
        db_query($sql,"The cost details for the inventory item could not be updated");
 }
 
-function add_overhead_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
-{
-       if ($qty != 0)
-               $costs /= $qty;
-       $sql = "SELECT overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
-               .db_escape($stock_id);
-       $result = db_query($sql);
-       $myrow = db_fetch($result);
-       $overhead_cost =  $myrow['overhead_cost'];
-       $qoh = get_qoh_on_date($stock_id);
-       if ($qoh < 0)
-               $qoh = 0;
-       if ($adj_only)
-       {
-               if ($qoh>0)
-               {
-                       if ($qoh + $qty != 0)   
-                               $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) /      ($qoh + $qty);
-                       elseif ($qty == 0)
-                               $overhead_cost = ($qoh * $overhead_cost + $costs) / $qoh;
-               }                       
-               else // Journal Entry if QOH is 0/negative 
-               {
-                       global $Refs;
-
-                       $id = get_next_trans_no(ST_JOURNAL);
-                       $ref = $Refs->get_next(ST_JOURNAL, null, $date_);
-
-                       $stock_gl_code = get_stock_gl_code($stock_id);
-                       add_journal(ST_JOURNAL, $id, $costs, $date_, get_company_currency(), $ref);
-                       $memo = "WO Overhead cost settlement JV for zero/negative respository of ".$stock_id;
-                       //Reverse the inventory effect if $qoh <=0
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
-                               $stock_gl_code["inventory_account"],
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, 
-                               -$costs);
-                       //GL Posting to inventory adjustment account
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
-                               $stock_gl_code["assembly_account"],
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
-                               $costs);
-                               
-                       add_audit_trail(ST_JOURNAL, $id, $date_);
-                       add_comments(ST_JOURNAL, $id, $date_, $memo);
-                       $Refs->save(ST_JOURNAL, $id, $ref);     
-                       if ($qty != 0)
-                               $overhead_cost = ($qoh * $overhead_cost + $costs) / $qty;
-               }
-       }
-       else
-       {               
-               if ($qoh + $qty != 0)   
-                       $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) /      ($qoh + $qty);
-       }
-       $sql = "UPDATE ".TB_PREF."stock_master SET overhead_cost=".db_escape($overhead_cost)."
-               WHERE stock_id=".db_escape($stock_id);
-       db_query($sql,"The cost details for the inventory item could not be updated");
-}
-
-function add_labour_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
-{
-       if ($qty != 0)
-               $costs /= $qty;
-       $sql = "SELECT labour_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
-               .db_escape($stock_id);
-       $result = db_query($sql);
-       $myrow = db_fetch($result);
-       $labour_cost =  $myrow['labour_cost'];
-       $qoh = get_qoh_on_date($stock_id);
-       if ($qoh < 0)
-               $qoh = 0;
-       if ($adj_only)
-       {
-               if ($qoh>0)
-               {
-                       if ($qoh + $qty != 0)   
-                               $labour_cost = ($qoh * $labour_cost + $qty * $costs) /  ($qoh + $qty);
-                       elseif ($qty == 0)
-                               $labour_cost = ($qoh * $labour_cost + $costs) / $qoh;
-               }               
-               else // Journal Entry if QOH is 0/negative 
-               {
-                       global $Refs;
-
-                       $id = get_next_trans_no(ST_JOURNAL);
-                       $ref = $Refs->get_next(ST_JOURNAL, null, $date_);
-                       add_journal(ST_JOURNAL, $id, $costs, $date_, get_company_currency(), $ref);
-
-                       $stock_gl_code = get_stock_gl_code($stock_id);
-                       $memo = "WO labour cost settlement JV for zero/negative respository of ".$stock_id;
-                       //Reverse the inventory effect if $qoh <=0
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
-                               $stock_gl_code["inventory_account"],
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, 
-                               -$costs);
-                       //GL Posting to inventory adjustment account
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
-                               $stock_gl_code["assembly_account"],
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
-                               $costs);
-
-                       add_audit_trail(ST_JOURNAL, $id, $date_);
-                       add_comments(ST_JOURNAL, $id, $date_, $memo);
-                       $Refs->save(ST_JOURNAL, $id, $ref);     
-                       if ($qty != 0)
-                               $labour_cost = ($qoh * $labour_cost + $costs) / $qty;
-               }
-       }
-       else
-       {
-               if ($qoh + $qty != 0)
-                       $labour_cost = ($qoh * $labour_cost + $qty * $costs) /  ($qoh + $qty);
-       }       
-       $sql = "UPDATE ".TB_PREF."stock_master SET labour_cost=".db_escape($labour_cost)."
-               WHERE stock_id=".db_escape($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, $adj_only=false)
 {
        if ($qty != 0)
@@ -366,6 +190,17 @@ function add_wo_costs_journal($wo_id, $amount, $cost_type, $cr_acc, $db_acc, $da
        add_gl_trans_std_cost(ST_JOURNAL, $journal_id, $date, $db_acc,
                $dim1, $dim2,  $wo_cost_types[$cost_type], $amount);
 
+       $wip = get_company_pref('wip_act');
+
+       if ($db_acc != $wip)
+       {
+               add_gl_trans_std_cost(ST_JOURNAL, $journal_id, $date, $db_acc,
+                       0, 0,  $wo_cost_types[$cost_type], -$amount);
+
+               add_gl_trans_std_cost(ST_JOURNAL, $journal_id, $date, $wip,
+                       0, 0,  $wo_cost_types[$cost_type], $amount);
+       }
+
        $Refs->save(ST_JOURNAL, $journal_id, $ref);
 
        add_wo_costing($wo_id, $cost_type, ST_JOURNAL, $journal_id);
@@ -376,6 +211,39 @@ function add_wo_costs_journal($wo_id, $amount, $cost_type, $cr_acc, $db_acc, $da
        commit_transaction();
 }
 
+/*
+       Process component usage: generate and post stock move, update average component cost.
+*/
+function work_order_production_gl($woid, $stock_id, $quantity, $date_, $rcv_no)
+{
+       $result = get_wo_requirements($woid);
+
+       // credit all the components
+       $total_cost = 0;
+       while ($bom_item = db_fetch($result))
+       {
+
+               update_wo_requirement_issued($bom_item['id'], $bom_item["units_req"] * $quantity, $bom_item["ComponentCost"]);
+
+               // insert a -ve stock move for each item
+               add_stock_move(ST_MANURECEIVE, $bom_item["stock_id"], $rcv_no,
+                       $bom_item["loc_code"], $date_, "", -$bom_item["units_req"] * $quantity, $bom_item["ComponentCost"], 0);
+
+               if (!is_service($bom_item["mb_flag"]))
+                       $ivaccount = $bom_item["inventory_account"];
+               else
+                       $ivaccount = $bom_item["assembly_account"];
+
+               $memo = $date_.": ".$bom_item["units_req"] ." * ".$bom_item["description"];
+
+               $total_cost += add_gl_trans_std_cost(ST_MANURECEIVE, $rcv_no, $date_, $ivaccount, 0, 0,
+                       $memo, -$bom_item["ComponentCost"] * $bom_item["units_req"] * $quantity);
+       }
+
+    add_gl_trans_std_cost(ST_MANURECEIVE, $rcv_no, $date_, get_company_pref('wip_act'),
+        0, 0, $memo, -$total_cost);
+}
+
 function void_wo_costing($wo_id)
 {
        $res = get_wo_costing($wo_id);
index 4fe8b13db17c88decb80363e9d3b68a8e153e81a..b980781acefa6f194089dd8194f777c18b81497b 100644 (file)
@@ -36,15 +36,13 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w
 
        foreach ($items as $item)
        {
-
                if ($to_work_order)
                        $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
@@ -53,8 +51,8 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w
 
                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);
 
@@ -64,7 +62,7 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w
                else
                        $ivaccount = $stockitem["assembly_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;
        }
@@ -78,7 +76,7 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w
     if (!$wip_account) // backward compatibility
        $wip_account = $stockitem["inventory_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_)
index 9ce682b38ec35fd85acc1d997aebde6f35b1cee0..d4b3832ee82f8d48bb99820c5175a21a668353f0 100644 (file)
@@ -9,14 +9,15 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
-function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
+function work_order_produce($woid, $ref, $quantity, $date_, $memo, $close_wo)
 {
        global $Refs;
 
+// FIXME: support for WO_UNASSEMBLY case
        begin_transaction();
 
        $args = func_get_args();
-       $args = (object)array_combine(array('woid', 'ref', 'quantity', 'date_', 'memo_','close_wo'),
+       $args = (object)array_combine(array('woid', 'ref', 'quantity', 'date_', 'memo','close_wo'),
                $args);
        $args->trans_no = 0;
        hook_db_prewrite($args, ST_MANURECEIVE);
@@ -35,7 +36,7 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
 
        // -------------------------------------------------------------------------
        // insert -ve and update averaged component unit cost for BOM usage (in wo_requirements)
-       work_order_receive_costs($woid, $product["stock_id"], $quantity, $date_, $id);
+       work_order_production_gl($woid, $product["stock_id"], $quantity, $date_, $id);
 
        // update wo quantity and close wo if requested (or finished)
        $closed = work_order_update_finished_quantity($woid, $quantity, $date_, $close_wo);
@@ -70,19 +71,24 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
                $o_cost = get_gl_wo_cost($woid, WO_OVERHEAD);
                $l_cost += get_gl_wo_cost($woid, WO_LABOUR);
 
-               $unit_cost = ($o_cost+$m_cost+$l_cost)/($product['units_issued']+$quantity);
+               $total_cost = $o_cost + $m_cost + $l_cost;
 
-               update_material_cost($product['stock_id'], $product['units_issued']+$quantity, $unit_cost, $date_);
-               // FIXME: ?
-//             update_labour_cost(stock_id, qty, unit_cost);
-//             update_overheads_cost(stock_id, qty, unit_cost);
+           add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, get_company_pref('wip_act'),
+           0, 0, $memo, -$total_cost);
+
+           add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $product['inventory_account'],
+                   0, 0, $memo, $total_cost);
+
+               $unit_cost = $total_cost/($product['units_issued']+$quantity);
 
                add_stock_move(ST_WORKORDER, $product["stock_id"], $woid,
                        $product["loc_code"], $date_, $ref, $product['units_issued']+$quantity, $unit_cost);
+
+               update_material_cost($product['stock_id'], $product['units_issued']+$quantity, $unit_cost, $date_);
        }
 
-       if ($memo_)
-               add_comments(ST_MANURECEIVE, $id, $date_, $memo_);
+       if ($memo)
+               add_comments(ST_MANURECEIVE, $id, $date_, $memo);
 
        $Refs->save(ST_MANURECEIVE, $id, $ref);
        add_audit_trail(ST_MANURECEIVE, $id, $date_, _("Production."));
@@ -93,40 +99,6 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
        commit_transaction();
 }
 
-/*
-       Process component usage: generate and post stock move, update average component cost.
-*/
-function work_order_receive_costs($woid, $stock_id, $quantity, $date_, $rcv_no)
-{
-       $result = get_wo_requirements($woid);
-
-       // credit all the components
-       $total_cost = 0;
-       while ($bom_item = db_fetch($result))
-       {
-
-               $bom_cost = $bom_item["ComponentCost"] * $quantity;
-
-               update_wo_requirement_issued($bom_item['id'], $bom_item["units_req"] * $quantity, $bom_item["ComponentCost"]);
-
-               // insert a -ve stock move for each item
-               add_stock_move(ST_MANURECEIVE, $bom_item["stock_id"], $rcv_no,
-                       $bom_item["loc_code"], $date_, "", -$bom_item["units_req"] * $quantity, $bom_item["ComponentCost"], 0);
-
-               if (!is_service($bom_item["mb_flag"]))
-                       $ivaccount = $bom_item["inventory_account"];
-               else
-                       $ivaccount = $bom_item["assembly_account"];
-
-               $memo = $date_.": ".$bom_item["units_req"] ." * ".$bom_item["description"];
-               $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
-                       $memo, -$bom_cost);
-       }
-
-    add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, get_company_pref('wip_act'),
-        0, 0, $memo, -$total_cost);
-}
-
 //--------------------------------------------------------------------------------------------
 
 function get_work_order_produce($id)
index 395ad6534b1aa4298d4565cfc301968b4c3e3c8f..6bb171c7329d85131ea11a1f9a60dbed0f68f39e 100644 (file)
@@ -13,7 +13,7 @@ function get_wo_requirements($woid)
 {
        $sql = "SELECT req.*, item.description, item.mb_flag, loc.location_name, 
                        center.name AS WorkCentreDescription,
-                       (item.material_cost+item.overhead_cost+item.labour_cost) as ComponentCost,
+                       item.material_cost as ComponentCost,
                        item.inventory_account,
                        item.assembly_account
                FROM (".TB_PREF."wo_requirements req,"
index 8dcaaed33312bb0de1aa754c1a8499c991fd8be6..11c9204fdf37f5c9ca45cd0bba2eeff82b6d66f6 100644 (file)
 */
 function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
        $type, $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc)
-{
-       if (!($type == WO_ADVANCED))
-               return add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, $date_, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc);
-       else
-               return add_work_order_advanced($wo_ref, $loc_code, $units_reqd, $stock_id, $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc);
-}
-
-/*
-       Advanced wrok order entry.
-*/
-function add_work_order_advanced($wo_ref, $loc_code, $units_reqd, $stock_id,
-       $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc)
 {
        global $Refs;
 
        begin_transaction();
        $args = func_get_args();
        $args = (object)array_combine(array('wo_ref', 'loc_code', 'units_reqd', 'stock_id',
-               'date_', 'required_by', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args);
+               'type', 'date_', 'required_by', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args);
+
        $args->woid = 0;
        hook_db_prewrite($args, ST_WORKORDER);
 
+       if ($type != WO_ADVANCED)
+               $required_by = $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 (".db_escape($wo_ref).", ".db_escape($loc_code).", "
        .db_escape($units_reqd).", ".db_escape($stock_id).",
-               ".WO_ADVANCED.", '$date', ".db_escape($required).")";
+               ".db_escape($type).", '$date', ".db_escape($required).")";
        db_query($sql, "could not add work order");
 
        $woid = db_insert_id();
@@ -56,6 +47,24 @@ function add_work_order_advanced($wo_ref, $loc_code, $units_reqd, $stock_id,
        $args->woid = $woid;
        hook_db_postwrite($args, ST_WORKORDER);
 
+       if ($type != WO_ADVANCED)
+       {
+               $stockitem = get_item($stock_id);
+               release_work_order($woid, $date_, '');
+               if ($costs != 0)
+                       add_wo_costs_journal($woid, $costs, WO_OVERHEAD, $cr_acc, $stockitem["assembly_account"],
+                               $date_, $stockitem["dimension_id"], $stockitem["dimension2_id"]);
+               if ($labour != 0)
+                       add_wo_costs_journal($woid, $labour, WO_LABOUR, $cr_lab_acc, $stockitem["assembly_account"],
+                               $date_, $stockitem["dimension_id"], $stockitem["dimension2_id"]);
+
+               if ($type == WO_UNASSEMBLY)
+                       $units_reqd = -$units_reqd;
+
+               $ref = $Refs->get_next(ST_MANURECEIVE, null, $date_);
+               work_order_produce($woid, $ref, $units_reqd, $date_, '', true);
+       }
+
        commit_transaction();
 
        return $woid;
@@ -113,8 +122,10 @@ function delete_work_order($woid, $stock_id, $qty, $date)
 function get_work_order($woid, $allow_null=false)
 {
     $sql = "SELECT wo.*,st.description As StockItemName,l.location_name,
-               l.delivery_address,l.email, l.contact
-               FROM ".TB_PREF."workorders wo, ".TB_PREF."stock_master st, ".TB_PREF."locations l
+               l.delivery_address,l.email, l.contact, st.inventory_account, st.assembly_account
+               FROM ".TB_PREF."workorders wo, "
+                       .TB_PREF."stock_master st, "
+                       .TB_PREF."locations l
                WHERE st.stock_id=wo.stock_id
                AND     l.loc_code=wo.loc_code
                AND wo.id=".db_escape($woid)."
@@ -239,13 +250,8 @@ function void_work_order($woid)
                // restore average product costs 
                $date = sql2date($work_order['date_']);
                $qty = $work_order['units_reqd'];
-               add_material_cost($work_order['stock_id'], -$qty, $date); // remove avg. cost for qty
-               $cost = get_gl_wo_cost($woid, WO_LABOUR); // get the labour cost and reduce avg cost
-               if ($cost != 0)
-                       add_labour_cost($work_order['stock_id'], -$qty, $date, $cost);
-               $cost = get_gl_wo_cost($woid, WO_OVERHEAD); // get the overhead cost and reduce avg cost
-               if ($cost != 0)
-                       add_overhead_cost($work_order['stock_id'], -$qty, $date, $cost);
+
+               // FIXME: update_material_cost
 
                // close workorder
                $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0 WHERE id = "
@@ -266,7 +272,8 @@ function void_work_order($woid)
                // void everything inside the work order : issues, productions, payments
                $date = sql2date($work_order['date_']);
 
-               add_material_cost($work_order['stock_id'], -$work_order['units_reqd'], $date); // remove avg. cost for qty
+               // FIXME: update_material_cost
+
                $result = get_work_order_productions($woid); // check the produced quantity
                $qty = 0;
                while ($row = db_fetch($result))
@@ -283,8 +290,8 @@ function void_work_order($woid)
                $issue_no = 0;
                while ($row = db_fetch($result))
                {
-                       $std_cost = get_standard_cost($row['stock_id']);
-                       $icost = $std_cost * $row['qty_issued'];
+                       $unit_cost = get_unit_cost($row['stock_id']);
+                       $icost = $unit_cost * $row['qty_issued'];
                        $cost += $icost;
                        if ($issue_no == 0)
                                $issue_no = $row['issue_no'];
@@ -299,9 +306,6 @@ function void_work_order($woid)
                if ($cost != 0)
                        add_issue_cost($work_order['stock_id'], -$qty, $date, $cost);
 
-               if ($cost != 0)
-                       add_overhead_cost($work_order['stock_id'], -$qty, $date, $cost);
-
                $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0 WHERE id = "
                        .db_escape($woid);
                db_query($sql, "The work order couldn't be voided");
diff --git a/manufacturing/includes/db/work_orders_quick_db.inc b/manufacturing/includes/db/work_orders_quick_db.inc
deleted file mode 100644 (file)
index 14570f1..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-<?php
-/**********************************************************************
-    Copyright (C) FrontAccounting, LLC.
-       Released under the terms of the GNU General Public License, GPL, 
-       as published by the Free Software Foundation, either version 3 
-       of the License, or (at your option) any later version.
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
-    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
-***********************************************************************/
-/*
-       Quick work order entry, $type is either WO_ASSEMBLY, or WO_UNASSEMBLY
-       All changes in material and manufactured item stock are made during work order entry.
-*/
-function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type, 
-       $date_, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc)
-{
-       global $Refs;
-
-       begin_transaction();
-       $args = func_get_args();
-       $args = (object)array_combine(array('wo_ref', 'loc_code', 'units_reqd', 'stock_id',
-               'type', 'date_', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args);
-       $args->woid = 0;
-       hook_db_prewrite($args, ST_WORKORDER);
-
-       // if unassembling, reverse the stock movements
-       if ($type == WO_UNASSEMBLY)
-               $units_reqd = -$units_reqd;
-
-       add_material_cost($stock_id, $units_reqd, $date_);
-
-       $date = date2sql($date_);
-       if (!isset($costs) || ($costs == ""))
-               $costs = 0;
-       add_overhead_cost($stock_id, $units_reqd, $date_, $costs);
-       if (!isset($labour) || ($labour == ""))
-               $labour = 0;
-       add_labour_cost($stock_id, $units_reqd, $date_, $labour);
-
-       $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).", ".db_escape($units_reqd)
-       .", ".db_escape($units_reqd).", ".db_escape($stock_id).",
-               ".db_escape($type).", ".db_escape($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))
-       {
-
-               $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"] . "',
-                       $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
-               $UnitCost = get_standard_cost($bom_item["component"]);
-               add_stock_move(ST_WORKORDER, $bom_item["component"], $woid,
-                       $bom_item["loc_code"], $date_, $wo_ref, -$item_quantity, $UnitCost, $UnitCost);
-       }
-
-       // -------------------------------------------------------------------------
-       //Negative Stock Handling
-       $qoh = get_qoh_on_date($stock_id);
-       $cost_adjust = false;
-       if ($qoh < 0)
-       {
-               if ($qoh + $units_reqd >= 0)
-                       $cost_adjust = true;
-       }
-
-       //Negative Stock Handling First; Prior to add_stock_move
-       if ($cost_adjust)
-               adjust_deliveries($stock_id, get_standard_cost($stock_id), $date_);
-
-       // -------------------------------------------------------------------------
-
-       // insert a +ve stock move for the item being manufactured
-       add_stock_move(ST_WORKORDER, $stock_id, $woid,  $loc_code, $date_,
-               $wo_ref, $units_reqd, 0);
-
-       // -------------------------------------------------------------------------
-
-       work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $costs, $cr_acc, $labour, $cr_lab_acc);
-
-       // -------------------------------------------------------------------------
-
-       add_comments(ST_WORKORDER, $woid, $date_, $memo_);
-
-       $Refs->save(ST_WORKORDER, $woid, $wo_ref);
-       add_audit_trail(ST_WORKORDER, $woid, $date_,_("Quick production."));
-
-       $args->woid = $woid;
-       hook_db_postwrite($args, ST_WORKORDER);
-
-       commit_transaction();
-       return $woid;
-}
-
-//--------------------------------------------------------------------------------------
-
-function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $costs, $cr_acc, $labour, $cr_lab_acc)
-{
-       $result = get_bom($stock_id);
-
-       // credit all the components
-       $total_cost = 0;
-       while ($bom_item = db_fetch($result))
-       {
-
-               $bom_accounts = get_stock_gl_code($bom_item["component"]);
-
-               $bom_cost = $bom_item["ComponentCost"] * $units_reqd; // ??  * $bom_item["quantity"]
-
-               $memo = $bom_item["quantity"] ." * ".$bom_item["description"];
-
-               if (!is_service($bom_accounts["mb_flag"]))
-                       $ivaccount = $bom_accounts["inventory_account"];
-               else
-                       $ivaccount = $bom_accounts["assembly_account"];
-               $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
-                       $memo, -$bom_cost);
-       }
-
-       $stockitem = get_item($stock_id);
-       // credit additional costs
-       if ($costs != 0.0)
-       {
-               add_wo_costs_journal($woid, $costs, WO_OVERHEAD, $cr_acc, $stockitem["assembly_account"],
-                       $date_, $stockitem["dimension_id"], $stockitem["dimension2_id"]);
-       }
-
-       if ($labour != 0.0)
-       {
-               add_wo_costs_journal($woid, $labour, WO_LABOUR, $cr_lab_acc, $stockitem["assembly_account"],
-                       $date_, $stockitem["dimension_id"], $stockitem["dimension2_id"]);
-       }
-
-       // debit total components $total_cost
-       $memo = _("Produced")." ".$units_reqd. " * ".$stockitem["description"];
-
-    add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $stockitem["inventory_account"],
-        0, 0, $memo, -$total_cost);
-
-       $UnitWOCost = ($total_cost + $costs + $labour)/$units_reqd;
-       update_stock_move(ST_WORKORDER, $woid, $stock_id, $UnitWOCost); 
-}
-
index 16428eec0cafeac897d6736ae3dfb69818b2a87f..8df5b16b2c59706e7a62e4ba9a0d0e000e9fb1f5 100644 (file)
@@ -13,7 +13,6 @@ include_once($path_to_root . "/includes/db/manufacturing_db.inc");
 include_once($path_to_root . "/manufacturing/includes/db/work_centres_db.inc");
 include_once($path_to_root . "/manufacturing/includes/db/work_orders_db.inc");
 include_once($path_to_root . "/manufacturing/includes/db/work_order_costing_db.inc");
-include_once($path_to_root . "/manufacturing/includes/db/work_orders_quick_db.inc");
 include_once($path_to_root . "/manufacturing/includes/db/work_order_issues_db.inc");
 include_once($path_to_root . "/manufacturing/includes/db/work_order_produce_items_db.inc");
 include_once($path_to_root . "/manufacturing/includes/db/work_order_requirements_db.inc");
index 2d55477ba767fb01651173eb6e5ea9ac930b1359..71997576d292b6c16e00e7941f5072fdb5d7f037 100644 (file)
@@ -26,7 +26,7 @@ function display_bom($item_check)
 
         start_table(TABLESTYLE);
         $th = array(_("Component"), _("Description"), _("Work Centre"),
-               _("From Location"), _("Quantity"), _("Unit Cost"), _("Total Cost"));
+               _("From Location"), _("Quantity"), _("Unit Cost"), _("Cost"));
 
         table_header($th);
 
@@ -45,19 +45,34 @@ function display_bom($item_check)
                        label_cell($myrow["WorkCentreDescription"]);
                        label_cell($myrow["location_name"]);
                        qty_cell($myrow["quantity"], false, get_qty_dec($myrow["component"]));
-                       amount_cell($myrow["standard_cost"]);
+                       amount_cell($myrow["ProductCost"]);
                        amount_cell($myrow["ComponentCost"]);
                        end_row();
                $total_cost += $myrow["ComponentCost"];
 
                $j++;
-               If ($j == 12)
+               if ($j == 12)
                {
                        $j = 1;
                        table_header($th);
-               }//end of page full new headings if
-               }//end of while
+               }
+               }
 
+               $item = get_item($item_check);
+               if ($item['labour_cost'] != 0)
+               {
+                       alt_table_row_color($k);
+               label_cells(_("Standard Labour Cost"), number_format2($item['labour_cost'],user_price_dec()),
+               "colspan=6 align=left", "class=odd_row nowrap align=right");
+           end_row();
+               }
+               if ($item['overhead_cost'] != 0)
+               {
+                       alt_table_row_color($k);
+               label_cells(_("Standard Overhead Cost"), number_format2($item['overhead_cost'],user_price_dec()),
+               "colspan=6 align=left", "nowrap align=right");
+           end_row();
+               }
         label_row("<b>" . _("Total Cost") . "</b>", "<b>" . number_format2($total_cost,user_price_dec()) ."</b>",
                "colspan=6 align=right", "nowrap align=right");
                end_table();
index 936685abd9d6877742ed775be455d9c94a50d341..066f80d63a52050feea101fe96a8f7b81c04411f 100644 (file)
@@ -116,7 +116,7 @@ function issue_edit_item_controls(&$order, $line_no=-1)
 
                $dec = $item_info["decimals"];
                $_POST['qty'] = number_format2(0, $dec);
-               $std_cost = $item_info["standard_cost"];
+               $std_cost = $item_info["material_cost"];
                $_POST['units'] = $item_info["units"];
        }
 
index 6e139ec62447cc5c595d4f752bbfc072f15d9932..80ed02dbc31b3165fb6b355d77a0ba0df1ebcfbd 100644 (file)
@@ -33,33 +33,54 @@ if ($_GET['trans_no'] != "")
 }
 
 //-------------------------------------------------------------------------------------------------
-
+function print_gl_rows($result, $title)
+{
+       global $systypes_array;
+
+    if (db_num_rows($result))
+    {
+               table_section_title($title, 7);
+               while($myrow = db_fetch($result)) {
+                       start_row();
+                       label_cell(sql2date($myrow["tran_date"]));
+                       label_cell(get_trans_view_str($myrow['type'],$myrow["type_no"], $systypes_array[$myrow['type']]. ' '.$myrow['type_no']));
+                   label_cell($myrow['account']);
+                       label_cell($myrow['account_name']);
+                       display_debit_or_credit_cells($myrow['amount']);
+                       label_cell($myrow['memo_']);
+                       end_row();
+               }
+       }
+}
 function display_wo_costs($prod_id)
 {
-       global $wo_cost_types;
-
-    $costs = get_gl_wo_cost_trans($prod_id);
-
        br(1);
     start_table(TABLESTYLE);
-    $th = array(_("Date"), _("Type"), _("Amount"), _("Memo"), '');
-    table_header($th);
-       while($myrow = db_fetch($costs)) {
-               start_row();
-               label_cell(sql2date($myrow["tran_date"]));
-               label_cell($wo_cost_types[$myrow["cost_type"]]);
-               amount_cell(-$myrow['amount']);
-               label_cell($myrow['memo_']);
-               label_cell(get_trans_view_str($myrow['trans_type'],$myrow["trans_no"]));
-               end_row();
-       }
+
+       $th = array(_("Date"), _("Transaction"), _("Account Code"), _("Account Name"),
+               _("Debit"), _("Credit"), _("Memo"));
+
+       table_header($th);
+
+       $productions = get_gl_wo_productions($prod_id, true);
+       print_gl_rows($productions, _("Finished Product Requirements"));
+
+       $issues = get_gl_wo_issue_trans($prod_id, -1, true);
+       print_gl_rows($issues, _("Additional Material Issues"));
+
+    $costs = get_gl_wo_cost_trans($prod_id, -1, true);
+       print_gl_rows($costs, _("Additional Costs"));
+
+       $wo = get_gl_trans(ST_WORKORDER, $prod_id);
+       print_gl_rows($wo, _("Finished Product Receival"));
        end_table(1);
 }
 
 //-------------------------------------------------------------------------------------------------
-
 display_heading(sprintf(_("Production Costs for Work Order # %d"), $wo_id));
 
+display_wo_details($wo_id, true);
+
 display_wo_costs($wo_id);
 
 //-------------------------------------------------------------------------------------------------
index 6bdb60e714a5d2a0f72048100de229d383409690..244c4a17c6b4894122b7b1cc306cf4039e017ee1 100644 (file)
@@ -133,20 +133,23 @@ br();
 date_row(_("Date:"), 'date_');
 ref_row(_("Reference:"), 'ref', '');
 
-yesno_list_row(_("Type:"), 'PaymentType', null,        $wo_cost_types[WO_OVERHEAD], $wo_cost_types[WO_LABOUR]);
+yesno_list_row(_("Type:"), 'PaymentType', null,        $wo_cost_types[WO_OVERHEAD], $wo_cost_types[WO_LABOUR], true);
+if (list_updated('PaymentType'))
+       $Ajax->activate('costs');
 
-$item_accounts = get_stock_gl_code($wo_details['stock_id']);
-$_POST['db_acc'] = $item_accounts['assembly_account'];
+$item = get_item($wo_details['stock_id']);
+$_POST['db_acc'] = $item['assembly_account'];
 $r = get_default_bank_account(get_company_pref('curr_default'));
 $_POST['cr_acc'] = $r[0];
+$_POST['costs'] = price_format(get_post('PaymentType')==WO_OVERHEAD ? $item['overhead_cost'] : $item['labour_cost']);
 
 amount_row(_("Additional Costs:"), 'costs');
 gl_all_accounts_list_row(_("Debit Account"), 'db_acc', null);
 gl_all_accounts_list_row(_("Credit Account"), 'cr_acc', null);
 textarea_row(_("Memo:"), 'memo', null, 40, 5);
 end_table(1);
-hidden('dim1', $item_accounts["dimension_id"]);
-hidden('dim2', $item_accounts["dimension2_id"]);
+hidden('dim1', $item["dimension_id"]);
+hidden('dim2', $item["dimension2_id"]);
 
 submit_center('process', _("Process Additional Cost"), true, '', true);
 
index cafdf21145772deeac11ff5cae357394dfb0f716..6a47ad5a1a8dc0b2182072b78268e188f64276c8 100644 (file)
@@ -343,7 +343,6 @@ if (isset($selected_id))
        $_POST['date_'] = sql2date($myrow["date_"]);
        $_POST['RequDate'] = sql2date($myrow["required_by"]);
        $_POST['released_date'] = sql2date($myrow["released_date"]);
-       $_POST['memo_'] = "";
        $_POST['units_issued'] = $myrow["units_issued"];
        $_POST['Costs'] = price_format($myrow["additional_costs"]);
 
@@ -362,6 +361,7 @@ if (isset($selected_id))
 else
 {
        $_POST['units_issued'] = $_POST['released'] = 0;
+
        ref_row(_("Reference:"), 'wo_ref', '', $Refs->get_next(ST_WORKORDER, null, get_post('date_')), false, ST_WORKORDER);
 
        wo_types_list_row(_("Type:"), 'type', null);
@@ -405,20 +405,19 @@ else
     date_row(_("Date") . ":", 'date_', '', true);
        hidden('RequDate', '');
 
-       $bank_act = get_default_bank_account();
-       if (!isset($_POST['Labour']))
+       if (!isset($_POST['Labour']) || list_updated('stock_id') || list_updated('type'))
        {
-               $_POST['Labour'] = price_format(0);
+               $bank_act = get_default_bank_account();
+               $item = get_item(get_post('stock_id'));
+               $_POST['Labour'] = price_format(get_post('type') == WO_ASSEMBLY ? $item['labour_cost'] : 0);
                $_POST['cr_lab_acc'] = $bank_act['account_code'];
+               $_POST['Costs'] = price_format(get_post('type') == WO_ASSEMBLY ? $item['overhead_cost'] : 0);
+               $_POST['cr_acc'] = $bank_act['account_code'];
+               $Ajax->activate('_page_body');
        }
 
        amount_row($wo_cost_types[WO_LABOUR], 'Labour');
        gl_all_accounts_list_row(_("Credit Labour Account"), 'cr_lab_acc', null);
-       if (!isset($_POST['Costs']))
-       {
-               $_POST['Costs'] = price_format(0);
-               $_POST['cr_acc'] = $bank_act['account_code'];
-       }
        amount_row($wo_cost_types[WO_OVERHEAD], 'Costs');
        gl_all_accounts_list_row(_("Credit Overhead Account"), 'cr_acc', null);
 
index 90d84eb47818e56ab027bebaf94ff559b6c51889..d5efafdb21ca86d2fc6157cfa57af0830d908682 100644 (file)
@@ -41,18 +41,11 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date,
     if (is_inventory_item($stock_id) && !$adj_only) 
         handle_negative_inventory($stock_id, $qty, $price_in_home_currency, $date);
        
-       $sql = "SELECT mb_flag, material_cost, labour_cost, overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id);
+       $sql = "SELECT mb_flag, material_cost FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id);
        $result = db_query($sql);
        $myrow = db_fetch($result);
        $material_cost = $myrow['material_cost'];
        
-       //Price adjustment for manufactured item
-       if (!$adj_only && $myrow['mb_flag'] == 'M') 
-       {
-               //reduce overhead_cost and labour_cost from price as those will remain as is
-               $price_in_home_currency = $price_in_home_currency - $myrow['labour_cost'] - $myrow['overhead_cost'];
-       }
-
        $cost_adjust = false;
 
        $qoh = get_qoh_on_date($stock_id);
@@ -132,7 +125,7 @@ function add_grn(&$po)
                        {
                                /*This must be the first receipt of goods against this line */
                                /*Need to get the standard cost as it is now so we can process GL jorunals later*/
-                               $order_line->standard_cost = get_standard_cost($order_line->stock_id);
+                               $order_line->standard_cost = get_unit_cost($order_line->stock_id);
                        }
                        // Update the purchase data table
                        add_or_update_purchase_data($po->supplier_id, $order_line->stock_id, $order_line->price, 
index 94f2f72f408d1f541c144c38c1f1d3d6a67eb356..89c4d94b4d5097803047f44bd5bef820f9344985 100644 (file)
@@ -197,7 +197,7 @@ function add_direct_supp_trans($cart)
                foreach($cart->line_items as $key => $line) {
                $inv->add_grn_to_trans($line->grn_item_id, $line->po_detail_rec, $line->stock_id,
                        $line->item_description, $line->receive_qty, 0, $line->receive_qty,
-                       $line->price, $line->price, true, get_standard_cost($line->stock_id), '');
+                       $line->price, $line->price, true, get_unit_cost($line->stock_id), '');
                $total += round2(($line->receive_qty * $line->price), user_price_dec());
        }
        $inv->tax_overrides = $cart->tax_overrides;
index 4246e8e01c298a5dfe3ebfd76e27ad1e1a87313a..c2dc63a3716866014262e38a2c72eadb12a540e7 100644 (file)
@@ -33,7 +33,7 @@ print_price_listing();
 function fetch_items($category=0)
 {
                $sql = "SELECT item.stock_id, item.description AS name,
-                               item.material_cost+item.labour_cost+item.overhead_cost AS Standardcost,
+                               item.material_cost AS Standardcost,
                                item.category_id,item.units,
                                category.description
                        FROM ".TB_PREF."stock_master item,
index 403e4b4ba28c89ccf5947a29a870d4b589b4989b..30cc9ac947d8826fca08568a08c2b49738646a79 100644 (file)
@@ -105,8 +105,8 @@ function getTransactions($category, $location, $date)
                        item.description, item.inactive,
                        move.loc_code,
                        SUM(move.qty) AS QtyOnHand, 
-                       item.material_cost + item.labour_cost + item.overhead_cost AS UnitCost,
-                       SUM(move.qty) *(item.material_cost + item.labour_cost + item.overhead_cost) AS ItemTotal 
+                       item.material_cost AS UnitCost,
+                       SUM(move.qty) * item.material_cost AS ItemTotal 
                        FROM "
                        .TB_PREF."stock_master item,"
                        .TB_PREF."stock_category category,"
index 28297c5825f23c33a37840afd9b0a0b2cb27469f..971c7e20553c246bd79625f6e9724f27e23f9125 100644 (file)
@@ -45,7 +45,7 @@ function getTransactions($category, $location, $fromcust, $from, $to, $show_serv
                        move.tran_date,
                        SUM(-move.qty) AS qty,
                        SUM(-move.qty*move.price) AS amt,
-                       SUM(-IF(move.standard_cost <> 0, move.qty * move.standard_cost, move.qty *(item.material_cost + item.labour_cost + item.overhead_cost))) AS cost
+                       SUM(-IF(move.standard_cost <> 0, move.qty * move.standard_cost, move.qty *item.material_cost)) AS cost
                FROM ".TB_PREF."stock_master item,
                        ".TB_PREF."stock_category category,
                        ".TB_PREF."debtor_trans trans,
index b35987824408c2102fab500cb8a189ef22c39582..ec206552f532a21d2fcd3858d54feb3e1e110831 100644 (file)
@@ -181,7 +181,7 @@ function add_credit_movements_item(&$credit_note, &$credit_line,
        $credit_type, $price, $credited_invoice=0)
 {
     //Chaitanya : Stamp current cost in stock moves $credit_line does not fetch cost
-    $curr_std_cost = get_standard_cost($credit_line->stock_id);
+    $curr_std_cost = get_unit_cost($credit_line->stock_id);
 
        $reference = _("Return");
        if ($credited_invoice) {
@@ -210,12 +210,12 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
 
        $total = 0;
        /* insert gl_trans to credit stock and debit cost of sales at standard cost*/
-       $standard_cost = get_standard_cost($order_line->stock_id);
-       if ($standard_cost != 0) {
+       $unit_cost = get_unit_cost($order_line->stock_id);
+       if ($unit_cost != 0) {
                /*first the cost of sales entry*/
 
                $total += add_gl_trans_std_cost(ST_CUSTCREDIT, $credit_no, $date_, $stock_gl_codes["cogs_account"],
-                       $dim, $dim2, "", -($standard_cost * $order_line->qty_dispatched),
+                       $dim, $dim2, "", -($unit_cost * $order_line->qty_dispatched),
                        PT_CUSTOMER, $order->customer_id,
                        "The cost of sales GL posting could not be inserted");
 
@@ -228,7 +228,7 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_,
                }
 
                $total += add_gl_trans_std_cost(ST_CUSTCREDIT, $credit_no, $date_, $stock_entry_account, 0, 0,
-                       "", ($standard_cost * $order_line->qty_dispatched),
+                       "", ($unit_cost * $order_line->qty_dispatched),
                        PT_CUSTOMER, $order->customer_id,
                        "The stock side (or write off) of the cost of sales GL posting could not be inserted");
 
index 6337ba7c624e298cab838db6ebe3422d218321a4..3f8ffc87dad5e50342e4e3185c11fb762e19f615 100644 (file)
@@ -78,7 +78,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
                $line_tax = get_full_price_for_item($delivery_line->stock_id, $delivery_line->price,
                        0, $delivery->tax_included, $delivery->tax_group_array) - $line_taxfree_price;
 
-               $delivery_line->standard_cost = get_standard_cost($delivery_line->stock_id);
+               $delivery_line->standard_cost = get_unit_cost($delivery_line->stock_id);
 
                /* add delivery details for all lines */
                write_customer_trans_detail_item(ST_CUSTDELIVERY, $delivery_no, $delivery_line->stock_id,
index 7f3257afad9c8db2b9184eb3adcfdf02b4e82ea2..710a5300523ea16ce54be40df16d1df0ad73c80c 100644 (file)
@@ -285,7 +285,7 @@ function get_sales_order_details($order_no, $trans_type) {
                                qty_sent as qty_done,
                                item.units,
                                item.mb_flag,
-                               item.material_cost + item.labour_cost + item.overhead_cost AS standard_cost
+                               item.material_cost
                        FROM ".TB_PREF."sales_order_details line,"
                                .TB_PREF."stock_master item
                        WHERE line.stk_code = item.stock_id
@@ -340,7 +340,7 @@ function read_sales_order($order_no, &$order, $trans_type)
                {
                        $order->add_to_cart($line_no,$myrow["stk_code"],$myrow["quantity"],
                                $myrow["unit_price"], $myrow["discount_percent"],
-                               $myrow["qty_done"], $myrow["standard_cost"], $myrow["description"], $myrow["id"] );
+                               $myrow["qty_done"], $myrow["material_cost"], $myrow["description"], $myrow["id"] );
                $line_no++;
                }
        }
index 949ee79e2f404b5d47b2c19348704eefc174a9d6..2177d2e7afbc70b239fb6d389bbc9d3a94008748 100644 (file)
@@ -47,7 +47,7 @@ function add_gl_trans_customer($type, $type_no, $date_, $account, $dimension, $d
 
 function get_calculated_price($stock_id, $add_pct)
 {
-       $avg = get_standard_cost($stock_id);
+       $avg = get_unit_cost($stock_id);
        if ($avg == 0)
                return 0;
        return round2($avg * (1 + $add_pct / 100), user_price_dec());
index 485776933d56ea779482ab0dbe43bd036516b05c..3517196df208c18965e70d7b915fde0269af05be 100644 (file)
@@ -531,7 +531,7 @@ function check_item_data()
                return false;
        }
 
-       $cost_home = get_standard_cost(get_post('stock_id')); // Added 2011-03-27 Joe Hunt
+       $cost_home = get_unit_cost(get_post('stock_id')); // Added 2011-03-27 Joe Hunt
        $cost = $cost_home / get_exchange_rate_from_home_currency($_SESSION['Items']->customer_currency, $_SESSION['Items']->document_date);
        if (input_num('price') < $cost)
        {
index b220d62ad76a268d602ef473549775c06effe06b..a2f3e6f2c17266d7b624057de93caa3ba3be6650 100644 (file)
@@ -30,3 +30,4 @@ ALTER TABLE `0_wo_issue_items` ADD COLUMN  `unit_cost` double NOT NULL default '
 ALTER TABLE `0_wo_requirements` CHANGE COLUMN `std_cost` `unit_cost` double NOT NULL default '0';
 
 ALTER TABLE `0_stock_master` DROP COLUMN `last_cost`;
+UPDATE `0_stock_master` SET `material_cost`=`material_cost`+`labour_cost`+`overhead_cost`;