From af7aee6e2c907d5b6e5927bd35903eacbc0e99b8 Mon Sep 17 00:00:00 2001 From: Alex Meier <92195211+coolerParty@users.noreply.github.com> Date: Sat, 26 Nov 2022 17:06:29 +0800 Subject: [PATCH] Account Chart edit - added new field Current/Noncurrent. --- .../AccountChartEditComponent.php | 32 +++++++---------- app/Http/Requests/AccountChartEditRequest.php | 36 +++++++++++++++++++ .../account-chart-edit-component.blade.php | 13 +++++++ 3 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 app/Http/Requests/AccountChartEditRequest.php diff --git a/app/Http/Livewire/AccountChart/AccountChartEditComponent.php b/app/Http/Livewire/AccountChart/AccountChartEditComponent.php index 9a21244..392fc35 100644 --- a/app/Http/Livewire/AccountChart/AccountChartEditComponent.php +++ b/app/Http/Livewire/AccountChart/AccountChartEditComponent.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire\AccountChart; +use App\Http\Requests\AccountChartEditRequest; use App\Models\AccountChart; use App\Models\AccountGroup; use App\Models\MajorAccountGroup; @@ -20,40 +21,34 @@ class AccountChartEditComponent extends Component public $acctgrp_id; public $mjracctgrp_id; public $submjracctgrp_id; + public $current_non; + + public function rules(): array + { + return (new AccountChartEditRequest())->rules($this->account_id); + } public function mount($id) { - $account = AccountChart::findOrFail($id); + $account = AccountChart::findOrFail($id); $this->account_id = $account->id; $this->code = $account->code; $this->name = $account->name; $this->acctgrp_id = $account->acctgrp_id; $this->mjracctgrp_id = $account->mjracctgrp_id; $this->submjracctgrp_id = $account->submjracctgrp_id; + $this->current_non = $account->current_non; } public function updated($fields) { - $this->validateOnly($fields, [ - 'code' => ['required', 'string'], - 'name' => ['required', 'min:3', 'string', Rule::unique('account_charts')->ignore($this->account_id)], - 'acctgrp_id' => ['required'], - 'mjracctgrp_id' => ['required'], - 'submjracctgrp_id' => ['required'], - ]); + $this->validateOnly($fields); } public function update() { $this->confirmation(); - - $this->validate([ - 'code' => ['required', 'string'], - 'name' => ['required', 'min:3', 'string', Rule::unique('account_charts')->ignore($this->account_id)], - 'acctgrp_id' => ['required'], - 'mjracctgrp_id' => ['required'], - 'submjracctgrp_id' => ['required'], - ]); + $this->validate(); $account = AccountChart::find($this->account_id); $account->code = $this->code; @@ -61,6 +56,7 @@ public function update() $account->acctgrp_id = $this->acctgrp_id; $account->mjracctgrp_id = $this->mjracctgrp_id; $account->submjracctgrp_id = $this->submjracctgrp_id; + $account->current_non = $this->current_non; $account->save(); return redirect()->route('accountchart.index') @@ -69,10 +65,6 @@ public function update() public function confirmation() { - // if (!auth()->user()->can('account-chart-create')) { - // abort(404); - // } - $this->authorize('account-chart-create'); } diff --git a/app/Http/Requests/AccountChartEditRequest.php b/app/Http/Requests/AccountChartEditRequest.php new file mode 100644 index 0000000..71f7f6d --- /dev/null +++ b/app/Http/Requests/AccountChartEditRequest.php @@ -0,0 +1,36 @@ + + */ + public function rules($account_id) + { + return [ + 'code' => ['required', 'string', Rule::unique('account_charts')->ignore($account_id)], + 'name' => ['required', 'min:3', 'string', Rule::unique('account_charts')->ignore($account_id)], + 'acctgrp_id' => ['required'], + 'mjracctgrp_id' => ['required'], + 'submjracctgrp_id' => ['required'], + 'current_non' => ['required', 'min:1', 'max:3','digits:1', 'numeric'], + ]; + } +} diff --git a/resources/views/livewire/account-chart/account-chart-edit-component.blade.php b/resources/views/livewire/account-chart/account-chart-edit-component.blade.php index c850373..97e27a9 100644 --- a/resources/views/livewire/account-chart/account-chart-edit-component.blade.php +++ b/resources/views/livewire/account-chart/account-chart-edit-component.blade.php @@ -87,6 +87,19 @@ class="block w-full px-4 py-2 mt-2 bg-white border border-gray-200 rounded-md sh +
+
+ + +
+
+