Rerun Feature 5388: Print Invoices (documents) list gets too long. Fixed by default...
[fa-stable.git] / reporting / includes / reports_classes.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
13 // Standard report classess
14 define('RC_CUSTOMER', 0);
15 define('RC_SUPPLIER', 1);
16 define('RC_INVENTORY', 2);
17 define('RC_MANUFACTURE', 3);
18 define('RC_DIMENSIONS', 4);
19 define('RC_BANKING', 5);
20 define('RC_GL', 6);
21 define('RC_FIXEDASSETS', 7);
22
23 class BoxReports
24 {
25         var $ar_classes; // report class names
26         var $ar_reports;
27         var $ctrl_handlers = array();
28
29         function __construct()
30         {
31                 $this->ar_classes = array();
32         }
33
34         function addReportClass($class_name, $class_id=null)
35         {
36                 if (!$class_id)
37                         $class_id = count_array($this->ar_classes);
38                 $this->ar_classes[$class_id] = $class_name;
39
40                 return $class_id;
41         }
42
43         function addReport($class, $id, $rep_name, $params=null)
44         {
45                 unset($this->ar_reports[$class][$id]); // unset std report if any
46                 $this->ar_reports[$class][$id] = new Report($id, $rep_name, $params);
47         }
48
49         function getDisplay($class=null)
50         {
51                 global $path_to_root, $SysPrefs, $Ajax;
52
53                 if (find_submit('Rep') != -1) {
54                         include($path_to_root.'/reporting/prn_redirect.php');
55                         return;
56                 }
57
58                 $temp = array_values($this->ar_classes);
59                 $display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
60                 $st_reports = "";
61                 $st_params = "";
62                 $st_classes = "<b>" . _("Report Classes:") . "</b><br>";
63
64                 if (isset($_GET['Class']))
65                         set_focus('class'.$_GET['Class']);
66
67                 $cur_class = $_REQUEST['Class'];
68
69                 foreach($this->ar_classes as $class_id => $name)
70                 {
71                         if (!isset($this->ar_reports[$class_id]))
72                                 continue; // e.g. no dimensions
73
74                         $acc = access_string($name);
75                         $st_classes .= "<a href='"
76                                 .$_SERVER['PHP_SELF']."?Class=$class_id'"
77                                 ." style='font-weight:". ($cur_class == $class_id ? 'bold' : 'normal')."'"
78                                 ." class='repclass_link' id='".'class'.$class_id."'"
79                                 ."$acc[1]>$acc[0]</a> <br>";
80
81                         $style = $class_id==$cur_class ? '' : "style='display:none'";
82                         $st_reports .= "<table class='repclass' id='TAB_" . $class_id ."' $style cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td><b>" . _("Reports For Class: ") . "&nbsp;$name</b></td></tr>\n";
83                         foreach($this->ar_reports[$class_id] as $rep_id => $report)
84                         {
85                                 $acc = access_string($report->name);
86                                 $st_reports .= "<tr><td><a class='repopts_link'"
87                                         ." href='".$_SERVER['PHP_SELF']."?Class=$class_id&REP_ID=$report->id'"
88                                         ." style='font-weight:". (@$_REQUEST['REP_ID'] == $report->id ? 'bold' : 'normal')."'"
89                                         ." id='".$id = default_focus()."'"
90                                         ."$acc[1]>$acc[0]</a><tr><td>\n";
91
92                                 if (@$_REQUEST['REP_ID'] == $report->id) {
93                                         $Ajax->activate($id);
94                                 }
95
96                                 if (isset($_REQUEST['REP_ID']) && $_REQUEST['REP_ID']==$report->id) {
97                                         // parameters form
98                                         $action = $_SERVER['PHP_SELF'];
99                                         $st_params = "<table><tr><td>\n"
100                                                 . "<form method='POST' action='$action' target='_blank'>\n";
101                                         $st_params .= submit('Rep'.$report->id,  
102                                                 _("Display: ") . access_string($report->name, true),
103                                                 false, '', $SysPrefs->pdf_debug ? false : 'default popup') . hidden('REP_ID', $report->id, false).'<br><br>';
104                                         $st_params .= $this->getOptions($report->get_controls(), $report->id);
105                                         $st_params .= "\n<input type=hidden name='Class' value=".$cur_class.">"
106                                                 ."\n</form></td></tr></table>\n";
107                                         set_focus('Rep'.$report->id);
108                                         $Ajax->addUpdate(true, 'rep_form', $st_params);
109                                 }
110                         }
111                         $st_reports .= "</table>";
112                 }
113
114                 $st_params = "<div id='rep_form'>".
115                         "$st_params</div>";
116                 
117                 $st = "<table align='center' width='80%' style='border:1px solid #cccccc;'><tr valign='top'>";
118                 $st .= "<td width='30%'>$st_classes</td>";
119                 $st .= "<td width='35%' style='border-left:1px solid #cccccc;border-right:1px solid #cccccc;padding-left:3px;'>$st_reports</td>";
120                 $st .= "<td width='35%'>$st_params</td>";
121                 $st .= "</tr></table><br>";
122
123                 return $st;
124         }
125
126         function getOptions($controls, $id = 0)
127         {
128                 $st = '';
129                 if ($controls == null)
130                         return "";
131
132                 $cnt = 0;
133                 foreach($controls as $title => $type)
134                 {
135                         $ctrl = '';
136                         foreach($this->ctrl_handlers as $fun) { // first check for non-standard controls
137                                 $ctrl = $fun('PARAM_'.$cnt, $type);
138                                 if ($ctrl) break;
139                         }
140                         if ($ctrl == '') {
141                                 if (($id == 102 || $id == 202) && $cnt == 3) // set default Show Also Allocated to Yes in aged reports 2014-09-19 Joe Hunt
142                                         $_POST['PARAM_'.$cnt] = 1;
143                                 
144                                 if (isset($_COOKIE['select'][$id][$cnt])) // saved parameters 2010-10-06 Joe Hunt
145                                         $_POST['PARAM_'.$cnt] = $_COOKIE['select'][$id][$cnt];
146                                 $ctrl = $this->get_ctrl('PARAM_'.$cnt, $type);
147                         }
148                         if ($ctrl != '')  {
149                                 $st .= $title . ':<br>';
150                                 $st .= $ctrl;
151                                 $st .= "<br><br>";
152                         } else {
153                                 display_error(_('Unknown report parameter type:').$type);
154                         }
155                         $cnt++;
156                 }
157                 return $st;
158         }
159
160         //
161         //      Register additional control handler
162         // $handle - name of global function f($name, $type) returning html code for control
163         function register_controls($handler) {
164                 $this->ctrl_handlers[] = $handler;
165         }
166         //
167         //      Returns html code for input control $name of type $type 
168         //
169         function get_ctrl($name, $type)
170         {
171                 global $path_to_root, $SysPrefs,
172                         $type_shortcuts;
173                 $day_range = get_company_pref("max_days_in_docs");
174                 if (!$day_range)
175                         $day_range = 180;
176                 $st = '';
177                         switch ($type)
178                         {
179                                 case 'CURRENCY':
180                                         $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) AS name FROM ".TB_PREF."currencies";
181                                         return combo_input($name, '', $sql, 'curr_abrev', 'name',array('spec_option'=>_("No Currency Filter"),'spec_id'=>ALL_TEXT,'order'=>false));
182
183                                 case 'DATE':
184                                 case 'DATEBEGIN':
185                                 case 'DATEEND':
186                                 case 'DATEBEGINM':
187                                 case 'DATEENDM':
188                                 case 'DATEBEGINTAX':
189                                 case 'DATEENDTAX':
190                                         if (!isset($_POST[$name]))
191                                         {
192                                                 if ($type == 'DATEBEGIN')
193                                                         $date = begin_fiscalyear();
194                                                 elseif ($type == 'DATEEND')
195                                                         $date = end_fiscalyear();
196                                                 else
197                                                         $date = Today();
198                                                 if ($type == 'DATEBEGINM')
199                                                         $date = begin_month($date);
200                                                 elseif ($type == 'DATEENDM')
201                                                         $date = end_month($date);
202                                                 elseif ($type == 'DATEBEGINTAX' || $type == 'DATEENDTAX')
203                                                 {
204                                                         $row = get_company_prefs();
205                                                         $edate = add_months($date, -$row['tax_last']);
206                                                         $edate = end_month($edate);
207                                                         if ($type == 'DATEENDTAX')
208                                                                 $date = $edate;
209                                                         else
210                                                         {
211                                                                 $bdate = begin_month($edate);
212                                                                 $bdate = add_months($bdate, -$row['tax_prd'] + 1);
213                                                                 $date = $bdate;
214                                                         }
215                                                 }
216                                         }
217                                         else // saved parameters
218                                                 $date = $_POST[$name];
219                                         $st = "<input type='text' name='$name' value='$date'>";
220                                         if (user_use_date_picker())
221                                         {
222                                                 $calc_image = (file_exists("$path_to_root/themes/".user_theme()."/images/cal.gif")) ? 
223                                                         "$path_to_root/themes/".user_theme()."/images/cal.gif" : "$path_to_root/themes/default/images/cal.gif";
224                                                 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
225                                                 . "     <img src='$calc_image' style='vertical-align:middle;padding-bottom:4px;width:16px;height:16px;border:0;' alt='"._('Click Here to Pick up the date')."'></a>\n";
226                                         }       
227                                         return $st;
228                                         break;
229
230                                 case 'YES_NO':
231                                         return yesno_list($name);
232
233                                 case 'PAYMENT_LINK':
234                                         return payment_services($name, null);
235
236                                 case 'DESTINATION':
237                                         $sel = array(_("PDF/Printer"), "Excel");
238                                         $def = 0;
239                                         if (user_def_print_destination() == 1)
240                                                 $def = 1;
241                                         return array_selector($name, $def, $sel);
242
243                                 case 'ORIENTATION':
244                                         $sel = array(_("Portrait"), _("Landscape"));
245                                         $def = 0;
246                                         if (user_def_print_orientation() == 1)
247                                                 $def = 1;
248                                         return array_selector($name, $def, $sel);
249
250                                 case 'COMPARE':
251                                         $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
252                                         return array_selector($name, null, $sel);
253
254                                 case 'GRAPHIC':
255                                         $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), 
256                                                                 _("Dots"), _("Lines"), _("Pie"), _("Donut"));
257                                         return array_selector($name, null, $sel);
258
259                                 case 'SYS_TYPES':
260                                         return gl_systypes_list($name, null, _("No Type Filter"));
261
262                                 case 'SYS_TYPES_ALL':
263                                         return systypes_list($name, null, _("No Type Filter"));
264
265                                 case 'TEXT':
266                                         return "<input type='text' name='$name'>";
267
268                                 case 'TEXTBOX':
269                                         $value = (isset($_POST[$name]) ? $_POST[$name] : "");
270                                         return "<textarea rows=4 cols=30 maxlength=130 name='$name'>$value</textarea>";
271
272                                 case 'ACCOUNTS': // not used
273                                         return gl_account_types_list($name, null, _("No Account Group Filter"), true);
274
275                                 case 'ACCOUNTS_NO_FILTER': // not used
276                                         return gl_account_types_list($name);
277
278                                 case 'GL_ACCOUNTS':
279                                         return gl_all_accounts_list($name);
280
281                                 case 'BANK_ACCOUNTS_NO_FILTER':
282                                 case 'BANK_ACCOUNTS':
283                                         if ($type == 'BANK_ACCOUNTS_NO_FILTER')
284                                                 return bank_accounts_list($name, null, false, _("All"));
285                                         else
286                                                 return bank_accounts_list($name);
287
288                                 case 'DIMENSION':
289                                         return dimensions_list($name, null, false, ' ', false, true, 0);
290                                         
291                                 case 'DIMENSIONS':
292                                         return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 0);
293
294                                 case 'DIMENSION1':
295                                         return dimensions_list($name, null, false, ' ', false, true, 1);
296
297                                 case 'DIMENSIONS1':
298                                         return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 1);
299
300                                 case 'DIMENSION2':
301                                         return dimensions_list($name, null, false, ' ', false, true, 2);
302
303                                 case 'DIMENSIONS2':
304                                         return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 2);
305
306                                 case 'CUSTOMERS_NO_FILTER':
307                                 case 'CUSTOMERS':
308                                         if ($type == 'CUSTOMERS_NO_FILTER')
309                                                 return customer_list($name, null, _("No Customer Filter"));
310                                         else
311                                                 return customer_list($name);
312
313                                 case 'SUPPLIERS_NO_FILTER':
314                                 case 'SUPPLIERS':
315                                         if ($type == 'SUPPLIERS_NO_FILTER')
316                                                 return supplier_list($name, null, _("No Supplier Filter"));
317                                         else
318                                                 return supplier_list($name);
319
320                                 case 'INVOICE':
321                                         $IV = $type_shortcuts[ST_SALESINVOICE];
322                                         $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
323                                         $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
324                                                                 concat('$IV ', debtor_trans.$ref,' ', debtor.name) as IName
325                                                 FROM ".TB_PREF."debtors_master debtor,"
326                                                         .TB_PREF."debtor_trans debtor_trans LEFT JOIN ".TB_PREF."voided AS vd ON debtor_trans.type=vd.type AND
327                                                         debtor_trans.trans_no=vd.id
328                                                 WHERE debtor_trans.type=".ST_SALESINVOICE." AND debtor.debtor_no=debtor_trans.debtor_no AND ISNULL(vd.id)
329                                                 AND debtor_trans.tran_date > SUBDATE(CURRENT_DATE, INTERVAL $day_range DAY)
330                                                 ORDER BY debtor_trans.trans_no DESC";
331                                         return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
332
333                                 case 'CREDIT':
334                                         $CN = $type_shortcuts[ST_CUSTCREDIT];
335                                         $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
336                                         $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
337                                                                 concat('$CN ', debtor_trans.$ref,' ', debtor.name) as IName
338                                                 FROM ".TB_PREF."debtors_master debtor,"
339                                                         .TB_PREF."debtor_trans debtor_trans LEFT JOIN ".TB_PREF."voided AS vd ON debtor_trans.type=vd.type AND
340                                                         debtor_trans.trans_no=vd.id
341                                                 WHERE debtor_trans.type=".ST_CUSTCREDIT." AND debtor.debtor_no=debtor_trans.debtor_no AND ISNULL(vd.id)
342                                                 AND debtor_trans.tran_date > SUBDATE(CURRENT_DATE, INTERVAL $day_range DAY)
343                                                 ORDER BY debtor_trans.trans_no DESC";
344                                         return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
345
346                                 case 'DELIVERY':
347                                         $DN = $type_shortcuts[ST_CUSTDELIVERY];
348                                         $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
349                                                                 concat(debtor_trans.trans_no, ' $DN ', debtor.name) as IName
350                                                 FROM ".TB_PREF."debtors_master debtor,"
351                                                         .TB_PREF."debtor_trans debtor_trans LEFT JOIN ".TB_PREF."voided AS vd ON debtor_trans.type=vd.type AND
352                                                         debtor_trans.trans_no=vd.id
353                                                 WHERE debtor_trans.type=".ST_CUSTDELIVERY." AND debtor.debtor_no=debtor_trans.debtor_no AND ISNULL(vd.id)
354                                                 AND debtor_trans.tran_date > SUBDATE(CURRENT_DATE, INTERVAL $day_range DAY)
355                                                 ORDER BY debtor_trans.trans_no DESC";
356                                         return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
357
358                                 case 'ORDERS':
359                                         $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
360                                         $sql = "SELECT sorder.order_no, concat(sorder.$ref, '-', debtor.name) as IName
361                                                 FROM ".TB_PREF."debtors_master debtor,"
362                                                         .TB_PREF."sales_orders sorder
363                                                 WHERE debtor.debtor_no=sorder.debtor_no AND sorder.trans_type=".ST_SALESORDER." 
364                                                 AND sorder.ord_date > SUBDATE(CURRENT_DATE, INTERVAL $day_range DAY)
365                                                 ORDER BY sorder.order_no DESC";
366                                         return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
367
368                                 case 'QUOTATIONS':
369                                         $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
370                                         $sql = "SELECT sorder.order_no, concat(sorder.$ref, '-', debtor.name) as IName
371                                                 FROM ".TB_PREF."debtors_master debtor,"
372                                                         .TB_PREF."sales_orders sorder
373                                                 WHERE debtor.debtor_no=sorder.debtor_no AND sorder.trans_type=".ST_SALESQUOTE." 
374                                                 AND sorder.ord_date > SUBDATE(CURRENT_DATE, INTERVAL $day_range DAY)
375                                                 ORDER BY sorder.order_no DESC";
376                                         return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
377
378                                 case 'PO':
379                                         $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
380                                         $sql = "SELECT po.order_no, concat(po.$ref, '-', supplier.supp_name) as IName
381                                                 FROM ".TB_PREF."suppliers supplier,"
382                                                         .TB_PREF."purch_orders po
383                                                 WHERE supplier.supplier_id=po.supplier_id
384                                                 AND po.ord_date > SUBDATE(CURRENT_DATE, INTERVAL $day_range DAY)
385                                                 ORDER BY po.order_no DESC";
386                                         return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
387
388                                 case 'REMITTANCE':
389                                         $BP = $type_shortcuts[ST_BANKPAYMENT];
390                                         $SP = $type_shortcuts[ST_SUPPAYMENT];
391                                         $CN = $type_shortcuts[ST_SUPPCREDIT];
392                                         $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
393                                         $sql = "SELECT concat(trans.trans_no, '-',trans.type) AS TNO,
394                                                                 concat(trans.$ref, IF(trans.type=".ST_BANKPAYMENT.", ' $BP ', IF(trans.type=".ST_SUPPAYMENT.", ' $SP ', 
395                                                                 ' $CN ')),
396                                                                 supplier.supp_name) as IName
397                                                 FROM ".TB_PREF."suppliers supplier, "
398                                                         .TB_PREF."supp_trans trans  LEFT JOIN ".TB_PREF."voided AS vd ON trans.type=vd.type AND trans.trans_no=vd.id
399                                                 WHERE trans.type IN(".ST_BANKPAYMENT.",".ST_SUPPAYMENT.",".ST_SUPPCREDIT.") AND
400                                                         supplier.supplier_id=trans.supplier_id AND ISNULL(vd.id)
401                                                 AND trans.tran_date > SUBDATE(CURRENT_DATE, INTERVAL $day_range DAY)
402                                                 ORDER BY trans.trans_no DESC";
403                                         return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
404
405                                 case 'RECEIPT':
406                                         $BD = $type_shortcuts[ST_BANKDEPOSIT];
407                                         $CP = $type_shortcuts[ST_CUSTPAYMENT];
408                                         $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
409                                         $sql = "SELECT concat(trans.trans_no, '-', trans.type) AS TNO,
410                                                                 concat(trans.$ref, IF(trans.type=".ST_BANKDEPOSIT.", ' $BD ', ' $CP '), debtor.name) as IName
411                                                 FROM ".TB_PREF."debtors_master debtor,"
412                                                         .TB_PREF."debtor_trans trans LEFT JOIN ".TB_PREF."voided AS vd ON trans.type=vd.type AND trans.trans_no=vd.id
413                                                 WHERE trans.type IN(".ST_BANKDEPOSIT.",".ST_CUSTPAYMENT.",".ST_CUSTCREDIT.") AND
414                                                         debtor.debtor_no=trans.debtor_no AND ISNULL(vd.id)
415                                                 AND trans.tran_date > SUBDATE(CURRENT_DATE, INTERVAL $day_range DAY)
416                                                 ORDER BY trans.trans_no DESC";
417                                         return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
418
419                                 case 'ITEMS':
420                                         return stock_manufactured_items_list($name);
421
422                                 case 'ITEMS_ALL':
423                                         return stock_manufactured_items_list($name, null, true);
424
425                                 case 'ITEMS_P':
426                                         return stock_purchasable_items_list($name, null, true);
427                                 
428                                 case 'WORKORDER':
429                                         $sql = "SELECT wo.id, concat(wo.id, '-', item.description) as IName
430                                                 FROM ".TB_PREF."stock_master item,"
431                                                         .TB_PREF."workorders wo 
432                                                         LEFT JOIN ".TB_PREF."voided v ON wo.id=v.id and v.type=".ST_WORKORDER."
433                                                 WHERE ISNULL(v.id)
434                                                 AND item.stock_id=wo.stock_id
435                                                 ORDER BY wo.id DESC";
436                                         return combo_input($name, '', $sql, 'id', 'IName',array('order'=>false));
437
438                                 case 'LOCATIONS':
439                                         return  locations_list($name, null, _("No Location Filter"));
440                                 case 'FLOCATIONS':
441                                         return  locations_list($name, null, _("No Location Filter"), false, true);
442
443                                 case 'CATEGORIES':
444                                         return stock_categories_list($name, null, _("No Category Filter"));
445                                 case 'FCATEGORIES':
446                                         return stock_categories_list($name, null, _("No Category Filter"), false, true);
447                                 case 'FCLASS':
448                                         return fixed_asset_classes_list($name, null, _("No Class Filter"), false);
449                                 case 'SALESTYPES':
450                                         return sales_types_list($name);
451
452                                 case 'AREAS':
453                                         return sales_areas_list($name, null, _("No Areas Filter"));
454
455                                 case 'SALESMEN':
456                                         return sales_persons_list($name, null, _("No Sales Folk Filter"));
457                                         
458                                 case 'TRANS_YEARS':
459                                         return fiscalyears_list($name);
460
461                                 case 'USERS':
462                                         $sql = "SELECT id, user_id FROM ".TB_PREF."users";
463                                         return combo_input($name, '', $sql, 'id', 'user_id',array('spec_option'=>_("No Users Filter"),'spec_id'=>ALL_NUMERIC));
464
465                                 case 'ACCOUNTTAGS':
466                                 case 'DIMENSIONTAGS':
467                                         if ($type == 'ACCOUNTTAGS')
468                                                 $tag_type = TAG_ACCOUNT;
469                                         else
470                                                 $tag_type = TAG_DIMENSION;
471                                         return tag_list($name, 5, $tag_type, true);
472
473                         }
474                 return '';
475         }
476 }
477
478 class Report
479 {
480         var $id;
481         var $name;
482         var $ar_params;
483         var $controls;
484         
485         function __construct($id, $name, $ar_params = null)
486         {
487                 $this->id = $id;
488                 $this->name = $name;
489                 if ($ar_params) $this->set_controls($ar_params);
490         }
491         
492         function set_controls($ar_params) {
493                 $this->controls = $ar_params;
494         }
495         
496         function get_controls() {
497                 return $this->controls;
498         }
499         
500 }
501
502 //------------------------------------------------------------------------------------------------
503 function gl_systypes_list($name, $value=null, $spec_opt=false)
504 {
505         global $systypes_array;
506         
507         $types = $systypes_array;
508         
509         foreach(array(ST_LOCTRANSFER, ST_PURCHORDER, ST_SUPPRECEIVE, ST_MANUISSUE,
510                                 ST_MANURECEIVE, ST_SALESORDER, ST_SALESQUOTE, ST_DIMENSION) as $type)
511                 unset($types[$type]);
512
513         return array_selector($name, $value, $types, 
514                 array( 
515                         'spec_option'=> $spec_opt,
516                         'spec_id' => ALL_NUMERIC,
517                         'async' => false,
518                         )
519         );
520 }
521 /*
522         Add extension/custom reports to report manager.
523 */
524 function add_custom_reports(&$reports)
525 {
526         global $installed_extensions, $path_to_root;
527         
528         // include reports installed inside extension modules
529         if (count($installed_extensions) > 0)
530         {
531                 $extensions = $installed_extensions;
532                 foreach ($extensions as $ext)
533                         if (($ext['active'] && $ext['type'] == 'extension')) {
534                                 $file = $path_to_root.'/'.$ext['path']."/reporting/reports_custom.php";
535                                 if (file_exists($file)) {
536                                         set_ext_domain($ext['path']);
537                                         include_once($file);
538                                         set_ext_domain();
539                                 }
540                         }
541         }
542         $file = company_path()."/reporting/reports_custom.php";
543         if (file_exists($file))
544                 include_once($file);
545 }
546