<h5 class="h6">{{ __('procurement.po.lines') }}</h5>
<x-ui.table.table :columns="[
    ['label' => __('inventory.items.fields.sku')],
    ['label' => __('procurement.po.ordered')],
    ['label' => __('procurement.po.posted_received')],
    ['label' => __('procurement.po.remaining')],
]">
    @foreach ($purchaseOrder->items as $line)
        @php
            $ordered = (string) $line->quantity_ordered;
            $posted = (string) $line->quantity_received_posted;
            $remaining = function_exists('bcsub') ? bcsub($ordered, $posted, 4) : (string) round((float) $ordered - (float) $posted, 4);
        @endphp
        <x-ui.table.row>
            <td>{{ $line->inventoryItem?->sku ?? '—' }}</td>
            <td>{{ $ordered }}</td>
            <td>{{ $posted }}</td>
            <td>
                {{ $remaining }}
                @if ((float) $remaining > 0 && (float) $posted > 0)
                    <x-ui.operational.status-badge
                        class="ms-1"
                        :label="__('procurement.po.partial')"
                        variant="warning"
                    />
                @endif
            </td>
        </x-ui.table.row>
    @endforeach
</x-ui.table.table>

@can('createReceipt', $purchaseOrder)
    <div class="card border mt-4" id="operational-receive">
        <div class="card-header fw-semibold small">{{ __('procurement.po.new_receipt') }}</div>
        <div class="card-body">
            <form method="post" action="{{ route('procurement.purchase-orders.goods-receipts.store', $purchaseOrder) }}" class="row g-2 align-items-end">
                @csrf
                <div class="col-md-8">
                    <x-ui.form.search-select
                        name="warehouse_id"
                        lookup="warehouses"
                        :label="__('procurement.po.warehouse')"
                        :options="collect($warehouseChoices)->mapWithKeys(fn ($wh) => [$wh->id => $wh->name.' ('.$wh->code.')'])->all()"
                        :placeholder="__('common.select')"
                        class="form-select-sm"
                        required
                    />
                </div>
                <div class="col-md-4">
                    <button type="submit" class="btn btn-primary btn-sm w-100">{{ __('procurement.po.new_receipt') }}</button>
                </div>
            </form>
        </div>
    </div>
@endcan
