diff --git a/app/Entities/BaseRepository.php b/app/Entities/BaseRepository.php index 2b861fe..67895bd 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'); } /** @@ -33,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; @@ -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/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/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/app/Http/Controllers/PaymentsController.php b/app/Http/Controllers/PaymentsController.php index 4d92ad5..7f26ab5 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.customer') => $this->repo->getCustomersList()]; } else { - $partners = $this->repo->getCustomersAndVendorsList(); + $partners = [__('vendor.vendor') => $this->repo->getVendorsList()]; } return view('payments.edit', compact('payment', 'projects', 'partners')); 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..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,32 +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') - {!! 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'), + 'placeholder' => $payment->in_out ? __('customer.select') : __('vendor.select') + ]) !!}
- {!! FormField::textarea('description', ['label'=> __('payment.description')]) !!} + {!! FormField::textarea('description', ['label' => __('payment.description')]) !!}
{!! Form::close() !!} @@ -72,6 +73,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 diff --git a/routes/api.php b/routes/api.php index df7f5ca..0b188cf 100644 --- a/routes/api.php +++ b/routes/api.php @@ -10,4 +10,14 @@ 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'); + + /* + * Vendor Route + */ + Route::post('vendors', 'VendorController@index')->name('vendors.index'); }); diff --git a/tests/Feature/Api/FetchPartnerListTest.php b/tests/Feature/Api/FetchPartnerListTest.php new file mode 100644 index 0000000..44a08cd --- /dev/null +++ b/tests/Feature/Api/FetchPartnerListTest.php @@ -0,0 +1,43 @@ +createUser('admin'); + $customer = factory(Customer::class)->create(); + + $this->postJson(route('api.customers.index'), [], [ + 'Authorization' => 'Bearer '.$user->api_token, + ]); + + $this->seeJson([ + $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, + ]); + } +} 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));