<?php
/** PSI 销售出库列表 */
$chLabel = ['domestic' => '内销', 'export' => '外贸出口'];
?>
<div class="page-head">
    <h1>销售出库</h1>
    <a class="btn-primary" href="<?php echo site_url('PSI/sales/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></tr></thead>
        <tbody>
        <?php foreach ($sales as $s): ?>
            <tr>
                <td><?php echo e($s['order_no']); ?></td>
                <td><?php echo e($s['customer'] ?? ''); ?></td>
                <td><?php echo e($chLabel[$s['channel'] ?? ''] ?? $s['channel'] ?? ''); ?></td>
                <td><?php echo e($s['region'] ?? ''); ?></td>
                <td><?php echo e((float)($s['qty'] ?? 0)); ?></td>
                <td>¥<?php echo e(number_format((float)($s['price'] ?? 0), 2)); ?></td>
                <td>¥<?php echo e(number_format((float)($s['amount'] ?? 0), 2)); ?></td>
                <td><?php echo e($s['created_at'] ?? ''); ?></td>
                <td class="row-actions">
                    <a href="<?php echo site_url('PSI/sales/show/' . $s['id']); ?>">查看</a>
                    <a href="<?php echo site_url('PSI/sales/print/' . $s['id']); ?>" target="_blank">打印</a>
                    <a class="del" href="<?php echo site_url('PSI/sales/destroy/' . $s['id']); ?>" data-confirm="删除不会回滚库存，确认？">删除</a>
                </td>
            </tr>
        <?php endforeach; ?>
        <?php if (empty($sales)): ?><tr><td colspan="9" class="muted">暂无销售记录</td></tr><?php endif; ?>
        </tbody>
    </table>
</div>
