2018-03-02 06:20:13 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Listeners;
|
|
|
|
|
2019-07-16 03:51:35 +08:00
|
|
|
use App\Contracts\Listener;
|
2018-03-03 07:29:11 +08:00
|
|
|
use App\Events\PirepAccepted;
|
|
|
|
use App\Events\PirepRejected;
|
2018-03-06 12:49:42 +08:00
|
|
|
use App\Services\Finance\PirepFinanceService;
|
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
|
|
|
|
*/
|
2019-11-20 23:16:01 +08:00
|
|
|
class FinanceEventHandler extends Listener
|
2018-03-02 06:20:13 +08:00
|
|
|
{
|
|
|
|
private $financeSvc;
|
|
|
|
|
2019-11-20 23:16:01 +08:00
|
|
|
public static $callbacks = [
|
|
|
|
PirepAccepted::class => 'onPirepAccept',
|
|
|
|
PirepRejected::class => 'onPirepReject',
|
|
|
|
];
|
2018-03-02 06:20:13 +08:00
|
|
|
|
2019-11-20 23:16:01 +08:00
|
|
|
public function __construct(PirepFinanceService $financeSvc)
|
2018-03-02 06:20:13 +08:00
|
|
|
{
|
2019-11-20 23:16:01 +08:00
|
|
|
$this->financeSvc = $financeSvc;
|
2018-03-02 06:20:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kick off the finance events when a PIREP is accepted
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-02 06:20:13 +08:00
|
|
|
* @param PirepAccepted $event
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
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
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-03 07:29:11 +08:00
|
|
|
* @param PirepRejected $event
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-03 07:29:11 +08:00
|
|
|
* @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
|
|
|
}
|