phpvms/app/Listeners/FinanceEventHandler.php

57 lines
1.4 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;
/**
* Subscribe for events that we do some financial processing for
* This includes when a PIREP is accepted, or rejected
*/
class FinanceEventHandler extends Listener
{
private $financeSvc;
public static $callbacks = [
PirepAccepted::class => 'onPirepAccept',
PirepRejected::class => 'onPirepReject',
];
public function __construct(PirepFinanceService $financeSvc)
{
$this->financeSvc = $financeSvc;
}
/**
* 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);
}
}