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 __construct()
31 $this->ar_classes = array();
34 function addReportClass($class_name, $class_id=null)
37 $class_id = count_array($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 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);
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,
173 $day_range = get_company_pref("max_days_in_docs");
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));
190 if (!isset($_POST[$name]))
192 if ($type == 'DATEBEGIN')
193 $date = begin_fiscalyear();
194 elseif ($type == 'DATEEND')
195 $date = end_fiscalyear();
198 if ($type == 'DATEBEGINM')
199 $date = begin_month($date);
200 elseif ($type == 'DATEENDM')
201 $date = end_month($date);
202 elseif ($type == 'DATEBEGINTAX' || $type == 'DATEENDTAX')
204 $row = get_company_prefs();
205 $edate = add_months($date, -$row['tax_last']);
206 $edate = end_month($edate);
207 if ($type == 'DATEENDTAX')
211 $bdate = begin_month($edate);
212 $bdate = add_months($bdate, -$row['tax_prd'] + 1);
217 else // saved parameters
218 $date = $_POST[$name];
219 $st = "<input type='text' name='$name' value='$date'>";
220 if (user_use_date_picker())
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";
231 return yesno_list($name);
234 return payment_services($name, null);
237 $sel = array(_("PDF/Printer"), "Excel");
239 if (user_def_print_destination() == 1)
241 return array_selector($name, $def, $sel);
244 $sel = array(_("Portrait"), _("Landscape"));
246 if (user_def_print_orientation() == 1)
248 return array_selector($name, $def, $sel);
251 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
252 return array_selector($name, null, $sel);
255 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"),
256 _("Dots"), _("Lines"), _("Pie"), _("Donut"), _("Half Donut"), _("Splines"));
257 return array_selector($name, null, $sel);
260 return gl_systypes_list($name, null, _("No Type Filter"));
262 case 'SYS_TYPES_ALL':
263 return systypes_list($name, null, _("No Type Filter"));
266 return "<input type='text' name='$name'>";
269 $value = (isset($_POST[$name]) ? $_POST[$name] : "");
270 return "<textarea rows=4 cols=30 maxlength=130 name='$name'>$value</textarea>";
272 case 'ACCOUNTS': // not used
273 return gl_account_types_list($name, null, _("No Account Group Filter"), true);
275 case 'ACCOUNTS_NO_FILTER': // not used
276 return gl_account_types_list($name);
279 return gl_all_accounts_list($name);
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"));
286 return bank_accounts_list($name);
289 return dimensions_list($name, null, false, ' ', false, true, 0);
292 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 0);
295 return dimensions_list($name, null, false, ' ', false, true, 1);
298 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 1);
301 return dimensions_list($name, null, false, ' ', false, true, 2);
304 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 2);
306 case 'CUSTOMERS_NO_FILTER':
308 if ($type == 'CUSTOMERS_NO_FILTER')
309 return customer_list($name, null, _("No Customer Filter"));
311 return customer_list($name);
313 case 'SUPPLIERS_NO_FILTER':
315 if ($type == 'SUPPLIERS_NO_FILTER')
316 return supplier_list($name, null, _("No Supplier Filter"));
318 return supplier_list($name);
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));
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));
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));
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));
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));
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));
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 ',
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));
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));
420 return stock_manufactured_items_list($name);
423 return stock_manufactured_items_list($name, null, true);
426 return stock_purchasable_items_list($name, null, true);
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."
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));
439 return locations_list($name, null, _("No Location Filter"));
441 return locations_list($name, null, _("No Location Filter"), false, true);
444 return stock_categories_list($name, null, _("No Category Filter"));
446 return stock_categories_list($name, null, _("No Category Filter"), false, true);
448 return fixed_asset_classes_list($name, null, _("No Class Filter"), false);
450 return sales_types_list($name);
453 return sales_areas_list($name, null, _("No Areas Filter"));
456 return sales_persons_list($name, null, _("No Sales Folk Filter"));
459 return fiscalyears_list($name);
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));
466 case 'DIMENSIONTAGS':
467 if ($type == 'ACCOUNTTAGS')
468 $tag_type = TAG_ACCOUNT;
470 $tag_type = TAG_DIMENSION;
471 return tag_list($name, 5, $tag_type, true);
485 function __construct($id, $name, $ar_params = null)
489 if ($ar_params) $this->set_controls($ar_params);
492 function set_controls($ar_params) {
493 $this->controls = $ar_params;
496 function get_controls() {
497 return $this->controls;
502 //------------------------------------------------------------------------------------------------
503 function gl_systypes_list($name, $value=null, $spec_opt=false)
505 global $systypes_array;
507 $types = $systypes_array;
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]);
513 return array_selector($name, $value, $types,
515 'spec_option'=> $spec_opt,
516 'spec_id' => ALL_NUMERIC,
522 Add extension/custom reports to report manager.
524 function add_custom_reports(&$reports)
526 global $installed_extensions, $path_to_root;
528 // include reports installed inside extension modules
529 if (count($installed_extensions) > 0)
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']);
542 $file = company_path()."/reporting/reports_custom.php";
543 if (file_exists($file))