2018-03-17 09:12:56 +08:00
|
|
|
<?php
|
|
|
|
|
2018-04-07 06:14:01 +08:00
|
|
|
namespace App\Cron\Monthly;
|
2018-03-17 09:12:56 +08:00
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Listener;
|
2019-07-16 03:51:35 +08:00
|
|
|
use App\Events\CronMonthly;
|
2018-03-17 09:12:56 +08:00
|
|
|
use App\Models\Enums\ExpenseType;
|
|
|
|
use App\Services\Finance\RecurringFinanceService;
|
2021-03-03 04:43:34 +08:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-03-17 09:12:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
private RecurringFinanceService $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 month
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-17 09:12:56 +08:00
|
|
|
* @param CronMonthly $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
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
public function handle(CronMonthly $event): void
|
2018-03-17 09:12:56 +08:00
|
|
|
{
|
2021-03-03 04:43:34 +08:00
|
|
|
Log::info('Monthly: Applying monthly expenses');
|
2018-03-20 09:50:40 +08:00
|
|
|
$this->financeSvc->processExpenses(ExpenseType::MONTHLY);
|
2018-03-17 09:12:56 +08:00
|
|
|
}
|
|
|
|
}
|