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);
24 var $ar_classes; // report class names
26 var $ctrl_handlers = array();
28 function ReportClasses()
30 $this->ar_classes = array();
33 function addReportClass($class_name, $class_id=null)
36 $class_id = count($this->ar_classes);
37 $this->ar_classes[$class_id] = $class_name;
42 function addReport($class, $id, $rep_name, $params=null)
44 unset($this->ar_reports[$class][$id]); // unset std report if any
45 $this->ar_reports[$class][$id] = new Report($id, $rep_name, $params);
48 function getDisplay($class=null)
50 global $path_to_root, $SysPrefs, $Ajax;
52 if (find_submit('Rep') != -1) {
53 include($path_to_root.'/reporting/prn_redirect.php');
57 $temp = array_values($this->ar_classes);
58 $display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
61 $st_classes = "<b>" . _("Report Classes:") . "</b><br>";
63 if (isset($_GET['Class']))
64 set_focus('class'.$_GET['Class']);
66 $cur_class = $_REQUEST['Class'];
68 foreach($this->ar_classes as $class_id => $name)
70 if (!isset($this->ar_reports[$class_id]))
71 continue; // e.g. no dimensions
73 $acc = access_string($name);
74 $st_classes .= "<a href='"
75 .$_SERVER['PHP_SELF']."?Class=$class_id'"
76 ." style='font-weight:". ($cur_class == $class_id ? 'bold' : 'normal')."'"
77 ." class='repclass_link' id='".'class'.$class_id."'"
78 ."$acc[1]>$acc[0]</a> <br>";
80 $style = $class_id==$cur_class ? '' : "style='display:none'";
81 $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";
82 foreach($this->ar_reports[$class_id] as $rep_id => $report)
84 $acc = access_string($report->name);
85 $st_reports .= "<tr><td><a class='repopts_link'"
86 ." href='".$_SERVER['PHP_SELF']."?Class=$class_id&REP_ID=$report->id'"
87 ." style='font-weight:". (@$_REQUEST['REP_ID'] == $report->id ? 'bold' : 'normal')."'"
88 ." id='".$id = default_focus()."'"
89 ."$acc[1]>$acc[0]</a><tr><td>\n";
91 if (@$_REQUEST['REP_ID'] == $report->id) {
95 if (isset($_REQUEST['REP_ID']) && $_REQUEST['REP_ID']==$report->id) {
97 $action = $_SERVER['PHP_SELF'];
98 $st_params = "<table><tr><td>\n"
99 . "<form method='POST' action='$action' target='_blank'>\n";
100 $st_params .= submit('Rep'.$report->id,
101 _("Display: ") . access_string($report->name, true),
102 false, '', $SysPrefs->pdf_debug ? false : 'default process') . hidden('REP_ID', $report->id, false).'<br><br>';
103 $st_params .= $this->getOptions($report->get_controls(), $report->id);
104 $st_params .= "\n<input type=hidden name='Class' value=".$cur_class.">"
105 ."\n</form></td></tr></table>\n";
106 set_focus('Rep'.$report->id);
107 $Ajax->addUpdate(true, 'rep_form', $st_params);
110 $st_reports .= "</table>";
113 $st_params = "<div id='rep_form'>".
116 $st = "<table align='center' width='80%' style='border:1px solid #cccccc;'><tr valign='top'>";
117 $st .= "<td width='30%'>$st_classes</td>";
118 $st .= "<td width='35%' style='border-left:1px solid #cccccc;border-right:1px solid #cccccc;padding-left:3px;'>$st_reports</td>";
119 $st .= "<td width='35%'>$st_params</td>";
120 $st .= "</tr></table><br>";
125 function getOptions($controls, $id = 0)
128 if ($controls == null)
132 foreach($controls as $title => $type)
135 foreach($this->ctrl_handlers as $fun) { // first check for non-standard controls
136 $ctrl = $fun('PARAM_'.$cnt, $type);
140 if (($id == 102 || $id == 202) && $cnt == 3) // set default Show Also Allocated to Yes in aged reports 2014-09-19 Joe Hunt
141 $_POST['PARAM_'.$cnt] = 1;
143 if (isset($_COOKIE['select'][$id][$cnt])) // saved parameters 2010-10-06 Joe Hunt
144 $_POST['PARAM_'.$cnt] = $_COOKIE['select'][$id][$cnt];
145 $ctrl = $this->get_ctrl('PARAM_'.$cnt, $type);
148 $st .= $title . ':<br>';
152 display_error(_('Unknown report parameter type:').$type);
160 // Register additional control handler
161 // $handle - name of global function f($name, $type) returning html code for control
162 function register_controls($handler) {
163 $this->ctrl_handlers[] = $handler;
166 // Returns html code for input control $name of type $type
168 function get_ctrl($name, $type)
170 global $path_to_root, $SysPrefs,
177 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) AS name FROM ".TB_PREF."currencies";
178 return combo_input($name, '', $sql, 'curr_abrev', 'name',array('spec_option'=>_("No Currency Filter"),'spec_id'=>ALL_TEXT,'order'=>false));
187 if (!isset($_POST[$name]))
189 if ($type == 'DATEBEGIN')
190 $date = begin_fiscalyear();
191 elseif ($type == 'DATEEND')
192 $date = end_fiscalyear();
195 if ($type == 'DATEBEGINM')
196 $date = begin_month($date);
197 elseif ($type == 'DATEENDM')
198 $date = end_month($date);
199 elseif ($type == 'DATEBEGINTAX' || $type == 'DATEENDTAX')
201 $row = get_company_prefs();
202 $edate = add_months($date, -$row['tax_last']);
203 $edate = end_month($edate);
204 if ($type == 'DATEENDTAX')
208 $bdate = begin_month($edate);
209 $bdate = add_months($bdate, -$row['tax_prd'] + 1);
214 else // saved parameters
215 $date = $_POST[$name];
216 $st = "<input type='text' name='$name' value='$date'>";
217 if (user_use_date_picker())
219 $calc_image = (file_exists("$path_to_root/themes/".user_theme()."/images/cal.gif")) ?
220 "$path_to_root/themes/".user_theme()."/images/cal.gif" : "$path_to_root/themes/default/images/cal.gif";
221 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
222 . " <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";
228 return yesno_list($name);
231 return payment_services($name, null);
234 $sel = array(_("PDF/Printer"), "Excel");
236 if (user_def_print_destination() == 1)
238 return array_selector($name, $def, $sel);
241 $sel = array(_("Portrait"), _("Landscape"));
243 if (user_def_print_orientation() == 1)
245 return array_selector($name, $def, $sel);
248 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
249 return array_selector($name, null, $sel);
252 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"),
253 _("Dots"), _("Lines"), _("Pie"), _("Donut"));
254 return array_selector($name, null, $sel);
257 return gl_systypes_list($name, null, _("No Type Filter"));
259 case 'SYS_TYPES_ALL':
260 return systypes_list($name, null, _("No Type Filter"));
263 return "<input type='text' name='$name'>";
266 $value = (isset($_POST[$name]) ? $_POST[$name] : "");
267 return "<textarea rows=4 cols=30 name='$name'>$value</textarea>";
269 case 'ACCOUNTS': // not used
270 return gl_account_types_list($name, null, _("No Account Group Filter"), true);
272 case 'ACCOUNTS_NO_FILTER': // not used
273 return gl_account_types_list($name);
276 return gl_all_accounts_list($name);
278 case 'BANK_ACCOUNTS':
279 return bank_accounts_list($name);
282 return dimensions_list($name, null, false, ' ', false, true, 0);
285 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 0);
288 return dimensions_list($name, null, false, ' ', false, true, 1);
291 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 1);
294 return dimensions_list($name, null, false, ' ', false, true, 2);
297 return dimensions_list($name, null, true, _("No Dimension Filter"), false, true, 2);
299 case 'CUSTOMERS_NO_FILTER':
301 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master";
302 if ($type == 'CUSTOMERS_NO_FILTER')
303 return customer_list($name, null, _("No Customer Filter"));
305 return customer_list($name);
307 case 'SUPPLIERS_NO_FILTER':
309 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers";
310 if ($type == 'SUPPLIERS_NO_FILTER')
311 return supplier_list($name, null, _("No Supplier Filter"));
313 return supplier_list($name);
316 $IV = $type_shortcuts[ST_SALESINVOICE];
317 $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
318 $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
319 concat('$IV ', debtor_trans.$ref,' ', debtor.name) as IName
320 FROM ".TB_PREF."debtors_master debtor,"
321 .TB_PREF."debtor_trans debtor_trans
322 WHERE type=".ST_SALESINVOICE." AND debtor.debtor_no=debtor_trans.debtor_no
323 ORDER BY debtor_trans.trans_no DESC";
324 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
327 $CN = $type_shortcuts[ST_CUSTCREDIT];
328 $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
329 $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
330 concat('$CN ', debtor_trans.$ref,' ', debtor.name) as IName
331 FROM ".TB_PREF."debtors_master debtor,"
332 .TB_PREF."debtor_trans debtor_trans
333 WHERE type=".ST_CUSTCREDIT." AND debtor.debtor_no=debtor_trans.debtor_no
334 ORDER BY debtor_trans.trans_no DESC";
335 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
338 $DN = $type_shortcuts[ST_CUSTDELIVERY];
339 $sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
340 concat(debtor_trans.trans_no, ' $DN ', debtor.name) as IName
341 FROM ".TB_PREF."debtors_master debtor,"
342 .TB_PREF."debtor_trans debtor_trans
343 WHERE type=".ST_CUSTDELIVERY." AND debtor.debtor_no=debtor_trans.debtor_no
344 ORDER BY debtor_trans.trans_no DESC";
345 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
348 $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
349 $sql = "SELECT sorder.order_no, concat(sorder.$ref, '-', debtor.name) as IName
350 FROM ".TB_PREF."debtors_master debtor,"
351 .TB_PREF."sales_orders sorder
352 WHERE debtor.debtor_no=sorder.debtor_no AND sorder.trans_type=".ST_SALESORDER
353 ." ORDER BY sorder.order_no DESC";
354 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
357 $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
358 $sql = "SELECT sorder.order_no, concat(sorder.$ref, '-', debtor.name) as IName
359 FROM ".TB_PREF."debtors_master debtor,"
360 .TB_PREF."sales_orders sorder
361 WHERE debtor.debtor_no=sorder.debtor_no AND sorder.trans_type=".ST_SALESQUOTE
362 ." ORDER BY sorder.order_no DESC";
363 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
366 $ref = ($SysPrefs->print_invoice_no() == 1 ? "order_no" : "reference");
367 $sql = "SELECT po.order_no, concat(po.$ref, '-', supplier.supp_name) as IName
368 FROM ".TB_PREF."suppliers supplier,"
369 .TB_PREF."purch_orders po
370 WHERE supplier.supplier_id=po.supplier_id
371 ORDER BY po.order_no DESC";
372 return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
375 $BP = $type_shortcuts[ST_BANKPAYMENT];
376 $SP = $type_shortcuts[ST_SUPPAYMENT];
377 $CN = $type_shortcuts[ST_SUPPCREDIT];
378 $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
379 $sql = "SELECT concat(trans.trans_no, '-',trans.type) AS TNO,
380 concat(trans.$ref, IF(type=".ST_BANKPAYMENT.", ' $BP ', IF(type=".ST_SUPPAYMENT.", ' $SP ', ' $CN ')), supplier.supp_name) as IName
381 FROM ".TB_PREF."suppliers supplier, "
382 .TB_PREF."supp_trans trans
383 WHERE type IN(".ST_BANKPAYMENT.",".ST_SUPPAYMENT.",".ST_SUPPCREDIT.")
384 AND supplier.supplier_id=trans.supplier_id
385 ORDER BY trans.trans_no DESC";
386 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
389 $BD = $type_shortcuts[ST_BANKDEPOSIT];
390 $CP = $type_shortcuts[ST_CUSTPAYMENT];
391 $ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");
392 $sql = "SELECT concat(trans.trans_no, '-', trans.type) AS TNO,
393 concat(trans.$ref, IF(type=".ST_BANKDEPOSIT.", ' $BD ', ' $CP '), debtor.name) as IName
394 FROM ".TB_PREF."debtors_master debtor,"
395 .TB_PREF."debtor_trans trans
396 WHERE type IN(".ST_BANKDEPOSIT.",".ST_CUSTPAYMENT.",".ST_CUSTCREDIT.") AND debtor.debtor_no=trans.debtor_no
397 ORDER BY trans.trans_no DESC";
398 return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
401 return stock_manufactured_items_list($name);
404 return stock_manufactured_items_list($name, null, true);
407 return stock_purchasable_items_list($name, null, true);
410 $sql = "SELECT wo.id, concat(wo.id, '-', item.description) as IName
411 FROM ".TB_PREF."stock_master item,"
412 .TB_PREF."workorders wo
413 WHERE item.stock_id=wo.stock_id
414 ORDER BY wo.id DESC";
415 return combo_input($name, '', $sql, 'id', 'IName',array('order'=>false));
418 return locations_list($name, null, _("No Location Filter"));
421 return stock_categories_list($name, null, _("No Category Filter"));
424 return sales_types_list($name);
427 return sales_areas_list($name);
430 return sales_persons_list($name, null, _("No Sales Folk Filter"));
433 return fiscalyears_list($name);
436 $sql = "SELECT id, user_id FROM ".TB_PREF."users";
437 return combo_input($name, '', $sql, 'id', 'user_id',array('spec_option'=>_("No Users Filter"),'spec_id'=>ALL_NUMERIC));
440 case 'DIMENSIONTAGS':
441 if ($type == 'ACCOUNTTAGS')
442 $tag_type = TAG_ACCOUNT;
444 $tag_type = TAG_DIMENSION;
445 return tag_list($name, 5, $tag_type, true);
459 function Report($id, $name, $ar_params = null)
463 if ($ar_params) $this->set_controls($ar_params);
466 function set_controls($ar_params) {
467 $this->controls = $ar_params;
470 function get_controls() {
471 return $this->controls;
476 //------------------------------------------------------------------------------------------------
477 function gl_systypes_list($name, $value=null, $spec_opt=false)
479 global $systypes_array;
481 $types = $systypes_array;
483 foreach(array(ST_LOCTRANSFER, ST_PURCHORDER, ST_SUPPRECEIVE, ST_MANUISSUE,
484 ST_MANURECEIVE, ST_SALESORDER, ST_SALESQUOTE, ST_DIMENSION) as $type)
485 unset($types[$type]);
487 return array_selector($name, $value, $types,
489 'spec_option'=> $spec_opt,
490 'spec_id' => ALL_NUMERIC,
496 Add extension/custom reports to report manager.
498 function add_custom_reports(&$reports)
500 global $installed_extensions, $path_to_root;
502 // include reports installed inside extension modules
503 if (count($installed_extensions) > 0)
505 $extensions = $installed_extensions;
506 foreach ($extensions as $ext)
507 if (($ext['active'] && $ext['type'] == 'extension')) {
508 $file = $path_to_root.'/'.$ext['path']."/reporting/reports_custom.php";
509 if (file_exists($file)) {
510 set_ext_domain($ext['path']);
516 $file = company_path()."/reporting/reports_custom.php";
517 if (file_exists($file))