A couple of small bugs in customer and supplier balances report fixed.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 18 Apr 2013 08:10:36 +0000 (10:10 +0200)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 18 Apr 2013 08:10:36 +0000 (10:10 +0200)
reporting/rep101.php
reporting/rep201.php

index 2826c94be51ab415f49197166e7945e7eabd3daf..b098dad56f5c9740f1c6e32c54e8199da074cd4e 100644 (file)
@@ -35,12 +35,12 @@ function get_open_balance($debtorno, $to, $convert)
        if($to)
                $to = date2sql($to);
 
-    $sql = "SELECT SUM(IF(t.type = ".ST_SALESINVOICE.",
+    $sql = "SELECT SUM(IF(t.type = ".ST_SALESINVOICE." OR t.type = ".ST_BANKPAYMENT.",
        (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount)";
     if ($convert)
        $sql .= " * rate";
     $sql .= ", 0)) AS charges,
-       SUM(IF(t.type <> ".ST_SALESINVOICE.",
+       SUM(IF(t.type <> ".ST_SALESINVOICE." AND t.type <> ".ST_BANKPAYMENT.",
        (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount)";
     if ($convert)
        $sql .= " * rate";
@@ -49,7 +49,7 @@ function get_open_balance($debtorno, $to, $convert)
        if ($convert)
                $sql .= " * rate";
        $sql .= ") AS Allocated,
-               SUM(IF(t.type = ".ST_SALESINVOICE.",
+               SUM(IF(t.type = ".ST_SALESINVOICE." OR t.type = ".ST_BANKPAYMENT.",
                        (t.ov_amount + t.ov_gst + t.ov_freight + t.ov_freight_tax + t.ov_discount - t.alloc)";
     if ($convert)
        $sql .= " * rate";
@@ -219,12 +219,6 @@ function print_customer_balances()
                        }
                        $item[2] = round2($trans['Allocated'] * $rate, $dec);
                        $rep->AmountCol(6, 7, $item[2], $dec);
-                       /*
-                       if ($trans['type'] == 10)
-                               $item[3] = ($trans['TotalAmount'] - $trans['Allocated']) * $rate;
-                       else
-                               $item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate;
-                       */
                        if ($trans['type'] == ST_SALESINVOICE || $trans['type'] == ST_BANKPAYMENT)
                                $item[3] = $item[0] + $item[1] - $item[2];
                        else    
index 895c3a5c5ea4361256d5f997165a6eebccc3de09..6e2af1c02cc15bfc1e580ff9825d5fec655cef67 100644 (file)
@@ -31,13 +31,13 @@ function get_open_balance($supplier_id, $to, $convert)
 {
        $to = date2sql($to);
 
-    $sql = "SELECT SUM(IF(".TB_PREF."supp_trans.type = ".ST_SUPPINVOICE.", (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + 
-       ".TB_PREF."supp_trans.ov_discount)";
+    $sql = "SELECT SUM(IF(".TB_PREF."supp_trans.type = ".ST_SUPPINVOICE." OR ".TB_PREF."supp_trans.type = ".ST_BANKDEPOSIT.", 
+       (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount)";
     if ($convert)
        $sql .= " * rate";
     $sql .= ", 0)) AS charges,
-       SUM(IF(".TB_PREF."supp_trans.type <> ".ST_SUPPINVOICE.", (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + 
-       ".TB_PREF."supp_trans.ov_discount)";
+       SUM(IF(".TB_PREF."supp_trans.type <> ".ST_SUPPINVOICE." AND ".TB_PREF."supp_trans.type <> ".ST_BANKDEPOSIT.", 
+       (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount)";
     if ($convert)
        $sql .= "* rate";
     $sql .= ", 0)) AS credits,
@@ -45,8 +45,9 @@ function get_open_balance($supplier_id, $to, $convert)
        if ($convert)
                $sql .= " * rate";
        $sql .= ") AS Allocated,
-               SUM((".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + 
-       ".TB_PREF."supp_trans.ov_discount - ".TB_PREF."supp_trans.alloc)";
+               SUM(IF(".TB_PREF."supp_trans.type = ".ST_SUPPINVOICE." OR ".TB_PREF."supp_trans.type = ".ST_BANKDEPOSIT.",
+               (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount - ".TB_PREF."supp_trans.alloc),
+               (".TB_PREF."supp_trans.ov_amount + ".TB_PREF."supp_trans.ov_gst + ".TB_PREF."supp_trans.ov_discount + ".TB_PREF."supp_trans.alloc))";
     if ($convert)
        $sql .= " * rate";
     $sql .= ") AS OutStanding
@@ -203,16 +204,10 @@ function print_supplier_balances()
                        }
                        $item[2] = round2($trans['Allocated'] * $rate, $dec);
                        $rep->AmountCol(6, 7, $item[2], $dec);
-                       /*
-                       if ($trans['type'] == 20)
-                               $item[3] = ($trans['TotalAmount'] - $trans['Allocated']) * $rate;
-                       else
-                               $item[3] = ($trans['TotalAmount'] + $trans['Allocated']) * $rate;
-                       */      
-                       if ($trans['type'] == ST_SUPPINVOICE || $trans['type'] == ST_BANKDEPOSIT)
-                               $item[3] = $item[0] + $item[1] - $item[2];
+                       if ($trans['TotalAmount'] > 0.0)
+                               $item[3] = $item[0] - $item[2];
                        else    
-                               $item[3] = $item[0] - $item[1] + $item[2];
+                               $item[3] = ($item[1] - $item[2]) * -1;
                        $rep->AmountCol(7, 8, $item[3], $dec);
                        for ($i = 0; $i < 4; $i++)
                        {