diff --git a/app/Enums/InvoiceStatus.php b/app/Enums/InvoiceStatus.php index ec8eedc..0b59c95 100644 --- a/app/Enums/InvoiceStatus.php +++ b/app/Enums/InvoiceStatus.php @@ -22,9 +22,9 @@ enum InvoiceStatus: string public function color(): string { return match ($this) { - self::DRAFT => 'gray', + self::DRAFT => 'zinc', self::POSTED => 'green', - self::VOID => 'zinc', + self::VOID => 'red', self::PAID => 'blue', }; } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index c70ab02..6b280ef 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Str; class Invoice extends Model { @@ -16,6 +17,7 @@ class Invoice extends Model { static::creating(function (Invoice $invoice) { $invoice->invoice_number ??= static::generateInvoiceNumber(); + $invoice->uuid = (string) Str::uuid(); }); } @@ -49,6 +51,17 @@ class Invoice extends Model 'sent_at' => 'date', ]; + /** + * Get the route key for the model. + * This tells Laravel to use the 'uuid' column for route model binding. + * + * @return string + */ + public function getRouteKeyName(): string + { + return 'uuid'; + } + public function client(): BelongsTo { return $this->belongsTo(Client::class); diff --git a/database/migrations/2026_01_28_155045_add_uuid_column_to_invoices_table.php b/database/migrations/2026_01_28_155045_add_uuid_column_to_invoices_table.php new file mode 100644 index 0000000..075604e --- /dev/null +++ b/database/migrations/2026_01_28_155045_add_uuid_column_to_invoices_table.php @@ -0,0 +1,28 @@ +uuid('uuid')->after('id')->unique(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('invoices', function (Blueprint $table) { + $table->dropColumn('uuid'); + }); + } +}; diff --git a/resources/views/components/⚡edit-invoice.blade.php b/resources/views/components/⚡edit-invoice.blade.php index 0a14837..cfc1401 100644 --- a/resources/views/components/⚡edit-invoice.blade.php +++ b/resources/views/components/⚡edit-invoice.blade.php @@ -1,21 +1,176 @@ invoice = $invoice; + $this->invoice = $invoice; + $this->client_id = $invoice?->client_id; + $this->notes = $invoice?->notes; + $this->internal_notes = $invoice?->internal_notes; + } + + public function updateClient(): void + { + $this->validate([ + 'client_id' => 'required|exists:clients,id' + ]); + + $this->invoice->update(['client_id' => $this->client_id]); + } + + public function updateNotes(): void + { + $this->validate([ + 'notes' => 'nullable|string', + 'internal_notes' => 'nullable|string' + ]); + $this->invoice->update([ + 'notes' => $this->notes, + 'internal_notes' => $this->internal_notes, + ]); + } + + public function setStatus($newStatus): void + { + $updatedValue = match ($newStatus) { + 'posted' => InvoiceStatus::POSTED, + 'draft' => InvoiceStatus::DRAFT, + 'void' => InvoiceStatus::VOID, + 'paid' => InvoiceStatus::PAID, + default => $this->invoice->status + }; + $this->invoice->update([ + 'status' => $updatedValue, + ]); + + if ($newStatus === 'posted') { + $this->invoice->update([ + 'invoice_date' => now(), + 'due_date' => now()->addDays(30), + ]); + } + } + + #[Computed] + public function clients() + { + return Client::where('status', 'active')->orderBy('abbreviation')->get(); } }; ?>