@extends('layouts.master')
@section('title', 'Balance Sheet')

@section('content')
<div class="container-fluid py-3">
    <div class="d-flex justify-content-between align-items-center mb-3 no-print">
        <h4 class="mb-0">Balance Sheet</h4>
        <div class="d-flex gap-2">
            <button onclick="window.print()" class="btn btn-secondary btn-sm"><i class="fas fa-print me-1"></i> Print</button>
        </div>
    </div>

    <form method="GET" class="row g-2 mb-3 no-print">
        <div class="col-md-3">
            <label class="form-label mb-1">From Date</label>
            <input type="date" class="form-control" name="from_date" value="{{ $from }}">
        </div>
        <div class="col-md-3">
            <label class="form-label mb-1">To Date</label>
            <input type="date" class="form-control" name="to_date" value="{{ $to }}">
        </div>
        <div class="col-md-3 d-flex align-items-end">
            <button class="btn btn-primary">Run</button>
        </div>
    </form>

    <div class="card shadow-sm">
        <div class="card-body p-0">
            <div style="background:#4e73df;color:#fff;padding:12px 16px;font-weight:700;">
                {{ $companyName ?? 'Company' }} <span style="float:right;">Balance Sheet</span>
            </div>
            <div class="p-3">
                <table class="table table-bordered mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>Balance Sheet</th>
                            <th class="text-end">Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="table-primary"><td colspan="2"><strong>Assets</strong></td></tr>
                        @foreach($assets as $r)
                            <tr><td>{{ $r['name'] }}</td><td class="text-end">{{ number_format($r['value'], 2) }}</td></tr>
                        @endforeach
                        <tr class="table-secondary"><td><strong>Total Assets</strong></td><td class="text-end"><strong>{{ number_format($totalAssets, 2) }}</strong></td></tr>

                        <tr class="table-primary"><td colspan="2"><strong>Liabilities</strong></td></tr>
                        @foreach($liabilities as $r)
                            <tr><td>{{ $r['name'] }}</td><td class="text-end">{{ number_format($r['value'], 2) }}</td></tr>
                        @endforeach
                        <tr class="table-light"><td><strong>Total Liabilities</strong></td><td class="text-end"><strong>{{ number_format($totalLiabilities, 2) }}</strong></td></tr>

                        <tr class="table-primary"><td colspan="2"><strong>Owner's Equity</strong></td></tr>
                        @foreach($equity as $r)
                            <tr><td>{{ $r['name'] }}</td><td class="text-end">{{ number_format($r['value'], 2) }}</td></tr>
                        @endforeach
                        <tr class="table-light"><td><strong>Total Equity</strong></td><td class="text-end"><strong>{{ number_format($totalEquity, 2) }}</strong></td></tr>

                        <tr class="table-secondary"><td><strong>Total Liabilities and Owner's Equity</strong></td><td class="text-end"><strong>{{ number_format($totalLE, 2) }}</strong></td></tr>
                        @if(abs($totalAssets - $totalLE) > 0.01)
                            <tr class="table-warning"><td colspan="2"><strong>Warning:</strong> Balance Sheet does not balance.</td></tr>
                        @endif
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<style>
@media print {
    .no-print { display:none !important; }
    body { background:#fff !important; }
    .card { border:none !important; box-shadow:none !important; }
}
</style>
@endsection

