diff --git a/composer.json b/composer.json index 50d26ba..6088999 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=7.1.0", - "illuminate/support": ">=5.0", + "illuminate/support": "^9.0.0", "maatwebsite/excel": "^3.1" }, "autoload": { diff --git a/readme.md b/readme.md index f14c6e0..394895a 100644 --- a/readme.md +++ b/readme.md @@ -9,6 +9,7 @@ This package provides a simple pdf, csv & excel report generators to speed up yo | 1.0 | <= 5.6 | <=7.0 | ~2.1.0 | using `chunk()` to handle big data | 1.1 | <= 5.6 | <=7.0 | ~2.1.0 | using `cursor()` to handle big data | 2.0 | \>= 5.5 | ^7.0 | ^3.1 | Using new version of maatwebsite (v3.1) +| 3.0 | \>= 9.0 | ^7.0 | ^3.1 | Add support Laravel x9 Find the comparison between `chunk` and `cursor` in [here](https://qiita.com/ryo511/items/ebcd1c1b2ad5addc5c9d) @@ -17,7 +18,7 @@ Add package to your composer: composer require jimmyjs/laravel-report-generator -If you are running Laravel > 5.5 that's all you need to do. If you are using Laravel < 5.5 add the ServiceProvider to the providers array in config/app.php +If you are running Laravel > 9.0 that's all you need to do. If you are using Laravel < 5.5 add the ServiceProvider to the providers array in config/app.php Jimmyjs\ReportGenerator\ServiceProvider::class, @@ -161,7 +162,9 @@ Or, you can total all records by group using `groupBy` method ]) ->groupBy('Registered At') // Show total of value on specific group. Used with showTotal() enabled. ->showTotal([ - 'Total Balance' => 'point' + 'Total Balance' => [ + 'function' => 'sum', // Allow Values sum and avg or function($total) + 'format' => 'point' ]) ->stream(); ``` @@ -312,3 +315,17 @@ ExcelReport::of($title, $meta, $queryBuilder, $columns) ->simple() ->download('filename'); ``` +### 9. setTotalLabel($label) +**Supported Media Type**: PDF, Excel + +**Description**: Set Label for Total + +**Params**: +* None + +**Usage:** +```php +ExcelReport::of($title, $meta, $queryBuilder, $columns) + ->setTotalLabel('Average') + >make(); +``` \ No newline at end of file diff --git a/src/ReportGenerator.php b/src/ReportGenerator.php index 93a186c..a1fe6ea 100644 --- a/src/ReportGenerator.php +++ b/src/ReportGenerator.php @@ -23,6 +23,7 @@ class ReportGenerator protected $withoutManipulation = false; protected $showMeta = true; protected $showHeader = true; + protected $totalLabel = 'Grand Total'; public function __construct() { @@ -99,6 +100,11 @@ public function setPaper($paper) return $this; } + public function setTotalLabel(string $label) { + $this->totalLabel = $label; + return $this; + } + public function editColumn($columnName, Array $options) { foreach ($options as $option => $value) { @@ -124,6 +130,8 @@ public function showTotal(Array $columns) return $this; } + + public function groupBy($column) { if (is_array($column)) { diff --git a/src/ReportMedia/ExcelReport.php b/src/ReportMedia/ExcelReport.php index 2288e48..a2ca033 100644 --- a/src/ReportMedia/ExcelReport.php +++ b/src/ReportMedia/ExcelReport.php @@ -54,13 +54,14 @@ public function make() $styles = $this->styles; $showHeader = $this->showHeader; $showMeta = $this->showMeta; + $totalLabel = $this->totalLabel; $applyFlush = $this->applyFlush; $showNumColumn = $this->showNumColumn; if ($this->withoutManipulation) { - $view = view('laravel-report-generator::without-manipulation-excel-template', compact('headers', 'columns', 'showTotalColumns', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn')); + $view = view('laravel-report-generator::without-manipulation-excel-template', compact('headers', 'columns', 'showTotalColumns', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn', 'totalLabel')); } else { - $view = view('laravel-report-generator::general-excel-template', compact('headers', 'columns', 'editColumns', 'showTotalColumns', 'styles', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn')); + $view = view('laravel-report-generator::general-excel-template', compact('headers', 'columns', 'editColumns', 'showTotalColumns', 'styles', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn', 'totalLabel')); } return new ExportView($view); diff --git a/src/ReportMedia/PdfReport.php b/src/ReportMedia/PdfReport.php index cc4cad9..fbe58b1 100644 --- a/src/ReportMedia/PdfReport.php +++ b/src/ReportMedia/PdfReport.php @@ -19,13 +19,14 @@ public function make() $styles = $this->styles; $showHeader = $this->showHeader; $showMeta = $this->showMeta; + $totalLabel = $this->totalLabel; $showNumColumn = $this->showNumColumn; $applyFlush = $this->applyFlush; if ($this->withoutManipulation) { - $html = \View::make('laravel-report-generator::without-manipulation-pdf-template', compact('headers', 'columns', 'showTotalColumns', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn'))->render(); + $html = \View::make('laravel-report-generator::without-manipulation-pdf-template', compact('headers', 'columns', 'showTotalColumns', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn', 'totalLabel'))->render(); } else { - $html = \View::make('laravel-report-generator::general-pdf-template', compact('headers', 'columns', 'editColumns', 'showTotalColumns', 'styles', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn'))->render(); + $html = \View::make('laravel-report-generator::general-pdf-template', compact('headers', 'columns', 'editColumns', 'showTotalColumns', 'styles', 'query', 'limit', 'groupByArr', 'orientation', 'showHeader', 'showMeta', 'applyFlush', 'showNumColumn', 'totalLabel'))->render(); } try { diff --git a/src/views/general-excel-template.blade.php b/src/views/general-excel-template.blade.php index f2e2fe2..bdaae2c 100644 --- a/src/views/general-excel-template.blade.php +++ b/src/views/general-excel-template.blade.php @@ -110,15 +110,29 @@ if ($isOnSameGroup === false) { echo '