From 67de82a525a4bf784e9766759ee88598d37fc6af Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 27 Jan 2026 21:59:59 -0600 Subject: [PATCH] Invoice model --- app/Casts/MoneyCast.php | 29 +++++++++++++++++++ app/Enums/InvoiceStatus.php | 11 +++++++ app/Models/Invoice.php | 15 +++++++++- ...026_01_28_024527_create_invoices_table.php | 8 ++++- 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 app/Casts/MoneyCast.php create mode 100644 app/Enums/InvoiceStatus.php diff --git a/app/Casts/MoneyCast.php b/app/Casts/MoneyCast.php new file mode 100644 index 0000000..0d7e38b --- /dev/null +++ b/app/Casts/MoneyCast.php @@ -0,0 +1,29 @@ + $attributes + */ + public function get(Model $model, string $key, mixed $value, array $attributes): float + { + return $value / 100; + } + + /** + * Prepare the given value for storage. + * + * @param array $attributes + */ + public function set(Model $model, string $key, mixed $value, array $attributes): int + { + return (int) round($value * 100); + } +} diff --git a/app/Enums/InvoiceStatus.php b/app/Enums/InvoiceStatus.php new file mode 100644 index 0000000..5f8d995 --- /dev/null +++ b/app/Enums/InvoiceStatus.php @@ -0,0 +1,11 @@ + MoneyCast::class, + 'status' => InvoiceStatus::class, + 'invoice_date' => 'date', + 'due_date' => 'date', + 'date_sent' => 'date', + ]; + + public function formattedTotal(): string + { + return '$'.number_format($this->total, 2); + } } diff --git a/database/migrations/2026_01_28_024527_create_invoices_table.php b/database/migrations/2026_01_28_024527_create_invoices_table.php index f58911c..30c80f1 100644 --- a/database/migrations/2026_01_28_024527_create_invoices_table.php +++ b/database/migrations/2026_01_28_024527_create_invoices_table.php @@ -16,7 +16,13 @@ return new class extends Migration $table->id(); $table->string('invoice_number')->unique(); $table->foreignIdFor(Client::class); - $table->json('lines'); + $table->string('status')->default('draft'); + $table->date('invoice_date')->nullable(); + $table->date('date_sent')->nullable(); + $table->date('due_date')->nullable(); + $table->integer('total'); + $table->text('notes')->nullable(); + $table->text('internal_notes')->nullable(); $table->timestamps(); }); }