Added option for using GRN Clearing Account for non invoiced GRNs
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 30 Dec 2010 11:41:49 +0000 (11:41 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 30 Dec 2010 11:41:49 +0000 (11:41 +0000)
CHANGELOG.txt
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/po_class.inc
sql/en_US-demo.sql
sql/en_US-new.sql

index 326d4f7a40c7d0dbbc6d7e5457499d48e13267de..5e518213edef36788c3f4383724514295783d7df 100644 (file)
@@ -19,6 +19,18 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+30-Dec-2010 Janusz Dobrowolski
++ Added option for using GRN Clearing Account for yet non invoiced GRNs.
+$ /purchasing/includes/po_class.inc
+  /purchasing/includes/db/grn_db.inc
+  /purchasing/includes/db/invoice_db.inc
+  /sql/en_US-demo.sql
+  /sql/en_US-new.sql
+! Added GRN clearing account setting
+$ /admin/gl_setup.php
+! Added set_company_pref() function
+$ /admin/db/company_db.inc
+
 29-Dec-2010 Janusz Dobrowolski
 ! Hook files inclusion moved to session.inc
 $ /includes/hooks.inc
index 2b979f1a3b91359d3ed522365ecda8b527bcb37f..7b66d030470df274f0528f669810cbe61e2941ba 100644 (file)
@@ -89,12 +89,25 @@ function add_grn(&$po)
 
        $grn = add_grn_batch($po->order_no, $po->supplier_id, $po->reference, $po->Location, $date_);
 
+    $clearing_act = get_company_pref('grn_clearing_act');
+       if ($clearing_act) {    // otherwise GRN clearing account is not used
+           $total = 0;
+       $supplier_accounts = get_supplier_accounts($po->supplier_id);
+       }
        foreach ($po->line_items as $line_no => $order_line)
        {
-
                if ($order_line->receive_qty != 0 && $order_line->receive_qty != "" && isset($order_line->receive_qty))
                {
+                       $stock_gl_code = get_stock_gl_code($order_line->stock_id);
+
+                       if($clearing_act) {
+                               $inv_act = (is_inventory_item($order_line->stock_id) ? $stock_gl_code["inventory_account"] : 
+                                       ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"]));
 
+                               $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $inv_act,
+                                       $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
+                                       $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id);
+                       }
                        /*Update sales_order_details for the new quantity received and the standard cost used for postings to GL and recorded in the stock movements for FIFO/LIFO stocks valuations*/
                        //------------------- update average material cost ------------------------------------------ Joe Hunt Mar-03-2008
                        if (is_inventory_item($order_line->stock_id))
@@ -126,6 +139,10 @@ function add_grn(&$po)
                } /*quantity received is != 0 */
        } /*end of order_line loop */
 
+       if ($clearing_act) {
+               $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $clearing_act,
+                       0, 0, -$total, $po->supplier_id);
+       }
        $Refs->save(ST_SUPPRECEIVE, $grn, $po->reference);
 
        add_audit_trail(ST_SUPPRECEIVE, $grn, $date_);
index 58e3aeb7bf6c7ab2c126bbc78abfb8adcb51df37..8b7afeea3d2d6632e114d66eb9ba943aaa7e74bb 100644 (file)
@@ -189,6 +189,8 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                        $trans_type, $invoice_id, $entered_gl_code->amount,
                        $ex_rate, $date_, $supp_trans->supp_reference, $supp_trans->tax_included);
     }
+    
+    $clearing_act = get_company_pref('grn_clearing_act');
     foreach ($supp_trans->grn_items as $line_no => $entered_grn)
     {
 
@@ -200,14 +202,14 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                $line_taxfree = $entered_grn->taxfree_charge_price($supp_trans->tax_group_id);
                $line_tax = $entered_grn->full_charge_price($supp_trans->tax_group_id) - $line_taxfree;
                $stock_gl_code = get_stock_gl_code($entered_grn->item_code);
-               $iv_act = (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : 
-                       ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"]));
+               
+               $iv_act = $clearing_act ? $clearing_act : (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : 
+                               ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"]));
+
                $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act,
                        $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
                        $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);
-               /*$total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act,
-                       $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
-                       $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id);*/
+
        // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
        if ($trans_type == ST_SUPPINVOICE)
        {
index 2324d25dbd6c70c2d73a0249b7244b0c738d868b..b767e9ea9261f66e9ee64245c4f9067bae4bd475 100644 (file)
@@ -230,6 +230,12 @@ class po_line_details
                $this->standard_cost =0;
                $this->grn_item_id = $grn_item_id;
        }
+       
+       function taxfree_charge_price($po)
+       {
+               return get_tax_free_price_for_item($this->stock_id, $this->price, 
+                 $po->tax_group_id, $po->tax_included, $po->tax_group_array);
+       }
 }
 
 ?>
index 4905730154bd8221cbb5a44072a7b507ca38bc15..c822b4b128f00f571a1d83e016244993fc19d405 100644 (file)
@@ -2065,6 +2065,7 @@ INSERT INTO `0_sys_prefs` VALUES('default_assembly_act', 'glsetup.items', 'varch
 INSERT INTO `0_sys_prefs` VALUES('default_workorder_required', 'glsetup.manuf', 'int', 11, '20');
 INSERT INTO `0_sys_prefs` VALUES('version_id', 'system', 'varchar', 11, '2.3rc');
 INSERT INTO `0_sys_prefs` VALUES('auto_curr_reval', 'setup.company', 'smallint', 6, '1');
+INSERT INTO `0_sys_prefs` VALUES('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, '1550');
 
 -- --------------------------------------------------------
 
index 041bced2cd601abdc0ff1dd95cca7cad6122d65b..e904c2bae20b06e6683e4283ea1cac4ab2758e98 100644 (file)
@@ -1824,6 +1824,7 @@ INSERT INTO `0_sys_prefs` VALUES('default_assembly_act', 'glsetup.items', 'varch
 INSERT INTO `0_sys_prefs` VALUES('default_workorder_required', 'glsetup.manuf', 'int', 11, '20');
 INSERT INTO `0_sys_prefs` VALUES('version_id', 'system', 'varchar', 11, '2.3rc');
 INSERT INTO `0_sys_prefs` VALUES('auto_curr_reval', 'setup.company', 'smallint', 6, '1');
+INSERT INTO `0_sys_prefs` VALUES('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, '1550');
 
 -- --------------------------------------------------------