diff --git a/app/Entities/Partners/Customer.php b/app/Entities/Partners/Customer.php index efcd132..1e04e50 100644 --- a/app/Entities/Partners/Customer.php +++ b/app/Entities/Partners/Customer.php @@ -10,7 +10,12 @@ class Customer extends Model public function projects() { - return $this->hasMany('App\Entities\Projects\Project', 'customer_id'); + return $this->hasMany('App\Entities\Projects\Project'); + } + + public function payments() + { + return $this->hasMany('App\Entities\Payments\Payment', 'partner_id'); } public function nameLink() diff --git a/app/Http/Controllers/Customers/PaymentsController.php b/app/Http/Controllers/Customers/PaymentsController.php new file mode 100644 index 0000000..f15f11d --- /dev/null +++ b/app/Http/Controllers/Customers/PaymentsController.php @@ -0,0 +1,24 @@ + + */ +class PaymentsController extends Controller +{ + public function index(Customer $customer) + { + $payments = $customer->payments() + ->latest() + ->with('project') + ->paginate(); + + return view('customers.payments', compact('customer', 'payments')); + } +} diff --git a/resources/lang/en/customer.php b/resources/lang/en/customer.php index 4275879..f6beb46 100644 --- a/resources/lang/en/customer.php +++ b/resources/lang/en/customer.php @@ -33,4 +33,5 @@ return [ // Relations 'projects' => 'Project List', + 'payments' => 'Payment History', ]; diff --git a/resources/lang/id/customer.php b/resources/lang/id/customer.php index 411342b..5fe170e 100644 --- a/resources/lang/id/customer.php +++ b/resources/lang/id/customer.php @@ -33,4 +33,5 @@ return [ // Relations 'projects' => 'List Project', + 'payments' => 'History Pembayaran', ]; diff --git a/resources/views/customers/partials/nav-tabs.blade.php b/resources/views/customers/partials/nav-tabs.blade.php index 89ca29f..c157cb7 100644 --- a/resources/views/customers/partials/nav-tabs.blade.php +++ b/resources/views/customers/partials/nav-tabs.blade.php @@ -6,5 +6,8 @@
  • {!! link_to_route('customers.projects', trans('customer.projects').' ('.$customer->projects->count().')', [$customer]) !!}
  • +
  • + {!! link_to_route('customers.payments', trans('customer.payments').' ('.$customer->payments->count().')', [$customer]) !!} +

  • diff --git a/resources/views/customers/payments.blade.php b/resources/views/customers/payments.blade.php new file mode 100755 index 0000000..9b0afca --- /dev/null +++ b/resources/views/customers/payments.blade.php @@ -0,0 +1,56 @@ +@extends('layouts.customer') + +@section('title', trans('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') }}
    {{ $payments->firstItem() + $key }} + {{ link_to_route( + 'projects.payments', + $payment->project->name, + [$payment->project_id], + ['title' => 'Lihat seluruh Pembayaran Project ini'] + ) }} + {{ $payment->type() }}{{ $payment->date }}{{ $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')]) !!} +
    {{ trans('payment.not_found') }}
    +
    +{{ $payments->appends(Request::except('page'))->render() }} +@endsection + +@section('ext_css') + +@endsection diff --git a/routes/web.php b/routes/web.php index 7b8ee2c..ba4d7ec 100644 --- a/routes/web.php +++ b/routes/web.php @@ -29,6 +29,7 @@ Route::group(['middleware' => ['web', 'auth']], function () { * Customers Routes */ 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::resource('customers', 'Partners\CustomersController'); /* diff --git a/tests/Unit/Models/CustomerTest.php b/tests/Unit/Models/CustomerTest.php index d189638..933bba1 100644 --- a/tests/Unit/Models/CustomerTest.php +++ b/tests/Unit/Models/CustomerTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit\Models; use App\Entities\Partners\Customer; +use App\Entities\Payments\Payment; use App\Entities\Projects\Project; use Illuminate\Support\Collection; use Tests\TestCase as TestCase; @@ -20,6 +21,16 @@ class CustomerTest extends TestCase } /** @test */ + public function a_customer_has_many_payments_relation() + { + $customer = factory(Customer::class)->create(); + $payment = factory(Payment::class)->create(['partner_id' => $customer->id]); + + $this->assertInstanceOf(Collection::class, $customer->payments); + $this->assertInstanceOf(Payment::class, $customer->payments->first()); + } + + /** @test */ public function a_customer_has_name_link_method() { $customer = factory(Customer::class)->make();