phpvms/app/Listeners/FinanceEvents.php

71 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Listeners;
2018-03-03 07:29:11 +08:00
use App\Events\PirepAccepted;
use App\Events\PirepRejected;
use App\Interfaces\Listener;
use App\Services\Finance\PirepFinanceService;
use Illuminate\Contracts\Events\Dispatcher;
/**
* Subscribe for events that we do some financial processing for
* This includes when a PIREP is accepted, or rejected
* @package App\Listeners
*/
class FinanceEvents extends Listener
{
private $financeSvc;
/**
* FinanceEvents constructor.
* @param PirepFinanceService $financeSvc
*/
public function __construct(
PirepFinanceService $financeSvc
) {
$this->financeSvc = $financeSvc;
}
/**
* @param $events
*/
public function subscribe(Dispatcher $events): void
{
$events->listen(
PirepAccepted::class,
'App\Listeners\FinanceEvents@onPirepAccept'
);
2018-03-03 07:29:11 +08:00
$events->listen(
PirepRejected::class,
'App\Listeners\FinanceEvents@onPirepReject'
);
}
/**
* 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
*/
public function onPirepAccept(PirepAccepted $event): void
{
$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): void
2018-03-03 07:29:11 +08:00
{
$this->financeSvc->deleteFinancesForPirep($event->pirep);
}
}