@extends('backEnd.layouts.master')
@section('title', 'Monthly Expense Summary')
@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="page-title-box">
                <h4 class="page-title">Monthly Expense Summary ({{ date("F", mktime(0, 0, 0, $month, 10)) }} {{ $year }})</h4>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-4">
            <div class="card widget-flat bg-danger text-white">
                <div class="card-body">
                    <h5 class="fw-normal mt-0">Monthly Total Expense</h5>
                    <h3 class="mt-3 mb-3">৳{{ number_format($monthlyTotal) }}</h3>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-xl-8">
            <div class="card">
                <div class="card-body">
                    <h4 class="header-title mb-4">Detailed Expenses</h4>
                    <div class="table-responsive">
                        <table class="table table-hover table-centered mb-0">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Category</th>
                                    <th>Title</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($data as $expense)
                                <tr>
                                    <td>{{ date('d M, Y', strtotime($expense->expense_date)) }}</td>
                                    <td><span class="badge bg-soft-info text-info">{{ $expense->expense_category }}</span></td>
                                    <td>{{ $expense->expense_title }}</td>
                                    <td>৳{{ number_format($expense->amount) }}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xl-4">
            <div class="card">
                <div class="card-body">
                    <h4 class="header-title mb-4">Category Summary</h4>
                    <div class="table-responsive">
                        <table class="table table-sm">
                            <thead>
                                <tr>
                                    <th>Category</th>
                                    <th>Total</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($categorySummary as $cat => $total)
                                <tr>
                                    <td>{{ $cat }}</td>
                                    <td>৳{{ number_format($total) }}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
