<div class="row">
    <div class="col-sm-12">
        <div class="page-title-box"><h2 class="page-title">Return to Warehouse</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_warehouse_return" class="btn btn-primary mb-3">+ Create Return</a>
                <div class="table-responsive">
                    <table id="example" class="display table table-hover table-condensed" cellspacing="0" width="100%">
                        <thead><tr><th>#</th><th>Return ID</th><th>From</th><th>To</th><th>Amount</th><th>Status</th><th>Created</th><th>Action</th></tr></thead>
                        <tbody>
                        <?php $x=1; foreach($returns as $r): $d=$r["Inventory_return"]; ?>
                            <tr>
                                <td><?= $x++ ?></td><td><?= h($d["return_id"]) ?></td>
                                <td><?= h($d["from_location_name"]) ?></td><td><?= h($d["to_location_name"]) ?></td>
                                <td><?= number_format($d["total_amount"],2) ?></td>
                                <td><?php $s=$d["status"]; echo $s==1?"<span class=\"badge badge-warning\">Pending</span>":($s==2?"<span class=\"badge badge-success\">Approved</span>":"$s"); ?></td>
                                <td><?= date("d-m-Y", strtotime($d["created"])) ?></td>
                                <td>
                                    <a href="<?= $this->base ?>/dashboard/view_warehouse_return/<?= $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_warehouse_return/<?= $d["id"] ?>" class="btn btn-sm btn-success" onclick="return confirm('Approve? Stock will be adjusted.')">Approve</a>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
