From 678fcc288a42a014142fb9d7826ccd70dda0c619 Mon Sep 17 00:00:00 2001 From: IbtissamNoukta Date: Wed, 25 Jan 2023 05:14:50 +0100 Subject: [PATCH] Add export for report (Excel) still not working package => laravel excel --- app/Exports/SalesExport.php | 34 ++++++ composer.json | 4 +- composer.lock | 137 +++++++++++++++++++++-- config/app.php | 3 +- resources/views/reports/export.blade.php | 60 ++++++++++ 5 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 app/Exports/SalesExport.php create mode 100644 resources/views/reports/export.blade.php diff --git a/app/Exports/SalesExport.php b/app/Exports/SalesExport.php new file mode 100644 index 0000000..5ae6c1a --- /dev/null +++ b/app/Exports/SalesExport.php @@ -0,0 +1,34 @@ +from = $from; + $this->to = $to; + $this->sales = $sales = Sale::whereBetween("created_at",[$from,$to]) + ->where("payment_status","Paid")->get();; + $this->total = $this->sales->sum("total_price"); + } + + public function view(): View + { + return view('reports.export', [ + 'total' => $this->total, + 'sales' => $this->sales, + 'from' => $this->from, + 'to' => $this->to + + ]); + } +} diff --git a/composer.json b/composer.json index 015de15..3f85a9c 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,9 @@ "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.19", "laravel/sanctum": "^3.0", - "laravel/tinker": "^2.7" + "laravel/tinker": "^2.7", + "maatwebsite/excel": "^1.1", + "psr/simple-cache": "2.0" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index b87b8a0..030bce7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f15ecd80592498840a214b170e85dfbe", + "content-hash": "886840a0b3da90d44d816253c4a912b6", "packages": [ { "name": "brick/math", @@ -1656,6 +1656,65 @@ ], "time": "2022-04-17T13:12:02+00:00" }, + { + "name": "maatwebsite/excel", + "version": "v1.1.5", + "source": { + "type": "git", + "url": "https://github.com/Maatwebsite/Laravel-Excel.git", + "reference": "0c67aba8387726458d42461eae91a3415593bbc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Maatwebsite/Laravel-Excel/zipball/0c67aba8387726458d42461eae91a3415593bbc4", + "reference": "0c67aba8387726458d42461eae91a3415593bbc4", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "phpoffice/phpexcel": "~1.8.0" + }, + "require-dev": { + "mockery/mockery": "~0.9", + "orchestra/testbench": "~2.2.0@dev", + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Maatwebsite\\Excel\\": "src/" + }, + "classmap": [ + "src/Maatwebsite/Excel", + "tests/TestCase.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL" + ], + "authors": [ + { + "name": "Maatwebsite.nl", + "email": "patrick@maatwebsite.nl" + } + ], + "description": "An eloquent way of importing and exporting Excel and CSV in Laravel 4 with the power of PHPExcel", + "keywords": [ + "PHPExcel", + "batch", + "csv", + "excel", + "export", + "import", + "laravel" + ], + "support": { + "issues": "https://github.com/Maatwebsite/Laravel-Excel/issues", + "source": "https://github.com/Maatwebsite/Laravel-Excel/tree/master" + }, + "time": "2014-07-10T09:06:07+00:00" + }, { "name": "monolog/monolog", "version": "2.8.0", @@ -2149,6 +2208,68 @@ ], "time": "2022-12-20T19:00:15+00:00" }, + { + "name": "phpoffice/phpexcel", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/PHPOffice/PHPExcel.git", + "reference": "372c7cbb695a6f6f1e62649381aeaa37e7e70b32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPOffice/PHPExcel/zipball/372c7cbb695a6f6f1e62649381aeaa37e7e70b32", + "reference": "372c7cbb695a6f6f1e62649381aeaa37e7e70b32", + "shasum": "" + }, + "require": { + "ext-xml": "*", + "ext-xmlwriter": "*", + "php": ">=5.2.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "PHPExcel": "Classes/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL" + ], + "authors": [ + { + "name": "Maarten Balliauw", + "homepage": "http://blog.maartenballiauw.be" + }, + { + "name": "Mark Baker" + }, + { + "name": "Franck Lefevre", + "homepage": "http://blog.rootslabs.net" + }, + { + "name": "Erik Tilt" + } + ], + "description": "PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine", + "homepage": "http://phpexcel.codeplex.com", + "keywords": [ + "OpenXML", + "excel", + "php", + "spreadsheet", + "xls", + "xlsx" + ], + "support": { + "issues": "https://github.com/PHPOffice/PHPExcel/issues", + "source": "https://github.com/PHPOffice/PHPExcel/tree/master" + }, + "abandoned": "phpoffice/phpspreadsheet", + "time": "2015-05-01T07:00:55+00:00" + }, { "name": "phpoption/phpoption", "version": "1.9.0", @@ -2539,16 +2660,16 @@ }, { "name": "psr/simple-cache", - "version": "3.0.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/php-fig/simple-cache.git", - "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865" + "reference": "8707bf3cea6f710bf6ef05491234e3ab06f6432a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865", - "reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/8707bf3cea6f710bf6ef05491234e3ab06f6432a", + "reference": "8707bf3cea6f710bf6ef05491234e3ab06f6432a", "shasum": "" }, "require": { @@ -2557,7 +2678,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -2584,9 +2705,9 @@ "simple-cache" ], "support": { - "source": "https://github.com/php-fig/simple-cache/tree/3.0.0" + "source": "https://github.com/php-fig/simple-cache/tree/2.0.0" }, - "time": "2021-10-29T13:26:27+00:00" + "time": "2021-10-29T13:22:09+00:00" }, { "name": "psy/psysh", diff --git a/config/app.php b/config/app.php index ef76a7e..544d2e8 100644 --- a/config/app.php +++ b/config/app.php @@ -181,7 +181,6 @@ Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, - /* * Package Service Providers... */ @@ -194,7 +193,6 @@ // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, - ], /* @@ -210,6 +208,7 @@ 'aliases' => Facade::defaultAliases()->merge([ // 'ExampleClass' => App\Example\ExampleClass::class, + 'Excel' => Maatwebsite\Excel\Facades\Excel::class, ])->toArray(), ]; diff --git a/resources/views/reports/export.blade.php b/resources/views/reports/export.blade.php new file mode 100644 index 0000000..eb9fa37 --- /dev/null +++ b/resources/views/reports/export.blade.php @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + @foreach ($sales as $sale) + + + + + + + + + + + @endforeach + + + + + + + +
IdMenusQuantityTablesServersTotalPayment typePayment status
+ {{ $sale->id }} + + @foreach ($sale->menus()->where("sale_id",$sale->id)->get() as $menu) +
{{ $menu->title }}
+
{{ $menu->price }} DH
+ @endforeach +
+ @foreach ($sale->menus()->where("sale_id",$sale->id)->get() as $menu) +
{{ $menu->pivot->quantity }}
+ @endforeach +
+ @foreach ($sale->tables()->where("sale_id", $sale->id)->get() as $table) + {{ $table->name }} + @endforeach + + {{ $sale->servant->name }} + + {{ $sale->total_price }} + + {{ $sale->payment_type === "cash"? "Cash" : "Credit Card" }} + + {{ $sale->payment_status }} +
+ Report from {{ Str::substr($startDate, 0, 10) }} to {{ Str::substr($endDate, 0, 10) }} +
+ Total : {{ $total }} DH