Browse Source

Merge branch 'vendor-detail'

User can view vendor detail, then see payment list of the vendor.
pull/18/head
Nafies Luthfi 7 years ago
parent
commit
b1e70310dd
  1. 22
      app/Entities/Partners/Vendor.php
  2. 11
      app/Http/Controllers/Partners/VendorsController.php
  3. 2
      resources/lang/de/vendor.php
  4. 2
      resources/lang/en/vendor.php
  5. 2
      resources/lang/id/vendor.php
  6. 29
      resources/views/vendors/index.blade.php
  7. 62
      resources/views/vendors/show.blade.php
  8. 17
      tests/Unit/Models/VendorTest.php

22
app/Entities/Partners/Vendor.php

@ -6,10 +6,30 @@ use Illuminate\Database\Eloquent\Model;
class Vendor extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'notes', 'website', 'is_active'];
/**
* Vendor has many payments relation.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function payments()
{
return $this->hasMany('App\Entities\Payments\Payment', 'partner_id');
return $this->morphMany('App\Entities\Payments\Payment', 'partner');
}
/**
* Get status attribute.
*
* @return string
*/
public function getStatusAttribute()
{
return $this->is_active == 1 ? __('app.active') : __('app.in_active');
}
}

11
app/Http/Controllers/Partners/VendorsController.php

@ -76,6 +76,17 @@ class VendorsController extends Controller
}
/**
* Show vendor detail page.
*
* @param \App\Entities\Partners\Vendor $vendor
* @return \Illuminate\View\View
*/
public function show(Vendor $vendor)
{
return view('vendors.show', compact('vendor'));
}
/**
* Remove the specified vendor from storage.
*
* @param \App\Entities\Partners\Vendor $vendor

2
resources/lang/de/vendor.php

@ -4,6 +4,7 @@ return [
// Labels
'vendor' => 'Hersteller',
'list' => 'Hersteller Liste',
'detail' => 'Vendor Detail',
'search' => 'Hersteller suchen',
'not_found' => 'Hersteller nicht gefunden.',
'empty' => 'Hersteller Liste ist leer.',
@ -25,5 +26,6 @@ return [
// Attributes
'name' => 'Hersteller Name',
'website' => 'Vendor Website',
'description' => 'Hersteller Beschreibung',
];

2
resources/lang/en/vendor.php

@ -4,6 +4,7 @@ return [
// Labels
'vendor' => 'Vendor',
'list' => 'Vendor List',
'detail' => 'Vendor Detail',
'search' => 'Search Vendor',
'not_found' => 'Vendor not found.',
'empty' => 'Vendor list is empty.',
@ -25,5 +26,6 @@ return [
// Attributes
'name' => 'Vendor Name',
'website' => 'Vendor Website',
'description' => 'Vendor Description',
];

2
resources/lang/id/vendor.php

@ -4,6 +4,7 @@ return [
// Labels
'vendor' => 'Vendor',
'list' => 'Daftar Vendor',
'detail' => 'Detail Vendor',
'search' => 'Cari Vendor',
'not_found' => 'Vendor tidak ditemukan',
'empty' => 'Belum ada Vendor',
@ -25,5 +26,6 @@ return [
// Attributes
'name' => 'Nama Vendor',
'website' => 'Website Vendor',
'description' => 'Deskripsi Vendor',
];

29
resources/views/vendors/index.blade.php

@ -1,32 +1,32 @@
@extends('layouts.app')
@section('title', trans('vendor.list'))
@section('title', __('vendor.list'))
@section('content')
<h1 class="page-header">
<div class="pull-right">
{{ link_to_route('vendors.index', trans('vendor.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }}
{{ link_to_route('vendors.index', __('vendor.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }}
</div>
{{ trans('vendor.list') }}
<small>{{ trans('app.total') }} : {{ $vendors->total() }} {{ trans('vendor.vendor') }}</small>
{{ __('vendor.list') }}
<small>{{ __('app.total') }} : {{ $vendors->total() }} {{ __('vendor.vendor') }}</small>
</h1>
<div class="row">
<div class="col-md-8">
<div class="panel panel-default table-responsive">
<div class="panel-heading">
{{ Form::open(['method' => 'get','class' => 'form-inline']) }}
{!! FormField::text('q', ['value' => request('q'), 'label' => trans('vendor.search'), 'class' => 'input-sm']) !!}
{{ Form::submit(trans('vendor.search'), ['class' => 'btn btn-sm']) }}
{{ link_to_route('vendors.index', trans('app.reset')) }}
{!! FormField::text('q', ['value' => request('q'), 'label' => __('vendor.search'), 'class' => 'input-sm']) !!}
{{ Form::submit(__('vendor.search'), ['class' => 'btn btn-sm']) }}
{{ link_to_route('vendors.index', __('app.reset')) }}
{{ Form::close() }}
</div>
<table class="table table-condensed">
<thead>
<tr>
<th class="text-center">{{ trans('app.table_no') }}</th>
<th>{{ trans('vendor.name') }}</th>
<th>{{ trans('app.notes') }}</th>
<th class="text-center">{{ trans('app.action') }}</th>
<th class="text-center">{{ __('app.table_no') }}</th>
<th>{{ __('vendor.name') }}</th>
<th>{{ __('app.notes') }}</th>
<th class="text-center">{{ __('app.action') }}</th>
</tr>
</thead>
<tbody>
@ -36,12 +36,13 @@
<td>{{ $vendor->name }}</td>
<td>{{ $vendor->notes }}</td>
<td class="text-center">
{!! link_to_route(
{{ link_to_route('vendors.show', __('app.show'), $vendor) }} |
{{ link_to_route(
'vendors.index',
trans('app.edit'),
__('app.edit'),
['action' => 'edit', 'id' => $vendor->id] + Request::only('page', 'q'),
['id' => 'edit-vendor-' . $vendor->id]
) !!}
) }}
</td>
</tr>
@endforeach

62
resources/views/vendors/show.blade.php

@ -0,0 +1,62 @@
@extends('layouts.app')
@section('title', $vendor->name.' - '.__('vendor.detail'))
@section('content')
<h1 class="page-header">
<div class="pull-right">
{!! link_to_route('vendors.index', __('vendor.back_to_index'), [], ['class' => 'btn btn-default']) !!}
</div>
{{ $vendor->name }} <small>{{ __('vendor.detail') }}</small>
</h1>
<div class="row">
<div class="col-md-5">
<div class="panel panel-default">
<table class="table table-condensed">
<tbody>
<tr><td class="col-xs-3">{{ __('vendor.name') }}</td><td>{{ $vendor->name }}</td></tr>
<tr><td>{{ __('vendor.website') }}</td><td>{{ $vendor->website }}</td></tr>
<tr><td>{{ __('app.status') }}</td><td>{{ $vendor->status }}</td></tr>
<tr><td>{{ __('app.notes') }}</td><td>{!! nl2br($vendor->notes) !!}</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">{{ __('payment.payments') }}</h3></div>
<div class="panel-body">
<table class="table table-condensed">
<thead>
<tr>
<th class="text-center">{{ __('app.table_no') }}</th>
<th class="">{{ __('payment.project') }}</th>
<th class="text-center ">{{ __('app.date') }}</th>
<th class="text-right ">{{ __('payment.amount') }}</th>
<th class="col-md-7">{{ __('payment.description') }}</th>
</tr>
</thead>
<tbody>
@foreach ($vendor->payments as $key => $payment)
<tr>
<td class="text-center">{{ 1 + $key }}</td>
<td>{{ $payment->project->name }}</td>
<td class="text-center">{{ $payment->date }}</td>
<td class="text-right">{{ formatRp($payment->amount) }}</td>
<td>{{ $payment->description }}</td>
</tr>
@endforeach
</tbody>
<tfoot>
<tr>
<th class="text-right" colspan="3">{{ __('app.total') }}</th>
<th class="text-right">{{ formatRp($vendor->payments->sum('amount')) }}</th>
<th>&nbsp;</th>
</tr>
</tfoot>
</table>
</div>
</div>
@endsection

17
tests/Unit/Models/VendorTest.php

@ -20,12 +20,25 @@ class VendorTest extends TestCase
}
/** @test */
public function a_vendor_has_many_payments_relation()
public function a_vendor_has_morph_many_payments_relation()
{
$vendor = factory(Vendor::class)->create();
$payment = factory(Payment::class)->create(['partner_id' => $vendor->id]);
$payment = factory(Payment::class)->create([
'partner_id' => $vendor->id,
'partner_type' => 'App\Entities\Partners\Vendor',
]);
$this->assertInstanceOf(Collection::class, $vendor->payments);
$this->assertInstanceOf(Payment::class, $vendor->payments->first());
}
/** @test */
public function a_vendor_has_status_attribute()
{
$vendor = factory(Vendor::class)->make(['is_active' => 1]);
$this->assertEquals(__('app.active'), $vendor->status);
$vendor->is_active = 0;
$this->assertEquals(__('app.in_active'), $vendor->status);
}
}
Loading…
Cancel
Save