<h1 class="h3 mb-4">Create Bill</h1>
<form method="post" action="<%= url('/invoices') %>" class="card p-4">
  <input type="hidden" id="defaultHsnValue" value="<%= settings.default_hsn || '' %>">
  <input type="hidden" name="seller_state_code" value="<%= settings.state_code %>">
  <input type="hidden" name="settings_cgst" value="<%= settings.cgst_percent %>">
  <input type="hidden" name="settings_sgst" value="<%= settings.sgst_percent %>">
  <input type="hidden" name="settings_igst" value="<%= settings.igst_percent %>">
  <div class="row g-3 mb-4">
    <div class="col-md-3"><label class="form-label">Invoice No</label><input class="form-control" value="<%= invoiceNumber %>" disabled></div>
    <div class="col-md-3"><label class="form-label required">Invoice Date</label><input type="date" name="invoice_date" class="form-control" value="<%= new Date().toISOString().slice(0,10) %>" required></div>
    <div class="col-md-3"><label class="form-label">Payment Mode</label><select name="payment_mode" class="form-select"><option>Cash</option><option>UPI</option><option>Bank Transfer</option><option>Credit</option></select></div>
    <div class="col-md-3"><label class="form-label">Destination</label><input name="destination" class="form-control"></div>
    <div class="col-md-3"><label class="form-label">Delivery Note</label><input name="delivery_note" class="form-control"></div>
    <div class="col-md-3"><label class="form-label">Buyer Order No</label><input name="buyer_order_no" class="form-control"></div>
    <div class="col-md-3"><label class="form-label">Dispatch Doc No</label><input name="dispatch_doc_no" class="form-control"></div>
    <div class="col-md-3"><label class="form-label">Delivery Date</label><input type="date" name="delivery_date" class="form-control"></div>
    <div class="col-12"><label class="form-label">Terms of Delivery</label><input name="terms_of_delivery" class="form-control"></div>
  </div>
  <div class="row g-3 mb-4">
    <div class="col-lg-6"><h2 class="h5">Buyer</h2><div class="row g-2"><div class="col-12"><label class="form-label required">Customer Name</label><input name="customer_name" class="form-control" required></div><div class="col-12"><label class="form-label">Address</label><textarea name="customer_address" class="form-control" rows="3"></textarea></div><div class="col-md-6"><label class="form-label">Phone</label><input name="customer_phone" class="form-control"></div><div class="col-md-6"><label class="form-label">Email</label><input name="customer_email" class="form-control"></div><div class="col-md-6"><label class="form-label">GSTIN/UIN</label><input name="customer_gstin" class="form-control"></div><div class="col-md-6"><label class="form-label">State</label><div class="input-group"><input name="customer_state_name" class="form-control" value="Kerala"><input name="customer_state_code" class="form-control calc" value="32"></div></div></div></div>
    <div class="col-lg-6"><h2 class="h5">Consignee</h2><div class="form-check mb-2"><input type="checkbox" class="form-check-input" id="same_as_buyer" name="same_as_buyer" checked><label for="same_as_buyer" class="form-check-label">Same as buyer</label></div><div id="consigneeFields" class="row g-2 d-none"><div class="col-12"><label class="form-label">Consignee Name</label><input name="consignee_name" class="form-control"></div><div class="col-12"><label class="form-label">Address</label><textarea name="consignee_address" class="form-control" rows="3"></textarea></div><div class="col-md-6"><label class="form-label">GSTIN/UIN</label><input name="consignee_gstin" class="form-control"></div><div class="col-md-6"><label class="form-label">State</label><div class="input-group"><input name="consignee_state_name" class="form-control"><input name="consignee_state_code" class="form-control"></div></div></div></div>
  </div>
  <h2 class="h5">Items</h2>
  <div class="table-responsive mb-3"><table class="table table-bordered align-middle"><thead><tr><th>#</th><th>Description</th><th>Paper Type</th><th>HSN</th><th>Qty</th><th>Rate</th><th>Disc %</th><th class="text-end">Taxable</th><th class="text-end">Line Total</th><th></th></tr></thead><tbody id="itemsBody"><tr><td class="row-index"></td><td><input name="description" class="form-control" value="Tissue Paper" required></td><td><select name="paper_type" class="form-select" required><option>Soft</option><option>Semi Soft</option><option>Hard</option></select></td><td><input name="hsn_code" class="form-control" value="<%= settings.default_hsn || '' %>"></td><td><input name="quantity" type="number" step="0.001" min="0" class="form-control calc" required></td><td><input name="rate" type="number" step="0.01" min="0" class="form-control calc" required></td><td><input name="discount_percent" type="number" step="0.01" min="0" value="0" class="form-control calc"></td><td class="line-taxable text-end">0.00</td><td class="line-total text-end">0.00</td><td><button type="button" class="btn btn-sm btn-outline-danger remove-row">×</button></td></tr></tbody></table></div>
  <button type="button" id="addRow" class="btn btn-outline-primary mb-4">Add Item</button>
  <div class="row"><div class="col-lg-7"><h2 class="h5">Invoice Display</h2><div class="form-check"><input class="form-check-input" type="checkbox" name="show_logo" checked><label class="form-check-label">Show logo</label></div><div class="form-check"><input class="form-check-input" type="checkbox" name="show_signature" checked><label class="form-check-label">Show signature</label></div><div class="form-check"><input class="form-check-input" type="checkbox" name="show_seal" checked><label class="form-check-label">Show seal</label></div></div><div class="col-lg-5"><div class="card bg-light p-3"><div class="d-flex justify-content-between"><span>Taxable</span><strong>₹<span id="taxablePreview">0.00</span></strong></div><div class="d-flex justify-content-between"><span>CGST</span><strong>₹<span id="cgstPreview">0.00</span></strong></div><div class="d-flex justify-content-between"><span>SGST</span><strong>₹<span id="sgstPreview">0.00</span></strong></div><div class="d-flex justify-content-between"><span>IGST</span><strong>₹<span id="igstPreview">0.00</span></strong></div><div class="d-flex justify-content-between"><span>Round Off</span><strong>₹<span id="roundPreview">0.00</span></strong></div><hr><div class="d-flex justify-content-between h4"><span>Total</span><strong>₹<span id="grandPreview">0.00</span></strong></div></div></div></div>
  <div class="mt-4"><button class="btn btn-primary btn-lg">Save Bill</button></div>
</form>
<script src="<%= url('/public/js/invoice-form.js') %>"></script>
