php 8. cannot generate recurring invoices after upgrade to 2.4.12. Fixed.
[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, $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         $def_orientation = (user_def_print_orientation() == 1 ? 1 : 0);
25
26         switch ($type_no)
27         {
28                 case ST_SALESQUOTE :
29                         $rep = 111;
30                         // from, to, currency, email, comments, orientation
31                         $ar = array(
32                                 'PARAM_0' => $doc_no, 
33                                 'PARAM_1' => $doc_no, 
34                                 'PARAM_2' => '', 
35                                 'PARAM_3' => $email, 
36                                 'PARAM_4' => '',
37                                 'PARAM_5' => $def_orientation);
38                         break;
39                 case ST_SALESORDER :
40                         $rep = 109;
41                         // from, to, currency, email, quote, comments, orientation
42                         $ar = array(
43                                 'PARAM_0' => $doc_no, 
44                                 'PARAM_1' => $doc_no, 
45                                 'PARAM_2' => '', 
46                                 'PARAM_3' => $email, 
47                                 'PARAM_4' => 0, 
48                                 'PARAM_5' => '',
49                                 'PARAM_6' => $def_orientation);
50                         break;
51                 case ST_CUSTDELIVERY :
52                         $rep = 110;
53                         // from, to, email, packing slip, comments, orientation
54                         $ar = array(
55                                 'PARAM_0' => $doc_no, 
56                                 'PARAM_1' => $doc_no, 
57                                 'PARAM_2' => $email,
58                                 'PARAM_3' => $extra,
59                                 'PARAM_4' => '',
60                                 'PARAM_5' => $def_orientation);
61                         break;
62                 case ST_SALESINVOICE : // Sales Invoice
63                 case ST_CUSTCREDIT : // Customer Credit Note
64                         $rep = $type_no==ST_CUSTCREDIT ? 113 : 107;
65                         // from, to, currency, email, paylink, comments, orientation
66                         $ar = array(
67                                 'PARAM_0' => $doc_no, 
68                                 'PARAM_1' => $doc_no, 
69                                 'PARAM_2' => '', 
70                                 'PARAM_3' => $email, 
71                                 'PARAM_4' => '',
72                                 'PARAM_5' => '', 
73                                 'PARAM_6' => $rep == 107 ? '' : $def_orientation);
74                         if ($rep == 107)
75                                 $ar['PARAM_7'] = $def_orientation;
76                         break;
77                 case ST_PURCHORDER :
78                         $rep = 209;
79                         // from, to, currency, email, comments, orientation
80                         $ar = array(
81                                 'PARAM_0' => $doc_no, 
82                                 'PARAM_1' => $doc_no, 
83                                 'PARAM_2' => '', 
84                                 'PARAM_3' => $email, 
85                                 'PARAM_4' => '',
86                                 'PARAM_5' => $def_orientation);
87                         break;
88                 case ST_CUSTPAYMENT :
89                         $rep = 112;
90                         // from, to, currency, comments, orientation
91                         $ar = array(
92                                 'PARAM_0' => $doc_no, 
93                                 'PARAM_1' => $doc_no, 
94                                 'PARAM_2' => '', 
95                                 'PARAM_3' => $email,
96                                 'PARAM_4' => '',
97                                 'PARAM_5' => $def_orientation);
98                         break;
99                 case ST_SUPPAYMENT :
100                         $rep = 210;
101                         // from, to, currency, email, comments, orientation
102                         $ar = array(
103                                 'PARAM_0' => $doc_no, 
104                                 'PARAM_1' => $doc_no, 
105                                 'PARAM_2' => '', 
106                                 'PARAM_3' => $email, 
107                                 'PARAM_4' => '',
108                                 'PARAM_5' => $def_orientation);
109                         break;
110                 case ST_WORKORDER :
111                         $rep = 409;
112                         // from, to, email, comments, orientation
113                         $ar = array(
114                                 'PARAM_0' => $doc_no, 
115                                 'PARAM_1' => $doc_no, 
116                                 'PARAM_2' => $email, 
117                                 'PARAM_3' => '', 
118                                 'PARAM_4' => $def_orientation);
119                         break;
120                 case ST_DIMENSION :
121                         $rep = 501;
122                         // from, to, email, comments, orientation
123                         $ar = array(
124                                 'PARAM_0' => $doc_no, 
125                                 'PARAM_1' => $doc_no, 
126                                 'PARAM_2' => 1, 
127                                 'PARAM_3' => '', 
128                                 'PARAM_4' => $def_orientation);
129                         break;
130                 default:
131                         return null;
132         }
133
134         return print_link($link_text, $rep, $ar, "", $icon, $class, $id);
135 }
136 //
137 //      Universal link to any kind of report.
138 //
139 function print_link($link_text, $rep, $pars = array(), $dir = '', 
140         $icon=false, $class='printlink', $id='')
141 {
142         global $path_to_root, $SysPrefs;
143         $url = $dir == '' ?  $path_to_root.'/reporting/prn_redirect.php?' : $dir;
144
145         $id = default_focus($id);
146         $parm = array();
147         foreach($pars as $par => $val) {
148                 if ($val != "")
149                         $parm[] = "$par=".urlencode($val);
150         }
151         $parm[] = 'REP_ID='.urlencode($rep);
152         $url .= implode ('&', $parm);
153         if ($class != '')
154                 $class = $SysPrefs->pdf_debug ? '' : " class='$class'";
155         if ($id != '')
156                 $id = " id='$id'";
157         $pars = access_string($link_text);
158         if (user_graphic_links() && $icon)
159                 $pars[0] = set_icon($icon, $pars[0]);
160         return "<a target='_blank' href='$url'$id$class $pars[1]>$pars[0]</a>";
161 }
162
163 /*
164 // Purpose: Function to parse a string into parameters
165 // Release Date: 2014-12-26
166 // Author: ApMuthu <apmuthu@usa.net>
167 // Usage:
168 $str = "PPFrt#2000 CID#6378465 TaxEx#2345-038 abcde ertrgdert COD#4253 jdegtd PIN#6473654";
169 $p = parse_notes_params($str);
170 echo print_r($p, true);
171
172 An example of usage will be in the reporting/rep110.php file at near the end just before the last $rep-Font(); statement: 
173
174
175     $notes_params = parse_notes_params($branch['notes']);
176     if ($packing_slip == 0 && array_key_exists('CID', $notes_params)) {
177         $rep->NewLine(1);
178         $rep->TextCol(1, 7, "Old Customer# : " . $notes_params['CID'], - 2);
179     }
180 */
181
182 function parse_notes_params($str, $sep=" ", $delim="#") {
183     $str_params = explode($sep, $str);
184     $param_array=Array('notes' => '');
185     foreach ($str_params AS $str_param) {
186         $param_set=explode($delim, trim($str_param));
187         $key = (array_key_exists(0, $param_set) ? trim($param_set[0]) : '');
188         $val = (array_key_exists(1, $param_set) ? trim($param_set[1]) : '');
189         if (strlen($key) > 0 && strlen($val) > 0) {
190             $param_array[$key]=$val;
191         } else {
192             // stop at first missing parameter set
193             // break;
194             // Collect the rest into notes
195             $param_array['notes'] .= (" " .  $str_param);
196         }
197     }
198     $param_array['notes'] = trim($param_array['notes']);
199     return $param_array;
200 }
201