芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/Models/ProjectTimeLog.php
'datetime', 'end_time' => 'datetime', ]; protected $with = ['breaks']; const CUSTOM_FIELD_MODEL = 'App\Models\ProjectTimeLog'; /** * @return BelongsTo */ public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id')->withoutGlobalScope(ActiveScope::class); } public function editor(): BelongsTo { return $this->belongsTo(User::class, 'edited_by_user')->withoutGlobalScope(ActiveScope::class); } public function project(): BelongsTo { return $this->belongsTo(Project::class, 'project_id')->withTrashed(); } public function task(): BelongsTo { return $this->belongsTo(Task::class, 'task_id')->withTrashed(); } public function breaks(): HasMany { return $this->hasMany(ProjectTimeLogBreak::class, 'project_time_log_id'); } public function activeBreak(): HasOne { return $this->hasOne(ProjectTimeLogBreak::class, 'project_time_log_id')->whereNull('end_time'); } protected $appends = ['hours', 'duration', 'timer', 'hours_only']; public function getDurationAttribute() { $finishTime = now(); if (!is_null($this->start_time)) { return $finishTime->diff($this->start_time)->format('%d days %H Hrs %i Mins %s Secs'); } return ''; } public function getHoursAttribute() { if (is_null($this->end_time)) { $totalMinutes = (($this->activeBreak) ? $this->activeBreak->start_time->diffInMinutes($this->start_time) : now()->diffInMinutes($this->start_time)) - $this->breaks->sum('total_minutes'); } else { $totalMinutes = $this->total_minutes - $this->breaks->sum('total_minutes'); } /** @phpstan-ignore-next-line */ return CarbonInterval::formatHuman($totalMinutes); } public function getHoursOnlyAttribute() { if (is_null($this->end_time)) { $totalMinutes = (($this->activeBreak) ? $this->activeBreak->start_time->diffInMinutes($this->start_time) : now()->diffInMinutes($this->start_time)) - $this->breaks->sum('total_minutes'); } else { $totalMinutes = $this->total_minutes - $this->breaks->sum('total_minutes'); } $hours = floor($totalMinutes / 60); $minutes = ($totalMinutes % 60); return sprintf('%02d'.__('app.hrs').' %02d'.__('app.mins'), $hours, $minutes); } public function getTimerAttribute() { $finishTime = now(); if (!is_null($this->activeBreak)) { $finishTime = $this->activeBreak->start_time; } $startTime = Carbon::parse($this->start_time); $days = $finishTime->diff($startTime)->format('%d'); $hours = $finishTime->diff($startTime)->format('%H'); if ($hours < 10) { $hours = '0' . $hours; } $minutes = $finishTime->diffInMinutes($startTime); $minutes = $minutes - $this->breaks->sum('total_minutes'); if ($minutes < 10) { $minutes = '0' . $minutes; } $secs = $finishTime->diff($startTime)->format('%s'); if ($secs < 10) { $secs = '0' . $secs; } $hours = floor((int)$minutes / 60); $minutes = ((int)$minutes % 60); return sprintf('%02d:%02d:%02d', $hours, $minutes, $secs); } public static function dateWiseTimelogs($date, $userID = null) { $timelogs = ProjectTimeLog::with('breaks')->whereDate('start_time', $date); if (!is_null($userID)) { $timelogs = $timelogs->where('user_id', $userID); } return $timelogs = $timelogs->get(); } public static function weekWiseTimelogs($startDate, $endDate, $userID = null) { $timelogs = ProjectTimeLog::whereBetween(DB::raw('DATE(`start_time`)'), [$startDate, $endDate]); if (!is_null($userID)) { $timelogs = $timelogs->where('user_id', $userID); } return $timelogs = $timelogs->sum('total_minutes'); } public static function projectActiveTimers($projectId) { return ProjectTimeLog::with('user')->whereNull('end_time') ->where('project_id', $projectId) ->get(); } public static function taskActiveTimers($taskId) { return ProjectTimeLog::with('user')->whereNull('end_time') ->where('task_id', $taskId) ->get(); } public static function projectTotalHours($projectId) { return ProjectTimeLog::where('project_id', $projectId) ->sum('total_hours'); } public static function projectTotalMinuts($projectId) { return ProjectTimeLog::where('project_id', $projectId) ->sum('total_minutes'); } public static function memberActiveTimer($memberId) { return ProjectTimeLog::with('project')->where('user_id', $memberId) ->whereNull('end_time') ->first(); } public static function selfActiveTimer() { $selfActiveTimer = ProjectTimeLog::doesnthave('activeBreak') ->where('user_id', user()->id) ->whereNull('end_time') ->first(); if (is_null($selfActiveTimer)) { $selfActiveTimer = ProjectTimeLog::with('activeBreak') ->where('user_id', user()->id) ->whereNull('end_time') ->orderBy('id', 'desc') ->first(); } return $selfActiveTimer; } }