diff --git a/app/Http/Controllers/References/BankAccountsController.php b/app/Http/Controllers/References/BankAccountsController.php
new file mode 100644
index 0000000..5f65be4
--- /dev/null
+++ b/app/Http/Controllers/References/BankAccountsController.php
@@ -0,0 +1,142 @@
+first();
+
+ if (!is_null($bankAccounts)) {
+ $bankAccounts = $bankAccounts->value;
+ $bankAccounts = json_decode($bankAccounts, true);
+
+ if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
+ $editableBankAccount = (object) $bankAccounts[request('id')];
+ }
+ } else {
+ $bankAccounts = [];
+ }
+
+ return view('bank-accounts.index', compact('bankAccounts', 'editableBankAccount'));
+ }
+
+ /**
+ * Store a newly created bank account in storage.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @return \Illuminate\Http\Response
+ */
+ public function store(Request $request)
+ {
+ $newBankAccount = $request->validate([
+ 'name' => 'required|max:60',
+ 'number' => 'required|max:60',
+ 'account_name' => 'required|max:60',
+ 'description' => 'nullable|max:255',
+ ]);
+
+ $option = Option::firstOrNew(['key' => 'bank_accounts']);
+ if ($option->exists) {
+ $bankAccounts = $option->value;
+ $bankAccounts = json_decode($bankAccounts, true);
+ if ($bankAccounts == []) {
+ $bankAccounts[1] = $newBankAccount;
+ } else {
+ $bankAccounts[] = $newBankAccount;
+ }
+ } else {
+ $bankAccounts = [];
+ $bankAccounts[1] = $newBankAccount;
+ }
+
+ $bankAccounts = json_encode($bankAccounts);
+
+ $option->value = $bankAccounts;
+ $option->save();
+
+ flash(trans('bank_account.created'), 'success');
+
+ return redirect()->route('bank-accounts.index');
+ }
+
+ /**
+ * Update the specified bank account in storage.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @param \App\Entities\Invoices\BankAccount $bankAccount
+ * @return \Illuminate\Http\Response
+ */
+ public function update(Request $request, $bankAccountId)
+ {
+ $bankAccountData = $request->validate([
+ 'name' => 'required|max:60',
+ 'number' => 'required|max:60',
+ 'account_name' => 'required|max:60',
+ 'description' => 'nullable|max:255',
+ ]);
+
+ $bankAccounts = Option::where('key', 'bank_accounts')->first();
+
+ $bankAccounts = $bankAccounts->value;
+ $bankAccounts = json_decode($bankAccounts, true);
+
+ $bankAccounts[$bankAccountId] = $bankAccountData;
+
+ $bankAccounts = json_encode($bankAccounts);
+
+ $option = Option::where('key', 'bank_accounts')->first();
+ $option->value = $bankAccounts;
+ $option->save();
+
+ flash(trans('bank_account.updated'), 'success');
+
+ return redirect()->route('bank-accounts.index');
+ }
+
+ /**
+ * Remove the specified bank account from storage.
+ *
+ * @param \App\Entities\Invoices\BankAccount $bankAccount
+ * @return \Illuminate\Http\Response
+ */
+ public function destroy($bankAccountId)
+ {
+ request()->validate([
+ 'bank_account_id' => 'required',
+ ]);
+
+ if (request('bank_account_id') == $bankAccountId) {
+
+ $bankAccounts = Option::where('key', 'bank_accounts')->first();
+
+ $bankAccounts = $bankAccounts->value;
+ $bankAccounts = json_decode($bankAccounts, true);
+
+ unset($bankAccounts[$bankAccountId]);
+
+ $bankAccounts = json_encode($bankAccounts);
+
+ $option = Option::where('key', 'bank_accounts')->first();
+ $option->value = $bankAccounts;
+ $option->save();
+
+ flash(trans('bank_account.deleted'), 'success');
+
+ return redirect()->route('bank-accounts.index');
+ }
+
+ return back();
+ }
+}
diff --git a/resources/lang/id/bank_account.php b/resources/lang/id/bank_account.php
new file mode 100644
index 0000000..fc21def
--- /dev/null
+++ b/resources/lang/id/bank_account.php
@@ -0,0 +1,28 @@
+ 'Rekening Bank',
+ 'list' => 'Daftar Rekening Bank',
+ 'empty' => 'Belum ada Rekening Bank',
+ 'back_to_index' => 'Kembali ke daftar Rekening Bank',
+
+ // Actions
+ 'create' => 'Input Rekening Bank Baru',
+ 'created' => 'Input Rekening Bank baru telah berhasil.',
+ 'show' => 'Lihat Detail Rekening Bank',
+ 'edit' => 'Edit Rekening Bank',
+ 'update' => 'Update Rekening Bank',
+ 'updated' => 'Update data Rekening Bank telah berhasil.',
+ 'delete' => 'Hapus Rekening Bank',
+ 'delete_confirm' => 'Anda yakin akan menghapus Rekening Bank ini?',
+ 'deleted' => 'Hapus data Rekening Bank telah berhasil.',
+ 'undeleted' => 'Data Rekening Bank gagal dihapus.',
+ 'undeleteable' => 'Data Rekening Bank tidak dapat dihapus.',
+
+ // Attributes
+ 'name' => 'Nama Bank',
+ 'number' => 'No. Rekening',
+ 'account_name' => 'Atas Nama',
+ 'description' => 'Deskripsi',
+];
diff --git a/resources/views/bank-accounts/forms.blade.php b/resources/views/bank-accounts/forms.blade.php
new file mode 100644
index 0000000..740038d
--- /dev/null
+++ b/resources/views/bank-accounts/forms.blade.php
@@ -0,0 +1,65 @@
+@if (Request::get('action') == 'create')
+
+
{{ trans('bank_account.create') }}
+ {!! Form::open(['route' => 'bank-accounts.store']) !!}
+
+ {!! FormField::text('name', ['required' => true, 'label' => trans('bank_account.name')]) !!}
+ {!! FormField::text('number', ['required' => true, 'label' => trans('bank_account.number')]) !!}
+ {!! FormField::text('account_name', ['required' => true, 'label' => trans('bank_account.account_name')]) !!}
+ {!! FormField::textarea('description', ['label' => trans('bank_account.description')]) !!}
+
+
+ {!! Form::close() !!}
+
+@endif
+@if (Request::get('action') == 'edit' && $editableBankAccount)
+
+
{{ trans('bank_account.edit') }}
+ {!! Form::model($editableBankAccount, ['route' => ['bank-accounts.update', request('id')],'method' => 'patch']) !!}
+
+ {!! FormField::text('name', ['required' => true, 'label' => trans('bank_account.name')]) !!}
+ {!! FormField::text('number', ['required' => true, 'label' => trans('bank_account.number')]) !!}
+ {!! FormField::text('account_name', ['required' => true, 'label' => trans('bank_account.account_name')]) !!}
+ {!! FormField::textarea('description', ['label' => trans('bank_account.description')]) !!}
+
+
+ {!! Form::close() !!}
+
+@endif
+@if (Request::get('action') == 'delete' && $editableBankAccount)
+
+
{{ trans('bank_account.delete') }}
+
+
+
{{ $editableBankAccount->name }}
+
+
{{ $editableBankAccount->number }}
+
+
{{ $editableBankAccount->account_name }}
+
+
{{ $editableBankAccount->description }}
+ {!! $errors->first('bank_account_id', '
:message') !!}
+
+
+
{{ trans('app.delete_confirm') }}
+
+
+@endif
diff --git a/resources/views/bank-accounts/index.blade.php b/resources/views/bank-accounts/index.blade.php
new file mode 100644
index 0000000..29143d7
--- /dev/null
+++ b/resources/views/bank-accounts/index.blade.php
@@ -0,0 +1,66 @@
+@extends('layouts.app')
+
+@section('title', trans('bank_account.list'))
+
+@section('content')
+
+
+
+
+
+
+
+ | {{ trans('app.table_no') }} |
+ {{ trans('bank_account.name') }} |
+ {{ trans('bank_account.number') }} |
+ {{ trans('bank_account.account_name') }} |
+ {{ trans('bank_account.description') }} |
+ {{ trans('app.action') }} |
+
+
+
+ @forelse($bankAccounts as $key => $bankAccount)
+ @php
+ $bankAccount = (object) $bankAccount;
+ @endphp
+
+ | {{ $key }} |
+ {{ $bankAccount->name }} |
+ {{ $bankAccount->number }} |
+ {{ $bankAccount->account_name }} |
+ {{ $bankAccount->description }} |
+
+ {!! link_to_route(
+ 'bank-accounts.index',
+ trans('app.edit'),
+ ['action' => 'edit', 'id' => $key],
+ ['id' => 'edit-bank_account-' . $key]
+ ) !!} |
+ {!! link_to_route(
+ 'bank-accounts.index',
+ trans('app.delete'),
+ ['action' => 'delete', 'id' => $key],
+ ['id' => 'del-bank_account-' . $key]
+ ) !!}
+ |
+
+ @empty
+
+ | {{ trans('bank_account.empty') }} |
+
+ @endforelse
+
+
+
+
+
+ @includeWhen(Request::has('action'), 'bank-accounts.forms')
+
+
+@endsection
diff --git a/routes/web/references.php b/routes/web/references.php
index 439d789..c407609 100644
--- a/routes/web/references.php
+++ b/routes/web/references.php
@@ -8,4 +8,9 @@ Route::group(['namespace' => 'References', 'middleware' => ['web', 'role:admin']
Route::post('options/store', ['as' => 'options.store', 'uses' => 'OptionsController@store']);
Route::patch('options/save', ['as' => 'options.save', 'uses' => 'OptionsController@save']);
Route::delete('options/{optionId}/destroy', ['as' => 'options.destroy', 'uses' => 'OptionsController@destroy']);
+
+ /**
+ * Bank Accounts Routes
+ */
+ Route::apiResource('bank-accounts', 'BankAccountsController');
});
diff --git a/tests/Feature/References/ManageBankAccountsTest.php b/tests/Feature/References/ManageBankAccountsTest.php
new file mode 100644
index 0000000..199b60f
--- /dev/null
+++ b/tests/Feature/References/ManageBankAccountsTest.php
@@ -0,0 +1,121 @@
+adminUserSigningIn();
+ $this->visit(route('bank-accounts.index'));
+ }
+
+ /** @test */
+ public function user_can_create_a_bank_account()
+ {
+ $this->adminUserSigningIn();
+ $this->visit(route('bank-accounts.index'));
+
+ $this->click(trans('bank_account.create'));
+ $this->seePageIs(route('bank-accounts.index', ['action' => 'create']));
+
+ $this->submitForm(trans('bank_account.create'), [
+ 'name' => 'BankAccount 1 name',
+ 'number' => '1234567890',
+ 'account_name' => 'John Doe',
+ 'description' => 'BankAccount 1 description',
+ ]);
+
+ $this->seePageIs(route('bank-accounts.index'));
+
+ $bankAccounts = [];
+
+ $bankAccounts[1] = [
+ 'name' => 'BankAccount 1 name',
+ 'number' => '1234567890',
+ 'account_name' => 'John Doe',
+ 'description' => 'BankAccount 1 description',
+ ];
+
+ $this->seeInDatabase('site_options', [
+ 'value' => json_encode($bankAccounts),
+ ]);
+ }
+
+ /** @test */
+ public function user_can_edit_a_bank_account_within_search_query()
+ {
+ $this->adminUserSigningIn();
+
+ $bankAccounts = [];
+ $bankAccounts[1] = [
+ 'name' => 'BankAccount 1 name',
+ 'number' => '1234567890',
+ 'account_name' => 'John Doe',
+ 'description' => 'BankAccount 1 description',
+ ];
+
+ Option::set('bank_accounts', json_encode($bankAccounts));
+
+ $this->visit(route('bank-accounts.index'));
+ $this->click('edit-bank_account-1');
+ $this->seePageIs(route('bank-accounts.index', ['action' => 'edit', 'id' => '1']));
+
+ $this->submitForm(trans('bank_account.update'), [
+ 'name' => 'BankAccount 2 name',
+ 'number' => '1234567890',
+ 'account_name' => 'John Doe',
+ 'description' => 'BankAccount 2 description',
+ ]);
+
+ $this->seePageIs(route('bank-accounts.index'));
+
+ $bankAccounts[1] = [
+ 'name' => 'BankAccount 2 name',
+ 'number' => '1234567890',
+ 'account_name' => 'John Doe',
+ 'description' => 'BankAccount 2 description',
+ ];
+
+ $this->seeInDatabase('site_options', [
+ 'value' => json_encode($bankAccounts),
+ ]);
+ }
+
+ /** @test */
+ public function user_can_delete_a_bank_account()
+ {
+ $this->adminUserSigningIn();
+
+ $bankAccounts = [];
+ $bankAccounts[2] = [
+ 'name' => 'BankAccount 1 name',
+ 'number' => '1234567890',
+ 'account_name' => 'John Doe',
+ 'description' => 'BankAccount 1 description',
+ ];
+
+ Option::set('bank_accounts', json_encode($bankAccounts));
+
+ $this->seeInDatabase('site_options', [
+ 'value' => json_encode($bankAccounts),
+ ]);
+
+ $this->visit(route('bank-accounts.index'));
+ $this->click('del-bank_account-2');
+ $this->seePageIs(route('bank-accounts.index', ['action' => 'delete', 'id' => '2']));
+
+ $this->press(trans('app.delete_confirm_button'));
+
+ $this->dontSeeInDatabase('site_options', [
+ 'value' => json_encode($bankAccounts),
+ ]);
+ }
+}