<?php
$assetBase =
    basename(rtrim(FCPATH, "\\/")) === "public" ? "assets/" : "public/assets/";
$clientName = $invoice["first_name"] . " " . $invoice["last_name"];
?>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title><?= esc(
    $invoice["invoice_number"],
) ?> · BrandSquare Admin</title><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap" rel="stylesheet"><link rel="stylesheet" href="<?= base_url(
     $assetBase . "css/admin.css",
 ) ?>"></head><body class="admin-page">
<aside class="admin-sidebar"><a href="<?= base_url(
    "admin/leads",
) ?>" class="admin-logo">Brand<span>Square.</span></a><nav><a href="<?= base_url(
    "admin/leads",
) ?>"><i>◎</i> Leads</a><a href="<?= base_url(
    "admin/clients",
) ?>"><i>◉</i> Clients</a><a href="<?= base_url(
    "admin/quotations",
) ?>"><i>₹</i> Quotations</a><a class="active" href="<?= base_url(
    "admin/invoices",
) ?>"><i>▤</i> Invoices</a><a href="<?= base_url(
    "admin/industries",
) ?>"><i>◆</i> Industries</a><a href="<?= base_url(
    "admin/email-templates",
) ?>"><i>✦</i> Email templates</a><a href="<?= base_url(
    "admin/articles",
) ?>"><i>▤</i> Articles</a><a href="<?= base_url(
    "admin/settings",
) ?>"><i>⚙</i> Settings</a><a href="<?= base_url() ?>" target="_blank"><i>↗</i> View website</a></nav><div class="admin-user"><span><?= esc(
    strtoupper(substr((string) session("admin_name"), 0, 2)),
) ?></span><div><b><?= esc(session("admin_name")) ?></b><small><?= esc(
    session("admin_email"),
) ?></small></div></div><form action="<?= base_url(
    "admin/logout",
) ?>" method="post"><?= csrf_field() ?><button class="logout">Sign out →</button></form></aside>
<main class="admin-main quotation-view-main"><header class="admin-heading"><div><a class="back-to-templates" href="<?= base_url(
    "admin/invoices",
) ?>">← Invoice register</a><h1>Invoice details</h1><p>Review, download, or deliver this client invoice.</p></div><div class="quotation-actions"><a href="<?= base_url(
    "admin/invoices/" . $invoice["id"] . "/download",
) ?>">Download PDF <span>↓</span></a><form method="post" action="<?= base_url(
    "admin/invoices/" . $invoice["id"] . "/email-pdf",
) ?>" onsubmit="return confirm('Email this invoice PDF to the client?')"><?= csrf_field() ?><button>Email PDF <span>↗</span></button></form><form method="post" action="<?= base_url(
    "admin/invoices/" . $invoice["id"] . "/email",
) ?>" onsubmit="return confirm('Email this invoice without an attachment?')"><?= csrf_field() ?><button>Email invoice <span>↗</span></button></form><a class="edit-quotation-action" href="<?= base_url(
    "admin/invoices/" . $invoice["id"] . "/edit",
) ?>">Edit invoice <span>→</span></a></div></header>
<?php
if (session("error")): ?><div class="alert error"><?= esc(
    session("error"),
) ?></div><?php endif;
if (session("success")): ?><div class="alert success"><?= esc(
    session("success"),
) ?></div><?php endif;
?>
<article class="quotation-document invoice-document"><header><a class="quotation-brand" href="<?= base_url() ?>">Brand<span>Square.</span></a><div><span>INVOICE</span><h2><?= esc(
    $invoice["invoice_number"],
) ?></h2><b class="quote-status status-<?= esc($invoice["status"]) ?>"><?= esc(
    ucfirst($invoice["status"]),
) ?></b></div></header><section class="quotation-parties"><div><span>Bill to</span><h3><?= esc(
    $clientName,
) ?></h3><a href="mailto:<?= esc($invoice["email"]) ?>"><?= esc(
    $invoice["email"],
) ?></a><a href="tel:<?= esc(
    preg_replace("/[^0-9+]/", "", $invoice["mobile"]),
) ?>"><?= esc($invoice["mobile"]) ?></a><p><?= nl2br(
    esc($invoice["address"]),
) ?></p></div><dl><div><dt>Invoice source</dt><dd><?= $invoice[
    "quotation_number"
]
    ? "Quotation " . esc($invoice["quotation_number"])
    : "Standalone invoice" ?></dd></div><div><dt>Invoice date</dt><dd><?= date(
    "d M Y",
    strtotime($invoice["invoice_date"]),
) ?></dd></div><div><dt>Due date</dt><dd><?= $invoice["due_date"]
    ? date("d M Y", strtotime($invoice["due_date"]))
    : "On receipt" ?></dd></div></dl></section><div class="quotation-document-table-wrap"><table class="quotation-document-table"><thead><tr><th>Item</th><th>Description</th><th>Quantity</th><th>Price</th><th>Amount</th></tr></thead><tbody><?php foreach (
    $items
    as $item
): ?><tr><td><b><?= esc($item["item_name"]) ?></b></td><td><?= nl2br(
    esc($item["description"]),
) ?></td><td><?= number_format(
    (float) $item["quantity"],
    2,
) ?></td><td>₹<?= number_format(
    (float) $item["price"],
    2,
) ?></td><td>₹<?= number_format(
    (float) $item["line_total"],
    2,
) ?></td></tr><?php endforeach; ?></tbody></table></div><section class="quotation-document-total"><span>Total due</span><strong>₹<?= number_format(
    (float) $invoice["total"],
    2,
) ?></strong></section><?php if (
    $invoice["notes"]
): ?><section class="quotation-document-notes"><span>Payment notes</span><p><?= nl2br(
    esc($invoice["notes"]),
) ?></p></section><?php endif; ?><footer><span><?= $invoice["quotation_number"]
    ? "Created from " . esc($invoice["quotation_number"])
    : "Created directly for this client" ?></span><form method="post" action="<?= base_url(
    "admin/invoices/" . $invoice["id"] . "/delete",
) ?>" onsubmit="return confirm('Permanently delete this invoice?')"><?= csrf_field() ?><button>Delete invoice</button></form></footer></article></main></body></html>
