Merged changes from main branch up to 2.1.3.
[fa-stable.git] / reporting / includes / reports_classes.inc
index fd08842fa0a54ce361367cc89f606f2ceb62f38f..803160fe8b740ec7d7afc8032c34eb2fd7475ea8 100644 (file)
@@ -1,4 +1,14 @@
 <?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       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/gpl-3.0.html>.
+***********************************************************************/
 class BoxReports
 {
        var $ar_classes;
@@ -34,15 +44,17 @@ class BoxReports
                        $style = $class_counter==$_REQUEST['Class'] ? '' : "style='display:none'";
                        $acc = access_string($key);
                        $st_classes .= "<a href='"
-                               .$_SERVER['PHP_SELF']."?Class=$class_counter"
-                               ."' onclick='return showClass($class_counter);'$acc[1]>$acc[0]</a> <br>";
+                               .$_SERVER['PHP_SELF']."?Class=$class_counter'"
+                               ." class='menu_option' id='".default_focus()."'"
+                               ." onclick='return showClass($class_counter);'$acc[1]>$acc[0]</a> <br>";
                        $st_reports .= "<table id='TAB_" . $class_counter ."' $style cellpadding=0 cellspacing=0 border=0 width='100%'><tr><td><b>" . _("Reports For Class: ") . "&nbsp;$key</b></td></tr>\n";
                        foreach($value as $report)
                        {
                                $acc = access_string($report->name);
                                $st_reports .= "<tr><td><a class='printlink' href='"
-                                       .$_SERVER['PHP_SELF']."?Class=$class_counter&rep_id=$report->id"
-                                       ."'$acc[1]>$acc[0]</a><tr><td>\n";
+                                       .$_SERVER['PHP_SELF']."?Class=$class_counter&rep_id=$report->id'"
+                                       ." id='".default_focus()."'"
+                                       ."$acc[1]>$acc[0]</a><tr><td>\n";
                                if (isset($_REQUEST['rep_id']) && $_REQUEST['rep_id']==$report->id) {
 
                                        $action = $path_to_root.'/reporting/prn_redirect.php';
@@ -51,10 +63,11 @@ class BoxReports
                                                . "<form method='POST' action='$action' target='_blank'>\n";
                                        $st_params .= hidden('REP_ID', $report->id, false);
                                        $st_params .= submit('Rep'.$report->id,  
-                                               _("Display: ") . access_string($report->name,true),
-                                               false, '', $pdf_debug==0) . '<br><br>';
+                                               _("Display: ") . access_string($report->name, true),
+                                               false, '', $pdf_debug ? false : 'default') . '<br><br>';
                                        $st_params .= $report->getDisplay() 
                                                . "\n</form></td></tr></table>\n";
+                                       set_focus('Rep'.$report->id);
                                        $Ajax->addUpdate(true, 'rep_form', $st_params);
                                }
                        }
@@ -109,7 +122,7 @@ class Report
        
        function getDisplay()
        {
-               global $path_to_root, $use_date_picker, $pdf_debug;
+               global $path_to_root, $use_date_picker, $pdf_debug, $print_invoice_no;
 
                $st = '';
                $dummy = "";
@@ -150,8 +163,9 @@ class Report
                                                        $date = $edate;
                                                else
                                                {
-                                                       $bdate = add_months($edate, -$row['tax_prd'] + 1);
-                                                       $date = begin_month($bdate);
+                                                       $bdate = begin_month($edate);
+                                                       $bdate = add_months($bdate, -$row['tax_prd'] + 1);
+                                                       $date = $bdate;
                                                }
                                        }
                                        $name = "PARAM_$index";
@@ -170,6 +184,10 @@ class Report
                                        $sel = array(_("No Payment Link"), "PayPal");
                                        $st .= dup_simple_name_list("PARAM_$index", $sel);
                                        break;
+                               case 'DESTINATION':
+                                       $sel = array(_("PDF/Printer"), "Excel");
+                                       $st .= dup_simple_name_list("PARAM_$index", $sel);
+                                       break;
                                case 'COMPARE':
                                        $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
                                        $st .= dup_simple_name_list("PARAM_$index", $sel);
@@ -196,32 +214,31 @@ class Report
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
                                        break;
                                case 'BANK_ACCOUNTS':
-                                       $sql = "SELECT ".TB_PREF."bank_accounts.account_code, concat(bank_account_name, if (bank_curr_code=curr_default,'', concat(' - ', bank_curr_code))) FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master, ".TB_PREF."company
-                                               WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
+                                       $sql = "SELECT ".TB_PREF."bank_accounts.id, concat(bank_account_name, if (bank_curr_code=curr_default,'', concat(' - ', bank_curr_code))) FROM ".TB_PREF."bank_accounts, ".TB_PREF."company";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
                                        break;
                                case 'DIMENSION':
-                                       $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
+                                       $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
                                        break;
                                case 'DIMENSIONS':
-                                       $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
+                                       $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
                                        break;
                                case 'DIMENSION1':
-                                       $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
+                                       $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index". "_$index", $dummy);
                                        break;
                                case 'DIMENSIONS1':
-                                       $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
+                                       $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
                                        break;
                                case 'DIMENSION2':
-                                       $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
+                                       $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
                                        break;
                                case 'DIMENSIONS2':
-                                       $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
+                                       $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
                                        break;
                                case 'CUSTOMERS_NO_FILTER':
@@ -243,9 +260,14 @@ class Report
                                case 'INVOICE':
                                        $IV = _("IV");
                                        $CN = _("CN");
-                                       $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
-                                               ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
-                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
+                                       if ($print_invoice_no == 1)
+                                               $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
+                                                       ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
+                                                       FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
+                                       else            
+                                               $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
+                                                       ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.reference, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
+                                                       FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
                                        $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
                                        break;
                                case 'DELIVERY':