From d7f3613f437cde562d688b8a5119e629810c52ad Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 5 Oct 2017 18:16:39 +0800 Subject: [PATCH] Add invoice detail page Change invoice_no column into number in invoices table --- app/Entities/Invoices/Invoice.php | 8 ++- app/Http/Controllers/InvoiceDraftController.php | 4 +- app/Http/Controllers/InvoicesController.php | 2 +- app/Services/InvoiceDraft/InvoiceDraft.php | 10 ++-- .../InvoiceDraft/InvoiceDraftCollection.php | 8 --- database/factories/ModelFactory.php | 16 ++++++ .../2017_10_05_162758_create_invoices_table.php | 2 +- resources/lang/id/invoice.php | 5 ++ .../invoices/partials/form-draft-detail.blade.php | 6 ++- resources/views/invoices/show.blade.php | 58 ++++++++++++++++++++++ tests/Feature/InvoiceEntryTest.php | 2 +- tests/Unit/Models/InvoiceTest.php | 17 +++++++ 12 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 resources/views/invoices/show.blade.php create mode 100644 tests/Unit/Models/InvoiceTest.php diff --git a/app/Entities/Invoices/Invoice.php b/app/Entities/Invoices/Invoice.php index 8a32c5b..927ce5d 100755 --- a/app/Entities/Invoices/Invoice.php +++ b/app/Entities/Invoices/Invoice.php @@ -2,6 +2,7 @@ namespace App\Entities\Invoices; +use App\Entities\Projects\Project; use Illuminate\Database\Eloquent\Model; class Invoice extends Model @@ -12,6 +13,11 @@ class Invoice extends Model public function getRouteKeyName() { - return 'invoice_no'; + return 'number'; + } + + public function project() + { + return $this->belongsTo(Project::class); } } diff --git a/app/Http/Controllers/InvoiceDraftController.php b/app/Http/Controllers/InvoiceDraftController.php index 9bd5c5f..92562bf 100644 --- a/app/Http/Controllers/InvoiceDraftController.php +++ b/app/Http/Controllers/InvoiceDraftController.php @@ -126,8 +126,8 @@ class InvoiceDraftController extends Controller $invoice = $draft->store(); $draft->destroy(); - flash(trans('invoice.created', ['invoice_no' => $invoice->invoice_no]), 'success')->important(); + flash(trans('invoice.created', ['number' => $invoice->number]), 'success')->important(); - return redirect()->route('invoices.show', $invoice->invoice_no); + return redirect()->route('invoices.show', $invoice->number); } } diff --git a/app/Http/Controllers/InvoicesController.php b/app/Http/Controllers/InvoicesController.php index d86c4f6..e13e8f7 100644 --- a/app/Http/Controllers/InvoicesController.php +++ b/app/Http/Controllers/InvoicesController.php @@ -9,6 +9,6 @@ class InvoicesController extends Controller { public function show(Invoice $invoice) { - return $invoice; + return view('invoices.show', compact('invoice')); } } diff --git a/app/Services/InvoiceDraft/InvoiceDraft.php b/app/Services/InvoiceDraft/InvoiceDraft.php index 0ff4fa3..c2c4772 100644 --- a/app/Services/InvoiceDraft/InvoiceDraft.php +++ b/app/Services/InvoiceDraft/InvoiceDraft.php @@ -62,7 +62,7 @@ class InvoiceDraft public function store() { $invoice = new Invoice(); - $invoice->invoice_no = $this->getNewInvoiceNo(); + $invoice->number = $this->getNewInvoiceNo(); $invoice->items = $this->getItemsArray(); $invoice->project_id = $this->projectId; $invoice->amount = $this->getTotal(); @@ -79,16 +79,16 @@ class InvoiceDraft { $prefix = date('ym'); - $lastInvoice = Invoice::orderBy('invoice_no', 'desc')->first(); + $lastInvoice = Invoice::orderBy('number', 'desc')->first(); if (!is_null($lastInvoice)) { - $lastInvoiceNo = $lastInvoice->invoice_no; - if (substr($lastInvoiceNo, 0, 4) == $prefix) { + $lastInvoiceNo = $lastInvoice->number; + if (substr($lastInvoiceNo, 0, 3) == $prefix) { return ++$lastInvoiceNo; } } - return $prefix.'0001'; + return $prefix.'001'; } protected function getItemsArray() diff --git a/app/Services/InvoiceDraft/InvoiceDraftCollection.php b/app/Services/InvoiceDraft/InvoiceDraftCollection.php index d20aa6e..838a765 100644 --- a/app/Services/InvoiceDraft/InvoiceDraftCollection.php +++ b/app/Services/InvoiceDraft/InvoiceDraftCollection.php @@ -2,7 +2,6 @@ namespace App\Services\InvoiceDrafts; -use App\Product; use Illuminate\Support\Collection; /** @@ -110,13 +109,6 @@ class InvoiceDraftCollection return $item; } - public function draftHasItem(TrasactionDraft $draft, Product $product) - { - $item = $draft->search($product); - - return !is_null($item); - } - public function updateDraftItem($draftKey, $itemKey, $newItemData) { $content = $this->getContent(); diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 771ef77..d83cd47 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -1,5 +1,6 @@ define(Event::class, function (Faker\Generator $faker) { 'end' => $faker->dateTimeBetween('-2 months', '-2 months')->format('Y-m-d H:i:s'), 'is_allday' => rand(0,1), ]; +}); + +$factory->define(Invoice::class, function (Faker\Generator $faker) { + + return [ + 'project_id' => function () { + return factory(Project::class)->create()->id; + }, + 'number' => date('ym').'001', + 'items' => [], + 'amount' => 100000, + 'notes' => $faker->paragraph, + 'status_id' => 1, + 'user_id' => 1, + ]; }); \ No newline at end of file diff --git a/database/migrations/2017_10_05_162758_create_invoices_table.php b/database/migrations/2017_10_05_162758_create_invoices_table.php index 856adcc..33157e3 100644 --- a/database/migrations/2017_10_05_162758_create_invoices_table.php +++ b/database/migrations/2017_10_05_162758_create_invoices_table.php @@ -16,7 +16,7 @@ class CreateInvoicesTable extends Migration Schema::create('invoices', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('project_id'); - $table->string('invoice_no', 8); + $table->string('number', 8)->unique(); $table->text('items'); $table->unsignedInteger('amount'); $table->string('notes'); diff --git a/resources/lang/id/invoice.php b/resources/lang/id/invoice.php index 710cc6b..ff4fb70 100644 --- a/resources/lang/id/invoice.php +++ b/resources/lang/id/invoice.php @@ -12,6 +12,7 @@ return [ // Actions 'proccess' => 'Proses Invoice', + 'item_list_empty' => 'List Item masih kosong.', 'create' => 'Input Invoice Baru', 'created' => 'Input Invoice baru telah berhasil.', 'show' => 'Detail Invoice', @@ -25,7 +26,11 @@ return [ 'undeleteable' => 'Data Invoice tidak dapat dihapus.', // Attributes + 'number' => 'No. Invoice', 'project' => 'Project', 'items' => 'Item Invoice', 'notes' => 'Catatan', + 'amount' => 'Tagihan', + 'item_description' => 'Deskripsi', + 'item_amount' => 'Biaya', ]; diff --git a/resources/views/invoices/partials/form-draft-detail.blade.php b/resources/views/invoices/partials/form-draft-detail.blade.php index feba000..06860e5 100644 --- a/resources/views/invoices/partials/form-draft-detail.blade.php +++ b/resources/views/invoices/partials/form-draft-detail.blade.php @@ -1,6 +1,10 @@ {{ trans('invoice.detail') }} {{ Form::open(['route' => ['cart.draft-proccess', $draft->draftKey], 'method' => 'patch']) }} -{!! FormField::select('project_id', $projects, ['label' => trans('invoice.project'), 'required' => true]) !!} +{!! FormField::select('project_id', $projects, [ + 'label' => trans('invoice.project'), + 'value' => $draft->projectId, + 'required' => true, +] ) !!} {!! FormField::textarea('notes', ['label' => trans('invoice.notes'), 'value' => $draft->notes]) !!} {{ Form::submit(trans('invoice.proccess'), ['class' => 'btn btn-info']) }} {{ Form::close() }} \ No newline at end of file diff --git a/resources/views/invoices/show.blade.php b/resources/views/invoices/show.blade.php new file mode 100644 index 0000000..39b77ff --- /dev/null +++ b/resources/views/invoices/show.blade.php @@ -0,0 +1,58 @@ +@extends('layouts.app') + +@section('title', $invoice->number . ' - ' . trans('invoice.detail')) + +@section('content') +{{--
{{ link_to_route('invoices.pdf', trans('invoice.invoice_print'), [$invoice->number], ['class' => 'btn btn-info']) }}
--}} +

{{ $invoice->number }} {{ trans('invoice.detail') }}

+
+
+
+

{{ trans('invoice.detail') }}

+
+ + + + + + + + + +
{{ trans('invoice.number') }}{{ $invoice->number }}
{{ trans('app.date') }}{{ $invoice->created_at->format('Y-m-d') }}
{{ trans('invoice.project') }}{{ $invoice->project_id }}
{{ trans('invoice.customer_phone') }}{{ $invoice->customer['phone'] }}
{{ trans('invoice.items_count') }}{{ $invoice->items_count }}
{{ trans('invoice.amount') }}{{ formatRp($invoice->amount) }}
+
+
+
+
+
+

{{ trans('invoice.items') }}

+
+ + + + + + + + + + @foreach($invoice->items as $key => $item) + + + + + + @endforeach + + + + + + + +
{{ trans('app.table_no') }}{{ trans('invoice.item_description') }}{{ trans('invoice.item_amount') }}
{{ $key + 1 }}{{ $item['description'] }}{{ formatRp($item['amount']) }}
{{ trans('app.total') }} :{{ formatRp($invoice['total']) }}
+
+
+
+
+@endsection \ No newline at end of file diff --git a/tests/Feature/InvoiceEntryTest.php b/tests/Feature/InvoiceEntryTest.php index fba5024..a959cba 100644 --- a/tests/Feature/InvoiceEntryTest.php +++ b/tests/Feature/InvoiceEntryTest.php @@ -157,7 +157,7 @@ class InvoiceEntryTest extends TestCase // $this->see(trans('invoice.created', ['invoice_no' => date('ym').'0001'])); $this->seeInDatabase('invoices', [ - 'invoice_no' => date('ym').'0001', + 'number' => date('ym').'001', 'items' => '[{"description":"Deskripsi item invoice","amount":1000},{"description":"Deskripsi item invoice","amount":2000}]', 'project_id' => $project->id, 'amount' => 3000, diff --git a/tests/Unit/Models/InvoiceTest.php b/tests/Unit/Models/InvoiceTest.php new file mode 100644 index 0000000..79bb494 --- /dev/null +++ b/tests/Unit/Models/InvoiceTest.php @@ -0,0 +1,17 @@ +create(); + $this->assertTrue($invoice->project instanceof Project); + } +}