2018-03-17 09:12:56 +08:00
|
|
|
<?php
|
|
|
|
|
2018-04-07 06:14:01 +08:00
|
|
|
namespace App\Cron\Nightly;
|
2018-03-17 09:12:56 +08:00
|
|
|
|
|
|
|
use App\Events\CronNightly;
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Listener;
|
2018-03-17 09:12:56 +08:00
|
|
|
use App\Models\Enums\ExpenseType;
|
|
|
|
use App\Services\Finance\RecurringFinanceService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Go through and apply any finances that are daily
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class ApplyExpenses extends Listener
|
2018-03-17 09:12:56 +08:00
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
private $financeSvc;
|
2018-03-17 09:12:56 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* ApplyExpenses constructor.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param RecurringFinanceService $financeSvc
|
|
|
|
*/
|
|
|
|
public function __construct(RecurringFinanceService $financeSvc)
|
2018-03-17 09:12:56 +08:00
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
$this->financeSvc = $financeSvc;
|
2018-03-17 09:12:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply all of the expenses for a day
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-17 09:12:56 +08:00
|
|
|
* @param CronNightly $event
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-17 09:12:56 +08:00
|
|
|
* @throws \UnexpectedValueException
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
|
|
|
*/
|
|
|
|
public function handle(CronNightly $event): void
|
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
$this->financeSvc->processExpenses(ExpenseType::DAILY);
|
2018-03-17 09:12:56 +08:00
|
|
|
}
|
|
|
|
}
|