Fixed bug in earlier invoice_db (GRN Provision should have only one row)
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 31 Dec 2010 11:43:21 +0000 (11:43 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 31 Dec 2010 11:43:21 +0000 (11:43 +0000)
Only GRN Clearring on stock items.

CHANGELOG.txt
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc

index 6b8e1ca578f6e7b122afaaee4f294564b27275e4..a691fa507219578ee8ac9954dc70c54ac4a1c77d 100644 (file)
@@ -19,6 +19,19 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+31-Dec-2010 Joe Hunt
+# Fixed bug in earlier invoice_db (GRN Provision should have only one row)
+  Only GRN Clearring on stock items.
+$ /purchasing/includes/db/grn_db.inc
+  /purchasing/includes/db/invoice_db.inc
+! Changed so supplier credit note items shows the invoice price/not grn price
+$ /purchasing/includes/db/grn_db.inc
+  /invoice_ui.inc
++ Added link for viewing GL Delivery if clearing account
+$ /purchasing/po_receive_items.php
+# Bug. $n undefined in /admin/gl_setup.php
+$ /admin/gl_setup.php
+  
 30-Dec-2010 Janusz Dobrowolski
 + Added option for using GRN Clearing Account for yet non invoiced GRNs.
 $ /purchasing/includes/po_class.inc
index 7b66d030470df274f0528f669810cbe61e2941ba..691ae73f8f71f92bb63bd316859e332a37c08245 100644 (file)
@@ -92,7 +92,6 @@ function add_grn(&$po)
     $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)
        {
@@ -100,19 +99,17 @@ function add_grn(&$po)
                {
                        $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
+                       //------------------- update average material cost and clearing account ----- Joe Hunt Mar-03-2008
                        if (is_inventory_item($order_line->stock_id))
+                       {
+                               if ($clearing_act)
+                                       $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $stock_gl_code["inventory_account"],
+                                               $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'],
+                                               $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id);
                                update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price,
                                        $order_line->receive_qty, $date_);
+                       }               
                        //----------------------------------------------------------------------------------------------------------------
                        if ($order_line->qty_received == 0)
                        {
@@ -139,9 +136,9 @@ function add_grn(&$po)
                } /*quantity received is != 0 */
        } /*end of order_line loop */
 
-       if ($clearing_act) {
+       if ($clearing_act && $total != 0.0) {
                $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $clearing_act,
-                       0, 0, -$total, $po->supplier_id);
+                       0, 0, -$total, null);
        }
        $Refs->save(ST_SUPPRECEIVE, $grn, $po->reference);
 
@@ -247,6 +244,7 @@ function get_grn_items($grn_batch_id=0, $supplier_id="", $outstanding_only=false
 {
     $sql = "SELECT ".TB_PREF."grn_batch.*, ".TB_PREF."grn_items.*, "
        .TB_PREF."purch_order_details.unit_price,"
+       .TB_PREF."purch_order_details.act_price,"
        .TB_PREF."purch_order_details.quantity_ordered,"
                .TB_PREF."purch_order_details.std_cost_unit, units
        FROM ".TB_PREF."grn_batch, ".TB_PREF."grn_items, "
index 8b7afeea3d2d6632e114d66eb9ba943aaa7e74bb..a8b6e0dc48631201d458bfb2f5d7497b69ff9ff7 100644 (file)
@@ -203,16 +203,19 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                $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 = $clearing_act ? $clearing_act : (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : 
+       if ($trans_type == ST_SUPPCREDIT)
+               {
+                       $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"]));
-
-               $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)
+                       $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);
+               }
+       else
        {
+               // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt
+                       $iv_act = is_inventory_item($entered_grn->item_code) ? ($clearing_act ? $clearing_act : $stock_gl_code["inventory_account"]) : 
+                               ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"]);
                $old = update_supp_received_items_for_invoice($entered_grn->id, $entered_grn->po_detail_item,
                        $entered_grn->this_quantity_inv, $entered_grn->chg_price);
                        // Since the standard cost is always calculated on basis of the po unit_price,
@@ -230,8 +233,17 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                        //{
                        //$diff = $entered_grn->chg_price - $old_price;
                        $old_date = sql2date($old[1]);
-                       if (is_inventory_item($entered_grn->item_code))
+                       if (!is_inventory_item($entered_grn->item_code))
+                               $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);
+                       else
                        {
+                               $currency = get_supplier_currency($supp_trans->supplier_id);
+                               $ex_rate = get_exchange_rate_from_home_currency($currency, $old_date);
+                               $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 * $old_price, $supp_trans->supplier_id, "", $ex_rate);
                                $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price, 
                                        $entered_grn->chg_price);       
                        
@@ -245,14 +257,14 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                                if (($diff * $entered_grn->this_quantity_inv) != 0 )
                                {
                                        $diff_amt = $diff * $entered_grn->this_quantity_inv;
-                                       add_gl_trans($trans_type, $invoice_id, $date_,  $iv_act,
+                                       $total += add_gl_trans($trans_type, $invoice_id, $date_,        $stock_gl_code["inventory_account"],
                                                $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], 'GRN Provision',
                                                $diff_amt, null, null, null,
                                                "The general ledger transaction could not be added for the GRN of the inventory item"); 
                                        
-                                       add_gl_trans($trans_type, $invoice_id, $date_,  $stock_gl_code["cogs_account"],
-                                               0, 0, 'GRN Provision', -$diff_amt, null, null, null,
-                                               "The general ledger transaction could not be added for the GRN of the inventory item");                         
+                                       //add_gl_trans($trans_type, $invoice_id, $date_,        $stock_gl_code["cogs_account"],
+                                       //      0, 0, 'GRN Provision', -$diff_amt, null, null, null,
+                                       //      "The general ledger transaction could not be added for the GRN of the inventory item");                         
                                }
                        }       
                        // added 2008-12-08 Joe Hunt. Update the purchase data table