Stable merged into unstable again (due to failure on binary file during previous...
[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;
21         include_once($path_to_root . "/includes/types.inc");
22
23         $url = $path_to_root.'/reporting/prn_redirect.php?';
24
25         switch ($type_no)
26         {
27                 case ST_SALESQUOTE :
28                         $rep = 111;
29                         // from, to, currency, bank acc, email, quote, comments
30                         $ar = array(
31                                 'PARAM_0' => $doc_no, 
32                                 'PARAM_1' => $doc_no, 
33                                 'PARAM_2' => '', 
34                                 'PARAM_3' => $email, 
35                                 'PARAM_4' => '');
36                         break;
37                 case ST_SALESORDER :
38                         $rep = 109;
39                         // from, to, currency, bank acc, email, quote, comments
40                         $ar = array(
41                                 'PARAM_0' => $doc_no, 
42                                 'PARAM_1' => $doc_no, 
43                                 'PARAM_2' => '', 
44                                 'PARAM_3' => $email, 
45                                 'PARAM_4' => 0, 
46                                 'PARAM_5' => '');
47                         break;
48                 case ST_CUSTDELIVERY :
49                         $rep = 110;
50                         // from, to, email, comments
51                         $ar = array(
52                                 'PARAM_0' => $doc_no, 
53                                 'PARAM_1' => $doc_no, 
54                                 'PARAM_2' => $email,
55                                 'PARAM_3' => $extra);
56                         break;
57                 case ST_SALESINVOICE : // Sales Invoice
58                 case ST_CUSTCREDIT : // Customer Credit Note
59                         $rep = $type_no==ST_CUSTCREDIT ? 113 : 107;
60                         // from, to, currency, bank acc, email, paylink, comments, type
61                         $ar = array(
62                                 'PARAM_0' => $doc_no, 
63                                 'PARAM_1' => $doc_no, 
64                                 'PARAM_2' => '', 
65                                 'PARAM_3' => $email, 
66                                 'PARAM_4' => '',
67                                 'PARAM_5' => '', 
68                                 'PARAM_6' => $type_no);
69                         break;
70                 case ST_PURCHORDER :
71                         $rep = 209;
72                         // from, to, currency, bank acc, email, comments
73                         $ar = array(
74                                 'PARAM_0' => $doc_no, 
75                                 'PARAM_1' => $doc_no, 
76                                 'PARAM_2' => '', 
77                                 'PARAM_3' => $email, 
78                                 'PARAM_4' => '');
79                         break;
80                 case ST_CUSTPAYMENT :
81                         $rep = 112;
82                         // from, to, currency, bank acc, email, comments
83                         $ar = array(
84                                 'PARAM_0' => $doc_no, 
85                                 'PARAM_1' => $doc_no, 
86                                 'PARAM_2' => '', 
87                                 'PARAM_4' => '');
88                         break;
89                 case ST_SUPPAYMENT :
90                         $rep = 210;
91                         // from, to, currency, bank acc, email, comments
92                         $ar = array(
93                                 'PARAM_0' => $doc_no, 
94                                 'PARAM_1' => $doc_no, 
95                                 'PARAM_2' => '', 
96                                 'PARAM_3' => $email, 
97                                 'PARAM_4' => '');
98                         break;
99                 case ST_WORKORDER :
100                         $rep = 409;
101                         // from, to, currency, bank acc, email, comments
102                         $ar = array(
103                                 'PARAM_0' => $doc_no, 
104                                 'PARAM_1' => $doc_no, 
105                                 'PARAM_2' => $email, 
106                                 'PARAM_3' => '', 
107                                 'PARAM_4' => '');
108                         break;
109 //              default: $ar = array();
110         }
111         
112         return print_link($link_text, $rep, $ar, "", $icon, $class, $id);
113 }
114 //
115 //      Universal link to any kind of report.
116 //
117 function print_link($link_text, $rep, $pars = array(), $dir = '', 
118         $icon=false, $class='printlink', $id='')
119 {
120         global $path_to_root, $pdf_debug;
121
122         $url = $dir == '' ?  $path_to_root.'/reporting/prn_redirect.php?' : $dir;
123
124         $id = default_focus($id);
125         foreach($pars as $par => $val) {
126                 $pars[$par] = "$par=".urlencode($val);
127         }
128         $pars[] = 'REP_ID='.urlencode($rep);
129         $url .= implode ('&', $pars);
130
131         if ($class != '')
132                 $class = $pdf_debug ? '' : " class='$class'";
133         if ($id != '')
134                 $id = " id='$id'";
135         $pars = access_string($link_text);
136         if (user_graphic_links() && $icon)
137                 $pars[0] = set_icon($icon, $pars[0]);
138         return "<a target='_blank' href='$url'$id$class $pars[1]>$pars[0]</a>";
139 }
140
141 ?>