Redundant sql sentences in Report Filters.
[fa-stable.git] / reporting / includes / reports_classes.inc
index c824ddc311dd3e036fd7fee7dadd9837b5d5e92f..1b9694d3890783ddd6acd5bb3a4625744b34627e 100644 (file)
@@ -18,6 +18,7 @@ define('RC_MANUFACTURE', 3);
 define('RC_DIMENSIONS', 4);
 define('RC_BANKING', 5);
 define('RC_GL', 6);
+define('RC_FIXEDASSETS', 7);
 
 class BoxReports
 {
@@ -25,7 +26,7 @@ class BoxReports
        var $ar_reports;
        var $ctrl_handlers = array();
 
-       function ReportClasses()
+       function __construct()
        {
                $this->ar_classes = array();
        }
@@ -47,43 +48,62 @@ class BoxReports
 
        function getDisplay($class=null)
        {
-               global $table_style, $path_to_root, $pdf_debug, $Ajax;
+               global $path_to_root, $SysPrefs, $Ajax;
 
+               if (find_submit('Rep') != -1) {
+                       include($path_to_root.'/reporting/prn_redirect.php');
+                       return;
+               }
 
                $temp = array_values($this->ar_classes);
                $display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
                $st_reports = "";
                $st_params = "";
                $st_classes = "<b>" . _("Report Classes:") . "</b><br>";
+
+               if (isset($_GET['Class']))
+                       set_focus('class'.$_GET['Class']);
+
+               $cur_class = $_REQUEST['Class'];
+
                foreach($this->ar_classes as $class_id => $name)
                {
-                       $style = $class_id==$_REQUEST['Class'] ? '' : "style='display:none'";
-//                     $cname = access_string($key, true);
-//                     $style = $_REQUEST['Class']==$cname ? '' : "style='display:none'";
+                       if (!isset($this->ar_reports[$class_id]))
+                               continue; // e.g. no dimensions
+
                        $acc = access_string($name);
                        $st_classes .= "<a href='"
                                .$_SERVER['PHP_SELF']."?Class=$class_id'"
-                               ." class='menu_option' id='".default_focus()."'"
-                               ." onclick='return showClass(\"$class_id\");'$acc[1]>$acc[0]</a> <br>";
-                       $st_reports .= "<table class='repclass' id='TAB_" . $class_id ."' $style cellpadding=0 cellspacing=0 border=0 width='100%'><tr><td><b>" . _("Reports For Class: ") . "&nbsp;$name</b></td></tr>\n";
+                               ." style='font-weight:". ($cur_class == $class_id ? 'bold' : 'normal')."'"
+                               ." class='repclass_link' id='".'class'.$class_id."'"
+                               ."$acc[1]>$acc[0]</a> <br>";
+
+                       $style = $class_id==$cur_class ? '' : "style='display:none'";
+                       $st_reports .= "<table class='repclass' id='TAB_" . $class_id ."' $style cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td><b>" . _("Reports For Class: ") . "&nbsp;$name</b></td></tr>\n";
                        foreach($this->ar_reports[$class_id] as $rep_id => $report)
                        {
                                $acc = access_string($report->name);
-                               $st_reports .= "<tr><td><a class='printlink' href='"
-                                       .$_SERVER['PHP_SELF']."?Class=$class_id&rep_id=$report->id'"
-                                       ." id='".default_focus()."'"
+                               $st_reports .= "<tr><td><a class='repopts_link'"
+                                       ." href='".$_SERVER['PHP_SELF']."?Class=$class_id&REP_ID=$report->id'"
+                                       ." style='font-weight:". (@$_REQUEST['REP_ID'] == $report->id ? 'bold' : 'normal')."'"
+                                       ." 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';
-       
+                               if (@$_REQUEST['REP_ID'] == $report->id) {
+                                       $Ajax->activate($id);
+                               }
+
+                               if (isset($_REQUEST['REP_ID']) && $_REQUEST['REP_ID']==$report->id) {
+                                       // parameters form
+                                       $action = $_SERVER['PHP_SELF'];
                                        $st_params = "<table><tr><td>\n"
                                                . "<form method='POST' action='$action' target='_blank'>\n";
                                        $st_params .= submit('Rep'.$report->id,  
                                                _("Display: ") . access_string($report->name, true),
-                                               false, '', $pdf_debug ? false : 'default') . hidden('REP_ID', $report->id, false).'<br><br>';
-                                       $st_params .= $this->getOptions($report->get_controls());
-                                       $st_params .= "\n</form></td></tr></table>\n";
+                                               false, '', $SysPrefs->pdf_debug ? false : 'default process') . hidden('REP_ID', $report->id, false).'<br><br>';
+                                       $st_params .= $this->getOptions($report->get_controls(), $report->id);
+                                       $st_params .= "\n<input type=hidden name='Class' value=".$cur_class.">"
+                                               ."\n</form></td></tr></table>\n";
                                        set_focus('Rep'.$report->id);
                                        $Ajax->addUpdate(true, 'rep_form', $st_params);
                                }
@@ -94,28 +114,7 @@ class BoxReports
                $st_params = "<div id='rep_form'>".
                        "$st_params</div>";
                
-
-               $st =   "<script language='javascript'>
-                                       function showClass(pClass) {
-                                               var classes = document.getElementsBySelector('.repclass');
-                                               for(var i in  classes) {
-                                                       cl = classes[i];
-                                                       cl.style.display=
-                                                       (cl.id==('TAB_'+pClass)) ? \"block\" : \"none\";
-                                               }
-                                               document.getElementById('rep_form').innerHTML = '';
-//                                             document.getElementById('rep_form').style.display = 'none';
-                                               return false;
-                                       }
-                                       function checkDate(pObj) {
-                                               var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
-                                               if (re.test(pObj.value)==false) {
-                                                       alert('" . _("Invalid date format") . "')
-                                               }
-                                       }
-                               </script>
-                               ";
-               $st .= "<table align='center' width='80%' style='border:1px solid #cccccc;'><tr valign='top'>";
+               $st = "<table align='center' width='80%' style='border:1px solid #cccccc;'><tr valign='top'>";
                $st .= "<td width='30%'>$st_classes</td>";
                $st .= "<td width='35%' style='border-left:1px solid #cccccc;border-right:1px solid #cccccc;padding-left:3px;'>$st_reports</td>";
                $st .= "<td width='35%'>$st_params</td>";
@@ -124,7 +123,7 @@ class BoxReports
                return $st;
        }
 
-       function getOptions($controls)
+       function getOptions($controls, $id = 0)
        {
                $st = '';
                if ($controls == null)
@@ -139,6 +138,11 @@ class BoxReports
                                if ($ctrl) break;
                        }
                        if ($ctrl == '') {
+                               if (($id == 102 || $id == 202) && $cnt == 3) // set default Show Also Allocated to Yes in aged reports 2014-09-19 Joe Hunt
+                                       $_POST['PARAM_'.$cnt] = 1;
+                               
+                               if (isset($_COOKIE['select'][$id][$cnt])) // saved parameters 2010-10-06 Joe Hunt
+                                       $_POST['PARAM_'.$cnt] = $_COOKIE['select'][$id][$cnt];
                                $ctrl = $this->get_ctrl('PARAM_'.$cnt, $type);
                        }
                        if ($ctrl != '')  {
@@ -164,7 +168,8 @@ class BoxReports
        //
        function get_ctrl($name, $type)
        {
-               global $path_to_root, $use_date_picker, $pdf_debug, $print_invoice_no;
+               global $path_to_root, $SysPrefs,
+                       $type_shortcuts;
 
                $st = '';
                        switch ($type)
@@ -180,35 +185,43 @@ class BoxReports
                                case 'DATEENDM':
                                case 'DATEBEGINTAX':
                                case 'DATEENDTAX':
-                                       if ($type == 'DATEBEGIN')
-                                               $date = begin_fiscalyear();
-                                       elseif ($type == 'DATEEND')
-                                               $date = end_fiscalyear();
-                                       else
-                                               $date = Today();
-                                       if ($type == 'DATEBEGINM')
-                                               $date = begin_month($date);
-                                       elseif ($type == 'DATEENDM')
-                                               $date = end_month($date);
-                                       elseif ($type == 'DATEBEGINTAX' || $type == 'DATEENDTAX')
+                                       if (!isset($_POST[$name]))
                                        {
-                                               $row = get_company_prefs();
-                                               $edate = add_months($date, -$row['tax_last']);
-                                               $edate = end_month($edate);
-                                               if ($type == 'DATEENDTAX')
-                                                       $date = $edate;
+                                               if ($type == 'DATEBEGIN')
+                                                       $date = begin_fiscalyear();
+                                               elseif ($type == 'DATEEND')
+                                                       $date = end_fiscalyear();
                                                else
+                                                       $date = Today();
+                                               if ($type == 'DATEBEGINM')
+                                                       $date = begin_month($date);
+                                               elseif ($type == 'DATEENDM')
+                                                       $date = end_month($date);
+                                               elseif ($type == 'DATEBEGINTAX' || $type == 'DATEENDTAX')
                                                {
-                                                       $bdate = begin_month($edate);
-                                                       $bdate = add_months($bdate, -$row['tax_prd'] + 1);
-                                                       $date = $bdate;
+                                                       $row = get_company_prefs();
+                                                       $edate = add_months($date, -$row['tax_last']);
+                                                       $edate = end_month($edate);
+                                                       if ($type == 'DATEENDTAX')
+                                                               $date = $edate;
+                                                       else
+                                                       {
+                                                               $bdate = begin_month($edate);
+                                                               $bdate = add_months($bdate, -$row['tax_prd'] + 1);
+                                                               $date = $bdate;
+                                                       }
                                                }
                                        }
-
+                                       else // saved parameters
+                                               $date = $_POST[$name];
                                        $st = "<input type='text' name='$name' value='$date'>";
-                                       if ($use_date_picker)
+                                       if (user_use_date_picker())
+                                       {
+                                               $calc_image = (file_exists("$path_to_root/themes/".user_theme()."/images/cal.gif")) ? 
+                                                       "$path_to_root/themes/".user_theme()."/images/cal.gif" : "$path_to_root/themes/default/images/cal.gif";
                                                $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
-                                               . "     <img src='$path_to_root/themes/default/images/cal.gif' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
+                                               . "     <img src='$calc_image' style='vertical-align:middle;padding-bottom:4px;width:16px;height:16px;border:0;' alt='"._('Click Here to Pick up the date')."'></a>\n";
+                                       }       
                                        return $st;
                                        break;
 
@@ -216,12 +229,21 @@ class BoxReports
                                        return yesno_list($name);
 
                                case 'PAYMENT_LINK':
-                                       $sel = array(_("No payment Link"), "PayPal");
-                                       return array_selector($name, null, $sel);
+                                       return payment_services($name, null);
 
                                case 'DESTINATION':
                                        $sel = array(_("PDF/Printer"), "Excel");
-                                       return array_selector($name, null, $sel);
+                                       $def = 0;
+                                       if (user_def_print_destination() == 1)
+                                               $def = 1;
+                                       return array_selector($name, $def, $sel);
+
+                               case 'ORIENTATION':
+                                       $sel = array(_("Portrait"), _("Landscape"));
+                                       $def = 0;
+                                       if (user_def_print_orientation() == 1)
+                                               $def = 1;
+                                       return array_selector($name, $def, $sel);
 
                                case 'COMPARE':
                                        $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
@@ -242,7 +264,8 @@ class BoxReports
                                        return "<input type='text' name='$name'>";
 
                                case 'TEXTBOX':
-                                       return "<textarea rows=4 cols=30 name='$name'></textarea>";
+                                       $value = (isset($_POST[$name]) ? $_POST[$name] : "");
+                                       return "<textarea rows=4 cols=30 maxlength=130 name='$name'>$value</textarea>";
 
                                case 'ACCOUNTS': // not used
                                        return gl_account_types_list($name, null, _("No Account Group Filter"), true);
@@ -276,108 +299,136 @@ class BoxReports
 
                                case 'CUSTOMERS_NO_FILTER':
                                case 'CUSTOMERS':
-                                       $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master";
                                        if ($type == 'CUSTOMERS_NO_FILTER')
-                                               return combo_input($name, '', $sql, 'debtor_no', 'name',array('spec_option'=>_("No Customer Filter"),'spec_id'=>ALL_NUMERIC));
-// FIX allitems numeric!
-//                                             return customer_list($name, null, _("No Customer Filter"));
+                                               return customer_list($name, null, _("No Customer Filter"));
                                        else
-                                               return combo_input($name, '', $sql, 'debtor_no', 'name', null);
-//                                             return customer_list($name);
+                                               return customer_list($name);
 
                                case 'SUPPLIERS_NO_FILTER':
                                case 'SUPPLIERS':
-                                       $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers";
                                        if ($type == 'SUPPLIERS_NO_FILTER')
-                                               return combo_input($name, '', $sql, 'supplier_id', 'supp_name',array('spec_option'=>_("No Supplier Filter"),'spec_id'=>ALL_NUMERIC));
-// FIX allitems numeric!
-//                                             return supplier_list($name, null, _("No Supplier Filter"));
+                                               return supplier_list($name, null, _("No Supplier Filter"));
                                        else
-                                               return combo_input($name, '', $sql, 'supplier_id', 'supp_name', null);
-//                                             return supplier_list($name);
+                                               return supplier_list($name);
 
                                case 'INVOICE':
-                                       $IV = _("IV");
-                                       $CN = _("CN");
-                                       $ref = ($print_invoice_no == 1 ? "trans_no" : "reference");
-                                       $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
-                                               ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.$ref, if (type=".ST_SALESINVOICE.", ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
-                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=".ST_SALESINVOICE." OR type=".ST_CUSTCREDIT.") AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
+                                       $IV = $type_shortcuts[ST_SALESINVOICE];
+                                       $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
+                                       $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
+                                                               concat('$IV ', debtor_trans.$ref,' ', debtor.name) as IName
+                                               FROM ".TB_PREF."debtors_master debtor,"
+                                                       .TB_PREF."debtor_trans debtor_trans
+                                               WHERE type=".ST_SALESINVOICE." AND debtor.debtor_no=debtor_trans.debtor_no
+                                               ORDER BY debtor_trans.trans_no DESC";
+                                       return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
+
+                               case 'CREDIT':
+                                       $CN = $type_shortcuts[ST_CUSTCREDIT];
+                                       $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
+                                       $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
+                                                               concat('$CN ', debtor_trans.$ref,' ', debtor.name) as IName
+                                               FROM ".TB_PREF."debtors_master debtor,"
+                                                       .TB_PREF."debtor_trans debtor_trans
+                                               WHERE type=".ST_CUSTCREDIT." AND debtor.debtor_no=debtor_trans.debtor_no
+                                               ORDER BY debtor_trans.trans_no DESC";
                                        return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
 
                                case 'DELIVERY':
-                                       $DN = _("DN");
-                                       $sql = "SELECT
-                                       concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
-                                        ".TB_PREF."debtors_master.name) as IName
-                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
-                                               WHERE type=".ST_CUSTDELIVERY." AND ".TB_PREF."debtors_master.debtor_no=".
-                                               TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
+                                       $DN = $type_shortcuts[ST_CUSTDELIVERY];
+                                       $sql = "SELECT  concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
+                                                               concat(debtor_trans.trans_no, ' $DN ', debtor.name) as IName
+                                               FROM ".TB_PREF."debtors_master debtor,"
+                                                       .TB_PREF."debtor_trans debtor_trans
+                                               WHERE type=".ST_CUSTDELIVERY." AND debtor.debtor_no=debtor_trans.debtor_no
+                                               ORDER BY debtor_trans.trans_no DESC";
                                        return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
 
                                case 'ORDERS':
-                                       $ref = ($print_invoice_no == 1 ? "order_no" : "reference");
-                                       $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.$ref, '-',
-                                               ".TB_PREF."debtors_master.name) as IName
-                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."sales_orders WHERE ".TB_PREF."debtors_master.debtor_no=".TB_PREF."sales_orders.debtor_no 
-                                               AND ".TB_PREF."sales_orders.trans_type=".ST_SALESORDER." ORDER BY ".TB_PREF."sales_orders.order_no DESC";
+                                       $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
+                                       $sql = "SELECT sorder.order_no, concat(sorder.$ref, '-', debtor.name) as IName
+                                               FROM ".TB_PREF."debtors_master debtor,"
+                                                       .TB_PREF."sales_orders sorder
+                                               WHERE debtor.debtor_no=sorder.debtor_no AND sorder.trans_type=".ST_SALESORDER
+                                               ." ORDER BY sorder.order_no DESC";
                                        return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
 
                                case 'QUOTATIONS':
-                                       $ref = ($print_invoice_no == 1 ? "order_no" : "reference");
-                                       $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.$ref, '-',
-                                               ".TB_PREF."debtors_master.name) as IName
-                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."sales_orders WHERE ".TB_PREF."debtors_master.debtor_no=".TB_PREF."sales_orders.debtor_no 
-                                               AND ".TB_PREF."sales_orders.trans_type=".ST_SALESQUOTE." ORDER BY ".TB_PREF."sales_orders.order_no DESC";
+                                       $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
+                                       $sql = "SELECT sorder.order_no, concat(sorder.$ref, '-', debtor.name) as IName
+                                               FROM ".TB_PREF."debtors_master debtor,"
+                                                       .TB_PREF."sales_orders sorder
+                                               WHERE debtor.debtor_no=sorder.debtor_no AND sorder.trans_type=".ST_SALESQUOTE
+                                                       ." ORDER BY sorder.order_no DESC";
                                        return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
 
                                case 'PO':
-                                       $ref = ($print_invoice_no == 1 ? "order_no" : "reference");
-                                       $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.$ref, '-',
-                                               ".TB_PREF."suppliers.supp_name) as IName
-                                               FROM ".TB_PREF."suppliers, ".TB_PREF."purch_orders WHERE ".TB_PREF."suppliers.supplier_id=".TB_PREF."purch_orders.supplier_id ORDER BY ".TB_PREF."purch_orders.order_no DESC";
+                                       $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
+                                       $sql = "SELECT po.order_no, concat(po.$ref, '-', supplier.supp_name) as IName
+                                               FROM ".TB_PREF."suppliers supplier,"
+                                                       .TB_PREF."purch_orders po
+                                               WHERE supplier.supplier_id=po.supplier_id
+                                               ORDER BY po.order_no DESC";
                                        return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
 
                                case 'REMITTANCE':
-                                       $BP = _("BP");
-                                       $SP = _("SP");
-                                       $CN = _("CN");
-                                       $ref = ($print_invoice_no == 1 ? "trans_no" : "reference");
-                                       $sql = "SELECT concat(".TB_PREF."supp_trans.trans_no, '-',
-                                               ".TB_PREF."supp_trans.type) AS TNO, concat(".TB_PREF."supp_trans.$ref, if (type=".ST_BANKPAYMENT.", ' $BP ', if (type=".ST_SUPPAYMENT.", ' $SP ', ' $CN ')), ".TB_PREF."suppliers.supp_name) as IName
-                                               FROM ".TB_PREF."suppliers, ".TB_PREF."supp_trans WHERE (type=".ST_BANKPAYMENT." OR type=".ST_SUPPAYMENT." OR type=".ST_SUPPCREDIT.") AND ".TB_PREF."suppliers.supplier_id=".TB_PREF."supp_trans.supplier_id ORDER BY ".TB_PREF."supp_trans.trans_no DESC";
+                                       $BP = $type_shortcuts[ST_BANKPAYMENT];
+                                       $SP = $type_shortcuts[ST_SUPPAYMENT];
+                                       $CN = $type_shortcuts[ST_SUPPCREDIT];
+                                       $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
+                                       $sql = "SELECT concat(trans.trans_no, '-',trans.type) AS TNO,
+                                                               concat(trans.$ref, IF(type=".ST_BANKPAYMENT.", ' $BP ', IF(type=".ST_SUPPAYMENT.", ' $SP ', ' $CN ')), supplier.supp_name) as IName
+                                                       FROM ".TB_PREF."suppliers supplier, "
+                                                               .TB_PREF."supp_trans trans
+                                                       WHERE type IN(".ST_BANKPAYMENT.",".ST_SUPPAYMENT.",".ST_SUPPCREDIT.")
+                                                               AND supplier.supplier_id=trans.supplier_id
+                                                       ORDER BY trans.trans_no DESC";
                                        return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
 
                                case 'RECEIPT':
-                                       $BD = _("BD");
-                                       $CP = _("CP");
-                                       $CN = _("CN");
-                                       $ref = ($print_invoice_no == 1 ? "trans_no" : "reference");
-                                       $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
-                                               ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.$ref, if (type=".ST_BANKDEPOSIT.", ' $BD ', if (type=".ST_CUSTPAYMENT.", ' $CP ', ' $CN ')), ".TB_PREF."debtors_master.name) as IName
-                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=".ST_BANKDEPOSIT." OR type=".ST_CUSTPAYMENT." OR type=".ST_CUSTCREDIT.") AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
+                                       $BD = $type_shortcuts[ST_BANKDEPOSIT];
+                                       $CP = $type_shortcuts[ST_CUSTPAYMENT];
+                                       $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
+                                       $sql = "SELECT concat(trans.trans_no, '-', trans.type) AS TNO,
+                                                               concat(trans.$ref, IF(type=".ST_BANKDEPOSIT.", ' $BD ', ' $CP '), debtor.name) as IName
+                                               FROM ".TB_PREF."debtors_master debtor,"
+                                                       .TB_PREF."debtor_trans trans
+                                               WHERE type IN(".ST_BANKDEPOSIT.",".ST_CUSTPAYMENT.",".ST_CUSTCREDIT.") AND debtor.debtor_no=trans.debtor_no
+                                               ORDER BY trans.trans_no DESC";
                                        return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
 
                                case 'ITEMS':
                                        return stock_manufactured_items_list($name);
 
+                               case 'ITEMS_ALL':
+                                       return stock_manufactured_items_list($name, null, true);
+
+                               case 'ITEMS_P':
+                                       return stock_purchasable_items_list($name, null, true);
+                               
                                case 'WORKORDER':
-                                       $sql = "SELECT ".TB_PREF."workorders.id, concat(".TB_PREF."workorders.id, '-',
-                                               ".TB_PREF."stock_master.description) as IName
-                                               FROM ".TB_PREF."stock_master, ".TB_PREF."workorders WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id ORDER BY ".TB_PREF."workorders.id DESC";
+                                       $sql = "SELECT wo.id, concat(wo.id, '-', item.description) as IName
+                                               FROM ".TB_PREF."stock_master item,"
+                                                       .TB_PREF."workorders wo
+                                               WHERE item.stock_id=wo.stock_id
+                                               ORDER BY wo.id DESC";
                                        return combo_input($name, '', $sql, 'id', 'IName',array('order'=>false));
 
                                case 'LOCATIONS':
                                        return  locations_list($name, null, _("No Location Filter"));
+                               case 'FLOCATIONS':
+                                       return  locations_list($name, null, _("No Location Filter"), false, true);
 
                                case 'CATEGORIES':
                                        return stock_categories_list($name, null, _("No Category Filter"));
-
+                               case 'FCATEGORIES':
+                                       return stock_categories_list($name, null, _("No Category Filter"), false, true);
+                               case 'FCLASS':
+                                       return fixed_asset_classes_list($name, null, _("No Class Filter"), false);
                                case 'SALESTYPES':
                                        return sales_types_list($name);
 
                                case 'AREAS':
-                                       return sales_areas_list($name);
+                                       return sales_areas_list($name, null, _("No Areas Filter"));
 
                                case 'SALESMEN':
                                        return sales_persons_list($name, null, _("No Sales Folk Filter"));
@@ -395,7 +446,7 @@ class BoxReports
                                                $tag_type = TAG_ACCOUNT;
                                        else
                                                $tag_type = TAG_DIMENSION;
-                                       return tag_list($name, 5, $tag_type, true, _("No tags"));
+                                       return tag_list($name, 5, $tag_type, true);
 
                        }
                return '';
@@ -409,7 +460,7 @@ class Report
        var $ar_params;
        var $controls;
        
-       function Report($id, $name, $ar_params = null)
+       function __construct($id, $name, $ar_params = null)
        {
                $this->id = $id;
                $this->name = $name;
@@ -459,8 +510,11 @@ function add_custom_reports(&$reports)
                foreach ($extensions as $ext)
                        if (($ext['active'] && $ext['type'] == 'extension')) {
                                $file = $path_to_root.'/'.$ext['path']."/reporting/reports_custom.php";
-                               if (file_exists($file))
+                               if (file_exists($file)) {
+                                       set_ext_domain($ext['path']);
                                        include_once($file);
+                                       set_ext_domain();
+                               }
                        }
        }
        $file = company_path()."/reporting/reports_custom.php";
@@ -468,4 +522,3 @@ function add_custom_reports(&$reports)
                include_once($file);
 }
 
-?>
\ No newline at end of file