Changed $path_to_root and stamped copyright
[fa-stable.git] / reporting / rep102.php
index e3bf9d3ff795dd1176fc621881ba971106d175cf..620d50117f63dff9d6ac7516aad90d7aa427700a 100644 (file)
@@ -1,5 +1,14 @@
 <?php
-
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU Affero General Public License,
+       AGPL, as published by the Free Software Foundation, either version 
+       3 of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+***********************************************************************/
 $page_security = 2;
 // ----------------------------------------------------------------
 // $ Revision: 2.0 $
@@ -7,12 +16,12 @@ $page_security = 2;
 // date_:      2005-05-19
 // Title:      Aged Customer Balances
 // ----------------------------------------------------------------
-$path_to_root="../";
+$path_to_root="..";
 
-include_once($path_to_root . "includes/session.inc");
-include_once($path_to_root . "includes/date_functions.inc");
-include_once($path_to_root . "includes/data_checks.inc");
-include_once($path_to_root . "gl/includes/gl_db.inc");
+include_once($path_to_root . "/includes/session.inc");
+include_once($path_to_root . "/includes/date_functions.inc");
+include_once($path_to_root . "/includes/data_checks.inc");
+include_once($path_to_root . "/gl/includes/gl_db.inc");
 
 //----------------------------------------------------------------------------------------------------
 
@@ -26,56 +35,16 @@ function get_invoices($costomer_id, $to)
        $PastDueDays2 = 2 * $PastDueDays1;
 
        // 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)";
+       $due = "IF (".TB_PREF."debtor_trans.type=10,".TB_PREF."debtor_trans.due_date,".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
-                       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
-                                       ".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
-                       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
-                       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
-                       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
-                       END
-               ) AS Overdue2
+               $value as Balance,
+               IF ((TO_DAYS('$todate') - TO_DAYS($due)) >= 0,$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,
@@ -88,10 +57,9 @@ function get_invoices($costomer_id, $to)
                        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 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
+                       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
                        ORDER BY ".TB_PREF."debtor_trans.tran_date";
 
-
        return db_query($sql, "The customer details could not be retrieved");
 }
 
@@ -101,7 +69,7 @@ function print_aged_customer_analysis()
 {
     global $comp_path, $path_to_root;
 
-    include_once($path_to_root . "reporting/includes/pdf_report.inc");
+    include_once($path_to_root . "/reporting/includes/pdf_report.inc");
 
     $to = $_POST['PARAM_0'];
     $fromcust = $_POST['PARAM_1'];
@@ -111,7 +79,7 @@ function print_aged_customer_analysis()
     $comments = $_POST['PARAM_5'];
        if ($graphics)
        {
-               include_once($path_to_root . "reporting/includes/class.graphic.inc");
+               include_once($path_to_root . "/reporting/includes/class.graphic.inc");
                $pg = new graph();
        }
 
@@ -258,7 +226,7 @@ function print_aged_customer_analysis()
                $pg->type      = $graphics;
                $pg->skin      = $graph_skin;
                $pg->built_in  = false;
-               $pg->fontfile  = $path_to_root . "reporting/fonts/Vera.ttf";
+               $pg->fontfile  = $path_to_root . "/reporting/fonts/Vera.ttf";
                $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
                $filename = $comp_path .'/'. user_company(). "/images/test.png";
                $pg->display($filename, true);