Skip to content

Commit

Permalink
Merge pull request #33 from coolerParty/feature_26_account_chart_edit…
Browse files Browse the repository at this point in the history
…_form_add_non_current

Account Chart edit  -  added new  field Current/Noncurrent.
  • Loading branch information
coolerParty authored Nov 26, 2022
2 parents 73f1e52 + af7aee6 commit 76f2911
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
32 changes: 12 additions & 20 deletions app/Http/Livewire/AccountChart/AccountChartEditComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,47 +21,42 @@ 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;
$account->name = $this->name;
$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')
Expand All @@ -69,10 +65,6 @@ public function update()

public function confirmation()
{
// if (!auth()->user()->can('account-chart-create')) {
// abort(404);
// }

$this->authorize('account-chart-create');
}

Expand Down
36 changes: 36 additions & 0 deletions app/Http/Requests/AccountChartEditRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class AccountChartEditRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
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'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ class="block w-full px-4 py-2 mt-2 bg-white border border-gray-200 rounded-md sh
</div>
</div>

<div class="mt-4">
<div>
<label for="current_non" class="text-gray-700 dark:text-gray-200">Current / Non-current</label>
<select id="current_non" name="current_non" autocomplete="current_non"
wire:model="current_non"
class="block w-full px-4 py-2 mt-2 bg-white border border-gray-200 rounded-md shadow-sm dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 focus:outline-none focus:ring focus:border-blue-400 dark:focus:border-blue-300 sm:text-sm">
<option value="1">Current</option>
<option value="2">Non-Current</option>
<option value="3">Not Current/Non-Current</option>
</select>
</div>
</div>

<div class="flex justify-end mt-6">
<button type="submit"
class="px-6 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded-md hover:bg-gray-600 focus:outline-none focus:bg-gray-600">Update</button>
Expand Down

0 comments on commit 76f2911

Please sign in to comment.