<?php
/** PSI 采购入库列表 */
?>
<div class="page-head">
    <h1>采购入库</h1>
    <a class="btn-primary" href="<?php echo site_url('PSI/purchases/create'); ?>">+ 新增采购</a>
</div>
<div class="panel">
    <p class="muted">提交采购单后系统自动增加对应物料/成品库存，并写入库存流水。</p>
    <table class="tbl">
        <thead><tr><th>单号</th><th>供应商</th><th>类型</th><th>批次/缸号</th><th>数量</th><th>单价</th><th>金额</th><th>预计到货</th><th>日期</th><th>操作</th></tr></thead>
        <tbody>
        <?php foreach ($purchases as $p): ?>
            <tr>
                <td><?php echo e($p['order_no']); ?></td>
                <td><?php echo e($smap[$p['supplier_id']] ?? ''); ?></td>
                <td><?php echo $p['item_type'] === 'product' ? '成品' : '物料'; ?></td>
                <td><?php echo e($p['batch_no'] ?? ''); ?></td>
                <td><?php echo e((float)($p['qty'] ?? 0)); ?></td>
                <td>¥<?php echo e(number_format((float)($p['price'] ?? 0), 2)); ?></td>
                <td>¥<?php echo e(number_format((float)($p['amount'] ?? 0), 2)); ?></td>
                <td><?php echo e($p['expected_at'] ?? ''); ?></td>
                <td><?php echo e($p['created_at'] ?? ''); ?></td>
                <td class="row-actions">
                    <a href="<?php echo site_url('PSI/purchases/destroy/' . $p['id']); ?>" data-confirm="删除不会回滚库存，确认？">删除</a>
                </td>
            </tr>
        <?php endforeach; ?>
        <?php if (empty($purchases)): ?><tr><td colspan="10" class="muted">暂无采购记录</td></tr><?php endif; ?>
        </tbody>
    </table>
</div>
