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 $comp_path, $path_to_root, $use_date_picker;
90 $rep_file = $comp_path.'/'.user_company().
91 "/reporting/rep".$this->id.".php";
92 if (!file_exists($rep_file))
93 $rep_file = $path_to_root ."/reporting/rep".$this->id.".php";
96 <script language='javascript'>
97 function displayReport_" . $this->id . "() {
98 pParamCount = " . count($this->ar_params) . ";
99 document.forms[0].REP_ID.value = " . $this->id . ";
100 document.forms[0].PARAM_COUNT.value = pParamCount;
101 for (i=0; i<pParamCount; i++) {
102 eval('document.forms[0].PARAM_' + i + '.value=document.forms[0].RP_" . $this->id . "_' + i + '.value');
105 window.open('','REP_WINDOW','toolbar=no,scrollbar=no,resizable=yes,menubar=no');
106 document.forms[0].target='REP_WINDOW';
107 document.forms[0].action= '$rep_file';
108 document.forms[0].submit();
110 function checkDate(pObj) {
111 var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
112 if (re.test(pObj.value)==false) {
113 alert('" . _("Invalid date format") . "')
118 $st .= "<input type='button' onclick='javascript:displayReport_" . $this->id ."()' value='" . _("Display: ") . $this->name . "'><br><br>";
120 if ($this->ar_params==null)
122 foreach($this->ar_params as $index=>$param)
124 $st .= $param->param_name . ':<br>';
125 switch ($param->param_type)
128 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) FROM ".TB_PREF."currencies";
129 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Currency Filter"));
138 if ($param->param_type == 'DATEBEGIN')
139 $date = begin_fiscalyear();
140 elseif ($param->param_type == 'DATEEND')
141 $date = end_fiscalyear();
144 if ($param->param_type == 'DATEBEGINM')
145 $date = begin_month($date);
146 elseif ($param->param_type == 'DATEENDM')
147 $date = end_month($date);
148 elseif ($param->param_type == 'DATEBEGINTAX' || $param->param_type == 'DATEENDTAX')
150 $row = get_company_prefs();
151 $edate = add_months($date, -$row['tax_last']);
152 $edate = end_month($edate);
153 if ($param->param_type == 'DATEENDTAX')
157 $bdate = add_months($edate, -$row['tax_prd'] + 1);
158 $date = begin_month($bdate);
161 $name = "RP_" . $this->id . "_$index";
162 //$st .= "<input type='text' name='$name' value='$date' onblur='javascript:checkDate(this)'>";
163 $st .= "<input type='text' name='$name' value='$date'>";
164 if ($use_date_picker)
165 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
166 . " <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";
170 $sel = array(_('No'), _("Yes"));
171 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
174 $sel = array(_("No Payment Link"), "PayPal");
175 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
178 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
179 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
182 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), _("Dots"), _("Lines"), _("Pie"), _("Donut"));
183 $st .= dup_simple_name_list("RP_" . $this->id . "_$index", $sel);
186 $st .= dup_systypes_list("RP_" . $this->id . "_$index", $dummy, true, _("No Type Filter"), true);
189 $st .= "<input type='text' name='RP_" . $this->id . "_$index'>";
192 $st .= "<textarea rows=4 cols=30 name='RP_" . $this->id . "_$index'></textarea>";
195 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
196 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Account Group Filter"), true);
199 $sql = "SELECT account_code, concat(account_code, ' - ', account_name) as account_name FROM ".TB_PREF."chart_master ORDER BY account_code";
200 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
202 case 'BANK_ACCOUNTS':
203 $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
204 WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
205 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
208 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions ORDER BY reference";
209 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
212 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions ORDER BY reference";
213 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
216 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
217 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
220 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1 ORDER BY reference";
221 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
224 $sql = "SELECT reference, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
225 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
228 $sql = "SELECT reference, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2 ORDER BY reference";
229 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Dimension Filter"), true);
231 case 'CUSTOMERS_NO_FILTER':
233 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master ORDER BY name";
234 if ($param->param_type == 'CUSTOMERS_NO_FILTER')
235 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Customer Filter"), true);
237 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
239 case 'SUPPLIERS_NO_FILTER':
241 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers ORDER BY supp_name";
242 if ($param->param_type == 'SUPPLIERS_NO_FILTER')
243 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Supplier Filter"), true);
245 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
250 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
251 ".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
252 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";
253 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
258 concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
259 ".TB_PREF."debtors_master.name) as IName
260 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
261 WHERE type=13 AND ".TB_PREF."debtors_master.debtor_no=".
262 TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
263 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
266 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
267 ".TB_PREF."debtors_master.name) as IName
268 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";
269 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
272 $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.order_no, '-',
273 ".TB_PREF."suppliers.supp_name) as IName
274 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";
275 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
278 $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";
279 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
282 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations ORDER BY location_name";
283 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Location Filter"), false);
286 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category ORDER BY description";
287 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Category Filter"), true);
290 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types ORDER BY sales_type";
291 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
294 $sql = "SELECT area_code, description FROM ".TB_PREF."areas ORDER BY description";
295 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Area Filter"), true);
298 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman ORDER BY salesman_name";
299 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy, true, _("No Sales Folk Filter"), true);
302 $sql = "SELECT DISTINCT YEAR(tran_date), YEAR(tran_date) FROM ".TB_PREF."gl_trans";
303 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
305 case 'ACCOUNTS_NO_FILTER':
306 $sql = "SELECT id, name FROM ".TB_PREF."chart_types ORDER BY name";
307 $st .= dup_simple_codeandname_list($sql, "RP_" . $this->id . "_$index", $dummy);
322 function ReportParam($param_name, $param_type)
324 $this->param_name = $param_name;
325 $this->param_type = $param_type;
329 function dup_simple_codeandname_list($sql, $name, &$selected_id,
330 $all_option=false, $all_option_name=null, $all_option_numeric=false,
331 $submit_on_change=false)
333 if ($submit_on_change == true)
334 $st = "<select name='$name' onchange='this.form.submit();'>";
336 $st = "<select name='$name'>";
338 if ($all_option == true)
340 if ($all_option_numeric)
341 $reserved_word = reserved_words::get_all_numeric();
343 $reserved_word = reserved_words::get_all();
345 if ($reserved_word == $selected_id)
347 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
351 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
353 if ($selected_id == "")
355 $selected_id = $reserved_word;
359 $result = db_query($sql);
361 while ($row = db_fetch_row($result))
363 if ($selected_id == $row[0])
365 $st .= "<option selected value='" . $row[0] . "'>";
369 $st .= "<option value='" . $row[0] . "'>";
371 $st .= $row[1] . "</option>\n";
373 if ($selected_id == "")
375 $selected_id = $row[0];
380 db_free_result($result);
385 function dup_simple_name_list($name, $selections)
387 $st = "<select name='$name'>";
388 for ($i = 0; $i < count($selections); $i++)
389 $st .= "<option value='" . $i . "'>" . $selections[$i] . "</option>\n";
394 //------------------------------------------------------------------------------------------------
396 function dup_systypes_list($name, &$selected_id, $all_option=false, $all_option_name=null)
398 global $systypes_array;
400 $st = "<select name='$name'>";
401 if ($all_option == true)
403 $reserved_word = reserved_words::get_all_numeric();
404 if ($reserved_word == $selected_id)
405 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
407 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
408 if ($selected_id == "")
409 $selected_id = $reserved_word;
412 foreach ($systypes_array as $i => $value)
414 if ($i == 16 || $i == 18 || $i == 25 || $i >= 28)
416 $st .= "<option" . ($selected_id == $i ? " selected" : "") . " value='$i'>" . $value['name'] . "</option>\n";