Include totals in exported report

This commit is contained in:
Hillel Coren 2017-10-22 11:27:42 +03:00
parent 002665b2db
commit 715838d401

View File

@ -147,10 +147,16 @@ class ReportController extends BaseController
} }
//Get labeled header //Get labeled header
$columns_labeled = $report->tableHeaderArray(); $data = array_merge(
[
array_map(function($col) {
return $col['label'];
}, $report->tableHeaderArray())
],
$data
);
$summary = []; $summary = [];
/*
if (count(array_values($totals))) { if (count(array_values($totals))) {
$summary[] = array_merge([ $summary[] = array_merge([
trans("texts.totals") trans("texts.totals")
@ -163,49 +169,59 @@ class ReportController extends BaseController
foreach ($each as $dimension => $val) { foreach ($each as $dimension => $val) {
$tmp = []; $tmp = [];
$tmp[] = Utils::getFromCache($currencyId, 'currencies')->name . (($dimension) ? ' - ' . $dimension : ''); $tmp[] = Utils::getFromCache($currencyId, 'currencies')->name . (($dimension) ? ' - ' . $dimension : '');
foreach ($val as $id => $field) { foreach ($val as $id => $field) {
$tmp[] = Utils::formatMoney($field, $currencyId); $tmp[] = Utils::formatMoney($field, $currencyId);
} }
$summary[] = $tmp; $summary[] = $tmp;
} }
} }
*/
return Excel::create($filename, function($excel) use($report, $data, $reportType, $format, $columns_labeled, $summary) { return Excel::create($filename, function($excel) use($report, $data, $reportType, $format, $summary) {
$excel->sheet(trans("texts.$reportType"), function($sheet) use($report, $data, $format, $columns_labeled, $summary) {
$excel->sheet(trans("texts.$reportType"), function($sheet) use($report, $data, $format, $summary) {
$sheet->setOrientation('landscape'); $sheet->setOrientation('landscape');
$sheet->freezeFirstRow(); $sheet->freezeFirstRow();
if ($format == 'pdf') { if ($format == 'pdf') {
$sheet->setAllBorders('thin'); $sheet->setAllBorders('thin');
} }
$sheet->rows(array_merge( if ($format == 'csv') {
[array_map(function($col) {return $col['label'];}, $columns_labeled)], $sheet->rows(array_merge($data, [[]], $summary));
$data } else {
)); $sheet->rows($data);
}
/*
$sheet->rows(array_merge(
[],
$summary
));
*/
// Styling header // Styling header
$sheet->cells('A1:'.Utils::num2alpha(count($columns_labeled)-1).'1', function($cells) { $sheet->cells('A1:'.Utils::num2alpha(count($data[0])-1).'1', function($cells) {
$cells->setBackground('#777777'); $cells->setBackground('#777777');
$cells->setFontColor('#FFFFFF'); $cells->setFontColor('#FFFFFF');
$cells->setFontSize(13); $cells->setFontSize(13);
$cells->setFontFamily('Calibri'); $cells->setFontFamily('Calibri');
$cells->setFontWeight('bold'); $cells->setFontWeight('bold');
}); });
$sheet->setAutoSize(true); $sheet->setAutoSize(true);
}); });
$excel->sheet(trans("texts.totals"), function($sheet) use($report, $summary, $format) {
$sheet->setOrientation('landscape');
$sheet->freezeFirstRow();
if ($format == 'pdf') {
$sheet->setAllBorders('thin');
}
$sheet->rows($summary);
// Styling header
$sheet->cells('A1:'.Utils::num2alpha(count($summary[0])-1).'1', function($cells) {
$cells->setBackground('#777777');
$cells->setFontColor('#FFFFFF');
$cells->setFontSize(13);
$cells->setFontFamily('Calibri');
$cells->setFontWeight('bold');
});
$sheet->setAutoSize(true);
});
})->export($format); })->export($format);
} }
} }