@extends('layouts.admin') @section('title', 'Confirmar pedido') @section('content') @php $fmt = static function ($n, int $maxDec = 4): string { $n = (float) $n; if (abs($n - round($n)) < 0.00005) { return number_format(round($n), 0); } return rtrim(rtrim(number_format($n, $maxDec, '.', ''), '0'), '.') ?: '0'; }; @endphp

Confirmar {{ $order->number }}

Revise los lotes. Al confirmar se bloqueará y validará nuevamente el stock disponible. @if($order->items->contains(fn ($i) => $i->enteredAsPacks()))
Las cantidades se muestran en cajas/empaque cuando el pedido se vendió así; el inventario se reserva en unidades internas.
@endif
@csrf @foreach($order->items as $item) @php $asPacks = $item->enteredAsPacks(); $perPack = max(1, (int) ($item->units_per_pack ?: 1)); $packName = $item->pack_name ?: ($item->product?->packLabel() ?: 'caja'); $unitName = $item->product?->unitLabel() ?: 'und'; $salePrice = $asPacks ? (float) ($item->price_entered ?? bcmul((string) $item->unit_sale_price, (string) $perPack, 4)) : (float) $item->unit_sale_price; $priceSuffix = $asPacks ? '/ '.$packName : '/ '.$unitName; @endphp

{{ $item->product->name }}

Pedido: {{ $item->quantityLabel() }} · ${{ number_format($salePrice, 4) }} {{ $priceSuffix }} @if($asPacks) ({{ $fmt($item->quantity) }} {{ $unitName }} internas) @endif

@foreach($suggestions[$item->id] as $i => $row) @php $availBase = (float) $row['available']; $qtyBase = (float) $row['quantity']; $unitCost = (float) $row['unit_cost']; $refUnit = (float) $row['reference_sale_price']; if ($asPacks) { $availShow = $availBase / $perPack; $qtyShow = $qtyBase / $perPack; $costShow = $unitCost * $perPack; $refShow = $refUnit * $perPack; $margin = $salePrice - $costShow; $maxShow = $availShow; } else { $availShow = $availBase; $qtyShow = $qtyBase; $costShow = $unitCost; $refShow = $refUnit; $margin = (float) $item->unit_sale_price - $unitCost; $maxShow = $availBase; } @endphp @endforeach
Lote Disponible Costo {{ $asPacks ? $packName : $unitName }} Precio ref. Asignar ({{ $asPacks ? $packName : $unitName }}) Margen
{{ $row['code'] }} {{ $fmt($availShow) }} {{ $asPacks ? $packName.($availShow == 1 ? '' : 's') : $unitName }} @if($asPacks)
{{ $fmt($availBase) }} {{ $unitName }}
@endif
${{ number_format($costShow, 4) }} ${{ number_format($refShow, 4) }} @if($asPacks)
Se reservará en {{ $unitName }}
@endif
${{ number_format($margin, 4) }}
por {{ $asPacks ? $packName : $unitName }}
@endforeach @if($errors->any())
{{ $errors->first() }}
@endif @if($order->wants_invoice && $billingEnabled && $canAutoInvoice) @if($billingIssuers->isEmpty())
Este pedido está marcado para facturar, pero no hay emisores configurados. Configure un emisor antes de confirmar.
@else @php $selectedBillingIssuerId = old( 'billing_issuer_id', $order->billing_issuer_id ?? $billingIssuers->firstWhere('is_default', true)?->id ?? $billingIssuers->first()?->id ); @endphp

Facturación al confirmar

Se emitirá la factura electrónica con el emisor seleccionado. Cada RUC usa su propio certificado y secuencial.

@endif @elseif($order->wants_invoice && $billingEnabled && ! $canAutoInvoice)
Este pedido solicita factura. Tras confirmar, un usuario con permiso de emisión podrá facturarlo manualmente.
@endif Volver
@endsection @push('scripts') @endpush