2018-03-02 06:20:13 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
2018-03-03 07:29:11 +08:00
|
|
|
use App\Events\PirepAccepted;
|
|
|
|
use App\Events\PirepRejected;
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Listener;
|
2018-03-06 12:49:42 +08:00
|
|
|
use App\Services\Finance\PirepFinanceService;
|
2018-03-20 09:50:40 +08:00
|
|
|
use Illuminate\Contracts\Events\Dispatcher;
|
2018-03-02 06:20:13 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subscribe for events that we do some financial processing for
|
|
|
|
* This includes when a PIREP is accepted, or rejected
|
|
|
|
* @package App\Listeners
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class FinanceEvents extends Listener
|
2018-03-02 06:20:13 +08:00
|
|
|
{
|
|
|
|
private $financeSvc;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* FinanceEvents constructor.
|
|
|
|
* @param PirepFinanceService $financeSvc
|
|
|
|
*/
|
2018-03-02 06:20:13 +08:00
|
|
|
public function __construct(
|
2018-03-06 12:49:42 +08:00
|
|
|
PirepFinanceService $financeSvc
|
2018-03-02 06:20:13 +08:00
|
|
|
) {
|
|
|
|
$this->financeSvc = $financeSvc;
|
|
|
|
}
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* @param $events
|
|
|
|
*/
|
|
|
|
public function subscribe(Dispatcher $events): void
|
2018-03-02 06:20:13 +08:00
|
|
|
{
|
|
|
|
$events->listen(
|
|
|
|
PirepAccepted::class,
|
|
|
|
'App\Listeners\FinanceEvents@onPirepAccept'
|
|
|
|
);
|
2018-03-03 07:29:11 +08:00
|
|
|
|
|
|
|
$events->listen(
|
|
|
|
PirepRejected::class,
|
|
|
|
'App\Listeners\FinanceEvents@onPirepReject'
|
|
|
|
);
|
2018-03-02 06:20:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kick off the finance events when a PIREP is accepted
|
|
|
|
* @param PirepAccepted $event
|
2018-03-03 07:29:11 +08:00
|
|
|
* @throws \UnexpectedValueException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \Exception
|
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2018-03-02 06:20:13 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function onPirepAccept(PirepAccepted $event): void
|
2018-03-02 06:20:13 +08:00
|
|
|
{
|
|
|
|
$this->financeSvc->processFinancesForPirep($event->pirep);
|
|
|
|
}
|
2018-03-03 07:29:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all finances in the journal for a given PIREP
|
|
|
|
* @param PirepRejected $event
|
|
|
|
* @throws \UnexpectedValueException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function onPirepReject(PirepRejected $event): void
|
2018-03-03 07:29:11 +08:00
|
|
|
{
|
|
|
|
$this->financeSvc->deleteFinancesForPirep($event->pirep);
|
|
|
|
}
|
2018-03-02 06:20:13 +08:00
|
|
|
}
|