@php /* |-------------------------------------------------------------------------- | NORMALIZAR CONFIGURACIÓN |-------------------------------------------------------------------------- | Configuracion::todas() puede devolver arrays u objetos. | Convertimos todo a una colección accesible de forma segura. */ $configData = collect($config ?? []) ->mapWithKeys(function ($valor, $clave) { if (is_object($valor)) { if (isset($valor->clave)) { return [ $valor->clave => $valor->valor ?? null ]; } return [ $clave => $valor->valor ?? null ]; } return [ $clave => $valor ]; }) ->toArray(); $sym = $configData['moneda_simbolo'] ?? 'S/'; $empresa = $configData['empresa_nombre'] ?? ''; $ruc = $configData['empresa_ruc'] ?? ''; $direccion = $configData['empresa_direccion'] ?? ''; $telefono = $configData['empresa_telefono'] ?? ''; $mensajeTicket = $configData['mensaje_ticket'] ?? 'Gracias por su compra'; $igvPorcentaje = $configData['igv_porcentaje'] ?? 18; /* |-------------------------------------------------------------------------- | TIPO DE COMPROBANTE |-------------------------------------------------------------------------- */ $tipoComprobante = match ($venta->tipo_comprobante) { 'factura' => 'FACTURA', 'boleta' => 'BOLETA', 'nota_venta' => 'NOTA DE VENTA', default => strtoupper( str_replace('_', ' ', $venta->tipo_comprobante) ), }; /* |-------------------------------------------------------------------------- | CLIENTE |-------------------------------------------------------------------------- */ $clienteNombre = 'Cliente Varios'; if ($venta->cliente) { $clienteNombre = trim( implode(' ', array_filter([ $venta->cliente->nombre ?? '', $venta->cliente->apellido_paterno ?? '', $venta->cliente->apellido_materno ?? '', ])) ); if ($clienteNombre === '') { $clienteNombre = 'Cliente Varios'; } } /* |-------------------------------------------------------------------------- | CÓDIGO DE CANJE |-------------------------------------------------------------------------- */ $codigo = $codigoCanje ?? null; /* |-------------------------------------------------------------------------- | OFERTAS |-------------------------------------------------------------------------- */ $ofertasDisponibles = collect($ofertas ?? []); $codigosDisponibles = collect($codigosHabilitados ?? []); @endphp {{ $tipoComprobante }} {{ $venta->numero_comprobante }} {{-- ================================================================ ACCIONES ================================================================= --}}
← Nueva venta
{{-- ================================================================ CONTENEDOR ================================================================= --}}
{{-- ============================================================ COMPROBANTE PRINCIPAL ============================================================= --}}
{{-- EMPRESA --}}
{{ $empresa }}
@if ($ruc)

RUC {{ $ruc }}

@endif @if ($direccion || $telefono)

{{ $direccion }} @if ($telefono) · Tel. {{ $telefono }} @endif

@endif

{{ $tipoComprobante }}

{{ $venta->numero_comprobante }}

{{-- DATOS DE VENTA --}}
Fecha: {{ $venta->created_at?->format('d/m/Y H:i') }}
Cajero: {{ $venta->usuario?->name ?? '—' }}
Cliente: {{ $clienteNombre }}
@if ($venta->cliente?->numero_documento)
Documento: {{ $venta->cliente->numero_documento }}
@endif
Pago: {{ $venta->metodo_pago }}
{{-- PRODUCTOS --}} @foreach ($venta->detalles as $d) @endforeach
Producto Cant P.U. Subt.
{{ $d->descripcion }} @if ($d->stockProducto?->lote)
Lote: {{ $d->stockProducto->lote }}
@endif
{{ $d->cantidad }} {{ number_format($d->precio_unitario, 2) }} {{ number_format($d->subtotal, 2) }}
{{-- TOTALES --}}
Op. Gravada {{ $sym }} {{ number_format($venta->subtotal, 2) }}
IGV ({{ $igvPorcentaje }}%) {{ $sym }} {{ number_format($venta->igv, 2) }}
@if ($venta->descuento > 0)
Descuento − {{ $sym }} {{ number_format($venta->descuento, 2) }}
@endif
TOTAL {{ $sym }} {{ number_format($venta->total, 2) }}
{{-- PAGOS --}} @if ($venta->pagos->count())

Detalle de pago

@foreach ($venta->pagos as $pago)
{{ $pago->medio_pago }} {{ $sym }} {{ number_format($pago->monto, 2) }}
@if ($pago->referencia)
Ref: {{ $pago->referencia }}
@endif @endforeach
@endif {{-- PUNTOS --}} @if ($esCanjePuntos)

CANJE DE PUNTOS

Esta operación fue realizada utilizando puntos de fidelización.

@endif

{{ $mensajeTicket }}

{{-- ============================================================ CORTE ENTRE COMPROBANTE Y PROMOCIONES ============================================================= --}} @if ($codigo || $ofertasDisponibles->count() || $codigosDisponibles->count())
{{-- ======================================================== SEGUNDA PARTE: PROMOCIONES / CANJE ========================================================= --}}

¡Gracias por tu compra!

Aprovecha nuestras promociones

{{-- CÓDIGO DE CANJE --}} @if ($codigo)

Código de canje

{{ $codigo }}

Presente este código para utilizar su beneficio.

@endif {{-- CÓDIGOS HABILITADOS --}} @if ($codigosDisponibles->count())

CÓDIGOS DISPONIBLES

@foreach ($codigosDisponibles->take(10) as $codigoDisponible) @php $codigoTexto = $codigoDisponible->codigo ?? ''; $codigoNombre = $codigoDisponible->nombre ?? ''; $codigoTipo = strtolower(trim((string) ($codigoDisponible->tipo ?? ''))); $codigoValor = (float) ($codigoDisponible->valor ?? 0); $codigoBeneficio = $codigoTipo === 'porcentaje' ? 'DESCUENTO DE ' . rtrim(rtrim(number_format($codigoValor, 2, '.', ''), '0'), '.') . '%' : ($codigoTipo === 'monto' ? 'DESCUENTO DE ' . $sym . number_format($codigoValor, 2) : 'BENEFICIO DE PUNTOS'); $codigoCondiciones = collect($codigoDisponible->condiciones ?? []); $codigoObjetivos = []; $codigoCondiciones->each(function ($condicion) use (&$codigoObjetivos) { $tipoCondicion = strtolower((string) ($condicion->tipo ?? $condicion['tipo'] ?? '')); $productoNombre = $condicion->producto_nombre ?? ($condicion['producto_nombre'] ?? $condicion->producto?->nombre ?? null); $categoriaNombre = $condicion->categoria_nombre ?? ($condicion['categoria_nombre'] ?? $condicion->categoria?->nombre ?? null); $valorCondicion = (float) ($condicion->valor ?? ($condicion['valor'] ?? 0)); if ($tipoCondicion === 'producto' && $productoNombre) { $codigoObjetivos[] = mb_strtoupper($productoNombre); } elseif ($tipoCondicion === 'categoria' && $categoriaNombre) { $codigoObjetivos[] = mb_strtoupper($categoriaNombre); } elseif ($tipoCondicion === 'monto_minimo') { $codigoObjetivos[] = 'COMPRAS DESDE ' . $sym . number_format($valorCondicion, 2); } elseif ($tipoCondicion === 'cantidad_minima') { $codigoObjetivos[] = 'COMPRAS DE ' . number_format($valorCondicion, 0) . ' UNIDADES O MÁS'; } }); $codigoObjetivos = array_values(array_unique(array_filter($codigoObjetivos))); $codigoPara = count($codigoObjetivos) ? 'EN ' . implode(' / ', $codigoObjetivos) : 'EN LA COMPRA'; @endphp

Código

{{ $codigoTexto }}

{{ $codigoBeneficio }} {{ $codigoPara }}

@if ($codigoNombre)

{{ $codigoNombre }}

@endif
@endforeach
@endif {{-- OFERTAS --}} @if ($ofertasDisponibles->count())

OFERTAS DISPONIBLES

@foreach ($ofertasDisponibles->take(5) as $oferta) @php $getOferta = function ($obj, $key, $default = null) { if (is_object($obj)) return $obj->{$key} ?? $default; return is_array($obj) ? ($obj[$key] ?? $default) : $default; }; $ofertaNombre = $getOferta($oferta, 'nombre', 'Oferta'); $ofertaTipo = strtolower(trim((string) $getOferta($oferta, 'tipo', ''))); $ofertaValor = (float) $getOferta($oferta, 'valor', 0); $condiciones = collect($getOferta($oferta, 'condiciones', []) ?? []); $objetivos = []; $condiciones->each(function ($condicion) use (&$objetivos) { $tipoCondicion = strtolower((string) ($condicion->tipo ?? $condicion['tipo'] ?? '')); $productoNombre = $condicion->producto_nombre ?? ($condicion['producto_nombre'] ?? $condicion->producto?->nombre ?? null); $categoriaNombre = $condicion->categoria_nombre ?? ($condicion['categoria_nombre'] ?? $condicion->categoria?->nombre ?? null); $valorCondicion = (float) ($condicion->valor ?? ($condicion['valor'] ?? 0)); if ($tipoCondicion === 'producto' && $productoNombre) { $objetivos[] = mb_strtoupper($productoNombre); } elseif ($tipoCondicion === 'categoria' && $categoriaNombre) { $objetivos[] = mb_strtoupper($categoriaNombre); } elseif ($tipoCondicion === 'monto_minimo') { $objetivos[] = 'COMPRAS DESDE S/ ' . number_format($valorCondicion, 2); } elseif ($tipoCondicion === 'cantidad_minima') { $objetivos[] = 'COMPRAS DE ' . number_format($valorCondicion, 0) . ' UNIDADES O MÁS'; } }); $objetivos = array_values(array_unique(array_filter($objetivos))); $aplicaA = count($objetivos) ? implode(' / ', $objetivos) : 'LA COMPRA'; $valorTexto = $ofertaTipo === 'porcentaje' ? rtrim(rtrim(number_format($ofertaValor, 2, '.', ''), '0'), '.') . '%' : ($ofertaTipo === 'monto' ? $sym . number_format($ofertaValor, 2) : null); $descripcionOferta = $valorTexto ? 'DESCUENTO DE ' . $valorTexto . ' EN ' . $aplicaA : mb_strtoupper((string) ($getOferta($oferta, 'descripcion', '') ?: 'PROMOCIÓN ESPECIAL')) . ' EN ' . $aplicaA; @endphp

Oferta

{{ $descripcionOferta }}

@if ($ofertaNombre && strcasecmp(trim((string) $ofertaNombre), 'oferta') !== 0)

{{ $ofertaNombre }}

@endif
@endforeach
@endif

Consulte las condiciones de cada promoción.

@endif
{{-- ================================================================ IMPRESIÓN ================================================================= --}}