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