@extends('layout.main') @section('content') {{-- Reportes → Ventas por fechas (ReportController@salesRange). Une Venta diaria y Venta mensual: arriba se elige el rango (calendario), abajo se ve qué pasó en ese período. --}} @php $money = function ($v) { return '$' . number_format((float) $v, 2); }; $max = max(1, collect($periods)->max('grand_total')); $q = function ($desde, $hasta) use ($warehouse_id) { return route('report.salesRange', array_filter(['desde' => $desde, 'hasta' => $hasta, 'local' => $warehouse_id ?: null])); }; $today = now()->startOfDay(); $quick = [ 'Hoy' => [$today, $today], 'Ayer' => [$today->copy()->subDay(), $today->copy()->subDay()], 'Esta semana' => [$today->copy()->startOfWeek(), $today], 'Este mes' => [$today->copy()->startOfMonth(), $today], 'Mes pasado' => [$today->copy()->subMonthNoOverflow()->startOfMonth(), $today->copy()->subMonthNoOverflow()->endOfMonth()], 'Últimos 30 días' => [$today->copy()->subDays(29), $today], 'Este año' => [$today->copy()->startOfYear(), $today], ]; $byKey = collect($periods)->keyBy('key'); $months = []; if ($daily) { $m = $from->copy()->startOfMonth(); while ($m <= $to) { $months[] = $m->copy(); $m->addMonthNoOverflow(); } } $monthNames = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']; $level = function ($v) use ($max) { return $v <= 0 ? 0 : min(4, 1 + (int) floor(3.999 * $v / $max)); }; $rangeText = $from->isSameDay($to) ? $from->format('d/m/Y') : $from->format('d/m/Y') . ' al ' . $to->format('d/m/Y'); @endphp
{{-- ============ CALENDARIO / SELECCIÓN DE FECHAS ============ --}}

Ventas por fechas

@foreach($quick as $label => [$a, $b]) {{ $label }} @endforeach
@if($lims_warehouse_list->count() > 1)
@endif
@if($daily)
@foreach($months as $m)
{{ $monthNames[$m->month - 1] }} {{ $m->year }}
@foreach(['L', 'M', 'M', 'J', 'V', 'S', 'D'] as $d)
{{ $d }}
@endforeach @for($i = 1; $i < $m->dayOfWeekIso; $i++)@endfor @for($day = $m->copy(); $day->month == $m->month; $day->addDay()) @php $p = $byKey[$day->toDateString()] ?? null; @endphp @if($p) {{ $day->day }} @else {{ $day->day }} @endif @endfor
@endforeach
Menos Más · Toca un día para verlo solo.
@endif
{{-- ============ RESULTADOS DEL RANGO ============ --}}
Ventas · {{ $rangeText }}{{ $money($totals['grand_total']) }} {{ $totals['n'] }} {{ $totals['n'] == 1 ? 'venta' : 'ventas' }}@if($totals['returns'] > 0) · netas {{ $money($totals['net']) }}@endif
Ticket promedio{{ $money($totals['ticket']) }}por venta
IVA{{ $money($totals['total_tax'] + $totals['order_tax']) }}incluido en las ventas
{{ $daily ? 'Mejor día' : 'Mejor mes' }}{{ $best && $best['grand_total'] > 0 ? $money($best['grand_total']) : '—' }} {{ $best && $best['grand_total'] > 0 ? ($daily ? $best['date']->format('d/m/Y') : $best['label']) : 'sin ventas' }}

{{ $daily ? 'Ventas por día' : 'Ventas por mes' }}

@php $step = max(1, (int) ceil(count($periods) / 12)); @endphp
@foreach($periods as $i => $p){{ $i % $step == 0 ? $p['label'] : '' }}@endforeach

Productos más vendidos

@php $topMax = max(1, $top->max('total')); @endphp
    @forelse($top as $t)
  • {{ $t->name }} ×{{ (float) $t->qty }}{{ $money($t->total) }}
  • @empty
  • Sin ventas en el rango.
  • @endforelse

Por vendedor

@php $uMax = max(1, $by_user->max('total')); @endphp
    @forelse($by_user as $u)
  • {{ $u->name }} {{ $u->n }}{{ $money($u->total) }}
  • @empty
  • Sin ventas en el rango.
  • @endforelse

{{ $by_store->isNotEmpty() ? 'Por local' : 'Descuentos y envíos' }}

    @if($by_store->isNotEmpty()) @php $sMax = max(1, $by_store->max('total')); @endphp @foreach($by_store as $st)
  • {{ preg_replace('/\s*-\s*Entre Tu y Yo$/i', '', $st->name) }} {{ $st->n }}{{ $money($st->total) }}
  • @endforeach @endif
  • Descuentos{{ $money($totals['discount']) }}
  • Envíos cobrados{{ $money($totals['shipping_cost']) }}
  • Devoluciones{{ $money($totals['returns']) }}
{{-- Lo mismo que mostraban Venta diaria / Venta mensual, fila por fila --}}
Detalle {{ $daily ? 'por día' : 'por mes' }}
@foreach($periods as $p) @if($p['n'] > 0) @endif @endforeach
{{ $daily ? 'Día' : 'Mes' }}VentasDesc. productosDesc. pedidoIVAImpuesto pedidoEnvíoTotal
{{ $daily ? $p['date']->format('d/m/Y') : $p['label'] }} {{ $p['n'] }} {{ number_format($p['total_discount'], 2) }} {{ number_format($p['order_discount'], 2) }} {{ number_format($p['total_tax'], 2) }} {{ number_format($p['order_tax'], 2) }} {{ number_format($p['shipping_cost'], 2) }} {{ number_format($p['grand_total'], 2) }}
Total{{ $totals['n'] }}{{ number_format($totals['discount'], 2) }}{{ number_format($totals['total_tax'], 2) }}{{ number_format($totals['order_tax'], 2) }}{{ number_format($totals['shipping_cost'], 2) }}{{ number_format($totals['grand_total'], 2) }}
@endsection