Aplikasi Keuangan yang mengatur lalu lintas transaksi antara bank dan aplikasi internal Kampus
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.
 
 
 
 
 

83 lines
2.5 KiB

<?php
use App\Domains\Academic\Actions\Calendar\InitializeAcademicTerm;
use App\Domains\Academic\Actions\Calendar\ModifyTermDate;
use App\Domains\Academic\DTOs\Calendar\InitializeAcademicTermDTO;
use App\Domains\Academic\DTOs\Calendar\ModifyTermDateDTO;
use App\Domains\Academic\Models\Term;
use App\Livewire\Concerns\WithModal;
use App\Livewire\Concerns\WithToast;
use App\Livewire\Forms\Academic\TermForm;
use Carbon\CarbonImmutable;
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 TermForm $form;
protected string $resourceName = 'term';
public function save(InitializeAcademicTerm $create, ModifyTermDate $update): void
{
$this->form->validate();
$startDate = CarbonImmutable::parse($this->form->date_start);
$endDate = CarbonImmutable::parse($this->form->date_end);
if ($this->mode === 'create') {
$create->execute(new InitializeAcademicTermDTO(
name: $this->form->name,
code: $this->form->code,
yearStudy: $this->form->year_study,
semester: $this->form->semester,
startDate: $startDate,
endDate: $endDate,
));
} elseif ($this->mode === 'update') {
$update->execute($this->term, new ModifyTermDateDTO(
startDate: $startDate,
endDate: $endDate,
));
}
$this->success($this->message);
$this->dispatch('hide-term-form-modal');
$this->js("LaravelDataTables['term-table'].ajax.reload(null, false)");
$this->form->reset();
$this->form->resetValidation();
$this->reset('id', 'mode');
}
#[Computed]
public function term(): ?Term
{
return $this->id ? Term::where('ulid', $this->id)->first() : null;
}
public function show(int|string $id): void
{
$this->id = $id;
$this->mode = 'update';
$this->form->fill($this->term->only(['name', 'code', 'year_study', 'semester']));
$this->form->date_start = $this->term->date_start->format('Y-m-d');
$this->form->date_end = $this->term->date_end->format('Y-m-d');
}
public function hide(): void
{
$this->form->reset();
$this->form->resetValidation();
$this->reset('id', 'mode');
}
};