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 ***********************************************************************/
15 var $ctrl_handlers = array();
17 function ReportClasses()
19 $this->ar_classes = array();
22 function addReportClass($class_name)
24 $this->ar_classes[$class_name] = array();
27 function addReport($class_name, $id, $rep_name, $params=null)
29 unset($this->ar_classes[$class_name][$id]); // unset std report if any
30 $this->ar_classes[$class_name][$id] = new Report($id, $rep_name, $params);
33 function getDisplay($class=null)
35 global $table_style2, $comp_path, $path_to_root, $pdf_debug, $Ajax;
38 $temp = array_values($this->ar_classes);
39 $display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
44 $st_classes = "<b>" . _("Report Classes:") . "</b><br>";
45 foreach($this->ar_classes as $key=>$value)
47 $style = $class_counter==$_REQUEST['Class'] ? '' : "style='display:none'";
48 $acc = access_string($key);
49 $st_classes .= "<a href='"
50 .$_SERVER['PHP_SELF']."?Class=$class_counter'"
51 ." class='menu_option' id='".default_focus()."'"
52 ." onclick='return showClass($class_counter);'$acc[1]>$acc[0]</a> <br>";
53 $st_reports .= "<table id='TAB_" . $class_counter ."' $style cellpadding=0 cellspacing=0 border=0 width='100%'><tr><td><b>" . _("Reports For Class: ") . " $key</b></td></tr>\n";
54 foreach($value as $report)
56 $acc = access_string($report->name);
57 $st_reports .= "<tr><td><a class='printlink' href='"
58 .$_SERVER['PHP_SELF']."?Class=$class_counter&rep_id=$report->id'"
59 ." id='".default_focus()."'"
60 ."$acc[1]>$acc[0]</a><tr><td>\n";
61 if (isset($_REQUEST['rep_id']) && $_REQUEST['rep_id']==$report->id) {
63 $action = $path_to_root.'/reporting/prn_redirect.php';
65 $st_params = "<table border=0><tr><td>\n"
66 . "<form method='POST' action='$action' target='_blank'>\n";
67 $st_params .= submit('Rep'.$report->id,
68 _("Display: ") . access_string($report->name, true),
69 false, '', $pdf_debug ? false : 'default') . hidden('REP_ID', $report->id, false).'<br><br>';
70 $st_params .= $this->getOptions($report->get_controls());
71 $st_params .= "\n</form></td></tr></table>\n";
72 set_focus('Rep'.$report->id);
73 $Ajax->addUpdate(true, 'rep_form', $st_params);
76 $st_reports .= "</table>";
80 $st_params = "<div id='rep_form'>".
84 $st = "<script language='javascript'>
85 function showClass(pClass) {
86 for(i=0; i<$class_counter; i++) {
87 document.getElementById(\"TAB_\" + i).style.display=
88 i==pClass ? \"block\" : \"none\";
90 document.getElementById('rep_form').innerHTML = '';
91 // document.getElementById('rep_form').style.display = 'none';
94 function checkDate(pObj) {
95 var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
96 if (re.test(pObj.value)==false) {
97 alert('" . _("Invalid date format") . "')
102 $st .= "<table align='center' width='80%' $table_style2><tr valign='top'>";
103 $st .= "<td width='30%'>$st_classes</td>";
104 $st .= "<td width='35%'>$st_reports</td>";
105 $st .= "<td width='35%'>$st_params</td>";
106 $st .= "</tr></table><br>";
111 function getOptions($controls)
114 if ($controls == null)
118 foreach($controls as $title => $type)
121 foreach($this->ctrl_handlers as $fun) { // first check for non-standard controls
122 $ctrl = $fun('PARAM_'.$cnt, $type);
126 $ctrl = $this->get_ctrl('PARAM_'.$cnt, $type);
129 $st .= $title . ':<br>';
133 display_error(_('Unknown report parameter type:').$type);
141 // Register additional control handler
142 // $handle - name of global function f($name, $type) returning html code for control
143 function register_controls($handler) {
144 $this->ctrl_handlers[] = $handler;
147 // Returns html code for input control $name of type $type
149 function get_ctrl($name, $type)
151 global $path_to_root, $use_date_picker, $pdf_debug, $print_invoice_no;
157 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) AS name FROM ".TB_PREF."currencies";
158 return combo_input($name, '', $sql, 'curr_abrev', 'name',array('spec_option'=>_("No Currency Filter"),'spec_id'=>ALL_TEXT,'order'=>false));
167 if ($type == 'DATEBEGIN')
168 $date = begin_fiscalyear();
169 elseif ($type == 'DATEEND')
170 $date = end_fiscalyear();
173 if ($type == 'DATEBEGINM')
174 $date = begin_month($date);
175 elseif ($type == 'DATEENDM')
176 $date = end_month($date);
177 elseif ($type == 'DATEBEGINTAX' || $type == 'DATEENDTAX')
179 $row = get_company_prefs();
180 $edate = add_months($date, -$row['tax_last']);
181 $edate = end_month($edate);
182 if ($type == 'DATEENDTAX')
186 $bdate = begin_month($edate);
187 $bdate = add_months($bdate, -$row['tax_prd'] + 1);
192 $st = "<input type='text' name='$name' value='$date'>";
193 if ($use_date_picker)
194 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
195 . " <img src='$path_to_root/themes/default/images/cal.gif' width='16' height='16' border='0' alt='"._('Click Here to Pick up the date')."'></a>\n";
200 return yesno_list($name);
203 $sel = array(_("No payment Link"), "PayPal");
204 return array_selector($name, null, $sel);
207 $sel = array(_("PDF/Printer"), "Excel");
208 return array_selector($name, null, $sel);
211 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
212 return array_selector($name, null, $sel);
215 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"),
216 _("Dots"), _("Lines"), _("Pie"), _("Donut"));
217 return array_selector($name, null, $sel);
220 return gl_systypes_list($name, null, _("No Type Filter"));
222 case 'SYS_TYPES_ALL':
223 return systypes_list($name, null, _("No Type Filter"));
226 return "<input type='text' name='$name'>";
229 return "<textarea rows=4 cols=30 name='$name'></textarea>";
231 case 'ACCOUNTS': // not used
232 // $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
233 // return combo_input($name, '', $sql, 'id', 'name',array('spec_option'=>_("No Account Group Filter"),'spec_id'=>ALL_NUMERIC));
234 return gl_account_types_list($name, null, _("No Account Group Filter"), true);
236 case 'ACCOUNTS_NO_FILTER': // not used
237 return gl_account_types_list($name);
240 return gl_all_accounts_list($name);
242 case 'BANK_ACCOUNTS':
243 return bank_accounts_list($name);
246 return dimensions_list($name, null, false, ' ', false, true, 0);
249 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 0);
252 return dimensions_list($name, null, false, ' ', false, true, 1);
255 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 1);
258 return dimensions_list($name, null, false, ' ', false, true, 2);
261 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 2);
263 case 'CUSTOMERS_NO_FILTER':
265 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master";
266 if ($type == 'CUSTOMERS_NO_FILTER')
267 return combo_input($name, '', $sql, 'debtor_no', 'name',array('spec_option'=>_("No Customer Filter"),'spec_id'=>ALL_NUMERIC));
268 // FIX allitems numeric!
269 // return customer_list($name, null, _("No Customer Filter"));
271 return combo_input($name, '', $sql, 'debtor_no', 'name', null);
272 // return customer_list($name);
274 case 'SUPPLIERS_NO_FILTER':
276 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers";
277 if ($type == 'SUPPLIERS_NO_FILTER')
278 return combo_input($name, '', $sql, 'supplier_id', 'supp_name',array('spec_option'=>_("No Supplier Filter"),'spec_id'=>ALL_NUMERIC));
279 // FIX allitems numeric!
280 // return supplier_list($name, null, _("No Supplier Filter"));
282 return combo_input($name, '', $sql, 'supplier_id', 'supp_name', null);
283 // return supplier_list($name);
288 $ref = ($print_invoice_no == 1 ? "trans_no" : "reference");
289 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
290 ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.$ref, if (type=".ST_SALESINVOICE.", ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
291 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=".ST_SALESINVOICE." OR type=".ST_CUSTCREDIT.") AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
292 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
297 concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
298 ".TB_PREF."debtors_master.name) as IName
299 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
300 WHERE type=".ST_CUSTDELIVERY." AND ".TB_PREF."debtors_master.debtor_no=".
301 TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
302 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
305 $ref = ($print_invoice_no == 1 ? "order_no" : "reference");
306 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.$ref, '-',
307 ".TB_PREF."debtors_master.name) as IName
308 FROM ".TB_PREF."debtors_master, ".TB_PREF."sales_orders WHERE ".TB_PREF."debtors_master.debtor_no=".TB_PREF."sales_orders.debtor_no
309 AND ".TB_PREF."sales_orders.trans_type=".ST_SALESORDER." ORDER BY ".TB_PREF."sales_orders.order_no DESC";
310 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
313 $ref = ($print_invoice_no == 1 ? "order_no" : "reference");
314 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.$ref, '-',
315 ".TB_PREF."debtors_master.name) as IName
316 FROM ".TB_PREF."debtors_master, ".TB_PREF."sales_orders WHERE ".TB_PREF."debtors_master.debtor_no=".TB_PREF."sales_orders.debtor_no
317 AND ".TB_PREF."sales_orders.trans_type=".ST_SALESQUOTE." ORDER BY ".TB_PREF."sales_orders.order_no DESC";
318 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
321 $ref = ($print_invoice_no == 1 ? "order_no" : "reference");
322 $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.$ref, '-',
323 ".TB_PREF."suppliers.supp_name) as IName
324 FROM ".TB_PREF."suppliers, ".TB_PREF."purch_orders WHERE ".TB_PREF."suppliers.supplier_id=".TB_PREF."purch_orders.supplier_id ORDER BY ".TB_PREF."purch_orders.order_no DESC";
325 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
331 $ref = ($print_invoice_no == 1 ? "trans_no" : "reference");
332 $sql = "SELECT concat(".TB_PREF."supp_trans.trans_no, '-',
333 ".TB_PREF."supp_trans.type) AS TNO, concat(".TB_PREF."supp_trans.$ref, if (type=".ST_BANKPAYMENT.", ' $BP ', if (type=".ST_SUPPAYMENT.", ' $SP ', ' $CN ')), ".TB_PREF."suppliers.supp_name) as IName
334 FROM ".TB_PREF."suppliers, ".TB_PREF."supp_trans WHERE (type=".ST_BANKPAYMENT." OR type=".ST_SUPPAYMENT." OR type=".ST_SUPPCREDIT.") AND ".TB_PREF."suppliers.supplier_id=".TB_PREF."supp_trans.supplier_id ORDER BY ".TB_PREF."supp_trans.trans_no DESC";
335 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
341 $ref = ($print_invoice_no == 1 ? "trans_no" : "reference");
342 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
343 ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.$ref, if (type=".ST_BANKDEPOSIT.", ' $BD ', if (type=".ST_CUSTPAYMENT.", ' $CP ', ' $CN ')), ".TB_PREF."debtors_master.name) as IName
344 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=".ST_BANKDEPOSIT." OR type=".ST_CUSTPAYMENT." OR type=".ST_CUSTCREDIT.") AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
345 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
348 return stock_manufactured_items_list($name);
351 $sql = "SELECT ".TB_PREF."workorders.id, concat(".TB_PREF."workorders.id, '-',
352 ".TB_PREF."stock_master.description) as IName
353 FROM ".TB_PREF."stock_master, ".TB_PREF."workorders WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id ORDER BY ".TB_PREF."workorders.id DESC";
354 return combo_input($name, '', $sql, 'id', 'IName',array('order'=>false));
357 return locations_list($name, null, _("No Location Filter"));
360 return stock_categories_list($name, null, _("No Category Filter"));
363 return sales_types_list($name);
366 return sales_areas_list($name);
369 return sales_persons_list($name, null, _("No Sales Folk Filter"));
372 return fiscalyears_list($name);
375 $sql = "SELECT id, user_id FROM ".TB_PREF."users";
376 return combo_input($name, '', $sql, 'id', 'user_id',array('spec_option'=>_("No Users Filter"),'spec_id'=>ALL_NUMERIC));
379 case 'DIMENSIONTAGS':
380 if ($type == 'ACCOUNTTAGS')
381 $tag_type = TAG_ACCOUNT;
383 $tag_type = TAG_DIMENSION;
384 return tag_list($name, 5, $tag_type, true, _("No tags"));
398 function Report($id, $name, $ar_params = null)
402 if ($ar_params) $this->set_controls($ar_params);
405 function set_controls($ar_params) {
406 $this->controls = $ar_params;
409 function get_controls() {
410 return $this->controls;
415 //------------------------------------------------------------------------------------------------
416 function gl_systypes_list($name, $value=null, $spec_opt=false)
418 global $systypes_array;
420 $types = $systypes_array;
422 foreach(array(ST_LOCTRANSFER, ST_PURCHORDER, ST_SUPPRECEIVE, ST_MANUISSUE,
423 ST_MANURECEIVE, ST_SALESORDER, ST_SALESQUOTE, ST_DIMENSION) as $type)
424 unset($types[$type]);
426 return array_selector($name, $value, $types,
428 'spec_option'=> $spec_opt,
429 'spec_id' => ALL_NUMERIC,
435 function add_custom_reports(&$reports)
437 global $installed_extensions, $path_to_root, $comp_path;
439 // include reports installed inside extension modules
440 if (count($installed_extensions) > 0)
442 $extensions = $installed_extensions;
443 foreach ($extensions as $ext)
444 if (($ext['active'] && $ext['type'] == 'module')) {
445 $file = $path_to_root.'/'.$ext['path']."/reporting/reports_custom.php";
446 if (file_exists($file))
450 $file = $comp_path.'/'.user_company()."/reporting/reports_custom.php";
451 if (file_exists($file))