Fixed wrong calculaiton of standard cost during Advanced Manufacturing. Petros.
[fa-stable.git] / manufacturing / includes / db / work_order_produce_items_db.inc
index 38af2add9b98efd04427682b1d22abdcb67aa694..ac9171e757c15ec211dc3bb2aee1d28596614eb4 100644 (file)
@@ -53,12 +53,25 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
 
        // Chaitanya: stamp BOM cost to finished item
        $m_cost = 0;
-    $result = get_bom($details["stock_id"]);
+       $result = get_bom($details["stock_id"]);
        while ($bom_item = db_fetch($result))
        {
                $standard_cost = get_standard_cost($bom_item['component']);
                $m_cost += ($bom_item['quantity'] * $standard_cost);
-       }       
+       }
+       // new Joe Hunt 2015.10.15      
+       // additilnal costs.
+       if (work_order_has_issues($woid))
+       {
+               $res = get_additional_issues($woid);
+               while ($issue = db_fetch($res))
+               {
+                       $standard_cost = get_standard_cost($issue['stock_id']);
+                       $m_cost += ($issue['qty_issued'] * $standard_cost);
+               }
+       }
+       $m_cost += (get_gl_wo_cost($woid, WO_LABOUR) / $quantity);
+       $m_cost += (get_gl_wo_cost($woid, WO_OVERHEAD) / $quantity);
 
        // insert a +ve stock move for the item being manufactured
        // negative means "unproduce" or unassemble
@@ -150,7 +163,8 @@ function void_work_order_produce($type_no)
                if (!is_service($issue["mb_flag"]))
                        $ivaccount = $issue["inventory_account"];
                else
-                       $ivaccount = $issue["cogs_account"];            
+                       //$ivaccount = $issue["cogs_account"];          
+                       $ivaccount = $issue["assembly_account"]; // changed 2015.10.14 by Petros .              
                
                if ($issue_cost != 0)
                {