<!-- <?php include __DIR__ . '/../layout.php'; ?> -->
<div class="container">
    <div style="margin-bottom:10px;">
    <a class="btn btn-primary" href="index.php?controller=report&action=export_csv&type=monthwise&year=<?php echo $year; ?>&month=<?php echo $month ?? 'all'; ?>" class="btn">Download CSV</a>
</div>

    <h2>Month-wise Report (<?php echo $year; ?>)</h2>
    <!-- <form method="get" action="">
        <label>Select Year:</label>
        <input type="number" name="year" value="<?php echo $year; ?>" min="2000" max="2100">
        <button type="submit">Show</button>
    </form> -->
    <form method="get" action="index.php">
    <input type="hidden" name="controller" value="report">
    <input type="hidden" name="action" value="monthwise">
<div class="form-row filters">
    <div class="field">
    <label>Select Year:</label>
    <input type="number" name="year" value="<?php echo $year; ?>" min="2000" max="2100">
</div>
<div class="field">
    <label>Select Month:</label>
    <select name="month">
        <option value="all" <?php if(($month ?? 'all')=='all') echo 'selected'; ?>>All</option>
        <?php for($m=1; $m<=12; $m++): ?>
            <option value="<?php echo $m; ?>" <?php if(($month ?? 0)==$m) echo 'selected'; ?>>
                <?php echo date("F", mktime(0,0,0,$m,10)); ?>
            </option>
        <?php endfor; ?>
    </select>
        </div>
        <div style="align-self:end">
    <button type="submit" class="btn btn-primary">Show</button>
        </div>
        </div>
</form>

    <table class="table">
        <thead>
            <tr><th>Month</th><th>Income</th><th>Expense</th><th>Balance</th></tr>
        </thead>
        <tbody>
            <?php foreach($data as $row): ?>
            <tr>
                <td><?php echo date("F", mktime(0,0,0,$row['month'],10)); ?></td>
                <td><?php echo number_format($row['income'],2); ?></td>
                <td><?php echo number_format($row['expense'],2); ?></td>
                <td><?php echo number_format($row['balance'],2); ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<!-- <?php include __DIR__ . '/../layout/footer.php'; ?> -->
