From d377134e70ed12a7377ea89ad27c6614b86117d2 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Mon, 29 Oct 2018 22:24:24 +0800 Subject: [PATCH 1/9] Update luthfi/simple-crud-generator package --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index ee5c8e2..be9d10b 100644 --- a/composer.lock +++ b/composer.lock @@ -1,7 +1,7 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], "content-hash": "fd28a38cbcaf3bccc1d6fb34444372ee", @@ -3008,16 +3008,16 @@ }, { "name": "luthfi/simple-crud-generator", - "version": "1.2.3", + "version": "1.2.7", "source": { "type": "git", "url": "https://github.com/nafiesl/SimpleCrudGenerator.git", - "reference": "6a64e62c3b91eb92739b7c7b89d2e3439d180c94" + "reference": "0dc629fab1c1708eedf545aa81c428905e7e4864" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nafiesl/SimpleCrudGenerator/zipball/6a64e62c3b91eb92739b7c7b89d2e3439d180c94", - "reference": "6a64e62c3b91eb92739b7c7b89d2e3439d180c94", + "url": "https://api.github.com/repos/nafiesl/SimpleCrudGenerator/zipball/0dc629fab1c1708eedf545aa81c428905e7e4864", + "reference": "0dc629fab1c1708eedf545aa81c428905e7e4864", "shasum": "" }, "require": { @@ -3060,7 +3060,7 @@ "tdd-workflow", "testing" ], - "time": "2018-09-10T09:02:29+00:00" + "time": "2018-10-23T09:49:27+00:00" }, { "name": "maximebf/debugbar", From 7ab183ce845eed42e5026adadcadf650da7e76ff Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Tue, 30 Oct 2018 21:58:59 +0800 Subject: [PATCH 2/9] Add failing test for Bank Account Entry --- .../Feature/References/ManageBankAccountsTest.php | 62 ++++++---------------- 1 file changed, 17 insertions(+), 45 deletions(-) diff --git a/tests/Feature/References/ManageBankAccountsTest.php b/tests/Feature/References/ManageBankAccountsTest.php index f89dba1..f9979ab 100644 --- a/tests/Feature/References/ManageBankAccountsTest.php +++ b/tests/Feature/References/ManageBankAccountsTest.php @@ -2,8 +2,7 @@ namespace Tests\Feature\References; -use Option; -use Tests\TestCase as TestCase; +use Tests\TestCase; use Illuminate\Foundation\Testing\DatabaseMigrations; /** @@ -19,7 +18,10 @@ class ManageBankAccountsTest extends TestCase public function user_can_see_bank_account_list_in_bank_account_index_page() { $this->adminUserSigningIn(); + $bankAccount = factory(BankAccount::class)->create(); $this->visit(route('bank-accounts.index')); + + $this->seeText($bankAccount->name); } /** @test */ @@ -28,10 +30,10 @@ class ManageBankAccountsTest extends TestCase $this->adminUserSigningIn(); $this->visit(route('bank-accounts.index')); - $this->click(trans('bank_account.create')); + $this->click(__('bank_account.create')); $this->seePageIs(route('bank-accounts.index', ['action' => 'create'])); - $this->submitForm(trans('bank_account.create'), [ + $this->submitForm(__('bank_account.create'), [ 'name' => 'BankAccount 1 name', 'number' => '1234567890', 'account_name' => 'John Doe', @@ -40,40 +42,26 @@ class ManageBankAccountsTest extends TestCase $this->seePageIs(route('bank-accounts.index')); - $bankAccounts = []; - - $bankAccounts[1] = [ + $this->seeInDatabase('bank_accounts', [ '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() + public function user_can_edit_a_bank_account() { $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)); + $bankAccount = factory(BankAccount::class)->create(); $this->visit(route('bank-accounts.index')); $this->click('edit-bank_account-1'); - $this->seePageIs(route('bank-accounts.index', ['action' => 'edit', 'id' => '1'])); + $this->seePageIs(route('bank-accounts.index', ['action' => 'edit', 'id' => $bankAccount->id])); - $this->submitForm(trans('bank_account.update'), [ + $this->submitForm(__('bank_account.update'), [ 'name' => 'BankAccount 2 name', 'number' => '1234567890', 'account_name' => 'John Doe', @@ -82,15 +70,11 @@ class ManageBankAccountsTest extends TestCase $this->seePageIs(route('bank-accounts.index')); - $bankAccounts[1] = [ + $this->seeInDatabase('bank_accounts', [ 'name' => 'BankAccount 2 name', 'number' => '1234567890', 'account_name' => 'John Doe', 'description' => 'BankAccount 2 description', - ]; - - $this->seeInDatabase('site_options', [ - 'value' => json_encode($bankAccounts), ]); } @@ -99,28 +83,16 @@ class ManageBankAccountsTest extends TestCase { $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), - ]); + $bankAccount = factory(BankAccount::class)->create(); $this->visit(route('bank-accounts.index')); - $this->click('del-bank_account-2'); + $this->click('del-bank_account-'.$bankAccount->id); $this->seePageIs(route('bank-accounts.index', ['action' => 'delete', 'id' => '2'])); - $this->press(trans('app.delete_confirm_button')); + $this->press(__('app.delete_confirm_button')); - $this->dontSeeInDatabase('site_options', [ - 'value' => json_encode($bankAccounts), + $this->dontSeeInDatabase('bank_accounts', [ + 'id' => $bankAccount->id, ]); } } From 14c42eb1862697d3ca1a3af4a2715b6b2f584989 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Tue, 30 Oct 2018 22:06:32 +0800 Subject: [PATCH 3/9] Make bank account listing test passed --- app/Entities/Invoices/BankAccount.php | 10 +++++++ .../References/BankAccountsController.php | 18 +++-------- database/factories/BankAccountFactory.php | 12 ++++++++ ...018_10_30_215937_create_bank_accounts_table.php | 35 ++++++++++++++++++++++ .../Feature/References/ManageBankAccountsTest.php | 1 + 5 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 app/Entities/Invoices/BankAccount.php create mode 100644 database/factories/BankAccountFactory.php create mode 100644 database/migrations/2018_10_30_215937_create_bank_accounts_table.php diff --git a/app/Entities/Invoices/BankAccount.php b/app/Entities/Invoices/BankAccount.php new file mode 100644 index 0000000..ab21340 --- /dev/null +++ b/app/Entities/Invoices/BankAccount.php @@ -0,0 +1,10 @@ +first(); - - if (!is_null($bankAccounts)) { - $bankAccounts = $bankAccounts->value; - $bankAccounts = json_decode($bankAccounts, true); - $bankAccounts = collect($bankAccounts) - ->map(function ($bankAccount) { - return (object) $bankAccount; - }); + $bankAccounts = BankAccount::all(); - if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { - $editableBankAccount = $bankAccounts[request('id')]; - } - } else { - $bankAccounts = collect([]); + if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { + $editableBankAccount = BankAccount::find(request('id')); } return view('bank-accounts.index', compact('bankAccounts', 'editableBankAccount')); diff --git a/database/factories/BankAccountFactory.php b/database/factories/BankAccountFactory.php new file mode 100644 index 0000000..917dac3 --- /dev/null +++ b/database/factories/BankAccountFactory.php @@ -0,0 +1,12 @@ +define(BankAccount::class, function (Faker $faker) { + return [ + 'name' => 'Bank '.strtoupper(str_random(4)), + 'number' => str_random(10), + 'account_name' => $faker->name, + ]; +}); diff --git a/database/migrations/2018_10_30_215937_create_bank_accounts_table.php b/database/migrations/2018_10_30_215937_create_bank_accounts_table.php new file mode 100644 index 0000000..79eb4ff --- /dev/null +++ b/database/migrations/2018_10_30_215937_create_bank_accounts_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->string('name', 60); + $table->string('number', 30); + $table->string('account_name', 60); + $table->string('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('bank_accounts'); + } +} diff --git a/tests/Feature/References/ManageBankAccountsTest.php b/tests/Feature/References/ManageBankAccountsTest.php index f9979ab..4cb0a14 100644 --- a/tests/Feature/References/ManageBankAccountsTest.php +++ b/tests/Feature/References/ManageBankAccountsTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature\References; use Tests\TestCase; +use App\Entities\Invoices\BankAccount; use Illuminate\Foundation\Testing\DatabaseMigrations; /** From 2f69a2d3082f9cf545e73c19957018a7d989309d Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 31 Oct 2018 08:29:44 +0800 Subject: [PATCH 4/9] Fix bank account create, edit and delete --- .../References/BankAccountsController.php | 51 +++------------------- resources/views/bank-accounts/index.blade.php | 10 ++--- .../Feature/References/ManageBankAccountsTest.php | 2 +- 3 files changed, 11 insertions(+), 52 deletions(-) diff --git a/app/Http/Controllers/References/BankAccountsController.php b/app/Http/Controllers/References/BankAccountsController.php index 4876401..f75dc29 100644 --- a/app/Http/Controllers/References/BankAccountsController.php +++ b/app/Http/Controllers/References/BankAccountsController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers\References; use Illuminate\Http\Request; -use App\Entities\Options\Option; use App\Http\Controllers\Controller; use App\Entities\Invoices\BankAccount; @@ -47,24 +46,7 @@ class BankAccountsController extends Controller '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(); + BankAccount::create($newBankAccount); flash(trans('bank_account.created'), 'success'); @@ -79,7 +61,7 @@ class BankAccountsController extends Controller * * @return \Illuminate\Http\Response */ - public function update(Request $request, $bankAccountId) + public function update(Request $request, BankAccount $bankAccount) { $bankAccountData = $request->validate([ 'name' => 'required|max:60', @@ -88,18 +70,7 @@ class BankAccountsController extends Controller '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(); + $bankAccount->update($bankAccountData); flash(trans('bank_account.updated'), 'success'); @@ -113,25 +84,13 @@ class BankAccountsController extends Controller * * @return \Illuminate\Http\Response */ - public function destroy($bankAccountId) + public function destroy(BankAccount $bankAccount) { 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(); + if (request('bank_account_id') == $bankAccount->id && $bankAccount->delete()) { flash(trans('bank_account.deleted'), 'success'); diff --git a/resources/views/bank-accounts/index.blade.php b/resources/views/bank-accounts/index.blade.php index e0fd339..7494cef 100644 --- a/resources/views/bank-accounts/index.blade.php +++ b/resources/views/bank-accounts/index.blade.php @@ -6,7 +6,7 @@
- @foreach ($bankAccounts as $key => $bankAccount) + @foreach ($bankAccounts as $bankAccount)

{{ $bankAccount->name }}

@@ -21,14 +21,14 @@ {!! link_to_route( 'bank-accounts.index', trans('app.edit'), - ['action' => 'edit', 'id' => $key], - ['id' => 'edit-bank_account-' . $key] + ['action' => 'edit', 'id' => $bankAccount->id], + ['id' => 'edit-bank_account-' . $bankAccount->id] ) !!} {!! link_to_route( 'bank-accounts.index', trans('app.delete'), - ['action' => 'delete', 'id' => $key], - ['id' => 'del-bank_account-' . $key, 'class' => 'pull-right'] + ['action' => 'delete', 'id' => $bankAccount->id], + ['id' => 'del-bank_account-' . $bankAccount->id, 'class' => 'pull-right'] ) !!}
diff --git a/tests/Feature/References/ManageBankAccountsTest.php b/tests/Feature/References/ManageBankAccountsTest.php index 4cb0a14..e79af46 100644 --- a/tests/Feature/References/ManageBankAccountsTest.php +++ b/tests/Feature/References/ManageBankAccountsTest.php @@ -88,7 +88,7 @@ class ManageBankAccountsTest extends TestCase $this->visit(route('bank-accounts.index')); $this->click('del-bank_account-'.$bankAccount->id); - $this->seePageIs(route('bank-accounts.index', ['action' => 'delete', 'id' => '2'])); + $this->seePageIs(route('bank-accounts.index', ['action' => 'delete', 'id' => $bankAccount->id])); $this->press(__('app.delete_confirm_button')); From 504ade55318f7385c09f77759c2ea77d3fdbb4ec Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 31 Oct 2018 08:32:34 +0800 Subject: [PATCH 5/9] Update bank account controller docblocks --- .../References/BankAccountsController.php | 22 +++++++++------------- .../Feature/References/ManageBankAccountsTest.php | 10 ++++++++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/References/BankAccountsController.php b/app/Http/Controllers/References/BankAccountsController.php index f75dc29..a95f966 100644 --- a/app/Http/Controllers/References/BankAccountsController.php +++ b/app/Http/Controllers/References/BankAccountsController.php @@ -14,9 +14,9 @@ use App\Entities\Invoices\BankAccount; class BankAccountsController extends Controller { /** - * Display a listing of the bankAccount. + * Display a listing of the bank account. * - * @return \Illuminate\Http\Response + * @return \Illuminate\View\View */ public function index() { @@ -33,9 +33,8 @@ class BankAccountsController extends Controller /** * Store a newly created bank account in storage. * - * @param \Illuminate\Http\Request $request - * - * @return \Illuminate\Http\Response + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\RedirectResponse */ public function store(Request $request) { @@ -56,10 +55,9 @@ class BankAccountsController extends Controller /** * Update the specified bank account in storage. * - * @param \Illuminate\Http\Request $request - * @param \App\Entities\Invoices\BankAccount $bankAccount - * - * @return \Illuminate\Http\Response + * @param \Illuminate\Http\Request $request + * @param \App\Entities\Invoices\BankAccount $bankAccount + * @return \Illuminate\Http\RedirectResponse */ public function update(Request $request, BankAccount $bankAccount) { @@ -80,9 +78,8 @@ class BankAccountsController extends Controller /** * Remove the specified bank account from storage. * - * @param \App\Entities\Invoices\BankAccount $bankAccount - * - * @return \Illuminate\Http\Response + * @param \App\Entities\Invoices\BankAccount $bankAccount + * @return \Illuminate\Http\RedirectResponse */ public function destroy(BankAccount $bankAccount) { @@ -91,7 +88,6 @@ class BankAccountsController extends Controller ]); if (request('bank_account_id') == $bankAccount->id && $bankAccount->delete()) { - flash(trans('bank_account.deleted'), 'success'); return redirect()->route('bank-accounts.index'); diff --git a/tests/Feature/References/ManageBankAccountsTest.php b/tests/Feature/References/ManageBankAccountsTest.php index e79af46..bef5f49 100644 --- a/tests/Feature/References/ManageBankAccountsTest.php +++ b/tests/Feature/References/ManageBankAccountsTest.php @@ -60,7 +60,10 @@ class ManageBankAccountsTest extends TestCase $this->visit(route('bank-accounts.index')); $this->click('edit-bank_account-1'); - $this->seePageIs(route('bank-accounts.index', ['action' => 'edit', 'id' => $bankAccount->id])); + + $this->seePageIs(route('bank-accounts.index', [ + 'action' => 'edit', 'id' => $bankAccount->id, + ])); $this->submitForm(__('bank_account.update'), [ 'name' => 'BankAccount 2 name', @@ -88,7 +91,10 @@ class ManageBankAccountsTest extends TestCase $this->visit(route('bank-accounts.index')); $this->click('del-bank_account-'.$bankAccount->id); - $this->seePageIs(route('bank-accounts.index', ['action' => 'delete', 'id' => $bankAccount->id])); + + $this->seePageIs(route('bank-accounts.index', [ + 'action' => 'delete', 'id' => $bankAccount->id, + ])); $this->press(__('app.delete_confirm_button')); From f466c5414b0cd7ecc6fac15783b9e6f6d4ef3a81 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 1 Nov 2018 21:18:04 +0800 Subject: [PATCH 6/9] User can swith bank account status Bank account status: 1:active 0:in_active --- app/Entities/Invoices/BankAccount.php | 19 ++++++++++++++++++- .../References/BankAccountsController.php | 1 + ...018_10_30_215937_create_bank_accounts_table.php | 1 + resources/views/bank-accounts/forms.blade.php | 1 + resources/views/bank-accounts/index.blade.php | 1 + .../Feature/References/ManageBankAccountsTest.php | 8 ++++++++ tests/Unit/Models/BankAccountTest.php | 22 ++++++++++++++++++++++ 7 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/Models/BankAccountTest.php diff --git a/app/Entities/Invoices/BankAccount.php b/app/Entities/Invoices/BankAccount.php index ab21340..5bdc7ae 100644 --- a/app/Entities/Invoices/BankAccount.php +++ b/app/Entities/Invoices/BankAccount.php @@ -6,5 +6,22 @@ use Illuminate\Database\Eloquent\Model; class BankAccount extends Model { - protected $fillable = ['name', 'number', 'account_name', 'description']; + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'name', 'number', 'account_name', 'description', 'is_active', + ]; + + /** + * Get status attribute. + * + * @return string + */ + public function getStatusAttribute() + { + return $this->is_active == 1 ? __('app.active') : __('app.in_active'); + } } diff --git a/app/Http/Controllers/References/BankAccountsController.php b/app/Http/Controllers/References/BankAccountsController.php index a95f966..296d920 100644 --- a/app/Http/Controllers/References/BankAccountsController.php +++ b/app/Http/Controllers/References/BankAccountsController.php @@ -66,6 +66,7 @@ class BankAccountsController extends Controller 'number' => 'required|max:60', 'account_name' => 'required|max:60', 'description' => 'nullable|max:255', + 'is_active' => 'required|in:0,1', ]); $bankAccount->update($bankAccountData); diff --git a/database/migrations/2018_10_30_215937_create_bank_accounts_table.php b/database/migrations/2018_10_30_215937_create_bank_accounts_table.php index 79eb4ff..c4740c3 100644 --- a/database/migrations/2018_10_30_215937_create_bank_accounts_table.php +++ b/database/migrations/2018_10_30_215937_create_bank_accounts_table.php @@ -19,6 +19,7 @@ class CreateBankAccountsTable extends Migration $table->string('number', 30); $table->string('account_name', 60); $table->string('description')->nullable(); + $table->boolean('is_active')->default(1); // 1:active, 0:in_active $table->timestamps(); }); } diff --git a/resources/views/bank-accounts/forms.blade.php b/resources/views/bank-accounts/forms.blade.php index 740038d..d7a962a 100644 --- a/resources/views/bank-accounts/forms.blade.php +++ b/resources/views/bank-accounts/forms.blade.php @@ -24,6 +24,7 @@ {!! 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')]) !!} + {!! FormField::radios('is_active', [__('app.in_active'), __('app.active')], ['label' => __('app.status')]) !!}