@extends('layouts.app') @section('title', 'Reporte de Ventas') @section('content')

Reporte de Ventas

Análisis detallado de las ventas e ingresos del sistema

Total Facturas
{{ number_format($stats['total_invoices'] ?? 0) }}
Monto Total
${{ number_format($stats['total_amount'] ?? 0, 2) }}
Monto Pagado
${{ number_format($stats['total_paid'] ?? 0, 2) }}
Monto Pendiente
${{ number_format($stats['total_due'] ?? 0, 2) }}
Limpiar
Facturas de Venta
@forelse($invoices as $invoice) @empty @endforelse
N° Factura Cliente Vendedor Fecha Vencimiento Subtotal Total Pagado Pendiente Estado Acciones
{{ $invoice->invoice_number }} @if($invoice->client)
{{ Str::limit($invoice->client->business_name, 30) }}
@if($invoice->client->contact_person) {{ Str::limit($invoice->client->contact_person, 25) }} @endif
@else N/A @endif
@if($invoice->salesman)
{{ $invoice->salesman->name }}
@else N/A @endif
{{ $invoice->invoice_date ? $invoice->invoice_date->format('d/m/Y') : 'N/A' }} {{ $invoice->due_date ? $invoice->due_date->format('d/m/Y') : 'N/A' }} @php // Calcular subtotal en USD $isMultiCurrency = $invoice->currency !== 'USD'; if ($invoice->currency === 'USD') { $subtotalUSD = $invoice->subtotal_usd ?? $invoice->subtotal ?? 0; $subtotalLocal = 0; } else { $subtotalLocal = $invoice->subtotal ?? 0; $subtotalUSD = $invoice->subtotal_usd ?? $invoice->subtotal_legal ?? 0; if ($invoice->total_legal > 0 && $invoice->total_amount > 0) { $rate = $invoice->total_amount / $invoice->total_legal; $subtotalUSD = $subtotalLocal / $rate; } elseif ($invoice->exchange_rate_legal > 0) { $subtotalUSD = $subtotalLocal / $invoice->exchange_rate_legal; } } @endphp
${{ number_format($subtotalUSD, 2) }} @if($isMultiCurrency)
{{ number_format($subtotalLocal, 2) }} {{ $invoice->currency }} @endif
@php // El monto total a cobrar está en total_legal (USD legal) para multi-moneda // O total_amount_usd si está en USD directamente // O convertir total_amount si está en otra moneda if ($invoice->currency === 'USD') { $totalUSD = $invoice->total_amount_usd ?? $invoice->total_amount ?? 0; $isMultiCurrency = false; } else { $isMultiCurrency = true; $totalLocal = $invoice->total_amount ?? 0; // Para multi-moneda, usar total_legal (que es el monto en USD legal a cobrar) if ($invoice->total_legal > 0) { $totalUSD = $invoice->total_legal; } elseif ($invoice->total_amount_usd > 0) { $totalUSD = $invoice->total_amount_usd; } elseif ($invoice->exchange_rate_legal > 0 && $invoice->total_amount > 0) { // Convertir desde moneda local a USD legal $totalUSD = $invoice->total_amount / $invoice->exchange_rate_legal; } elseif ($invoice->exchange_rate > 0 && $invoice->total_amount > 0) { // Fallback: usar exchange_rate $totalUSD = $invoice->total_amount / $invoice->exchange_rate; } else { $totalUSD = 0; } } @endphp
${{ number_format($totalUSD, 2) }} @if($isMultiCurrency)
{{ number_format($totalLocal, 2) }} {{ $invoice->currency }} @endif
@php // Convertir amount_paid a USD $isMultiCurrency = $invoice->currency !== 'USD'; if ($invoice->currency === 'USD') { $paidUSD = $invoice->amount_paid ?? 0; $paidLocal = 0; } else { $paidLocal = $invoice->amount_paid ?? 0; if ($invoice->total_legal > 0 && $invoice->total_amount > 0) { $rate = $invoice->total_amount / $invoice->total_legal; $paidUSD = $paidLocal / $rate; } else { $rate = $invoice->exchange_rate_legal ?? $invoice->exchange_rate ?? 1; $paidUSD = $rate > 0 ? ($paidLocal / $rate) : 0; } } @endphp
${{ number_format($paidUSD, 2) }} @if($isMultiCurrency && $paidLocal > 0)
{{ number_format($paidLocal, 2) }} {{ $invoice->currency }} @endif
@php // Convertir amount_due a USD if ($invoice->currency === 'USD') { $dueUSD = $invoice->amount_due ?? 0; $dueLocal = 0; } else { $dueLocal = $invoice->amount_due ?? 0; if ($invoice->total_legal > 0 && $invoice->total_amount > 0) { $rate = $invoice->total_amount / $invoice->total_legal; $dueUSD = $dueLocal / $rate; } else { $rate = $invoice->exchange_rate_legal ?? $invoice->exchange_rate ?? 1; $dueUSD = $rate > 0 ? ($dueLocal / $rate) : 0; } } @endphp
${{ number_format($dueUSD, 2) }} @if($isMultiCurrency && $dueLocal > 0)
{{ number_format($dueLocal, 2) }} {{ $invoice->currency }} @endif
@php $statusConfig = [ 'draft' => ['class' => 'secondary', 'icon' => 'edit', 'label' => 'Borrador'], 'sent' => ['class' => 'primary', 'icon' => 'paper-plane', 'label' => 'Enviada'], 'paid' => ['class' => 'success', 'icon' => 'check-circle', 'label' => 'Pagada'], 'overdue' => ['class' => 'danger', 'icon' => 'exclamation-triangle', 'label' => 'Vencida'], 'cancelled' => ['class' => 'dark', 'icon' => 'times-circle', 'label' => 'Cancelada'] ]; $status = $statusConfig[$invoice->status] ?? ['class' => 'secondary', 'icon' => 'circle', 'label' => ucfirst($invoice->status)]; @endphp {{ $status['label'] }}
No hay facturas de venta registradas

Las facturas de venta aparecerán aquí

@if($invoices->hasPages()) @endif
@push('styles') @endpush @endsection