Minor bugfixes.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 28 Mar 2008 11:00:31 +0000 (11:00 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Fri, 28 Mar 2008 11:00:31 +0000 (11:00 +0000)
CHANGELOG.txt
config.php
reporting/includes/doctext.inc
reporting/includes/doctext2.inc
reporting/rep101.php
reporting/rep102.php
sales/includes/db/customers_db.inc
sales/includes/db/sales_credit_db.inc

index 032b80f0af56e9111e2a05997fec1b82bddb853f..ca67337f6a2a0968035b54e0da56aef2e46e3880 100644 (file)
@@ -19,6 +19,18 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+28-Mar-2008 Joe Hunt
+# Fixed a minor bug in customers_db.inc (should include type == 2 - Bank Deposits)
+$ /sales/includes/db/customers_db.inc
+# Fixed a PHP vers. 5.xx bug. No need for & operator in function calls, only in declaration. Gives a warning.
+$ /sales/includes/db/sales_credit_db.inc
+# Fixed a wrong variabel declaration doc_Document_no to doc_Invoice_no
+$ /reporting/includes/doctext.inc
+  /reporting/includes/doctext2.inc
+# Fixed so Customer Balances and Aged Customer Analysis reports presents correct sign.  
+$ /reporting/rep101.php
+  /reporting/rep102.php
+
 28-Mar-2008 Janusz Dobrowolski
 # Layout/focus fixes for no_[customer/supplier/item]_list option on
    /includes/ui/ui_lists.inc
index 9132cbb754512974cec4f88f91169c736e2b0021..5cdc2b4d258f80bc1a93dd1ee538adab5073efe6 100644 (file)
@@ -23,7 +23,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_
 
        $debug                  = 1;
        $show_sql               = 0;
-       $go_debug               = 1;
+       $go_debug               = 0;
        if ($go_debug == 1)
        {
                error_reporting(E_ALL);
@@ -60,7 +60,7 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_
 
        /* per user data/cache directory */
        $comp_path = $path_to_root.'/company';
-       
+
        /* allow alpha characters in accounts. 0 = numeric, 1 = alpha numeric, 2 = uppercase alpha numeric */
        $accounts_alpha = 0;
 
@@ -172,5 +172,5 @@ if(isset($_SESSION["wa_current_user"])) {
        $js_static = array('behaviour.js');
        // additional js source included in header
        $js_lib = $js_userlib = array();
-       
+
 ?>
\ No newline at end of file
index 46e225e3340b6939fbb97fd2461103977fdb9387..d2366c20d6c6192e6216a94bf3e2d9e454a72f44 100644 (file)
@@ -29,7 +29,7 @@ if (isset($header2type))
        $doc_Bank = _("Bank");
        $doc_Bank_Account = _("Bank Account");
        $doc_Payment_Link = _("You can pay through");
-       if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11 || $doctype == 11)
+       if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11 || $doctype == 13)
        {
                if ($doctype == 8)
                        $this->title = _("PURCHASE ORDER");
@@ -41,19 +41,19 @@ if (isset($header2type))
                        $this->title = _("INVOICE");
                else
                        $this->title = _("CREDIT NOTE");
-               if ($doctype == 8)      
-                       $this->headers = array(_("Item Code"), _("Item Description"),   
-                               _("Delivery Date"), _("Quantity"),      _("Unit"), _("Price"), _("Total"));     
-               else            
-                       $this->headers = array(_("Item Code"), _("Item Description"),   _("Quantity"), 
-                               _("Unit"), _("Price"), _("Discount %"), _("Total"));    
-       }               
+               if ($doctype == 8)
+                       $this->headers = array(_("Item Code"), _("Item Description"),
+                               _("Delivery Date"), _("Quantity"),      _("Unit"), _("Price"), _("Total"));
+               else
+                       $this->headers = array(_("Item Code"), _("Item Description"),   _("Quantity"),
+                               _("Unit"), _("Price"), _("Discount %"), _("Total"));
+       }
        else if ($doctype == 12)
        {
                $this->title = _("STATEMENT");
                $this->headers = array(_("Trans Type"), _("#"), _("Date"), _("DueDate"), _("Charges"),
                        _("Credits"), _("Allocated"), _("Outstanding"));
-       }               
+       }
 }
 if (isset($emailtype))
 {
@@ -64,10 +64,10 @@ if (isset($emailtype))
 }
 if (isset($header2type) || isset($linetype))
 {
-       $doc_Document_no = $doctype==13 ? _("Delivery Note No.") : _("Invoice No.");
+       $doc_Invoice_no = $doctype==13 ? _("Delivery Note No.") : _("Invoice No.");
        $doc_Delivery_no = "Delivery Note No.";
        $doc_Order_no = _("Order no.");
-}      
+}
 if (isset($linetype))
 {
        if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11 || $doctype == 13)
@@ -90,6 +90,6 @@ if (isset($linetype))
                $doc_as_of = _("as of");
                $doc_Days = _("Days");
                $doc_Over = _("Over");
-       }       
+       }
 }
 ?>
\ No newline at end of file
index 461877a8eeb717bb6d2d96c028aae71bc0629ddd..6a7078f100fb420b0b6f4ef29a3afb05296dcfb8 100644 (file)
@@ -8,7 +8,7 @@ if (isset($header2type))
        $doc_Shipping_Company = "Shipping Company";
        if ($doctype == 9)
                $doc_Due_Date = "Delivery Date";
-       else    
+       else
                $doc_Due_Date = "Due Date";
        $doc_Your_Ref = "Your Ref";
        $doc_Our_Ref = "Our Ref.";
@@ -41,19 +41,19 @@ if (isset($header2type))
                        $this->title = _("DELIVERY NOTE");
                else
                        $this->title = "CREDIT NOTE";
-               if ($doctype == 8)      
-                       $this->headers = array('Item Code', 'Item Description', 'Delivery Date', 
-                               'Quantity', 'Unit',     'Price', 'Total');      
-               else            
+               if ($doctype == 8)
+                       $this->headers = array('Item Code', 'Item Description', 'Delivery Date',
+                               'Quantity', 'Unit',     'Price', 'Total');
+               else
                        $this->headers = array('Item Code', 'Item Description', 'Quantity', 'Unit',
-                               'Price', 'Discount %', 'Total');        
-       }               
+                               'Price', 'Discount %', 'Total');
+       }
        else if ($doctype == 12)
        {
                $this->title = "STATEMENT";
                $this->headers = array('Trans Type', '#', 'Date', 'Due Date', 'Charges',
                        'Credits', 'Allocated', 'Outstanding');
-       }               
+       }
 }
 if (isset($emailtype))
 {
@@ -64,9 +64,9 @@ if (isset($emailtype))
 }
 if (isset($header2type) || isset($linetype))
 {
-       $doc_Document_no = $doctype==13 ? "Delivery Note No." : "Invoice No.";
+       $doc_Invoice_no = $doctype==13 ? "Delivery Note No." : "Invoice No.";
        $doc_Order_no = "Order no.";
-}      
+}
 if (isset($linetype))
 {
        if ($doctype == 8 || $doctype == 9 || $doctype == 10 || $doctype == 11 || $doctype == 13)
@@ -89,6 +89,6 @@ if (isset($linetype))
                $doc_as_of = "as of";
                $doc_Days = "Days";
                $doc_Over = "Over";
-       }       
+       }
 }
 ?>
\ No newline at end of file
index 3fd3e979030e69771a01e5a1d900f94ee201135f..c98253f2ce46e94887ec38f3b8c9acf80d83bc9f 100644 (file)
@@ -30,7 +30,7 @@ function get_transactions($debtorno, $date)
                ((".TB_PREF."debtor_trans.type = 10)
                AND ".TB_PREF."debtor_trans.due_date < '$date') AS OverDue
        FROM ".TB_PREF."debtor_trans, ".TB_PREF."sys_types
-       WHERE ".TB_PREF."debtor_trans.tran_date <= '$date' 
+       WHERE ".TB_PREF."debtor_trans.tran_date <= '$date'
        AND ".TB_PREF."debtor_trans.debtor_no = '$debtorno'
        AND ".TB_PREF."debtor_trans.type != 13
        AND ".TB_PREF."debtor_trans.type = ".TB_PREF."sys_types.type_id
@@ -84,7 +84,6 @@ function print_customer_balances()
     $rep->Info($params, $cols, $headers, $aligns);
     $rep->Header();
 
-       $total = array(0,0,0,0);
        $grandtotal = array(0,0,0,0);
 
        $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
@@ -107,6 +106,7 @@ function print_customer_balances()
                if (db_num_rows($res)==0)
                        continue;
                $rep->Line($rep->row + 4);
+               $total = array(0,0,0,0);
                while ($trans = db_fetch($res))
                {
                        $rep->NewLine(1, 2);
@@ -121,6 +121,8 @@ function print_customer_balances()
                                $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $date);
                        else
                                $rate = 1.0;
+                       if ($trans['type'] == 11 || $trans['type'] == 12 || $trans['type'] == 2)
+                               $trans['TotalAmount'] *= -1;
                        if ($trans['TotalAmount'] > 0.0)
                        {
                                $item[0] = abs($trans['TotalAmount']) * $rate;
index 508844da6c5d233fd8afffdba82d425a60b950a5..e09bdefd8832544710856c9be521784d80075922 100644 (file)
@@ -26,67 +26,68 @@ function get_invoices($costomer_id, $to)
        $PastDueDays2 = 2 * $PastDueDays1;
 
        // Revomed allocated from sql
-       $sql = "SELECT ".TB_PREF."sys_types.type_name, ".TB_PREF."debtor_trans.reference, 
-               ".TB_PREF."debtor_trans.tran_date, 
+       $sql = "SELECT ".TB_PREF."sys_types.type_name, ".TB_PREF."debtor_trans.type, ".TB_PREF."debtor_trans.reference,
+               ".TB_PREF."debtor_trans.tran_date,
                (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount) as Balance,
                IF (".TB_PREF."payment_terms.days_before_due > 0,
-                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= ".TB_PREF."payment_terms.days_before_due THEN 
-                               ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount 
+                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= ".TB_PREF."payment_terms.days_before_due THEN
+                               ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount
                        ELSE
-                               0 
+                               0
                        END,
 
-                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(DATE_ADD(DATE_ADD(".TB_PREF."debtor_trans.tran_date, 
-                               INTERVAL 1 MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month - 
-                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= 0 THEN 
-                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount 
-                       ELSE 
-                               0 
+                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(DATE_ADD(DATE_ADD(".TB_PREF."debtor_trans.tran_date,
+                               INTERVAL 1 MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month -
+                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= 0 THEN
+                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount
+                       ELSE
+                               0
                        END
                ) AS Due,
                IF (".TB_PREF."payment_terms.days_before_due > 0,
-                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) > ".TB_PREF."payment_terms.days_before_due 
-                               AND TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= (".TB_PREF."payment_terms.days_before_due + $PastDueDays1) THEN 
-                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount 
-                       ELSE 
-                               0 
+                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) > ".TB_PREF."payment_terms.days_before_due
+                               AND TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= (".TB_PREF."payment_terms.days_before_due + $PastDueDays1) THEN
+                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount
+                       ELSE
+                               0
                        END,
 
-                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(DATE_ADD(DATE_ADD(".TB_PREF."debtor_trans.tran_date, 
-                               INTERVAL 1 MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month - 
-                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= $PastDueDays1 THEN 
-                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount 
-                       ELSE 
-                               0 
+                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(DATE_ADD(DATE_ADD(".TB_PREF."debtor_trans.tran_date,
+                               INTERVAL 1 MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month -
+                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= $PastDueDays1 THEN
+                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount
+                       ELSE
+                               0
                        END
                ) AS Overdue1,
                IF (".TB_PREF."payment_terms.days_before_due > 0,
-                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) > ".TB_PREF."payment_terms.days_before_due 
-                               AND TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= (".TB_PREF."payment_terms.days_before_due + $PastDueDays2) THEN 
-                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount 
-                       ELSE 
-                               0 
+                       CASE WHEN TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) > ".TB_PREF."payment_terms.days_before_due
+                               AND TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= (".TB_PREF."payment_terms.days_before_due + $PastDueDays2) THEN
+                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount
+                       ELSE
+                               0
                        END,
 
                        CASE WHEN TO_DAYS('$todate') - TO_DAYS(DATE_ADD(DATE_ADD(".TB_PREF."debtor_trans.tran_date,
-                               INTERVAL 1 MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month - 
-                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= $PastDueDays2 THEN 
-                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount 
-                       ELSE 
-                               0 
+                               INTERVAL 1 MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month -
+                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= $PastDueDays2 THEN
+                                       ".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount
+                       ELSE
+                               0
                        END
                ) AS Overdue2
 
-               FROM ".TB_PREF."debtors_master, 
-                       ".TB_PREF."payment_terms, 
-                       ".TB_PREF."debtor_trans, 
+               FROM ".TB_PREF."debtors_master,
+                       ".TB_PREF."payment_terms,
+                       ".TB_PREF."debtor_trans,
                        ".TB_PREF."sys_types
 
-               WHERE ".TB_PREF."sys_types.type_id = ".TB_PREF."debtor_trans.type 
-                       AND ".TB_PREF."debtors_master.payment_terms = ".TB_PREF."payment_terms.terms_indicator 
+               WHERE ".TB_PREF."sys_types.type_id = ".TB_PREF."debtor_trans.type
+                   AND ".TB_PREF."debtor_trans.type <> 13
+                       AND ".TB_PREF."debtors_master.payment_terms = ".TB_PREF."payment_terms.terms_indicator
                        AND ".TB_PREF."debtors_master.debtor_no = ".TB_PREF."debtor_trans.debtor_no
-                       AND ".TB_PREF."debtor_trans.debtor_no = $costomer_id 
-                       AND ".TB_PREF."debtor_trans.tran_date <= '$todate' 
+                       AND ".TB_PREF."debtor_trans.debtor_no = $costomer_id
+                       AND ".TB_PREF."debtor_trans.tran_date <= '$todate'
                        AND ABS(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount) > 0.004
                        ORDER BY ".TB_PREF."debtor_trans.tran_date";
 
@@ -112,8 +113,8 @@ function print_aged_customer_analysis()
        {
                include_once($path_to_root . "reporting/includes/class.graphic.inc");
                $pg = new graph();
-       }       
-    
+       }
+
        if ($fromcust == reserved_words::get_all_numeric())
                $from = _('All');
        else
@@ -143,8 +144,8 @@ function print_aged_customer_analysis()
                _('Total Balance'));
 
        $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right',     'right');
-    
-    $params =   array(         0 => $comments,   
+
+    $params =   array(         0 => $comments,
                                        1 => array('text' => _('End Date'), 'from' => $to, 'to' => ''),
                                    2 => array('text' => _('Customer'), 'from' => $from, 'to' => ''),
                                    3 => array('text' => _('Currency'), 'from' => $currency, 'to' => ''),
@@ -158,16 +159,15 @@ function print_aged_customer_analysis()
     $rep->Info($params, $cols, $headers, $aligns);
     $rep->Header();
 
-       $total = array();
-       $total[0] = $total[1] = $total[2] = $total[3] = $total[4] = 0.0;
-       
+       $total = array(0,0,0,0);
+
        $sql = "SELECT debtor_no, name, curr_code FROM ".TB_PREF."debtors_master ";
        if ($fromcust != reserved_words::get_all_numeric())
                $sql .= "WHERE debtor_no=$fromcust ";
        $sql .= "ORDER BY name";
        $result = db_query($sql, "The customers could not be retrieved");
-       
-       while ($myrow=db_fetch($result)) 
+
+       while ($myrow=db_fetch($result))
        {
                if (!$convert && $currency != $myrow['curr_code'])
                        continue;
@@ -182,7 +182,7 @@ function print_aged_customer_analysis()
                        $rate = 1.0;
                $rep->fontSize -= 2;
                $custrec = get_customer_details($myrow['debtor_no'], $to);
-               foreach ($custrec as $i => $value) 
+               foreach ($custrec as $i => $value)
                        $custrec[$i] *= $rate;
                $total[0] += ($custrec["Balance"] - $custrec["Due"]);
                $total[1] += ($custrec["Due"]-$custrec["Overdue1"]);
@@ -196,7 +196,7 @@ function print_aged_customer_analysis()
                        number_format2($custrec["Balance"],$dec));
                for ($i = 0; $i < count($str); $i++)
                        $rep->TextCol($i + 3, $i + 4, $str[$i]);
-               $rep->NewLine(1, 2);    
+               $rep->NewLine(1, 2);
                if (!$summaryOnly)
                {
                        $res = get_invoices($myrow['debtor_no'], $to);
@@ -209,7 +209,14 @@ function print_aged_customer_analysis()
                        $rep->TextCol(0, 1,     $trans['type_name'], -2);
                                $rep->TextCol(1, 2,     $trans['reference'], -2);
                                $rep->TextCol(2, 3, sql2date($trans['tran_date']), -2);
-                               foreach ($trans as $i => $value) 
+                               if ($trans['type'] == 11 || $trans['type'] == 12 || $trans['type'] == 2)
+                               {
+                                       $trans['Balance'] *= -1;
+                                       $trans['Due'] *= -1;
+                                       $trans['Overdue1'] *= -1;
+                                       $trans['Overdue2'] *= -1;
+                               }
+                               foreach ($trans as $i => $value)
                                        $trans[$i] *= $rate;
                                $str = array(number_format2(($trans["Balance"] - $trans["Due"]),$dec),
                                        number_format2(($trans["Due"]-$trans["Overdue1"]),$dec),
@@ -221,7 +228,7 @@ function print_aged_customer_analysis()
                        }
                        $rep->Line($rep->row - 8);
                        $rep->NewLine(2);
-               }       
+               }
        }
        if ($summaryOnly)
        {
@@ -237,8 +244,8 @@ function print_aged_customer_analysis()
                if ($graphics && $i < count($total) - 1)
                {
                        $pg->y[$i] = abs($total[$i]);
-               }       
-       }       
+               }
+       }
        $rep->Line($rep->row - 8);
        if ($graphics)
        {
index 012aff3ed79d42de3a50fc9fba0c22bade60720f..637bc07a8b19dc28f331778fc3cffedc42b3e16e 100644 (file)
@@ -2,79 +2,79 @@
 
 function get_customer_details($customer_id, $to=null)
 {
-       
+
        if ($to == null)
                $todate = date("Y-m-d");
-       else    
+       else
                $todate = date2sql($to);
        $past1 = get_company_pref('past_due_days');
        $past2 = 2 * $past1;
        // removed - debtor_trans.alloc from all summations
 
-    $value = "IF(".TB_PREF."debtor_trans.type=11 OR ".TB_PREF."debtor_trans.type=12,
-       -1, 1) *". 
+    $value = "IF(".TB_PREF."debtor_trans.type=11 OR ".TB_PREF."debtor_trans.type=12 OR ".TB_PREF."debtor_trans.type=2,
+       -1, 1) *".
       "(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
                .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + "
                .TB_PREF."debtor_trans.ov_discount)";
-       
+
     $sql = "SELECT ".TB_PREF."debtors_master.name, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."payment_terms.terms,
                ".TB_PREF."debtors_master.credit_limit, ".TB_PREF."credit_status.dissallow_invoices, ".TB_PREF."credit_status.reason_description,
 
                Sum(".$value.") AS Balance,
 
                Sum(IF (".TB_PREF."payment_terms.days_before_due > 0,
-                       CASE WHEN (TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date)) >= ".TB_PREF."payment_terms.days_before_due 
-                       THEN 
+                       CASE WHEN (TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date)) >= ".TB_PREF."payment_terms.days_before_due
+                       THEN
                            $value
-                       ELSE 0 
+                       ELSE 0
                        END,
 
                        CASE WHEN TO_DAYS('$todate') - TO_DAYS(DATE_ADD(DATE_ADD(".TB_PREF."debtor_trans.tran_date,
                                INTERVAL 1 MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month -
-                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= 0 
-                       THEN 
+                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= 0
+                       THEN
                            $value
-                       ELSE 0 
+                       ELSE 0
                        END
 
                )) AS Due,
 
                Sum(IF (".TB_PREF."payment_terms.days_before_due > 0,
                        CASE WHEN TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) > ".TB_PREF."payment_terms.days_before_due
-                               AND TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= (".TB_PREF."payment_terms.days_before_due + $past1) 
-                       THEN 
+                               AND TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= (".TB_PREF."payment_terms.days_before_due + $past1)
+                       THEN
                                $value
-                       ELSE 
-                               0 
+                       ELSE
+                               0
                        END,
 
                        CASE WHEN (TO_DAYS('$todate') - TO_DAYS(DATE_ADD(DATE_ADD(".TB_PREF."debtor_trans.tran_date,
                                INTERVAL 1  MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month -
-                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= $past1) 
-                       THEN 
+                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= $past1)
+                       THEN
                                $value
-                       ELSE 
-                               0 
+                       ELSE
+                               0
                        END
 
                )) AS Overdue1,
 
                Sum(IF (".TB_PREF."payment_terms.days_before_due > 0,
                        CASE WHEN TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) > ".TB_PREF."payment_terms.days_before_due
-                               AND TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= (".TB_PREF."payment_terms.days_before_due + $past2) 
-                       THEN 
+                               AND TO_DAYS('$todate') - TO_DAYS(".TB_PREF."debtor_trans.tran_date) >= (".TB_PREF."payment_terms.days_before_due + $past2)
+                       THEN
                            $value
-                       ELSE 
-                               0 
+                       ELSE
+                               0
                        END,
 
                        CASE WHEN (TO_DAYS('$todate') - TO_DAYS(DATE_ADD(DATE_ADD(".TB_PREF."debtor_trans.tran_date,
-                               INTERVAL 1  MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month - 
-                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= $past2) 
-                       THEN 
+                               INTERVAL 1  MONTH), INTERVAL (".TB_PREF."payment_terms.day_in_following_month -
+                               DAYOFMONTH(".TB_PREF."debtor_trans.tran_date)) DAY)) >= $past2)
+                       THEN
                                $value
-                       ELSE 
-                               0 
+                       ELSE
+                               0
                        END
 
                )) AS Overdue2
@@ -100,66 +100,66 @@ function get_customer_details($customer_id, $to=null)
                          ".TB_PREF."debtors_master.credit_limit,
                          ".TB_PREF."credit_status.dissallow_invoices,
                          ".TB_PREF."credit_status.reason_description";
-    
+
     $result = db_query($sql,"The customer details could not be retrieved");
 
     if (db_num_rows($result) == 0)
     {
-    
+
        /*Because there is no balance - so just retrieve the header information about the customer - the choice is do one query to get the balance and transactions for those customers who have a balance and two queries for those who don't have a balance OR always do two queries - I opted for the former */
-    
+
        $nil_balance = true;
-    
+
        $sql = "SELECT ".TB_PREF."debtors_master.name, ".TB_PREF."debtors_master.curr_code, ".TB_PREF."debtors_master.debtor_no,  ".TB_PREF."payment_terms.terms,
                ".TB_PREF."debtors_master.credit_limit, ".TB_PREF."credit_status.dissallow_invoices, ".TB_PREF."credit_status.reason_description
                FROM ".TB_PREF."debtors_master,
                     ".TB_PREF."payment_terms,
                     ".TB_PREF."credit_status
-    
+
                WHERE
                     ".TB_PREF."debtors_master.payment_terms = ".TB_PREF."payment_terms.terms_indicator
                     AND ".TB_PREF."debtors_master.credit_status = ".TB_PREF."credit_status.id
                     AND ".TB_PREF."debtors_master.debtor_no = '$customer_id'";
-            
+
        $result = db_query($sql,"The customer details could not be retrieved");
-    
-    } 
-    else 
+
+    }
+    else
     {
        $nil_balance = false;
     }
-    
+
     $customer_record = db_fetch($result);
-    
+
     if ($nil_balance == true)
     {
        $customer_record["Balance"] = 0;
        $customer_record["Due"] = 0;
        $customer_record["Overdue1"] = 0;
        $customer_record["Overdue2"] = 0;
-    }    
-    
+    }
+
     return $customer_record;
-       
+
 }
 
 function get_customer_name($customer_id)
 {
        $sql = "SELECT name FROM ".TB_PREF."debtors_master WHERE debtor_no=$customer_id";
-       
+
        $result = db_query($sql, "could not get customer");
-       
+
        $row = db_fetch_row($result);
-       
+
        return $row[0];
 }
 
 function get_area_name($id)
 {
        $sql = "SELECT description FROM ".TB_PREF."areas WHERE area_code=$id";
-       
+
        $result = db_query($sql, "could not get sales type");
-       
+
        $row = db_fetch_row($result);
        return $row[0];
 }
@@ -167,9 +167,9 @@ function get_area_name($id)
 function get_salesman_name($id)
 {
        $sql = "SELECT salesman_name FROM ".TB_PREF."salesman WHERE salesman_code=$id";
-       
+
        $result = db_query($sql, "could not get sales type");
-       
+
        $row = db_fetch_row($result);
        return $row[0];
 }
index 4cf0aa567ab717acc78189315c17a25e4b95af07..6b03ce0e66821bfdd81cfada0ac99ae2f2730fd3 100644 (file)
@@ -102,7 +102,7 @@ function write_credit_note($credit_note, $write_off_acc)
                        $credit_line->line_price(), $line_tax, $credit_line->discount_percent,
                        $credit_line->standard_cost, $trans_no==0 ? 0:  $credit_line->id);
 
-               add_credit_movements_item(&$credit_note, &$credit_line,
+               add_credit_movements_item($credit_note, $credit_line,
                        $credit_type, $line_taxfree_price+$line_tax, $credit_invoice);
 
                add_gl_trans_credit_costs($credit_note, $credit_line, $credit_no,