@extends('layouts.app') @section('title', 'Confirmar Venta con Descuentos') @section('content')

Confirmar Venta

@if(session('error'))
{{ session('error') }}
@endif @php // ¡Asegúrate de que este valor SIEMPRE venga del request, nunca 'No seleccionado'! $metodoPagoSeleccionado = $metodoPagoSeleccionado ?? ''; $pagaCon = $pagaCon ?? null; $vuelto = ($metodoPagoSeleccionado === 'Cash' && is_numeric($pagaCon)) ? ($pagaCon - $totalConDescuento) : null; @endphp
@foreach($carrito as $item) @php $productoId = $item->producto->id; $subtotal = $item->producto->precio * $item->cantidad; $descuento = $descuentos['productos'][$productoId]['monto'] ?? 0; $tipoDescuento = $descuentos['productos'][$productoId]['tipo'] ?? 'fijo'; $totalProducto = max($subtotal - $descuento, 0); $porcentajeDescuento = $subtotal > 0 ? ($descuento / $subtotal) * 100 : 0; @endphp @endforeach @php $porcentajeDescuentoGeneral = $total > 0 ? ($descuentos['general']['monto'] / $total) * 100 : 0; @endphp @if($metodoPagoSeleccionado === 'Cash' && is_numeric($pagaCon)) @endif
Producto Precio Unitario Cantidad Subtotal Descuento Total Producto
{{ $item->producto->nombre }} ${{ number_format($item->producto->precio, 2) }} {{ $item->cantidad }} ${{ number_format($subtotal, 2) }} @if($tipoDescuento == 'porcentaje') {{ number_format($porcentajeDescuento, 2) }} % @else ${{ number_format($descuento, 2) }} @endif ${{ number_format($totalProducto, 2) }}
Subtotal: ${{ number_format($total, 2) }}
Descuento General: @if($descuentos['general']['tipo'] == 'porcentaje') {{ number_format($porcentajeDescuentoGeneral, 2) }} % @else ${{ number_format($descuentos['general']['monto'], 2) }} @endif
Método de Pago: @if($metodoPagoSeleccionado) {{ $metodoPagoSeleccionado }} @else No seleccionado @endif
Total a Pagar: ${{ number_format($totalConDescuento, 2) }}
Paga con: ${{ number_format($pagaCon, 2) }}
Vuelto: ${{ number_format($vuelto, 2) }}
Volver al Carrito
@csrf @foreach($carrito as $item) @endforeach
@endsection