@extends('layouts.app')

@section('content')
<!-- Background seluruh halaman -->
<div style="background-color: #e0e0e0; width: 100%; min-height: 100vh; border-radius: 15px; padding: 1rem;">

    <!-- Header -->
    <div style="background-color: #000; color: #fff; padding: 0.1rem; border-radius: 0.5rem;">
        <h1 class="m-0">Data Kas</h1>
    </div>

    <!-- Konten utama -->
    <div class="container mt-4">

        @if(session('success'))
            <div class="alert alert-success">{{ session('success') }}</div>
        @endif

        <div class="card p-4 border border-secondary" style="border-radius: 15px; background-color: #fff;">
            <div class="d-flex justify-content-between mb-3">
                <a href="{{ route('dashboard') }}" class="btn btn-secondary">Kembali</a>
            </div>

            <div class="table-responsive">
    <table class="table table-bordered table-hover mb-0">
        <thead class="table-dark text-center">
            <tr>
                <th>No</th>
                <th>Tanggal</th>
                <th>Nama Donatur</th>
                <th>Kategori</th>
                <th>Quantity</th>
                <th>Harga Satuan</th>
                <th>Jumlah</th>
                <th>Masuk</th>
                <th>Keluar</th>
                <th>Keterangan</th>
            </tr>
        </thead>
        <tbody>
            @php $no = 1; @endphp
            @forelse($data_kas as $item)
                <tr>
                    <td class="text-center">{{ $no++ }}</td>
                    <td>{{ \Carbon\Carbon::parse($item->tanggal)->format('d-m-Y') }}</td>
                    <td>{{ $item->nama }}</td>
                    <td class="text-center">{{ ucfirst($item->kategori) }}</td>
                    <td class="text-center">{{ $item->kategori === 'barang' ? $item->quantity : '-' }}</td>
                    <td class="text-end">{{ $item->kategori === 'barang' ? 'Rp ' . number_format($item->harga, 0, ',', '.') : '-' }}</td>
                    <td class="text-end">Rp {{ number_format($item->subtotal, 0, ',', '.') }}</td>
                    <td class="text-end">
                        {{ $item->jenis === 'masuk' ? 'Rp ' . number_format($item->subtotal, 0, ',', '.') : '-' }}
                    </td>
                    <td class="text-end">
                        {{ $item->jenis === 'keluar' ? 'Rp ' . number_format($item->subtotal, 0, ',', '.') : '-' }}
                    </td>
                    <td>{{ $item->keterangan ?? '-' }}</td>
                </tr>
            @empty
                <tr>
                    <td colspan="10" class="text-center">Belum ada data kas.</td>
                </tr>
            @endforelse
        </tbody>

        @if(count($data_kas) > 0)
        <tfoot>
            <tr class="table-success fw-bold">
                <td colspan="7" class="text-end">Total Masuk</td>
                <td class="text-end">Rp {{ number_format($total_pemasukan, 0, ',', '.') }}</td>
                <td colspan="2"></td>
            </tr>
            <tr class="table-danger fw-bold">
                <td colspan="8" class="text-end">Total Keluar</td>
                <td class="text-end">Rp {{ number_format($total_pengeluaran, 0, ',', '.') }}</td>
                <td></td>
            </tr>
            <tr class="table-primary fw-bold">
                <td colspan="7" class="text-end">Saldo Akhir</td>
                <td colspan="3" class="text-end">Rp {{ number_format($saldo_akhir, 0, ',', '.') }}</td>
            </tr>
        </tfoot>
        @endif
    </table>
</div>





        </div>
    </div>
</div>
@endsection
