Browse Source

Add numberLink method on Invoice model

pull/3/head
Nafies Luthfi 8 years ago
parent
commit
d7d50b7d37
  1. 15
      app/Entities/Invoices/Invoice.php
  2. 2
      resources/views/invoices/index.blade.php
  3. 24
      tests/Unit/Models/InvoiceTest.php

15
app/Entities/Invoices/Invoice.php

@ -6,6 +6,11 @@ use App\Entities\Projects\Project;
use App\Entities\Users\User; use App\Entities\Users\User;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
/**
* Invoice Model.
*
* @author Nafies Luthfi <nafiesl@gmail.com>
*/
class Invoice extends Model class Invoice extends Model
{ {
protected $guarded = ['id', 'created_at', 'updated_at']; protected $guarded = ['id', 'created_at', 'updated_at'];
@ -49,4 +54,14 @@ class Invoice extends Model
return count($this->items); return count($this->items);
} }
public function numberLink()
{
return link_to_route('invoices.show', $this->number, [$this->number], [
'title' => trans(
'app.show_detail_title',
['name' => $this->number, 'type' => trans('invoice.invoice')]
),
]);
}
} }

2
resources/views/invoices/index.blade.php

@ -30,7 +30,7 @@
@forelse($invoices as $key => $invoice) @forelse($invoices as $key => $invoice)
<tr> <tr>
<td class="text-center">{{ 1 + $key }}</td> <td class="text-center">{{ 1 + $key }}</td>
<td class="text-center">{{ $invoice->number }}</td>
<td class="text-center">{{ $invoice->numberLink() }}</td>
<td class="text-center">{{ $invoice->created_at->format('Y-m-d') }}</td> <td class="text-center">{{ $invoice->created_at->format('Y-m-d') }}</td>
<td>{{ $invoice->project->nameLink() }}</td> <td>{{ $invoice->project->nameLink() }}</td>
<td>{{ $invoice->project->customer->nameLink() }}</td> <td>{{ $invoice->project->customer->nameLink() }}</td>

24
tests/Unit/Models/InvoiceTest.php

@ -7,12 +7,17 @@ use App\Entities\Projects\Project;
use App\Entities\Users\User; use App\Entities\Users\User;
use Tests\TestCase; use Tests\TestCase;
/**
* Invoice Model Test.
*
* @author Nafies Luthfi <nafiesl@gmail.com>
*/
class InvoiceTest extends TestCase class InvoiceTest extends TestCase
{ {
/** @test */ /** @test */
public function it_has_project_relation() public function it_has_project_relation()
{ {
$user = $this->adminUserSigningIn();
$user = $this->adminUserSigningIn();
$project = factory(Project::class)->create(); $project = factory(Project::class)->create();
$invoice = factory(Invoice::class)->create(['project_id' => $project->id]); $invoice = factory(Invoice::class)->create(['project_id' => $project->id]);
@ -23,7 +28,7 @@ class InvoiceTest extends TestCase
/** @test */ /** @test */
public function it_has_creator_relation() public function it_has_creator_relation()
{ {
$user = $this->adminUserSigningIn();
$user = $this->adminUserSigningIn();
$invoice = factory(Invoice::class)->create(['creator_id' => $user->id]); $invoice = factory(Invoice::class)->create(['creator_id' => $user->id]);
$this->assertInstanceOf(User::class, $invoice->creator); $this->assertInstanceOf(User::class, $invoice->creator);
@ -39,4 +44,19 @@ class InvoiceTest extends TestCase
$invoice2 = factory(Invoice::class)->create(); $invoice2 = factory(Invoice::class)->create();
$this->assertEquals(date('ym').'002', $invoice2->number); $this->assertEquals(date('ym').'002', $invoice2->number);
} }
/** @test */
public function it_has_number_link_method()
{
$invoice = factory(Invoice::class)->make();
$this->assertEquals(
link_to_route('invoices.show', $invoice->number, [$invoice->number], [
'title' => trans(
'app.show_detail_title',
['name' => $invoice->number, 'type' => trans('invoice.invoice')]
),
]), $invoice->numberLink()
);
}
} }
Loading…
Cancel
Save