From f5a007021dc18a5c4ec7a6d3a0a16ef650551977 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 26 Oct 2017 15:23:58 +0800 Subject: [PATCH] Add customer feature --- app/Entities/Partners/Customer.php | 10 ++ .../Controllers/Partners/CustomersController.php | 104 ++++++++++++ app/Policies/Partners/CustomerPolicy.php | 64 ++++++++ app/Providers/AuthServiceProvider.php | 1 + database/factories/CustomerFactory.php | 11 ++ .../2017_10_26_134455_create_customers_table.php | 38 +++++ resources/lang/id/customer.php | 27 +++ resources/views/customers/forms.blade.php | 66 ++++++++ resources/views/customers/index.blade.php | 67 ++++++++ routes/web.php | 4 +- routes/web/helpers.php | 182 --------------------- tests/Feature/ManageCustomersTest.php | 108 ++++++++++++ tests/Unit/Models/CustomerTest.php | 19 +++ tests/Unit/Policies/CustomerPolicyTest.php | 43 +++++ 14 files changed, 560 insertions(+), 184 deletions(-) create mode 100644 app/Entities/Partners/Customer.php create mode 100644 app/Http/Controllers/Partners/CustomersController.php create mode 100644 app/Policies/Partners/CustomerPolicy.php create mode 100644 database/factories/CustomerFactory.php create mode 100644 database/migrations/2017_10_26_134455_create_customers_table.php create mode 100644 resources/lang/id/customer.php create mode 100644 resources/views/customers/forms.blade.php create mode 100644 resources/views/customers/index.blade.php delete mode 100644 routes/web/helpers.php create mode 100644 tests/Feature/ManageCustomersTest.php create mode 100644 tests/Unit/Models/CustomerTest.php create mode 100644 tests/Unit/Policies/CustomerPolicyTest.php diff --git a/app/Entities/Partners/Customer.php b/app/Entities/Partners/Customer.php new file mode 100644 index 0000000..027eabb --- /dev/null +++ b/app/Entities/Partners/Customer.php @@ -0,0 +1,10 @@ +where('name', 'like', '%'.request('q').'%'); + })->paginate(25); + + if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) { + $editableCustomer = Customer::find(request('id')); + } + + return view('customers.index', compact('customers', 'editableCustomer')); + } + + /** + * Store a newly created customer in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + $newCustomerData = $this->validate($request, [ + 'name' => 'required|max:60', + 'email' => 'nullable|email|unique:customers,email', + 'phone' => 'nullable|max:255', + 'pic' => 'nullable|max:255', + 'address' => 'nullable|max:255', + 'notes' => 'nullable|max:255', + ]); + + Customer::create($newCustomerData); + + flash(trans('customer.created'), 'success'); + + return redirect()->route('customers.index'); + } + + /** + * Update the specified customer in storage. + * + * @param \Illuminate\Http\Request $request + * @param \App\Entities\Partners\Customer $customer + * @return \Illuminate\Http\Response + */ + public function update(Request $request, Customer $customer) + { + $customerData = $this->validate($request, [ + 'name' => 'required|max:60', + 'email' => 'nullable|email|unique:customers,email,'.$customer->id, + 'phone' => 'nullable|max:255', + 'pic' => 'nullable|max:255', + 'address' => 'nullable|max:255', + 'notes' => 'nullable|max:255', + 'is_active' => 'required|boolean', + ]); + + $routeParam = request()->only('page', 'q'); + + $customer = $customer->update($customerData); + + flash(trans('customer.updated'), 'success'); + return redirect()->route('customers.index', $routeParam); + } + + /** + * Remove the specified customer from storage. + * + * @param \App\Entities\Partners\Customer $customer + * @return \Illuminate\Http\Response + */ + public function destroy(Customer $customer) + { + // TODO: user cannot delete customer that has been used in other table + $this->validate(request(), [ + 'customer_id' => 'required', + ]); + + $routeParam = request()->only('page', 'q'); + + if (request('customer_id') == $customer->id && $customer->delete()) { + flash(trans('customer.deleted'), 'warning'); + return redirect()->route('customers.index', $routeParam); + } + + flash(trans('customer.undeleted'), 'danger'); + return back(); + } +} diff --git a/app/Policies/Partners/CustomerPolicy.php b/app/Policies/Partners/CustomerPolicy.php new file mode 100644 index 0000000..20992f6 --- /dev/null +++ b/app/Policies/Partners/CustomerPolicy.php @@ -0,0 +1,64 @@ + 'App\Policies\Partners\CustomerPolicy', 'App\Entities\Partners\Vendor' => 'App\Policies\Partners\VendorPolicy', 'App\Entities\Users\Event' => 'App\Policies\EventPolicy', ]; diff --git a/database/factories/CustomerFactory.php b/database/factories/CustomerFactory.php new file mode 100644 index 0000000..6047205 --- /dev/null +++ b/database/factories/CustomerFactory.php @@ -0,0 +1,11 @@ +define(Customer::class, function (Faker $faker) { + + return [ + 'name' => $faker->company, + ]; +}); diff --git a/database/migrations/2017_10_26_134455_create_customers_table.php b/database/migrations/2017_10_26_134455_create_customers_table.php new file mode 100644 index 0000000..f9e55a1 --- /dev/null +++ b/database/migrations/2017_10_26_134455_create_customers_table.php @@ -0,0 +1,38 @@ +increments('id'); + $table->string('name', 60); + $table->string('email')->nullable()->unique(); + $table->string('phone')->nullable(); + $table->string('pic')->nullable(); + $table->string('address')->nullable(); + $table->string('notes')->nullable(); + $table->boolean('is_active')->default(1); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('customers'); + } +} diff --git a/resources/lang/id/customer.php b/resources/lang/id/customer.php new file mode 100644 index 0000000..bd6250b --- /dev/null +++ b/resources/lang/id/customer.php @@ -0,0 +1,27 @@ + 'Customer', + 'list' => 'Customer List', + 'search' => 'Search Customer', + 'not_found' => 'Customer not found.', + 'empty' => 'Customer is empty.', + 'back_to_show' => 'Back to Customer Detail', + 'back_to_index' => 'Back to Customer List', + + // Actions + 'create' => 'Create new Customer', + 'created' => 'Create new Customer succeded.', + 'edit' => 'Edit Customer', + 'update' => 'Update Customer', + 'updated' => 'Update Customer succeded.', + 'delete' => 'Delete Customer', + 'delete_confirm' => 'Are you sure to delete this Customer?', + 'deleted' => 'Delete Customer succeded.', + 'undeleted' => 'Customer not deleted.', + + // Attributes + 'name' => 'Customer Name', + 'description' => 'Customer Description', +]; diff --git a/resources/views/customers/forms.blade.php b/resources/views/customers/forms.blade.php new file mode 100644 index 0000000..fb88d52 --- /dev/null +++ b/resources/views/customers/forms.blade.php @@ -0,0 +1,66 @@ +@if (Request::get('action') == 'create') + {!! Form::open(['route' => 'customers.store']) !!} + {!! FormField::text('name', ['required' => true]) !!} + {!! FormField::email('email') !!} + {!! FormField::text('phone') !!} + {!! FormField::text('pic') !!} + {!! FormField::textarea('address') !!} + {!! FormField::textarea('notes') !!} + {!! Form::submit(trans('customer.create'), ['class' => 'btn btn-success']) !!} + {{ link_to_route('customers.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} + {!! Form::close() !!} +@endif +@if (Request::get('action') == 'edit' && $editableCustomer) + {!! Form::model($editableCustomer, ['route' => ['customers.update', $editableCustomer->id],'method' => 'patch']) !!} + {!! FormField::text('name', ['required' => true]) !!} + {!! FormField::email('email') !!} + {!! FormField::text('phone') !!} + {!! FormField::text('pic') !!} + {!! FormField::textarea('address') !!} + {!! FormField::textarea('notes') !!} + {!! FormField::radios('is_active', ['Non Aktif', 'Aktif']) !!} + @if (request('q')) + {{ Form::hidden('q', request('q')) }} + @endif + @if (request('page')) + {{ Form::hidden('page', request('page')) }} + @endif + {!! Form::submit(trans('customer.update'), ['class' => 'btn btn-success']) !!} + {{ link_to_route('customers.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} + {!! Form::close() !!} +@endif +@if (Request::get('action') == 'delete' && $editableCustomer) +
+

{{ trans('customer.delete') }}

+
+ +

{{ $editableCustomer->name }}

+ +

{{ $editableCustomer->email }}

+ +

{{ $editableCustomer->phone }}

+ +

{{ $editableCustomer->address }}

+ +

{{ $editableCustomer->is_active }}

+ +

{{ $editableCustomer->notes }}

+ {!! $errors->first('customer_id', ':message') !!} +
+
+
{{ trans('app.delete_confirm') }}
+ +
+@endif diff --git a/resources/views/customers/index.blade.php b/resources/views/customers/index.blade.php new file mode 100644 index 0000000..2fc5da9 --- /dev/null +++ b/resources/views/customers/index.blade.php @@ -0,0 +1,67 @@ +@extends('layouts.app') + +@section('title', trans('customer.list')) + +@section('content') +

+
+ {{ link_to_route('customers.index', trans('customer.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }} +
+ {{ trans('customer.list') }} + {{ trans('app.total') }} : {{ $customers->total() }} {{ trans('customer.customer') }} +

+
+
+
+
+ {{ Form::open(['method' => 'get','class' => 'form-inline']) }} + {!! FormField::text('q', ['value' => request('q'), 'label' => trans('customer.search'), 'class' => 'input-sm']) !!} + {{ Form::submit(trans('customer.search'), ['class' => 'btn btn-sm']) }} + {{ link_to_route('customers.index', trans('app.reset')) }} + {{ Form::close() }} +
+ + + + + + + + + + + + + @foreach($customers as $key => $customer) + + + + + + + + + @endforeach + +
{{ trans('app.table_no') }}{{ trans('customer.name') }}{{ trans('contact.email') }}{{ trans('contact.phone') }}{{ trans('app.status') }}{{ trans('app.action') }}
{{ $customers->firstItem() + $key }}{{ $customer->name }}{{ $customer->email }}{{ $customer->phone }}{{ $customer->is_active }} + {!! link_to_route( + 'customers.index', + trans('app.edit'), + ['action' => 'edit', 'id' => $customer->id] + Request::only('page', 'q'), + ['id' => 'edit-customer-' . $customer->id] + ) !!} | + {!! link_to_route( + 'customers.index', + trans('app.delete'), + ['action' => 'delete', 'id' => $customer->id] + Request::only('page', 'q'), + ['id' => 'del-customer-' . $customer->id] + ) !!} +
+
{{ $customers->appends(Request::except('page'))->render() }}
+
+
+
+ @includeWhen(Request::has('action'), 'customers.forms') +
+
+@endsection diff --git a/routes/web.php b/routes/web.php index 0809622..db047bf 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1,5 @@ loginUsingId(1); -require __DIR__ . '/web/helpers.php'; require __DIR__ . '/web/pages.php'; require __DIR__ . '/web/users.php'; require __DIR__ . '/web/references.php'; @@ -25,3 +23,5 @@ Route::group(['middleware' => ['web','role:admin']], function () { }); Route::apiResource('vendors', 'Partners\VendorsController'); + +Route::apiResource('customers', 'Partners\CustomersController'); diff --git a/routes/web/helpers.php b/routes/web/helpers.php deleted file mode 100644 index fdd9cc5..0000000 --- a/routes/web/helpers.php +++ /dev/null @@ -1,182 +0,0 @@ -
'; -// }); - -// Route::get('add-customers', function() { -// $customers = ['Huda','Om Ekong','Isra Tanjung','Ahmad Fatah','STAI Buntok','Hasto','Jakhoster','Ujang Rahman','Donny','Ipul Batulicin','Joenathan Tanumiha','Prima','Dinas Koperasi UKM Kalsel','Stikes Husada Borneo','Rumah Web','Herbert','Donny Kurniawan']; -// foreach ($customers as $customer) { -// $user = new App\Entities\Users\User; -// $user->name = $customer; -// $user->username = str_replace(' ', '_', strtolower($customer)); -// $user->email = $user->username . '@mail.com'; -// $user->password = 'member'; -// $user->save(); -// $user->assignRole('customer'); -// } -// }); - -Route::get('add-existing-payments', function() { - // $payments = [ - // ['Frestour.com','500000','2014-05-14','Jasa website','Heru Yugo'], - // ['Elfbandung','500000','2014-06-12','Sistem reservasi','Heru Yugo'], - // ['Skripsi Ryan','250000','2014-06-21','Input jadwal, export to XL & PDF','Heru Yugo'], - // ['Bandungrafting.com','300000','2014-06-30','Jasa website','Heru Yugo'], - // ['Cianjurnews.com','150000','2014-07-09','Halaman index','Heru Yugo'], - // ['Bandungrafting.com','150000','2014-07-11','Jasa website','Heru Yugo'], - // ['Glowinklash.com','250000','2014-07-20','Jasa website','Heru Yugo'], - // ['Trijayatrans.com','50000','2014-07-20','Form reservasi email','Heru Yugo'], - // ['Skripsi Rotan','500000','2014-08-10','Shopping cart, halaman produk dgn pengurutan produk terlaris, CRUD tarif pengiriman','Andie'], - // ['Skripsi Makarizo','500000','2014-08-10','Shopping cart, laporan penjualan, backup database MySQL','Andie'], - // ['Stimi-bjm.ac.id','2000000','2014-08-11','DP jasa website','STIMI'], - // ['Stimi-bjm.ac.id','-1000000','2014-08-11','DP jasa website, hosting, domain','Heru Yugo'], - // ['Belimukena.com','5000000','2014-08-17','Shopping cart, management sistem','Heru Yugo'], - // ['Belimukena.com','-500000','2014-08-17','Pembagian belimukena.com','Heru Yugo'], - // ['Skripsi Absensi (sms gateway)','700000','2014-08-17','SMS gateway broadcast, input absen dan laporan semester','Andie'], - // ['Skripsi SPB (sms gateway)','300000','2014-08-17','SMS gateway broadcast dan laporan','Andie'], - // ['Belimukena.com','200000','2014-09-08','Revisi tambahan','Heru Yugo'], - // ['Imet18.com','750000','2014-09-12','Sistem informasi laporan prospecting','Heru Yugo'], - // ['Livescore','2000000','2014-09-18','Website seperti livescore','Heru Yugo'], - // ['Rajabagus','1400000','2014-09-24','Pembuatan import code/voucher dan signup with voucher','Heru Yugo'], - // ['Stimi-bjm.ac.id','2000000','2014-10-14','Pelunasan website stimi','STIMI'], - // ['Belimukena.com','600000','2014-11-07','Biaya maintenance 2014-11','Heru Yugo'], - // ['bandungtraverservice.com','500000','2014-11-13','fee isi content bandung travel service','Heru Yugo'], - // ['Belimukena.com','300000','2014-12-08','Biaya maintenance 2014-12','Heru Yugo'], - // ['Belimukena.com','100000','2014-12-08','fee buat reject order reason','Heru Yugo'], - // ['Legacyvapestore.com','350000','2014-12-12','fee isi content dan buat tutorial','Heru Yugo'], - // ['Aplikasi Toko Obat Sholah (Andie)','700000','2014-12-23','fee buat shopping cart apotik dan print nota','Andie'], - // ['Panjimitra.co.id','344500','2015-01-02','DP corporate email panjimitra.co.id','Heru Yugo'], - // ['Aplikasi Toko Obat Sholah (Andie)','1000000','2015-01-02','fee revisi shopping cart apotik dan management stok','Andie'], - // ['Panjimitra.co.id','580000','2015-01-05','Pelunasan corporate email panjimitra.co.id','Heru Yugo'], - // ['elfjakarta.com','150000','2015-01-05','DP pembuatan website dan aplikasi reservasi elfjakarta.com','Heru Yugo'], - // ['Aplikasi Toko Obat Sholah (Andie)','100000','2015-01-09','Jasa setting printer dan printout nota','Sholah'], - // ['Belimukena.com','300000','2015-01-09','Biaya maintenance 2015-01','Heru Yugo'], - // ['elfjakarta.com','150000','2015-01-10','Pelunasan Elfjakarta.com','Heru Yugo'], - // ['mambabykid.com','250000','2015-01-16','DP MambabyKid.com','Heru Yugo'], - // ['mambabykid.com','250000','2015-01-20','Pelunasan Mambabykid.com','Heru Yugo'], - // ['Aplikasi Reservasi Frestour','1000000','2015-01-21','DP Payapps','Heru Yugo'], - // ['Belimukena.com','300000','2015-02-10','Biaya maintenance 2015-02','Heru Yugo'], - // ['alamjayatrans.com','350000','2015-02-20','Buat landing page untuk car rental','Heru Yugo'], - // ['Rajatourbandung.com','50000','2015-02-20','Form reservasi email','Heru Yugo'], - // ['Belimukena.com','300000','2015-03-04','Biaya maintenance 2015-03','Heru Yugo'], - // ['Belimukena.com','350000','2015-03-04','Revisi form cart (ditambahkan custom nama pengirim di akun admin, reseller dan company reseller)','Heru Yugo'], - // ['Diskonmobisuzuki.com','350000','2015-03-20','Pembuatan fitur sales area','Eko'], - // ['Aplikasi Order','200000','2015-03-22','DP aplikasi order','Heru Yugo'], - // ['azka.co.id','300000','2015-03-30','Landing page car rental','Heru Yugo'], - // ['Legacyvapestore.com','350000','2015-04-04','DP redesign Legacyvapestore','Heru Yugo'], - // ['autodaihatsu.com','300000','2015-04-08','DP pembuatan website sales daihatsu bandung','Heru Yugo'], - // ['Belimukena.com','450000','2015-04-13','Biaya maintenance 2015-04 (plus security)','Heru Yugo'], - // ['my-trans.co.id','1300000','2015-04-27','DP pembuatan web company profile www.my-trans.co.id','Yamin'], - // ['my-trans.co.id','-650000','2015-04-27','Biaya hosting dan domain','Heru Yugo'], - // ['berkahsynergy.com','300000','2015-04-28','Pembuatan template berkahsynergy.com (redesign)','Erwin Fastweb'], - // ['autodaihatsu.com','200000','2015-04-30','Pelunasan pembuatan website sales daihatsu bandung','Heru Yugo'], - // ['Legacyvapestore.com','250000','2015-05-04','Pelunasan redesign website legacyvapestore','Heru Yugo'], - // ['Belimukena.com','1350000','2015-05-15','Biaya maintenance 2015-05, 2015-06, 2015-07','Heru Yugo'], - // ['Belimukena.com','150000','2015-05-15','Sebagian biaya maintenance 2015-08 (dipake mas yugo/pak Arise)','Heru Yugo'], - // ['Aplikasi Toko Obat Sholah (Andie)','100000','2015-05-23','Backup dan restore aplikasi web toko sholah','Sholah'], - // ['Aplikasi Toko Obat Sholah','1000000','2015-05-26','DP pembuatan aplikasi','Sholah'], - // ['Kursus Private PHP dan Konsul Skripsi','900000','2015-05-28','DP Kursus Private Pemrograman PHP dan Konsultasi Skirpsi','Huda'], - // ['my-trans.co.id','500000','2015-05-29','Pembayaran ke 2 website my-trans dan aplikasi connote','Yamin'], - // ['my-trans.co.id','1250000','2015-06-22','Pelunasan website my trans','Yamin'], - // ['Aplikasi Toko Obat Sholah','700000','2015-06-23','Pelunasan pembuatan aplikasi toko obat Sholah','Sholah'], - // ['Ambasadortrans.com','250000','2015-07-01','DP aplikasi reservasi ambasador trans','Heru Yugo'], - // ['Kursus Private PHP dan Konsul Skripsi','900000','2015-07-02','Pelunasan Kursus Private Pemrograman PHP dan Konsultasi Skirpsi','Huda'], - // ['Aplikasi Reservasi Frestour','1200000','2015-07-06','Pelunasan payapps tourbandung.com dari total (Rp. 1.500.000)','Heru Yugo'], - // ['my-trans.co.id','150000','2015-07-08','Pembayaran fitur Konversi kurs dollar Tarif international dan setting email di ponsel','Yamin'], - // ['Aplikasi Toko Obat Sholah','100000','2015-07-23','Perbaiki Jaringan toko Sholah','Sholah'], - // ['pulaupermata.com','1000000','2015-07-28','Biaya pembuatan website toko permata','Om Ekong'], - // ['Belimukena.com','450000','2015-08-10','Biaya maintenance 2015-08','Heru Yugo'], - // ['Ambasadortrans.com','100000','2015-08-18','Pembayaran ke 2 (sisa Rp. 150.000)','Heru Yugo'], - // ['Stimi-bjm.ac.id','500000','2015-08-19','Pembayaran perbaikan pengumuman kopertis, pasang channel youtube stimi, setting social icons','STIMI'], - // ['Belimukena.com','450000','2015-09-07','Biaya maintenance 2015-09','Heru Yugo'], - // ['online.my-trans.co.id','4400000','2015-09-08','Pembayaran uang muka aplikasi My-Trans','Yamin'], - // ['Stimi-bjm.ac.id','1000000','2015-09-16','Perpanjangan hosting dan domain s/d 2016-10-01','STIMI'], - // ['Stimi-bjm.ac.id','-800000','2015-09-16','Transfer to mas Yugo (plus Rp. 100Rb utk talangan perpanjangan Indonet 2015-09)','Heru Yugo'], - // ['Aplikasi Apotek Iloenk','1000000','2015-09-27','DP Aplikasi Apotek Iloenk','Isra Tanjung'], - // ['Belimukena.com','900000','2015-09-29','Modifikasi kalkulasi ongkir dgn API Rajaongkir (Migrasi Rajaongkir)','Heru Yugo'], - // ['Belimukena.com','450000','2015-10-10','Biaya maintenance 2015-10','Heru Yugo'], - // ['Aplikasi Toko Obat Sholah','200000','2015-10-13','Install ulang aplikasi Toko Obat dan Restore Database','Sholah'], - // ['sia.stimi-bjm.ac.id','5000000','2015-10-28','Uang muka pembuatan aplikasi SIAKAD STIMI Banjarmasin','STIMI'], - // ['Aplikasi Apotek Iloenk','1000000','2015-11-02','Pelunasan Aplikasi Apotek Iloenk','Isra Tanjung'], - // ['Belimukena.com','450000','2015-11-06','Biaya maintenance 2015-11','Heru Yugo'], - // ['Ambasadortrans.com','150000','2015-12-05','Pelunasan','Heru Yugo'], - // ['Belimukena.com','450000','2015-12-07','Biaya maintenance 2015-12','Heru Yugo'], - // ['DutaKurirBorneo.co.id','525000','2015-12-08','Biaya hosting dan domain','Ahmad Fatah'], - // ['DutaKurirBorneo.co.id','-425000','2015-12-08','Biaya hosting dan domain','Heru Yugo'], - // ['Aplikasi Reservasi Frestour','100000','2015-12-08','Cicilan Frestour.com Payapps (sisa Rp. 200.000)','Heru Yugo'], - // ['Panjimitra.co.id','300000','2015-12-11','Fee hosting domain panjimitra.co.id','Heru Yugo'], - // ['stai-almaarif-buntok.ac.id','2300000','2015-12-14','DP+domain+hosting','STAI Buntok'], - // ['stai-almaarif-buntok.ac.id','-1800000','2015-12-14','DP+domain+hosting','Heru Yugo'], - // ['stai-almaarif-buntok.ac.id','100000','2015-12-14','Bonus dari Yugo','Heru Yugo'], - // ['Aplikasi Reservasi Frestour','200000','2015-12-14','Cicilan Frestour.com Payapps (Lunas)','Heru Yugo'], - // ['online.my-trans.co.id','4400000','2015-12-15','Pelunasan Aplikasi E-Connote My-trans','Yamin'], - // ['online.my-trans.co.id','-300000','2015-12-15','Fee mas yugo','Heru Yugo'], - // ['Belimukena.com','450000','2016-01-06','Biaya maintenance 2016-01','Heru Yugo'], - // ['borneotaichiclass.com','500000','2016-01-12','DP Website BorneoTaichiClass.com','Hasto'], - // ['borneotaichiclass.com','-240000','2016-01-12','Hosting Domain','Jakhoster'], - // ['bintangtimur.co.id','1325000','2016-01-21','DP Website BintangTimur.co.id','Ujang Rahman'], - // ['bintangtimur.co.id','-825000','2016-01-25','Domain Hosting Website BintangTimur.co.id','Heru Yugo'], - // ['borneotaichiclass.com','650000','2016-01-27','Pelunasan Website BorneoTaichiClass.com, domain taichichuanpropatria-bjm.com dan domain kungfupropatria-bjm.com','Hasto'], - // ['kungfupropatria-bjm.com','-240000','2016-01-27','domain taichichuanpropatria-bjm.com dan domain kungfupropatria-bjm.com','Jakhoster'], - // ['Belimukena.com','450000','2016-02-10','Biaya maintenance 2016-02','Heru Yugo'], - // ['majas.co.id','900000','2016-02-19','DP Pembuatan web majas.co.id','Donny'], - // ['Aplikasi Apotek Mubarok','1000000','2016-02-24','DP Pembuatan Aplikasi Apotek Mubarok','Ipul Batulicin'], - // ['Aplikasi Apotek Mubarok','1000000','2016-02-28','Pelunasan Pembuatan Aplikasi Apotek Mubarok','Ipul Batulicin'], - // ['sia.stimi-bjm.ac.id','5000000','2016-03-03','Pelunasan Aplikasi Siakad dan Tracer Study STIMI','STIMI'], - // ['Belimukena.com','450000','2016-03-08','Biaya maintenance 2016-03','Heru Yugo'], - // ['attelierjewelry.com','1000000','2016-03-10','DP online store attelierjewelry.com','Joenathan Tanumiha'], - // ['Aplikasi QRCode Haki','250000','2016-03-18','Cicilan 1 DP','Erwin Fastweb'], - // ['Calief Gallery','1500000','2016-03-31','Cicilan 1 DP Aplikasi Order Calief Gallery','Heru Yugo'], - // ['Aplikasi QRCode Haki','250000','2016-03-31','Cicilan 2 DP','Erwin Fastweb'], - // ['my-trans.co.id','650000','2016-04-04','Biaya hosting dan domain','Yamin'], - // ['my-trans.co.id','-650000','2016-04-04','Biaya hosting dan domain','Heru Yugo'], - // ['Calief Gallery','1000000','2016-04-04','Cicilan 2 DP Aplikasi Order Calief Gallery','Heru Yugo'], - // ['stai-almaarif-buntok.ac.id','2300000','2016-04-04','Pelunasan pembuatan website stai-almaarif-buntok.ac.id','STAI Buntok'], - // ['stai-almaarif-buntok.ac.id','-800000','2016-04-04','Pelunasan pembuatan website stai-almaarif-buntok.ac.id','Heru Yugo'], - // ['Belimukena.com','450000','2016-04-05','Biaya maintenance 2016-04','Heru Yugo'], - // ['stai-almaarif-buntok.ac.id','-400000','2016-04-06','Fee marketing dari pak Prima','Prima'], - // ['Bimtek Pemasaran Online','4000000','2016-04-14','Honor narasumber','Dinas Koperasi UKM Kalsel'], - // ['sia.stikeshusada-borneo.ac.id','8000000','2016-04-18','DP Aplikasi Siakad dan Tracer Study STIKES HB','Stikes Husada Borneo'], - // ['sia.stikeshusada-borneo.ac.id','-2000000','2016-04-19','Fee Aplikasi Siakad STIKES HB','Prima'], - // ['Calief Gallery','1800000','2016-04-19','Pelunasan Aplikasi Order Calief Gallery','Heru Yugo'], - // ['borneotaichiclass.com','150000','2016-04-26','Fee revisi website dan edit artikel','Hasto'], - // ['attelierjewelry.com','-315000','2016-04-27','Domain Hosting Attelierjewelry.com','Rumah Web'], - // ['bintangtimur.co.id','1000000','2016-04-28','Pelunasan Website BintangTimur.co.id (belum entry content)','Ujang Rahman'], - // ['Aplikasi QRCode Haki','500000','2016-04-29','Cicilan 3 DP','Erwin Fastweb'], - // ['Belimukena.com','450000','2016-05-04','Biaya maintenance 2016-05','Heru Yugo'], - // ['majas.co.id','-110000','2016-05-10','Domain majas.co.id','Rumah Web'], - // ['majas.co.id','-250000','2016-05-11','Hosting 2GB majas.co.id','Jakhoster'], - // ['Belimukena.com','450000','2016-06-06','Biaya maintenance 2016-06','Heru Yugo'], - // ['Aplikasi Toko Obat Berkah','1900000','2016-06-17','Aplikasi Toko Obat Berkah','Sholah'], - // ['Aplikasi e-report CK Balangan','1200000','2016-06-18','DP Aplikasi Pelaporan Online & Domain+Hosting','Herbert'], - // ['Aplikasi Direktori KKF','400000','2016-06-18','DP Aplikasi Direktori Pelaku Usaha KKF','Donny Kurniawan'], - // ['Aplikasi e-report CK Balangan','-55000','2016-06-24','Domain ckbalangan.web.id','Rumah Web'], - // ['Aplikasi QRCode Haki','1000000','2016-06-29','Cicilan 4','Erwin Fastweb'], - // ]; - // $formated = []; - // $projects = Project::all(); - // $customers = App\Entities\Users\User::latest()->hasRoles(['customer'])->get(); - // // dump($projects->lists('name')); - // foreach ($payments as $payment) { - // $formated[] = [ - // 'project_id' => ($project = $projects->where('name', $payment[0])->first()) ? $project->id : 'hit', - // 'amount' => abs($payment[1]), - // 'type' => $payment[1] < 0 ? 0 : 1, - // 'date' => $payment[2], - // 'description' => $payment[3], - // 'customer_id' => ($customer = $customers->where('name', $payment[4])->first()) ? $customer->id : 'hit', - // 'created_at' => $payment[2] . ' 00:00:00', - // ]; - // } - - // DB::beginTransaction(); - // DB::table('payments')->insert($formated); - // DB::commit(); - - // echo '
$formated : ', print_r($formated, true), '
'; - // die(); -}); diff --git a/tests/Feature/ManageCustomersTest.php b/tests/Feature/ManageCustomersTest.php new file mode 100644 index 0000000..314a8be --- /dev/null +++ b/tests/Feature/ManageCustomersTest.php @@ -0,0 +1,108 @@ +create(); + $customer2 = factory(Customer::class)->create(); + + $this->adminUserSigningIn(); + $this->visit(route('customers.index')); + $this->see($customer1->name); + $this->see($customer2->name); + } + + /** @test */ + public function user_can_create_a_customer() + { + $this->adminUserSigningIn(); + $this->visit(route('customers.index')); + + $this->click(trans('customer.create')); + $this->seePageIs(route('customers.index', ['action' => 'create'])); + + $this->submitForm(trans('customer.create'), [ + 'name' => 'Customer 1 name', + 'email' => 'customer1@mail.com', + 'phone' => '081234567890', + 'pic' => 'Nama PIC Customer', + 'address' => 'Alamat customer 1', + 'notes' => '', + ]); + + $this->seePageIs(route('customers.index')); + + $this->seeInDatabase('customers', [ + 'name' => 'Customer 1 name', + 'email' => 'customer1@mail.com', + 'phone' => '081234567890', + 'pic' => 'Nama PIC Customer', + 'address' => 'Alamat customer 1', + 'notes' => null, + ]); + } + + /** @test */ + public function user_can_edit_a_customer_within_search_query() + { + $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['name' => 'Testing 123']); + + $this->visit(route('customers.index', ['q' => '123'])); + $this->click('edit-customer-'.$customer->id); + $this->seePageIs(route('customers.index', ['action' => 'edit', 'id' => $customer->id, 'q' => '123'])); + + $this->submitForm(trans('customer.update'), [ + 'name' => 'Customer 1 name', + 'email' => 'customer1@mail.com', + 'phone' => '081234567890', + 'pic' => 'Nama PIC Customer', + 'address' => 'Alamat customer 1', + 'notes' => '', + 'is_active' => 0, + ]); + + $this->seePageIs(route('customers.index', ['q' => '123'])); + + $this->seeInDatabase('customers', [ + 'name' => 'Customer 1 name', + 'email' => 'customer1@mail.com', + 'phone' => '081234567890', + 'pic' => 'Nama PIC Customer', + 'address' => 'Alamat customer 1', + 'notes' => null, + 'is_active' => 0, + ]); + } + + /** @test */ + public function user_can_delete_a_customer() + { + $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(); + + $this->visit(route('customers.index', [$customer->id])); + $this->click('del-customer-'.$customer->id); + $this->seePageIs(route('customers.index', ['action' => 'delete', 'id' => $customer->id])); + + $this->seeInDatabase('customers', [ + 'id' => $customer->id, + ]); + + $this->press(trans('app.delete_confirm_button')); + + $this->dontSeeInDatabase('customers', [ + 'id' => $customer->id, + ]); + } +} diff --git a/tests/Unit/Models/CustomerTest.php b/tests/Unit/Models/CustomerTest.php new file mode 100644 index 0000000..2f02a4c --- /dev/null +++ b/tests/Unit/Models/CustomerTest.php @@ -0,0 +1,19 @@ +create(['name' => 'Customer 1 name']); + $this->assertEquals('Customer 1 name', $customer->name); + } +} diff --git a/tests/Unit/Policies/CustomerPolicyTest.php b/tests/Unit/Policies/CustomerPolicyTest.php new file mode 100644 index 0000000..6497d07 --- /dev/null +++ b/tests/Unit/Policies/CustomerPolicyTest.php @@ -0,0 +1,43 @@ +adminUserSigningIn(); + $this->assertTrue($user->can('create', new Customer)); + } + + /** @test */ + public function user_can_view_customer() + { + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['name' => 'Customer 1 name']); + $this->assertTrue($user->can('view', $customer)); + } + + /** @test */ + public function user_can_update_customer() + { + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['name' => 'Customer 1 name']); + $this->assertTrue($user->can('update', $customer)); + } + + /** @test */ + public function user_can_delete_customer() + { + $user = $this->adminUserSigningIn(); + $customer = factory(Customer::class)->create(['name' => 'Customer 1 name']); + $this->assertTrue($user->can('delete', $customer)); + } +}