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.
 
 
 
 
 

116 lines
3.8 KiB

<?php
use App\Domains\Accounting\Actions\LedgerConfiguration\AdjustAccountClassification;
use App\Domains\Accounting\Actions\LedgerConfiguration\RegisterChartOfAccount;
use App\Domains\Accounting\DTOs\LedgerConfiguration\AdjustAccountClassificationDTO;
use App\Domains\Accounting\DTOs\LedgerConfiguration\RegisterChartOfAccountDTO;
use App\Domains\Accounting\Models\ChartOfAccount;
use App\Livewire\Concerns\HasModelFill;
use App\Livewire\Concerns\WithModal;
use App\Livewire\Concerns\WithToast;
use App\Livewire\Forms\Accounting\ChartOfAccountForm;
use Illuminate\Support\Collection;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
new class extends Component
{
use WithModal;
use WithToast;
public ChartOfAccountForm $form;
#[Locked]
public ?string $id = null;
#[Locked]
public string $mode = 'create';
protected string $resourceName = 'chart_of_account';
public function updating($property, $value): void
{
if ($property === 'form.parent_id') {
$props = explode('.', $property);
$props = implode('->', $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();
}
};