From 3020cb9cdd377d707df65d6377e52f0397fb43b6 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Tue, 4 Sep 2018 21:02:42 +0800 Subject: [PATCH] Update customer payments page --- app/Entities/Partners/Customer.php | 2 +- .../Controllers/Customers/PaymentsController.php | 2 +- resources/views/customers/payments.blade.php | 34 ++++++++++++---------- tests/Unit/Models/CustomerTest.php | 5 +++- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/app/Entities/Partners/Customer.php b/app/Entities/Partners/Customer.php index 2ec29f7..0c0dc9f 100644 --- a/app/Entities/Partners/Customer.php +++ b/app/Entities/Partners/Customer.php @@ -15,7 +15,7 @@ class Customer extends Model public function payments() { - return $this->hasMany('App\Entities\Payments\Payment', 'partner_id'); + return $this->morphMany('App\Entities\Payments\Payment', 'partner'); } public function subscriptions() diff --git a/app/Http/Controllers/Customers/PaymentsController.php b/app/Http/Controllers/Customers/PaymentsController.php index 3298aa4..75f0adf 100644 --- a/app/Http/Controllers/Customers/PaymentsController.php +++ b/app/Http/Controllers/Customers/PaymentsController.php @@ -23,7 +23,7 @@ class PaymentsController extends Controller $payments = $customer->payments() ->latest() ->with('project') - ->paginate(); + ->get(); return view('customers.payments', compact('customer', 'payments')); } diff --git a/resources/views/customers/payments.blade.php b/resources/views/customers/payments.blade.php index a62ab7f..38364f8 100755 --- a/resources/views/customers/payments.blade.php +++ b/resources/views/customers/payments.blade.php @@ -1,23 +1,23 @@ @extends('layouts.customer') -@section('title', trans('customer.payments')) +@section('title', __('customer.payments')) @section('content-customer')
- - - - - - - + + + + + + + @forelse($payments as $key => $payment) - + @empty - - - + @endforelse + + + + + + +
{{ trans('app.table_no') }}{{ trans('payment.project') }}{{ trans('payment.type') }}{{ trans('app.date') }}{{ trans('payment.amount') }}{{ trans('payment.description') }}{{ trans('app.action') }}{{ __('app.table_no') }}{{ __('payment.project') }}{{ __('app.type') }}{{ __('app.date') }}{{ __('payment.amount') }}{{ __('payment.description') }}{{ __('app.action') }}
{{ $payments->firstItem() + $key }}{{ 1 + $key }} {{ link_to_route( 'projects.payments', @@ -31,19 +31,23 @@ {{ $payment->present()->amount }} {{ $payment->description }} - {!! 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')]) !!} + {!! html_link_to_route('payments.show', '', [$payment->id], ['icon' => 'search', 'class' => 'btn btn-info btn-xs', 'title' => __('app.show')]) !!} + {!! html_link_to_route('payments.pdf', '', [$payment->id], ['icon' => 'print', 'class' => 'btn btn-warning btn-xs', 'title' => __('app.print')]) !!}
{{ trans('payment.not_found') }}
{{ __('payment.not_found') }}
{{ __('app.total') }}{{ formatRp($payments->sum('amount')) }} 
-{{ $payments->appends(Request::except('page'))->render() }} @endsection @section('ext_css') diff --git a/tests/Unit/Models/CustomerTest.php b/tests/Unit/Models/CustomerTest.php index 52fa192..a588450 100644 --- a/tests/Unit/Models/CustomerTest.php +++ b/tests/Unit/Models/CustomerTest.php @@ -26,7 +26,10 @@ class CustomerTest extends TestCase public function a_customer_has_many_payments_relation() { $customer = factory(Customer::class)->create(); - $payment = factory(Payment::class)->create(['partner_id' => $customer->id]); + $payment = factory(Payment::class)->create([ + 'partner_id' => $customer->id, + 'partner_type' => 'App\Entities\Partners\Customer', + ]); $this->assertInstanceOf(Collection::class, $customer->payments); $this->assertInstanceOf(Payment::class, $customer->payments->first());