* #108 - wip * #108 - add icon to absence * #108 - wip * #108 - fix * #108 - fix title Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Infrastructure\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
use Toby\Infrastructure\Http\Controllers\Controller;
|
||||
use Toby\Infrastructure\Http\Requests\Api\GetAvailableVacationTypesRequest;
|
||||
|
||||
class GetAvailableVacationTypesController extends Controller
|
||||
{
|
||||
public function __invoke(
|
||||
GetAvailableVacationTypesRequest $request,
|
||||
VacationTypeConfigRetriever $configRetriever,
|
||||
): JsonResponse {
|
||||
/** @var User $user */
|
||||
$user = User::query()->find($request->get("user"));
|
||||
|
||||
$types = VacationType::all()
|
||||
->filter(fn(VacationType $type) => $configRetriever->isAvailableFor($type, $user->employment_form))
|
||||
->map(fn(VacationType $type) => [
|
||||
"label" => $type->label(),
|
||||
"value" => $type->value,
|
||||
])
|
||||
->values();
|
||||
|
||||
return new JsonResponse($types);
|
||||
}
|
||||
}
|
@@ -7,30 +7,43 @@ namespace Toby\Infrastructure\Http\Controllers;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Month;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\TimesheetExport;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class TimesheetController extends Controller
|
||||
{
|
||||
public function __invoke(Month $month, YearPeriodRetriever $yearPeriodRetriever): BinaryFileResponse
|
||||
{
|
||||
public function __invoke(
|
||||
Month $month,
|
||||
YearPeriodRetriever $yearPeriodRetriever,
|
||||
VacationTypeConfigRetriever $configRetriever,
|
||||
): BinaryFileResponse {
|
||||
$this->authorize("generateTimesheet");
|
||||
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
$carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber());
|
||||
|
||||
$users = User::query()
|
||||
->where("employment_form", EmploymentForm::EmploymentContract)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->get();
|
||||
|
||||
$types = VacationType::all()
|
||||
->filter(
|
||||
fn(VacationType $type) => $configRetriever->isAvailableFor($type, EmploymentForm::EmploymentContract),
|
||||
);
|
||||
|
||||
$filename = "{$carbonMonth->translatedFormat("F Y")}.xlsx";
|
||||
|
||||
$timesheet = (new TimesheetExport())
|
||||
->forMonth($carbonMonth)
|
||||
->forUsers($users);
|
||||
->forUsers($users)
|
||||
->forVacationTypes($types);
|
||||
|
||||
return Excel::download($timesheet, $filename);
|
||||
}
|
||||
|
@@ -158,10 +158,7 @@ class VacationRequestController extends Controller
|
||||
|
||||
public function create(Request $request, YearPeriodRetriever $yearPeriodRetriever): Response
|
||||
{
|
||||
$yearPeriod = $yearPeriodRetriever->selected();
|
||||
|
||||
$users = User::query()
|
||||
->withVacationLimitIn($yearPeriod)
|
||||
->orderBy("last_name")
|
||||
->orderBy("first_name")
|
||||
->get();
|
||||
|
Reference in New Issue
Block a user