Merged last changes from stable.
[fa-stable.git] / reporting / includes / reports_classes.inc
index 2faf00ae63bbb8ab73cc079464499032e852e22b..fdb8a17561e50956ca7e81c38f3cf5e773b0898b 100644 (file)
@@ -49,6 +49,10 @@ class BoxReports
        {
                global $path_to_root, $pdf_debug, $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];
@@ -59,6 +63,8 @@ class BoxReports
                if (isset($_GET['Class']))
                        set_focus('class'.$_GET['Class']);
 
+               $cur_class = $_REQUEST['Class'];
+
                foreach($this->ar_classes as $class_id => $name)
                {
                        if (!isset($this->ar_reports[$class_id]))
@@ -67,36 +73,36 @@ class BoxReports
                        $acc = access_string($name);
                        $st_classes .= "<a href='"
                                .$_SERVER['PHP_SELF']."?Class=$class_id'"
-                               ." style='font-weight:". ($_REQUEST['Class'] == $class_id ? 'bold' : 'normal')."'"
+                               ." 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==$_REQUEST['Class'] ? '' : "style='display:none'";
+                       $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='repopts_link'"
-                                       ." href='".$_SERVER['PHP_SELF']."?Class=$class_id&rep_id=$report->id'"
-                                       ." style='font-weight:". (@$_GET['rep_id'] == $report->id ? 'bold' : 'normal')."'"
+                                       ." 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 (@$_REQUEST['rep_id'] == $report->id) {
+                               if (@$_REQUEST['REP_ID'] == $report->id) {
                                        $Ajax->activate($id);
                                }
 
-                               if (isset($_REQUEST['rep_id']) && $_REQUEST['rep_id']==$report->id) {
-
-                                       $action = $path_to_root.'/reporting/prn_redirect.php';
-       
+                               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 process') . hidden('REP_ID', $report->id, false).'<br><br>';
                                        $st_params .= $this->getOptions($report->get_controls(), $report->id);
-                                       $st_params .= "\n</form></td></tr></table>\n";
+                                       $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);
                                }
@@ -159,7 +165,7 @@ class BoxReports
        function get_ctrl($name, $type)
        {
                global $path_to_root, $use_date_picker, $pdf_debug, $print_invoice_no,
-                       $def_print_destination, $type_shortcuts;
+                       $def_print_destination, $def_print_orientation, $type_shortcuts;
 
                $st = '';
                        switch ($type)
@@ -206,8 +212,12 @@ class BoxReports
                                                $date = $_POST[$name];
                                        $st = "<input type='text' name='$name' value='$date'>";
                                        if ($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' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
+                                       }       
                                        return $st;
                                        break;
 
@@ -215,8 +225,7 @@ 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");
@@ -225,6 +234,13 @@ class BoxReports
                                                $def = 1;
                                        return array_selector($name, $def, $sel);
 
+                               case 'ORIENTATION':
+                                       $sel = array(_("Portrait"), _("Landscape"));
+                                       $def = 0;
+                                       if (isset($def_print_orientation) && $def_print_orientation == 1)
+                                               $def = 1;
+                                       return array_selector($name, $def, $sel);
+
                                case 'COMPARE':
                                        $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
                                        return array_selector($name, null, $sel);
@@ -281,31 +297,32 @@ class BoxReports
                                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 = $type_shortcuts[ST_SALESINVOICE];
+                                       $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('$IV ', ".TB_PREF."debtor_trans.$ref,' ', ".TB_PREF."debtors_master.name) as IName
+                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE type=".ST_SALESINVOICE." AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
+                                       return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
+
+                               case 'CREDIT':
                                        $CN = $type_shortcuts[ST_CUSTCREDIT];
                                        $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";
+                                               ".TB_PREF."debtor_trans.type) AS TNO, concat('$CN ', ".TB_PREF."debtor_trans.$ref,' ', ".TB_PREF."debtors_master.name) as IName
+                                               FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE 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";
                                        return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
 
                                case 'DELIVERY':
@@ -354,16 +371,18 @@ class BoxReports
                                case 'RECEIPT':
                                        $BD = $type_shortcuts[ST_BANKDEPOSIT];
                                        $CP = $type_shortcuts[ST_CUSTPAYMENT];
-                                       $CN = $type_shortcuts[ST_CUSTCREDIT];
                                        $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
+                                               ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.$ref, if (type=".ST_BANKDEPOSIT.", ' $BD ', ' $CP '), ".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";
                                        return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
 
                                case 'ITEMS':
                                        return stock_manufactured_items_list($name);
 
+                               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