EOL cleanup.
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Sat, 26 Mar 2011 10:54:30 +0000 (11:54 +0100)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Sat, 26 Mar 2011 10:54:30 +0000 (11:54 +0100)
inventory/cost_update.php
inventory/includes/db/items_adjust_db.inc
inventory/includes/db/items_trans_db.inc
inventory/manage/item_codes.php
inventory/purchasing_data.php
manufacturing/includes/db/work_order_issues_db.inc
manufacturing/includes/db/work_order_produce_items_db.inc
manufacturing/includes/db/work_orders_db.inc
manufacturing/includes/db/work_orders_quick_db.inc
manufacturing/work_order_costs.php
reporting/rep305.php

index 0d872191016480bb95fcc10cc2dad52d6c55aa7a..7268d797ab9bde32bdceac23e5a98ada8594991a 100644 (file)
@@ -83,14 +83,14 @@ if (!isset($_POST['stock_id']))
        $_POST['stock_id'] = get_global_stock_item();
 
 echo "<center>" . _("Item:"). "&nbsp;";
-//echo stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);\r
-echo stock_items_list('stock_id', $_POST['stock_id'], false, true);\r
+//echo stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
+echo stock_items_list('stock_id', $_POST['stock_id'], false, true);
 
 echo "</center><hr>";
 set_global_stock_item($_POST['stock_id']);
 
 $myrow = get_item($_POST['stock_id']);
-\r
+
 div_start('cost_table');
 hidden("OldMaterialCost", $myrow["material_cost"]);
 hidden("OldLabourCost", $myrow["labour_cost"]);
index 77d5b02ea9adedb27e111cf3e48d76ea9cb9799c..7be0f9bbb05a1b759b9cb816f8a14af19592008d 100644 (file)
@@ -51,7 +51,7 @@ function add_stock_adjustment($items, $location, $date_, $type, $increase, $refe
 function void_stock_adjustment($type_no)
 {
        hook_db_prevoid(ST_INVADJUST, $type_no);
-       void_gl_trans(ST_INVADJUST, $type_no);\r
+       void_gl_trans(ST_INVADJUST, $type_no);
        void_stock_move(ST_INVADJUST, $type_no);
 }
 
@@ -81,39 +81,39 @@ function add_stock_adjustment_item($adj_id, $stock_id, $location, $date_, $type,
        display_db_error("Cannot do inventory adjustment for Service item : $stock_id", "");
     }
 
-       /* Logic shifted to function update_average_material_cost\r
-       //Chaitanya : If negative adjustment result in negative or zero inventory \r
-       //then difference should be adjusted\r
-       $qoh = get_qoh_on_date($stock_id);\r
-       if ($qoh + $quantity <= 0 && $qoh > 0) //Positive inventory turning zero/negative\r
-       {\r
-               global $Refs;\r
-\r
-               $id = get_next_trans_no(ST_JOURNAL);\r
-               $ref = $Refs->get_next(ST_JOURNAL);\r
-               $diff = get_standard_cost($stock_id) - $standard_cost;\r
-               \r
-               if ($diff !=0)\r
-               {\r
-                       $stock_gl_code = get_stock_gl_code($stock_id);\r
-                       $memo = _("For zero inventory of ").$stock_id." INVADJ REF: ".$reference;\r
-                       //Reverse the inventory effect if $qoh <=0\r
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, \r
-                               $stock_gl_code["inventory_account"],\r
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, \r
-                               -$qoh * $diff);\r
-                       //GL Posting to inventory adjustment account\r
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, \r
-                               $stock_gl_code["adjustment_account"],\r
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,\r
-                               $qoh * $diff);\r
-                               \r
-                       add_audit_trail(ST_JOURNAL, $id, $date_);\r
-                       add_comments(ST_JOURNAL, $id, $date_, $memo);\r
-                       $Refs->save(ST_JOURNAL, $id, $ref);     \r
-               }               \r
-       }*/\r
-\r
+       /* Logic shifted to function update_average_material_cost
+       //Chaitanya : If negative adjustment result in negative or zero inventory 
+       //then difference should be adjusted
+       $qoh = get_qoh_on_date($stock_id);
+       if ($qoh + $quantity <= 0 && $qoh > 0) //Positive inventory turning zero/negative
+       {
+               global $Refs;
+
+               $id = get_next_trans_no(ST_JOURNAL);
+               $ref = $Refs->get_next(ST_JOURNAL);
+               $diff = get_standard_cost($stock_id) - $standard_cost;
+               
+               if ($diff !=0)
+               {
+                       $stock_gl_code = get_stock_gl_code($stock_id);
+                       $memo = _("For zero inventory of ").$stock_id." INVADJ REF: ".$reference;
+                       //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, 
+                               -$qoh * $diff);
+                       //GL Posting to inventory adjustment account
+                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, 
+                               $stock_gl_code["adjustment_account"],
+                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,
+                               $qoh * $diff);
+                               
+                       add_audit_trail(ST_JOURNAL, $id, $date_);
+                       add_comments(ST_JOURNAL, $id, $date_, $memo);
+                       $Refs->save(ST_JOURNAL, $id, $ref);     
+               }               
+       }*/
+
        update_average_material_cost(null, $stock_id, $standard_cost, $quantity, $date_);
 
        add_stock_move(ST_INVADJUST, $stock_id, $adj_id, $location,
index 3d364a446407afcf16c71afabbf2e2b41ef89455..78930e81d9bce8ca9dc4132646aa25fa9664ef0e 100644 (file)
@@ -16,20 +16,20 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co
 {
        $mb_flag = get_mb_flag($stock_id);
     
-       $update_no = -1;\r
-\r
+       $update_no = -1;
+
     if (is_service($mb_flag))
     {
-       //display_db_error("Cannot do cost update for Service item : $stock_id", "");   \r
-               \r
-               //Chaitanya\r
-               $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."\r
-               WHERE stock_id=".db_escape($stock_id);\r
-               \r
-               db_query($sql,"The cost details for the inventory item could not be updated");\r
-               \r
-               return $update_no;\r
-               \r
+       //display_db_error("Cannot do cost update for Service item : $stock_id", "");   
+               
+               //Chaitanya
+               $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");
+               
+               return $update_no;
+               
     }          
        
        begin_transaction();
@@ -44,26 +44,26 @@ function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_co
        $qoh = get_qoh_on_date($_POST['stock_id']);
        
        $date_ = Today();
-       if (!is_date_in_fiscalyear($date_))\r
-               $date_ = end_fiscalyear();\r
-\r
+       if (!is_date_in_fiscalyear($date_))
+               $date_ = end_fiscalyear();
+
        if ($qoh > 0)
        {
                $new_cost = $material_cost + $labour_cost + $overhead_cost;
 
                $value_of_change = round2($qoh * ($new_cost - $last_cost), user_price_dec());
-\r
+
                if ($value_of_change != 0)
-               {\r
-                       $stock_gl_code = get_stock_gl_code($stock_id);\r
-                       $update_no = get_next_trans_no(ST_COSTUPDATE);\r
+               {
+                       $stock_gl_code = get_stock_gl_code($stock_id);
+                       $update_no = get_next_trans_no(ST_COSTUPDATE);
                        $memo_ = "Cost was " . $last_cost . " changed to " . $new_cost . " x quantity on hand of $qoh";
                        add_gl_trans_std_cost(ST_COSTUPDATE, $update_no, $date_, $stock_gl_code["adjustment_account"], 
                                $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], $memo_, (-$value_of_change));     
 
                        add_gl_trans_std_cost(ST_COSTUPDATE, $update_no, $date_, $stock_gl_code["inventory_account"], 0, 0, $memo_, 
                                $value_of_change);
-               }               \r
+               }               
        }
 
        add_audit_trail(ST_COSTUPDATE, $update_no, $date_);
index 1b37162f6c548cf7f2c471e51baf22d8b92c62dd..892c0a359d42a01520cb78d05a4bfa70ce616788 100644 (file)
@@ -103,9 +103,9 @@ if (!isset($_POST['stock_id']))
        $_POST['stock_id'] = get_global_stock_item();
 
 echo "<center>" . _("Item:"). "&nbsp;";
-//Chaitanya : Manufcatured item visible\r
-echo stock_items_list('stock_id', $_POST['stock_id'], false, true);\r
-//echo stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);\r
+//Chaitanya : Manufcatured item visible
+echo stock_items_list('stock_id', $_POST['stock_id'], false, true);
+//echo stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
 
 echo "<hr></center>";
 
index f85bc089e29f47175155cb7442129f7729e4d5b9..0a7a01c3d02be91c6cae1fe1610af77d2ae9b32e 100644 (file)
@@ -99,9 +99,9 @@ if (!isset($_POST['stock_id']))
        $_POST['stock_id'] = get_global_stock_item();
 
 echo "<center>" . _("Item:"). "&nbsp;";
-//Chaitanya : All items can be purchased\r
-echo stock_items_list('stock_id', $_POST['stock_id'], false, true);\r
-//echo stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);\r
+//Chaitanya : All items can be purchased
+echo stock_items_list('stock_id', $_POST['stock_id'], false, true);
+//echo stock_purchasable_items_list('stock_id', $_POST['stock_id'], false, true);
 
 echo "<hr></center>";
 
index 7cc79f007c8eb6bfed55fd9d0dad6370e26a5e4f..ca2f4a86883b5d213f556cc460a5c738b3b41275 100644 (file)
@@ -55,11 +55,11 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w
                if ($to_work_order)
                        $item->quantity = -$item->quantity;
 
-               //Chaitanya: Stamp the standard_cost\r
-               $standard_cost = get_standard_cost($item->stock_id);\r
+               //Chaitanya: Stamp the standard_cost
+               $standard_cost = get_standard_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);\r
+                       $location, $date_, $memo_, -$item->quantity, $standard_cost);
 
                $sql = "INSERT INTO ".TB_PREF."wo_issue_items (issue_id, stock_id, qty_issued)
                        VALUES (".db_escape($number).", ".db_escape($item->stock_id).", "
@@ -70,20 +70,20 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w
                $issue_cost = $standard_cost * $item->quantity;
                $issue = get_stock_gl_code($item->stock_id);
         $stockitem = get_item($item->stock_id);
-               \r
-               //Chaitanya : Compatibility for Service Items\r
-               if (!is_service($issue["mb_flag"]))\r
-                       $ivaccount = $issue["inventory_account"];\r
-               else\r
-                       $ivaccount = $issue["cogs_account"];            \r
-               \r
-        $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,\r
+               
+               //Chaitanya : Compatibility for Service Items
+               if (!is_service($issue["mb_flag"]))
+                       $ivaccount = $issue["inventory_account"];
+               else
+                       $ivaccount = $issue["cogs_account"];            
+               
+        $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
                 $date_.": "._("Issue of")." ".$stockitem["description"], -$issue_cost);                        
                $issue_total += $issue_cost;
        }       
        if ($issue_total != 0)
-               //Chaitanya : Apply cost to QOH as adjustment only\r
-               add_issue_cost($details['stock_id'], $details['units_reqd'], $date_, $issue_total, true);\r
+               //Chaitanya : Apply cost to QOH as adjustment only
+               add_issue_cost($details['stock_id'], $details['units_reqd'], $date_, $issue_total, true);
        $issue = get_stock_gl_code($details['stock_id']);
     $stockitem = get_item($details['stock_id']);
     add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $issue["inventory_account"],
@@ -166,63 +166,63 @@ function void_work_order_issue($type_no)
 {
        begin_transaction();
        hook_db_prevoid(ST_MANUISSUE, $type_no);
-       \r
-       //Chaitanya : Skip processing already voided entry i.e. explicitly voided\r
-       $void_entry = get_voided_entry(ST_MANUISSUE, $type_no);\r
-       if ($void_entry)\r
-               return;\r
+       
+       //Chaitanya : Skip processing already voided entry i.e. explicitly voided
+       $void_entry = get_voided_entry(ST_MANUISSUE, $type_no);
+       if ($void_entry)
+               return;
 
        // void the actual issue items and their quantities
        $sql = "UPDATE ".TB_PREF."wo_issue_items Set qty_issued = 0 WHERE issue_id="
                .db_escape($type_no);
        db_query($sql,"A work order issue item could not be voided");
 
-       // void any related gl trans\r
-       //Chaitanya : Nothing happens due to next statement as all gl postings are done against WO\r
-       //void_gl_trans(ST_MANUISSUE, $type_no, true);\r
-       \r
-       //Chaitanya : Reverse the gl posting\r
-       $issue = get_work_order_issue($type_no);\r
-       $manf_stock_id = $issue["stock_id"];\r
-       $date_ = sql2date($issue["issue_date"]);\r
-       $woid = $issue["workorder_id"];\r
-               \r
-       $result = get_stock_moves(ST_MANUISSUE, $type_no);\r
-       $total_cost = 0;\r
-       $issue_total = 0;\r
-       while ($myrow = db_fetch($result))\r
-       {\r
-               $issue_cost = $myrow["qty"]*$myrow["standard_cost"];\r
-               $issue = get_stock_gl_code($myrow["stock_id"]);\r
-        $stockitem = get_item($myrow["stock_id"]);\r
-               \r
-               //Chaitanya : Compatibility for Service Items\r
-               if (!is_service($issue["mb_flag"]))\r
-                       $ivaccount = $issue["inventory_account"];\r
-               else\r
-                       $ivaccount = $issue["cogs_account"];            \r
-               \r
-               if ($issue_cost != 0)\r
-               {\r
-                       $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,\r
-                               $date_.": "._("Reversed the issue of")." ".$stockitem["description"],\r
-                               -$issue_cost);                  \r
-                       $issue_total += $issue_cost;\r
-               }\r
-       }\r
-       if ($issue_total != 0)\r
-               //Chaitanya : Revese cost effect on manfactured stock item as adjustment only\r
-               add_issue_cost($manf_stock_id, 0, $date_, $issue_total, true);\r
-       $issue = get_stock_gl_code($manf_stock_id);\r
-    $stockitem = get_item($manf_stock_id);\r
-       if ($total_cost != 0)\r
-               add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $issue["inventory_account"],\r
-                       0, 0, $date_.": "._("Reversed the issue to")." ".$stockitem["description"], \r
-                       -$total_cost);  \r
-       \r
-       //Chaitanya : Shifted below void all related stock moves\r
+       // void any related gl trans
+       //Chaitanya : Nothing happens due to next statement as all gl postings are done against WO
+       //void_gl_trans(ST_MANUISSUE, $type_no, true);
+       
+       //Chaitanya : Reverse the gl posting
+       $issue = get_work_order_issue($type_no);
+       $manf_stock_id = $issue["stock_id"];
+       $date_ = sql2date($issue["issue_date"]);
+       $woid = $issue["workorder_id"];
+               
+       $result = get_stock_moves(ST_MANUISSUE, $type_no);
+       $total_cost = 0;
+       $issue_total = 0;
+       while ($myrow = db_fetch($result))
+       {
+               $issue_cost = $myrow["qty"]*$myrow["standard_cost"];
+               $issue = get_stock_gl_code($myrow["stock_id"]);
+        $stockitem = get_item($myrow["stock_id"]);
+               
+               //Chaitanya : Compatibility for Service Items
+               if (!is_service($issue["mb_flag"]))
+                       $ivaccount = $issue["inventory_account"];
+               else
+                       $ivaccount = $issue["cogs_account"];            
+               
+               if ($issue_cost != 0)
+               {
+                       $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
+                               $date_.": "._("Reversed the issue of")." ".$stockitem["description"],
+                               -$issue_cost);                  
+                       $issue_total += $issue_cost;
+               }
+       }
+       if ($issue_total != 0)
+               //Chaitanya : Revese cost effect on manfactured stock item as adjustment only
+               add_issue_cost($manf_stock_id, 0, $date_, $issue_total, true);
+       $issue = get_stock_gl_code($manf_stock_id);
+    $stockitem = get_item($manf_stock_id);
+       if ($total_cost != 0)
+               add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $issue["inventory_account"],
+                       0, 0, $date_.": "._("Reversed the issue to")." ".$stockitem["description"], 
+                       -$total_cost);  
+       
+       //Chaitanya : Shifted below void all related stock moves
        void_stock_move(ST_MANUISSUE, $type_no);
-       \r
+       
        commit_transaction();
 }
 
index 1c72f94f3cc8d8e25409aa9d93380a549d35753a..38af2add9b98efd04427682b1d22abdcb67aa694 100644 (file)
@@ -44,26 +44,26 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo_, $close_wo)
        db_query($sql,"A work order manufacture could not be added");
 
        $id = db_insert_id();
-       \r
-       // -------------------------------------------------------------------------\r
+       
+       // -------------------------------------------------------------------------
 
-       work_order_quick_costs($woid, $details["stock_id"], $quantity, $date_, $id);\r
-       \r
+       work_order_quick_costs($woid, $details["stock_id"], $quantity, $date_, $id);
+       
        // -------------------------------------------------------------------------
 
-       // Chaitanya: stamp BOM cost to finished item\r
-       $m_cost = 0;\r
-    $result = get_bom($details["stock_id"]);\r
-       while ($bom_item = db_fetch($result))\r
-       {\r
-               $standard_cost = get_standard_cost($bom_item['component']);\r
-               $m_cost += ($bom_item['quantity'] * $standard_cost);\r
-       }       \r
+       // Chaitanya: stamp BOM cost to finished item
+       $m_cost = 0;
+    $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);
+       }       
 
        // insert a +ve stock move for the item being manufactured
        // negative means "unproduce" or unassemble
        add_stock_move(ST_MANURECEIVE, $details["stock_id"], $id,
-               $details["loc_code"], $date_, $ref, $quantity, $m_cost);\r
+               $details["loc_code"], $date_, $ref, $quantity, $m_cost);
        // update wo quantity and close wo if requested
        work_order_update_finished_quantity($woid, $quantity, $close_wo);
 
@@ -118,53 +118,53 @@ function void_work_order_produce($type_no)
 {
        begin_transaction();
        hook_db_prevoid(ST_MANURECEIVE, $type_no);
-       \r
-       //Chaitanya : Skip processing already voided entry i.e. explicitly voided\r
-       $void_entry = get_voided_entry(ST_MANURECEIVE, $type_no);\r
-       if ($void_entry)\r
-               return; \r
+       
+       //Chaitanya : Skip processing already voided entry i.e. explicitly voided
+       $void_entry = get_voided_entry(ST_MANURECEIVE, $type_no);
+       if ($void_entry)
+               return; 
 
        $row = get_work_order_produce($type_no);
 
        // deduct the quantity of this production from the parent work order
        work_order_update_finished_quantity($row["workorder_id"], -$row["quantity"]);
 
-       //Chaitanya : skipped this step as BOM may have got changed\r
-       //work_order_quick_costs($row['workorder_id'], $row['stock_id'], -$row['quantity'], sql2date($row['date_']), $type_no);\r
-
-       // void any related gl trans\r
-       //Chaitanya : Nothing happens due to next statement as all gl postings are done against WO\r
-       //void_gl_trans(ST_MANURECEIVE, $type_no, true);\r
-       \r
-       $woid = $row["workorder_id"];\r
-       $date_ = sql2date($row["date_"]);\r
-               \r
-       $result = get_stock_moves(ST_MANURECEIVE, $type_no);\r
-       while ($myrow = db_fetch($result))\r
-       {\r
-               $issue_cost = $myrow["qty"]*$myrow["standard_cost"];\r
-               $issue = get_stock_gl_code($myrow["stock_id"]);\r
-        $stockitem = get_item($myrow["stock_id"]);\r
-               \r
-               //Chaitanya : Compatibility for Service Items\r
-               if (!is_service($issue["mb_flag"]))\r
-                       $ivaccount = $issue["inventory_account"];\r
-               else\r
-                       $ivaccount = $issue["cogs_account"];            \r
-               \r
-               if ($issue_cost != 0)\r
-               {\r
-                       add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,\r
-                               $date_.": "._("Reversed the production ")." ".$stockitem["description"],\r
-                               -$issue_cost);\r
-               }\r
-       }       \r
-                       \r
+       //Chaitanya : skipped this step as BOM may have got changed
+       //work_order_quick_costs($row['workorder_id'], $row['stock_id'], -$row['quantity'], sql2date($row['date_']), $type_no);
+
+       // void any related gl trans
+       //Chaitanya : Nothing happens due to next statement as all gl postings are done against WO
+       //void_gl_trans(ST_MANURECEIVE, $type_no, true);
+       
+       $woid = $row["workorder_id"];
+       $date_ = sql2date($row["date_"]);
+               
+       $result = get_stock_moves(ST_MANURECEIVE, $type_no);
+       while ($myrow = db_fetch($result))
+       {
+               $issue_cost = $myrow["qty"]*$myrow["standard_cost"];
+               $issue = get_stock_gl_code($myrow["stock_id"]);
+        $stockitem = get_item($myrow["stock_id"]);
+               
+               //Chaitanya : Compatibility for Service Items
+               if (!is_service($issue["mb_flag"]))
+                       $ivaccount = $issue["inventory_account"];
+               else
+                       $ivaccount = $issue["cogs_account"];            
+               
+               if ($issue_cost != 0)
+               {
+                       add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
+                               $date_.": "._("Reversed the production ")." ".$stockitem["description"],
+                               -$issue_cost);
+               }
+       }       
+                       
        // clear the production record
        $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=".db_escape($type_no);
-       db_query($sql, "Cannot void a wo production");                  \r
-       \r
-       //Chaitanya : Shifted below\r
+       db_query($sql, "Cannot void a wo production");                  
+       
+       //Chaitanya : Shifted below
        // void all related stock moves
        void_stock_move(ST_MANURECEIVE, $type_no);
 
index 8cee8bd946948b9f6ad0be853034e1a495c4cb97..981b000627b0dc0dd96f4316e0cf99a21fd967ce 100644 (file)
@@ -11,8 +11,8 @@
 ***********************************************************************/
 //--------------------------------------------------------------------------------------
 
-//Chaitanya : Added $advanced Parameter for Advanced Manufacturing\r
-function add_material_cost($stock_id, $qty, $date_, $advanced=false)\r
+//Chaitanya : Added $advanced Parameter for Advanced Manufacturing
+function add_material_cost($stock_id, $qty, $date_, $advanced=false)
 {
        $m_cost = 0;
     $result = get_bom($stock_id);
@@ -21,46 +21,46 @@ function add_material_cost($stock_id, $qty, $date_, $advanced=false)
                $standard_cost = get_standard_cost($bom_item['component']);
                $m_cost += ($bom_item['quantity'] * $standard_cost);
        }
-       $bom_cost = $m_cost;\r
-       \r
+       $bom_cost = $m_cost;
+       
        //$dec = user_price_dec();
        //price_decimal_format($m_cost, $dec);
-       $sql = "SELECT material_cost, labour_cost, overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = "\r
+       $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'];
-       \r
-       //Chaitanya : Upating material cost without considering labour, overhead costs results in invalid costing       \r
-       if ($advanced)\r
-       {\r
-               //reduce overhead_cost and labour_cost from price as those will remain as is\r
-               $m_cost = $m_cost - $myrow['labour_cost'] - $myrow['overhead_cost'];\r
-       }\r
-       \r
+       
+       //Chaitanya : Upating material cost without considering labour, overhead costs results in invalid costing       
+       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, null, $date_);
        $qoh = get_qoh_on_date($stock_id);
-       $cost_adjust = false;\r
+       $cost_adjust = false;
        if ($qoh < 0)
-       {\r
-               if ($qoh + $qty >= 0)\r
-                       $cost_adjust = true;\r
+       {
+               if ($qoh + $qty >= 0)
+                       $cost_adjust = true;
                $qoh = 0;
-       }               \r
+       }               
        if ($qoh + $qty != 0)   
                $material_cost = ($qoh * $material_cost + $qty * $m_cost) /     ($qoh + $qty);
-       //$material_cost = round2($material_cost, $dec);\r
-       \r
-       if ($advanced && $cost_adjust) // new 2010-02-10\r
-               adjust_deliveries($stock_id, $bom_cost, $date_);        \r
-       \r
-       $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."\r
-                   WHERE stock_id=".db_escape($stock_id);\r
+       //$material_cost = round2($material_cost, $dec);
+       
+       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");
 }
 
-//Chaitanya : Added Adjustement Only Parameter\r
-function add_overhead_cost($stock_id, $qty, $date_, $costs, $adj_only=false)\r
+//Chaitanya : Added Adjustement Only Parameter
+function add_overhead_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
 {
        //$dec = user_price_dec();
        //price_decimal_format($costs, $dec); 
@@ -75,50 +75,50 @@ function add_overhead_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
        $qoh = get_qoh_on_date($stock_id);
        if ($qoh < 0)
                $qoh = 0;
-       if ($adj_only)\r
-       {\r
-               if ($qty != 0)\r
-                       $costs = $qty * $costs;\r
-               if ($qoh>0)\r
-                       $overhead_cost = ($qoh * $overhead_cost + $costs) / $qoh;\r
-               else //Chaitanya : Pass JV if qoh is 0/negative \r
-               {\r
-                       global $Refs;\r
-\r
-                       $id = get_next_trans_no(ST_JOURNAL);\r
-                       $ref = $Refs->get_next(ST_JOURNAL);\r
-                       \r
-                       $stock_gl_code = get_stock_gl_code($stock_id);\r
-                       $memo = "WO Overhead cost settlement JV for zero/negative respository of ".$stock_id;\r
-                       //Reverse the inventory effect if $qoh <=0\r
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, \r
-                               $stock_gl_code["inventory_account"],\r
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, \r
-                               -$costs);\r
-                       //GL Posting to inventory adjustment account\r
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, \r
-                               $stock_gl_code["adjustment_account"],\r
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,\r
-                               $costs);\r
-                               \r
-                       add_audit_trail(ST_JOURNAL, $id, $date_);\r
-                       add_comments(ST_JOURNAL, $id, $date_, $memo);\r
-                       $Refs->save(ST_JOURNAL, $id, $ref);     \r
-               }\r
-       }\r
-       else\r
-       {               \r
-               if ($qoh + $qty != 0)   \r
-                       $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) /      ($qoh + $qty);\r
-       }\r
+       if ($adj_only)
+       {
+               if ($qty != 0)
+                       $costs = $qty * $costs;
+               if ($qoh>0)
+                       $overhead_cost = ($qoh * $overhead_cost + $costs) / $qoh;
+               else //Chaitanya : Pass JV 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["adjustment_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);     
+               }
+       }
+       else
+       {               
+               if ($qoh + $qty != 0)   
+                       $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) /      ($qoh + $qty);
+       }
        //$overhead_cost = round2($overhead_cost, $dec);        
        $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");
 }
 
-//Chaitanya : Added Adjustement Only Parameter\r
-function add_labour_cost($stock_id, $qty, $date_, $costs, $adj_only=false)\r
+//Chaitanya : Added Adjustement Only Parameter
+function add_labour_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
 {
        //$dec = user_price_dec();
        //price_decimal_format($costs, $dec); 
@@ -133,50 +133,50 @@ function add_labour_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
        $qoh = get_qoh_on_date($stock_id);
        if ($qoh < 0)
                $qoh = 0;
-       if ($adj_only)\r
-       {\r
-               if ($qty != 0)\r
-                       $costs = $qty * $costs;\r
-               if ($qoh>0)\r
-                       $labour_cost = ($qoh * $labour_cost + $costs) / $qoh;   \r
-               else //Chaitanya : Pass JV if qoh is 0/negative \r
-               {\r
-                       global $Refs;\r
-\r
-                       $id = get_next_trans_no(ST_JOURNAL);\r
-                       $ref = $Refs->get_next(ST_JOURNAL);\r
-                       \r
-                       $stock_gl_code = get_stock_gl_code($stock_id);\r
-                       $memo = "WO labour cost settlement JV for zero/negative respository of ".$stock_id;\r
-                       //Reverse the inventory effect if $qoh <=0\r
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, \r
-                               $stock_gl_code["inventory_account"],\r
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, \r
-                               -$costs);\r
-                       //GL Posting to inventory adjustment account\r
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, \r
-                               $stock_gl_code["adjustment_account"],\r
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,\r
-                               $costs);\r
-                               \r
-                       add_audit_trail(ST_JOURNAL, $id, $date_);\r
-                       add_comments(ST_JOURNAL, $id, $date_, $memo);\r
-                       $Refs->save(ST_JOURNAL, $id, $ref);     \r
-               }\r
-       }\r
-       else\r
-       {               \r
-               if ($qoh + $qty != 0)   \r
-                       $labour_cost = ($qoh * $labour_cost + $qty * $costs) /  ($qoh + $qty);\r
-       }\r
+       if ($adj_only)
+       {
+               if ($qty != 0)
+                       $costs = $qty * $costs;
+               if ($qoh>0)
+                       $labour_cost = ($qoh * $labour_cost + $costs) / $qoh;   
+               else //Chaitanya : Pass JV 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["adjustment_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);     
+               }
+       }
+       else
+       {               
+               if ($qoh + $qty != 0)   
+                       $labour_cost = ($qoh * $labour_cost + $qty * $costs) /  ($qoh + $qty);
+       }
        //$labour_cost = round2($labour_cost, $dec);    
        $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");
 }
 
-//Chaitanya : Added Adjustement Only Parameter\r
-function add_issue_cost($stock_id, $qty, $date_, $costs, $adj_only=false)\r
+//Chaitanya : Added Adjustement Only Parameter
+function add_issue_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
 {
        if ($qty != 0)
                $costs /= $qty;
@@ -191,42 +191,42 @@ function add_issue_cost($stock_id, $qty, $date_, $costs, $adj_only=false)
        $qoh = get_qoh_on_date($stock_id);
        if ($qoh < 0)
                $qoh = 0;
-       if ($adj_only)\r
-       {\r
-               if ($qty != 0)\r
-                       $costs = $qty * $costs;\r
-               if ($qoh>0)\r
-                       $material_cost = $costs / $qoh;\r
-               else //Chaitanya : Pass JV if qoh is 0/negative \r
-               {\r
-                       global $Refs;\r
-\r
-                       $id = get_next_trans_no(ST_JOURNAL);\r
-                       $ref = $Refs->get_next(ST_JOURNAL);\r
-                       \r
-                       $stock_gl_code = get_stock_gl_code($stock_id);\r
-                       $memo = "WO Issue settlement JV for zero/negative respository of ".$stock_id;\r
-                       //Reverse the inventory effect if $qoh <=0\r
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, \r
-                               $stock_gl_code["inventory_account"],\r
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo, \r
-                               -$costs);\r
-                       //GL Posting to inventory adjustment account\r
-                       add_gl_trans_std_cost(ST_JOURNAL, $id, $date_, \r
-                               $stock_gl_code["adjustment_account"],\r
-                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], $memo,\r
-                               $costs);\r
-                               \r
-                       add_audit_trail(ST_JOURNAL, $id, $date_);\r
-                       add_comments(ST_JOURNAL, $id, $date_, $memo);\r
-                       $Refs->save(ST_JOURNAL, $id, $ref);     \r
-               }\r
-       }\r
-       else\r
-       {\r
-               if ($qoh + $qty != 0)   \r
-                       $material_cost = ($qty * $costs) /      ($qoh + $qty);\r
-       }\r
+       if ($adj_only)
+       {
+               if ($qty != 0)
+                       $costs = $qty * $costs;
+               if ($qoh>0)
+                       $material_cost = $costs / $qoh;
+               else //Chaitanya : Pass JV 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["adjustment_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);     
+               }
+       }
+       else
+       {
+               if ($qoh + $qty != 0)   
+                       $material_cost = ($qty * $costs) /      ($qoh + $qty);
+       }
        //$material_cost = round2($material_cost, $dec);        
        $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=material_cost+"
                .db_escape($material_cost)
@@ -249,8 +249,8 @@ function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
        $args->woid = 0;
        hook_db_prewrite($args, ST_WORKORDER);
 
-       //Chaitanya : Material cost should be added at time of production as per BOM at the time.\r
-       //add_material_cost($stock_id, $units_reqd, $date_);\r
+       //Chaitanya : Material cost should be added at time of production as per BOM at the time.
+       //add_material_cost($stock_id, $units_reqd, $date_);
 
        $date = date2sql($date_);
        $required = date2sql($required_by);
@@ -287,9 +287,9 @@ function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
                'date_', 'required_by', 'memo_'), $args);
        hook_db_prewrite($args, ST_WORKORDER);
 
-       //Chaitanya: Material Cost to be calculated at production\r
-       //add_material_cost($_POST['old_stk_id'], -$_POST['old_qty'], $date_);\r
-       //add_material_cost($stock_id, $units_reqd, $date_);\r
+       //Chaitanya: Material Cost to be calculated at production
+       //add_material_cost($_POST['old_stk_id'], -$_POST['old_qty'], $date_);
+       //add_material_cost($stock_id, $units_reqd, $date_);
 
        $date = date2sql($date_);
        $required = date2sql($required_by);
@@ -314,8 +314,8 @@ function delete_work_order($woid)
        begin_transaction();
        hook_db_prevoid(ST_WORKORDER, $woid);
 
-       //Chaitanya : Cost calculation are affected only at time of production\r
-       //add_material_cost($_POST['stock_id'], -$_POST['quantity'], $_POST['date_']);\r
+       //Chaitanya : Cost calculation are affected only at time of production
+       //add_material_cost($_POST['stock_id'], -$_POST['quantity'], $_POST['date_']);
 
        // delete the work order requirements
        delete_wo_requirements($woid);
@@ -445,9 +445,9 @@ function void_work_order($woid)
        $work_order = get_work_order($woid);
        if (!($work_order["type"] == WO_ADVANCED))
        {
-               //Chaitanya : Removed WO costing from here. Handled in void_stock_move\r
-               //Reason - if BOM is changed since WO was executed then add_material_cost will result in incorrect costing as it is based on current BOM for material cost.\r
-               /*$date = sql2date($work_order['date_']);\r
+               //Chaitanya : Removed WO costing from here. Handled in void_stock_move
+               //Reason - if BOM is changed since WO was executed then add_material_cost will result in incorrect costing as it is based on current BOM for material cost.
+               /*$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
@@ -455,7 +455,7 @@ function void_work_order($woid)
                        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);*/\r
+                       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);
@@ -474,52 +474,52 @@ function void_work_order($woid)
        {
                // void everything inside the work order : issues, productions, payments
                $date = sql2date($work_order['date_']);
-               \r
-               //Chaitanya : Removed WO costing from here. Handled in void_stock_move\r
-               //Reason - if BOM is changed since WO was executed then add_material_cost will result in incorrect costing as it is based on current BOM for material cost.\r
-               //add_material_cost($work_order['stock_id'], -$work_order['units_reqd'], $date); // remove avg. cost for qty\r
-               \r
+               
+               //Chaitanya : Removed WO costing from here. Handled in void_stock_move
+               //Reason - if BOM is changed since WO was executed then add_material_cost will result in incorrect costing as it is based on current BOM for material cost.
+               //add_material_cost($work_order['stock_id'], -$work_order['units_reqd'], $date); // remove avg. cost for qty
+               
                $result = get_work_order_productions($woid); // check the produced quantity
                $qty = 0;
                while ($row = db_fetch($result))
                {
-                       //Chaitanya : Use native function for voiding\r
-                       void_work_order_produce($row['id']);\r
-                       \r
-                       //Post voided entry if not prevoided explicitly\r
-                       $void_entry = get_voided_entry(ST_MANURECEIVE, $row['id']);\r
-                       if ($void_entry)\r
-                               continue;\r
-                       $memo_ = _("Voiding Work Order Trans # ").$woid;\r
-                       add_audit_trail(ST_MANURECEIVE, $row['id'], today(), _("Voided.")."\n".$memo_);\r
-                       add_voided_entry(ST_MANURECEIVE, $row['id'], today(), $memo_);                  \r
-               \r
-                       /*$qty += $row['quantity'];\r
+                       //Chaitanya : Use native function for voiding
+                       void_work_order_produce($row['id']);
+                       
+                       //Post voided entry if not prevoided explicitly
+                       $void_entry = get_voided_entry(ST_MANURECEIVE, $row['id']);
+                       if ($void_entry)
+                               continue;
+                       $memo_ = _("Voiding Work Order Trans # ").$woid;
+                       add_audit_trail(ST_MANURECEIVE, $row['id'], today(), _("Voided.")."\n".$memo_);
+                       add_voided_entry(ST_MANURECEIVE, $row['id'], today(), $memo_);                  
+               
+                       /*$qty += $row['quantity'];
                        // clear the production record
-                       $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=".$row['id'];\r
+                       $sql = "UPDATE ".TB_PREF."wo_manufacture SET quantity=0 WHERE id=".$row['id'];
                        db_query($sql, "Cannot void a wo production");
                        
-                       void_stock_move(ST_MANURECEIVE, $row['id']); // and void the stock moves; */\r
+                       void_stock_move(ST_MANURECEIVE, $row['id']); // and void the stock moves; */
                }
-               //Chaitanya : Get all work order issues\r
-               //$result = get_additional_issues($woid); // check the issued quantities\r
-               $result = get_work_order_issues($woid);\r
+               //Chaitanya : Get all work order issues
+               //$result = get_additional_issues($woid); // check the issued quantities
+               $result = get_work_order_issues($woid);
                $cost = 0;
                $issue_no = 0;
                while ($row = db_fetch($result))
                {
-                       //Chaitanya : Use native function for voiding\r
-                       void_work_order_issue($row['issue_no']);\r
-                       \r
-                       //Post voided entry if not prevoided explicitly\r
-                       $void_entry = get_voided_entry(ST_MANUISSUE, $row['issue_no']);\r
-                       if ($void_entry)\r
-                               continue;\r
-                       $memo_ = _("Voiding Work Order Trans # ").$woid;\r
-                       add_audit_trail(ST_MANUISSUE, $row['issue_no'], today(), _("Voided.")."\n".$memo_);\r
-                       add_voided_entry(ST_MANUISSUE, $row['issue_no'], today(), $memo_);                              \r
-                       \r
-                       /*$std_cost = get_standard_cost($row['stock_id']);\r
+                       //Chaitanya : Use native function for voiding
+                       void_work_order_issue($row['issue_no']);
+                       
+                       //Post voided entry if not prevoided explicitly
+                       $void_entry = get_voided_entry(ST_MANUISSUE, $row['issue_no']);
+                       if ($void_entry)
+                               continue;
+                       $memo_ = _("Voiding Work Order Trans # ").$woid;
+                       add_audit_trail(ST_MANUISSUE, $row['issue_no'], today(), _("Voided.")."\n".$memo_);
+                       add_voided_entry(ST_MANUISSUE, $row['issue_no'], today(), $memo_);                              
+                       
+                       /*$std_cost = get_standard_cost($row['stock_id']);
                        $icost = $std_cost * $row['qty_issued'];
                        $cost += $icost;
                        if ($issue_no == 0)
@@ -527,24 +527,24 @@ function void_work_order($woid)
                        // void the actual issue items and their quantities
                        $sql = "UPDATE ".TB_PREF."wo_issue_items SET qty_issued = 0 WHERE issue_id="
                                .db_escape($row['id']);
-                       db_query($sql,"A work order issue item could not be voided");*/ \r
-               }\r
-               \r
-               //Chaitaya : Voiding each issue handles the \r
-               //if ($issue_no != 0)\r
-                       //void_stock_move(ST_MANUISSUE, $issue_no); // and void the stock moves \r
-               //if ($cost != 0)\r
-                       //add_issue_cost($work_order['stock_id'], -$qty, $date, $cost);\r
-
-               //Chaitanya : Reverse the cost effects on $work_order['stock_id'] as adjustement\r
+                       db_query($sql,"A work order issue item could not be voided");*/ 
+               }
+               
+               //Chaitaya : Voiding each issue handles the 
+               //if ($issue_no != 0)
+                       //void_stock_move(ST_MANUISSUE, $issue_no); // and void the stock moves 
+               //if ($cost != 0)
+                       //add_issue_cost($work_order['stock_id'], -$qty, $date, $cost);
+
+               //Chaitanya : Reverse the cost effects on $work_order['stock_id'] as adjustement
                $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);\r
-                       add_labour_cost($work_order['stock_id'], 1, $date, -$cost, true);\r
+                       //add_labour_cost($work_order['stock_id'], -$qty, $date, $cost);
+                       add_labour_cost($work_order['stock_id'], 1, $date, -$cost, true);
                $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);\r
-                       add_overhead_cost($work_order['stock_id'], 1, $date, -$cost, true);\r
+                       //add_overhead_cost($work_order['stock_id'], -$qty, $date, $cost);
+                       add_overhead_cost($work_order['stock_id'], 1, $date, -$cost, true);
                
                $sql = "UPDATE ".TB_PREF."workorders SET closed=1,units_reqd=0,units_issued=0 WHERE id = "
                        .db_escape($woid);
index 31fbadb87202f5b835c0c1b12eb5c02113d50b5d..e91797ba17ef89edafa0d97f12b28352491d0b1c 100644 (file)
@@ -66,21 +66,21 @@ function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type,
         db_query($sql, "The work order requirements could not be added");
 
                // insert a -ve stock move for each item
-               // Chaitanya: Updated to record price and cost as std_cost for work order issued item\r
-               $UnitCost = get_standard_cost($bom_item["component"]);\r
+               // Chaitanya: Updated to record price and cost as std_cost for work order issued 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, 0, 1, $UnitCost);\r
+                       $bom_item["loc_code"], $date_, $wo_ref, -$item_quantity, $UnitCost, 0, 1, $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;
        }
-       \r
-       // -------------------------------------------------------------------------\r
-       //Negative Stock Handling\r
-       $qoh = get_qoh_on_date($stock_id);\r
-       $cost_adjust = false;\r
-       if ($qoh < 0)\r
-       {\r
-               if ($qoh + $units_reqd > 0)\r
-                       $cost_adjust = true;\r
-       }\r
 
        // -------------------------------------------------------------------------
 
@@ -93,12 +93,12 @@ function add_work_order_quick($wo_ref, $loc_code, $units_reqd, $stock_id, $type,
        work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, 0, $costs, $cr_acc, $labour, $cr_lab_acc);
 
        // -------------------------------------------------------------------------
-       \r
-       //Negative Stock Handling\r
-       if ($cost_adjust)\r
-               adjust_deliveries($stock_id, get_standard_cost($stock_id), $date_);\r
-               \r
-       //--------------------------------------------------------------------------\r
+       
+       //Negative Stock Handling
+       if ($cost_adjust)
+               adjust_deliveries($stock_id, get_standard_cost($stock_id), $date_);
+               
+       //--------------------------------------------------------------------------
 
        add_comments(ST_WORKORDER, $woid, $date_, $memo_);
 
@@ -120,8 +120,8 @@ function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced
 
        // credit all the components
        $total_cost = 0;
-       //Chaitanya : capture the exact i.e. non-rounded cost to avoid rounding error amplification\r
-       $total_material_cost = 0;\r
+       //Chaitanya : capture the exact i.e. non-rounded cost to avoid rounding error amplification
+       $total_material_cost = 0;
        while ($bom_item = db_fetch($result))
        {
                $bom_accounts = get_stock_gl_code($bom_item["component"]);
@@ -134,26 +134,26 @@ function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced
                        $memo = $date_.": ".$memo; 
                        update_wo_requirement_issued($woid, $bom_item['component'], $bom_item["quantity"] * $units_reqd);                       
                        // insert a -ve stock move for each item
-                       // Chaitanya: Updated to record price and cost as std_cost for work order issued item\r
-                       $UnitCost = get_standard_cost($bom_item["component"]);                  \r
+                       // Chaitanya: Updated to record price and cost as std_cost for work order issued item
+                       $UnitCost = get_standard_cost($bom_item["component"]);                  
                        add_stock_move(ST_MANURECEIVE, $bom_item["component"], $advanced,
-                               $bom_item["loc_code"], $date_, "", -$bom_item["quantity"] * $units_reqd, $UnitCost, 0, 1, $UnitCost);\r
+                               $bom_item["loc_code"], $date_, "", -$bom_item["quantity"] * $units_reqd, $UnitCost, 0, 1, $UnitCost);
                }
-               \r
-               //Chaitanya : Compatibility for Service Items\r
-               if (!is_service($bom_accounts["mb_flag"]))\r
-                       $ivaccount = $bom_accounts["inventory_account"];\r
-               else\r
-                       $ivaccount = $bom_accounts["cogs_account"];\r
-               $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,\r
+               
+               //Chaitanya : Compatibility for Service Items
+               if (!is_service($bom_accounts["mb_flag"]))
+                       $ivaccount = $bom_accounts["inventory_account"];
+               else
+                       $ivaccount = $bom_accounts["cogs_account"];
+               $total_cost += add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $ivaccount, 0, 0,
                        $memo, -$bom_cost);
-               $total_material_cost += $bom_cost;\r
+               $total_material_cost += $bom_cost;
        }
        if ($advanced)
        {
-               //Chaitanya: Material cost added at time of production as per BOM at the time and in adjustment mode.\r
-               add_material_cost($stock_id, $units_reqd, $date_, true);        \r
-       \r
+               //Chaitanya: Material cost added at time of production as per BOM at the time and in adjustment mode.
+               add_material_cost($stock_id, $units_reqd, $date_, true);        
+       
                $wo = get_work_order($woid);
                // also take the additional issues
                // moved to work_order_issues_db.inc
@@ -173,13 +173,13 @@ function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced
                if ($issue_total != 0)
                        add_issue_cost($stock_id, $units_reqd, $date_, $issue_total);
                */      
-               \r
-               // Logic moved to work_order_costs.php\r
-               /*\r
+               
+               // Logic moved to work_order_costs.php
+               /*
                $lcost = get_gl_wo_cost($woid, WO_LABOUR);
                add_labour_cost($stock_id, $units_reqd, $date_, $lcost * $units_reqd / $wo['units_reqd']);
                $ocost = get_gl_wo_cost($woid, WO_OVERHEAD);
-               add_overhead_cost($stock_id, $units_reqd, $date_, $ocost * $units_reqd / $wo['units_reqd']); */\r
+               add_overhead_cost($stock_id, $units_reqd, $date_, $ocost * $units_reqd / $wo['units_reqd']); */
        }
        // credit additional costs
        $item_accounts = get_stock_gl_code($stock_id);
@@ -222,10 +222,10 @@ function work_order_quick_costs($woid, $stock_id, $units_reqd, $date_, $advanced
                $memo = $date_.": ".$memo;
     add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $item_accounts["inventory_account"],
         0, 0, $memo, -$total_cost);    
-               \r
-       //Chaitanya : Update cost of the manufactured item in stock moves table\r
-       $UnitWOCost = ($total_material_cost + $costs + $labour)/$units_reqd;\r
-       update_stock_move(ST_WORKORDER, $woid, $stock_id, $UnitWOCost);         \r
+               
+       //Chaitanya : Update cost of the manufactured item in stock moves table
+       $UnitWOCost = ($total_material_cost + $costs + $labour)/$units_reqd;
+       update_stock_move(ST_WORKORDER, $woid, $stock_id, $UnitWOCost);         
 }
 
 //--------------------------------------------------------------------------------------
index 590b80c3417beef27d0919e6abd4d222168989d5..e7e0fb07700dbe18a9f45fc70448590f7c0a2204 100644 (file)
@@ -76,7 +76,7 @@ function can_process()
                display_error(_("The amount entered is not a valid number or less then zero."));
                set_focus('costs');
                return false;
-       }       \r
+       }       
 
        if (!is_date($_POST['date_']))
        {
@@ -119,14 +119,14 @@ if (isset($_POST['process']) && can_process() == true)
        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']);
-                       \r
-       //Chaitanya : Apply the costs to manfuctured stock item as adjustement\r
-       $wo = get_work_order($_POST['selected_id']);\r
-       if ($_POST['PaymentType'] == 0)\r
-               add_labour_cost($wo['stock_id'], 0, $_POST['date_'], input_num('costs'), true);\r
-       else\r
-               add_overhead_cost($wo['stock_id'], 0, $_POST['date_'], input_num('costs'), true);\r
-                       \r
+                       
+       //Chaitanya : 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'], 0, $_POST['date_'], input_num('costs'), true);
+       else
+               add_overhead_cost($wo['stock_id'], 0, $_POST['date_'], input_num('costs'), true);
+                       
        commit_transaction();   
 
        meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_POST['selected_id']);
index 879e70ea67b122d06f398ec578f72520f080d99c..1471ae66c1e46c59862948bf4f0a755e4b43ab81 100644 (file)
@@ -34,22 +34,22 @@ function getTransactions($from, $to)
        $from = date2sql($from);
        $to = date2sql($to);
        
-       $sql = "SELECT ".TB_PREF."grn_batch.id batch_no,\r
-                       ".TB_PREF."grn_batch.supplier_id, \r
+       $sql = "SELECT ".TB_PREF."grn_batch.id batch_no,
+                       ".TB_PREF."grn_batch.supplier_id, 
             ".TB_PREF."purch_order_details.*,
-            ".TB_PREF."stock_master.description,\r
-                       ".TB_PREF."grn_items.qty_recd,\r
-                       ".TB_PREF."grn_items.quantity_inv,\r
-                       ".TB_PREF."grn_items.id grn_item_id\r
+            ".TB_PREF."stock_master.description,
+                       ".TB_PREF."grn_items.qty_recd,
+                       ".TB_PREF."grn_items.quantity_inv,
+                       ".TB_PREF."grn_items.id grn_item_id
         FROM ".TB_PREF."stock_master,
             ".TB_PREF."purch_order_details,
-            ".TB_PREF."grn_batch,\r
-                       ".TB_PREF."grn_items \r
+            ".TB_PREF."grn_batch,
+                       ".TB_PREF."grn_items 
         WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."purch_order_details.item_code
         AND ".TB_PREF."grn_batch.purch_order_no=".TB_PREF."purch_order_details.order_no
-               AND ".TB_PREF."grn_batch.id = ".TB_PREF."grn_items.grn_batch_id \r
-               AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."purch_order_details.po_detail_item\r
-        AND ".TB_PREF."grn_items.qty_recd>0\r
+               AND ".TB_PREF."grn_batch.id = ".TB_PREF."grn_items.grn_batch_id 
+               AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."purch_order_details.po_detail_item
+        AND ".TB_PREF."grn_items.qty_recd>0
         AND ".TB_PREF."grn_batch.delivery_date>='$from'
         AND ".TB_PREF."grn_batch.delivery_date<='$to'
         ORDER BY ".TB_PREF."stock_master.stock_id, ".TB_PREF."grn_batch.delivery_date";        
@@ -58,22 +58,22 @@ function getTransactions($from, $to)
 
 }
 
-function getSuppInvDetails($grn_item_id)\r
-{\r
-       $sql = "SELECT\r
-                       ".TB_PREF."supp_invoice_items.supp_trans_no inv_no,\r
-                       ".TB_PREF."supp_invoice_items.quantity inv_qty,\r
-                       ".TB_PREF."supp_invoice_items.unit_price inv_price\r
-                       FROM ".TB_PREF."grn_items, ".TB_PREF."supp_invoice_items\r
-                       WHERE ".TB_PREF."grn_items.id = ".TB_PREF."supp_invoice_items.grn_item_id\r
-                       AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."supp_invoice_items.po_detail_item_id\r
-                       AND ".TB_PREF."grn_items.item_code = ".TB_PREF."supp_invoice_items.stock_id\r
-                       AND ".TB_PREF."supp_invoice_items.grn_item_id = ".$grn_item_id."\r
-                       ORDER BY ".TB_PREF."supp_invoice_items.id asc";\r
-\r
-       return db_query($sql,"No transactions were returned");\r
-}\r
-\r
+function getSuppInvDetails($grn_item_id)
+{
+       $sql = "SELECT
+                       ".TB_PREF."supp_invoice_items.supp_trans_no inv_no,
+                       ".TB_PREF."supp_invoice_items.quantity inv_qty,
+                       ".TB_PREF."supp_invoice_items.unit_price inv_price
+                       FROM ".TB_PREF."grn_items, ".TB_PREF."supp_invoice_items
+                       WHERE ".TB_PREF."grn_items.id = ".TB_PREF."supp_invoice_items.grn_item_id
+                       AND ".TB_PREF."grn_items.po_detail_item = ".TB_PREF."supp_invoice_items.po_detail_item_id
+                       AND ".TB_PREF."grn_items.item_code = ".TB_PREF."supp_invoice_items.stock_id
+                       AND ".TB_PREF."supp_invoice_items.grn_item_id = ".$grn_item_id."
+                       ORDER BY ".TB_PREF."supp_invoice_items.id asc";
+
+       return db_query($sql,"No transactions were returned");
+}
+
 //----------------------------------------------------------------------------------------------------
 
 function print_grn_valuation()
@@ -91,10 +91,10 @@ function print_grn_valuation()
 
     $dec = user_price_dec();
 
-       $cols = array(0, 75, 225, 260, 295, 330, 370, 410, 455, 515);\r
-       $headers = array(_('Stock ID'), _('Description'), _('PO No'), _('GRN')."#", _('Inv')."#", _('Qty'), _('Inv Price'), _('PO Price'), _('Total'));\r
+       $cols = array(0, 75, 225, 260, 295, 330, 370, 410, 455, 515);
+       $headers = array(_('Stock ID'), _('Description'), _('PO No'), _('GRN')."#", _('Inv')."#", _('Qty'), _('Inv Price'), _('PO Price'), _('Total'));
 
-       $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');\r
+       $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
 
     $params =   array(         0 => $comments,
                                    1 => array('text' => _('Period'),'from' => $from, 'to' => $to));
@@ -117,8 +117,8 @@ function print_grn_valuation()
                                $rep->Line($rep->row  - 4);
                                $rep->NewLine(2);
                                $rep->TextCol(0, 3, _('Total'));
-                               $rep->AmountCol(5, 6, $qtotal, $qdec);\r
-                               $rep->AmountCol(8, 9, $total, $dec);\r
+                               $rep->AmountCol(5, 6, $qtotal, $qdec);
+                               $rep->AmountCol(8, 9, $total, $dec);
                                $rep->NewLine();
                                $total = $qtotal = 0;
                        }
@@ -131,55 +131,55 @@ function print_grn_valuation()
 
                $rep->NewLine();
                $rep->TextCol(0, 1, $trans['item_code']);
-               $rep->TextCol(1, 2, $trans['description']);\r
+               $rep->TextCol(1, 2, $trans['description']);
                $rep->TextCol(2, 3, $trans['order_no']);
                $qdec = get_qty_dec($trans['item_code']);
-               $rep->TextCol(3, 4, $trans['batch_no']);\r
-               \r
-               if ($trans['quantity_inv'])\r
-               {\r
-                       $suppinv = getSuppInvDetails($trans['grn_item_id']);\r
-                       while ($inv=db_fetch($suppinv))\r
-                       {       \r
-                               $inv['inv_price'] *= $rate;\r
-                               $rep->TextCol(4, 5, $inv['inv_no']);\r
-                               $rep->AmountCol(5, 6, $inv['inv_qty'], $qdec);\r
-                               $rep->AmountCol(6, 7, $inv['inv_price'], $dec);\r
-                               $rep->AmountCol(7, 8, $trans['unit_price'], $dec);\r
-                               $amt = round2($inv['inv_qty'] * $inv['inv_price'], $dec);\r
-                               $rep->AmountCol(8, 9, $amt, $dec);\r
-                               $rep->NewLine();\r
-                               $total += $amt;\r
-                               $qtotal += $inv['inv_qty'];\r
-                               $grandtotal += $amt;\r
-                       }\r
-               }\r
-       \r
-               if ($trans['qty_recd'] - $trans['quantity_inv'] !=0 )\r
-               {\r
-                       $rep->TextCol(4, 5, "--");\r
-                       $rep->AmountCol(5, 6, $trans['qty_recd'] - $trans['quantity_inv'], $qdec);\r
-                       $rep->AmountCol(7, 8, $trans['unit_price'], $dec);\r
-                       $amt = round2(($trans['qty_recd'] - $trans['quantity_inv']) * $trans['unit_price'], $dec);\r
-                       $rep->AmountCol(8, 9, $amt, $dec);\r
-                       $total += $amt;\r
-                       $qtotal += $trans['qty_recd'] - $trans['quantity_inv'];\r
-                       $grandtotal += $amt;\r
-               }\r
-               else\r
-                       $rep->NewLine(-1);\r
+               $rep->TextCol(3, 4, $trans['batch_no']);
+               
+               if ($trans['quantity_inv'])
+               {
+                       $suppinv = getSuppInvDetails($trans['grn_item_id']);
+                       while ($inv=db_fetch($suppinv))
+                       {       
+                               $inv['inv_price'] *= $rate;
+                               $rep->TextCol(4, 5, $inv['inv_no']);
+                               $rep->AmountCol(5, 6, $inv['inv_qty'], $qdec);
+                               $rep->AmountCol(6, 7, $inv['inv_price'], $dec);
+                               $rep->AmountCol(7, 8, $trans['unit_price'], $dec);
+                               $amt = round2($inv['inv_qty'] * $inv['inv_price'], $dec);
+                               $rep->AmountCol(8, 9, $amt, $dec);
+                               $rep->NewLine();
+                               $total += $amt;
+                               $qtotal += $inv['inv_qty'];
+                               $grandtotal += $amt;
+                       }
+               }
+       
+               if ($trans['qty_recd'] - $trans['quantity_inv'] !=0 )
+               {
+                       $rep->TextCol(4, 5, "--");
+                       $rep->AmountCol(5, 6, $trans['qty_recd'] - $trans['quantity_inv'], $qdec);
+                       $rep->AmountCol(7, 8, $trans['unit_price'], $dec);
+                       $amt = round2(($trans['qty_recd'] - $trans['quantity_inv']) * $trans['unit_price'], $dec);
+                       $rep->AmountCol(8, 9, $amt, $dec);
+                       $total += $amt;
+                       $qtotal += $trans['qty_recd'] - $trans['quantity_inv'];
+                       $grandtotal += $amt;
+               }
+               else
+                       $rep->NewLine(-1);
        }
        if ($stock_id != '')
        {
                $rep->Line($rep->row  - 4);
                $rep->NewLine(2);
                $rep->TextCol(0, 3, _('Total'));
-               $rep->AmountCol(5, 6, $qtotal, $qdec);\r
-               $rep->AmountCol(8, 9, $total, $dec);\r
+               $rep->AmountCol(5, 6, $qtotal, $qdec);
+               $rep->AmountCol(8, 9, $total, $dec);
                $rep->Line($rep->row  - 4);
                $rep->NewLine(2);
-               $rep->TextCol(0, 7, _('Grand Total'));\r
-               $rep->AmountCol(8, 9, $grandtotal, $dec);\r
+               $rep->TextCol(0, 7, _('Grand Total'));
+               $rep->AmountCol(8, 9, $grandtotal, $dec);
        }
 
        $rep->Line($rep->row  - 4);