<?php
$receipt  = $receipt ?? [];
$orders   = $orders ?? [];
$isEdit   = ! empty($receipt['id']);
?>
<div class="enterprise-settings-fields">
    <div class="enterprise-field">
        <label class="enterprise-field-label">Purchase Order <span class="text-danger">*</span></label>
        <select name="purchase_order_id" class="form-select" required>
            <option value="">— Select PO —</option>
            <?php foreach ($orders as $o): ?>
                <option value="<?= $o['id'] ?>" <?= (string) old('purchase_order_id', $receipt['purchase_order_id'] ?? '') === (string) $o['id'] ? 'selected' : '' ?>>
                    <?= esc($o['number']) ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="enterprise-field">
        <label class="enterprise-field-label">Receipt Date <span class="text-danger">*</span></label>
        <input type="date" name="receipt_date" class="form-control" required
               value="<?= esc(old('receipt_date', $receipt['receipt_date'] ?? date('Y-m-d'))) ?>">
    </div>
    <div class="enterprise-field" style="grid-column: 1 / -1;">
        <label class="enterprise-field-label">Notes</label>
        <textarea name="notes" class="form-control" rows="3"><?= esc(old('notes', $receipt['notes'] ?? '')) ?></textarea>
    </div>
    <?= $this->include('Modules\Sale\Views\partials\document_lines', [
        'lines' => $lines ?? [],
        'mode'  => 'delivery',
    ]) ?>
</div>
