status = 'success'; $this->save(); } public function setStatusFailed() { $this->status = 'failed'; $this->save(); } public function project() { return $this->belongsTo(Project::class); } public function weeksAgo() { return now()->diffInWeeks(now()->setISODate($this->year, $this->week)); } public function getFileName() { return 'week_'.$this->week.'_'.$this->year; } public function getFullPathName() { return storage_path('app/'.$this->project->download_path.'/'.$this->path); } public function getReportDate() { return self::getReportDateForYearAndWeek( $this->project, $this->year, $this->week )->toDateString(); } public static function getReportDateForYearAndWeek(Project $project, $year, $week) { $date = Carbon::now()->setISODate($year, $week); $dayOfWeek = Carbon::parse($project->mail_day)->subDay(2)->dayOfWeek; if ($dayOfWeek == 6) { $reportDay = $date->startOfWeek()->subDay(); } else { $reportDay = $date->startOfWeek()->addDays($dayOfWeek); } return $reportDay; } }