Added GL trans on Removal GRN items (Supp Invoice) if GRN Clearing
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 31 Dec 2010 16:22:31 +0000 (16:22 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 31 Dec 2010 16:22:31 +0000 (16:22 +0000)
CHANGELOG.txt
purchasing/includes/db/invoice_db.inc

index 5d62fa2838e9ed3facda3740e94c0e2189891afb..f755e30c453ab17e8d4b513987e49a7210768d30 100644 (file)
@@ -32,6 +32,8 @@ $ /purchasing/po_receive_items.php
   /purchasing/po_entry_items.php
 # Bug. $n undefined in /admin/gl_setup.php
 $ /admin/gl_setup.php
+! Added GL trans on Removal GRN items (Supp Invoice) if GRN Clearing
+$ /purchasing/includes/db/invoice_db.inc
   
 30-Dec-2010 Janusz Dobrowolski
 + Added option for using GRN Clearing Account for yet non invoiced GRNs.
index a8b6e0dc48631201d458bfb2f5d7497b69ff9ff7..06d27cde04265d5093cd79c1647c729b1a85678e 100644 (file)
@@ -580,6 +580,21 @@ function remove_not_invoice_item($id)
 
        add_stock_move(ST_SUPPRECEIVE, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
                -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
+               
+    $clearing_act = get_company_pref('grn_clearing_act');
+       if ($clearing_act) {    // otherwise GRN clearing account is not used
+               if (is_inventory_item($myrow['item_code']))
+               {
+               $total = 0;
+                       $stock_gl_code = get_stock_gl_code($myrow['item_code']);
+                       $date = sql2date($grn["delivery_date"]);
+                       $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $stock_gl_code["inventory_account"],
+                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
+                               -$myrow['QtyOstdg'] * $myrow['unit_price'], $grn["supplier_id"], "", 0, _("GRN Removal"));
+                       $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $myrow['grn_batch_id'], $date, $clearing_act,
+                               0, 0, -$total, null, "", 0, _("GRN Removal"));
+               }       
+       }
 
        commit_transaction();
 }