Browse Source

Small improvement on customer and payment index page

Add customer status and status_label attribute
pull/6/head
Nafies Luthfi 8 years ago
parent
commit
4f108f9a79
  1. 12
      app/Entities/Partners/Customer.php
  2. 1
      app/Http/Controllers/Partners/CustomersController.php
  3. 8
      resources/views/customers/index.blade.php
  4. 2
      resources/views/customers/show.blade.php
  5. 32
      resources/views/payments/index.blade.php
  6. 4
      tests/Feature/Payments/ManagePaymentsTest.php
  7. 30
      tests/Unit/Models/CustomerTest.php

12
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 '<span class="badge"'.$color.'>'.$this->status.'</span>';
}
}

1
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);

8
resources/views/customers/index.blade.php

@ -37,8 +37,12 @@
<td>{{ $customer->nameLink() }}</td>
<td>{{ $customer->email }}</td>
<td>{{ $customer->phone }}</td>
<td class="text-center">{{ $customer->projects_count }}</td>
<td class="text-center">{{ $customer->is_active }}</td>
<td class="text-center">
@if ($customer->projects_count)
{{ link_to_route('customers.projects', $customer->projects_count, $customer) }}
@endif
</td>
<td class="text-center">{!! $customer->status_label !!}</td>
</tr>
@endforeach
</tbody>

2
resources/views/customers/show.blade.php

@ -12,7 +12,7 @@
<tr><td>{{ trans('contact.phone') }}</td><td>{{ $customer->phone }}</td></tr>
<tr><td>{{ trans('customer.pic') }}</td><td>{{ $customer->pic }}</td></tr>
<tr><td>{{ trans('address.address') }}</td><td>{{ $customer->address }}</td></tr>
<tr><td>{{ trans('app.status') }}</td><td>{{ $customer->is_active }}</td></tr>
<tr><td>{{ trans('app.status') }}</td><td>{!! $customer->status_label !!}</td></tr>
<tr><td>{{ trans('app.notes') }}</td><td>{!! nl2br($customer->notes) !!}</td></tr>
</tbody>
</table>

32
resources/views/payments/index.blade.php

@ -5,28 +5,29 @@
@section('content')
<h1 class="page-header">
<div class="pull-right">
{!! link_to_route('payments.create', trans('payment.create'), [], ['class'=>'btn btn-success']) !!}
{!! link_to_route('payments.create', trans('payment.create'), [], ['class' => 'btn btn-success']) !!}
</div>
{{ trans('payment.payments') }} <small>{{ $payments->total() }} {{ trans('payment.found') }}</small>
</h1>
<div class="well well-sm text-right">
<div class="pull-left hidden-xs">{!! str_replace('/?', '?', $payments->appends(Request::except('page'))->render()) !!}</div>
{{ Form::open(['method'=>'get','class'=>'form-inline']) }}
{{ Form::text('q', request('q'), ['class'=>'form-control index-search-field','placeholder' => trans('payment.search')]) }}
<div class="pull-left hidden-xs">{{ $payments->appends(Request::except('page'))->render() }}</div>
{{ 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() }}
</div>
<table class="table table-condensed">
<div class="panel panel-default">
<table class="table">
<thead>
<th>{{ trans('app.table_no') }}</th>
<th class="col-md-3">{{ trans('payment.project') }}</th>
<th class="col-md-1 text-center">{{ trans('app.date') }}</th>
<th class="col-md-2 text-right">{{ trans('payment.amount') }}</th>
<th class="col-md-3">{{ trans('payment.description') }}</th>
<th class="col-md-1">{{ trans('payment.customer') }}</th>
<th class="col-md-2">{{ trans('app.action') }}</th>
<th class="col-md-2 text-right">{{ trans('payment.amount') }}</th>
<th class="col-md-4">{{ trans('payment.description') }}</th>
<th class="col-md-1 text-center">{{ trans('app.action') }}</th>
</thead>
<tbody>
@forelse($payments as $key => $payment)
@ -42,22 +43,23 @@
<strong class="text-success">{{ $payment->type() }}</strong>
</td>
<td class="text-center">{{ $payment->date }}</td>
<td>{{ $payment->partner->name }}</td>
<td class="text-right">{{ $payment->present()->amount }}</td>
<td>{{ $payment->description }}</td>
<td>{{ $payment->partner->name }}</td>
<td>
{!! 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']) !!}
<td class="text-center">
{!! 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')]) !!}
</td>
</tr>
@empty
<tr>
<td colspan="5">{{ trans('payment.not_found') }}</td>
<td colspan="7">{{ trans('payment.not_found') }}</td>
</tr>
@endforelse
</tbody>
</table>
{!! str_replace('/?', '?', $payments->appends(Request::except('page'))->render()) !!}
</div>
{{ $payments->appends(Request::except('page'))->render() }}
@endsection
@section('ext_css')

4
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);

30
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 = '<span class="badge" style="background-color: #337ab7">'.trans('app.active').'</span>';
$this->assertEquals($activeLabel, $customer->status_label);
$customer = factory(Customer::class)->make(['is_active' => 0]);
$this->assertEquals(0, $customer->is_active);
$inActiveLabel = '<span class="badge">'.trans('app.in_active').'</span>';
$this->assertEquals($inActiveLabel, $customer->status_label);
}
}
Loading…
Cancel
Save