Move cron scripts to root namespace

This commit is contained in:
Nabeel Shahzad
2018-04-06 17:14:01 -05:00
parent 7179910bc6
commit 3e89a53fc1
5 changed files with 8 additions and 8 deletions

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Cron\Monthly;
use App\Events\CronMonthly;
use App\Interfaces\Listener;
use App\Models\Enums\ExpenseType;
use App\Services\Finance\RecurringFinanceService;
/**
* Go through and apply any finances that are daily
* @package App\Listeners\Cron\Nightly
*/
class ApplyExpenses extends Listener
{
private $financeSvc;
/**
* ApplyExpenses constructor.
* @param RecurringFinanceService $financeSvc
*/
public function __construct(RecurringFinanceService $financeSvc)
{
$this->financeSvc = $financeSvc;
}
/**
* Apply all of the expenses for a month
* @param CronMonthly $event
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function handle(CronMonthly $event): void
{
$this->financeSvc->processExpenses(ExpenseType::MONTHLY);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Cron\Nightly;
use App\Events\CronNightly;
use App\Interfaces\Listener;
use App\Models\Enums\ExpenseType;
use App\Services\Finance\RecurringFinanceService;
/**
* Go through and apply any finances that are daily
* @package App\Listeners\Cron\Nightly
*/
class ApplyExpenses extends Listener
{
private $financeSvc;
/**
* ApplyExpenses constructor.
* @param RecurringFinanceService $financeSvc
*/
public function __construct(RecurringFinanceService $financeSvc)
{
$this->financeSvc = $financeSvc;
}
/**
* Apply all of the expenses for a day
* @param CronNightly $event
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function handle(CronNightly $event): void
{
$this->financeSvc->processExpenses(ExpenseType::DAILY);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Cron\Nightly;
use App\Events\CronNightly;
use App\Interfaces\Listener;
use App\Models\Enums\UserState;
use App\Models\User;
use App\Services\UserService;
use Carbon\Carbon;
/**
* Determine if any pilots should be set to ON LEAVE status
* @package App\Listeners\Cron\Nightly
*/
class PilotLeave extends Listener
{
private $userSvc;
/**
* PilotLeave constructor.
*/
public function __construct(UserService $userSvc)
{
$this->userSvc = $userSvc;
}
/**
* Set any users to being on leave after X days
* @param CronNightly $event
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
*/
public function handle(CronNightly $event): void
{
if(setting('pilots.auto_leave_days') === 0) {
return;
}
$date = Carbon::now()->subDay(setting('pilots.auto_leave_days'));
$users = User::where('status', UserState::ACTIVE)
->whereDate('updated_at', '<', $date);
foreach($users as $user) {
$this->userSvc->setStatusOnLeave($user);
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Cron\Nightly;
use App\Events\CronNightly;
use App\Interfaces\Listener;
use App\Models\Journal;
use App\Repositories\JournalRepository;
use Log;
/**
* This recalculates the balances on all of the journals
* @package App\Listeners\Cron
*/
class RecalculateBalances extends Listener
{
private $journalRepo;
/**
* Nightly constructor.
* @param JournalRepository $journalRepo
*/
public function __construct(JournalRepository $journalRepo)
{
$this->journalRepo = $journalRepo;
}
/**
* Recalculate all the balances for the different ledgers
* @param CronNightly $event
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
*/
public function handle(CronNightly $event): void
{
Log::info('Recalculating balances');
$journals = Journal::all();
foreach ($journals as $journal) {
$old_balance = $journal->balance;
$this->journalRepo->recalculateBalance($journal);
$journal->refresh();
Log::info('Adjusting balance on '.
$journal->morphed_type.':'.$journal->morphed_id
.' from '.$old_balance.' to '.$journal->balance);
}
Log::info('Done calculating balances');
}
}