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 ***********************************************************************/
16 function ReportClasses()
18 $this->ar_classes = array();
21 function addReportClass($class_name)
23 $this->ar_classes[$class_name] = array();
26 function addReport($class_name, $id, $rep_name, $params=null)
28 $this->ar_classes[$class_name][] = new Report($id,$rep_name,$params);
31 function getDisplay($class=null)
33 global $table_style2, $comp_path, $path_to_root, $pdf_debug, $Ajax;
35 $temp = array_values($this->ar_classes);
36 $display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
41 $st_classes = "<b>" . _("Report Classes:") . "</b><br>";
42 foreach($this->ar_classes as $key=>$value)
44 $style = $class_counter==$_REQUEST['Class'] ? '' : "style='display:none'";
45 $acc = access_string($key);
46 $st_classes .= "<a href='"
47 .$_SERVER['PHP_SELF']."?Class=$class_counter'"
48 ." class='menu_option' id='".default_focus()."'"
49 ." onclick='return showClass($class_counter);'$acc[1]>$acc[0]</a> <br>";
50 $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";
51 foreach($value as $report)
53 $acc = access_string($report->name);
54 $st_reports .= "<tr><td><a class='printlink' href='"
55 .$_SERVER['PHP_SELF']."?Class=$class_counter&rep_id=$report->id'"
56 ." id='".default_focus()."'"
57 ."$acc[1]>$acc[0]</a><tr><td>\n";
58 if (isset($_REQUEST['rep_id']) && $_REQUEST['rep_id']==$report->id) {
60 $action = $path_to_root.'/reporting/prn_redirect.php';
62 $st_params = "<table border=0><tr><td>\n"
63 . "<form method='POST' action='$action' target='_blank'>\n";
64 $st_params .= hidden('REP_ID', $report->id, false);
65 $st_params .= submit('Rep'.$report->id,
66 _("Display: ") . access_string($report->name, true),
67 false, '', $pdf_debug ? false : 'default') . '<br><br>';
68 $st_params .= $report->getDisplay()
69 . "\n</form></td></tr></table>\n";
70 set_focus('Rep'.$report->id);
71 $Ajax->addUpdate(true, 'rep_form', $st_params);
74 $st_reports .= "</table>";
78 $st_params = "<div id='rep_form'>".
82 $st = "<script language='javascript'>
83 function showClass(pClass) {
84 for(i=0; i<$class_counter; i++) {
85 document.getElementById(\"TAB_\" + i).style.display=
86 i==pClass ? \"block\" : \"none\";
88 document.getElementById('rep_form').innerHTML = '';
89 // document.getElementById('rep_form').style.display = 'none';
92 function checkDate(pObj) {
93 var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
94 if (re.test(pObj.value)==false) {
95 alert('" . _("Invalid date format") . "')
100 $st .= "<table align='center' width='80%' $table_style2><tr valign='top'>";
101 $st .= "<td width='30%'>$st_classes</td>";
102 $st .= "<td width='35%'>$st_reports</td>";
103 $st .= "<td width='35%'>$st_params</td>";
104 $st .= "</tr></table><br>";
116 function Report($id, $name, $ar_params)
120 $this->ar_params = $ar_params;
123 function getDisplay()
125 global $path_to_root, $use_date_picker, $pdf_debug;
129 if ($this->ar_params==null)
131 foreach($this->ar_params as $index=>$param)
133 $st .= $param->param_name . ':<br>';
134 switch ($param->param_type)
137 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) FROM ".TB_PREF."currencies";
138 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Currency Filter"));
147 if ($param->param_type == 'DATEBEGIN')
148 $date = begin_fiscalyear();
149 elseif ($param->param_type == 'DATEEND')
150 $date = end_fiscalyear();
153 if ($param->param_type == 'DATEBEGINM')
154 $date = begin_month($date);
155 elseif ($param->param_type == 'DATEENDM')
156 $date = end_month($date);
157 elseif ($param->param_type == 'DATEBEGINTAX' || $param->param_type == 'DATEENDTAX')
159 $row = get_company_prefs();
160 $edate = add_months($date, -$row['tax_last']);
161 $edate = end_month($edate);
162 if ($param->param_type == 'DATEENDTAX')
166 $bdate = add_months($edate, -$row['tax_prd'] + 1);
167 $date = begin_month($bdate);
170 $name = "PARAM_$index";
172 $st .= "<input type='text' name='$name' value='$date'>";
173 if ($use_date_picker)
174 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
175 . " <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";
179 $sel = array(_('No'), _("Yes"));
180 $st .= dup_simple_name_list("PARAM_$index", $sel);
183 $sel = array(_("No Payment Link"), "PayPal");
184 $st .= dup_simple_name_list("PARAM_$index", $sel);
187 $sel = array(_("PDF/Printer"), "Excel");
188 $st .= dup_simple_name_list("PARAM_$index", $sel);
191 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
192 $st .= dup_simple_name_list("PARAM_$index", $sel);
195 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), _("Dots"), _("Lines"), _("Pie"), _("Donut"));
196 $st .= dup_simple_name_list("PARAM_$index", $sel);
199 $st .= dup_systypes_list("PARAM_$index", $dummy, true, _("No Type Filter"), true);
202 $st .= "<input type='text' name='PARAM_$index'>";
205 $st .= "<textarea rows=4 cols=30 name='PARAM_$index'></textarea>";
208 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
209 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Account Group Filter"), true);
212 $sql = "SELECT account_code, concat(account_code, ' - ', account_name) as account_name FROM ".TB_PREF."chart_master ORDER BY account_code";
213 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
215 case 'BANK_ACCOUNTS':
216 $sql = "SELECT ".TB_PREF."bank_accounts.id, concat(bank_account_name, if (bank_curr_code=curr_default,'', concat(' - ', bank_curr_code))) FROM ".TB_PREF."bank_accounts, ".TB_PREF."company";
217 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
220 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
221 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
224 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
225 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
228 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
229 $st .= dup_simple_codeandname_list($sql, "PARAM_$index". "_$index", $dummy);
232 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
233 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
236 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
237 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
240 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
241 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
243 case 'CUSTOMERS_NO_FILTER':
245 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master ORDER BY name";
246 if ($param->param_type == 'CUSTOMERS_NO_FILTER')
247 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Customer Filter"), true);
249 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
251 case 'SUPPLIERS_NO_FILTER':
253 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers ORDER BY supp_name";
254 if ($param->param_type == 'SUPPLIERS_NO_FILTER')
255 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Supplier Filter"), true);
257 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
262 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
263 ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
264 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=10 OR type=11) AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
265 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
270 concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
271 ".TB_PREF."debtors_master.name) as IName
272 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
273 WHERE type=13 AND ".TB_PREF."debtors_master.debtor_no=".
274 TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
275 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
278 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
279 ".TB_PREF."debtors_master.name) as IName
280 FROM ".TB_PREF."debtors_master, ".TB_PREF."sales_orders WHERE ".TB_PREF."debtors_master.debtor_no=".TB_PREF."sales_orders.debtor_no ORDER BY ".TB_PREF."sales_orders.order_no DESC";
281 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
284 $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.order_no, '-',
285 ".TB_PREF."suppliers.supp_name) as IName
286 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";
287 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
290 $sql = "SELECT stock_id, concat(stock_id, '-', description) as name FROM ".TB_PREF."stock_master WHERE (mb_flag='A' OR mb_flag='M') ORDER BY stock_id";
291 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
294 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations ORDER BY location_name";
295 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Location Filter"), false);
298 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category ORDER BY description";
299 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Category Filter"), true);
302 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types ORDER BY sales_type";
303 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
306 $sql = "SELECT area_code, description FROM ".TB_PREF."areas ORDER BY description";
307 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Area Filter"), true);
310 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman ORDER BY salesman_name";
311 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Sales Folk Filter"), true);
314 $sql = "SELECT DISTINCT YEAR(tran_date), YEAR(tran_date) FROM ".TB_PREF."gl_trans";
315 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
317 case 'ACCOUNTS_NO_FILTER':
318 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
319 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
334 function ReportParam($param_name, $param_type)
336 $this->param_name = $param_name;
337 $this->param_type = $param_type;
341 function dup_simple_codeandname_list($sql, $name, &$selected_id,
342 $all_option=false, $all_option_name=null, $all_option_numeric=false,
343 $submit_on_change=false)
345 if ($submit_on_change == true)
346 $st = "<select name='$name' onchange='this.form.submit();'>";
348 $st = "<select name='$name'>";
350 if ($all_option == true)
352 if ($all_option_numeric)
353 $reserved_word = reserved_words::get_all_numeric();
355 $reserved_word = reserved_words::get_all();
357 if ($reserved_word == $selected_id)
359 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
363 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
365 if ($selected_id == "")
367 $selected_id = $reserved_word;
371 $result = db_query($sql);
373 while ($row = db_fetch_row($result))
375 if ($selected_id == $row[0])
377 $st .= "<option selected value='" . $row[0] . "'>";
381 $st .= "<option value='" . $row[0] . "'>";
383 $st .= $row[1] . "</option>\n";
385 if ($selected_id == "")
387 $selected_id = $row[0];
392 db_free_result($result);
397 function dup_simple_name_list($name, $selections)
399 $st = "<select name='$name'>";
400 for ($i = 0; $i < count($selections); $i++)
401 $st .= "<option value='" . $i . "'>" . $selections[$i] . "</option>\n";
406 //------------------------------------------------------------------------------------------------
408 function dup_systypes_list($name, &$selected_id, $all_option=false, $all_option_name=null)
410 global $systypes_array;
412 $st = "<select name='$name'>";
413 if ($all_option == true)
415 $reserved_word = reserved_words::get_all_numeric();
416 if ($reserved_word == $selected_id)
417 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
419 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
420 if ($selected_id == "")
421 $selected_id = $reserved_word;
424 foreach ($systypes_array as $i => $value)
426 if ($i == 16 || $i == 18 || $i == 25 || ($i >= 28 && $i <= 30) || $i >= 40)
428 $st .= "<option" . ($selected_id == $i ? " selected" : "") . " value='$i'>" . $value['name'] . "</option>\n";