![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Jobs/ |
<?php namespace Corals\Modules\Timesheet\Jobs; use Corals\Modules\Timesheet\Facades\Timesheet; use Corals\Modules\Timesheet\Models\Entry; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; class NotifyExceededBudget implements ShouldQueue { use Queueable; protected $project; /** */ public function __construct($project) { $this->project = $project; } /** * Execute the job. */ public function handle() { $project = $this->project; try { logger(__CLASS__ . ' Started'); switch ($project->budget_by) { case 'project_hours': $entries = Entry::query()->where('project_id', $project->id) ->get(); $totalHoursForProjectEntries = 0; foreach ($entries as $entry) { $totalHoursForProjectEntries += Timesheet::getEntryTotalHours($entry); } if (($project->budget_alert_limit * $project->budget) / 100 < $totalHoursForProjectEntries) { event('notifications.project_budget.exceed', ['project' => $project]); } break; case 'project_fees': $totalAmountsForProjectEntries = Entry::query()->where('project_id', $project->id) ->sum('amount'); if (($project->budget_alert_limit * $project->budget) / 100 < $totalAmountsForProjectEntries) { event('notifications.project_budget.exceed', ['project' => $project]); } break; } logger(__CLASS__ . ' Completed'); } catch (\Exception $exception) { report($exception); } } }