From 4f108f9a7983d0d17828d8df66a5d6a56d8f7d02 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 28 Jan 2018 13:14:32 +0800 Subject: [PATCH] Small improvement on customer and payment index page Add customer status and status_label attribute --- app/Entities/Partners/Customer.php | 12 ++++++++ .../Controllers/Partners/CustomersController.php | 1 + resources/views/customers/index.blade.php | 8 ++++-- resources/views/customers/show.blade.php | 2 +- resources/views/payments/index.blade.php | 32 ++++++++++++---------- tests/Feature/Payments/ManagePaymentsTest.php | 4 +-- tests/Unit/Models/CustomerTest.php | 30 ++++++++++++++++++++ 7 files changed, 69 insertions(+), 20 deletions(-) diff --git a/app/Entities/Partners/Customer.php b/app/Entities/Partners/Customer.php index 48f7bb3..2ec29f7 100644 --- a/app/Entities/Partners/Customer.php +++ b/app/Entities/Partners/Customer.php @@ -37,4 +37,16 @@ class Customer extends Model ), ]); } + + public function getStatusAttribute() + { + return $this->is_active == 1 ? trans('app.active') : trans('app.in_active'); + } + + public function getStatusLabelAttribute() + { + $color = $this->is_active == 1 ? ' style="background-color: #337ab7"' : ''; + + return ''.$this->status.''; + } } diff --git a/app/Http/Controllers/Partners/CustomersController.php b/app/Http/Controllers/Partners/CustomersController.php index e9c332e..6d73f25 100644 --- a/app/Http/Controllers/Partners/CustomersController.php +++ b/app/Http/Controllers/Partners/CustomersController.php @@ -18,6 +18,7 @@ class CustomersController extends Controller $customers = Customer::where(function ($query) { $query->where('name', 'like', '%'.request('q').'%'); }) + ->latest() ->withCount('projects') ->paginate(25); diff --git a/resources/views/customers/index.blade.php b/resources/views/customers/index.blade.php index 911d4d4..52b2c8b 100644 --- a/resources/views/customers/index.blade.php +++ b/resources/views/customers/index.blade.php @@ -37,8 +37,12 @@ {{ $customer->nameLink() }} {{ $customer->email }} {{ $customer->phone }} - {{ $customer->projects_count }} - {{ $customer->is_active }} + + @if ($customer->projects_count) + {{ link_to_route('customers.projects', $customer->projects_count, $customer) }} + @endif + + {!! $customer->status_label !!} @endforeach diff --git a/resources/views/customers/show.blade.php b/resources/views/customers/show.blade.php index f9832d9..91b09ec 100755 --- a/resources/views/customers/show.blade.php +++ b/resources/views/customers/show.blade.php @@ -12,7 +12,7 @@ {{ trans('contact.phone') }}{{ $customer->phone }} {{ trans('customer.pic') }}{{ $customer->pic }} {{ trans('address.address') }}{{ $customer->address }} - {{ trans('app.status') }}{{ $customer->is_active }} + {{ trans('app.status') }}{!! $customer->status_label !!} {{ trans('app.notes') }}{!! nl2br($customer->notes) !!} diff --git a/resources/views/payments/index.blade.php b/resources/views/payments/index.blade.php index 44a66af..7672971 100755 --- a/resources/views/payments/index.blade.php +++ b/resources/views/payments/index.blade.php @@ -5,28 +5,29 @@ @section('content')

- {!! link_to_route('payments.create', trans('payment.create'), [], ['class'=>'btn btn-success']) !!} + {!! link_to_route('payments.create', trans('payment.create'), [], ['class' => 'btn btn-success']) !!}
{{ trans('payment.payments') }} {{ $payments->total() }} {{ trans('payment.found') }}

- - {{ Form::open(['method'=>'get','class'=>'form-inline']) }} - {{ Form::text('q', request('q'), ['class'=>'form-control index-search-field','placeholder' => trans('payment.search')]) }} + + {{ Form::open(['method' => 'get', 'class' => 'form-inline']) }} + {{ Form::text('q', request('q'), ['class' => 'form-control index-search-field', 'placeholder' => trans('payment.search')]) }} {{ Form::select('partner_id', ['' => '-- '.trans('payment.customer').' --'] + $partnersList, request('partner_id'), ['class' => 'form-control', 'id' => 'partner_id']) }} {{ Form::submit(trans('app.search'), ['class' => 'btn btn-info btn-sm']) }} - {{ link_to_route('payments.index','Reset',[],['class' => 'btn btn-default btn-sm']) }} + {{ link_to_route('payments.index', trans('app.reset'), [], ['class' => 'btn btn-default btn-sm']) }} {{ Form::close() }}
- +
+
- - - + + + @forelse($payments as $key => $payment) @@ -42,22 +43,23 @@ {{ $payment->type() }} + - - @empty - + @endforelse
{{ trans('app.table_no') }} {{ trans('payment.project') }} {{ trans('app.date') }}{{ trans('payment.amount') }}{{ trans('payment.description') }} {{ trans('payment.customer') }}{{ trans('app.action') }}{{ trans('payment.amount') }}{{ trans('payment.description') }}{{ trans('app.action') }}
{{ $payment->date }}{{ $payment->partner->name }} {{ $payment->present()->amount }} {{ $payment->description }}{{ $payment->partner->name }} - {!! link_to_route('payments.show', trans('app.show'), [$payment->id], ['class'=>'btn btn-info btn-xs']) !!} - {!! link_to_route('payments.edit', trans('app.edit'), [$payment->id], ['class'=>'btn btn-warning btn-xs']) !!} + + {!! html_link_to_route('payments.show', '', [$payment->id], ['icon' => 'search', 'class' => 'btn btn-info btn-xs', 'title' => trans('app.show')]) !!} + {!! html_link_to_route('payments.pdf', '', [$payment->id], ['icon' => 'print', 'class' => 'btn btn-warning btn-xs', 'title' => trans('app.print')]) !!}
{{ trans('payment.not_found') }}{{ trans('payment.not_found') }}
- {!! str_replace('/?', '?', $payments->appends(Request::except('page'))->render()) !!} + +{{ $payments->appends(Request::except('page'))->render() }} @endsection @section('ext_css') diff --git a/tests/Feature/Payments/ManagePaymentsTest.php b/tests/Feature/Payments/ManagePaymentsTest.php index 4fe6af5..87b8c1d 100644 --- a/tests/Feature/Payments/ManagePaymentsTest.php +++ b/tests/Feature/Payments/ManagePaymentsTest.php @@ -115,7 +115,7 @@ class ManagePaymentsTest extends TestCase $user = $this->adminUserSigningIn(); $payment = factory(Payment::class)->create(); - $this->visit(route('payments.index')); + $this->visit(route('payments.show', $payment)); $this->click(trans('app.edit')); $this->click(trans('payment.delete')); $this->press(trans('app.delete_confirm_button')); @@ -130,7 +130,7 @@ class ManagePaymentsTest extends TestCase $payment = factory(Payment::class)->create(); $this->visit(route('payments.index')); - $this->click(trans('app.show')); + $this->click($payment->number); $this->seePageIs(route('payments.show', $payment->id)); $this->see(trans('payment.detail')); $this->see($payment->date); diff --git a/tests/Unit/Models/CustomerTest.php b/tests/Unit/Models/CustomerTest.php index 17f73f8..82d2cee 100644 --- a/tests/Unit/Models/CustomerTest.php +++ b/tests/Unit/Models/CustomerTest.php @@ -66,4 +66,34 @@ class CustomerTest extends TestCase ]), $customer->nameLink() ); } + + /** @test */ + public function a_customer_has_status_attribute() + { + $customer = factory(Customer::class)->make(['is_active' => 1]); + + $this->assertEquals(1, $customer->is_active); + $this->assertEquals(trans('app.active'), $customer->status); + + $customer = factory(Customer::class)->make(['is_active' => 0]); + + $this->assertEquals(0, $customer->is_active); + $this->assertEquals(trans('app.in_active'), $customer->status); + } + + /** @test */ + public function a_customer_has_status_label_attribute() + { + $customer = factory(Customer::class)->make(['is_active' => 1]); + + $this->assertEquals(1, $customer->is_active); + $activeLabel = ''.trans('app.active').''; + $this->assertEquals($activeLabel, $customer->status_label); + + $customer = factory(Customer::class)->make(['is_active' => 0]); + + $this->assertEquals(0, $customer->is_active); + $inActiveLabel = ''.trans('app.in_active').''; + $this->assertEquals($inActiveLabel, $customer->status_label); + } }