*** empty log message ***
[fa-stable.git] / reporting / includes / reporting.inc
1 <?php
2 // Link to printing single document with bulk report template file.
3 // Ex. label_cell(print_document_link($myrow['order_no'], _("Print")), $type);
4 // or display_note(print_document_link($order_no, _("Print this order")));
5 // You only need full parameter list for invoices/credit notes
6
7 function print_document_link($doc_no, $link_text, $link=true, $type_no)
8 {
9         global $path_to_root;
10         include_once($path_to_root . "/includes/types.inc");
11
12         $url = $path_to_root.'/reporting/prn_redirect.php?';
13
14         switch ($type_no)
15         {
16                 case systypes::sales_order() :
17                         $rep = 109;
18                         // from, to, currency, bank acc, email, quote, comments
19                         $ar = array(
20                                 'PARAM_0' => $doc_no, 
21                                 'PARAM_1' => $doc_no, 
22                                 'PARAM_2' => "", 
23                                 'PARAM_3' => get_first_bank_account(), 
24                                 'PARAM_4' => 0, 
25                                 'PARAM_5' => 0, 
26                                 'PARAM_6' => "");
27                         break;
28                 case systypes::cust_dispatch() :
29                         $rep = 110;
30                         // from, to, email, comments
31                         $ar = array(
32                                 'PARAM_0' => $doc_no, 
33                                 'PARAM_1' => $doc_no, 
34                                 'PARAM_2' => 0, 
35                                 'PARAM_3' => "");
36                         break;
37                 case 10 : // Sales Invoice
38                 case 11 : // Customer Credit Note
39                         $rep = 107;
40                         // from, to, currency, bank acc, email, paylink, comments, type
41                         $ar = array(
42                                 'PARAM_0' => $doc_no, 
43                                 'PARAM_1' => $doc_no, 
44                                 'PARAM_2' => "", 
45                                 'PARAM_3' => get_first_bank_account(), 
46                                 'PARAM_4' => 0, 
47                                 'PARAM_5' => "",
48                                 'PARAM_6' => "", 
49                                 'PARAM_7' => $type_no);
50                         break;
51                 case systypes::po() :
52                         $rep = 209;
53                         // from, to, currency, bank acc, email, comments
54                         $ar = array(
55                                 'PARAM_0' => $doc_no, 
56                                 'PARAM_1' => $doc_no, 
57                                 'PARAM_2' => "", 
58                                 'PARAM_3' => get_first_bank_account(), 
59                                 'PARAM_4' => 0, 
60                                 'PARAM_5' => "");
61                         break;
62 //              default: $ar = array();
63         }
64         
65         return print_link($link_text, $rep, $ar);
66 }
67 //
68 //      Universal link to any kind of report.
69 //
70 function print_link($link_text, $rep, $pars = array(), $dir = '')
71 {
72         global $path_to_root, $pdf_debug;
73
74         $url = $dir == '' ?  $path_to_root.'/reporting/prn_redirect.php?' : $dir;
75
76         foreach($pars as $par => $val) {
77                 $pars[$par] = "$par=".urlencode($val);
78         }
79         $pars[] = 'REP_ID='.urlencode($rep);
80         $url .= implode ('&', $pars);
81         $class = $pdf_debug ? '' : "class='printlink'";
82         $pars = access_string($link_text);
83         return "<a $class target='_blank' href='$url'$pars[1]>$pars[0]</a>";
84 }
85
86 function get_first_bank_account()
87 {
88         $sql = "SELECT ".TB_PREF."bank_accounts.id FROM ".TB_PREF."bank_accounts, ".TB_PREF."company
89                 WHERE bank_curr_code=curr_default LIMIT 0, 1";
90         $result = db_query($sql);
91         $row = db_fetch_row($result);
92         return $row[0];
93 }
94 ?>