Browse Source

Add payments tab on customer detail page

pull/6/head
Nafies Luthfi 8 years ago
parent
commit
10412460a7
  1. 7
      app/Entities/Partners/Customer.php
  2. 24
      app/Http/Controllers/Customers/PaymentsController.php
  3. 1
      resources/lang/en/customer.php
  4. 1
      resources/lang/id/customer.php
  5. 3
      resources/views/customers/partials/nav-tabs.blade.php
  6. 56
      resources/views/customers/payments.blade.php
  7. 1
      routes/web.php
  8. 11
      tests/Unit/Models/CustomerTest.php

7
app/Entities/Partners/Customer.php

@ -10,7 +10,12 @@ class Customer extends Model
public function projects()
{
return $this->hasMany('App\Entities\Projects\Project', 'customer_id');
return $this->hasMany('App\Entities\Projects\Project');
}
public function payments()
{
return $this->hasMany('App\Entities\Payments\Payment', 'partner_id');
}
public function nameLink()

24
app/Http/Controllers/Customers/PaymentsController.php

@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\Customers;
use App\Entities\Partners\Customer;
use App\Http\Controllers\Controller;
/**
* Customer Payments Controller.
*
* @author Nafies Luthfi <nafiesL@gmail.com>
*/
class PaymentsController extends Controller
{
public function index(Customer $customer)
{
$payments = $customer->payments()
->latest()
->with('project')
->paginate();
return view('customers.payments', compact('customer', 'payments'));
}
}

1
resources/lang/en/customer.php

@ -33,4 +33,5 @@ return [
// Relations
'projects' => 'Project List',
'payments' => 'Payment History',
];

1
resources/lang/id/customer.php

@ -33,4 +33,5 @@ return [
// Relations
'projects' => 'List Project',
'payments' => 'History Pembayaran',
];

3
resources/views/customers/partials/nav-tabs.blade.php

@ -6,5 +6,8 @@
<li class="{{ Request::segment(3) == 'projects' ? 'active' : '' }}">
{!! link_to_route('customers.projects', trans('customer.projects').' ('.$customer->projects->count().')', [$customer]) !!}
</li>
<li class="{{ Request::segment(3) == 'payments' ? 'active' : '' }}">
{!! link_to_route('customers.payments', trans('customer.payments').' ('.$customer->payments->count().')', [$customer]) !!}
</li>
</ul>
<br>

56
resources/views/customers/payments.blade.php

@ -0,0 +1,56 @@
@extends('layouts.customer')
@section('title', trans('customer.payments'))
@section('content-customer')
<div class="panel panel-default table-responsive">
<table class="table table-condensed">
<thead>
<th class="table-no">{{ trans('app.table_no') }}</th>
<th class="col-md-2">{{ trans('payment.project') }}</th>
<th class="col-md-2 text-center">{{ trans('payment.type') }}</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-4">{{ trans('payment.description') }}</th>
<th class="col-md-1 text-center">{{ trans('app.action') }}</th>
</thead>
<tbody>
@forelse($payments as $key => $payment)
<tr>
<td class="text-center">{{ $payments->firstItem() + $key }}</td>
<td>
{{ link_to_route(
'projects.payments',
$payment->project->name,
[$payment->project_id],
['title' => 'Lihat seluruh Pembayaran Project ini']
) }}
</td>
<td class="text-center"><strong class="text-success">{{ $payment->type() }}</strong></td>
<td class="text-center">{{ $payment->date }}</td>
<td class="text-right">{{ $payment->present()->amount }}</td>
<td>{{ $payment->description }}</td>
<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="7">{{ trans('payment.not_found') }}</td>
</tr>
@endforelse
</tbody>
</table>
</div>
{{ $payments->appends(Request::except('page'))->render() }}
@endsection
@section('ext_css')
<style>
th.table-no, td.table-no {
min-width: 2%;
text-align: center;
}
</style>
@endsection

1
routes/web.php

@ -29,6 +29,7 @@ Route::group(['middleware' => ['web', 'auth']], function () {
* Customers Routes
*/
Route::get('customers/{customer}/projects', ['as' => 'customers.projects', 'uses' => 'Customers\ProjectsController@index']);
Route::get('customers/{customer}/payments', ['as' => 'customers.payments', 'uses' => 'Customers\PaymentsController@index']);
Route::resource('customers', 'Partners\CustomersController');
/*

11
tests/Unit/Models/CustomerTest.php

@ -3,6 +3,7 @@
namespace Tests\Unit\Models;
use App\Entities\Partners\Customer;
use App\Entities\Payments\Payment;
use App\Entities\Projects\Project;
use Illuminate\Support\Collection;
use Tests\TestCase as TestCase;
@ -20,6 +21,16 @@ class CustomerTest extends TestCase
}
/** @test */
public function a_customer_has_many_payments_relation()
{
$customer = factory(Customer::class)->create();
$payment = factory(Payment::class)->create(['partner_id' => $customer->id]);
$this->assertInstanceOf(Collection::class, $customer->payments);
$this->assertInstanceOf(Payment::class, $customer->payments->first());
}
/** @test */
public function a_customer_has_name_link_method()
{
$customer = factory(Customer::class)->make();

Loading…
Cancel
Save