{% extends "base.html" %}
{% block title %}Returns & Refunds{% endblock %}
{% block content %}
<div class="card p-4 mb-4"><h2>🔁 Order Return / Replacement / Refund</h2><form method="post" class="row g-3"><div class="col-md-4"><label class="form-label">Order</label><select name="order_id" class="form-select" required>{% for o in recent_orders %}<option value="{{ o.id }}">{{ o.invoice_no or o.order_id or o.id }} - {{ o.item_name }} - {{ o.imei or o.contact1 }}</option>{% endfor %}</select></div><div class="col-md-2"><label class="form-label">Date</label><input type="date" name="return_date" class="form-control"></div><div class="col-md-2"><label class="form-label">Type</label><select name="return_type" class="form-select"><option>Return</option><option>Replacement</option><option>Refund</option></select></div><div class="col-md-2"><label class="form-label">Refund Amount</label><input type="number" step="0.01" name="refund_amount" class="form-control" value="0"></div><div class="col-md-2"><label class="form-label">Replacement Item</label><input name="replacement_item" class="form-control"></div><div class="col-md-12"><label class="form-label">Reason</label><textarea name="reason" class="form-control" required></textarea></div><div class="col-md-12"><button class="btn btn-success">Save Return</button></div></form></div>
<div class="card p-4"><h4>Return History</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><th>By</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><td>{{ r.created_by }}</td></tr>{% else %}<tr><td colspan="8" class="text-center text-muted">No return records</td></tr>{% endfor %}</tbody></table></div></div>
{% endblock %}
