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 $Ajax->addUpdate(true, 'rep_form', $st_params);
73 $st_reports .= "</table>";
77 $st_params = "<div id='rep_form'>".
81 $st = "<script language='javascript'>
82 function showClass(pClass) {
83 for(i=0; i<$class_counter; i++) {
84 document.getElementById(\"TAB_\" + i).style.display=
85 i==pClass ? \"block\" : \"none\";
87 document.getElementById('rep_form').innerHTML = '';
88 // document.getElementById('rep_form').style.display = 'none';
91 function checkDate(pObj) {
92 var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
93 if (re.test(pObj.value)==false) {
94 alert('" . _("Invalid date format") . "')
99 $st .= "<table align='center' width='80%' $table_style2><tr valign='top'>";
100 $st .= "<td width='30%'>$st_classes</td>";
101 $st .= "<td width='35%'>$st_reports</td>";
102 $st .= "<td width='35%'>$st_params</td>";
103 $st .= "</tr></table><br>";
115 function Report($id, $name, $ar_params)
119 $this->ar_params = $ar_params;
122 function getDisplay()
124 global $path_to_root, $use_date_picker, $pdf_debug;
128 if ($this->ar_params==null)
130 foreach($this->ar_params as $index=>$param)
132 $st .= $param->param_name . ':<br>';
133 switch ($param->param_type)
136 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) FROM ".TB_PREF."currencies";
137 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Currency Filter"));
146 if ($param->param_type == 'DATEBEGIN')
147 $date = begin_fiscalyear();
148 elseif ($param->param_type == 'DATEEND')
149 $date = end_fiscalyear();
152 if ($param->param_type == 'DATEBEGINM')
153 $date = begin_month($date);
154 elseif ($param->param_type == 'DATEENDM')
155 $date = end_month($date);
156 elseif ($param->param_type == 'DATEBEGINTAX' || $param->param_type == 'DATEENDTAX')
158 $row = get_company_prefs();
159 $edate = add_months($date, -$row['tax_last']);
160 $edate = end_month($edate);
161 if ($param->param_type == 'DATEENDTAX')
165 $bdate = add_months($edate, -$row['tax_prd'] + 1);
166 $date = begin_month($bdate);
169 $name = "PARAM_$index";
171 $st .= "<input type='text' name='$name' value='$date'>";
172 if ($use_date_picker)
173 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
174 . " <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";
178 $sel = array(_('No'), _("Yes"));
179 $st .= dup_simple_name_list("PARAM_$index", $sel);
182 $sel = array(_("No Payment Link"), "PayPal");
183 $st .= dup_simple_name_list("PARAM_$index", $sel);
186 $sel = array(_("PDF/Printer"), "Excel");
187 $st .= dup_simple_name_list("PARAM_$index", $sel);
190 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
191 $st .= dup_simple_name_list("PARAM_$index", $sel);
194 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), _("Dots"), _("Lines"), _("Pie"), _("Donut"));
195 $st .= dup_simple_name_list("PARAM_$index", $sel);
198 $st .= dup_systypes_list("PARAM_$index", $dummy, true, _("No Type Filter"), true);
201 $st .= "<input type='text' name='PARAM_$index'>";
204 $st .= "<textarea rows=4 cols=30 name='PARAM_$index'></textarea>";
207 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
208 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Account Group Filter"), true);
211 $sql = "SELECT account_code, concat(account_code, ' - ', account_name) as account_name FROM ".TB_PREF."chart_master ORDER BY account_code";
212 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
214 case 'BANK_ACCOUNTS':
215 $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";
216 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
219 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
220 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
223 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
224 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
227 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
228 $st .= dup_simple_codeandname_list($sql, "PARAM_$index". "_$index", $dummy);
231 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
232 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
235 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
236 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
239 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
240 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
242 case 'CUSTOMERS_NO_FILTER':
244 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master ORDER BY name";
245 if ($param->param_type == 'CUSTOMERS_NO_FILTER')
246 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Customer Filter"), true);
248 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
250 case 'SUPPLIERS_NO_FILTER':
252 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers ORDER BY supp_name";
253 if ($param->param_type == 'SUPPLIERS_NO_FILTER')
254 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Supplier Filter"), true);
256 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
261 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
262 ".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
263 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";
264 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
269 concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
270 ".TB_PREF."debtors_master.name) as IName
271 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
272 WHERE type=13 AND ".TB_PREF."debtors_master.debtor_no=".
273 TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
274 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
277 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
278 ".TB_PREF."debtors_master.name) as IName
279 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";
280 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
283 $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.order_no, '-',
284 ".TB_PREF."suppliers.supp_name) as IName
285 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";
286 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
289 $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";
290 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
293 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations ORDER BY location_name";
294 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Location Filter"), false);
297 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category ORDER BY description";
298 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Category Filter"), true);
301 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types ORDER BY sales_type";
302 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
305 $sql = "SELECT area_code, description FROM ".TB_PREF."areas ORDER BY description";
306 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Area Filter"), true);
309 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman ORDER BY salesman_name";
310 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Sales Folk Filter"), true);
313 $sql = "SELECT DISTINCT YEAR(tran_date), YEAR(tran_date) FROM ".TB_PREF."gl_trans";
314 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
316 case 'ACCOUNTS_NO_FILTER':
317 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
318 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
333 function ReportParam($param_name, $param_type)
335 $this->param_name = $param_name;
336 $this->param_type = $param_type;
340 function dup_simple_codeandname_list($sql, $name, &$selected_id,
341 $all_option=false, $all_option_name=null, $all_option_numeric=false,
342 $submit_on_change=false)
344 if ($submit_on_change == true)
345 $st = "<select name='$name' onchange='this.form.submit();'>";
347 $st = "<select name='$name'>";
349 if ($all_option == true)
351 if ($all_option_numeric)
352 $reserved_word = reserved_words::get_all_numeric();
354 $reserved_word = reserved_words::get_all();
356 if ($reserved_word == $selected_id)
358 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
362 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
364 if ($selected_id == "")
366 $selected_id = $reserved_word;
370 $result = db_query($sql);
372 while ($row = db_fetch_row($result))
374 if ($selected_id == $row[0])
376 $st .= "<option selected value='" . $row[0] . "'>";
380 $st .= "<option value='" . $row[0] . "'>";
382 $st .= $row[1] . "</option>\n";
384 if ($selected_id == "")
386 $selected_id = $row[0];
391 db_free_result($result);
396 function dup_simple_name_list($name, $selections)
398 $st = "<select name='$name'>";
399 for ($i = 0; $i < count($selections); $i++)
400 $st .= "<option value='" . $i . "'>" . $selections[$i] . "</option>\n";
405 //------------------------------------------------------------------------------------------------
407 function dup_systypes_list($name, &$selected_id, $all_option=false, $all_option_name=null)
409 global $systypes_array;
411 $st = "<select name='$name'>";
412 if ($all_option == true)
414 $reserved_word = reserved_words::get_all_numeric();
415 if ($reserved_word == $selected_id)
416 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
418 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
419 if ($selected_id == "")
420 $selected_id = $reserved_word;
423 foreach ($systypes_array as $i => $value)
425 if ($i == 16 || $i == 18 || $i == 25 || ($i >= 28 && $i <= 30) || $i >= 40)
427 $st .= "<option" . ($selected_id == $i ? " selected" : "") . " value='$i'>" . $value['name'] . "</option>\n";