Drawer

Standalone App Code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>SwiftBill — Freelance Invoice Manager</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <style>
    @media print {
      body * { visibility: hidden; }
      #printModal, #printModal * { visibility: visible; }
      #printModal { position: absolute; left: 0; top: 0; width: 100%; background: white; }
      .no-print { display: none !important; }
    }
  </style>
</head>
<body class="bg-slate-50 text-slate-800 min-h-screen font-sans">

  <!-- Header -->
  <header class="bg-indigo-950 text-white py-5 px-6 shadow-md">
    <div class="max-w-6xl mx-auto flex justify-between items-center">
      <div>
        <h1 class="text-2xl font-bold tracking-tight">SwiftBill</h1>
        <p class="text-indigo-200 text-xs">Smart Freelance Invoice & Client Manager</p>
      </div>
      <span class="bg-indigo-800 text-indigo-100 text-xs font-medium px-3 py-1 rounded-full">v1.0 Live</span>
    </div>
  </header>

  <main class="max-w-6xl mx-auto p-6 space-y-6">

    <!-- KPI Cards -->
    <section class="grid grid-cols-1 md:grid-cols-3 gap-4">
      <div class="bg-white p-5 rounded-xl shadow-sm border border-slate-200">
        <p class="text-xs font-semibold uppercase text-slate-400">Total Billed</p>
        <p id="totalBilled" class="text-2xl font-bold text-slate-900 mt-1">$0.00</p>
      </div>
      <div class="bg-white p-5 rounded-xl shadow-sm border border-slate-200">
        <p class="text-xs font-semibold uppercase text-emerald-600">Paid Revenue</p>
        <p id="paidRevenue" class="text-2xl font-bold text-emerald-600 mt-1">$0.00</p>
      </div>
      <div class="bg-white p-5 rounded-xl shadow-sm border border-slate-200">
        <p class="text-xs font-semibold uppercase text-amber-600">Pending Balance</p>
        <p id="pendingBalance" class="text-2xl font-bold text-amber-600 mt-1">$0.00</p>
      </div>
    </section>

    <!-- Main Grid -->
    <div class="grid grid-cols-1 lg:grid-cols-12 gap-6">

      <!-- Create Invoice Form -->
      <section class="lg:col-span-5 bg-white p-6 rounded-xl shadow-sm border border-slate-200">
        <h2 class="text-lg font-bold text-slate-800 mb-4">Create New Invoice</h2>
        <form id="invoiceForm" class="space-y-4">
          <div>
            <label class="block text-xs font-semibold text-slate-600 mb-1">Client Name</label>
            <input type="text" id="clientName" required placeholder="e.g., Apex Design Studio" class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-600 outline-none" />
          </div>
          <div class="grid grid-cols-2 gap-3">
            <div>
              <label class="block text-xs font-semibold text-slate-600 mb-1">Client Email</label>
              <input type="email" id="clientEmail" required placeholder="billing@client.com" class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-600 outline-none" />
            </div>
            <div>
              <label class="block text-xs font-semibold text-slate-600 mb-1">Due Date</label>
              <input type="date" id="dueDate" required class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-600 outline-none" />
            </div>
          </div>
          <div>
            <label class="block text-xs font-semibold text-slate-600 mb-1">Service / Project Description</label>
            <input type="text" id="serviceDesc" required placeholder="e.g., Website UI Redesign & SEO Setup" class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-600 outline-none" />
          </div>
          <div class="grid grid-cols-3 gap-3">
            <div>
              <label class="block text-xs font-semibold text-slate-600 mb-1">Qty / Hours</label>
              <input type="number" id="qty" value="1" min="1" required class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-600 outline-none" />
            </div>
            <div>
              <label class="block text-xs font-semibold text-slate-600 mb-1">Rate ($)</label>
              <input type="number" id="rate" placeholder="250" min="1" step="0.01" required class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-600 outline-none" />
            </div>
            <div>
              <label class="block text-xs font-semibold text-slate-600 mb-1">Tax (%)</label>
              <input type="number" id="tax" value="5" min="0" max="100" class="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-600 outline-none" />
            </div>
          </div>
          <button type="submit" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-semibold py-2.5 rounded-lg text-sm transition">
            + Generate Invoice
          </button>
        </form>
      </section>

      <!-- Invoice List -->
      <section class="lg:col-span-7 bg-white p-6 rounded-xl shadow-sm border border-slate-200">
        <div class="flex justify-between items-center mb-4">
          <h2 class="text-lg font-bold text-slate-800">Client Invoices</h2>
          <span id="invoiceCount" class="text-xs text-slate-500 font-medium">0 Invoices</span>
        </div>
        <div class="overflow-x-auto">
          <table class="w-full text-left border-collapse">
            <thead>
              <tr class="border-b border-slate-200 text-xs uppercase text-slate-400">
                <th class="py-2">Invoice / Client</th>
                <th class="py-2">Due</th>
                <th class="py-2">Total</th>
                <th class="py-2">Status</th>
                <th class="py-2 text-right">Actions</th>
              </tr>
            </thead>
            <tbody id="invoiceTableBody" class="divide-y divide-slate-100 text-sm"></tbody>
          </table>
        </div>
      </section>

    </div>
  </main>

  <!-- Printable Invoice Modal -->
  <div id="printModal" class="fixed inset-0 bg-slate-900/50 hidden items-center justify-center p-4 z-50">
    <div class="bg-white rounded-xl max-w-lg w-full p-8 shadow-xl border border-slate-200">
      <div class="flex justify-between items-start border-b pb-4">
        <div>
          <h3 class="text-xl font-bold text-indigo-950">INVOICE</h3>
          <p id="modalInvId" class="text-xs text-slate-500 mt-0.5">#INV-1001</p>
        </div>
        <span id="modalStatus" class="px-2.5 py-1 rounded-full text-xs font-semibold"></span>
      </div>
      <div class="my-5 grid grid-cols-2 text-sm gap-4">
        <div>
          <p class="text-xs text-slate-400 uppercase font-semibold">Billed To</p>
          <p id="modalClient" class="font-bold text-slate-800 mt-0.5"></p>
          <p id="modalEmail" class="text-slate-500 text-xs"></p>
        </div>
        <div class="text-right">
          <p class="text-xs text-slate-400 uppercase font-semibold">Due Date</p>
          <p id="modalDue" class="font-medium text-slate-800 mt-0.5"></p>
        </div>
      </div>
      <div class="border-t border-b border-slate-200 py-4 my-4 text-sm">
        <div class="flex justify-between font-medium text-slate-800">
          <span id="modalDesc"></span>
          <span id="modalSubtotal"></span>
        </div>
        <p id="modalMeta" class="text-xs text-slate-400 mt-1"></p>
      </div>
      <div class="space-y-1 text-sm text-right">
        <p class="text-slate-500">Tax: <span id="modalTax" class="text-slate-800 font-medium"></span></p>
        <p class="text-lg font-bold text-indigo-950">Total Due: <span id="modalTotal"></span></p>
      </div>
      <div class="mt-6 flex justify-end gap-2 no-print">
        <button onclick="window.print()" class="bg-indigo-600 text-white px-4 py-2 rounded-lg text-xs font-semibold hover:bg-indigo-700">Print / Save PDF</button>
        <button onclick="closeModal()" class="bg-slate-200 text-slate-700 px-4 py-2 rounded-lg text-xs font-semibold hover:bg-slate-300">Close</button>
      </div>
    </div>
  </div>

  <script>
    const defaultInvoices = [
      { id: 'INV-1041', client: 'Nova Retail Group', email: 'accounts@novaretail.co', due: '2026-11-05', desc: 'E-Commerce Checkout Optimization', qty: 1, rate: 850, tax: 5, status: 'Paid' },
      { id: 'INV-1042', client: 'Horizon Logistics', email: 'finance@horizonlog.com', due: '2026-11-12', desc: 'Custom Client Portal UI & Setup', qty: 15, rate: 45, tax: 5, status: 'Pending' },
      { id: 'INV-1043', client: 'Verde Coffee Roasters', email: 'hello@verdecoffee.com', due: '2026-11-18', desc: 'Landing Page & Subscription Flow', qty: 1, rate: 520, tax: 0, status: 'Pending' }
    ];

    let invoices = JSON.parse(localStorage.getItem('swiftbill_invoices')) || defaultInvoices;

    function saveAndRender() {
      localStorage.setItem('swiftbill_invoices', JSON.stringify(invoices));
      const tbody = document.getElementById('invoiceTableBody');
      tbody.innerHTML = '';
      let total = 0, paid = 0, pending = 0;

      invoices.forEach((inv, index) => {
        const sub = inv.qty * inv.rate;
        const taxAmt = sub * (inv.tax / 100);
        const grand = sub + taxAmt;
        total += grand;
        if (inv.status === 'Paid') paid += grand; else pending += grand;

        const badge = inv.status === 'Paid'
          ? 'bg-emerald-100 text-emerald-800'
          : 'bg-amber-100 text-amber-800';

        tbody.innerHTML += `
          <tr class="hover:bg-slate-50">
            <td class="py-3">
              <p class="font-bold text-slate-800">${inv.client}</p>
              <p class="text-xs text-slate-400">${inv.id} • ${inv.desc}</p>
            </td>
            <td class="py-3 text-xs text-slate-600">${inv.due}</td>
            <td class="py-3 font-semibold text-slate-900">$${grand.toFixed(2)}</td>
            <td class="py-3">
              <button onclick="toggleStatus(${index})" class="px-2.5 py-1 rounded-full text-xs font-semibold ${badge}">
                ${inv.status}
              </button>
            </td>
            <td class="py-3 text-right space-x-2">
              <button onclick="viewInvoice(${index})" class="text-indigo-600 hover:underline text-xs font-semibold">View/PDF</button>
              <button onclick="deleteInvoice(${index})" class="text-rose-500 hover:underline text-xs">Delete</button>
            </td>
          </tr>`;
      });

      document.getElementById('totalBilled').textContent = `$${total.toFixed(2)}`;
      document.getElementById('paidRevenue').textContent = `$${paid.toFixed(2)}`;
      document.getElementById('pendingBalance').textContent = `$${pending.toFixed(2)}`;
      document.getElementById('invoiceCount').textContent = `${invoices.length} Invoices`;
    }

    document.getElementById('invoiceForm').addEventListener('submit', (e) => {
      e.preventDefault();
      const newInv = {
        id: 'INV-' + Math.floor(1000 + Math.random() * 9000),
        client: document.getElementById('clientName').value,
        email: document.getElementById('clientEmail').value,
        due: document.getElementById('dueDate').value,
        desc: document.getElementById('serviceDesc').value,
        qty: parseFloat(document.getElementById('qty').value),
        rate: parseFloat(document.getElementById('rate').value),
        tax: parseFloat(document.getElementById('tax').value || 0),
        status: 'Pending'
      };
      invoices.unshift(newInv);
      e.target.reset();
      saveAndRender();
    });

    function toggleStatus(idx) {
      invoices[idx].status = invoices[idx].status === 'Paid' ? 'Pending' : 'Paid';
      saveAndRender();
    }

    function deleteInvoice(idx) {
      invoices.splice(idx, 1);
      saveAndRender();
    }

    function viewInvoice(idx) {
      const inv = invoices[idx];
      const sub = inv.qty * inv.rate;
      const taxAmt = sub * (inv.tax / 100);
      const grand = sub + taxAmt;
      document.getElementById('modalInvId').textContent = inv.id;
      document.getElementById('modalClient').textContent = inv.client;
      document.getElementById('modalEmail').textContent = inv.email;
      document.getElementById('modalDue').textContent = inv.due;
      document.getElementById('modalDesc').textContent = inv.desc;
      document.getElementById('modalMeta').textContent = `${inv.qty} unit(s) @ $${inv.rate.toFixed(2)}`;
      document.getElementById('modalSubtotal').textContent = `$${sub.toFixed(2)}`;
      document.getElementById('modalTax').textContent = `$${taxAmt.toFixed(2)} (${inv.tax}%)`;
      document.getElementById('modalTotal').textContent = `$${grand.toFixed(2)}`;
      const statusEl = document.getElementById('modalStatus');
      statusEl.textContent = inv.status;
      statusEl.className = `px-2.5 py-1 rounded-full text-xs font-semibold ${inv.status === 'Paid' ? 'bg-emerald-100 text-emerald-800' : 'bg-amber-100 text-amber-800'}`;
      const modal = document.getElementById('printModal');
      modal.classList.remove('hidden');
      modal.classList.add('flex');
    }

    function closeModal() {
      const modal = document.getElementById('printModal');
      modal.classList.add('hidden');
      modal.classList.remove('flex');
    }

    saveAndRender();
  </script>
</body>
</html>