diff --git a/app/Entities/Invoices/Invoice.php b/app/Entities/Invoices/Invoice.php index f373d4c..04bb84a 100755 --- a/app/Entities/Invoices/Invoice.php +++ b/app/Entities/Invoices/Invoice.php @@ -3,11 +3,12 @@ namespace App\Entities\Invoices; use App\Entities\Projects\Project; +use App\Entities\Users\User; use Illuminate\Database\Eloquent\Model; class Invoice extends Model { - protected $guarded = ['id','created_at','updated_at']; + protected $guarded = ['id', 'created_at', 'updated_at']; protected $casts = ['items' => 'array']; @@ -21,13 +22,18 @@ class Invoice extends Model return $this->belongsTo(Project::class); } + public function creator() + { + return $this->belongsTo(User::class); + } + public function generateNewNumber() { $prefix = date('ym'); $lastInvoice = $this->orderBy('number', 'desc')->first(); - if (!is_null($lastInvoice)) { + if ( ! is_null($lastInvoice)) { $lastInvoiceNo = $lastInvoice->number; if (substr($lastInvoiceNo, 0, 4) == $prefix) { return ++$lastInvoiceNo; diff --git a/app/Services/InvoiceDraft/InvoiceDraft.php b/app/Services/InvoiceDraft/InvoiceDraft.php index e79f65f..f97bbc2 100644 --- a/app/Services/InvoiceDraft/InvoiceDraft.php +++ b/app/Services/InvoiceDraft/InvoiceDraft.php @@ -31,8 +31,7 @@ class InvoiceDraft unset($this->items[$itemKey]); } - public function empty() - { + function empty() { $this->items = []; } @@ -48,7 +47,7 @@ class InvoiceDraft public function updateItem($itemKey, $newItemData) { - if (!isset($this->items[$itemKey])) { + if ( ! isset($this->items[$itemKey])) { return; } @@ -61,14 +60,14 @@ class InvoiceDraft public function store() { - $invoice = new Invoice(); - $invoice->number = $invoice->generateNewNumber(); - $invoice->items = $this->getItemsArray(); + $invoice = new Invoice(); + $invoice->number = $invoice->generateNewNumber(); + $invoice->items = $this->getItemsArray(); $invoice->project_id = $this->projectId; - $invoice->amount = $this->getTotal(); - $invoice->notes = $this->notes; - $invoice->status_id = 1; - $invoice->user_id = auth()->id() ?: 1; + $invoice->amount = $this->getTotal(); + $invoice->notes = $this->notes; + $invoice->status_id = 1; + $invoice->creator_id = auth()->id() ?: 1; $invoice->save(); diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index fead664..695ef17 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -103,6 +103,8 @@ $factory->define(Invoice::class, function (Faker\Generator $faker) { 'amount' => 100000, 'notes' => $faker->paragraph, 'status_id' => 1, - 'user_id' => 1, + 'creator_id' => function () { + return factory(User::class)->create()->id; + }, ]; }); 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 33157e3..e0f2bdd 100644 --- a/database/migrations/2017_10_05_162758_create_invoices_table.php +++ b/database/migrations/2017_10_05_162758_create_invoices_table.php @@ -1,8 +1,8 @@ string('number', 8)->unique(); $table->text('items'); $table->unsignedInteger('amount'); - $table->string('notes'); + $table->string('notes')->nullable(); $table->unsignedTinyInteger('status_id'); - $table->unsignedInteger('user_id'); + $table->unsignedInteger('creator_id'); $table->timestamps(); }); } diff --git a/resources/lang/id/invoice.php b/resources/lang/id/invoice.php index 40e5a44..06d5b48 100644 --- a/resources/lang/id/invoice.php +++ b/resources/lang/id/invoice.php @@ -2,39 +2,40 @@ return [ // Labels - 'invoice' => 'Invoice', - 'list' => 'Daftar Invoice', - 'search' => 'Cari Invoice', - 'detail' => 'Detail Invoice', - 'not_found' => 'Invoice tidak ditemukan', - 'empty' => 'Belum ada Invoice', - 'back_to_index' => 'Kembali ke daftar Invoice', - 'draft_not_found' => 'Draft Invoice tidak ditemukan', + 'invoice' => 'Invoice', + 'list' => 'Daftar Invoice', + 'search' => 'Cari Invoice', + 'detail' => 'Detail Invoice', + 'not_found' => 'Invoice tidak ditemukan', + 'empty' => 'Belum ada Invoice', + 'back_to_index' => 'Kembali ke daftar Invoice', + 'draft_not_found' => 'Draft Invoice tidak ditemukan', // Actions - 'proccess' => 'Proses Invoice', - 'item_list_empty' => 'List Item masih kosong.', - 'create' => 'Input Invoice Baru', - 'created' => 'Input Invoice baru telah berhasil.', - 'show' => 'Detail Invoice', - 'edit' => 'Edit Invoice', - 'update' => 'Update Invoice', - 'updated' => 'Update data Invoice telah berhasil.', - 'delete' => 'Hapus Invoice', - 'delete_confirm' => 'Anda yakin akan menghapus Invoice ini?', - 'deleted' => 'Hapus data Invoice telah berhasil.', - 'undeleted' => 'Data Invoice gagal dihapus.', - 'undeleteable' => 'Data Invoice tidak dapat dihapus.', - 'print' => 'Cetak Invoice', + 'proccess' => 'Proses Invoice', + 'item_list_empty' => 'List Item masih kosong.', + 'create' => 'Input Invoice Baru', + 'created' => 'Input Invoice baru telah berhasil.', + 'show' => 'Detail Invoice', + 'edit' => 'Edit Invoice', + 'update' => 'Update Invoice', + 'updated' => 'Update data Invoice telah berhasil.', + 'delete' => 'Hapus Invoice', + 'delete_confirm' => 'Anda yakin akan menghapus Invoice ini?', + 'deleted' => 'Hapus data Invoice telah berhasil.', + 'undeleted' => 'Data Invoice gagal dihapus.', + 'undeleteable' => 'Data Invoice tidak dapat dihapus.', + 'print' => 'Cetak Invoice', // Attributes - 'number' => 'No. Invoice', - 'project' => 'Project', - 'items' => 'Item Invoice', - 'notes' => 'Catatan', - 'amount' => 'Tagihan', - 'customer' => 'Customer', + 'number' => 'No. Invoice', + 'project' => 'Project', + 'creator' => 'Dibuat Oleh', + 'items' => 'Item Invoice', + 'notes' => 'Catatan', + 'amount' => 'Tagihan', + 'customer' => 'Customer', 'item_description' => 'Deskripsi', - 'item_amount' => 'Biaya', - 'items_count' => 'Jumlah Item', + 'item_amount' => 'Biaya', + 'items_count' => 'Jumlah Item', ]; diff --git a/resources/views/invoices/show.blade.php b/resources/views/invoices/show.blade.php index 99c7e36..b7e99b2 100644 --- a/resources/views/invoices/show.blade.php +++ b/resources/views/invoices/show.blade.php @@ -19,6 +19,7 @@