<!DOCTYPE html>
<html>
<head>
    <title>Laporan Buku Kas Produksi</title>
    <style>
        body { font-family: Arial, sans-serif; font-size: 12px; }
        table { width: 100%; border-collapse: collapse; }
        th, td { border: 1px solid #000; padding: 4px 6px; }
        th { background-color: #f0f0f0; text-align: center; }
        .txt-right { text-align: right; }
        .txt-center { text-align: center; }
        .header { margin-bottom: 20px; }
        .header h2 { margin: 0; }
    </style>
</head>
<body onload="window.print();">
    <div class="header">
        <h2 align="center">LAPORAN BUKU KAS PRODUKSI</h2>
        <h4 align="center"><?php echo $user->name; ?></h4>
        <p align="center">Periode: <?php echo date('d-m-Y', strtotime($date_1)); ?> s/d <?php echo date('d-m-Y', strtotime($date_2)); ?></p>
    </div>

    <table>
        <thead>
            <tr>
                <th width="5%">No</th>
                <th width="12%">Tanggal</th>
                <th width="18%">Item</th>
                <th width="25%">Keterangan</th>
                <th width="13%" class="txt-center">Debit (+)</th>
                <th width="13%" class="txt-center">Kredit (-)</th>
                <th width="14%" class="txt-center">Saldo</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td colspan="6" class="txt-right"><b>SALDO AWAL</b></td>
                <td class="txt-right"><b><?php echo number_format($opening_balance, 0, ',', '.'); ?></b></td>
            </tr>
            <?php
            $running = $opening_balance;
            $total_debit = 0;
            $total_credit = 0;
            $no = 0;
            foreach ($rows->result() as $row) {
                $running = $running + $row->debit - $row->credit;
                $total_debit += $row->debit;
                $total_credit += $row->credit;
                $no++;
            ?>
            <tr>
                <td class="txt-center"><?php echo $no; ?></td>
                <td class="txt-center"><?php echo date('d-m-Y', strtotime($row->transaction_date)); ?></td>
                <td><?php echo $row->item_name; ?></td>
                <td><?php echo $row->description; ?></td>
                <td class="txt-right"><?php echo $row->debit > 0 ? number_format($row->debit, 0, ',', '.') : ''; ?></td>
                <td class="txt-right"><?php echo $row->credit > 0 ? number_format($row->credit, 0, ',', '.') : ''; ?></td>
                <td class="txt-right"><?php echo number_format($running, 0, ',', '.'); ?></td>
            </tr>
            <?php } ?>
            <tr>
                <td colspan="4" class="txt-right"><b>TOTAL</b></td>
                <td class="txt-right"><b><?php echo number_format($total_debit, 0, ',', '.'); ?></b></td>
                <td class="txt-right"><b><?php echo number_format($total_credit, 0, ',', '.'); ?></b></td>
                <td class="txt-right"><b><?php echo number_format($opening_balance + $total_debit - $total_credit, 0, ',', '.'); ?></b></td>
            </tr>
        </tbody>
    </table>

    <br><br>
    <table width="100%">
        <tr>
            <td width="33%" align="center">Disetujui Oleh<br><br><br><br>(___________________)</td>
            <td width="33%" align="center">Diperiksa Oleh<br><br><br><br>(___________________)</td>
            <td width="33%" align="center">Produksi<br><br><br><br>(<?php echo $user->name; ?>)</td>
        </tr>
    </table>
</body>
</html>