%PDF- %PDF-
Direktori : /var/www/html/hr/api/app/Console/Commands/ |
Current File : /var/www/html/hr/api/app/Console/Commands/NotifyForDueMaintenancePaymentsCommand.php |
<?php namespace App\Console\Commands; use App\Models\MaintenancePayment; use App\Models\Role; use App\Models\User; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class NotifyForDueMaintenancePaymentsCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'notifyForDueMaintenancePaymentsCommand'; /** * The console command description. * * @var string */ protected $description = 'Check for payments that are due and notify admin & finance users'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $start = Carbon::now() ->endOfDay(); $payments = MaintenancePayment::query() ->where('is_active', true) ->where('next_payment_date', '<', $start) ->get(); if (count($payments) > 0) { $users = User::query() ->whereHas('roles', function (Builder $q) { $q->whereIn('name', [ Role::ADMIN, Role::FINANCE, ]); }) ->get(); /** @var User $user */ foreach ($users as $user) { /** @var MaintenancePayment $payment */ foreach ($payments as $payment) { $user->notifyForDuePayment($payment); } } } } }