This repository has been archived by the owner on Feb 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: manager approvals of timesheets (#464)
* feat: manager approvals of timesheets * wip * Optimised images with calibre/image-actions * final touch before CI * wip * cypress tests Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e622d0e
commit 70526e6
Showing
19 changed files
with
769 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
app/Http/Controllers/Company/Dashboard/DashboardTimesheetManagerController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Company\Dashboard; | ||
|
||
use Inertia\Response; | ||
use Illuminate\Http\Request; | ||
use App\Helpers\InstanceHelper; | ||
use App\Models\Company\Company; | ||
use App\Models\Company\Employee; | ||
use App\Models\Company\Timesheet; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Company\DirectReport; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use App\Services\Company\Employee\Timesheet\RejectTimesheet; | ||
use App\Services\Company\Employee\Timesheet\ApproveTimesheet; | ||
|
||
class DashboardTimesheetManagerController extends Controller | ||
{ | ||
/** | ||
* Approve the timesheet. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $timesheetId | ||
* @return JsonResponse | ||
*/ | ||
public function approve(Request $request, int $companyId, int $timesheetId): JsonResponse | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
$employee = InstanceHelper::getLoggedEmployee(); | ||
|
||
$timesheet = $this->canAccess($company, $timesheetId, $employee); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $employee->id, | ||
'employee_id' => $timesheet->employee->id, | ||
'timesheet_id' => $timesheetId, | ||
]; | ||
|
||
$timesheet = (new ApproveTimesheet)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => $timesheet->id, | ||
], 201); | ||
} | ||
|
||
/** | ||
* Reject the timesheet. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $timesheetId | ||
* @return JsonResponse | ||
*/ | ||
public function reject(Request $request, int $companyId, int $timesheetId): JsonResponse | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
$employee = InstanceHelper::getLoggedEmployee(); | ||
|
||
$timesheet = $this->canAccess($company, $timesheetId, $employee); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $employee->id, | ||
'employee_id' => $timesheet->employee->id, | ||
'timesheet_id' => $timesheetId, | ||
]; | ||
|
||
$timesheet = (new RejectTimesheet)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => $timesheet->id, | ||
], 201); | ||
} | ||
|
||
/** | ||
* Check that the current employee has access to this method. | ||
* @param Company $company | ||
* @param int $timesheetId | ||
* @param Employee $employee | ||
* @return mixed | ||
*/ | ||
private function canAccess(Company $company, int $timesheetId, Employee $employee) | ||
{ | ||
try { | ||
$timesheet = Timesheet::where('company_id', $company->id) | ||
->findOrFail($timesheetId); | ||
} catch (ModelNotFoundException $e) { | ||
return redirect('home'); | ||
} | ||
|
||
if ($timesheet->status !== Timesheet::READY_TO_SUBMIT) { | ||
return redirect('home'); | ||
} | ||
|
||
// is the user a manager? | ||
$directReports = DirectReport::where('company_id', $company->id) | ||
->where('manager_id', $employee->id) | ||
->with('directReport') | ||
->with('directReport.timesheets') | ||
->get(); | ||
|
||
if ($directReports->count() == 0) { | ||
return redirect('home'); | ||
} | ||
|
||
// can the manager see this timesheet? | ||
if (! $employee->isManagerOf($timesheet->employee->id)) { | ||
return redirect('home'); | ||
} | ||
|
||
return $timesheet; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.