Skip to content

Commit

Permalink
Merge pull request #32 from coolerParty/feature_25_account_chart_crea…
Browse files Browse the repository at this point in the history
…te_form_add_non_current

Account Chart View list/Create added field Current/Noncurrent.
  • Loading branch information
coolerParty authored Nov 26, 2022
2 parents 66af0d2 + 8b37ce0 commit 73f1e52
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 31 deletions.
30 changes: 11 additions & 19 deletions app/Http/Livewire/AccountChart/AccountChartAddComponent.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\AccountChartAddRequest;
use App\Imports\AccountChartImport;
use App\Models\AccountChart;
use App\Models\AccountGroup;
Expand All @@ -21,6 +22,7 @@ class AccountChartAddComponent extends Component
public $acctgrp_id;
public $mjracctgrp_id;
public $submjracctgrp_id;
public $current_non;

use WithFileUploads;
public $file;
Expand All @@ -39,40 +41,34 @@ public function importFile()
->with('create-success', 'File Uploaded successfully.');
}

public function rules(): array
{
return (new AccountChartAddRequest())->rules();
}

public function mount()
{
$this->type = null;
$this->current_non = 3;
}

public function updated($fields)
{
$this->validateOnly($fields, [
'code' => ['required', 'string'],
'name' => ['required', 'min:3', 'string', 'unique:account_charts'],
'acctgrp_id' => ['required'],
'mjracctgrp_id' => ['required'],
'submjracctgrp_id' => ['required'],
]);
$this->validateOnly($fields);
}

public function store()
{
$this->confirmation();

$this->validate([
'code' => ['required', 'string'],
'name' => ['required', 'min:3', 'string', 'unique:account_charts'],
'acctgrp_id' => ['required'],
'mjracctgrp_id' => ['required'],
'submjracctgrp_id' => ['required'],
]);
$this->validate();

$account = new AccountChart();
$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 @@ -81,10 +77,6 @@ public function store()

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

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

Expand Down
10 changes: 1 addition & 9 deletions app/Http/Livewire/AccountChart/AccountChartComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class AccountChartComponent extends Component

public function destroy($id)
{
// if (!auth()->user()->can('account-chart-delete')) {
// abort(404);
// }

$this->authorize('account-chart-delete');

$account = AccountChart::find($id);
Expand All @@ -27,13 +23,9 @@ public function destroy($id)

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

$this->authorize('account-chart-show');

$accounts = AccountChart::with('accountGroup','majorAccountGroup','SubMajorAccountGroup')->select('id', 'code', 'name', 'acctgrp_id', 'mjracctgrp_id', 'submjracctgrp_id')->orderBy('code','ASC')->paginate(10);
$accounts = AccountChart::with('accountGroup','majorAccountGroup','SubMajorAccountGroup')->select('id', 'code', 'name', 'acctgrp_id', 'mjracctgrp_id', 'submjracctgrp_id', 'current_non')->orderBy('code','ASC')->paginate(10);

return view('livewire.account-chart.account-chart-component', ['accounts' => $accounts])->layout('layouts.base');
}
Expand Down
35 changes: 35 additions & 0 deletions app/Http/Requests/AccountChartAddRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AccountChartAddRequest 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()
{
return [
'code' => ['required', 'string', 'unique:account_charts'],
'name' => ['required', 'min:3', 'string', 'unique:account_charts'],
'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 @@ -15,12 +15,12 @@ public function up()
{
Schema::create('account_charts', function (Blueprint $table) {
$table->id();
$table->string('code');
$table->string('code')->unique();
$table->string('name')->unique();
$table->BigInteger('acctgrp_id')->unsigned()->nullable();
$table->BigInteger('mjracctgrp_id')->unsigned()->nullable();
$table->BigInteger('submjracctgrp_id')->unsigned()->nullable();
$table->tinyInteger('current_non')->nullable(); // 1=Current, 2, Non-current,
$table->tinyInteger('current_non')->default(3); // 1=Current, 2, Non-current, 3, not yet set or Equity account group
$table->timestamps();
$table->foreign('acctgrp_id')->references('id')->on('account_groups');
$table->foreign('mjracctgrp_id')->references('id')->on('major_account_groups');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,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">Save</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppe
class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
Sub Major Account Group
</th>
<th scope="col"
class="px-6 py-3 text-xs font-medium tracking-wider text-left text-gray-500 uppercase">
Current / Non-current
</th>
<th scope="col" class="relative px-6 py-3">
Action
</th>
Expand Down Expand Up @@ -153,7 +157,7 @@ class="p-1 transition-colors duration-200 transform rounded-md hover:bg-opacity-
<td class="px-6 py-4 whitespace-nowrap">
<div class="text-sm font-medium text-gray-900">{{ $account->code }}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<td class="px-6 py-4">
<div class="text-sm font-medium text-gray-900">{{ $account->name }}</div>
</td>
<td class="px-6 py-4">
Expand All @@ -165,6 +169,19 @@ class="p-1 transition-colors duration-200 transform rounded-md hover:bg-opacity-
<td class="px-6 py-4 ">
<div class="text-sm font-medium text-gray-900">{{ $account->SubMajorAccountGroup->name }}</div>
</td>
<td class="px-6 py-4 ">
<div class="text-sm font-medium text-gray-900">
@if($account->current_non == 1)
Current
@elseif($account->current_non == 2)
Non Current
@elseif($account->accountgroup->code == 3)
Equity
@else
Not yet Selected
@endif
</div>
</td>
<td class="px-6 py-4 text-sm font-medium text-right whitespace-nowrap">
@can('account-chart-edit')
<x-link-success href="{{ route('accountchart.edit', ['id' => $account->id]) }}"> Edit
Expand Down

0 comments on commit 73f1e52

Please sign in to comment.