@extends('admin.layouts.app')
@section('title','Advanced Reports')
@section('content')
<div class="page-shell">
    <div class="page-head"><div><h1 class="page-title">Advanced Reports</h1><div class="page-subtitle">Date-wise sales, purchase, profit, due and top products</div></div></div>
    <form class="card panel-tight row" method="GET"><div class="col"><label>From</label><input type="date" name="from" value="{{ $from }}"></div><div class="col"><label>To</label><input type="date" name="to" value="{{ $to }}"></div><div class="col actions"><button class="btn primary">Generate</button></div></form>
    <div class="grid-4">
        <div class="stat"><div class="k">Sales</div><div class="v">{{ number_format($summary['sales'],2) }}</div></div>
        <div class="stat"><div class="k">Purchase</div><div class="v">{{ number_format($summary['purchase'],2) }}</div></div>
        <div class="stat"><div class="k">Profit</div><div class="v">{{ number_format($summary['profit'],2) }}</div></div>
        <div class="stat"><div class="k">Expense</div><div class="v">{{ number_format($summary['expense'],2) }}</div></div>
    </div>
    <div class="grid-2">
        <div class="card panel-tight table-wrap"><h3>Top Selling Products</h3><table class="table"><thead><tr><th>Product</th><th>Qty</th><th>Amount</th></tr></thead><tbody>@forelse($topProducts as $item)<tr><td>{{ $item->product_name }}</td><td>{{ $item->qty }}</td><td>{{ number_format($item->amount,2) }}</td></tr>@empty<tr><td colspan="3">No data.</td></tr>@endforelse</tbody></table></div>
        <div class="card panel-tight table-wrap"><h3>Low Stock Alert</h3><table class="table"><thead><tr><th>Code</th><th>Product</th><th>Stock</th></tr></thead><tbody>@forelse($lowStock as $item)<tr><td>{{ $item->product_code }}</td><td>{{ $item->product_name }}</td><td>{{ $item->stock_quantity }}</td></tr>@empty<tr><td colspan="3">No low stock product.</td></tr>@endforelse</tbody></table></div>
    </div>
    <div class="card panel-tight table-wrap"><h3>Daily Sales</h3><table class="table"><thead><tr><th>Date</th><th>Amount</th></tr></thead><tbody>@forelse($dailySales as $item)<tr><td>{{ $item->sale_date }}</td><td>{{ number_format($item->amount,2) }}</td></tr>@empty<tr><td colspan="2">No data.</td></tr>@endforelse</tbody></table></div>
</div>
@endsection
