<?php
/** PSI 采购订单打印正文 */
/** @var array $o @var array $items */
$amt = array_sum(array_map(fn($i) => (float)($i['amount'] ?? 0), $items));
?>
<h2>采购订单</h2>
<div class="sub"><?php echo e($o['order_no']); ?></div>
<div class="meta">
    <span><b>供应商：</b><?php echo e($o['supplier_name']); ?></span>
    <span><b>采购员：</b><?php echo e($o['salesman']); ?></span>
    <span><b>期望到货：</b><?php echo e($o['expected_at'] ?? '—'); ?></span>
    <span><b>下单：</b><?php echo e($o['created_at']); ?></span>
</div>
<table>
    <thead><tr><th>类型</th><th>名称</th><th>规格</th><th>单位</th><th>数量</th><th>单价</th><th>金额</th></tr></thead>
    <tbody>
    <?php foreach ($items as $it): ?>
        <tr>
            <td><?php echo $it['item_type'] === 'product' ? '成品' : '物料'; ?></td>
            <td><?php echo e($it['name']); ?></td>
            <td><?php echo e($it['spec']); ?></td>
            <td><?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>
    <tfoot><tr><th colspan="6" style="text-align:right">合计</th><th>¥<?php echo e(number_format($amt, 2)); ?></th></tr></tfoot>
</table>
<?php if ($o['remark']): ?><p style="font-size:13px;color:#374151;margin-top:10px"><b>备注：</b><?php echo e($o['remark']); ?></p><?php endif; ?>
<div class="sign"><span>制单：<?php echo e($o['salesman']); ?></span><span>供应商签字：____________</span></div>
