@php $logoFullPath = public_path('images/logo-full.png'); $logoPath = public_path('images/logo.png'); $logoBase64 = null; if(file_exists($logoFullPath)) { $logoData = base64_encode(file_get_contents($logoFullPath)); $logoBase64 = 'data:image/png;base64,' . $logoData; } elseif(file_exists($logoPath)) { $logoData = base64_encode(file_get_contents($logoPath)); $logoBase64 = 'data:image/png;base64,' . $logoData; } @endphp @if($logoBase64) @endif

FICHA DE VENTA

Número de Venta: {{ $venta->id }} Estado: {{ $venta->estado }}
Fecha de Creación: {{ $venta->fecha ? $venta->fecha->format('d/m/Y') : 'No definida' }} Fecha de Aprobación: {{ $venta->fecha_aprobacion ? $venta->fecha_aprobacion->format('d/m/Y') : 'Pendiente' }}
Contacto: {{ $venta->nombre ?: 'Sin nombre' }} Email: {{ $venta->email ?: 'No definido' }}
Fecha de Entrega: {{ $venta->fecha_entrega ? $venta->fecha_entrega->format('d/m/Y') : 'No definida' }} Teléfono: {{ $venta->telefono ?: 'No definido' }}
PRODUCTOS
@if($venta->ventaProductos && $venta->ventaProductos->count() > 0) @foreach($venta->ventaProductos as $ventaProducto) @continue(!$ventaProducto->incluir_calculo) @php // Calcular valores básicos sin código complejo $precioProveedor = $ventaProducto->precio_proveedor ?: 0; $valorEstimado = $ventaProducto->valor_estimado ?: 0; $maquila = $ventaProducto->maquila ?: 0; $factoring = $ventaProducto->factoring ?: 0; $utilidad = $ventaProducto->utilidad ?: 0; $cantidad = $ventaProducto->cantidad ?: 1; $porcentajeAgencia = intval($venta->porcentaje_agencia ?: 0); $base = $precioProveedor + $valorEstimado + $maquila; // base * (1 + utilidad%) * (1 + agencia%) * (1 + factoring%) $conUtilidad = $base * (1 + $utilidad / 100); $conAgencia = $conUtilidad * (1 + $porcentajeAgencia / 100); $valorUnitarioConAgencia = (int) round($conAgencia * (1 + $factoring / 100)); $valorTotal = $valorUnitarioConAgencia * $cantidad; $valorUtilidad = (int) round($base * ($utilidad / 100)); $utilidadTotal = $valorUtilidad * $cantidad; // Código del producto $codigo = 'Sin código'; if ($ventaProducto->producto) { $codigo = $ventaProducto->producto->code ?: 'Sin código'; } @endphp @endforeach
Imagen Cant. Producto Prov. Producto Prov. Aplicación Valores
@php $imagenBase64 = null; // Intentar con imágenes del producto primero if($ventaProducto->producto && $ventaProducto->producto->images) { $images = is_string($ventaProducto->producto->images) ? json_decode($ventaProducto->producto->images, true) : $ventaProducto->producto->images; $firstImage = is_array($images) && !empty($images) ? $images[0] : null; if($firstImage) { // Verificar si es una URL remota if(filter_var($firstImage, FILTER_VALIDATE_URL)) { try { $imagenData = @file_get_contents($firstImage); if($imagenData !== false) { $imagenBase64Data = base64_encode($imagenData); $extension = strtolower(pathinfo(parse_url($firstImage, PHP_URL_PATH), PATHINFO_EXTENSION)); $mimeType = $extension === 'png' ? 'png' : ($extension === 'webp' ? 'webp' : 'jpeg'); $imagenBase64 = "data:image/$mimeType;base64," . $imagenBase64Data; } } catch (\Exception $e) { // Silenciosamente ignorar errores de descarga } } else { // Es una ruta local $rutaImagen = storage_path('app/public/' . $firstImage); if(file_exists($rutaImagen)) { $imagenData = base64_encode(file_get_contents($rutaImagen)); $extension = strtolower(pathinfo($rutaImagen, PATHINFO_EXTENSION)); $mimeType = $extension === 'png' ? 'png' : ($extension === 'webp' ? 'webp' : 'jpeg'); $imagenBase64 = "data:image/$mimeType;base64," . $imagenData; } } } } // Si no hay imagen del producto, intentar con maqueta_imagen if(!$imagenBase64 && $ventaProducto->maqueta_imagen) { $rutaImagen = storage_path('app/public/' . $ventaProducto->maqueta_imagen); if(file_exists($rutaImagen)) { $imagenData = base64_encode(file_get_contents($rutaImagen)); $extension = strtolower(pathinfo($rutaImagen, PATHINFO_EXTENSION)); $mimeType = $extension === 'png' ? 'png' : ($extension === 'webp' ? 'webp' : 'jpeg'); $imagenBase64 = "data:image/$mimeType;base64," . $imagenData; } } @endphp @if($imagenBase64) Imagen del producto @else
Sin imagen
@endif
{{ $cantidad }}
{{ $ventaProducto->producto->name ?? 'Producto no encontrado' }}
{{ $codigo }}
@if($ventaProducto->isAgotado())
@else @if($ventaProducto->proveedor_producto)
{{ $ventaProducto->proveedorProducto->name ?? 'Proveedor ' . $ventaProducto->proveedor_producto }}
@endif @if($precioProveedor > 0)
${{ number_format($precioProveedor, 0, ',', '.') }}
@endif @endif
@if($ventaProducto->isAgotado())
@else @if($ventaProducto->tiene_aplicacion && $ventaProducto->proveedor_aplicacion)
{{ $ventaProducto->proveedorAplicacion->name ?? 'Proveedor ' . $ventaProducto->proveedor_aplicacion }}
@if($ventaProducto->tipo_aplicacion && $ventaProducto->tipo_aplicacion !== 'Sin Aplicación')
{{ $ventaProducto->tipo_aplicacion }}
@endif @if($valorEstimado > 0)
${{ number_format($valorEstimado, 0, ',', '.') }}
@endif @else
Sin aplicación
@endif @endif
@if($ventaProducto->isAgotado())
Producto Agotado
@else
Unidad: ${{ number_format($valorUnitarioConAgencia, 0, ',', '.') }}
Total: ${{ number_format($valorTotal, 0, ',', '.') }}
Util: ${{ number_format($utilidadTotal, 0, ',', '.') }} ({{ $utilidad }}%)
@endif

Resumen de Venta

@php $totalUtilidad = 0; $neto = 0; $descuento = intval($venta->descuento ?: 0); $porcentajeAgencia = intval($venta->porcentaje_agencia ?: 0); // Calcular valores usando la misma lógica que el JavaScript foreach($venta->ventaProductos as $ventaProducto) { // Solo incluir productos marcados para cálculo y que tengan precio if (!$ventaProducto->incluir_calculo || $ventaProducto->isAgotado()) { continue; } $cantidad = intval($ventaProducto->cantidad ?: 1); $precioProveedor = intval($ventaProducto->precio_proveedor ?: 0); $valorEstimado = intval($ventaProducto->valor_estimado ?: 0); $maquila = intval($ventaProducto->maquila ?: 0); $factoring = intval($ventaProducto->factoring ?: 0); $utilidad = intval($ventaProducto->utilidad ?: 0); // Base = precio proveedor + valor estimado aplicación + maquila $base = $precioProveedor + $valorEstimado + $maquila; // base * (1 + utilidad%) * (1 + agencia%) * (1 + factoring%) $conUtilidad = $base * (1 + $utilidad / 100); $conAgencia = $conUtilidad * (1 + $porcentajeAgencia / 100); $precioUnitario = (int) round($conAgencia * (1 + $factoring / 100)); // Sumar al neto total (ya incluye agencia por producto) $neto += $precioUnitario * $cantidad; // Sumar solo la utilidad (sin factoring) $totalUtilidad += (int) round($base * ($utilidad / 100)) * $cantidad; } // Calcular descuento sobre el neto (que ya incluye agencia) $descuentoMonto = round($neto * ($descuento / 100)); // Calcular subtotal $subtotal = $neto - $descuentoMonto; // Valor de despacho (sujeto a IVA) $valorDespacho = intval($venta->valor_despacho ?: 0); // Calcular IVA e impuestos $iva = round(($subtotal + $valorDespacho) * 0.19); $total = $subtotal + $valorDespacho + $iva; @endphp
Utilidad:
${{ number_format($totalUtilidad, 0, ',', '.') }}
Neto:
${{ number_format($neto, 0, ',', '.') }}
@if($descuento > 0)
Descuento ({{ $descuento }}%):
-${{ number_format($descuentoMonto, 0, ',', '.') }}
@endif
Subtotal:
${{ number_format($subtotal, 0, ',', '.') }}
@if($valorDespacho > 0)
Despacho:
${{ number_format($valorDespacho, 0, ',', '.') }}
@endif
IVA (19%):
${{ number_format($iva, 0, ',', '.') }}

TOTAL:
${{ number_format($total, 0, ',', '.') }}
@else

No hay productos asociados a esta venta.

@endif @if($venta->nota)
Nota Privada:
{!! strip_tags($venta->nota) !!}
@endif @if($venta->nota_cliente)
Nota Cliente:
{!! strip_tags($venta->nota_cliente) !!}
@endif