phpvms/app/Listeners/FinanceEvents.php

75 lines
1.8 KiB
PHP
Raw Normal View History

<?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;
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
*/
class FinanceEvents extends Listener
{
private $financeSvc;
/**
* FinanceEvents constructor.
2018-08-27 00:40:04 +08:00
*
* @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
2018-08-27 00:40:04 +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
*/
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
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
*/
public function onPirepReject(PirepRejected $event): void
2018-03-03 07:29:11 +08:00
{
$this->financeSvc->deleteFinancesForPirep($event->pirep);
}
}