Rerun of implemented Selectable Print Orientation (Portrait, Landscape) for all repor...
[fa-stable.git] / reporting / includes / reporting.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 // Link to printing single document with bulk report template file.
13 // Ex. label_cell(print_document_link($myrow['order_no'], _("Print")), $type);
14 // or display_note(print_document_link($order_no, _("Print this order")));
15 // You only need full parameter list for invoices/credit notes
16
17 function print_document_link($doc_no, $link_text, $link=true, $type_no, 
18         $icon=false, $class='printlink', $id='', $email=0, $extra=0)
19 {
20         global $path_to_root, $def_print_orientation;
21         include_once($path_to_root . "/includes/types.inc");
22
23         $url = $path_to_root.'/reporting/prn_redirect.php?';
24         $def_orientation = (isset($def_print_orientation) && $def_print_orientation == 1 ? 1 : 0);
25         switch ($type_no)
26         {
27                 case ST_SALESQUOTE :
28                         $rep = 111;
29                         // from, to, currency, email, comments, orientation
30                         $ar = array(
31                                 'PARAM_0' => $doc_no, 
32                                 'PARAM_1' => $doc_no, 
33                                 'PARAM_2' => '', 
34                                 'PARAM_3' => $email, 
35                                 'PARAM_4' => '',
36                                 'PARAM_5' => $def_orientation);
37                         break;
38                 case ST_SALESORDER :
39                         $rep = 109;
40                         // from, to, currency, email, quote, comments, orientation
41                         $ar = array(
42                                 'PARAM_0' => $doc_no, 
43                                 'PARAM_1' => $doc_no, 
44                                 'PARAM_2' => '', 
45                                 'PARAM_3' => $email, 
46                                 'PARAM_4' => 0, 
47                                 'PARAM_5' => '',
48                                 'PARAM_6' => $def_orientation);
49                         break;
50                 case ST_CUSTDELIVERY :
51                         $rep = 110;
52                         // from, to, email, packing slip, comments, orientation
53                         $ar = array(
54                                 'PARAM_0' => $doc_no, 
55                                 'PARAM_1' => $doc_no, 
56                                 'PARAM_2' => $email,
57                                 'PARAM_3' => $extra,
58                                 'PARAM_4' => '',
59                                 'PARAM_5' => $def_orientation);
60                         break;
61                 case ST_SALESINVOICE : // Sales Invoice
62                 case ST_CUSTCREDIT : // Customer Credit Note
63                         $rep = $type_no==ST_CUSTCREDIT ? 113 : 107;
64                         // from, to, currency, email, paylink, comments, orientation
65                         $ar = array(
66                                 'PARAM_0' => $doc_no, 
67                                 'PARAM_1' => $doc_no, 
68                                 'PARAM_2' => '', 
69                                 'PARAM_3' => $email, 
70                                 'PARAM_4' => '',
71                                 'PARAM_5' => '', 
72                                 'PARAM_6' => $def_orientation);
73                         break;
74                 case ST_PURCHORDER :
75                         $rep = 209;
76                         // from, to, currency, email, comments, orientation
77                         $ar = array(
78                                 'PARAM_0' => $doc_no, 
79                                 'PARAM_1' => $doc_no, 
80                                 'PARAM_2' => '', 
81                                 'PARAM_3' => $email, 
82                                 'PARAM_4' => '',
83                                 'PARAM_5' => $def_orientation);
84                         break;
85                 case ST_CUSTPAYMENT :
86                         $rep = 112;
87                         // from, to, currency, email, comments, orientation
88                         $ar = array(
89                                 'PARAM_0' => $doc_no, 
90                                 'PARAM_1' => $doc_no, 
91                                 'PARAM_2' => '', 
92                                 'PARAM_3' => '', 
93                                 'PARAM_4' => $def_orientation);
94                         break;
95                 case ST_SUPPAYMENT :
96                         $rep = 210;
97                         // from, to, currency, email, comments, orientation
98                         $ar = array(
99                                 'PARAM_0' => $doc_no, 
100                                 'PARAM_1' => $doc_no, 
101                                 'PARAM_2' => '', 
102                                 'PARAM_3' => $email, 
103                                 'PARAM_4' => '',
104                                 'PARAM_5' => $def_orientation);
105                         break;
106                 case ST_WORKORDER :
107                         $rep = 409;
108                         // from, to, email, comments, orientation
109                         $ar = array(
110                                 'PARAM_0' => $doc_no, 
111                                 'PARAM_1' => $doc_no, 
112                                 'PARAM_2' => $email, 
113                                 'PARAM_3' => '', 
114                                 'PARAM_4' => $def_orientation);
115                         break;
116 //              default: $ar = array();
117         }
118         
119         return print_link($link_text, $rep, $ar, "", $icon, $class, $id);
120 }
121 //
122 //      Universal link to any kind of report.
123 //
124 function print_link($link_text, $rep, $pars = array(), $dir = '', 
125         $icon=false, $class='printlink', $id='')
126 {
127         global $path_to_root, $pdf_debug;
128
129         $url = $dir == '' ?  $path_to_root.'/reporting/prn_redirect.php?' : $dir;
130
131         $id = default_focus($id);
132         foreach($pars as $par => $val) {
133                 $pars[$par] = "$par=".urlencode($val);
134         }
135         $pars[] = 'REP_ID='.urlencode($rep);
136         $url .= implode ('&', $pars);
137
138         if ($class != '')
139                 $class = $pdf_debug ? '' : " class='$class'";
140         if ($id != '')
141                 $id = " id='$id'";
142         $pars = access_string($link_text);
143         if (user_graphic_links() && $icon)
144                 $pars[0] = set_icon($icon, $pars[0]);
145         return "<a target='_blank' href='$url'$id$class $pars[1]>$pars[0]</a>";
146 }
147
148 ?>