Browse Source

Add payment Type reference class

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
d428013e7d
  1. 2
      app/Entities/Payments/Payment.php
  2. 35
      app/Entities/Payments/Type.php
  3. 2
      app/Http/Controllers/PaymentsController.php
  4. 15
      app/helpers.php
  5. 4
      config/app.php
  6. 7
      resources/lang/id/payment.php
  7. 3
      resources/views/payments/create.blade.php
  8. 3
      resources/views/payments/edit.blade.php
  9. 41
      tests/Unit/References/PaymentTypeTest.php

2
app/Entities/Payments/Payment.php

@ -26,6 +26,6 @@ class Payment extends Model
public function type()
{
return paymentTypes($this->type_id);
return Type::getNameById($this->type_id);
}
}

35
app/Entities/Payments/Type.php

@ -0,0 +1,35 @@
<?php
namespace App\Entities\Payments;
use App\Entities\ReferenceAbstract;
class Type extends ReferenceAbstract
{
protected static $lists = [
1 => 'project',
2 => 'add_feature',
3 => 'maintenance',
];
protected static $colors = [
1 => '#337ab7',
2 => '#4caf50',
3 => '#ff8181',
];
public static function getNameById($singleId)
{
return trans('payment.types.'.static::getById($singleId));
}
public static function toArray()
{
$lists = [];
foreach (static::$lists as $key => $value) {
$lists[$key] = trans('payment.types.'.$value);
}
return $lists;
}
}

2
app/Http/Controllers/PaymentsController.php

@ -21,7 +21,7 @@ class PaymentsController extends Controller
public function index(Request $request)
{
$payments = $this->repo->getPayments($request->only('q', 'partner_id'));
$payments = $this->repo->getPayments($request->only('q', 'partner_id'));
$partnersList = Customer::pluck('name', 'id')->all();
return view('payments.index', compact('payments', 'partnersList'));
}

15
app/helpers.php

@ -219,21 +219,6 @@ function dateDifference($date1, $date2, $differenceFormat = '%a')
return $interval->format($differenceFormat);
}
function paymentTypes($paymentTypeId = null)
{
$paymentTypes = [1 => 'Project', 'Add Feature', 'Maintenance'];
if (is_null($paymentTypeId)) {
return $paymentTypes;
}
if (array_key_exists($paymentTypeId, $paymentTypes)) {
return $paymentTypes[$paymentTypeId];
}
return null;
}
function appLogoImage()
{
$logoString = '<img style="display: block;text-align: center;margin: 0 auto;width: 100%;max-width: 200px"';

4
config/app.php

@ -211,6 +211,10 @@ return [
'Carbon' => Carbon\Carbon::class,
'Option' => App\Services\Facades\Option::class,
'Terbilang' => Riskihajar\Terbilang\Facades\Terbilang::class,
// Reference Facades
'PaymentType' => App\Entities\Payments\Type::class,
'SubscriptionType' => App\Entities\Subscriptions\Type::class,
],
];

7
resources/lang/id/payment.php

@ -39,4 +39,11 @@ return [
'cash_in' => 'Pemasukan',
'cash_out' => 'Pengeluaran',
'payer' => 'Pembayar',
// Types
'types' => [
'project' => 'Project',
'add_feature' => 'Add Feature',
'maintenance' => 'Maintenance',
],
];

3
resources/views/payments/create.blade.php

@ -3,6 +3,7 @@
@section('title', trans('payment.create'))
@section('content')
<ul class="breadcrumb hidden-print">
<li>{{ link_to_route('payments.index', trans('payment.payments')) }}</li>
<li class="active">{{ trans('payment.create') }}</li>
@ -19,7 +20,7 @@
{!! FormField::radios('in_out',['Pengeluaran', 'Pemasukan'],['label' => trans('payment.in_out'),'value' => 1]) !!}
</div>
<div class="col-md-6">
{!! FormField::radios('type_id', paymentTypes(), ['label'=> trans('payment.type'),'value' => 1,'list_style' => 'unstyled']) !!}
{!! FormField::radios('type_id', PaymentType::toArray(), ['label'=> trans('payment.type'),'value' => 1,'list_style' => 'unstyled']) !!}
</div>
</div>
<div class="row">

3
resources/views/payments/edit.blade.php

@ -3,6 +3,7 @@
@section('title', trans('payment.edit'))
@section('content')
@include('payments.partials.breadcrumb',['title' => trans('payment.edit')])
<div class="row">
@ -16,7 +17,7 @@
{!! FormField::radios('in_out',['Pengeluaran','Pemasukan'],['label'=> trans('payment.in_out'),'value' => 1]) !!}
</div>
<div class="col-md-6">
{!! FormField::radios('type_id', paymentTypes(), ['label'=> trans('payment.type'),'value' => 1,'list_style' => 'unstyled']) !!}
{!! FormField::radios('type_id', PaymentType::toArray(), ['label'=> trans('payment.type'),'value' => 1,'list_style' => 'unstyled']) !!}
</div>
</div>
<div class="row">

41
tests/Unit/References/PaymentTypeTest.php

@ -0,0 +1,41 @@
<?php
namespace Tests\Unit\Reference;
use App\Entities\Payments\Type;
use Tests\TestCase;
class PaymentTypeTest extends TestCase
{
/** @test */
public function retrieve_payment_type_list()
{
$paymentType = new Type;
$this->assertEquals([
1 => trans('payment.types.project'),
2 => trans('payment.types.add_feature'),
3 => trans('payment.types.maintenance'),
], $paymentType->toArray());
}
/** @test */
public function retrieve_payment_type_name_by_id()
{
$paymentType = new Type;
$this->assertEquals(trans('payment.types.project'), $paymentType->getNameById(1));
$this->assertEquals(trans('payment.types.add_feature'), $paymentType->getNameById(2));
$this->assertEquals(trans('payment.types.maintenance'), $paymentType->getNameById(3));
}
/** @test */
public function retrieve_payment_type_color_class_by_id()
{
$paymentType = new Type;
$this->assertEquals('#337ab7', $paymentType->getColorById(1));
$this->assertEquals('#4caf50', $paymentType->getColorById(2));
$this->assertEquals('#ff8181', $paymentType->getColorById(3));
}
}
Loading…
Cancel
Save