#39 - generate timesheet (#56)

* #39 - wip

* #39 - fix

* #39 - wip

* #39 - wip

* #39 - wip

* Update app/Domain/Enums/Month.php

Co-authored-by: Marcin Tracz <marcin.tracz@blumilk.pl>

* #39 - cr fixes

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
Co-authored-by: Marcin Tracz <marcin.tracz@blumilk.pl>
This commit is contained in:
Adrian Hopek
2022-02-21 16:09:45 +01:00
committed by GitHub
parent 77a4d5711c
commit 39b464388c
12 changed files with 1085 additions and 143 deletions

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Toby\Infrastructure\Http\Controllers;
use Illuminate\Support\Carbon;
use Maatwebsite\Excel\Facades\Excel;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Toby\Domain\Enums\Month;
use Toby\Domain\TimesheetExport;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\User;
class TimesheetController extends Controller
{
public function __invoke(Month $month, YearPeriodRetriever $yearPeriodRetriever): BinaryFileResponse
{
$yearPeriod = $yearPeriodRetriever->selected();
$carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber());
$users = User::query()
->orderBy("last_name")
->orderBy("first_name")
->get();
$filename = "{$carbonMonth->translatedFormat("F Y")}.xlsx";
$timesheet = (new TimesheetExport())
->forMonth($carbonMonth)
->forUsers($users);
return Excel::download($timesheet, $filename);
}
}

View File

@@ -4,11 +4,10 @@ declare(strict_types=1);
namespace Toby\Infrastructure\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Inertia\Response;
use Toby\Domain\CalendarGenerator;
use Toby\Domain\Enums\Month;
use Toby\Eloquent\Helpers\YearPeriodRetriever;
use Toby\Eloquent\Models\User;
use Toby\Infrastructure\Http\Resources\UserResource;
@@ -16,22 +15,25 @@ use Toby\Infrastructure\Http\Resources\UserResource;
class VacationCalendarController extends Controller
{
public function index(
Request $request,
YearPeriodRetriever $yearPeriodRetriever,
CalendarGenerator $calendarGenerator,
?string $month = null,
): Response {
$month = Str::lower($request->query("month", Carbon::now()->englishMonth));
$month = Month::fromNameOrCurrent((string)$month);
$yearPeriod = $yearPeriodRetriever->selected();
$carbonMonth = Carbon::create($yearPeriod->year, $month->toCarbonNumber());
$users = User::query()
->orderBy("last_name")
->orderBy("first_name")
->get();
$calendar = $calendarGenerator->generate($yearPeriod, $month);
$calendar = $calendarGenerator->generate($carbonMonth);
return inertia("Calendar", [
"calendar" => $calendar,
"currentMonth" => $month,
"currentMonth" => $month->value,
"users" => UserResource::collection($users),
]);
}