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 set_focus('Rep'.$report->id);
71 $Ajax->addUpdate(true, 'rep_form', $st_params);
74 $st_reports .= "</table>";
78 $st_params = "<div id='rep_form'>".
82 $st = "<script language='javascript'>
83 function showClass(pClass) {
84 for(i=0; i<$class_counter; i++) {
85 document.getElementById(\"TAB_\" + i).style.display=
86 i==pClass ? \"block\" : \"none\";
88 document.getElementById('rep_form').innerHTML = '';
89 // document.getElementById('rep_form').style.display = 'none';
92 function checkDate(pObj) {
93 var re = /^(3[01]|0[1-9]|[12]\d)\/(0[1-9]|1[012])\/\d{4}/;
94 if (re.test(pObj.value)==false) {
95 alert('" . _("Invalid date format") . "')
100 $st .= "<table align='center' width='80%' $table_style2><tr valign='top'>";
101 $st .= "<td width='30%'>$st_classes</td>";
102 $st .= "<td width='35%'>$st_reports</td>";
103 $st .= "<td width='35%'>$st_params</td>";
104 $st .= "</tr></table><br>";
116 function Report($id, $name, $ar_params)
120 $this->ar_params = $ar_params;
123 function getDisplay()
125 global $path_to_root, $use_date_picker, $pdf_debug, $print_invoice_no;
129 if ($this->ar_params==null)
131 foreach($this->ar_params as $index=>$param)
133 $st .= $param->param_name . ':<br>';
134 switch ($param->param_type)
137 $sql = "SELECT curr_abrev, concat(curr_abrev,' - ', currency) FROM ".TB_PREF."currencies";
138 $st .= dup_simple_codeandname_list($sql, "PARAM_$index", $dummy, true, _("No Currency Filter"));
147 if ($param->param_type == 'DATEBEGIN')
148 $date = begin_fiscalyear();
149 elseif ($param->param_type == 'DATEEND')
150 $date = end_fiscalyear();
153 if ($param->param_type == 'DATEBEGINM')
154 $date = begin_month($date);
155 elseif ($param->param_type == 'DATEENDM')
156 $date = end_month($date);
157 elseif ($param->param_type == 'DATEBEGINTAX' || $param->param_type == 'DATEENDTAX')
159 $row = get_company_prefs();
160 $edate = add_months($date, -$row['tax_last']);
161 $edate = end_month($edate);
162 if ($param->param_type == 'DATEENDTAX')
166 $bdate = begin_month($edate);
167 $bdate = add_months($bdate, -$row['tax_prd'] + 1);
171 $name = "PARAM_$index";
173 $st .= "<input type='text' name='$name' value='$date'>";
174 if ($use_date_picker)
175 $st .= "<a href=\"javascript:date_picker(document.forms[0].$name);\">"
176 . " <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";
180 $sel = array(_('No'), _("Yes"));
181 $st .= dup_simple_name_list("PARAM_$index", $sel);
184 $sel = array(_("No Payment Link"), "PayPal");
185 $st .= dup_simple_name_list("PARAM_$index", $sel);
188 $sel = array(_("PDF/Printer"), "Excel");
189 $st .= dup_simple_name_list("PARAM_$index", $sel);
192 $sel = array(_("Accumulated"), _("Period Y-1"), _("Budget"));
193 $st .= dup_simple_name_list("PARAM_$index", $sel);
196 $sel = array(_("No Graphics"), _("Vertical bars"), _("Horizontal bars"), _("Dots"), _("Lines"), _("Pie"), _("Donut"));
197 $st .= dup_simple_name_list("PARAM_$index", $sel);
200 case 'SYS_TYPES_ALL':
201 $st .= dup_systypes_list("PARAM_$index", $dummy, true, _("No Type Filter"), ($param->param_type=='SYS_TYPES_ALL'));
204 $st .= "<input type='text' name='PARAM_$index'>";
207 $st .= "<textarea rows=4 cols=30 name='PARAM_$index'></textarea>";
210 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
211 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'name',array('spec_option'=>_("No Account Group Filter"),'spec_id'=>ALL_NUMERIC));
214 $sql = "SELECT account_code, concat(account_code, ' - ', account_name) as account_name FROM ".TB_PREF."chart_master";
215 $st .= combo_input("PARAM_$index", '', $sql, 'account_code', 'account_name',array('order'=>array('account_code')));
217 case 'BANK_ACCOUNTS':
218 $sql = "SELECT ".TB_PREF."bank_accounts.id, concat(bank_account_name, if (bank_curr_code=curr_default,'', concat(' - ', bank_curr_code))) AS name FROM ".TB_PREF."bank_accounts, ".TB_PREF."company";
219 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'name',array('order'=>array('id')));
222 $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions";
223 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'DimName',array('order'=>array('reference')));
226 $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions";
227 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'DimName',array('spec_option'=>_("No Dimension Filter"),'spec_id'=>ALL_NUMERIC,'order'=>array('reference')));
230 $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=1";
231 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'DimName',array('order'=>array('reference')));
234 $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=1";
235 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'DimName',array('spec_option'=>_("No Dimension Filter"),'spec_id'=>ALL_NUMERIC,'order'=>array('reference')));
238 $sql = "SELECT id, concat(reference, ' - ', name) AS DimName FROM ".TB_PREF."dimensions WHERE type_=2";
239 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'DimName',array('order'=>array('reference')));
242 $sql = "SELECT id, concat(reference, ' - ', name) as DimName FROM ".TB_PREF."dimensions WHERE type_=2";
243 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'DimName',array('spec_option'=>_("No Dimension Filter"),'spec_id'=>ALL_NUMERIC,'order'=>array('reference')));
245 case 'CUSTOMERS_NO_FILTER':
247 $sql = "SELECT debtor_no, name FROM ".TB_PREF."debtors_master";
248 if ($param->param_type == 'CUSTOMERS_NO_FILTER')
249 $st .= combo_input("PARAM_$index", '', $sql, 'debtor_no', 'name',array('spec_option'=>_("No Customer Filter"),'spec_id'=>ALL_NUMERIC));
251 $st .= combo_input("PARAM_$index", '', $sql, 'debtor_no', 'name', null);
253 case 'SUPPLIERS_NO_FILTER':
255 $sql = "SELECT supplier_id, supp_name FROM ".TB_PREF."suppliers";
256 if ($param->param_type == 'SUPPLIERS_NO_FILTER')
257 $st .= combo_input("PARAM_$index", '', $sql, 'supplier_id', 'supp_name',array('spec_option'=>_("No Supplier Filter"),'spec_id'=>ALL_NUMERIC));
259 $st .= combo_input("PARAM_$index", '', $sql, 'supplier_id', 'supp_name', null);
264 if ($print_invoice_no == 1)
265 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
266 ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, if (type=".ST_SALESINVOICE.", ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
267 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=".ST_SALESINVOICE." OR type=".ST_CUSTCREDIT.") AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
269 $sql = "SELECT concat(".TB_PREF."debtor_trans.trans_no, '-',
270 ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.reference, if (type=".ST_SALESINVOICE.", ' $IV ', ' $CN '), ".TB_PREF."debtors_master.name) as IName
271 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans WHERE (type=".ST_SALESINVOICE." OR type=".ST_CUSTCREDIT.") AND ".TB_PREF."debtors_master.debtor_no=".TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
272 $st .= combo_input("PARAM_$index", '', $sql, 'TNO', 'IName',array('order'=>false));
277 concat(".TB_PREF."debtor_trans.trans_no, '-', ".TB_PREF."debtor_trans.type) AS TNO, concat(".TB_PREF."debtor_trans.trans_no, ' $DN ',
278 ".TB_PREF."debtors_master.name) as IName
279 FROM ".TB_PREF."debtors_master, ".TB_PREF."debtor_trans
280 WHERE type=".ST_CUSTDELIVERY." AND ".TB_PREF."debtors_master.debtor_no=".
281 TB_PREF."debtor_trans.debtor_no ORDER BY ".TB_PREF."debtor_trans.trans_no DESC";
282 $st .= combo_input("PARAM_$index", '', $sql, 'TNO', 'IName',array('order'=>false));
285 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
286 ".TB_PREF."debtors_master.name) as IName
287 FROM ".TB_PREF."debtors_master, ".TB_PREF."sales_orders WHERE ".TB_PREF."debtors_master.debtor_no=".TB_PREF."sales_orders.debtor_no
288 AND ".TB_PREF."sales_orders.trans_type=".ST_SALESORDER." ORDER BY ".TB_PREF."sales_orders.order_no DESC";
289 $st .= combo_input("PARAM_$index", '', $sql, 'order_no', 'IName',array('order'=>false));
292 $sql = "SELECT ".TB_PREF."sales_orders.order_no, concat(".TB_PREF."sales_orders.order_no, '-',
293 ".TB_PREF."debtors_master.name) as IName
294 FROM ".TB_PREF."debtors_master, ".TB_PREF."sales_orders WHERE ".TB_PREF."debtors_master.debtor_no=".TB_PREF."sales_orders.debtor_no
295 AND ".TB_PREF."sales_orders.trans_type=".ST_SALESQUOTE." ORDER BY ".TB_PREF."sales_orders.order_no DESC";
296 $st .= combo_input("PARAM_$index", '', $sql, 'order_no', 'IName',array('order'=>false));
299 $sql = "SELECT ".TB_PREF."purch_orders.order_no, concat(".TB_PREF."purch_orders.order_no, '-',
300 ".TB_PREF."suppliers.supp_name) as IName
301 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";
302 $st .= combo_input("PARAM_$index", '', $sql, 'order_no', 'IName',array('order'=>false));
305 $sql = "SELECT stock_id, concat(stock_id, '-', description) as name FROM ".TB_PREF."stock_master WHERE (mb_flag='A' OR mb_flag='M')";
306 $st .= combo_input("PARAM_$index", '', $sql, 'stock_id', 'name',array('order'=>array('stock_id')));
309 $sql = "SELECT ".TB_PREF."workorders.id, concat(".TB_PREF."workorders.id, '-',
310 ".TB_PREF."stock_master.description) as IName
311 FROM ".TB_PREF."stock_master, ".TB_PREF."workorders WHERE ".TB_PREF."stock_master.stock_id=".TB_PREF."workorders.stock_id ORDER BY ".TB_PREF."workorders.id DESC";
312 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'IName',array('order'=>false));
315 $sql = "SELECT loc_code, location_name FROM ".TB_PREF."locations";
316 $st .= combo_input("PARAM_$index", '', $sql, 'loc_code', 'location_name',array('spec_option'=>_("No Location Filter"),'spec_id'=>ALL_TEXT));
319 $sql = "SELECT category_id, description FROM ".TB_PREF."stock_category";
320 $st .= combo_input("PARAM_$index", '', $sql, 'category_id', 'description',array('spec_option'=>_("No Category Filter"),'spec_id'=>ALL_NUMERIC));
323 $sql = "SELECT id, sales_type FROM ".TB_PREF."sales_types";
324 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'sales_type', null);
327 $sql = "SELECT area_code, description FROM ".TB_PREF."areas";
328 $st .= combo_input("PARAM_$index", '', $sql, 'area_code', 'description',array('spec_option'=>_("No Area Filter"),'spec_id'=>ALL_NUMERIC));
331 $sql = "SELECT salesman_code, salesman_name FROM ".TB_PREF."salesman";
332 $st .= combo_input("PARAM_$index", '', $sql, 'salesman_code', 'salesman_name',array('spec_option'=>_("No Sales Folk Filter"),'spec_id'=>ALL_NUMERIC));
335 $sql = "SELECT DISTINCT YEAR(tran_date) AS tran_date, YEAR(tran_date) AS tran_date2 FROM ".TB_PREF."gl_trans";
336 $st .= combo_input("PARAM_$index", '', $sql, 'tran_date', 'tran_date2',array('order'=>array('tran_date')));
339 $sql = "SELECT id, user_id FROM ".TB_PREF."users";
340 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'user_id',array('spec_option'=>_("No Users Filter"),'spec_id'=>ALL_NUMERIC));
342 case 'ACCOUNTS_NO_FILTER':
343 $sql = "SELECT id, name FROM ".TB_PREF."chart_types";
344 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'name', null);
347 case 'DIMENSIONTAGS':
348 if ($param->param_type == 'ACCOUNTTAGS')
352 $sql = "SELECT id, name FROM ".TB_PREF."tags WHERE type=$type";
353 $st .= combo_input("PARAM_$index", '', $sql, 'id', 'name',array('spec_option'=>_("No tags"),'spec_id' => ALL_NUMERIC,'multi'=>true,'height'=>4));
368 function ReportParam($param_name, $param_type)
370 $this->param_name = $param_name;
371 $this->param_type = $param_type;
375 function dup_simple_name_list($name, $selections)
377 $st = "<select name='$name'>";
378 for ($i = 0; $i < count($selections); $i++)
379 $st .= "<option value='" . $i . "'>" . $selections[$i] . "</option>\n";
384 //------------------------------------------------------------------------------------------------
386 function dup_systypes_list($name, &$selected_id, $all_option=false, $all_option_name=null, $all_types=false)
388 global $systypes_array;
390 $st = "<select name='$name'>";
391 if ($all_option == true)
393 $reserved_word = ALL_NUMERIC;
394 if ($reserved_word == $selected_id)
395 $st .= "<option selected value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
397 $st .= "<option value='" . $reserved_word . "'>" . $all_option_name . "</option>\n";
398 if ($selected_id == "")
399 $selected_id = $reserved_word;
402 foreach ($systypes_array as $i => $value)
404 if (!$all_types && ($i == ST_LOCTRANSFER || $i == ST_PURCHORDER || $i == ST_SUPPRECEIVE || ($i >= ST_MANUISSUE && $i <= ST_SALESQUOTE) ||
407 $st .= "<option" . ($selected_id == $i ? " selected" : "") . " value='$i'>" . $value . "</option>\n";