#36 - wip
This commit is contained in:
parent
51d3849b58
commit
98ebe290a9
@ -21,6 +21,7 @@ use Toby\Domain\Enums\VacationType;
|
||||
* @property VacationRequestState $state
|
||||
* @property Carbon $from
|
||||
* @property Carbon $to
|
||||
* @property int $estimated_days
|
||||
* @property string $comment
|
||||
* @property User $user
|
||||
* @property YearPeriod $yearPeriod
|
||||
|
@ -11,6 +11,7 @@ use Illuminate\Http\Response as LaravelResponse;
|
||||
use Inertia\Response;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
use Toby\Domain\VacationDaysCalculator;
|
||||
use Toby\Domain\VacationRequestStateManager;
|
||||
use Toby\Domain\Validation\VacationRequestValidator;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
@ -64,9 +65,15 @@ class VacationRequestController extends Controller
|
||||
VacationRequestRequest $request,
|
||||
VacationRequestValidator $vacationRequestValidator,
|
||||
VacationRequestStateManager $stateManager,
|
||||
VacationDaysCalculator $vacationDaysCalculator,
|
||||
): RedirectResponse {
|
||||
/** @var VacationRequest $vacationRequest */
|
||||
$vacationRequest = $request->user()->vacationRequests()->make($request->data());
|
||||
$vacationRequest->estimated_days = $vacationDaysCalculator->calculateDays(
|
||||
$vacationRequest->yearPeriod,
|
||||
$vacationRequest->from,
|
||||
$vacationRequest->to,
|
||||
)->count();
|
||||
|
||||
$vacationRequestValidator->validate($vacationRequest);
|
||||
|
||||
|
@ -20,6 +20,7 @@ class VacationRequestResource extends JsonResource
|
||||
"state" => $this->state->label(),
|
||||
"from" => $this->from->toDisplayString(),
|
||||
"to" => $this->to->toDisplayString(),
|
||||
"estimatedDays" => $this->estimated_days,
|
||||
"comment" => $this->comment,
|
||||
];
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Database\Factories;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Toby\Domain\Enums\VacationRequestState;
|
||||
use Toby\Domain\Enums\VacationType;
|
||||
@ -30,6 +31,7 @@ class VacationRequestFactory extends Factory
|
||||
"state" => $this->faker->randomElement(VacationRequestState::cases()),
|
||||
"from" => $from,
|
||||
"to" => $from->addDays($days),
|
||||
"estimated_days" => fn(array $attributes) => $this->estimateDays($attributes),
|
||||
"comment" => $this->faker->boolean ? $this->faker->paragraph() : null,
|
||||
];
|
||||
}
|
||||
@ -41,4 +43,11 @@ class VacationRequestFactory extends Factory
|
||||
|
||||
return "{$number}/{$year}";
|
||||
}
|
||||
|
||||
protected function estimateDays(array $attributes): int
|
||||
{
|
||||
$period = CarbonPeriod::create($attributes["from"], $attributes["to"]);
|
||||
|
||||
return $period->count();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ return new class() extends Migration {
|
||||
$table->foreignIdFor(YearPeriod::class)->constrained()->cascadeOnDelete();
|
||||
$table->string("type");
|
||||
$table->string("state")->nullable();
|
||||
$table->integer("estimated_days");
|
||||
$table->date("from");
|
||||
$table->date("to");
|
||||
$table->text("comment")->nullable();
|
||||
|
@ -153,7 +153,7 @@
|
||||
id="comment"
|
||||
v-model="form.comment"
|
||||
rows="4"
|
||||
class="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full max-w-lg sm:text-sm border-gray-300 rounded-md"
|
||||
class="shadow-sm focus:ring-blumilk-500 focus:border-blumilk-500 block w-full max-w-lg sm:text-sm border-gray-300 rounded-md"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -61,6 +61,12 @@
|
||||
>
|
||||
Do
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
|
||||
>
|
||||
Dni urlopu
|
||||
</th>
|
||||
<th scope="col" />
|
||||
</tr>
|
||||
</thead>
|
||||
@ -90,6 +96,9 @@
|
||||
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{{ request.to }}
|
||||
</td>
|
||||
<td class="px-4 py-4 whitespace-nowrap text-right text-sm text-gray-500">
|
||||
{{ request.estimatedDays }}
|
||||
</td>
|
||||
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
<InertiaLink :href="`/vacation-requests/${request.id}`">
|
||||
<ChevronRightIcon class="block w-6 h-6 fill-gray-400" />
|
||||
|
@ -44,10 +44,10 @@
|
||||
</div>
|
||||
<div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium text-gray-500">
|
||||
Dni
|
||||
Dni urlopu
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
x
|
||||
{{ request.estimatedDays }}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="py-4 sm:py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
|
@ -74,7 +74,7 @@
|
||||
<h2>Wniosek o urlop</h2>
|
||||
<p class="content">
|
||||
Proszę o {{ mb_strtolower($vacationRequest->type->label()) }} w okresie od dnia {{ $vacationRequest->from->format("d.m.Y") }}
|
||||
do dnia {{ $vacationRequest->to->format("d.m.Y") }} włącznie tj. x dni roboczych za rok {{ $vacationRequest->yearPeriod->year }}.
|
||||
do dnia {{ $vacationRequest->to->format("d.m.Y") }} włącznie tj. {{ $vacationRequest->estimated_days }} dni roboczych za rok {{ $vacationRequest->yearPeriod->year }}.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user