Skip to content

Commit

Permalink
Add export for report (Excel)
Browse files Browse the repository at this point in the history
still not working package => laravel excel
  • Loading branch information
IbtissamNoukta committed Jan 25, 2023
1 parent 97acd5a commit 678fcc2
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 11 deletions.
34 changes: 34 additions & 0 deletions app/Exports/SalesExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Exports;

use App\Sale;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;

class SalesExport implements FromView
{
private $from;
private $to;
private $sales;
private $total;

public function __construct($from,$to){
$this->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

]);
}
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
137 changes: 129 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,

/*
* Package Service Providers...
*/
Expand All @@ -194,7 +193,6 @@
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,

],

/*
Expand All @@ -210,6 +208,7 @@

'aliases' => Facade::defaultAliases()->merge([
// 'ExampleClass' => App\Example\ExampleClass::class,
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
])->toArray(),

];
60 changes: 60 additions & 0 deletions resources/views/reports/export.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<table>
<thead>
<tr>
<th>Id</th>
<th>Menus</th>
<th>Quantity</th>
<th>Tables</th>
<th>Servers</th>
<th>Total</th>
<th>Payment type</th>
<th>Payment status</th>
</tr>
</thead>
<tbody>
@foreach ($sales as $sale)
<tr>
<td>
{{ $sale->id }}
</td>
<td>
@foreach ($sale->menus()->where("sale_id",$sale->id)->get() as $menu)
<h5>{{ $menu->title }}</h5>
<h5>{{ $menu->price }} DH</h5>
@endforeach
</td>
<td >
@foreach ($sale->menus()->where("sale_id",$sale->id)->get() as $menu)
<h5>{{ $menu->pivot->quantity }}</h5>
@endforeach
</td>
<td>
@foreach ($sale->tables()->where("sale_id", $sale->id)->get() as $table)
<span>{{ $table->name }}</span>
@endforeach
</td>
<td>
{{ $sale->servant->name }}
</td>
<td>
{{ $sale->total_price }}
</td>
<td>
{{ $sale->payment_type === "cash"? "Cash" : "Credit Card" }}
</td>
<td>
{{ $sale->payment_status }}
</td>
</tr>
@endforeach
<tr>
<td colspan="5">
Report from {{ Str::substr($startDate, 0, 10) }} to {{ Str::substr($endDate, 0, 10) }}
</td>
</tr>
<tr>
<td colspan="5">
Total : {{ $total }} DH </td>
</tr>
</tbody>
</table>

0 comments on commit 678fcc2

Please sign in to comment.