diff --git a/app/Entities/Partners/Customer.php b/app/Entities/Partners/Customer.php index d1be026..48f7bb3 100644 --- a/app/Entities/Partners/Customer.php +++ b/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], [ diff --git a/app/Http/Controllers/Customers/InvoicesController.php b/app/Http/Controllers/Customers/InvoicesController.php new file mode 100644 index 0000000..67e4a04 --- /dev/null +++ b/app/Http/Controllers/Customers/InvoicesController.php @@ -0,0 +1,21 @@ + + */ +class InvoicesController extends Controller +{ + public function index(Customer $customer) + { + $invoices = $customer->invoices()->orderBy('due_date')->get(); + + return view('customers.invoices', compact('customer', 'invoices')); + } +} diff --git a/resources/lang/en/customer.php b/resources/lang/en/customer.php index 9b52ef1..9043d54 100644 --- a/resources/lang/en/customer.php +++ b/resources/lang/en/customer.php @@ -35,4 +35,5 @@ return [ 'projects' => 'Project List', 'payments' => 'Payment History', 'subscriptions' => 'Subscription List', + 'invoices' => 'Invoice List', ]; diff --git a/resources/lang/id/customer.php b/resources/lang/id/customer.php index 8014972..fc896a3 100644 --- a/resources/lang/id/customer.php +++ b/resources/lang/id/customer.php @@ -35,4 +35,5 @@ return [ 'projects' => 'List Project', 'payments' => 'History Pembayaran', 'subscriptions' => 'List Langganan', + 'invoices' => 'List Invoice', ]; diff --git a/resources/views/customers/invoices.blade.php b/resources/views/customers/invoices.blade.php new file mode 100755 index 0000000..26be3b4 --- /dev/null +++ b/resources/views/customers/invoices.blade.php @@ -0,0 +1,58 @@ +@extends('layouts.customer') + +@section('title', trans('invoice.list')) + +@section('content-customer') +
+ + + + + + + + + + + + @forelse($invoices as $key => $invoice) + + + + + + + + + + @empty + + @endforelse + + + + + + + + +
{{ trans('app.table_no') }}{{ trans('invoice.number') }}{{ trans('app.date') }}{{ trans('project.project') }}{{ trans('invoice.customer') }}{{ trans('invoice.amount') }}{{ trans('app.action') }}
{{ 1 + $key }}{{ $invoice->numberLink() }}{{ $invoice->created_at->format('Y-m-d') }}{{ $invoice->project->nameLink() }}{{ $invoice->project->customer->nameLink() }}{{ formatRp($invoice->amount) }} + {!! 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' + ] + ) !!} +
{{ trans('invoice.empty') }}
{{ trans('app.total') }}{{ formatRp($invoices->sum('amount')) }}
+
+@endsection diff --git a/resources/views/customers/partials/nav-tabs.blade.php b/resources/views/customers/partials/nav-tabs.blade.php index 7c01196..f3a47bc 100644 --- a/resources/views/customers/partials/nav-tabs.blade.php +++ b/resources/views/customers/partials/nav-tabs.blade.php @@ -12,5 +12,8 @@
  • {!! link_to_route('customers.subscriptions', trans('customer.subscriptions').' ('.$customer->subscriptions->count().')', [$customer]) !!}
  • +
  • + {!! link_to_route('customers.invoices', trans('customer.invoices').' ('.$customer->invoices->count().')', [$customer]) !!} +

  • diff --git a/routes/web.php b/routes/web.php index ae386f6..5c070aa 100644 --- a/routes/web.php +++ b/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'); /* diff --git a/tests/Unit/Models/CustomerTest.php b/tests/Unit/Models/CustomerTest.php index 02d1b70..17f73f8 100644 --- a/tests/Unit/Models/CustomerTest.php +++ b/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();