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(); }); }