', $props); $this->{$props} = $value; $coa = $this->chartOfAccounts->where('ulid', $value)->first(); if ($coa) { $this->form->code = $coa->code + 1; $this->form->classification = $coa->classification; } } } public function show(int|string $id): void { $this->id = $id; $this->mode = 'update'; $coa = $this->coa->except(['ulid', 'created_at', 'updated_at']); $coa['parent_id'] = $this->chartOfAccounts ->where('id', $coa['parent_id']) ->first() ?->ulid; $this->form->fill($coa); } #[Computed] public function coa(): ChartOfAccount { return $this->id ? ChartOfAccount::where('ulid', $this->id)->first() : new ChartOfAccount; } #[Computed] public function chartOfAccounts(): Collection { return ChartOfAccount::query() ->select(['id', 'name', 'code', 'ulid', 'classification']) ->get(); } public function save(RegisterChartOfAccount $register, AdjustAccountClassification $adjust): void { $this->form->validate(); $parentId = null; if($this->form->parent_id) { $parentId = $this->chartOfAccounts ->where('ulid', $this->form->parent_id) ->first() ->id; } if ($this->mode === 'create') { $register->execute(new RegisterChartOfAccountDTO( code: $this->form->code, name: $this->form->name, classification: $this->form->classification, normal_balance: $this->form->normal_balance, status: $this->form->status, parentId: $parentId, )); $this->success(__('ui/crud.success.created', ['resource' => __('resources.chart_of_account')])); } elseif ($this->mode == 'update') { $adjust->execute($this->coa, new AdjustAccountClassificationDTO( code: $this->form->code, name: $this->form->name, classification: $this->form->classification, normal_balance: $this->form->normal_balance, parentId: $parentId, )); $this->success(__('ui/crud.success.updated', ['resource' => __('resources.chart_of_account')])); } $this->dispatch('hide-chartofaccount-form-modal'); $this->js("LaravelDataTables['chart-of-account-table'].ajax.reload(null, false)"); } public function hide(): void { $this->form->reset(); $this->reset('id', 'mode'); $this->form->reset(); } };