Rerun of Moving bugfixes from 2.3 to 2.4, Manufacturing routines
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 12 Dec 2015 08:39:02 +0000 (09:39 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 12 Dec 2015 08:39:02 +0000 (09:39 +0100)
gl/includes/db/gl_db_trans.inc
manufacturing/includes/db/work_order_costing_db.inc
manufacturing/includes/db/work_orders_db.inc
manufacturing/includes/db/work_orders_quick_db.inc
manufacturing/includes/manufacturing_db.inc
manufacturing/includes/manufacturing_ui.inc
manufacturing/work_order_costs.php

index 20c902322c74c9a121d57fa1e93128f6d3f9b80b..daac59ad062fcaddd2ed6c8be7016f56f690e553 100644 (file)
@@ -42,7 +42,7 @@ function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension
                else
                        $memo_ = $_SESSION["wa_current_user"]->username . " - " . $memo_;
        }
-       if ($type != ST_WORKORDER && (!is_subledger_account($account) || $account==get_company_pref('grn_clearing_act')))
+       if (!is_subledger_account($account) || $account==get_company_pref('grn_clearing_act'))
                $person_id = $person_type_id = null;
        
        $sql = "INSERT INTO ".TB_PREF."gl_trans ( type, type_no, tran_date,
@@ -206,16 +206,21 @@ function get_gl_trans($type, $trans_id)
 
 function get_gl_wo_cost_trans($trans_id, $cost_type=-1)
 {
-       $sql = "SELECT gl.*, chart.account_name FROM ".TB_PREF."gl_trans gl, ".TB_PREF."chart_master chart
-               WHERE chart.account_code=gl.account AND gl.type=".ST_WORKORDER." AND gl.type_no=".db_escape($trans_id)."
-               AND gl.person_type_id=".PT_WORKORDER;
-       if ($cost_type!= -1)
-               $sql .= " AND gl.person_id=".db_escape($cost_type);
+       $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
+               WHERE 
+                       costing.workorder_id=".db_escape($trans_id)
+               ."      AND chart.account_code=gl.account
+                       AND gl.type=costing.trans_type
+                       AND gl.type_no=costing.trans_no";
+       if ($cost_type != -1)
+               $sql .= " AND costing.cost_type=".db_escape($cost_type);
        $sql .= " AND amount < 0";
-
+       
        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 272e732825e999d593c73007b2edfacd578e0d1c..931b4c26b107c7dbb0424efcdafe36fdd6a75af5 100644 (file)
@@ -37,7 +37,7 @@ function delete_wo_costing($trans_type, $trans_no)
 }
 //--------------------------------------------------------------------------------------
 
-function add_material_cost($stock_id, $qty, $date_, $advanced=false)
+function add_material_cost($stock_id, $qty, $date_, $advanced=false, $woid=0)
 {
        $m_cost = 0;
     $result = get_bom($stock_id);
@@ -47,19 +47,31 @@ function add_material_cost($stock_id, $qty, $date_, $advanced=false)
                $m_cost += ($bom_item['quantity'] * $standard_cost);
        }
        $bom_cost = $m_cost;
-       
+       // new 2015.10.15       
+       // additilnal costs.
+       $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)
@@ -71,7 +83,7 @@ function add_material_cost($stock_id, $qty, $date_, $advanced=false)
        if ($qoh + $qty != 0)
        {
                if ($qoh == 0)
-                       $material_cost += $m_cost;
+                       $material_cost = $m_cost; // corrected 27.10.2014
                else
                        $material_cost = ($qoh * $material_cost + $qty * $m_cost) /     ($qoh + $qty);
        }
@@ -98,10 +110,13 @@ function add_overhead_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
                $qoh = 0;
        if ($adj_only)
        {
-               if ($qty != 0)
-                       $costs = $qty * $costs;
                if ($qoh>0)
-                       $overhead_cost = ($qoh * $overhead_cost + $costs) / $qoh;
+               {
+                       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;
@@ -119,7 +134,7 @@ function add_overhead_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
                                -$costs);
                        //GL Posting to inventory adjustment account
                        add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
-                               $stock_gl_code["adjustment_account"],
+                               $stock_gl_code["assembly_account"],
                                $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
                                $costs);
                                
@@ -154,10 +169,13 @@ function add_labour_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
                $qoh = 0;
        if ($adj_only)
        {
-               if ($qty != 0)
-                       $costs = $qty * $costs;
                if ($qoh>0)
-                       $labour_cost = ($qoh * $labour_cost + $costs) / $qoh;   
+               {
+                       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;
@@ -175,7 +193,7 @@ function add_labour_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
                                -$costs);
                        //GL Posting to inventory adjustment account
                        add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
-                               $stock_gl_code["adjustment_account"],
+                               $stock_gl_code["assembly_account"],
                                $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
                                $costs);
 
@@ -210,10 +228,8 @@ function add_issue_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
                $qoh = 0;
        if ($adj_only)
        {
-               if ($qty != 0)
-                       $costs = $qty * $costs;
                if ($qoh>0)
-                       $material_cost = $costs / $qoh;
+                       $material_cost = ($qoh * $material_cost + $costs) / $qoh;
                else // Journal Entry if QOH is 0/negative
                {
                        global $Refs;
@@ -231,7 +247,7 @@ function add_issue_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
                                -$costs);
                        //GL Posting to inventory adjustment account
                        add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
-                               $stock_gl_code["adjustment_account"],
+                               $stock_gl_code["assembly_account"],
                                $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
                                $costs);
                                
@@ -245,7 +261,7 @@ function add_issue_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
        else
        {
                if ($qoh + $qty != 0)   
-                       $material_cost = ($qty * $costs) /      ($qoh + $qty);
+                       $material_cost = ($qoh * $material_cost + $qty * $costs) /      ($qoh + $qty);
        }       
        $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=material_cost+"
                .db_escape($material_cost)
@@ -265,6 +281,7 @@ function add_wo_costs_journal($wo_id, $amount, $cost_type, $cr_acc, $db_acc, $da
        begin_transaction();
 
     $journal_id = get_next_trans_no(ST_JOURNAL);
+
     if (!$ref) $ref = $Refs->get_next(ST_JOURNAL, null, $date);
 
        add_gl_trans_std_cost(ST_JOURNAL, $journal_id, $date, $cr_acc,
index 15ea30f7cd3dbb70e05b622bbdfad06769b03c24..d59522cf01afbc71555004a7d9e95973bb708ca3 100644 (file)
 ***********************************************************************/
 //--------------------------------------------------------------------------------------
 
-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;
-       // new 2015.10.15       
-       // additilnal costs.
-       $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'] - $i_cost; // $i_cost was already added to material cost
-       $m_cost += $i_cost;
-       /* no, why will we do that?? Joe Hunt 2015.10.17
-       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) // 27.10.2014 apmuthu and dz.
-                       $material_cost = $m_cost;
-               else    
-                       $material_cost = ($qoh * $material_cost + $qty * $m_cost) /     ($qoh + $qty);
-       }
-       if ($advanced && $cost_adjust) // new 2010-02-10
-               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");
-}
-
-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);
-                       
-                       $stock_gl_code = get_stock_gl_code($stock_id);
-                       $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"], // changed 2015.10.14 from adjustment to assembly account. Petros.
-                               $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) // 27.10.2014 dz
-                               $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);
-                       
-                       $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"], // changed 2015.10.14 from adjustment to assembly account. Petros.
-                               $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) // 27.10.2014 dz
-                               $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=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)
-               $costs /= $qty;
-       $sql = "SELECT 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'];
-       $qoh = get_qoh_on_date($stock_id);
-       if ($qoh < 0)
-               $qoh = 0;
-       if ($adj_only)
-       {
-               if ($qoh>0)
-                       $material_cost = ($qoh * $material_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);
-                       
-                       $stock_gl_code = get_stock_gl_code($stock_id);
-                       $memo = "WO Issue 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"], // changed 2015.10.14 from adjustment to assembly account. Petros.
-                               $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) // 27.10.2014 dz
-                               $material_cost = $costs / $qty; 
-               }
-       }
-       else
-       {
-               if ($qoh + $qty != 0)   
-                       $material_cost = ($qoh * $material_cost + $qty * $costs) /      ($qoh + $qty);
-       }       
-       $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");
-}
-
 function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
        $type, $date_, $required_by, $memo_, $costs, $cr_acc, $labour, $cr_lab_acc)
 {
index e07ec8f35ad82ce3d61391547c4a64cd5d2efe68..73b16e625c7fa0527fa701186fd230fc604209e8 100644 (file)
@@ -112,7 +112,7 @@ function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type,
 
 function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced=0, $costs=0, $cr_acc="", $labour=0, $cr_lab_acc="")
 {
-       global $wo_cost_types;
+       //global $wo_cost_types;
        $result = get_bom($stock_id);
 
        // credit all the components
@@ -155,35 +155,13 @@ function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced
        $item_accounts = get_stock_gl_code($stock_id);
        if ($costs != 0.0)
        {
-               add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $cr_acc,
-                       0, 0, $wo_cost_types[WO_OVERHEAD], -$costs, PT_WORKORDER, WO_OVERHEAD);
-               $is_bank_to = is_bank_account($cr_acc);
-       if ($is_bank_to)
-       {
-               add_bank_trans(ST_WORKORDER, $woid, $is_bank_to, "",
-                       $date_, -$costs, PT_WORKORDER, WO_OVERHEAD, get_company_currency(),
-                       "Cannot insert a destination bank transaction");
-       }
-                       
-               add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $item_accounts["assembly_account"],
-                       $item_accounts["dimension_id"], $item_accounts["dimension2_id"], $wo_cost_types[WO_OVERHEAD], $costs, 
-                       PT_WORKORDER, WO_OVERHEAD);
+               add_wo_costs_journal($woid, $costs, WO_OVERHEAD, $cr_acc, $item_accounts["assembly_account"],
+                       $date_, $item_accounts["dimension_id"], $item_accounts["dimension2_id"]);
        }
        if ($labour != 0.0) // only for quick
        {
-               add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $cr_lab_acc,
-                       0, 0, $wo_cost_types[WO_LABOUR], -$labour, PT_WORKORDER, WO_LABOUR);
-               $is_bank_to = is_bank_account($cr_lab_acc);
-       if ($is_bank_to)
-       {
-               add_bank_trans(ST_WORKORDER, $woid, $is_bank_to, "",
-                       $date_, -$labour, PT_WORKORDER, WO_LABOUR, get_company_currency(),
-                       "Cannot insert a destination bank transaction");
-       }
-                       
-               add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $item_accounts["assembly_account"],
-                       $item_accounts["dimension_id"], $item_accounts["dimension2_id"], $wo_cost_types[WO_LABOUR], $labour, 
-                       PT_WORKORDER, WO_LABOUR);
+               add_wo_costs_journal($woid, $labour, WO_LABOUR, $cr_lab_acc, $item_accounts["assembly_account"],
+                       $date_, $item_accounts["dimension_id"], $item_accounts["dimension2_id"]);
        }
        // debit total components $total_cost
        $stockitem = get_item($stock_id);
index d42375c954a9f92369ac355b03f4290c26ea92f0..16428eec0cafeac897d6736ae3dfb69818b2a87f 100644 (file)
@@ -12,6 +12,7 @@
 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");
index b95d2641f09f3fdaae79d9b4f89695710ba32db8..2d55477ba767fb01651173eb6e5ea9ac930b1359 100644 (file)
@@ -245,7 +245,7 @@ function display_wo_payments($woid)
                        alt_table_row_color($k);
 
                label_cell(get_gl_view_str( $myrow["type"], $myrow["type_no"], $myrow["type_no"]));
-               label_cell($wo_cost_types[$myrow['person_id']]);
+               label_cell($wo_cost_types[$myrow['cost_type']]);
                $date = sql2date($myrow["tran_date"]);
                label_cell($date);
                        amount_cell(-($myrow['amount']));
index eb089384547bf86a92eef22588ae0ccb1ea47da6..6bdb60e714a5d2a0f72048100de229d383409690 100644 (file)
@@ -66,10 +66,8 @@ if (strlen($wo_details[0]) == 0)
 
 //--------------------------------------------------------------------------------------------------
 
-function can_process()
+function can_process($wo_details)
 {
-       global $wo_details;
-       
        if (!check_num('costs', 0))
        {
                display_error(_("The amount entered is not a valid number or less then zero."));
@@ -101,32 +99,15 @@ function can_process()
 
 //--------------------------------------------------------------------------------------------------
 
-if (isset($_POST['process']) && can_process() == true)
+if (isset($_POST['process']) && can_process($wo_details) == true)
 {
        $date = $_POST['date_'];
-       begin_transaction();
-       add_gl_trans_std_cost(ST_WORKORDER, $_POST['selected_id'], $_POST['date_'], $_POST['cr_acc'],
-               0, 0, $date.": ".$wo_cost_types[$_POST['PaymentType']], -input_num('costs'), PT_WORKORDER, $_POST['PaymentType']);
-       $is_bank_to = is_bank_account($_POST['cr_acc']);
-       if ($is_bank_to)
-       {
-               add_bank_trans(ST_WORKORDER, $_POST['selected_id'], $is_bank_to, "",
-                       $_POST['date_'], -input_num('costs'), PT_WORKORDER, $_POST['PaymentType'], get_company_currency(),
-                       "Cannot insert a destination bank transaction");
-       }
+       $memo = $_POST['memo'];
+       $ref  = $_POST['ref'];
+
+       add_wo_costs_journal($_POST['selected_id'], input_num('costs'), $_POST['PaymentType'], 
+               $_POST['cr_acc'], $_POST['db_acc'], $date, $_POST['dim1'], $_POST['dim2'], $memo, $ref);
 
-       add_gl_trans_std_cost(ST_WORKORDER, $_POST['selected_id'], $_POST['date_'], $_POST['db_acc'],
-               $_POST['dim1'], $_POST['dim2'], $date.": ".$wo_cost_types[$_POST['PaymentType']], input_num('costs'), PT_WORKORDER, 
-                       $_POST['PaymentType']);
-                       
-       //Apply the costs to manfuctured stock item as adjustement
-       $wo = get_work_order($_POST['selected_id']);
-       if ($_POST['PaymentType'] == 0)
-               add_labour_cost($wo['stock_id'], $wo['units_reqd'], $_POST['date_'], input_num('costs'), true);
-       else
-               add_overhead_cost($wo['stock_id'], $wo['units_reqd'], $_POST['date_'], input_num('costs'), true);
-                       
-       commit_transaction();   
        meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_POST['selected_id']);
 }