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 $st_classes .= "<a href='javascript:showClass($class_counter)'>$key</a> <br>";
35 $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>";
36 foreach($value as $report)
38 $st_reports .= "<tr><td><a href='javascript:showReport($rep_counter)'>" . $report->name . "</a></td></tr>";
39 $st_params .= "<table border=0 id='REP_" . $rep_counter++ . "' style='display:none'>";
40 $st_params .= "<tr><td>" . $report->getDisplay() . "</td></tr></table>";
42 $st_reports .= "</table>";
45 $st = "<script language='javascript'>
46 function showClass(pClass) {
47 for(i=0; i<$class_counter; i++) {
48 eval('document.getElementById(\"TAB_\" + i).style.display=\"none\"')
50 eval('document.getElementById(\"TAB_\" + pClass).style.display=\"block\"')
51 for (i=0; i<$rep_counter; i++) {
52 eval('document.getElementById(\"REP_\" + i).style.display=\"none\"')
55 function showReport(pId) {
57 for(i=0; i<$rep_counter; i++) {
58 eval('document.getElementById(\"REP_\" + i).style.display=\"none\"')
60 eval('document.getElementById(\"REP_\" + pId).style.display=\"block\"')
64 $st .= "<table align='center' width='80%' $table_style2><tr valign='top'>";
65 $st .= "<td width='30%'>$st_classes</td>";
66 $st .= "<td width='35%'>$st_reports</td>";
67 $st .= "<td width='35%'>$st_params</td>";
68 $st .= "</tr></table><br>";
80 function Report($id, $name, $ar_params)
84 $this->ar_params = $ar_params;
88 global $path_to_root, $use_date_picker;
90 <script language='javascript'>
91 function displayReport_" . $this->id . "() {
92 pParamCount = " . count($this->ar_params) . ";
93 document.forms[0].REP_ID.value = " . $this->id . ";
94 document.forms[0].PARAM_COUNT.value = pParamCount;
95 for (i=0; i<pParamCount; i++) {
96 eval('document.forms[0].PARAM_' + i + '.value=document.forms[0].RP_" . $this->id . "_' + i + '.value');
99 window.open('','REP_WINDOW','toolbar=no,scrollbar=no,resizable=yes,menubar=no');
100 document.forms[0].target='REP_WINDOW';
101 document.forms[0].action= '" . $path_to_root . "/reporting/rep" . $this->id . ".php';
102 document.forms[0].submit();
104 function checkDate(pObj) {
105 var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
106 if (re.test(pObj.value)==false) {
107 alert('" . _("Invalid date format") . "')
112 $st .= "<input type='button' onclick='javascript:displayReport_" . $this->id ."()' value='" . _("Display: ") . $this->name . "'><br><br>";
114 if ($this->ar_params==null)
116 foreach($this->ar_params as $index=>$param)
118 $st .= $param->param_name . ':<br>';
119 switch ($param->param_type)
122 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) FROM ".TB_PREF."currencies";
123 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Currency Filter"));
132 if ($param->param_type == 'DATEBEGIN')
133 $date = begin_fiscalyear();
134 elseif ($param->param_type == 'DATEEND')
135 $date = end_fiscalyear();
138 if ($param->param_type == 'DATEBEGINM')
139 $date = begin_month($date);
140 elseif ($param->param_type == 'DATEENDM')
141 $date = end_month($date);
142 elseif ($param->param_type == 'DATEBEGINTAX' || $param->param_type == 'DATEENDTAX')
144 $row = get_company_prefs();
145 $edate = add_months($date, -$row['tax_last']);
146 $edate = end_month($edate);
147 if ($param->param_type == 'DATEENDTAX')
151 $bdate = add_months($edate, -$row['tax_prd'] + 1);
152 $date = begin_month($bdate);
155 $name = "RP_" . $this->id . "_$index";
156 //$st .= "<input type='text' name='$name' value='$date' onblur='javascript:checkDate(this)'>";
157 $st .= "<input type='text' name='$name' value='$date'>";
158 if ($use_date_picker)
159 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
160 . " <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";
164 $sel = array(_('No'), _("Yes"));
165 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
168 $sel = array(_("No Payment Link"), "PayPal");
169 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
172 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
173 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
176 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), _("Dots"), _("Lines"), _("Pie"), _("Donut"));
177 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
180 $st .= dup_systypes_list("RP_" . $this->id . "_$index", $dummy, true, _("No Type Filter"), true);
183 $st .= "<input type='text' name='RP_" . $this->id . "_$index'>";
186 $st .= "<textarea rows=4 cols=30 name='RP_" . $this->id . "_$index'></textarea>";
189 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
190 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Account Group Filter"), true);
193 $sql = "SELECT account_code, concat(account_code, ' - ', account_name) as account_name FROM ".TB_PREF."chart_master ORDER BY account_code";
194 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
196 case 'BANK_ACCOUNTS':
197 $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
198 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
199 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
202 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
203 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
206 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
207 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
210 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
211 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
214 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
215 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
218 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
219 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
222 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
223 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
225 case 'CUSTOMERS_NO_FILTER':
227 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master ORDER BY name";
228 if ($param->param_type == 'CUSTOMERS_NO_FILTER')
229 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Customer Filter"), true);
231 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
233 case 'SUPPLIERS_NO_FILTER':
235 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers ORDER BY supp_name";
236 if ($param->param_type == 'SUPPLIERS_NO_FILTER')
237 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Supplier Filter"), true);
239 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
244 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
245 ".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
246 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";
247 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
252 concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
253 ".TB_PREF."debtors_master.name) as IName
254 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
255 WHERE type=13 AND ".TB_PREF."debtors_master.debtor_no=".
256 TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
257 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
260 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
261 ".TB_PREF."debtors_master.name) as IName
262 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";
263 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
266 $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.order_no, '-',
267 ".TB_PREF."suppliers.supp_name) as IName
268 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";
269 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
272 $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";
273 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
276 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations ORDER BY location_name";
277 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Location Filter"), false);
280 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category ORDER BY description";
281 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Category Filter"), true);
284 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types ORDER BY sales_type";
285 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
288 $sql = "SELECT area_code, description FROM ".TB_PREF."areas ORDER BY description";
289 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Area Filter"), true);
292 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman ORDER BY salesman_name";
293 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Sales Folk Filter"), true);
296 $sql = "SELECT DISTINCT YEAR(tran_date), YEAR(tran_date) FROM ".TB_PREF."gl_trans";
297 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
299 case 'ACCOUNTS_NO_FILTER':
300 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
301 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
316 function ReportParam($param_name, $param_type)
318 $this->param_name = $param_name;
319 $this->param_type = $param_type;
323 function dup_simple_codeandname_list($sql, $name, &$selected_id,
324 $all_option=false, $all_option_name=null, $all_option_numeric=false,
325 $submit_on_change=false)
327 if ($submit_on_change == true)
328 $st = "<select name='$name' onchange='this.form.submit();'>";
330 $st = "<select name='$name'>";
332 if ($all_option == true)
334 if ($all_option_numeric)
335 $reserved_word = reserved_words::get_all_numeric();
337 $reserved_word = reserved_words::get_all();
339 if ($reserved_word == $selected_id)
341 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
345 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
347 if ($selected_id == "")
349 $selected_id = $reserved_word;
353 $result = db_query($sql);
355 while ($row = db_fetch_row($result))
357 if ($selected_id == $row[0])
359 $st .= "<option selected value='" . $row[0] . "'>";
363 $st .= "<option value='" . $row[0] . "'>";
365 $st .= $row[1] . "</option>\n";
367 if ($selected_id == "")
369 $selected_id = $row[0];
374 db_free_result($result);
379 function dup_simple_name_list($name, $selections)
381 $st = "<select name='$name'>";
382 for ($i = 0; $i < count($selections); $i++)
383 $st .= "<option value='" . $i . "'>" . $selections[$i] . "</option>\n";
388 //------------------------------------------------------------------------------------------------
390 function dup_systypes_list($name, &$selected_id, $all_option=false, $all_option_name=null)
392 global $systypes_array;
394 $st = "<select name='$name'>";
395 if ($all_option == true)
397 $reserved_word = reserved_words::get_all_numeric();
398 if ($reserved_word == $selected_id)
399 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
401 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
402 if ($selected_id == "")
403 $selected_id = $reserved_word;
406 foreach ($systypes_array as $i => $value)
408 if ($i == 16 || $i == 18 || $i == 25 || $i >= 28)
410 $st .= "<option" . ($selected_id == $i ? " selected" : "") . " value='$i'>" . $value['name'] . "</option>\n";