belongsTo(Company::class); } public function documents() { return $this->morphMany(Document::class, 'documentable'); } public function assigned_user() { return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed(); } public function user() { return $this->belongsTo(User::class)->withTrashed(); } public function client() { return $this->belongsTo(Client::class)->withTrashed(); } public function status() { return $this->belongsTo(TaskStatus::class)->withTrashed(); } public function invoice() { return $this->belongsTo(Invoice::class)->withTrashed(); } public function project() { return $this->belongsTo(Project::class)->withTrashed(); } public function calcStartTime() { $parts = json_decode($this->time_log) ?: []; if (count($parts)) { return Carbon::createFromTimeStamp($parts[0][0])->timestamp; } else { return null; } } public function getLastStartTime() { $parts = json_decode($this->time_log) ?: []; if (count($parts)) { $index = count($parts) - 1; return $parts[$index][0]; } else { return ''; } } public function calcDuration($start_time_cutoff = 0, $end_time_cutoff = 0) { $duration = 0; $parts = json_decode($this->time_log) ?: []; foreach ($parts as $part) { $start_time = $part[0]; if (count($part) == 1 || ! $part[1]) { $end_time = time(); } else { $end_time = $part[1]; } if ($start_time_cutoff) { $start_time = max($start_time, $start_time_cutoff); } if ($end_time_cutoff) { $end_time = min($end_time, $end_time_cutoff); } $duration += max($end_time - $start_time, 0); } return round($duration); } public function translate_entity() { return ctrans('texts.task'); } }