Browse Source

Add subscription type_label for view readability

pull/6/head
Nafies Luthfi 8 years ago
parent
commit
aafa37d3c5
  1. 5
      app/Entities/Subscriptions/Subscription.php
  2. 6
      resources/views/customers/subscriptions.blade.php
  3. 6
      resources/views/subscriptions/index.blade.php
  4. 18
      tests/Unit/Models/SubscriptionTest.php

5
app/Entities/Subscriptions/Subscription.php

@ -70,4 +70,9 @@ class Subscription extends Model
{
return Type::getColorById($this->type_id);
}
public function getTypeLabelAttribute()
{
return '<span class="badge" style="background-color: '.$this->type_color.'">'.$this->type.'</span>';
}
}

6
resources/views/customers/subscriptions.blade.php

@ -21,11 +21,7 @@
<tr>
<td>{{ 1 + $key }}</td>
<td>{{ $subscription->nameLink() }}</td>
<td class="text-center">
<span class="badge" style="background-color: {{ $subscription->type_color }};">
{{ $subscription->type }}
</span>
</td>
<td class="text-center">{!! $subscription->type_label !!}</td>
<td>{{ $subscription->customer->name }}</td>
<td class="text-right" title="{!! $subscription->dueDateDescription() !!}">
{{ dateId($subscription->due_date) }} {!! $subscription->nearOfDueDateSign() !!}

6
resources/views/subscriptions/index.blade.php

@ -31,11 +31,7 @@
<tr>
<td>{{ $subscriptions->firstItem() + $key }}</td>
<td>{{ $subscription->nameLink() }}</td>
<td class="text-center">
<span class="badge" style="background-color: {{ $subscription->type_color }};">
{{ $subscription->type }}
</span>
</td>
<td class="text-center">{!! $subscription->type_label !!}</td>
<td>{{ $subscription->customer->name }}</td>
<td class="text-right" title="{!! $subscription->dueDateDescription() !!}">
{{ dateId($subscription->due_date) }} {!! $subscription->nearOfDueDateSign() !!}

18
tests/Unit/Models/SubscriptionTest.php

@ -120,4 +120,22 @@ class SubscriptionTest extends TestCase
$this->assertEquals(2, $subscription->type_id);
$this->assertEquals(Type::getColorById(2), $subscription->type_color);
}
/** @test */
public function a_subscription_has_type_label_attribute()
{
$subscription = factory(Subscription::class)->make();
$type = Type::getNameById(1);
$color = Type::getColorById(1);
$label = '<span class="badge" style="background-color: '.$color.'">'.$type.'</span>';
$this->assertEquals($label, $subscription->type_label);
$subscription = factory(Subscription::class)->make(['type_id' => 2]);
$type = Type::getNameById(2);
$color = Type::getColorById(2);
$label = '<span class="badge" style="background-color: '.$color.'">'.$type.'</span>';
$this->assertEquals($label, $subscription->type_label);
}
}
Loading…
Cancel
Save