Merging version 2.1 RC to main trunk.
[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, $icon=false)
18 {
19         global $path_to_root;
20         include_once($path_to_root . "/includes/types.inc");
21
22         $url = $path_to_root.'/reporting/prn_redirect.php?';
23
24         switch ($type_no)
25         {
26                 case systypes::sales_order() :
27                         $rep = 109;
28                         // from, to, currency, bank acc, email, quote, comments
29                         $ar = array(
30                                 'PARAM_0' => $doc_no, 
31                                 'PARAM_1' => $doc_no, 
32                                 'PARAM_2' => "", 
33                                 'PARAM_3' => get_first_bank_account(), 
34                                 'PARAM_4' => 0, 
35                                 'PARAM_5' => 0, 
36                                 'PARAM_6' => "");
37                         break;
38                 case systypes::cust_dispatch() :
39                         $rep = 110;
40                         // from, to, email, comments
41                         $ar = array(
42                                 'PARAM_0' => $doc_no, 
43                                 'PARAM_1' => $doc_no, 
44                                 'PARAM_2' => 0, 
45                                 'PARAM_3' => "");
46                         break;
47                 case 10 : // Sales Invoice
48                 case 11 : // Customer Credit Note
49                         $rep = 107;
50                         // from, to, currency, bank acc, email, paylink, comments, type
51                         $ar = array(
52                                 'PARAM_0' => $doc_no, 
53                                 'PARAM_1' => $doc_no, 
54                                 'PARAM_2' => "", 
55                                 'PARAM_3' => get_first_bank_account(), 
56                                 'PARAM_4' => 0, 
57                                 'PARAM_5' => "",
58                                 'PARAM_6' => "", 
59                                 'PARAM_7' => $type_no);
60                         break;
61                 case systypes::po() :
62                         $rep = 209;
63                         // from, to, currency, bank acc, email, comments
64                         $ar = array(
65                                 'PARAM_0' => $doc_no, 
66                                 'PARAM_1' => $doc_no, 
67                                 'PARAM_2' => "", 
68                                 'PARAM_3' => get_first_bank_account(), 
69                                 'PARAM_4' => 0, 
70                                 'PARAM_5' => "");
71                         break;
72 //              default: $ar = array();
73         }
74         
75         return print_link($link_text, $rep, $ar, "", $icon);
76 }
77 //
78 //      Universal link to any kind of report.
79 //
80 function print_link($link_text, $rep, $pars = array(), $dir = '', $icon=false)
81 {
82         global $path_to_root, $pdf_debug;
83
84         $url = $dir == '' ?  $path_to_root.'/reporting/prn_redirect.php?' : $dir;
85
86         foreach($pars as $par => $val) {
87                 $pars[$par] = "$par=".urlencode($val);
88         }
89         $pars[] = 'REP_ID='.urlencode($rep);
90         $url .= implode ('&', $pars);
91         $class = $pdf_debug ? '' : "class='printlink'";
92         $pars = access_string($link_text);
93         if (user_graphic_links() && $icon)
94                 $pars[0] = set_icon($icon, $pars[0]);
95         return "<a $class target='_blank' href='$url'$pars[1]>$pars[0]</a>";
96 }
97
98 function get_first_bank_account()
99 {
100         $sql = "SELECT ".TB_PREF."bank_accounts.id FROM ".TB_PREF."bank_accounts, ".TB_PREF."company
101                 WHERE bank_curr_code=curr_default LIMIT 0, 1";
102         $result = db_query($sql);
103         $row = db_fetch_row($result);
104         return $row[0];
105 }
106 ?>