@extends('layouts.dashboard') @section('content') @php /** * Vendor billing — a printable invoice for one subscription payment. * * Reuses the project's existing print approach (css/print.css): everything sits inside a normal * on-screen .qm-print-area block, and printing hides the rest of the panel so only the invoice * reaches the paper. No print rules are invented here. * * Every figure is read from the subscription row itself — the amount actually charged, the plan * it bought and the term it covers — so a reprint years later shows what was really paid rather * than what the plan costs today. * * @var array $sub subscription joined to its plan * @var array|null $restaurant the restaurant being billed * @var array $platform ['name','address','email','phone'] — who issued the invoice */ $status = (string) $sub['status']; $statusPill = [ 'active' => 'qm-pill-green', 'expired' => 'qm-pill-grey', 'cancelled' => 'qm-pill-grey', ][$status] ?? 'qm-pill-grey'; $cycleLabel = [ 'monthly' => t_raw('vendor.billing.cycle_monthly_suffix'), 'yearly' => t_raw('vendor.billing.cycle_yearly_suffix'), 'lifetime' => t_raw('vendor.billing.cycle_lifetime_suffix'), ]; // The invoice number comes from its own gapless counter, not from the row id — an abandoned // gateway checkout consumes an id, so an id-derived number left a hole for every one of them. // App\Services\Invoice issues the number (and the tax snapshot) the first time an activated // subscription needs one, and never changes either afterwards. $sub = \App\Services\Invoice::ensureIssued($sub); $invoiceNo = \App\Services\Invoice::number($sub); // Every figure below is read from the row's stored snapshot, so a reprint years from now shows // the rate that was actually charged rather than whatever the platform charges today. $totals = \App\Services\Invoice::totals($sub); $platformTaxNumber = (string) \App\Models\Setting::get('platform_tax_number', ''); $address = array_values(array_filter([ (string) ($restaurant['address'] ?? ''), trim(((string) ($restaurant['city'] ?? '')) . ' ' . ((string) ($restaurant['postcode'] ?? ''))), (string) ($restaurant['state'] ?? ''), ], static fn (string $line): bool => trim($line) !== '')); @endphp
{{ $invoiceSub ?? t_raw('vendor.billing.invoice_sub') }}
{!! t_raw('vendor.billing.invoice_issued', [':date' => fmt_day($sub['created_at'], true)]) !!}
{{ $platform['name'] }}
@if (trim($platform['address']) !== '')
{!! nl2br(e(trim($platform['address']))) !!}@endif
@if (trim($platform['email']) !== '')
{{ $platform['email'] }}@endif
@if (trim($platform['phone']) !== '')
{{ $platform['phone'] }}@endif
@if ($platformTaxNumber !== '')
{{ t_raw('pdf.tax_number') }} {{ $platformTaxNumber }}@endif
{{ (string) ($restaurant['name'] ?? '') }}
@foreach ($address as $line)
{{ $line }}@endforeach
@if (!empty($restaurant['email']))
{{ (string) $restaurant['email'] }}@endif
@php /* The restaurant is the billing entity — the subscription is sold to the
venue, not to whichever user account happens to own it today. */
@endphp
@if (!empty($restaurant['tax_number']))
{{ t_raw('pdf.tax_number') }} {{ (string) $restaurant['tax_number'] }}@endif
| {{ t_raw('vendor.billing.invoice_col_description') }} | {{ t_raw('common.period') }} | {{ t_raw('common.amount') }} |
|---|---|---|
| @php /* ONE INVOICE, TWO THINGS SOLD. The platform bills restaurants for plans and for sponsored placements, and both must print on the same document — one renderer, one numbering sequence, so a change to the format lands on both. A caller that sells something other than a plan passes its own line wording; everything else on the page is identical. */ @endphp {{ $sub['line_label'] ?? t_raw('vendor.billing.invoice_line_plan', [':plan' => (string) ($sub['plan_name'] ?? '')]) }} @if (isset($sub['line_sub'])){{ (string) $sub['line_sub'] }}@else{{ $cycleLabel[(string) (($sub['billing_cycle'] ?? '') ?: ($sub['plan_cycle'] ?? ''))] ?? '' }}@if ($sub['commission_percent'] !== null) · {{ t_raw('vendor.billing.invoice_line_commission', [':rate' => (string) (float) $sub['commission_percent']]) }}@endif @endif | @if (!empty($sub['starts_at'])) {!! fmt_day($sub['starts_at']) !!} – {!! !empty($sub['ends_at']) ? fmt_day($sub['ends_at']) : t('vendor.billing.never_lifetime') !!} @else {!! dash() !!} @endif | {{ money($totals['subtotal']) }} |
| {{ t_raw('pdf.subtotal') }} | {{ money($totals['subtotal']) }} | |
| {{ \App\Services\Invoice::taxLineLabel($totals) }} | {{ money($totals['tax']) }} | |
| {{ t_raw('vendor.billing.invoice_total') }} | {{ money($totals['total']) }} | |
{{ t_raw('vendor.billing.invoice_footer', [':site' => $platform['name']]) }}