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