Fixing tax_included in gl_items.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 10 Oct 2010 13:29:52 +0000 (13:29 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sun, 10 Oct 2010 13:29:52 +0000 (13:29 +0000)
CHANGELOG.txt
gl/includes/db/gl_db_trans.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/supp_trans_db.inc
purchasing/includes/supp_trans_class.inc
purchasing/includes/ui/invoice_ui.inc

index 052dc5992894dd19b867bd853ac838e2594dadfe..d7a13dcabdf08e161f372430c18a4a72c8f8d24c 100644 (file)
@@ -26,7 +26,10 @@ $ /includes/ui/allocation_cart.inc
 10-Oct-2010 Joe Hunt
 # Master bug in class supp_trans get_items_total. Minor bug in gl_db_trans.inc
   Wrong tax report and wrong supp trans/gl records with gl item lines.
+  Fixing tax_included in gl_items.
 $ /purchasing/includes/supp_trans_class.inc
+  /purchasing/includes/db/invoice_db.inc
+  /purchasing/includes/ui/invoice_ui.inc
   /gl/includes/db/gl_db_trans.inc
 
 06-Oct-2010 Jusz Dobrowolski
index 96963d4307c8843f20de81eecb3ebb5a4bc6c458..d2657c65edf328d628d8e2e41f942a04ac8d125b 100644 (file)
@@ -331,7 +331,7 @@ function get_only_budget_trans_from_to($from_date, $to_date, $account, $dimensio
 //--------------------------------------------------------------------------------
 //     Stores journal/bank transaction tax details if applicable
 //
-function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate, $date, $memo)
+function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate, $date, $memo, $included=0)
 {
        $tax_type = is_tax_account($gl_code);
        if(!$tax_type) return;  // $gl_code is not tax account
@@ -350,7 +350,7 @@ function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate,
                $net_amount = $amount/$tax['rate']*100; 
        }
                
-       add_trans_tax_details($trans_type, $trans_no, $tax['id'], $tax['rate'], 0
+       add_trans_tax_details($trans_type, $trans_no, $tax['id'], $tax['rate'], $included
                $amount, $net_amount, $ex_rate, $date, $memo);
                        
 }
index 308c2c25440ef5129b88262448d32ac910d024bd..48e33987503ab0704e3058224cb8516a0cdd0ec3 100644 (file)
@@ -157,7 +157,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
     /*First insert the invoice into the supp_trans table*/
        $invoice_id = add_supp_trans($trans_type, $supp_trans->supplier_id, $date_, $supp_trans->due_date,
                $supp_trans->reference, $supp_trans->supp_reference,
-               $invoice_items_total, $item_added_tax, $supp_trans->ov_discount);
+               $invoice_items_total, $item_added_tax, $supp_trans->ov_discount, "", 0, $supp_trans->tax_included);
 
        $total = 0;
     /* Now the control account */
@@ -188,7 +188,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b
                        $entered_gl_code->amount = -$entered_gl_code->amount;
                add_gl_tax_details($entered_gl_code->gl_code, 
                        $trans_type, $invoice_id, $entered_gl_code->amount,
-                       $ex_rate, $date_, $supp_trans->supp_reference);
+                       $ex_rate, $date_, $supp_trans->supp_reference, $supp_trans->tax_included);
     }
     foreach ($supp_trans->grn_items as $line_no => $entered_grn)
     {
index d5112d5322debbd2b598ad295cd71b88cdaf02b5..50ad5803c9e7a797718bf099f1a02728ecb1862e 100644 (file)
@@ -12,7 +12,7 @@
 //-------------------------------------------------------------------------------------------------------------
 
 function add_supp_trans($type, $supplier_id, $date_, $due_date, $reference, $supp_reference,
-       $amount, $amount_tax, $discount, $err_msg="", $rate=0)
+       $amount, $amount_tax, $discount, $err_msg="", $rate=0, $included=0)
 {
        $date = date2sql($date_);
        if ($due_date == "")
@@ -29,11 +29,11 @@ function add_supp_trans($type, $supplier_id, $date_, $due_date, $reference, $sup
 
 
        $sql = "INSERT INTO ".TB_PREF."supp_trans (trans_no, type, supplier_id, tran_date, due_date,
-               reference, supp_reference, ov_amount, ov_gst, rate, ov_discount) ";
+               reference, supp_reference, ov_amount, ov_gst, rate, ov_discount, tax_included) ";
        $sql .= "VALUES (".db_escape($trans_no).", ".db_escape($type)
        .", ".db_escape($supplier_id).", '$date', '$due_date',
                ".db_escape($reference).", ".db_escape($supp_reference).", ".db_escape($amount)
-               .", ".db_escape($amount_tax).", ".db_escape($rate).", ".db_escape($discount).")";
+               .", ".db_escape($amount_tax).", ".db_escape($rate).", ".db_escape($discount).", ".db_escape($included).")";
 
        if ($err_msg == "")
                $err_msg = "Cannot insert a supplier transaction record";
index 0647b96fd4e6eeec682da5f3791f9719845efe38..db940d62feb8300e815af650128ac38e5c36325a 100644 (file)
@@ -166,7 +166,7 @@ class supp_trans
 
                foreach ($this->gl_codes as $gl_line)
                {   //////// 2010-10-10 Joe Hunt
-                       if (!is_tax_account($gl_line->gl_code))
+                       if (!is_tax_account($gl_line->gl_code) || $this->tax_included)
                                $total += $gl_line->amount;
                }
                return $total;
index c551697fe1c1a7ea0115cb1d2704f4a1f1409029..ae71ad8a649aa89789c3c65cebd5340e6ab72da3 100644 (file)
@@ -45,7 +45,7 @@ function copy_to_trans(&$supp_trans)
                foreach ( $supp_trans->gl_codes as $gl_line)
                {
                        ////////// 2009-08-18 Joe Hunt
-                       if (!is_tax_account($gl_line->gl_code))
+                       if (!is_tax_account($gl_line->gl_code) || $supp_trans->tax_included)
                                $supp_trans->ov_amount += $gl_line->amount;
                }
        }
@@ -253,7 +253,7 @@ function display_gl_items(&$supp_trans, $mode=0)
                $th[] = "";
        }       
        table_header($th);
-       $total_gl_value=0;
+       $total_gl_value=$total = 0;
        $i = $k = 0;
 
        if (count($supp_trans->gl_codes) > 0)
@@ -286,10 +286,13 @@ function display_gl_items(&$supp_trans, $mode=0)
                        }       
                        end_row();
                        /////////// 2009-08-18 Joe Hunt
-                       if ($mode > 1 && !is_tax_account($entered_gl_code->gl_code))
-                               $total_gl_value += $entered_gl_code->amount;
+                       if ($mode > 1) {
+                               if ($supp_trans->tax_included || !is_tax_account($entered_gl_code->gl_code))
+                                       $total_gl_value += $entered_gl_code->amount;
+                       }               
                        else    
                                $total_gl_value += $entered_gl_code->amount;
+                       $total += $entered_gl_code->amount;     
                        $i++;
                        if ($i > 15)
                        {
@@ -302,7 +305,7 @@ function display_gl_items(&$supp_trans, $mode=0)
        if ($mode == 1)
                display_gl_controls($supp_trans, $k);
        $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
-       label_row(_("Total"), price_format($total_gl_value),
+       label_row(_("Total"), price_format($total),
                "colspan=".$colspan." align=right", "nowrap align=right", ($mode==1?3:1));
 
        end_table(1);