From 9d9838b02da68043db7b4fcc7d5b5adbe783cd25 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 28 Jan 2026 14:29:33 -0600 Subject: [PATCH] Manipulating status and notes on invoices works. --- app/Enums/InvoiceStatus.php | 4 +- app/Models/Invoice.php | 13 ++ ...5045_add_uuid_column_to_invoices_table.php | 28 +++ .../views/components/⚡edit-invoice.blade.php | 167 +++++++++++++++++- .../views/components/⚡invoice-list.blade.php | 16 ++ 5 files changed, 220 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2026_01_28_155045_add_uuid_column_to_invoices_table.php 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(); } }; ?>
- Edit Invoice - - Identifying Information +
+ Edit Invoice +
+ @if($this->invoice->status === InvoiceStatus::DRAFT) + Void Invoice + Post Invoice + @elseif($this->invoice->status === InvoiceStatus::POSTED) + Void Invoice + Un-Post Invoice + @elseif($this->invoice->status === InvoiceStatus::VOID) + Restore Invoice + @endif +
+
+ + +
+
+
+ ID + {{ $invoice->id }} +
+
+ Invoice Number + {{ $invoice->invoice_number }} +
+
+ UUID + {{ $invoice->uuid }} +
+
+
+ @if($invoice->status !== InvoiceStatus::DRAFT) +
+ Client + {{ $invoice->client->name }} +
+
+ Invoice Date + {{ $invoice->invoice_date?->format('m/d/Y') }} +
+
+ Due Date + {{ $invoice->due_date?->format('m/d/Y') }} +
+
+ Sent Date + {{ $invoice->sent_at?->format('m/d/Y') }} +
+ @else + + @foreach($this->clients as $client) + {{ $client->name }} + @endforeach + + @endif +
+
+
+ Status + + {{ $invoice->status->label() }} + +
+
+ Created + {{ $invoice->created_at->local()->format('m/d/Y | h:m:s') }} +
+
+ Last Updated + {{ $invoice->updated_at->local()->format('m/d/Y | h:m:s') }} +
+
+ +
+ +
+ +
+ + + + +
+
+ Save Notes +
+
+
diff --git a/resources/views/components/⚡invoice-list.blade.php b/resources/views/components/⚡invoice-list.blade.php index 23fa7a9..53967ea 100644 --- a/resources/views/components/⚡invoice-list.blade.php +++ b/resources/views/components/⚡invoice-list.blade.php @@ -72,6 +72,7 @@ new class extends Component { wire:click="sort('total')"> Total + @@ -103,6 +104,21 @@ new class extends Component { @endif {{ formatMoney($invoice->total) }} + + + + + + + + Edit Invoice + + + + + @endforeach