<!DOCTYPE html>
<html>
<head>
    <title>Laporan Neraca Laba Rugi</title>
    <style>
        body { font-family: sans-serif; font-size: 12px; }
        .header { text-align: center; margin-bottom: 20px; border-bottom: 2px solid #000; padding-bottom: 10px; }
        h1, h2, h3 { margin: 0; padding: 0; }
        .info { margin-bottom: 20px; }
        .info td { padding: 3px 0; }
        .table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
        .table th, .table td { border: 1px solid #ddd; padding: 8px; }
        .table th { background-color: #f4f4f4; text-align: left; }
        .text-right { text-align: right; }
        .text-center { text-align: center; }
        .bold { font-weight: bold; }
        .text-success { color: green; }
        .text-danger { color: red; }
        .bg-light { background-color: #f9f9f9; }
        .op-row td { padding-left: 20px; font-style: italic; color: #555; }
    </style>
</head>
<body>

    <div class="header">
        <h1>Warkop Cak Imin</h1>
        <h2>Laporan Neraca Laba Rugi</h2>
    </div>

    <table class="info">
        <tr>
            <td width="100"><b>Cabang</b></td>
            <td>: {{ $branch }}</td>
        </tr>
        <tr>
            <td><b>Periode</b></td>
            <td>: 
                @if($month && $year)
                    {{ date('F', mktime(0, 0, 0, $month, 1)) }} {{ $year }}
                @elseif($year)
                    Tahun {{ $year }}
                @elseif($month)
                    Bulan {{ date('F', mktime(0, 0, 0, $month, 1)) }} (Semua Tahun)
                @else
                    Semua Waktu (All Time)
                @endif
            </td>
        </tr>
        <tr>
            <td><b>Tanggal Cetak</b></td>
            <td>: {{ date('d M Y H:i') }}</td>
        </tr>
    </table>

    <table class="table">
        <thead>
            <tr>
                <th>Keterangan</th>
                <th class="text-right" width="30%">Jumlah (Rp)</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Total Penjualan (Pendapatan)</td>
                <td class="text-right text-success">+ {{ number_format($penjualan, 0, ',', '.') }}</td>
            </tr>
            <tr>
                <td>Total Pembelian (Harga Pokok / HPP)</td>
                <td class="text-right text-danger">- {{ number_format($pembelian, 0, ',', '.') }}</td>
            </tr>
            <tr class="bg-light">
                <td class="bold">Laba Kotor</td>
                <td class="text-right bold">{{ number_format($laba_kotor, 0, ',', '.') }}</td>
            </tr>
            
            <tr>
                <td colspan="2" class="bold">Biaya Operasional:</td>
            </tr>
            @forelse($operational as $op)
            <tr class="op-row">
                <td>- {{ $op->label }} @if($branch == 'Total Gabungan') ({{ $op->branch }}) @endif</td>
                <td class="text-right text-danger">- {{ number_format($op->amount, 0, ',', '.') }}</td>
            </tr>
            @empty
            <tr>
                <td colspan="2" class="text-center"><i>Tidak ada biaya operasional tercatat pada periode ini.</i></td>
            </tr>
            @endforelse
            
            <tr class="bg-light">
                <td class="bold">Total Biaya Operasional</td>
                <td class="text-right text-danger bold">- {{ number_format($total_operational, 0, ',', '.') }}</td>
            </tr>

            <tr>
                <td class="bold" style="font-size: 14px; text-transform: uppercase;">Laba Bersih</td>
                <td class="text-right bold" style="font-size: 14px;">{{ number_format($laba_bersih, 0, ',', '.') }}</td>
            </tr>
        </tbody>
    </table>

    <div style="margin-top: 50px; text-align: right;">
        <p>Disahkan Oleh,</p>
        <br><br><br>
        <p><b>{{ auth()->user()->name ?? 'Admin' }}</b></p>
    </div>

</body>
</html>
