GNU General Public License for more details. You should have received a copy of the GNU General Public License in the file license.txt along with IT CORE; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *********************************************************************************/ include '../../../../config.php'; include $FANNIE_ROOT . 'classlib2.0/FannieAPI.php'; $dbc = FannieDB::get($FANNIE_OP_DB); if (isset($_REQUEST['submit'])) { $d1 = $_REQUEST['date1']; $d2 = $_REQUEST['date2']; $dlog = DTransactionsModel::selectDlog($d1, $d2); if (isset($_REQUEST['excel'])) { $ext = \COREPOS\Fannie\API\data\DataConvert::excelFileExtension(); header("Content-Disposition: inline; filename=local_{$d1}_{$d2}.{$ext}"); header("Content-type: application/vnd.ms-excel; name='excel'"); ob_start(); } else { printf("<a href=index.php?date1=%s&date2=%s&submit=yes&excel=yes>Save to Excel</a>", $d1, $d2); } $sales = $dbc->prepare_statement("SELECT t.department,d.dept_name,s.superID,n.super_name,\n sum(case when numflag = 2 then total else 0 end) as localSales,\n sum(case when numflag = 1 then total else 0 end) as scSales,\n sum(total) as allSales\n FROM {$dlog} as t inner join departments as d\n ON t.department=d.dept_no LEFT JOIN \n MasterSuperDepts AS s ON s.dept_ID=t.department\n LEFT JOIN superDeptNames AS n ON s.superID=n.superID\n WHERE \n tdate BETWEEN ? AND ?\n and trans_type = 'I'\n and s.superID > 0\n AND upc Not IN ('RRR','DISCOUNT')\n group by t.department,d.dept_name,s.superID,n.super_name\n order by s.superID,t.department"); $result = $dbc->exec_statement($sales, array($d1 . ' 00:00:00', $d2 . ' 23:59:59')); $sID = -1; $sname = ""; $sttl = 0; $slocal = 0; $sc = 0; $master_totals = array(0, 0, 0); echo '<table cellspacing="0" cellpadding="4" border="1">';
/** Format data for display @param $data a two dimensional array of data @param $headers a header row (optional) @param $format output format (html | xls | csv) @return formatted string */ public function render_data($data, $headers = array(), $footers = array(), $format = 'html') { $url = $this->config->get('URL'); $ret = ""; switch (strtolower($format)) { case 'html': if ($this->multi_counter == 1) { if (!$this->new_tablesorter) { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // windows has trouble with symlinks $this->add_css_file($url . 'src/javascript/tablesorter-2.0.5b/themes/blue/style.css'); } else { $this->add_css_file($url . 'src/javascript/tablesorter/themes/blue/style.css'); } } else { $this->add_css_file($url . 'src/javascript/tablesorter-2.22.1/css/theme.bootstrap.css'); } if (!$this->window_dressing) { $ret .= '<!DOCTYPE html><html><head>' . '<meta http-equiv="Content-Type" ' . 'content="text/html; charset=iso-8859-1">' . '</head><body>'; $ret .= '<script type="text/javascript"> function highlightCell(e) { if ($(this).css(\'background-color\') != \'rgb(255, 255, 0)\') { $(this).css(\'background-color\',\'yellow\'); } else { $(this).css(\'background-color\',\'\'); } } </script>'; } $ret .= '<div id="pre-report-content">'; $uri = filter_input(INPUT_SERVER, 'REQUEST_URI'); if (\COREPOS\Fannie\API\data\DataConvert::excelSupport()) { $ret .= sprintf('<a href="%s%sexcel=xls">Download Excel</a> ', $uri, strstr($uri, '?') === false ? '?' : '&'); } $json = FormLib::queryStringtoJSON(filter_input(INPUT_SERVER, 'QUERY_STRING')); $ret .= sprintf('<a href="%s%sexcel=csv">Download CSV</a> <a href="?json=%s">Back</a>', $uri, strstr($uri, '?') === false ? '?' : '&', base64_encode($json)); $ret = array_reduce($this->defaultDescriptionContent(count($data)), function ($carry, $line) { return $carry . (substr($line, 0, 1) == '<' ? '' : '<br />') . $line; }, $ret); $ret = array_reduce($this->report_description_content(), function ($carry, $line) { return $carry . (substr($line, 0, 1) == '<' ? '' : '<br />') . $line; }, $ret); $ret .= '</div>'; } if ($this->sortable || $this->no_sort_but_style) { $ret .= '<table class="mySortableTable tablesorter tablesorter-bootstrap">'; } else { $ret .= '<table class="mySortableTable" cellspacing="0" cellpadding="4" border="1">' . "\n"; } break; case 'csv': foreach ($this->defaultDescriptionContent(count($data)) as $line) { $ret .= $this->csvLine(array(strip_tags($line))); } foreach ($this->report_description_content() as $line) { $ret .= $this->csvLine(array(strip_tags($line))); } case 'xls': break; } if (!empty($headers)) { $headers1 = $this->select_headers(False); if (!$this->multi_report_mode && strtolower($format) != 'xls') { $this->header_index++; } switch (strtolower($format)) { case 'html': $ret .= '<thead>' . "\n"; $ret .= $this->htmlLine($headers1, True); $ret .= '</thead>' . "\n"; break; case 'csv': $ret .= $this->csvLine($headers1); break; case 'xls': break; } } for ($i = 0; $i < count($data); $i++) { switch (strtolower($format)) { case 'html': if ($i == 0) { $ret .= "<tbody>\n"; } $ret .= $this->htmlLine($data[$i]); if ($i == count($data) - 1) { $ret .= "</tbody>\n"; } break; case 'csv': $ret .= $this->csvLine($data[$i]); break; case 'xls': break; } } if (!empty($footers)) { switch (strtolower($format)) { case 'html': $ret .= '<tfoot>'; // A single footer row if (!is_array($footers[0])) { $ret .= $this->htmlLine($footers, True); // More than one footer row } else { foreach ($footers as $footer) { $ret .= $this->htmlLine($footer, True); } } $ret .= '</tfoot>'; break; case 'csv': // A single footer row if (!is_array($footers[0])) { $ret .= $this->csvLine($footers); // More than one footer row } else { foreach ($footers as $footer) { $ret .= $this->csvLine($footer); } } break; case 'xls': break; } } switch (strtolower($format)) { case 'html': $ret .= '</table>'; $ret = array_reduce($this->report_end_content(), function ($carry, $line) { return $carry . (substr($line, 0, 1) == '<' ? '' : '<br />') . $line; }, $ret); if (!$this->no_jquery && !$this->new_tablesorter) { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // windows has trouble with symlinks $this->add_script($url . 'src/javascript/jquery-1.11.1/jquery-1.11.1.min.js'); } else { $this->add_script($url . 'src/javascript/jquery.js'); } } if (!$this->new_tablesorter) { if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { // windows has trouble with symlinks $this->add_script($url . 'src/javascript/tablesorter-2.0.5b/jquery.tablesorter.js'); } else { $this->add_script($url . 'src/javascript/tablesorter/jquery.tablesorter.js'); } } else { $this->add_script($url . 'src/javascript/tablesorter-2.22.1/js/jquery.tablesorter.js'); $this->add_script($url . 'src/javascript/tablesorter-2.22.1/js/jquery.tablesorter.widgets.js'); } $sort = sprintf('[[%d,%d]]', $this->sort_column, $this->sort_direction); if ($this->sortable) { if (!$this->new_tablesorter) { $this->add_onload_command("\$('.mySortableTable').tablesorter({sortList: {$sort}, widgets: ['zebra']});"); } else { $this->add_onload_command("\$.tablesorter.themes.bootstrap['active'] = 'info';"); $this->add_onload_command("\$.tablesorter.themes.bootstrap['table'] += ' tablesorter-core table-condensed small';"); $this->add_onload_command("\$.tablesorter.themes.bootstrap['header'] += ' table-condensed small';"); $this->add_onload_command("\$('.mySortableTable').tablesorter({sortList: {$sort}, theme:'bootstrap', headerTemplate: '{content} {icon}', widgets: ['uitheme','zebra']});"); } } elseif ($this->new_tablesorter) { /** New bootstrap-themed tablesorter requires more setup to style correctly even when sorting isn't used. Simply including a CSS file is not sufficient. */ $this->add_onload_command("\$.tablesorter.themes.bootstrap['active'] = 'info';"); $this->add_onload_command("\$.tablesorter.themes.bootstrap['table'] += ' tablesorter-core table-condensed small';"); $this->add_onload_command("\$.tablesorter.themes.bootstrap['header'] += ' table-condensed small';"); $this->add_onload_command("\$('.mySortableTable thead th').data('sorter', false);\n"); $this->add_onload_command("\$('.mySortableTable').tablesorter({theme:'bootstrap', headerTemplate: '{content} {icon}', widgets: ['uitheme','zebra']});"); } break; case 'csv': header('Content-Type: application/ms-excel'); header('Content-Disposition: attachment; filename="' . $this->header . '.csv"'); foreach ($this->report_end_content() as $line) { $ret .= $this->csvLine(array(strip_tags($line))); } break; case 'xls': // headers empty in multi-report-mode if (!empty($headers)) { $headers1 = $this->select_headers(True); array_unshift($data, $headers1); } if (!$this->multi_report_mode) { $data = $this->xlsMeta($data); } for ($i = 0; $i < count($data); $i++) { for ($j = 0; $j < count($data[$i]); $j++) { if (isset($data[$i][$j])) { $data[$i][$j] = $this->excelFormat($data[$i][$j]); } } } $xlsdata = $data; // footers empty in multi-report-mode if (!empty($footers)) { // A single footer row if (!is_array($footers[0])) { array_push($xlsdata, $footers); // More than one footer row } else { $xlsdata = array_reduce($footers, function ($carry, $footer) { $carry[] = $footer; return $carry; }, $xlsdata); } } $xlsdata = array_reduce($this->report_end_content(), function ($carry, $line) { $carry[] = strip_tags($line); return $carry; }, $xlsdata); $xlsdata = array_merge(array_reduce($this->report_description_content(), function ($carry, $line) { $carry[] = strip_tags($line); return $carry; }, array()), $xlsdata); // prepend $xlsdata = array_merge(array_reduce($this->defaultDescriptionContent(count($data)), function ($carry, $line) { $carry[] = strip_tags($line); return $carry; }, array()), $xlsdata); // prepend $ext = \COREPOS\Fannie\API\data\DataConvert::excelFileExtension(); $ret = \COREPOS\Fannie\API\data\DataConvert::arrayToExcel($xlsdata); header('Content-Type: application/ms-excel'); header('Content-Disposition: attachment; filename="' . $this->header . '.' . $ext . '"'); break; } $this->multi_counter++; $this->header_index++; return $ret; }