RELACION DE TRANSPORTE ACUMULADO POR TRANSPORTISTA SEGUN PEDIDO DE VENTA
({{$date_start}} - {{$date_end}})

Empresa:

{{ $company->name }}

Fecha:

{{ date('Y-m-d') }}

Ruc:

{{ $company->number }}

@php $sellers = []; foreach ($records as $record) { $seller_ids = explode(',', $record->seller_ids); $sellers = array_merge($sellers, $seller_ids); $sellers = array_unique($sellers); } $sellers = array_map(function ($seller_id) { $seller = App\Models\Tenant\User::find($seller_id); return $seller ? $seller->name : ''; }, $sellers); @endphp @if (!empty($records))
TRANSPORTISTA: {{ $dispatcher->name }} - {{ $dispatcher->number }}
VENDEDORES: {{ implode(', ', $sellers) }}
@foreach ($records as $key => $value) @php $seller_ids = explode(',', $value->seller_ids); $internal_id = null; $description = null; $quantity = $value->total_quantity; $unit_type_id = null; $presentations = $value->presentations; $unit_totals = []; $has_pipe = strpos($presentations, '|'); if ($has_pipe !== false) { $presentations = explode(',', $presentations); $presentations = array_map(function ($row) { $row = explode('|', $row); return [ 'description' => isset($row[0]) ? $row[0] : null, 'unit_type_id' => isset($row[1]) ? $row[1] : null, 'unit_quantity' => isset($row[2]) ? $row[2] : 0, 'quantity' => isset($row[3]) ? $row[3] : 0, ]; }, $presentations); foreach ($presentations as $presentation) { $unit_type = $presentation['description']; $quantity_ = (float) $presentation['quantity']; if (!isset($unit_totals[$unit_type])) { $unit_totals[$unit_type] = 0; } $unit_totals[$unit_type] += $quantity_; } } $formatted_result = []; foreach ($unit_totals as $unit_type => $total_quantity) { $formatted_result[] = "{$total_quantity} {$unit_type}"; } $quantity_presentation = null; $total = null; $item = App\Models\Tenant\Item::find($value->item_id); if ($item) { $internal_id = $item->internal_id; $description = $item->description; $unit_type_id = $item->unit_type_id; $quantity_presentation = $value->presentations; $total = $value->total; } $record = (object) [ 'seller_ids' => $seller_ids, 'internal_id' => $internal_id, 'description' => $description, 'quantity' => $quantity, 'unit_type_id' => $unit_type_id, 'quantity_presentation' => $quantity_presentation, 'total' => $total, 'presentations' => implode(', ', $formatted_result), ]; @endphp @endforeach
# Código Descripción Cantidad Unidad de medida Cantidad equivalente Precio de venta
{{ $key + 1 }} {{ $record->internal_id }} {{ $record->description }} {{ $record->quantity }} {{ $record->unit_type_id }} {{ $record->presentations }} {{ $record->total }}
TOTAL ITEMS {{ count($records) }} TOTAL VENTA {{$records->sum('total')}}
@else

No se encontraron registros.

@endif