<div class="row">
    <div class="col-sm-12">
        <div class="page-title-box">
            <h2 class="page-title">Credit / Debit Notes</h2>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-sm-12">
        <div class="card">
            <div class="card-body">
                <a href="<?= $this->base ?>/dashboard/create_credit_debit_note" class="btn btn-primary mb-3">+ Create Note</a>
                <div class="table-responsive">
                    <table id="example" class="display table table-hover table-condensed" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>#</th><th>Note ID</th><th>Type</th><th>Vendor</th>
                                <th>Location</th><th>Amount</th><th>Status</th>
                                <th>Created</th><th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php $x=1; foreach ($notes as $n): $d=$n["Credit_debit_note"]; ?>
                            <tr>
                                <td><?= $x++ ?></td>
                                <td><?= h($d["note_id"]) ?></td>
                                <td><span class="badge badge-<?= $d["type"]=="credit"?"success":"danger" ?>"><?= ucfirst($d["type"]) ?></span></td>
                                <td><?= h($d["vendor_name"]) ?></td>
                                <td><?= h($d["location_name"]) ?></td>
                                <td><?= number_format($d["total_amount"],2) ?></td>
                                <td>
                                    <?php if($d["status"]==1) echo "<span class=\"badge badge-warning\">Pending</span>";
                                    elseif($d["status"]==2) echo "<span class=\"badge badge-success\">Approved</span>";
                                    else echo "<span class=\"badge badge-secondary\">".$d["status"]."</span>"; ?>
                                </td>
                                <td><?= date("d-m-Y", strtotime($d["created"])) ?></td>
                                <td>
                                    <a href="<?= $this->base ?>/dashboard/view_credit_debit_note/<?= $d["id"] ?>" class="btn btn-sm btn-info">View</a>
                                    <?php if($d["status"]==1 && $this->Session->read("Auth.User.role")=="admin"): ?>
                                    <a href="<?= $this->base ?>/dashboard/approve_credit_debit_note/<?= $d["id"] ?>" class="btn btn-sm btn-success" onclick="return confirm('Approve this note?')">Approve</a>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
