public function updateTimesheet($id, $agency, $status) { if (!($timesheet = \Contractor::findTimesheetById($id))) { throw new \Exception("Timesheet not found", 1); return; } $job = $timesheet->job; if ($agency->id !== $job->agency_id) { throw new \Exception("Timesheet does not belong to the agency.", 1); return; } if ($status) { $timesheet->auth_agency = true; $timesheet->save(); if ($contractor = $timesheet->contractor) { $notificationData = ['contractor_id' => $contractor->id, 'alert_from' => 'System: Programme Chameleon', 'has_read' => false, 'title' => 'Your timesheet "' . $timesheet->name . '" for "' . $job->title . '" has been accepted.', 'description' => 'Accepted by ' . $agency->name, 'url' => '#']; \Contractor::addNotification($contractor, $notificationData); } if (!is_null($job->company_id)) { if ($company = \Company::findCompanyById($job->company_id)) { $_hash = new Hash(); $_hash = $_hash->getHasher(); $notificationData = ['company_id' => $company->id, 'alert_from' => 'System: Programme Chameleon', 'has_read' => false, 'title' => 'Timesheet "' . $timesheet->name . '" for "' . $job->title . '" has been accepted.', 'description' => 'Accepted by ' . $agency->name, 'url' => route('company.job.detail') . '?i=' . $_hash->encode($job->id)]; \Company::addNotification($company, $notificationData); } } } else { $timesheet->auth_agency = true; $timesheet->save(); if ($contractor = $timesheet->contractor) { $notificationData = ['contractor_id' => $contractor->id, 'alert_from' => 'System: Programme Chameleon', 'has_read' => false, 'title' => 'Your timesheet "' . $timesheet->name . '" for "' . $job->title . '" has been accepted.', 'description' => 'Accepted by ' . $agency->name, 'url' => '#']; \Contractor::addNotification($contractor, $notificationData); } if (!is_null($job->company_id)) { if ($company = \Company::findCompanyById($job->company_id)) { $_hash = new Hash(); $_hash = $_hash->getHasher(); $notificationData = ['company_id' => $company->id, 'alert_from' => 'System: Programme Chameleon', 'has_read' => false, 'title' => 'Timesheet "' . $timesheet->name . '" for "' . $job->title . '" has been accepted.', 'description' => 'Accepted by ' . $agency->name, 'url' => route('agency.job.detail') . '?i=' . $_hash->encode($job->id)]; \Company::addNotification($company, $notificationData); } } } return $timesheet; }