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 ***********************************************************************/
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);
21 define('RC_FIXEDASSETS', 7);
25 var $ar_classes; // report class names
27 var $ctrl_handlers = array();
29 function ReportClasses()
31 $this->ar_classes = array();
34 function addReportClass($class_name, $class_id=null)
37 $class_id = count($this->ar_classes);
38 $this->ar_classes[$class_id] = $class_name;
43 function addReport($class, $id, $rep_name, $params=null)
45 unset($this->ar_reports[$class][$id]); // unset std report if any
46 $this->ar_reports[$class][$id] = new Report($id, $rep_name, $params);
49 function getDisplay($class=null)
51 global $path_to_root, $SysPrefs, $Ajax;
53 if (find_submit('Rep') != -1) {
54 include($path_to_root.'/reporting/prn_redirect.php');
58 $temp = array_values($this->ar_classes);
59 $display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
62 $st_classes = "<b>" . _("Report Classes:") . "</b><br>";
64 if (isset($_GET['Class']))
65 set_focus('class'.$_GET['Class']);
67 $cur_class = $_REQUEST['Class'];
69 foreach($this->ar_classes as $class_id => $name)
71 if (!isset($this->ar_reports[$class_id]))
72 continue; // e.g. no dimensions
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>";
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: ") . " $name</b></td></tr>\n";
83 foreach($this->ar_reports[$class_id] as $rep_id => $report)
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";
92 if (@$_REQUEST['REP_ID'] == $report->id) {
96 if (isset($_REQUEST['REP_ID']) && $_REQUEST['REP_ID']==$report->id) {
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 process') . 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);
111 $st_reports .= "</table>";
114 $st_params = "<div id='rep_form'>".
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>";
126 function getOptions($controls, $id = 0)
129 if ($controls == null)
133 foreach($controls as $title => $type)
136 foreach($this->ctrl_handlers as $fun) { // first check for non-standard controls
137 $ctrl = $fun('PARAM_'.$cnt, $type);
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;
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);
149 $st .= $title . ':<br>';
153 display_error(_('Unknown report parameter type:').$type);
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;
167 // Returns html code for input control $name of type $type
169 function get_ctrl($name, $type)
171 global $path_to_root, $SysPrefs,
178 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) AS name FROM ".TB_PREF."currencies";
179 return combo_input($name, '', $sql, 'curr_abrev', 'name',array('spec_option'=>_("No Currency Filter"),'spec_id'=>ALL_TEXT,'order'=>false));
188 if (!isset($_POST[$name]))
190 if ($type == 'DATEBEGIN')
191 $date = begin_fiscalyear();
192 elseif ($type == 'DATEEND')
193 $date = end_fiscalyear();
196 if ($type == 'DATEBEGINM')
197 $date = begin_month($date);
198 elseif ($type == 'DATEENDM')
199 $date = end_month($date);
200 elseif ($type == 'DATEBEGINTAX' || $type == 'DATEENDTAX')
202 $row = get_company_prefs();
203 $edate = add_months($date, -$row['tax_last']);
204 $edate = end_month($edate);
205 if ($type == 'DATEENDTAX')
209 $bdate = begin_month($edate);
210 $bdate = add_months($bdate, -$row['tax_prd'] + 1);
215 else // saved parameters
216 $date = $_POST[$name];
217 $st = "<input type='text' name='$name' value='$date'>";
218 if (user_use_date_picker())
220 $calc_image = (file_exists("$path_to_root/themes/".user_theme()."/images/cal.gif")) ?
221 "$path_to_root/themes/".user_theme()."/images/cal.gif" : "$path_to_root/themes/default/images/cal.gif";
222 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
223 . " <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";
229 return yesno_list($name);
232 return payment_services($name, null);
235 $sel = array(_("PDF/Printer"), "Excel");
237 if (user_def_print_destination() == 1)
239 return array_selector($name, $def, $sel);
242 $sel = array(_("Portrait"), _("Landscape"));
244 if (user_def_print_orientation() == 1)
246 return array_selector($name, $def, $sel);
249 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
250 return array_selector($name, null, $sel);
253 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"),
254 _("Dots"), _("Lines"), _("Pie"), _("Donut"));
255 return array_selector($name, null, $sel);
258 return gl_systypes_list($name, null, _("No Type Filter"));
260 case 'SYS_TYPES_ALL':
261 return systypes_list($name, null, _("No Type Filter"));
264 return "<input type='text' name='$name'>";
267 $value = (isset($_POST[$name]) ? $_POST[$name] : "");
268 return "<textarea rows=4 cols=30 maxlength=130 name='$name'>$value</textarea>";
270 case 'ACCOUNTS': // not used
271 return gl_account_types_list($name, null, _("No Account Group Filter"), true);
273 case 'ACCOUNTS_NO_FILTER': // not used
274 return gl_account_types_list($name);
277 return gl_all_accounts_list($name);
279 case 'BANK_ACCOUNTS':
280 return bank_accounts_list($name);
283 return dimensions_list($name, null, false, ' ', false, true, 0);
286 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 0);
289 return dimensions_list($name, null, false, ' ', false, true, 1);
292 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 1);
295 return dimensions_list($name, null, false, ' ', false, true, 2);
298 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 2);
300 case 'CUSTOMERS_NO_FILTER':
302 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master";
303 if ($type == 'CUSTOMERS_NO_FILTER')
304 return customer_list($name, null, _("No Customer Filter"));
306 return customer_list($name);
308 case 'SUPPLIERS_NO_FILTER':
310 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers";
311 if ($type == 'SUPPLIERS_NO_FILTER')
312 return supplier_list($name, null, _("No Supplier Filter"));
314 return supplier_list($name);
317 $IV = $type_shortcuts[ST_SALESINVOICE];
318 $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
319 $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
320 concat('$IV ', debtor_trans.$ref,' ', debtor.name) as IName
321 FROM ".TB_PREF."debtors_master debtor,"
322 .TB_PREF."debtor_trans debtor_trans
323 WHERE type=".ST_SALESINVOICE." AND debtor.debtor_no=debtor_trans.debtor_no
324 ORDER BY debtor_trans.trans_no DESC";
325 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
328 $CN = $type_shortcuts[ST_CUSTCREDIT];
329 $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
330 $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
331 concat('$CN ', debtor_trans.$ref,' ', debtor.name) as IName
332 FROM ".TB_PREF."debtors_master debtor,"
333 .TB_PREF."debtor_trans debtor_trans
334 WHERE type=".ST_CUSTCREDIT." AND debtor.debtor_no=debtor_trans.debtor_no
335 ORDER BY debtor_trans.trans_no DESC";
336 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
339 $DN = $type_shortcuts[ST_CUSTDELIVERY];
340 $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
341 concat(debtor_trans.trans_no, ' $DN ', debtor.name) as IName
342 FROM ".TB_PREF."debtors_master debtor,"
343 .TB_PREF."debtor_trans debtor_trans
344 WHERE type=".ST_CUSTDELIVERY." AND debtor.debtor_no=debtor_trans.debtor_no
345 ORDER BY debtor_trans.trans_no DESC";
346 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
349 $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
350 $sql = "SELECT sorder.order_no, concat(sorder.$ref, '-', debtor.name) as IName
351 FROM ".TB_PREF."debtors_master debtor,"
352 .TB_PREF."sales_orders sorder
353 WHERE debtor.debtor_no=sorder.debtor_no AND sorder.trans_type=".ST_SALESORDER
354 ." ORDER BY sorder.order_no DESC";
355 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
358 $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
359 $sql = "SELECT sorder.order_no, concat(sorder.$ref, '-', debtor.name) as IName
360 FROM ".TB_PREF."debtors_master debtor,"
361 .TB_PREF."sales_orders sorder
362 WHERE debtor.debtor_no=sorder.debtor_no AND sorder.trans_type=".ST_SALESQUOTE
363 ." ORDER BY sorder.order_no DESC";
364 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
367 $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
368 $sql = "SELECT po.order_no, concat(po.$ref, '-', supplier.supp_name) as IName
369 FROM ".TB_PREF."suppliers supplier,"
370 .TB_PREF."purch_orders po
371 WHERE supplier.supplier_id=po.supplier_id
372 ORDER BY po.order_no DESC";
373 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
376 $BP = $type_shortcuts[ST_BANKPAYMENT];
377 $SP = $type_shortcuts[ST_SUPPAYMENT];
378 $CN = $type_shortcuts[ST_SUPPCREDIT];
379 $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
380 $sql = "SELECT concat(trans.trans_no, '-',trans.type) AS TNO,
381 concat(trans.$ref, IF(type=".ST_BANKPAYMENT.", ' $BP ', IF(type=".ST_SUPPAYMENT.", ' $SP ', ' $CN ')), supplier.supp_name) as IName
382 FROM ".TB_PREF."suppliers supplier, "
383 .TB_PREF."supp_trans trans
384 WHERE type IN(".ST_BANKPAYMENT.",".ST_SUPPAYMENT.",".ST_SUPPCREDIT.")
385 AND supplier.supplier_id=trans.supplier_id
386 ORDER BY trans.trans_no DESC";
387 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
390 $BD = $type_shortcuts[ST_BANKDEPOSIT];
391 $CP = $type_shortcuts[ST_CUSTPAYMENT];
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(type=".ST_BANKDEPOSIT.", ' $BD ', ' $CP '), debtor.name) as IName
395 FROM ".TB_PREF."debtors_master debtor,"
396 .TB_PREF."debtor_trans trans
397 WHERE type IN(".ST_BANKDEPOSIT.",".ST_CUSTPAYMENT.",".ST_CUSTCREDIT.") AND debtor.debtor_no=trans.debtor_no
398 ORDER BY trans.trans_no DESC";
399 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
402 return stock_manufactured_items_list($name);
405 return stock_manufactured_items_list($name, null, true);
408 return stock_purchasable_items_list($name, null, true);
411 $sql = "SELECT wo.id, concat(wo.id, '-', item.description) as IName
412 FROM ".TB_PREF."stock_master item,"
413 .TB_PREF."workorders wo
414 WHERE item.stock_id=wo.stock_id
415 ORDER BY wo.id DESC";
416 return combo_input($name, '', $sql, 'id', 'IName',array('order'=>false));
419 return locations_list($name, null, _("No Location Filter"));
421 return locations_list($name, null, _("No Location Filter"), false, true);
424 return stock_categories_list($name, null, _("No Category Filter"));
426 return stock_categories_list($name, null, _("No Category Filter"), false, true);
428 return fixed_asset_classes_list($name, null, _("No Class Filter"), false);
430 return sales_types_list($name);
433 return sales_areas_list($name);
436 return sales_persons_list($name, null, _("No Sales Folk Filter"));
439 return fiscalyears_list($name);
442 $sql = "SELECT id, user_id FROM ".TB_PREF."users";
443 return combo_input($name, '', $sql, 'id', 'user_id',array('spec_option'=>_("No Users Filter"),'spec_id'=>ALL_NUMERIC));
446 case 'DIMENSIONTAGS':
447 if ($type == 'ACCOUNTTAGS')
448 $tag_type = TAG_ACCOUNT;
450 $tag_type = TAG_DIMENSION;
451 return tag_list($name, 5, $tag_type, true);
465 function Report($id, $name, $ar_params = null)
469 if ($ar_params) $this->set_controls($ar_params);
472 function set_controls($ar_params) {
473 $this->controls = $ar_params;
476 function get_controls() {
477 return $this->controls;
482 //------------------------------------------------------------------------------------------------
483 function gl_systypes_list($name, $value=null, $spec_opt=false)
485 global $systypes_array;
487 $types = $systypes_array;
489 foreach(array(ST_LOCTRANSFER, ST_PURCHORDER, ST_SUPPRECEIVE, ST_MANUISSUE,
490 ST_MANURECEIVE, ST_SALESORDER, ST_SALESQUOTE, ST_DIMENSION) as $type)
491 unset($types[$type]);
493 return array_selector($name, $value, $types,
495 'spec_option'=> $spec_opt,
496 'spec_id' => ALL_NUMERIC,
502 Add extension/custom reports to report manager.
504 function add_custom_reports(&$reports)
506 global $installed_extensions, $path_to_root;
508 // include reports installed inside extension modules
509 if (count($installed_extensions) > 0)
511 $extensions = $installed_extensions;
512 foreach ($extensions as $ext)
513 if (($ext['active'] && $ext['type'] == 'extension')) {
514 $file = $path_to_root.'/'.$ext['path']."/reporting/reports_custom.php";
515 if (file_exists($file)) {
516 set_ext_domain($ext['path']);
522 $file = company_path()."/reporting/reports_custom.php";
523 if (file_exists($file))