<?php
/** PSI 出库单详情 */
/** @var array $o @var array $items */
$obStatus = ['delivered' => ['label' => '已交付', 'cls' => 'tag-green'], 'partial' => ['label' => '部分交付', 'cls' => 'tag-amber']];
$s = $obStatus[$o['status']] ?? $obStatus['delivered'];
$amt = array_sum(array_map(fn($i) => (float)($i['amount'] ?? 0), $items));
?>
<div class="page-head">
    <div><h1>出库单详情</h1><div class="desc">出库单号 <?php echo e($o['order_no']); ?></div></div>
    <div style="display:flex;gap:10px">
        <a class="btn-ghost" href="<?php echo site_url('PSI/outbounds/print/' . $o['id']); ?>" target="_blank"><?php echo admin_icon('printer', 16); ?> 打印</a>
        <a class="btn-ghost" href="<?php echo site_url('PSI/outbounds'); ?>">← 返回</a>
    </div>
</div>

<div class="panel two-col">
    <table class="tbl">
        <tr><th>关联销售订单</th><td><?php echo $o['so_no'] ? e($o['so_no']) : '<span class="muted">—</span>'; ?></td></tr>
        <tr><th>客户</th><td><?php echo e($o['customer']); ?></td></tr>
        <tr><th>业务员</th><td><?php echo e($o['salesman']); ?></td></tr>
        <tr><th>仓库</th><td><?php echo e($o['warehouse']); ?></td></tr>
        <tr><th>状态</th><td><span class="tag-mini <?php echo $s['cls']; ?>"><?php echo $s['label']; ?></span></td></tr>
        <tr><th>出库日期</th><td><?php echo e($o['delivery_date'] ?? '—'); ?></td></tr>
        <tr><th>备注</th><td class="muted"><?php echo e($o['remark'] ?: '—'); ?></td></tr>
    </table>
</div>

<div class="panel">
    <div class="panel-bar"><h3>出库明细</h3><span class="muted">合计 ¥<?php echo e(number_format($amt, 2)); ?></span></div>
    <div class="table-wrap">
        <table class="tbl">
            <thead><tr><th>商品</th><th>规格</th><th>单位</th><th>数量</th><th>单价</th><th>金额</th></tr></thead>
            <tbody>
            <?php foreach ($items as $it): ?>
                <tr>
                    <td><?php echo e($it['name']); ?></td>
                    <td class="muted"><?php echo e($it['spec']); ?></td>
                    <td class="muted"><?php echo e($it['unit']); ?></td>
                    <td><?php echo e($it['qty']); ?></td>
                    <td>¥<?php echo e(number_format((float)($it['price'] ?? 0), 2)); ?></td>
                    <td>¥<?php echo e(number_format((float)($it['amount'] ?? 0), 2)); ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <div style="margin-top:16px;display:flex;gap:10px">
        <a class="btn-primary" href="<?php echo site_url('PSI/outbounds/edit/' . $o['id']); ?>">编辑</a>
    </div>
</div>
