6 function ReportClasses()
8 $this->ar_classes = array();
11 function addReportClass($class_name)
13 $this->ar_classes[$class_name] = array();
16 function addReport($class_name, $id, $rep_name, $params=null)
18 $this->ar_classes[$class_name][] = new Report($id,$rep_name,$params);
21 function getDisplay($class=null)
24 $temp = array_values($this->ar_classes);
25 $display_class = $class==null ? $temp[0] : $this->ar_classes[$class];
30 $st_classes = "<b>" . _("Report Classes:") . "</b><br>";
31 foreach($this->ar_classes as $key=>$value)
33 $style = $class_counter==0 ? '' : $style = "style='display:none'";
34 $acc = access_string($key);
35 $st_classes .= "<a href='javascript:showClass($class_counter)'$acc[1]>$acc[0]</a> <br>";
36 $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>";
37 foreach($value as $report)
38 { $acc = access_string($report->name);
39 $st_reports .= "<tr><td><a href='javascript:showReport($rep_counter)'$acc[1]>$acc[0]</a></td></tr>";
40 $st_params .= "<table border=0 id='REP_" . $rep_counter++ . "' style='display:none'>";
41 $st_params .= "<tr><td>" . $report->getDisplay() . "</td></tr></table>";
43 $st_reports .= "</table>";
46 $st = "<script language='javascript'>
47 function showClass(pClass) {
48 for(i=0; i<$class_counter; i++) {
49 eval('document.getElementById(\"TAB_\" + i).style.display=\"none\"')
51 eval('document.getElementById(\"TAB_\" + pClass).style.display=\"block\"')
52 for (i=0; i<$rep_counter; i++) {
53 eval('document.getElementById(\"REP_\" + i).style.display=\"none\"')
56 function showReport(pId) {
58 for(i=0; i<$rep_counter; i++) {
59 eval('document.getElementById(\"REP_\" + i).style.display=\"none\"')
61 eval('document.getElementById(\"REP_\" + pId).style.display=\"block\"')
65 $st .= "<table align='center' width='80%' $table_style2><tr valign='top'>";
66 $st .= "<td width='30%'>$st_classes</td>";
67 $st .= "<td width='35%'>$st_reports</td>";
68 $st .= "<td width='35%'>$st_params</td>";
69 $st .= "</tr></table><br>";
81 function Report($id, $name, $ar_params)
85 $this->ar_params = $ar_params;
89 global $comp_path, $path_to_root, $use_date_picker;
91 $rep_file = $comp_path.'/'.user_company().
92 "/reporting/rep".$this->id.".php";
93 if (!file_exists($rep_file))
94 $rep_file = $path_to_root ."/reporting/rep".$this->id.".php";
97 <script language='javascript'>
98 function displayReport_" . $this->id . "() {
99 pParamCount = " . count($this->ar_params) . ";
100 document.forms[0].REP_ID.value = " . $this->id . ";
101 document.forms[0].PARAM_COUNT.value = pParamCount;
102 for (i=0; i<pParamCount; i++) {
103 eval('document.forms[0].PARAM_' + i + '.value=document.forms[0].RP_" . $this->id . "_' + i + '.value');
106 window.open('','REP_WINDOW','toolbar=no,scrollbar=no,resizable=yes,menubar=no');
107 document.forms[0].target='REP_WINDOW';
108 document.forms[0].action= '$rep_file';
109 document.forms[0].submit();
111 function checkDate(pObj) {
112 var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
113 if (re.test(pObj.value)==false) {
114 alert('" . _("Invalid date format") . "')
119 $st .= "<input type='button' onclick='javascript:displayReport_" . $this->id ."()' value='" . _("Display: ") . $this->name . "'><br><br>";
121 if ($this->ar_params==null)
123 foreach($this->ar_params as $index=>$param)
125 $st .= $param->param_name . ':<br>';
126 switch ($param->param_type)
129 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) FROM ".TB_PREF."currencies";
130 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Currency Filter"));
139 if ($param->param_type == 'DATEBEGIN')
140 $date = begin_fiscalyear();
141 elseif ($param->param_type == 'DATEEND')
142 $date = end_fiscalyear();
145 if ($param->param_type == 'DATEBEGINM')
146 $date = begin_month($date);
147 elseif ($param->param_type == 'DATEENDM')
148 $date = end_month($date);
149 elseif ($param->param_type == 'DATEBEGINTAX' || $param->param_type == 'DATEENDTAX')
151 $row = get_company_prefs();
152 $edate = add_months($date, -$row['tax_last']);
153 $edate = end_month($edate);
154 if ($param->param_type == 'DATEENDTAX')
158 $bdate = add_months($edate, -$row['tax_prd'] + 1);
159 $date = begin_month($bdate);
162 $name = "RP_" . $this->id . "_$index";
163 //$st .= "<input type='text' name='$name' value='$date' onblur='javascript:checkDate(this)'>";
164 $st .= "<input type='text' name='$name' value='$date'>";
165 if ($use_date_picker)
166 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
167 . " <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";
171 $sel = array(_('No'), _("Yes"));
172 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
175 $sel = array(_("No Payment Link"), "PayPal");
176 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
179 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
180 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
183 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), _("Dots"), _("Lines"), _("Pie"), _("Donut"));
184 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
187 $st .= dup_systypes_list("RP_" . $this->id . "_$index", $dummy, true, _("No Type Filter"), true);
190 $st .= "<input type='text' name='RP_" . $this->id . "_$index'>";
193 $st .= "<textarea rows=4 cols=30 name='RP_" . $this->id . "_$index'></textarea>";
196 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
197 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Account Group Filter"), true);
200 $sql = "SELECT account_code, concat(account_code, ' - ', account_name) as account_name FROM ".TB_PREF."chart_master ORDER BY account_code";
201 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
203 case 'BANK_ACCOUNTS':
204 $sql = "SELECT ".TB_PREF."bank_accounts.account_code, concat(bank_account_name, if (bank_curr_code=curr_default,'', concat(' - ', bank_curr_code))) FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master, ".TB_PREF."company
205 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
206 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
209 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
210 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
213 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
214 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
217 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
218 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
221 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
222 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
225 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
226 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
229 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
230 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
232 case 'CUSTOMERS_NO_FILTER':
234 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master ORDER BY name";
235 if ($param->param_type == 'CUSTOMERS_NO_FILTER')
236 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Customer Filter"), true);
238 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
240 case 'SUPPLIERS_NO_FILTER':
242 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers ORDER BY supp_name";
243 if ($param->param_type == 'SUPPLIERS_NO_FILTER')
244 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Supplier Filter"), true);
246 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
251 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
252 ".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
253 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";
254 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
259 concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
260 ".TB_PREF."debtors_master.name) as IName
261 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
262 WHERE type=13 AND ".TB_PREF."debtors_master.debtor_no=".
263 TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
264 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
267 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
268 ".TB_PREF."debtors_master.name) as IName
269 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";
270 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
273 $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.order_no, '-',
274 ".TB_PREF."suppliers.supp_name) as IName
275 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";
276 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
279 $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";
280 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
283 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations ORDER BY location_name";
284 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Location Filter"), false);
287 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category ORDER BY description";
288 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Category Filter"), true);
291 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types ORDER BY sales_type";
292 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
295 $sql = "SELECT area_code, description FROM ".TB_PREF."areas ORDER BY description";
296 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Area Filter"), true);
299 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman ORDER BY salesman_name";
300 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Sales Folk Filter"), true);
303 $sql = "SELECT DISTINCT YEAR(tran_date), YEAR(tran_date) FROM ".TB_PREF."gl_trans";
304 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
306 case 'ACCOUNTS_NO_FILTER':
307 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
308 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
323 function ReportParam($param_name, $param_type)
325 $this->param_name = $param_name;
326 $this->param_type = $param_type;
330 function dup_simple_codeandname_list($sql, $name, &$selected_id,
331 $all_option=false, $all_option_name=null, $all_option_numeric=false,
332 $submit_on_change=false)
334 if ($submit_on_change == true)
335 $st = "<select name='$name' onchange='this.form.submit();'>";
337 $st = "<select name='$name'>";
339 if ($all_option == true)
341 if ($all_option_numeric)
342 $reserved_word = reserved_words::get_all_numeric();
344 $reserved_word = reserved_words::get_all();
346 if ($reserved_word == $selected_id)
348 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
352 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
354 if ($selected_id == "")
356 $selected_id = $reserved_word;
360 $result = db_query($sql);
362 while ($row = db_fetch_row($result))
364 if ($selected_id == $row[0])
366 $st .= "<option selected value='" . $row[0] . "'>";
370 $st .= "<option value='" . $row[0] . "'>";
372 $st .= $row[1] . "</option>\n";
374 if ($selected_id == "")
376 $selected_id = $row[0];
381 db_free_result($result);
386 function dup_simple_name_list($name, $selections)
388 $st = "<select name='$name'>";
389 for ($i = 0; $i < count($selections); $i++)
390 $st .= "<option value='" . $i . "'>" . $selections[$i] . "</option>\n";
395 //------------------------------------------------------------------------------------------------
397 function dup_systypes_list($name, &$selected_id, $all_option=false, $all_option_name=null)
399 global $systypes_array;
401 $st = "<select name='$name'>";
402 if ($all_option == true)
404 $reserved_word = reserved_words::get_all_numeric();
405 if ($reserved_word == $selected_id)
406 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
408 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
409 if ($selected_id == "")
410 $selected_id = $reserved_word;
413 foreach ($systypes_array as $i => $value)
415 if ($i == 16 || $i == 18 || $i == 25 || ($i >= 28 && $i <= 30) || $i >= 40)
417 $st .= "<option" . ($selected_id == $i ? " selected" : "") . " value='$i'>" . $value['name'] . "</option>\n";