Browse Source

Add subscription list tab on customer detail page

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

5
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], [

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

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

5
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',
];

5
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',
];

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

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

45
resources/views/customers/subscriptions.blade.php

@ -0,0 +1,45 @@
@extends('layouts.customer')
@section('title', trans('customer.subscriptions'))
@section('content-customer')
<div class="panel panel-default">
<table class="table table-condensed">
<thead>
<th>{{ trans('app.table_no') }}</th>
<th>{{ trans('subscription.name') }}</th>
<th class="text-center">{{ trans('app.type') }}</th>
<th>{{ trans('subscription.customer') }}</th>
<th class="text-right">{{ trans('subscription.due_date') }}</th>
<th class="text-right">{{ trans('subscription.extension_price') }}</th>
<th>{{ trans('subscription.vendor') }}</th>
<th class="text-center">{{ trans('app.status') }}</th>
</thead>
<tbody>
@forelse($subscriptions as $key => $subscription)
<tr>
<td>{{ 1 + $key }}</td>
<td>{{ $subscription->nameLink() }}</td>
<td class="text-center">
<span class="badge" style="background-color: {{ $subscription->type_color }};">
{{ $subscription->type }}
</span>
</td>
<td>{{ $subscription->customer->name }}</td>
<td class="text-right" title="{!! $subscription->dueDateDescription() !!}">
{{ dateId($subscription->due_date) }} {!! $subscription->nearOfDueDateSign() !!}
</td>
<td class="text-right">{{ formatRp($subscription->price) }}</td>
<td>{{ $subscription->vendor->name }}</td>
<td class="text-center">{{ $subscription->status() }}</td>
</tr>
@empty
<tr>
<td colspan="8">{{ trans('subscription.not_found') }}</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@endsection

1
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');
/*

11
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();

Loading…
Cancel
Save