From a23bff9e5d35bffb9c7e8ff7aeb9f15acc4e947d Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 13 Jan 2019 20:45:09 +0800 Subject: [PATCH 1/6] Add customer listing api endpoint --- app/Http/Controllers/Api/CustomerController.php | 18 +++++++++++++++++ routes/api.php | 5 +++++ tests/Feature/Api/FetchPartnerListTest.php | 27 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 app/Http/Controllers/Api/CustomerController.php create mode 100644 tests/Feature/Api/FetchPartnerListTest.php diff --git a/app/Http/Controllers/Api/CustomerController.php b/app/Http/Controllers/Api/CustomerController.php new file mode 100644 index 0000000..48effd7 --- /dev/null +++ b/app/Http/Controllers/Api/CustomerController.php @@ -0,0 +1,18 @@ +orderBy('name') + ->pluck('name', 'id'); + + return response()->json($customers); + } +} diff --git a/routes/api.php b/routes/api.php index df7f5ca..eebaafe 100644 --- a/routes/api.php +++ b/routes/api.php @@ -10,4 +10,9 @@ Route::group(['prefix' => 'v1', 'namespace' => 'Api', 'as' => 'api.', 'middlewar Route::patch('events/update', ['as' => 'events.update', 'uses' => 'EventsController@update']); Route::patch('events/reschedule', ['as' => 'events.reschedule', 'uses' => 'EventsController@reschedule']); Route::delete('events/delete', ['as' => 'events.destroy', 'uses' => 'EventsController@destroy']); + + /* + * Customer Route + */ + Route::post('customers', 'CustomerController@index')->name('customers.index'); }); diff --git a/tests/Feature/Api/FetchPartnerListTest.php b/tests/Feature/Api/FetchPartnerListTest.php new file mode 100644 index 0000000..7fe0225 --- /dev/null +++ b/tests/Feature/Api/FetchPartnerListTest.php @@ -0,0 +1,27 @@ +createUser('admin'); + $customer = factory(Customer::class)->create(); + + $this->postJson(route('api.customers.index'), [], [ + 'Authorization' => 'Bearer '.$user->api_token, + ]); + + $this->seeJson([ + $customer->id => $customer->name, + ]); + } +} From 0e469abcf80235a14704e4c32dc16e11daf2a73a Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 13 Jan 2019 20:47:00 +0800 Subject: [PATCH 2/6] Add vendor listing api endpoint --- app/Http/Controllers/Api/VendorController.php | 18 ++++++++++++++++++ routes/api.php | 5 +++++ tests/Feature/Api/FetchPartnerListTest.php | 16 ++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 app/Http/Controllers/Api/VendorController.php diff --git a/app/Http/Controllers/Api/VendorController.php b/app/Http/Controllers/Api/VendorController.php new file mode 100644 index 0000000..dbf7ad2 --- /dev/null +++ b/app/Http/Controllers/Api/VendorController.php @@ -0,0 +1,18 @@ +orderBy('name') + ->pluck('name', 'id'); + + return response()->json($vendors); + } +} diff --git a/routes/api.php b/routes/api.php index eebaafe..0b188cf 100644 --- a/routes/api.php +++ b/routes/api.php @@ -15,4 +15,9 @@ Route::group(['prefix' => 'v1', 'namespace' => 'Api', 'as' => 'api.', 'middlewar * Customer Route */ Route::post('customers', 'CustomerController@index')->name('customers.index'); + + /* + * Vendor Route + */ + Route::post('vendors', 'VendorController@index')->name('vendors.index'); }); diff --git a/tests/Feature/Api/FetchPartnerListTest.php b/tests/Feature/Api/FetchPartnerListTest.php index 7fe0225..44a08cd 100644 --- a/tests/Feature/Api/FetchPartnerListTest.php +++ b/tests/Feature/Api/FetchPartnerListTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature\Api; use Tests\TestCase; +use App\Entities\Partners\Vendor; use App\Entities\Partners\Customer; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -24,4 +25,19 @@ class FetchPartnerListTest extends TestCase $customer->id => $customer->name, ]); } + + /** @test */ + public function user_can_fetch_vendor_listing() + { + $user = $this->createUser('admin'); + $vendor = factory(Vendor::class)->create(); + + $this->postJson(route('api.vendors.index'), [], [ + 'Authorization' => 'Bearer '.$user->api_token, + ]); + + $this->seeJson([ + $vendor->id => $vendor->name, + ]); + } } From b2cdda251d9227e1e4716702c67502c2735d2169 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 13 Jan 2019 21:16:38 +0800 Subject: [PATCH 3/6] Change partner_id options based on in_out selection --- resources/lang/de/customer.php | 3 ++- resources/lang/de/vendor.php | 1 + resources/lang/en/customer.php | 3 ++- resources/lang/en/vendor.php | 1 + resources/lang/id/customer.php | 3 ++- resources/lang/id/vendor.php | 1 + resources/views/payments/edit.blade.php | 30 +++++++++++++++++++++++++++--- 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/resources/lang/de/customer.php b/resources/lang/de/customer.php index 17bc36d..2ea6fee 100644 --- a/resources/lang/de/customer.php +++ b/resources/lang/de/customer.php @@ -4,12 +4,13 @@ return [ // Labels 'customer' => 'Kunde', 'list' => 'Kundenliste', + 'detail' => 'Kundendetails', 'search' => 'Kundensuche', + 'select' => 'Select Customer', 'not_found' => 'Kunde nicht gefunden.', 'empty' => 'Kunde ist leer.', 'back_to_show' => 'Zurück zu Kundendetails', 'back_to_index' => 'Zurück zur Kundennliste', - 'detail' => 'Kundendetails', 'contact' => 'Kundenkontakt', // Actions diff --git a/resources/lang/de/vendor.php b/resources/lang/de/vendor.php index 9ad37ee..0a8b981 100644 --- a/resources/lang/de/vendor.php +++ b/resources/lang/de/vendor.php @@ -6,6 +6,7 @@ return [ 'list' => 'Hersteller Liste', 'detail' => 'Vendor Detail', 'search' => 'Hersteller suchen', + 'select' => 'Select Vendor', 'not_found' => 'Hersteller nicht gefunden.', 'empty' => 'Hersteller Liste ist leer.', 'back_to_show' => 'Zurück zu Herstellerdetails', diff --git a/resources/lang/en/customer.php b/resources/lang/en/customer.php index 8d4234f..e61254d 100644 --- a/resources/lang/en/customer.php +++ b/resources/lang/en/customer.php @@ -4,12 +4,13 @@ return [ // Labels 'customer' => 'Customer', 'list' => 'Customer List', + 'detail' => 'Customer Detail', 'search' => 'Search Customer', + 'select' => 'Select Customer', 'not_found' => 'Customer not found.', 'empty' => 'Customer is empty.', 'back_to_show' => 'Back to Customer Detail', 'back_to_index' => 'Back to Customer List', - 'detail' => 'Customer Detail', 'contact' => 'Customer Contact', // Actions diff --git a/resources/lang/en/vendor.php b/resources/lang/en/vendor.php index 1fe3766..85cee3d 100644 --- a/resources/lang/en/vendor.php +++ b/resources/lang/en/vendor.php @@ -6,6 +6,7 @@ return [ 'list' => 'Vendor List', 'detail' => 'Vendor Detail', 'search' => 'Search Vendor', + 'select' => 'Select Vendor', 'not_found' => 'Vendor not found.', 'empty' => 'Vendor list is empty.', 'back_to_show' => 'Back to Vendor Detail', diff --git a/resources/lang/id/customer.php b/resources/lang/id/customer.php index 6a7b881..1b7533f 100644 --- a/resources/lang/id/customer.php +++ b/resources/lang/id/customer.php @@ -4,12 +4,13 @@ return [ // Labels 'customer' => 'Customer', 'list' => 'Daftar Customer', + 'detail' => 'Detail Customer', 'search' => 'Cari Customer', + 'select' => 'Pilih Customer', 'not_found' => 'Customer tidak ditemukan', 'empty' => 'Belum ada Customer', 'back_to_show' => 'Kembali ke detail Customer', 'back_to_index' => 'Kembali ke daftar Customer', - 'detail' => 'Detail Customer', 'contact' => 'Kontak Customer', // Actions diff --git a/resources/lang/id/vendor.php b/resources/lang/id/vendor.php index e283275..7fcc94f 100644 --- a/resources/lang/id/vendor.php +++ b/resources/lang/id/vendor.php @@ -6,6 +6,7 @@ return [ 'list' => 'Daftar Vendor', 'detail' => 'Detail Vendor', 'search' => 'Cari Vendor', + 'select' => 'Pilih Vendor', 'not_found' => 'Vendor tidak ditemukan', 'empty' => 'Belum ada Vendor', 'back_to_show' => 'Kembali ke detail Vendor', diff --git a/resources/views/payments/edit.blade.php b/resources/views/payments/edit.blade.php index a8d923d..687f40a 100755 --- a/resources/views/payments/edit.blade.php +++ b/resources/views/payments/edit.blade.php @@ -34,11 +34,9 @@
@if ($payment->partner_type == 'App\Entities\Users\User') - {!! FormField::select('partner_id', $partners, ['label'=> __('payment.customer')]) !!} {{ Form::hidden('partner_type', 'users') }} - @else - {!! FormField::select('partner_id', $partners, ['label'=> __('payment.customer')]) !!} @endif + {!! FormField::select('partner_id', $partners, ['label'=> __('payment.customer')]) !!}
{!! FormField::textarea('description', ['label'=> __('payment.description')]) !!} @@ -72,6 +70,32 @@ closeOnDateSelect: true, scrollInput: false }); + $('#in_out_0').click(function() { + $.post("{{ route('api.vendors.index') }}", {}, + function(data) { + var string = ''; + string = string + ``; + $.each(data, function(index, value) { + string = string + ``; + }); + string = string + ``; + $("#partner_id").html(string); + } + ); + }); + $('#in_out_1').click(function() { + $.post("{{ route('api.customers.index') }}", {}, + function(data) { + var string = ''; + string = string + ``; + $.each(data, function(index, value) { + string = string + ``; + }); + string = string + ``; + $("#partner_id").html(string); + } + ); + }); })(); @endsection From ad88a64c5c6594b8b5e1d5c4ca95bf8d30d1ac83 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 13 Jan 2019 21:26:42 +0800 Subject: [PATCH 4/6] Show partner_id list based on payment partner type --- app/Entities/BaseRepository.php | 8 ++++++-- app/Http/Controllers/PaymentsController.php | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Entities/BaseRepository.php b/app/Entities/BaseRepository.php index 2b861fe..2c0a317 100755 --- a/app/Entities/BaseRepository.php +++ b/app/Entities/BaseRepository.php @@ -22,7 +22,9 @@ abstract class BaseRepository extends EloquentRepository */ public function getCustomersList() { - return Customer::orderBy('name')->pluck('name', 'id'); + return Customer::where('is_active', 1) + ->orderBy('name') + ->pluck('name', 'id'); } /** @@ -57,7 +59,9 @@ abstract class BaseRepository extends EloquentRepository */ public function getVendorsList() { - return Vendor::orderBy('name')->pluck('name', 'id'); + return Vendor::where('is_active', 1) + ->orderBy('name') + ->pluck('name', 'id'); } /** diff --git a/app/Http/Controllers/PaymentsController.php b/app/Http/Controllers/PaymentsController.php index 4d92ad5..873680e 100755 --- a/app/Http/Controllers/PaymentsController.php +++ b/app/Http/Controllers/PaymentsController.php @@ -98,8 +98,10 @@ class PaymentsController extends Controller if ($payment->partner_type == 'App\Entities\Users\User') { $partners = $this->repo->getWorkersList(); + } elseif ($payment->partner_type == 'App\Entities\Partners\Customer') { + $partners = ['Customer' => $this->repo->getCustomersList()]; } else { - $partners = $this->repo->getCustomersAndVendorsList(); + $partners = ['Vendor' => $this->repo->getVendorsList()]; } return view('payments.edit', compact('payment', 'projects', 'partners')); From 8beb307bc0085d6e103abc3bdbde501b797407cb Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 13 Jan 2019 21:34:22 +0800 Subject: [PATCH 5/6] Update payment edit placeholder Fix #27 --- app/Entities/BaseRepository.php | 4 ++-- app/Http/Controllers/PaymentsController.php | 4 ++-- resources/views/payments/edit.blade.php | 25 ++++++++++++++----------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/Entities/BaseRepository.php b/app/Entities/BaseRepository.php index 2c0a317..67895bd 100755 --- a/app/Entities/BaseRepository.php +++ b/app/Entities/BaseRepository.php @@ -35,8 +35,8 @@ abstract class BaseRepository extends EloquentRepository public function getCustomersAndVendorsList() { $partners = [ - 'Customer' => Customer::orderBy('name')->pluck('name', 'id')->all(), - 'Vendor' => Vendor::orderBy('name')->pluck('name', 'id')->all(), + __('customer.customer') => Customer::orderBy('name')->pluck('name', 'id')->all(), + __('vendor.vendor') => Vendor::orderBy('name')->pluck('name', 'id')->all(), ]; return $partners; diff --git a/app/Http/Controllers/PaymentsController.php b/app/Http/Controllers/PaymentsController.php index 873680e..7f26ab5 100755 --- a/app/Http/Controllers/PaymentsController.php +++ b/app/Http/Controllers/PaymentsController.php @@ -99,9 +99,9 @@ class PaymentsController extends Controller if ($payment->partner_type == 'App\Entities\Users\User') { $partners = $this->repo->getWorkersList(); } elseif ($payment->partner_type == 'App\Entities\Partners\Customer') { - $partners = ['Customer' => $this->repo->getCustomersList()]; + $partners = [__('customer.customer') => $this->repo->getCustomersList()]; } else { - $partners = ['Vendor' => $this->repo->getVendorsList()]; + $partners = [__('vendor.vendor') => $this->repo->getVendorsList()]; } return view('payments.edit', compact('payment', 'projects', 'partners')); diff --git a/resources/views/payments/edit.blade.php b/resources/views/payments/edit.blade.php index 687f40a..7458da3 100755 --- a/resources/views/payments/edit.blade.php +++ b/resources/views/payments/edit.blade.php @@ -8,13 +8,13 @@
- {!! Form::model($payment, ['route'=>['payments.update', $payment->id], 'method' => 'patch']) !!} + {!! Form::model($payment, ['route' => ['payments.update', $payment], 'method' => 'patch']) !!}

{{ __('payment.edit') }}

- {!! FormField::radios('in_out', [__('payment.out'), __('payment.in')], ['label'=> __('payment.in_out')]) !!} + {!! FormField::radios('in_out', [__('payment.out'), __('payment.in')], ['label' => __('payment.in_out')]) !!}
{!! FormField::radios('type_id', PaymentType::toArray(), ['label' => __('payment.type'), 'list_style' => 'unstyled']) !!} @@ -22,30 +22,33 @@
- {!! FormField::text('date', ['label'=> __('app.date')]) !!} + {!! FormField::text('date', ['label' => __('app.date')]) !!}
- {!! FormField::price('amount', ['label'=> __('payment.amount'), 'currency' => Option::get('money_sign', 'Rp')]) !!} + {!! FormField::price('amount', ['label' => __('payment.amount'), 'currency' => Option::get('money_sign', 'Rp')]) !!}
- {!! FormField::select('project_id', $projects, ['label'=> __('payment.project')]) !!} + {!! FormField::select('project_id', $projects, ['label' => __('payment.project')]) !!}
@if ($payment->partner_type == 'App\Entities\Users\User') {{ Form::hidden('partner_type', 'users') }} @endif - {!! FormField::select('partner_id', $partners, ['label'=> __('payment.customer')]) !!} + {!! FormField::select('partner_id', $partners, [ + 'label' => __('payment.customer'), + 'placeholder' => $payment->in_out ? __('customer.select') : __('vendor.select') + ]) !!}
- {!! FormField::textarea('description', ['label'=> __('payment.description')]) !!} + {!! FormField::textarea('description', ['label' => __('payment.description')]) !!}
{!! Form::close() !!} @@ -73,7 +76,7 @@ $('#in_out_0').click(function() { $.post("{{ route('api.vendors.index') }}", {}, function(data) { - var string = ''; + var string = ' '; string = string + ``; $.each(data, function(index, value) { string = string + ``; @@ -86,7 +89,7 @@ $('#in_out_1').click(function() { $.post("{{ route('api.customers.index') }}", {}, function(data) { - var string = ''; + var string = ' '; string = string + ``; $.each(data, function(index, value) { string = string + ``; From 6a97501a45e4d9fc1b442a1486ac5e526f793124 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Mon, 14 Jan 2019 09:06:07 +0800 Subject: [PATCH 6/6] Use payment project customer to fix failed test --- tests/Feature/Payments/ManagePaymentsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/Payments/ManagePaymentsTest.php b/tests/Feature/Payments/ManagePaymentsTest.php index 8397fd1..4ea77f5 100644 --- a/tests/Feature/Payments/ManagePaymentsTest.php +++ b/tests/Feature/Payments/ManagePaymentsTest.php @@ -166,7 +166,7 @@ class ManagePaymentsTest extends TestCase 'partner_type' => Vendor::class, 'partner_id' => $vendor->id, ]); - $customer = factory(Customer::class)->create(); + $customer = $payment->project->customer; $this->visit(route('payments.edit', $payment->id)); $this->seePageIs(route('payments.edit', $payment->id));