Browse Source

Update customer payments page

pull/18/head
Nafies Luthfi 7 years ago
parent
commit
3020cb9cdd
  1. 2
      app/Entities/Partners/Customer.php
  2. 2
      app/Http/Controllers/Customers/PaymentsController.php
  3. 34
      resources/views/customers/payments.blade.php
  4. 5
      tests/Unit/Models/CustomerTest.php

2
app/Entities/Partners/Customer.php

@ -15,7 +15,7 @@ class Customer extends Model
public function payments() public function payments()
{ {
return $this->hasMany('App\Entities\Payments\Payment', 'partner_id');
return $this->morphMany('App\Entities\Payments\Payment', 'partner');
} }
public function subscriptions() public function subscriptions()

2
app/Http/Controllers/Customers/PaymentsController.php

@ -23,7 +23,7 @@ class PaymentsController extends Controller
$payments = $customer->payments() $payments = $customer->payments()
->latest() ->latest()
->with('project') ->with('project')
->paginate();
->get();
return view('customers.payments', compact('customer', 'payments')); return view('customers.payments', compact('customer', 'payments'));
} }

34
resources/views/customers/payments.blade.php

@ -1,23 +1,23 @@
@extends('layouts.customer') @extends('layouts.customer')
@section('title', trans('customer.payments'))
@section('title', __('customer.payments'))
@section('content-customer') @section('content-customer')
<div class="panel panel-default table-responsive"> <div class="panel panel-default table-responsive">
<table class="table table-condensed"> <table class="table table-condensed">
<thead> <thead>
<th class="table-no">{{ trans('app.table_no') }}</th>
<th class="col-md-2">{{ trans('payment.project') }}</th>
<th class="col-md-2 text-center">{{ trans('payment.type') }}</th>
<th class="col-md-1 text-center">{{ trans('app.date') }}</th>
<th class="col-md-2 text-right">{{ trans('payment.amount') }}</th>
<th class="col-md-4">{{ trans('payment.description') }}</th>
<th class="col-md-1 text-center">{{ trans('app.action') }}</th>
<th class="table-no">{{ __('app.table_no') }}</th>
<th class="col-md-3">{{ __('payment.project') }}</th>
<th class="col-md-1 text-center">{{ __('app.type') }}</th>
<th class="col-md-1 text-center">{{ __('app.date') }}</th>
<th class="col-md-2 text-right">{{ __('payment.amount') }}</th>
<th class="col-md-4">{{ __('payment.description') }}</th>
<th class="col-md-1 text-center">{{ __('app.action') }}</th>
</thead> </thead>
<tbody> <tbody>
@forelse($payments as $key => $payment) @forelse($payments as $key => $payment)
<tr> <tr>
<td class="text-center">{{ $payments->firstItem() + $key }}</td>
<td class="text-center">{{ 1 + $key }}</td>
<td> <td>
{{ link_to_route( {{ link_to_route(
'projects.payments', 'projects.payments',
@ -31,19 +31,23 @@
<td class="text-right">{{ $payment->present()->amount }}</td> <td class="text-right">{{ $payment->present()->amount }}</td>
<td>{{ $payment->description }}</td> <td>{{ $payment->description }}</td>
<td class="text-center"> <td class="text-center">
{!! 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')]) !!}
</td> </td>
</tr> </tr>
@empty @empty
<tr>
<td colspan="7">{{ trans('payment.not_found') }}</td>
</tr>
<tr><td colspan="7">{{ __('payment.not_found') }}</td></tr>
@endforelse @endforelse
</tbody> </tbody>
<tfoot>
<tr>
<th colspan="4" class="text-right">{{ __('app.total') }}</th>
<th class="text-right">{{ formatRp($payments->sum('amount')) }}</th>
<th colspan="2">&nbsp;</th>
</tr>
</tfoot>
</table> </table>
</div> </div>
{{ $payments->appends(Request::except('page'))->render() }}
@endsection @endsection
@section('ext_css') @section('ext_css')

5
tests/Unit/Models/CustomerTest.php

@ -26,7 +26,10 @@ class CustomerTest extends TestCase
public function a_customer_has_many_payments_relation() public function a_customer_has_many_payments_relation()
{ {
$customer = factory(Customer::class)->create(); $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(Collection::class, $customer->payments);
$this->assertInstanceOf(Payment::class, $customer->payments->first()); $this->assertInstanceOf(Payment::class, $customer->payments->first());

Loading…
Cancel
Save