@props([ 'sale' => null, 'saleId' => null, 'show' => false, 'closeAction' => 'closeReceiptModal', ]) @php if (!$sale && !empty($saleId)) { $sale = \App\Models\Sale::with(['customer', 'items.productVariant.product', 'user', 'location', 'receivable.payments'])->find($saleId); } if ($sale) { $sale->loadMissing(['customer', 'items.productVariant.product', 'user', 'location', 'receivable.payments']); } @endphp @if($show && $sale) @php $isCredit = $sale->isCredit(); $isQuote = $sale->isQuote(); $itemsSum = (float) $sale->items->sum(fn ($i) => (float) $i->subtotal_price_usdt); $totalUsdBcv = $itemsSum > 0 ? $itemsSum : (float) ($sale->usd_bcv_total ?? $sale->total_amount_usdt); $invoiceSettings = \App\Services\InvoiceSettingsService::getSettings(); // Obtener tasa oficial BCV actual real y evitar sobreescritura con 1.00 de ventas en divisas $rateService = app(\App\Services\ExchangeRateIngestionService::class); $bcvRates = $rateService->getAllCurrentRates(); $officialBcvRate = (float) ($bcvRates['VES_BCV'] ?? 70.0); if ($officialBcvRate <= 0) { $officialBcvRate = (float) (\App\Models\ExchangeRate::where('currency_code', 'VES')->where('rate_type', 'bcv')->latest('created_at')->value('rate') ?? 70.0); } $historicalRate = (float) ($sale->exchange_rate_applied ?? 0); $rateApplied = ($historicalRate > 1.0) ? $historicalRate : $officialBcvRate; $totalBs = $totalUsdBcv * $rateApplied; $docTitle = $isQuote ? 'PRESUPUESTO / COTIZACIÓN' : ($isCredit ? 'FACTURA DE VENTA A CRÉDITO' : 'Factura / Comprobante de Venta Fiscal'); $receivable = $sale->receivable; $paidAmount = $receivable ? (float)$receivable->paid_amount_usdt : ($isCredit ? 0.0 : $totalUsdBcv); $pendingBalance = $receivable ? (float)$receivable->remaining_balance_usdt : ($isCredit ? $totalUsdBcv : 0.0); @endphp
Kairos
{{ $invoiceSettings['company_name'] }} Oficial

R.I.F. {{ $invoiceSettings['rif'] }} • {{ $invoiceSettings['tax_condition'] }}

{{ $invoiceSettings['fiscal_address'] }} • Tel: {{ $invoiceSettings['phone'] }}

Tipo de Documento Fiscal

{{ $docTitle }}

N° de Factura / Control {{ $sale->sale_number }}
Fecha de Emisión {{ $sale->created_at->format('d/m/Y h:i A') }}
Condición de Pago {{ $isCredit ? 'Crédito / Fiado' : 'Contado' }}
Vencimiento {{ $isCredit && $receivable?->due_date ? $receivable->due_date->format('d/m/Y') : 'Inmediato' }}
Tasa Oficial BCV {{ number_format($rateApplied, 2, ',', '.') }} Bs/$
Datos del Cliente (Receptor)

{{ $sale->customer?->name ?: 'Cliente Ocasional / Vitrina' }}

C.I. / RIF: {{ $sale->customer?->identification_number ?: 'V-No Registrado' }}

@if($sale->customer?->phone)

Tel / WhatsApp: {{ $sale->customer->phone }}

@endif

Sucursal / Almacén: {{ $sale->location?->name ?: 'Depósito Central Caracas' }}

Atendido por: {{ $sale->user?->name ?: 'Personal de Tienda' }}

@if($sale->delivery_address)

Despacho: {{ $sale->delivery_address }}

@endif
Detalle de Prendas ({{ $sale->items->count() }} renglones) Valores en USD BCV & Bolívares
@forelse($sale->items as $item) @php $unitPrice = (float)$item->unit_price_usdt; $subtotalItem = (float)$item->subtotal_price_usdt; @endphp @empty @endforelse
Cant. Descripción de la Prenda / SKU P. Unitario Total ($ BCV)
{{ (int)$item->quantity }}x {{ $item->variant?->display_name ?: ($item->variant?->name ?: 'Prenda Kairos') }} SKU: {{ $item->variant?->sku ?: 'SKU-'.$item->id }} ${{ number_format($unitPrice, 2) }} ${{ number_format($subtotalItem, 2) }}
Sin prendas en la factura.
@if($isCredit)
⏳ Venta a Crédito / Fiado @if($receivable?->due_date) Límite de Pago: {{ $receivable->due_date->format('d/m/Y') }} @endif
Total Factura ${{ number_format($totalUsdBcv, 2) }} USD BCV
Abonado a la Fecha ${{ number_format($paidAmount, 2) }} USD BCV
Saldo Pendiente ${{ number_format($pendingBalance, 2) }} USD BCV

* Los abonos se registrarán en Bolívares a la tasa oficial del BCV del día en que se efectúe el pago, o en divisas acordadas.

@else
Liquidación & Moneda de Cobro @if($sale->charge_currency === 'VES')
Cobrado en Bolívares (VES): Bs. {{ number_format((float)$sale->total_amount_charged, 2, ',', '.') }}
Tasa Oficial BCV Aplicada: {{ number_format($rateApplied, 2, ',', '.') }} Bs/$
@elseif($sale->charge_currency === 'USD' || $sale->payment_method === 'cash_usd')
Cobrado en Divisas Efectivo ($): ${{ number_format((float)$sale->total_amount_charged, 2) }} USD
@elseif($sale->charge_currency === 'USDT' || $sale->payment_method === 'binance_usdt')
Cobrado en Cripto USDT (Binance P2P): {{ number_format((float)$sale->total_amount_charged, 2) }} USDT
@else
Método de Pago: {{ str_replace('_', ' ', $sale->payment_method) }}
@endif @if($sale->payment_notes)

Nota / Referencia: {{ $sale->payment_notes }}

@endif
@endif
Subtotal de Prendas: ${{ number_format($totalUsdBcv, 2) }} USD
I.V.A. (0% Exento): $0.00
Total Factura Valores en USD BCV
${{ number_format($totalUsdBcv, 2) }} USD
Total en Bolívares Tasa BCV: {{ number_format($rateApplied, 2, ',', '.') }} Bs/$
Bs. {{ number_format($totalBs, 2, ',', '.') }}
{{ $invoiceSettings['legal_base'] }} {{ $invoiceSettings['warranty_clause'] }}
@php $waUrl = $sale->isQuote() ? $sale->getWhatsAppQuoteUrl() : $sale->getWhatsAppReceiptUrl(); @endphp @if($waUrl) WhatsApp @endif
@endif