You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.7 KiB
104 lines
3.7 KiB
<?php
|
|
|
|
use App\Domains\Academic\Models\Term;
|
|
use App\Domains\Admission\Actions\IntakeScheduling\AdjustAdmissionScheduleDuration;
|
|
use App\Domains\Admission\Actions\IntakeScheduling\DefineAdmissionSchedule;
|
|
use App\Domains\Admission\DTOs\IntakeScheduling\AdjustAdmissionScheduleDurationDTO;
|
|
use App\Domains\Admission\DTOs\IntakeScheduling\DefineAdmissionScheduleDTO;
|
|
use App\Domains\Admission\Models\AdmissionSchedule;
|
|
use App\Domains\Admission\Models\AdmissionTrack;
|
|
use App\Livewire\Concerns\WithModal;
|
|
use App\Livewire\Concerns\WithToast;
|
|
use App\Livewire\Forms\Admission\AdmissionScheduleForm;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Support\Collection;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
new class extends Component
|
|
{
|
|
use WithModal;
|
|
use WithToast;
|
|
|
|
#[Locked]
|
|
public ?string $id = null;
|
|
|
|
#[Locked]
|
|
public string $mode = 'create';
|
|
|
|
public AdmissionScheduleForm $form;
|
|
|
|
protected string $resourceName = 'admission_schedule';
|
|
|
|
#[Computed]
|
|
public function terms(): Collection
|
|
{
|
|
return Term::all(['id', 'name']);
|
|
}
|
|
|
|
#[Computed]
|
|
public function tracks(): Collection
|
|
{
|
|
return AdmissionTrack::all(['id', 'name']);
|
|
}
|
|
|
|
public function save(DefineAdmissionSchedule $create, AdjustAdmissionScheduleDuration $update): void
|
|
{
|
|
$this->form->validate();
|
|
|
|
$startData = CarbonImmutable::parse($this->form->date_start);
|
|
$endData = CarbonImmutable::parse($this->form->date_end);
|
|
$reRegisterStartData = CarbonImmutable::parse($this->form->re_registration_date_start);
|
|
$reRegisterEndData = CarbonImmutable::parse($this->form->re_registration_date_end);
|
|
|
|
if ($this->mode === 'create') {
|
|
$create->execute(new DefineAdmissionScheduleDTO(
|
|
startData: $startData,
|
|
endData: $endData,
|
|
reRegisterStartData: $reRegisterStartData,
|
|
reRegisterEndData: $reRegisterEndData,
|
|
termId: (int) $this->form->term_id,
|
|
admissionTrackId: (int) $this->form->admission_track_id,
|
|
));
|
|
} elseif ($this->mode === 'update') {
|
|
$update->execute($this->admissionSchedule, new AdjustAdmissionScheduleDurationDTO(
|
|
startData: $startData,
|
|
endData: $endData,
|
|
reRegisterStartData: $reRegisterStartData,
|
|
reRegisterEndData: $reRegisterEndData,
|
|
));
|
|
}
|
|
|
|
$this->success($this->message);
|
|
$this->dispatch('hide-admissionschedule-form-modal');
|
|
$this->js("LaravelDataTables['admissionschedule-table'].ajax.reload(null, false)");
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
|
|
#[Computed]
|
|
public function admissionSchedule(): ?AdmissionSchedule
|
|
{
|
|
return $this->id ? AdmissionSchedule::where('ulid', $this->id)->first() : null;
|
|
}
|
|
|
|
public function show(int|string $id): void
|
|
{
|
|
$this->id = $id;
|
|
$this->mode = 'update';
|
|
$this->form->fill($this->admissionSchedule->only(['status', 'term_id', 'admission_track_id']));
|
|
$this->form->date_start = $this->admissionSchedule->date_start->format('Y-m-d');
|
|
$this->form->date_end = $this->admissionSchedule->date_end->format('Y-m-d');
|
|
$this->form->re_registration_date_start = $this->admissionSchedule->re_registration_date_start->format('Y-m-d');
|
|
$this->form->re_registration_date_end = $this->admissionSchedule->re_registration_date_end->format('Y-m-d');
|
|
}
|
|
|
|
public function hide(): void
|
|
{
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
};
|
|
|