![]() 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 Corals\Settings\Facades\Settings; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; class UpdateEntriesCalculations implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; /** * @var mixed */ protected $project; public function __construct($project) { $this->project = $project; } public function handle() { Entry::query() ->with('user') ->whereNull('invoice_id') ->where('project_id', $this->project->id) ->chunkById(500, function ($entries) { foreach ($entries as $entry) { $calculation = Timesheet::getEntryHourlyRate($entry->project, $entry->user_id, $entry->activity_id, Timesheet::getEntryTotalHours($entry)); $entryTotalHours = ($entry->hours ?? 0) + (($entry->minutes ?? 0) / 60); $user = $entry->user; $userRate = $user->hourly_rate ?? 0; if (!$userRate && $user->salary) { $userRate = round($user->salary / Settings::get('total_working_hours_per_month', 176), 1); } $entry->updateQuietly([ 'hourly_rate' => data_get($calculation, 'hourly_rate'), 'amount' => data_get($calculation, 'amount'), 'cost' => $entryTotalHours * $userRate ]); } }); } }