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:
co-authored by
Claude Sonnet 5.5
parent
ea9a53f742
commit
25f23d541e
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Models\Invoice;
|
||||
|
||||
class InvoiceLookup
|
||||
{
|
||||
public static function find(string $invoiceNumber, string $lookupCode): ?Invoice
|
||||
{
|
||||
$invoice = Invoice::query()
|
||||
->where('invoice_number', $invoiceNumber)
|
||||
->where('status', '!=', InvoiceStatus::CANCELLED->value)
|
||||
->first();
|
||||
|
||||
if (!$invoice || !hash_equals((string) $invoice->lookup_code, strtoupper(trim($lookupCode)))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
public static function emailRow(Invoice $invoice): string
|
||||
{
|
||||
return $invoice->lookup_code ? EmailTemplateShell::row('Mã tra cứu', '<strong>' . e($invoice->lookup_code) . '</strong>') : '';
|
||||
}
|
||||
|
||||
public static function emailNote(Invoice $invoice): string
|
||||
{
|
||||
if (!$invoice->lookup_code) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$url = MailGlobals::frontendUrl() . '/tra-cuu-hoa-don';
|
||||
|
||||
return EmailTemplateShell::paragraph(
|
||||
'Quý khách có thể tra cứu và tải hoá đơn tại <a href="' . e($url) . '">' . e($url) . '</a> bằng số hoá đơn <strong>'
|
||||
. e($invoice->invoice_number) . '</strong> và mã tra cứu <strong>' . e($invoice->lookup_code) . '</strong>.'
|
||||
);
|
||||
}
|
||||
|
||||
public static function payload(Invoice $invoice): array
|
||||
{
|
||||
$invoice->loadMissing(['invoiceItems', 'customer']);
|
||||
$buyer = InvoiceBuyer::forInvoice($invoice);
|
||||
|
||||
return [
|
||||
'invoice_number' => $invoice->invoice_number,
|
||||
'vat_serial' => $invoice->vat_serial,
|
||||
'vat_number' => $invoice->vat_number,
|
||||
'vat_issued_at' => $invoice->vat_issued_at?->toDateString(),
|
||||
'date' => $invoice->date?->toDateString(),
|
||||
'status' => $invoice->status,
|
||||
'status_text' => $invoice->status_label,
|
||||
'sub_total' => (int) $invoice->sub_total,
|
||||
'discount_amount' => (int) $invoice->discount_amount,
|
||||
'tax' => (int) $invoice->tax,
|
||||
'total' => (int) $invoice->total,
|
||||
'buyer' => [
|
||||
'company' => $buyer['company'],
|
||||
'tax_code' => $buyer['tax_code'],
|
||||
],
|
||||
'items' => $invoice->invoiceItems->map(fn ($item) => [
|
||||
'description' => $item->description,
|
||||
'quantity' => (float) ($item->quantity ?? 1),
|
||||
'unit_price' => (int) $item->unit_price,
|
||||
'total_price' => (int) $item->total_price,
|
||||
])->values(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user