Browse Source

Add invoice list tab on customer detail page

pull/6/head
Nafies Luthfi 8 years ago
parent
commit
d8345088cf
  1. 5
      app/Entities/Partners/Customer.php
  2. 21
      app/Http/Controllers/Customers/InvoicesController.php
  3. 1
      resources/lang/en/customer.php
  4. 1
      resources/lang/id/customer.php
  5. 58
      resources/views/customers/invoices.blade.php
  6. 3
      resources/views/customers/partials/nav-tabs.blade.php
  7. 1
      routes/web.php
  8. 12
      tests/Unit/Models/CustomerTest.php

5
app/Entities/Partners/Customer.php

@ -23,6 +23,11 @@ class Customer extends Model
return $this->hasMany('App\Entities\Subscriptions\Subscription');
}
public function invoices()
{
return $this->hasManyThrough('App\Entities\Invoices\Invoice', 'App\Entities\Projects\Project');
}
public function nameLink()
{
return link_to_route('customers.show', $this->name, [$this->id], [

21
app/Http/Controllers/Customers/InvoicesController.php

@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\Customers;
use App\Entities\Partners\Customer;
use App\Http\Controllers\Controller;
/**
* Customer Invoices Controller.
*
* @author Nafies Luthfi <nafiesL@gmail.com>
*/
class InvoicesController extends Controller
{
public function index(Customer $customer)
{
$invoices = $customer->invoices()->orderBy('due_date')->get();
return view('customers.invoices', compact('customer', 'invoices'));
}
}

1
resources/lang/en/customer.php

@ -35,4 +35,5 @@ return [
'projects' => 'Project List',
'payments' => 'Payment History',
'subscriptions' => 'Subscription List',
'invoices' => 'Invoice List',
];

1
resources/lang/id/customer.php

@ -35,4 +35,5 @@ return [
'projects' => 'List Project',
'payments' => 'History Pembayaran',
'subscriptions' => 'List Langganan',
'invoices' => 'List Invoice',
];

58
resources/views/customers/invoices.blade.php

@ -0,0 +1,58 @@
@extends('layouts.customer')
@section('title', trans('invoice.list'))
@section('content-customer')
<div class="panel panel-default">
<table class="table table-condensed">
<thead>
<th class="text-center">{{ trans('app.table_no') }}</th>
<th class="col-md-2 text-center">{{ trans('invoice.number') }}</th>
<th class="col-md-2 text-center">{{ trans('app.date') }}</th>
<th class="col-md-2">{{ trans('project.project') }}</th>
<th class="col-md-2">{{ trans('invoice.customer') }}</th>
<th class="col-md-2 text-right">{{ trans('invoice.amount') }}</th>
<th class="col-md-2 text-center">{{ trans('app.action') }}</th>
</thead>
<tbody>
@forelse($invoices as $key => $invoice)
<tr>
<td class="text-center">{{ 1 + $key }}</td>
<td class="text-center">{{ $invoice->numberLink() }}</td>
<td class="text-center">{{ $invoice->created_at->format('Y-m-d') }}</td>
<td>{{ $invoice->project->nameLink() }}</td>
<td>{{ $invoice->project->customer->nameLink() }}</td>
<td class="text-right">{{ formatRp($invoice->amount) }}</td>
<td class="text-center">
{!! html_link_to_route(
'invoices.show', '', [$invoice->number],
[
'icon' => 'search',
'class' => 'btn btn-info btn-xs',
'title' => 'Lihat ' . trans('invoice.show')
]
) !!}
{!! html_link_to_route(
'invoices.pdf', '', [$invoice->number],
[
'icon' => 'print',
'class' => 'btn btn-default btn-xs',
'title' => trans('invoice.print'), 'target' => '_blank'
]
) !!}
</td>
</tr>
@empty
<tr><td colspan="7">{{ trans('invoice.empty') }}</td></tr>
@endforelse
</tbody>
<tfoot>
<tr>
<th colspan="5" class="text-right">{{ trans('app.total') }}</th>
<th class="text-right">{{ formatRp($invoices->sum('amount')) }}</th>
<th></th>
</tr>
</tfoot>
</table>
</div>
@endsection

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

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

1
routes/web.php

@ -31,6 +31,7 @@ Route::group(['middleware' => ['web', 'auth']], function () {
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::get('customers/{customer}/subscriptions', ['as' => 'customers.subscriptions', 'uses' => 'Customers\SubscriptionsController@index']);
Route::get('customers/{customer}/invoices', ['as' => 'customers.invoices', 'uses' => 'Customers\InvoicesController@index']);
Route::resource('customers', 'Partners\CustomersController');
/*

12
tests/Unit/Models/CustomerTest.php

@ -2,6 +2,7 @@
namespace Tests\Unit\Models;
use App\Entities\Invoices\Invoice;
use App\Entities\Partners\Customer;
use App\Entities\Payments\Payment;
use App\Entities\Projects\Project;
@ -42,6 +43,17 @@ class CustomerTest extends TestCase
}
/** @test */
public function a_customer_has_many_invoices_through_projects_relation()
{
$customer = factory(Customer::class)->create();
$project = factory(Project::class)->create(['customer_id' => $customer->id]);
$invoice = factory(Invoice::class)->create(['project_id' => $project->id]);
$this->assertInstanceOf(Collection::class, $customer->invoices);
$this->assertInstanceOf(Invoice::class, $customer->invoices->first());
}
/** @test */
public function a_customer_has_name_link_method()
{
$customer = factory(Customer::class)->make();

Loading…
Cancel
Save