@php // Filtro Inteligente: Agrupa productos y oculta los abonos negativos $filteredDetails = []; if($order && $order->details) { $groupedDetails = []; foreach($order->details as $d) { $pid = $d->product_id; if(!isset($groupedDetails[$pid])) { $groupedDetails[$pid] = (object)[ 'primary_id' => $d->id, 'product' => $d->product, 'price' => $d->price, 'net_qty' => 0, 'primary_qty' => 0, 'note' => null, 'has_abono' => false ]; } $groupedDetails[$pid]->net_qty += $d->quantity; if($d->quantity > 0) { $groupedDetails[$pid]->primary_id = $d->id; $groupedDetails[$pid]->primary_qty += $d->quantity; if($d->note) $groupedDetails[$pid]->note = $d->note; } else { $groupedDetails[$pid]->has_abono = true; } } // Solo mostramos los que tengan cantidad positiva después de restar abonos $filteredDetails = array_filter($groupedDetails, function($item) { return $item->net_qty > 0; }); } @endphp @if($order && count($filteredDetails) > 0)
@foreach($filteredDetails as $detail) @endforeach
PROD. CANT. TOT.
@if($detail->has_abono) @else @endif
{{ $detail->product->name }}
{{ $currency ?? 'S/' }}{{ number_format($detail->price, 2) }} @if($detail->note) @endif @if(!$detail->has_abono) @endif
@if($detail->has_abono) {{ $detail->net_qty }} @else
@endif
{{ number_format($detail->net_qty * $detail->price, 2) }}
@else

Cuenta vacía

@endif
@if($order)
Subtotal:
{{ number_format($order->total, 2) }}
@if($order->discount > 0)
Descuento:
-{{ number_format($order->discount, 2) }}
@endif @if($order->tip > 0)
Propina:
+{{ number_format($order->tip, 2) }}
@endif
TOTAL:

{{ $currency ?? 'S/' }}{{ number_format($order->total + ($order->tip ?? 0) - ($order->discount ?? 0), 2) }}

@endif