@php /** * The sum of a vendor checkout, broken out — shared by the signup checkout and vendor/pay.php so * the two pages can never quote the same charge differently. * * @var string $label what is being bought — the plan name, "Business renewal", a placement… * @var float $amount the GROSS about to be taken: Invoice::grossFor() * @var float|null $listAmount the GROSS before the annual discount, when one applies; null otherwise * @var float $discountPct the operator's annual discount, for the discount line's label */ $amount = (float) $amount; $listAmount = isset($listAmount) && $listAmount !== null ? (float) $listAmount : null; $discountPct = (float) ($discountPct ?? 0); /* Tax is read from the same Invoice::taxOn() the invoice is carved from, so the checkout and the document can never quote different numbers. Silent where the platform charges no tax — there is nothing to explain, and a "Tax $0.00" line only invites the question. */ $tax = \App\Services\Invoice::taxOn($amount); $hasTax = ($tax['mode'] ?? 'none') !== 'none' && (float) ($tax['amount'] ?? 0) > 0; $taxName = $hasTax ? \App\Services\Invoice::taxLineLabel($tax) : ''; $netAmt = $hasTax ? round($amount - (float) $tax['amount'], 2) : $amount; /* AN ANNUAL DISCOUNT IS SHOWN AS A DISCOUNT: the twelve-month list price struck through, the saving on its own line, then the subtotal the tax is figured on — not one pre-discounted figure the buyer has to take on trust. The list is carried on the same basis as the subtotal (net of the tax line where there is one), so the three numbers add up on the page. */ $listNet = null; $discountAmt = 0.0; if ($listAmount !== null && $listAmount > $amount) { $listTax = \App\Services\Invoice::taxOn($listAmount); $listNet = $hasTax ? round($listAmount - (float) ($listTax['amount'] ?? 0), 2) : $listAmount; $discountAmt = round($listNet - $netAmt, 2); if ($discountAmt <= 0) { $listNet = null; } } $pctText = rtrim(rtrim(number_format($discountPct, 2, '.', ''), '0'), '.'); @endphp