The aging reports / inquiries had a 1 day error in presentation. Fixed.
[fa-stable.git] / reporting / rep102.php
index b839b6b7e650c399eb5543749417abe998230278..90f7db024a9b246bf5fa5795da37bd9919679459 100644 (file)
@@ -30,33 +30,37 @@ print_aged_customer_analysis();
 function get_invoices($customer_id, $to, $all=true)
 {
        $todate = date2sql($to);
-       $PastDueDays1 = get_company_pref('past_due_days');
-       $PastDueDays2 = 2 * $PastDueDays1;
+       $current = 1;
+       $PastDueDays1 = get_company_pref('past_due_days') + $current;
+       $PastDueDays2 = 2 * $PastDueDays1 + $current;
 
        // Revomed allocated from sql
-    $value = "(".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)";
+       if ($all)
+       $value = "(".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)";
+       else            
+       $value = "(".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 - ".TB_PREF."debtor_trans.alloc)";
        $due = "IF (".TB_PREF."debtor_trans.type=".ST_SALESINVOICE.",".TB_PREF."debtor_trans.due_date,".TB_PREF."debtor_trans.tran_date)";
        $sql = "SELECT ".TB_PREF."debtor_trans.type, ".TB_PREF."debtor_trans.reference,
                ".TB_PREF."debtor_trans.tran_date,
                $value as Balance,
-               IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= 0,$value,0) AS Due,
+               IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $current,$value,0) AS Due,
                IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $PastDueDays1,$value,0) AS Overdue1,
                IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= $PastDueDays2,$value,0) AS Overdue2
 
                FROM ".TB_PREF."debtors_master,
-                       ".TB_PREF."payment_terms,
                        ".TB_PREF."debtor_trans
 
                WHERE ".TB_PREF."debtor_trans.type <> ".ST_CUSTDELIVERY."
-                       AND ".TB_PREF."debtor_trans.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 = $customer_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_freight_tax + ".TB_PREF."debtor_trans.ov_discount) > 0.004 ";
+                       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_freight_tax + ".TB_PREF."debtor_trans.ov_discount) > ".FLOAT_COMP_DELTA." ";
        if (!$all)
-               $sql .= "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_freight_tax + ".TB_PREF."debtor_trans.ov_discount - ".TB_PREF."debtor_trans.alloc) > 0.004 ";  
+               $sql .= "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_freight_tax + ".TB_PREF."debtor_trans.ov_discount - ".TB_PREF."debtor_trans.alloc) > ".FLOAT_COMP_DELTA." ";  
        $sql .= "ORDER BY ".TB_PREF."debtor_trans.tran_date";
 
        return db_query($sql, "The customer details could not be retrieved");
@@ -76,11 +80,13 @@ function print_aged_customer_analysis()
        $no_zeros = $_POST['PARAM_5'];
        $graphics = $_POST['PARAM_6'];
        $comments = $_POST['PARAM_7'];
-       $destination = $_POST['PARAM_8'];
+       $orientation = $_POST['PARAM_8'];
+       $destination = $_POST['PARAM_9'];
        if ($destination)
                include_once($path_to_root . "/reporting/includes/excel_report.inc");
        else
                include_once($path_to_root . "/reporting/includes/pdf_report.inc");
+       $orientation = ($orientation ? 'L' : 'P');
        if ($graphics)
        {
                include_once($path_to_root . "/reporting/includes/class.graphic.inc");
@@ -132,8 +138,10 @@ function print_aged_customer_analysis()
 
        if ($convert)
                $headers[2] = _('Currency');
-       $rep = new FrontReport(_('Aged Customer Analysis'), "AgedCustomerAnalysis", user_pagesize());
-
+    $rep = new FrontReport(_('Aged Customer Analysis'), "AgedCustomerAnalysis", user_pagesize(), 9, $orientation);
+    if ($orientation == 'L')
+       recalculate_cols($cols);
     $rep->Font();
     $rep->Info($params, $cols, $headers, $aligns);
     $rep->NewPage();
@@ -165,7 +173,7 @@ function print_aged_customer_analysis()
                        $custrec["Overdue1"]-$custrec["Overdue2"],
                        $custrec["Overdue2"],
                        $custrec["Balance"]);
-               if ($no_zeros && array_sum($str) == 0) continue;
+               if ($no_zeros && floatcmp(array_sum($str), 0) == 0) continue;
 
                $rep->fontSize += 2;
                $rep->TextCol(0, 2, $myrow['name']);