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-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
|
|
|
|
* @package App\Listeners
|
|
|
|
*/
|
|
|
|
class FinanceEvents
|
|
|
|
{
|
|
|
|
private $financeSvc;
|
|
|
|
|
|
|
|
public function __construct(
|
2018-03-06 12:49:42 +08:00
|
|
|
PirepFinanceService $financeSvc
|
2018-03-02 06:20:13 +08:00
|
|
|
) {
|
|
|
|
$this->financeSvc = $financeSvc;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function subscribe($events)
|
|
|
|
{
|
|
|
|
$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
|
|
|
*/
|
|
|
|
public function onPirepAccept(PirepAccepted $event)
|
|
|
|
{
|
|
|
|
$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
|
|
|
|
*/
|
|
|
|
public function onPirepReject(PirepRejected $event)
|
|
|
|
{
|
|
|
|
$this->financeSvc->deleteFinancesForPirep($event->pirep);
|
|
|
|
}
|
2018-03-02 06:20:13 +08:00
|
|
|
}
|