{% extends "base.html" %}{% block title %}Sales Insights{% endblock %}{% block content %}
<div class="card p-4 shadow-sm mb-4"><h2>🧠 Sales Insights</h2><h4>Best Selling Items</h4><table class="table"><tr><th>Item</th><th>Sold Qty</th><th>Revenue</th><th>Cost</th><th>Gross Profit</th></tr>{% for i in top_items %}<tr><td>{{i.item_name}}</td><td>{{i.sold_qty}}</td><td>{{'%.2f'|format(i.revenue or 0)}}</td><td>{{'%.2f'|format(i.cost_total or 0)}}</td><td>{{'%.2f'|format(i.gross_profit or 0)}}</td></tr>{% endfor %}</table></div>
<div class="card p-4 shadow-sm"><h4>Low Margin Orders (&lt; 10%)</h4><table class="table"><tr><th>Order</th><th>Item</th><th>Sale</th><th>Cost</th><th>Profit</th><th>Suggestion</th></tr>{% for l in low_margin %}<tr><td>{{l.id}}</td><td>{{l.item_name}}</td><td>{{l.total_price}}</td><td>{{l.cost}}</td><td>{{l.profit}}</td><td>Check cost or increase selling price.</td></tr>{% else %}<tr><td colspan="6">No low margin orders found.</td></tr>{% endfor %}</table></div>
{% endblock %}
