@extends('layouts.admin')

@section('title', 'Monthly Ledger Summary')

@section('content')
<div class="admin-page-header d-flex justify-content-between align-items-center mb-4">
    <div>
        <h1>Monthly Ledger Summary</h1>
        <p class="admin-page-subtitle mb-0">Day-wise totals for {{ $month }}</p>
    </div>
    <a href="{{ route('admin.reports.day-ledger', ['date' => \Carbon\Carbon::parse($month . '-01')->toDateString()]) }}" class="btn btn-outline-secondary">
        Back to Day Ledger
    </a>
</div>

<div class="admin-card mb-4">
    <div class="card-body">
        <form method="GET" class="row g-3">
            <div class="col-md-3">
                <label class="admin-form-label">Month</label>
                <input type="month" name="month" class="admin-form-control form-control" value="{{ $month }}" required>
            </div>
            <div class="col-md-3 d-flex align-items-end">
                <button type="submit" class="admin-btn-primary">Load</button>
            </div>
        </form>
    </div>
</div>

<div class="admin-card">
    <div class="card-body">
        <div class="table-responsive">
            <table class="admin-table table table-hover">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th class="text-end">Opening (Cash)</th>
                        <th class="text-end">Sales</th>
                        <th class="text-end">Collection</th>
                        <th class="text-end">Expense</th>
                        <th class="text-end">Refund</th>
                        <th class="text-end">Closing (Cash)</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($rows as $row)
                        <tr>
                            <td>{{ \Carbon\Carbon::parse($row->date)->toDateString() }}</td>
                            <td class="text-end">Rs {{ number_format((float) $row->opening_balance, 2) }}</td>
                            <td class="text-end">Rs {{ number_format((float) $row->total_sales, 2) }}</td>
                            <td class="text-end">Rs {{ number_format((float) $row->total_collection, 2) }}</td>
                            <td class="text-end">Rs {{ number_format((float) $row->total_expense, 2) }}</td>
                            <td class="text-end">Rs {{ number_format((float) $row->total_refund, 2) }}</td>
                            <td class="text-end fw-semibold">Rs {{ number_format((float) $row->closing_balance, 2) }}</td>
                            <td>{{ strtoupper($row->status) }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="8" class="text-center text-muted py-3">No data found</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
