* fix css focuses * #90 - wip * #90 - fix to generate PDF * #90 - wip * #90 - wip * #90 - wip * #90 - wip * #90 - fix to calendar * #90 - wip * #90 - fix * #90 - fix lint * #90 - fix * Apply suggestions from code review Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * #90 - cr fixes * #90 - fix Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
		
			
				
	
	
		
			67 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| declare(strict_types=1);
 | |
| 
 | |
| namespace Toby\Infrastructure\Http\Controllers;
 | |
| 
 | |
| use Illuminate\Http\Request;
 | |
| use Inertia\Response;
 | |
| use Toby\Domain\Enums\Month;
 | |
| use Toby\Domain\UserVacationStatsRetriever;
 | |
| use Toby\Eloquent\Helpers\YearPeriodRetriever;
 | |
| use Toby\Eloquent\Models\User;
 | |
| use Toby\Infrastructure\Http\Resources\SimpleUserResource;
 | |
| 
 | |
| class MonthlyUsageController extends Controller
 | |
| {
 | |
|     public function __invoke(
 | |
|         Request $request,
 | |
|         YearPeriodRetriever $yearPeriodRetriever,
 | |
|         UserVacationStatsRetriever $statsRetriever,
 | |
|     ): Response {
 | |
|         $this->authorize("listMonthlyUsage");
 | |
| 
 | |
|         $currentYearPeriod = $yearPeriodRetriever->selected();
 | |
|         $currentUser = $request->user();
 | |
| 
 | |
|         $users = User::query()
 | |
|             ->withVacationLimitIn($currentYearPeriod)
 | |
|             ->where("id", "!=", $currentUser->id)
 | |
|             ->orderByProfileField("last_name")
 | |
|             ->orderByProfileField("first_name")
 | |
|             ->get();
 | |
| 
 | |
|         if ($currentUser->hasVacationLimit($currentYearPeriod)) {
 | |
|             $users->prepend($currentUser);
 | |
|         }
 | |
| 
 | |
|         $monthlyUsage = [];
 | |
| 
 | |
|         foreach ($users as $user) {
 | |
|             $vacationsByMonth = $statsRetriever->getUsedVacationDaysByMonth($user, $currentYearPeriod);
 | |
|             $limit = $statsRetriever->getVacationDaysLimit($user, $currentYearPeriod);
 | |
|             $used = $statsRetriever->getUsedVacationDays($user, $currentYearPeriod);
 | |
|             $pending = $statsRetriever->getPendingVacationDays($user, $currentYearPeriod);
 | |
|             $remaining = $limit - $used - $pending;
 | |
| 
 | |
|             $monthlyUsage[] = [
 | |
|                 "user" => new SimpleUserResource($user),
 | |
|                 "months" => $vacationsByMonth,
 | |
|                 "stats" => [
 | |
|                     "used" => $used,
 | |
|                     "pending" => $pending,
 | |
|                     "remaining" => $remaining,
 | |
|                 ],
 | |
|             ];
 | |
|         }
 | |
| 
 | |
|         return inertia("MonthlyUsage", [
 | |
|             "monthlyUsage" => $monthlyUsage,
 | |
|             "currentMonth" => Month::current(),
 | |
|             "can" => [
 | |
|                 "listMonthlyUsage" => $request->user()->can("listMonthlyUsage"),
 | |
|             ],
 | |
|         ]);
 | |
|     }
 | |
| }
 |