<?php $__env->startSection('title', 'Recibir Orden de Compra | Veltrix v2'); ?>

<?php $__env->startSection('content'); ?>
    <div class="container py-4">
        <div class="d-flex justify-content-between align-items-center mb-3 flex-wrap gap-2">
            <h1 class="h4 mb-0">Recepcion de orden <?php echo e($orden->numero); ?></h1>
            <a href="<?php echo e(route('compras.ordenes.index')); ?>" class="btn btn-outline-secondary">Volver a ordenes</a>
        </div>

        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($errors->any()): ?>
            <div class="alert alert-danger">
                <?php echo e($errors->first()); ?>

            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

        <div class="row g-3 mb-4">
            <div class="col-12 col-md-4">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body">
                        <h2 class="h6">Proveedor</h2>
                        <div><?php echo e($orden->proveedor?->nombre ?? 'N/A'); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-12 col-md-4">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body">
                        <h2 class="h6">Sucursal</h2>
                        <div><?php echo e($orden->sucursal?->nombre ?? 'General'); ?></div>
                    </div>
                </div>
            </div>
            <div class="col-12 col-md-4">
                <div class="card border-0 shadow-sm h-100">
                    <div class="card-body">
                        <h2 class="h6">Estado</h2>
                        <div class="text-capitalize"><?php echo e($orden->estado); ?></div>
                    </div>
                </div>
            </div>
        </div>

        <div class="card border-0 shadow-sm">
            <div class="card-body">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($orden->estado === 'anulada'): ?>
                    <div class="alert alert-warning mb-0">Esta orden esta anulada y no admite recepcion.</div>
                <?php elseif($orden->estado === 'completa'): ?>
                    <div class="alert alert-success mb-0">Esta orden ya fue recibida completamente.</div>
                <?php else: ?>
                    <form action="<?php echo e(route('compras.ordenes.receive.store', $orden)); ?>" method="POST">
                        <?php echo csrf_field(); ?>

                        <div class="row g-3 mb-4">
                            <div class="col-12 col-md-4">
                                <label class="form-label" for="numero_recepcion">Numero recepcion (opcional)</label>
                                <input class="form-control" id="numero_recepcion" name="numero_recepcion" maxlength="80" value="<?php echo e(old('numero_recepcion')); ?>">
                            </div>
                            <div class="col-12 col-md-4">
                                <label class="form-label" for="fecha_recepcion">Fecha recepcion</label>
                                <input class="form-control" id="fecha_recepcion" name="fecha_recepcion" type="datetime-local" value="<?php echo e(old('fecha_recepcion', now()->format('Y-m-d\TH:i'))); ?>" required>
                            </div>
                            <div class="col-12 col-md-4">
                                <label class="form-label" for="observacion">Observacion</label>
                                <input class="form-control" id="observacion" name="observacion" value="<?php echo e(old('observacion')); ?>">
                            </div>
                        </div>

                        <div class="table-responsive">
                            <table class="table align-middle mb-0">
                                <thead>
                                    <tr>
                                        <th>Producto</th>
                                        <th>Cantidad ordenada</th>
                                        <th>Recibida</th>
                                        <th>Pendiente</th>
                                        <th>Costo unit.</th>
                                        <th>Cantidad a recibir</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $orden->detalles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $detalle): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                                        <?php
                                            $pending = (float) ($lineasPendientes[(string) $detalle->id] ?? 0);
                                        ?>
                                        <tr>
                                            <td><?php echo e($detalle->producto?->nombre ?? 'N/A'); ?></td>
                                            <td><?php echo e(number_format((float) $detalle->cantidad, 2)); ?></td>
                                            <td><?php echo e(number_format((float) $detalle->cantidad_recibida, 2)); ?></td>
                                            <td><?php echo e(number_format($pending, 2)); ?></td>
                                            <td><?php echo e(number_format((float) $detalle->costo_unitario, 2)); ?></td>
                                            <td style="min-width: 180px;">
                                                <input
                                                    class="form-control"
                                                    type="number"
                                                    step="0.01"
                                                    min="0"
                                                    max="<?php echo e($pending); ?>"
                                                    name="lineas[<?php echo e($detalle->id); ?>]"
                                                    value="<?php echo e(old('lineas.'.$detalle->id, $pending > 0 ? $pending : 0)); ?>"
                                                    <?php if($pending <= 0): echo 'disabled'; endif; ?>
                                                >
                                            </td>
                                        </tr>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                                </tbody>
                            </table>
                        </div>

                        <div class="mt-4">
                            <button class="btn btn-primary">Registrar recepcion y entrada a inventario</button>
                        </div>
                    </form>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/veltrix-v2/resources/views/modules/compras/ordenes/receive.blade.php ENDPATH**/ ?>