From ca6befb25b2fad452d2ca2cadd88b5ef372c1fdd Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 28 Jan 2018 10:33:24 +0800 Subject: [PATCH] Add subscription list tab on customer detail page --- app/Entities/Partners/Customer.php | 5 +++ .../Customers/SubscriptionsController.php | 21 ++++++++++ resources/lang/en/customer.php | 5 ++- resources/lang/id/customer.php | 5 ++- .../views/customers/partials/nav-tabs.blade.php | 3 ++ resources/views/customers/subscriptions.blade.php | 45 ++++++++++++++++++++++ routes/web.php | 1 + tests/Unit/Models/CustomerTest.php | 11 ++++++ 8 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 app/Http/Controllers/Customers/SubscriptionsController.php create mode 100755 resources/views/customers/subscriptions.blade.php diff --git a/app/Entities/Partners/Customer.php b/app/Entities/Partners/Customer.php index 1e04e50..d1be026 100644 --- a/app/Entities/Partners/Customer.php +++ b/app/Entities/Partners/Customer.php @@ -18,6 +18,11 @@ class Customer extends Model return $this->hasMany('App\Entities\Payments\Payment', 'partner_id'); } + public function subscriptions() + { + return $this->hasMany('App\Entities\Subscriptions\Subscription'); + } + public function nameLink() { return link_to_route('customers.show', $this->name, [$this->id], [ diff --git a/app/Http/Controllers/Customers/SubscriptionsController.php b/app/Http/Controllers/Customers/SubscriptionsController.php new file mode 100644 index 0000000..f6c4152 --- /dev/null +++ b/app/Http/Controllers/Customers/SubscriptionsController.php @@ -0,0 +1,21 @@ + + */ +class SubscriptionsController extends Controller +{ + public function index(Customer $customer) + { + $subscriptions = $customer->subscriptions()->orderBy('due_date')->get(); + + return view('customers.subscriptions', compact('customer', 'subscriptions')); + } +} diff --git a/resources/lang/en/customer.php b/resources/lang/en/customer.php index f6beb46..9b52ef1 100644 --- a/resources/lang/en/customer.php +++ b/resources/lang/en/customer.php @@ -32,6 +32,7 @@ return [ 'projects_count' => 'Projects count', // Relations - 'projects' => 'Project List', - 'payments' => 'Payment History', + 'projects' => 'Project List', + 'payments' => 'Payment History', + 'subscriptions' => 'Subscription List', ]; diff --git a/resources/lang/id/customer.php b/resources/lang/id/customer.php index 5fe170e..8014972 100644 --- a/resources/lang/id/customer.php +++ b/resources/lang/id/customer.php @@ -32,6 +32,7 @@ return [ 'projects_count' => 'Jml Project', // Relations - 'projects' => 'List Project', - 'payments' => 'History Pembayaran', + 'projects' => 'List Project', + 'payments' => 'History Pembayaran', + 'subscriptions' => 'List Langganan', ]; diff --git a/resources/views/customers/partials/nav-tabs.blade.php b/resources/views/customers/partials/nav-tabs.blade.php index c157cb7..7c01196 100644 --- a/resources/views/customers/partials/nav-tabs.blade.php +++ b/resources/views/customers/partials/nav-tabs.blade.php @@ -9,5 +9,8 @@
  • {!! link_to_route('customers.payments', trans('customer.payments').' ('.$customer->payments->count().')', [$customer]) !!}
  • +
  • + {!! link_to_route('customers.subscriptions', trans('customer.subscriptions').' ('.$customer->subscriptions->count().')', [$customer]) !!} +

  • diff --git a/resources/views/customers/subscriptions.blade.php b/resources/views/customers/subscriptions.blade.php new file mode 100755 index 0000000..b1f0de3 --- /dev/null +++ b/resources/views/customers/subscriptions.blade.php @@ -0,0 +1,45 @@ +@extends('layouts.customer') + +@section('title', trans('customer.subscriptions')) + +@section('content-customer') + +
    + + + + + + + + + + + + + @forelse($subscriptions as $key => $subscription) + + + + + + + + + + + @empty + + + + @endforelse + +
    {{ trans('app.table_no') }}{{ trans('subscription.name') }}{{ trans('app.type') }}{{ trans('subscription.customer') }}{{ trans('subscription.due_date') }}{{ trans('subscription.extension_price') }}{{ trans('subscription.vendor') }}{{ trans('app.status') }}
    {{ 1 + $key }}{{ $subscription->nameLink() }} + + {{ $subscription->type }} + + {{ $subscription->customer->name }} + {{ dateId($subscription->due_date) }} {!! $subscription->nearOfDueDateSign() !!} + {{ formatRp($subscription->price) }}{{ $subscription->vendor->name }}{{ $subscription->status() }}
    {{ trans('subscription.not_found') }}
    +
    +@endsection diff --git a/routes/web.php b/routes/web.php index ba4d7ec..ae386f6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -30,6 +30,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::resource('customers', 'Partners\CustomersController'); /* diff --git a/tests/Unit/Models/CustomerTest.php b/tests/Unit/Models/CustomerTest.php index 933bba1..02d1b70 100644 --- a/tests/Unit/Models/CustomerTest.php +++ b/tests/Unit/Models/CustomerTest.php @@ -5,6 +5,7 @@ namespace Tests\Unit\Models; use App\Entities\Partners\Customer; use App\Entities\Payments\Payment; use App\Entities\Projects\Project; +use App\Entities\Subscriptions\Subscription; use Illuminate\Support\Collection; use Tests\TestCase as TestCase; @@ -31,6 +32,16 @@ class CustomerTest extends TestCase } /** @test */ + public function a_customer_has_many_subscriptions_relation() + { + $customer = factory(Customer::class)->create(); + $subscription = factory(Subscription::class)->create(['customer_id' => $customer->id]); + + $this->assertInstanceOf(Collection::class, $customer->subscriptions); + $this->assertInstanceOf(Subscription::class, $customer->subscriptions->first()); + } + + /** @test */ public function a_customer_has_name_link_method() { $customer = factory(Customer::class)->make();