Add event for mass store
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Philipp Lang 2023-12-20 23:38:09 +01:00
parent cc650ebf45
commit ebf856252c
2 changed files with 45 additions and 0 deletions

View File

@ -2,12 +2,14 @@
namespace App\Invoice\Actions;
use App\Invoice\Events\InvoicesMassStored;
use App\Invoice\Models\Invoice;
use App\Lib\JobMiddleware\JobChannels;
use App\Lib\JobMiddleware\WithJobState;
use App\Lib\Queue\TracksJob;
use App\Member\Member;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
@ -28,6 +30,9 @@ class MassStoreAction
public function handle(int $year): void
{
/** @var Collection<int, Invoice> */
$invoices = collect([]);
$memberGroup = Member::payable()->get()
->groupBy(fn ($member) => "{$member->bill_kind->value}{$member->lastname}{$member->address}{$member->zip}{$member->location}");
foreach ($memberGroup as $members) {
@ -42,7 +47,11 @@ class MassStoreAction
]);
}
}
$invoices->push($invoice);
}
event(new InvoicesMassStored($year, $invoices));
}
public function asController(ActionRequest $request): JsonResponse

View File

@ -0,0 +1,36 @@
<?php
namespace App\Invoice\Events;
use App\Invoice\Models\Invoice;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
class InvoicesMassStored
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @param Collection<int, Invoice> $invoices
* @return void
*/
public function __construct(public int $year, public Collection $invoices)
{
//
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}