Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/Models/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ public function scopeOwnedBy(Builder $query, User|int $user): Builder
return $query->where('user_id', $userId);
}

public function statusLabel(): string
{
return match ($this->status) {
'paid' => 'Paid',
'partial' => 'Partially paid',
'pending' => 'Payment pending',
'void' => 'Void',
'draft' => 'Draft',
default => 'Open',
};
}

public function scopeOpen(Builder $query): Builder
{
return $query->whereIn('status', ['draft', 'sent', 'partial']);
Expand Down
2 changes: 1 addition & 1 deletion resources/views/mail/invoice-ready.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<x-mail::panel>
**Due date:** {{ optional($invoice->due_date)->toFormattedDateString() ?? '—' }}
**Amount (BTC):** {{ $invoice->amount_btc ?? '—' }}
**Status:** Open
**Status:** {{ $invoice->statusLabel() }}
</x-mail::panel>

<x-mail::panel>
Expand Down
52 changes: 52 additions & 0 deletions tests/Feature/InvoiceReadyMailStatusTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Tests\Feature;

use App\Mail\InvoiceReadyMail;
use App\Models\Client;
use App\Models\Invoice;
use App\Models\InvoiceDelivery;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

/**
* The invoice email states the invoice's real status, not a fixed word (#185).
*/
class InvoiceReadyMailStatusTest extends TestCase
{
use RefreshDatabase;

public function test_the_invoice_email_reports_the_invoice_status(): void
{
$owner = User::factory()->create();
$client = Client::create(['user_id' => $owner->id, 'name' => 'Status Client', 'email' => 'status@example.com']);

foreach ([['paid', 'Paid'], ['partial', 'Partially paid'], ['sent', 'Open'], ['void', 'Void']] as [$status, $label]) {
$invoice = Invoice::create([
'user_id' => $owner->id,
'client_id' => $client->id,
'number' => 'INV-STATUS-'.strtoupper($status),
'amount_usd' => 10,
'btc_rate' => 40_000,
'amount_btc' => 0.00025,
'payment_address' => 'tb1qq0example'.$status,
'status' => $status,
'invoice_date' => now()->toDateString(),
]);
$invoice->enablePublicShare();
$delivery = InvoiceDelivery::create([
'invoice_id' => $invoice->id,
'user_id' => $owner->id,
'type' => 'send',
'status' => 'queued',
'recipient' => $client->email,
'dispatched_at' => now(),
]);

$html = (new InvoiceReadyMail($invoice->fresh(), $delivery))->render();

$this->assertStringContainsString('Status:</strong> '.$label, $html, "status {$status}");
}
}
}
Loading