2023-12-16 01:13:49 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Invoice\Actions;
|
|
|
|
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
use App\Invoice\Models\Invoice;
|
|
|
|
use App\Invoice\Resources\InvoiceResource;
|
2024-05-14 01:29:39 +02:00
|
|
|
use App\Invoice\Scopes\InvoiceFilterScope;
|
2023-12-16 01:13:49 +01:00
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
use Inertia\Inertia;
|
|
|
|
use Inertia\Response;
|
2024-05-14 01:29:39 +02:00
|
|
|
use Lorisleiva\Actions\ActionRequest;
|
2023-12-16 01:13:49 +01:00
|
|
|
|
|
|
|
class InvoiceIndexAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return LengthAwarePaginator<Invoice>
|
|
|
|
*/
|
2024-05-14 01:29:39 +02:00
|
|
|
public function handle(InvoiceFilterScope $filter): LengthAwarePaginator
|
2023-12-16 01:13:49 +01:00
|
|
|
{
|
2024-05-14 01:29:39 +02:00
|
|
|
return Invoice::withFilter($filter)->with('positions')->paginate(15);
|
2023-12-16 01:13:49 +01:00
|
|
|
}
|
|
|
|
|
2024-05-14 01:29:39 +02:00
|
|
|
public function asController(ActionRequest $request): Response
|
2023-12-16 01:13:49 +01:00
|
|
|
{
|
2023-12-16 13:08:17 +01:00
|
|
|
session()->put('menu', 'invoice');
|
|
|
|
session()->put('title', 'Rechnungen');
|
|
|
|
|
2024-05-14 01:29:39 +02:00
|
|
|
$filter = InvoiceFilterScope::fromRequest($request->input('filter', ''));
|
|
|
|
|
2023-12-16 01:13:49 +01:00
|
|
|
return Inertia::render('invoice/Index', [
|
2024-05-14 01:29:39 +02:00
|
|
|
'data' => InvoiceResource::collection($this->handle($filter)),
|
2023-12-16 01:13:49 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|