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 ."' onclick='return showClass($class_counter);'$acc[1]>$acc[0]</a> <br>";
49 $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";
50 foreach($value as $report)
52 $acc = access_string($report->name);
53 $st_reports .= "<tr><td><a class='printlink' href='"
54 .$_SERVER['PHP_SELF']."?Class=$class_counter&rep_id=$report->id"
55 ."'$acc[1]>$acc[0]</a><tr><td>\n";
56 if (isset($_REQUEST['rep_id']) && $_REQUEST['rep_id']==$report->id) {
58 $action = $path_to_root.'/reporting/prn_redirect.php';
60 $st_params = "<table border=0><tr><td>\n"
61 . "<form method='POST' action='$action' target='_blank'>\n";
62 $st_params .= hidden('REP_ID', $report->id, false);
63 $st_params .= submit('Rep'.$report->id,
64 _("Display: ") . access_string($report->name,true),
65 false, '', $pdf_debug==0) . '<br><br>';
66 $st_params .= $report->getDisplay()
67 . "\n</form></td></tr></table>\n";
68 $Ajax->addUpdate(true, 'rep_form', $st_params);
71 $st_reports .= "</table>";
75 $st_params = "<div id='rep_form'>".
79 $st = "<script language='javascript'>
80 function showClass(pClass) {
81 for(i=0; i<$class_counter; i++) {
82 document.getElementById(\"TAB_\" + i).style.display=
83 i==pClass ? \"block\" : \"none\";
85 document.getElementById('rep_form').innerHTML = '';
86 // document.getElementById('rep_form').style.display = 'none';
89 function checkDate(pObj) {
90 var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
91 if (re.test(pObj.value)==false) {
92 alert('" . _("Invalid date format") . "')
97 $st .= "<table align='center' width='80%' $table_style2><tr valign='top'>";
98 $st .= "<td width='30%'>$st_classes</td>";
99 $st .= "<td width='35%'>$st_reports</td>";
100 $st .= "<td width='35%'>$st_params</td>";
101 $st .= "</tr></table><br>";
113 function Report($id, $name, $ar_params)
117 $this->ar_params = $ar_params;
120 function getDisplay()
122 global $path_to_root, $use_date_picker, $pdf_debug, $print_invoice_no;
126 if ($this->ar_params==null)
128 foreach($this->ar_params as $index=>$param)
130 $st .= $param->param_name . ':<br>';
131 switch ($param->param_type)
134 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) FROM ".TB_PREF."currencies";
135 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Currency Filter"));
144 if ($param->param_type == 'DATEBEGIN')
145 $date = begin_fiscalyear();
146 elseif ($param->param_type == 'DATEEND')
147 $date = end_fiscalyear();
150 if ($param->param_type == 'DATEBEGINM')
151 $date = begin_month($date);
152 elseif ($param->param_type == 'DATEENDM')
153 $date = end_month($date);
154 elseif ($param->param_type == 'DATEBEGINTAX' || $param->param_type == 'DATEENDTAX')
156 $row = get_company_prefs();
157 $edate = add_months($date, -$row['tax_last']);
158 $edate = end_month($edate);
159 if ($param->param_type == 'DATEENDTAX')
163 $bdate = begin_month($edate);
164 $bdate = add_months($bdate, -$row['tax_prd'] + 1);
168 $name = "PARAM_$index";
170 $st .= "<input type='text' name='$name' value='$date'>";
171 if ($use_date_picker)
172 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
173 . " <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";
177 $sel = array(_('No'), _("Yes"));
178 $st .= dup_simple_name_list("PARAM_$index", $sel);
181 $sel = array(_("No Payment Link"), "PayPal");
182 $st .= dup_simple_name_list("PARAM_$index", $sel);
185 $sel = array(_("PDF/Printer"), "Excel");
186 $st .= dup_simple_name_list("PARAM_$index", $sel);
189 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
190 $st .= dup_simple_name_list("PARAM_$index", $sel);
193 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), _("Dots"), _("Lines"), _("Pie"), _("Donut"));
194 $st .= dup_simple_name_list("PARAM_$index", $sel);
197 $st .= dup_systypes_list("PARAM_$index", $dummy, true, _("No Type Filter"), true);
200 $st .= "<input type='text' name='PARAM_$index'>";
203 $st .= "<textarea rows=4 cols=30 name='PARAM_$index'></textarea>";
206 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
207 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Account Group Filter"), true);
210 $sql = "SELECT account_code, concat(account_code, ' - ', account_name) as account_name FROM ".TB_PREF."chart_master ORDER BY account_code";
211 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
213 case 'BANK_ACCOUNTS':
214 $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";
215 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
218 $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
219 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
222 $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
223 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
226 $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
227 $st .= dup_simple_codeandname_list($sql, "PARAM_$index". "_$index", $dummy);
230 $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
231 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
234 $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
235 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
238 $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
239 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Dimension Filter"), true);
241 case 'CUSTOMERS_NO_FILTER':
243 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master ORDER BY name";
244 if ($param->param_type == 'CUSTOMERS_NO_FILTER')
245 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Customer Filter"), true);
247 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
249 case 'SUPPLIERS_NO_FILTER':
251 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers ORDER BY supp_name";
252 if ($param->param_type == 'SUPPLIERS_NO_FILTER')
253 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Supplier Filter"), true);
255 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
260 if ($print_invoice_no == 1)
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";
265 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
266 ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.reference, if (type=10, ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
267 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";
268 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
273 concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
274 ".TB_PREF."debtors_master.name) as IName
275 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
276 WHERE type=13 AND ".TB_PREF."debtors_master.debtor_no=".
277 TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
278 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
281 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
282 ".TB_PREF."debtors_master.name) as IName
283 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";
284 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
287 $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.order_no, '-',
288 ".TB_PREF."suppliers.supp_name) as IName
289 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";
290 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
293 $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";
294 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
297 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations ORDER BY location_name";
298 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Location Filter"), false);
301 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category ORDER BY description";
302 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Category Filter"), true);
305 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types ORDER BY sales_type";
306 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
309 $sql = "SELECT area_code, description FROM ".TB_PREF."areas ORDER BY description";
310 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Area Filter"), true);
313 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman ORDER BY salesman_name";
314 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Sales Folk Filter"), true);
317 $sql = "SELECT DISTINCT YEAR(tran_date), YEAR(tran_date) FROM ".TB_PREF."gl_trans";
318 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
320 case 'ACCOUNTS_NO_FILTER':
321 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
322 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy);
337 function ReportParam($param_name, $param_type)
339 $this->param_name = $param_name;
340 $this->param_type = $param_type;
344 function dup_simple_codeandname_list($sql, $name, &$selected_id,
345 $all_option=false, $all_option_name=null, $all_option_numeric=false,
346 $submit_on_change=false)
348 if ($submit_on_change == true)
349 $st = "<select name='$name' onchange='this.form.submit();'>";
351 $st = "<select name='$name'>";
353 if ($all_option == true)
355 if ($all_option_numeric)
356 $reserved_word = reserved_words::get_all_numeric();
358 $reserved_word = reserved_words::get_all();
360 if ($reserved_word == $selected_id)
362 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
366 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
368 if ($selected_id == "")
370 $selected_id = $reserved_word;
374 $result = db_query($sql);
376 while ($row = db_fetch_row($result))
378 if ($selected_id == $row[0])
380 $st .= "<option selected value='" . $row[0] . "'>";
384 $st .= "<option value='" . $row[0] . "'>";
386 $st .= $row[1] . "</option>\n";
388 if ($selected_id == "")
390 $selected_id = $row[0];
395 db_free_result($result);
400 function dup_simple_name_list($name, $selections)
402 $st = "<select name='$name'>";
403 for ($i = 0; $i < count($selections); $i++)
404 $st .= "<option value='" . $i . "'>" . $selections[$i] . "</option>\n";
409 //------------------------------------------------------------------------------------------------
411 function dup_systypes_list($name, &$selected_id, $all_option=false, $all_option_name=null)
413 global $systypes_array;
415 $st = "<select name='$name'>";
416 if ($all_option == true)
418 $reserved_word = reserved_words::get_all_numeric();
419 if ($reserved_word == $selected_id)
420 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
422 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
423 if ($selected_id == "")
424 $selected_id = $reserved_word;
427 foreach ($systypes_array as $i => $value)
429 if ($i == 16 || $i == 18 || $i == 25 || ($i >= 28 && $i <= 30) || $i >= 40)
431 $st .= "<option" . ($selected_id == $i ? " selected" : "") . " value='$i'>" . $value['name'] . "</option>\n";