{% extends "base.html" %}
{% block title %}Global Search{% endblock %}
{% block content %}
<style>.card{border-radius:14px;box-shadow:0 4px 10px rgba(0,0,0,.08);margin-bottom:1.5rem}.badge{font-size:.8rem}</style>
<div class="card p-4">
  <h2>🔍 Global Search</h2>
  <p class="text-muted">Search phone number, IMEI, serial, invoice number, order ID, item name, or TRCSL reference.</p>
  <form method="get" class="row g-2">
    <div class="col-md-10"><input name="q" class="form-control form-control-lg" value="{{ q }}" placeholder="Example: phone / IMEI / invoice / order ID"></div>
    <div class="col-md-2"><button class="btn btn-primary btn-lg w-100">Search</button></div>
  </form>
</div>
{% if q %}
<div class="card p-4"><h4>Orders</h4><div class="table-responsive"><table class="table table-striped"><thead><tr><th>Invoice</th><th>Date</th><th>Item</th><th>Phone</th><th>IMEI</th><th>Amount</th><th>Invoice</th></tr></thead><tbody>{% for o in orders %}<tr><td>{{ o.invoice_no }}</td><td>{{ o.order_date }}</td><td>{{ o.item_name }}</td><td>{{ o.contact1 }}</td><td>{{ o.imei }}</td><td>Rs. {{ "{:,.2f}".format(o.cash_received or 0) }}</td><td><a class="btn btn-sm btn-outline-primary" href="{{ url_for('invoice', order_id=o.id) }}">Print</a></td></tr>{% else %}<tr><td colspan="7" class="text-center text-muted">No orders found</td></tr>{% endfor %}</tbody></table></div></div>
<div class="card p-4"><h4>IMEI / Warranty Devices</h4><div class="table-responsive"><table class="table table-striped"><thead><tr><th>IMEI</th><th>Serial</th><th>Item</th><th>Status</th><th>Product Warranty</th><th>Battery Warranty</th><th>TRCSL</th></tr></thead><tbody>{% for d in devices %}<tr><td>{{ d.imei }}</td><td>{{ d.serial }}</td><td>{{ d.item_name }}</td><td><span class="badge bg-info">{{ d.status }}</span></td><td>{{ d.product_warranty_expiry }}</td><td>{{ d.battery_warranty_expiry }}</td><td>{{ d.trcsl_status }}</td></tr>{% else %}<tr><td colspan="7" class="text-center text-muted">No devices found</td></tr>{% endfor %}</tbody></table></div></div>
<div class="card p-4"><h4>Returns / Refunds</h4><div class="table-responsive"><table class="table table-striped"><thead><tr><th>Date</th><th>Invoice</th><th>Item</th><th>IMEI</th><th>Type</th><th>Refund</th><th>Reason</th></tr></thead><tbody>{% for r in returns %}<tr><td>{{ r.return_date }}</td><td>{{ r.invoice_no }}</td><td>{{ r.item_name }}</td><td>{{ r.imei }}</td><td>{{ r.return_type }}</td><td>Rs. {{ "{:,.2f}".format(r.refund_amount or 0) }}</td><td>{{ r.reason }}</td></tr>{% else %}<tr><td colspan="7" class="text-center text-muted">No returns found</td></tr>{% endfor %}</tbody></table></div></div>
{% endif %}
{% endblock %}
