feat(billing): renewals, coupons, VAT numbering, billing cycles and invoice payment tracking

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-19 16:37:56 +07:00
co-authored by Claude Sonnet 5.5
parent ea9a53f742
commit 25f23d541e
134 changed files with 4926 additions and 185 deletions
+29
View File
@@ -4,7 +4,9 @@ namespace App\Services;
use App\Models\Invoice;
use App\Models\Setting;
use App\Support\InvoiceBuyer;
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Support\Facades\Log;
class InvoicePdfService
{
@@ -19,6 +21,7 @@ class InvoicePdfService
'invoice' => $invoice,
'invoiceItems' => $invoice->invoiceItems,
'customer' => $invoice->customer,
'buyer' => InvoiceBuyer::forInvoice($invoice),
'order' => $invoice->order,
'companyName' => $settingValue->company ?? 'Thế Giới Số',
'companyAddress' => $settingValue->address ?? '',
@@ -46,6 +49,32 @@ class InvoicePdfService
->output();
}
public function vatFileName(Invoice $invoice): string
{
return 'Hoa-don-VAT-' . $invoice->vat_serial . '-' . $invoice->vat_number . '.pdf';
}
/** @return array{pdf: string, file_name: string}|null */
public function attachment(?int $invoiceId): ?array
{
if (!$invoiceId) {
return null;
}
try {
$invoice = Invoice::find($invoiceId);
return $invoice ? ['pdf' => $this->generate($invoice), 'file_name' => $this->generateFileName($invoice)] : null;
} catch (\Throwable $e) {
Log::warning('InvoicePdfService: PDF generation failed, sending without attachment', [
'invoice_id' => $invoiceId,
'error' => $e->getMessage(),
]);
return null;
}
}
public function generateFileName(Invoice $invoice): string
{
return 'Hoa-don-' . $invoice->invoice_number . '.pdf';