![]() 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/dceprojects.corals.io/Corals/modules/Timesheet/Classes/ |
<?php namespace Corals\Modules\Timesheet\Classes; use Carbon\Carbon; use Corals\Modules\Timesheet\DataTables\Scopes\EmployeeJobsScope; use Corals\Modules\Timesheet\Models\Employee; use Corals\Modules\Timesheet\Models\Entry; use Corals\Modules\Timesheet\Models\Job; use Corals\User\Models\User; use Illuminate\Support\Str; class Timesheet { /** * Timesheet constructor. */ function __construct() { } public function getEmployeeJobs(User $employee = null) { if (!$employee) { $employee = \user(); } $employeeJobQB = Job::query(); (new EmployeeJobsScope($employee))->apply($employeeJobQB); return $employeeJobQB->pluck('title', 'id')->toArray(); } public function getLoggedTimeInHMFormat($hours = null, $minutes = 0) { $totalMinutes = ceil(($hours * 60) + $minutes); $totalHours = floor($totalMinutes / 60); $remainingMinutes = $totalMinutes % 60; return Str::padLeft($totalHours, 2, 0) . ':' . Str::padLeft($remainingMinutes, 2, 0); } public function getMissingDateToRecord(User $employee = null) { if (!$employee) { $employee = auth()->user(); } $employee = Employee::hydrate([$employee->toArray()])->first(); $jobs = $employee->jobs() ->select('id', 'starts_at', 'ends_at', 'title') ->get(); $missingEntries = []; $totalMissing = 0; $entries = Entry::query() ->where('user_id', $employee->id) ->select('id', 'spent_at', 'entrieable_id', 'user_id') ->get(); foreach ($jobs as $job) { $startDate = Carbon::parse($job->starts_at); $endDate = Carbon::parse($job->ends_at); $missingDates = []; for ($date = clone $startDate; $date->lt(min($endDate, Carbon::today())); $date->addDay()) { $recorded = $entries->contains(function ($item) use ($date, $job, $employee) { return $item->spent_at == $date->toDateString() && $item->entrieable_id == $job->id && $item->user_id == $employee->id; }); if (!$recorded) { $missingDates[] = $date->toDateString(); } } if (!empty($missingDates)) { $missingEntries[] = [ 'job_id' => $job->id, 'job_title' => $job->title, 'missing_dates' => $missingDates ]; $totalMissing += count($missingDates); } } return [ 'missing_entries' => $missingEntries, 'total_missing' => $totalMissing ]; } public function calculateWorkingDays(Carbon $startDate, Carbon $endDate = null, $startOfMonth = false) { if ($startOfMonth) { $startDate = $startDate->copy()->startOfMonth(); } else { $startDate = $startDate->copy(); } if (!$endDate) { $endDate = $startDate->copy()->endOfMonth(); } else { $endDate->endOfDay(); } return $startDate->diffInDaysFiltered(function ($date) { return in_array($date->shortDayName, config('timesheet.working_week_days')); }, $endDate); } public function formatMoney($amount) { $formatter = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY); return $formatter->formatCurrency($amount, config('timesheet.default_currency', 'USD')); } }