<?php
require __DIR__ . '/../layout/header.php';
require __DIR__ . '/../layout/sidebar.php';
?>

<div class="main">

    <div class="header">Kas Keluar</div>

    <!-- FORM -->
    <div class="card">

        <h3>Tambah Pengeluaran</h3>

        <form action="/membership/kas-keluar-store" method="POST" enctype="multipart/form-data">

            <div class="form-group">
                <input type="number" name="jumlah" placeholder="Jumlah (Rp)" required>
            </div>

            <div class="form-group">
                <input type="date" name="tanggal" required>
            </div>

            <div class="form-group">
                <select name="sumber_dana" required>
                    <option value="">-- Pilih Sumber Dana --</option>
                    <option value="iuran">Dari Iuran</option>
                    <option value="kas_vendor">Dari Kas Vendor</option>
                </select>
            </div>

            <div class="form-group">
                <textarea name="keterangan" placeholder="Keterangan"></textarea>
            </div>

            <div class="form-group">
                <input type="file" name="foto" accept="image/*">
            </div>

            <button class="btn btn-primary">Simpan</button>

        </form>

    </div>

    <!-- TABLE -->
    <div class="card" style="margin-top:20px;">

        <h3>Data Pengeluaran</h3>

        <table class="table">
            <thead>
                <tr>
                    <th>Tanggal</th>
                    <th>Jumlah</th>
                    <th>Sumber</th>
                    <th>Keterangan</th>
                    <th>Foto</th>
                    <th>Aksi</th>
                </tr>
            </thead>

            <tbody>
                <?php foreach ($data as $d): ?>
                <tr>
                    <td><?= $d['tanggal'] ?></td>
                    <td>Rp <?= number_format($d['jumlah']) ?></td>
                    <td>
                        <?= $d['sumber_dana'] == 'iuran' ? 'Iuran' : 'Kas Vendor' ?>
                    </td>
                    <td><?= $d['keterangan'] ?></td>

                    <td>
                        <?php if ($d['foto']): ?>
                            <a href="/membership/public/assets/uploads/<?= $d['foto'] ?>" target="_blank">
                                Lihat
                            </a>
                        <?php endif; ?>
                    </td>

                    <td>

                        <a href="/membership/kas-keluar-edit?id=<?= $d['id'] ?>" 
                           class="btn btn-warning">
                           Edit
                        </a>
                    
                        <a href="/membership/kas-keluar-delete?id=<?= $d['id'] ?>" 
                           class="btn btn-danger"
                           onclick="return confirm('Hapus data?')">
                           Hapus
                        </a>
                    
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>

    </div>

</div>

<?php require __DIR__ . '/../layout/footer.php'; ?>