@extends('pdf.base') @section('content') @php // ===== CLIENT AVATAR ===== // Priority: portalUser->avatar_url (User accessor) > client->avatar field $clientAvatarUrl = null; if ($client->portalUser) { $clientAvatarUrl = $client->portalUser->avatar_url; } if (!$clientAvatarUrl && ($client->avatar ?? null)) { $clientAvatarUrl = str_starts_with($client->avatar, 'http') ? $client->avatar : asset('storage/' . $client->avatar); } // ===== DATE ===== $currentDate = now()->locale('es')->isoFormat('dddd, D [de] MMMM [de] YYYY'); // ===== CLIENT DATA ===== $age = '-'; if ($client->age) { $age = $client->age . ' años'; } elseif ($client->date_of_birth ?? null) { try { $age = \Carbon\Carbon::parse($client->date_of_birth)->age . ' años'; } catch (\Exception $e) { $age = '-'; } } $gender = match($client->gender ?? '') { 'male' => 'Masculino', 'female' => 'Femenino', default => '-', }; $activityLabels = [ 'sedentary' => 'Sedentario', 'light' => 'Ligera', 'moderate' => 'Moderada', 'active' => 'Activa', 'very_active' => 'Muy Activa', ]; // ===== MEAL TYPE LABELS (both English and Spanish keys) ===== $allMealLabels = [ 'breakfast' => 'DESAYUNO', 'pre_workout' => 'PRE-ENTRENO', 'post_workout' => 'POST-ENTRENO', 'lunch' => 'ALMUERZO', 'snack' => 'MERIENDA', 'dinner' => 'CENA', 'mid_morning_snack' => 'MEDIA MAÑANA', 'mid_afternoon_snack' => 'MEDIA TARDE', 'intra_workout' => 'INTRA-ENTRENO', 'desayuno' => 'DESAYUNO', 'almuerzo' => 'ALMUERZO', 'merienda' => 'MERIENDA', 'merienda_media_manana' => 'MEDIA MAÑANA', 'merienda_media_tarde' => 'MEDIA TARDE', 'cena' => 'CENA', 'comida_1' => 'COMIDA 1', 'comida_2' => 'COMIDA 2', 'comida_3' => 'COMIDA 3', 'comida_4' => 'COMIDA 4', 'comida_5' => 'COMIDA 5', 'comida_6' => 'COMIDA 6', 'comida_7' => 'COMIDA 7', 'comida_8' => 'COMIDA 8', 'meal_1' => 'COMIDA 1', 'meal_2' => 'COMIDA 2', 'meal_3' => 'COMIDA 3', ]; // ===== TOTALS FROM ALL PLANS ===== $totalP = 0; $totalC = 0; $totalF = 0; $totalCals = 0; foreach ($dietPlans ?? [] as $plan) { foreach ($plan->items ?? $plan->mealItems ?? [] as $item) { $totalP += $item->proteins ?? 0; $totalC += $item->carbs ?? 0; $totalF += $item->fats ?? 0; $totalCals += $item->calories ?? 0; } } // ===== DAY LABELS ===== $dayLabels = [ 'monday' => 'LUN', 'tuesday' => 'MAR', 'wednesday' => 'MIE', 'thursday' => 'JUE', 'friday' => 'VIE', 'saturday' => 'SAB', 'sunday' => 'DOM', ]; @endphp
@if($clientAvatarUrl) {{ $client->name }} @else
{{ strtoupper(substr($client->name ?? 'C', 0, 1)) }}
@endif
{{ $client->name ?? 'Cliente' }}
Cliente
@if(($settings['show_logo'] ?? true) && ($settings['logo'] ?? null)) @php $logoPath = str_starts_with($settings['logo'], 'http') ? $settings['logo'] : asset('storage/' . $settings['logo']); @endphp Logo @endif
{{ $currentDate }}
Información Personal
Peso {{ number_format($client->weight ?? 0, 2) }} kg
Altura {{ number_format($client->height ?? 0, 2) }} cm
Edad {{ $age }}
Sexo {{ $gender }}
Nivel Actividad {{ $activityLabels[$client->activity_level] ?? '-' }}
Resumen de Macros
Proteínas Totales {{ number_format($totalP, 1) }}g
Carbohidratos Totales {{ number_format($totalC, 1) }}g
Grasas Totales {{ number_format($totalF, 1) }}g
@if($client->bmr ?? null)
BMR (Metabolismo Basal) {{ number_format($client->bmr, 2) }} kcal
@endif @if($client->tdee ?? null)
TDEE (Gasto Diario) {{ number_format($client->tdee, 2) }} kcal
@endif
@foreach($dietPlans ?? [] as $index => $dietPlan) @php // Get items from the relation (items = mealItems) $planItems = $dietPlan->items ?? $dietPlan->mealItems ?? collect(); // Calculate plan totals directly from pre-calculated values $planP = $planItems->sum('proteins'); $planC = $planItems->sum('carbs'); $planF = $planItems->sum('fats'); $planCals = $planItems->sum('calories'); // Group by meal_type - use ALL items, no filtering $grouped = $planItems->groupBy('meal_type'); // Get meal types in order as they appear $mealTypes = $grouped->keys()->toArray(); @endphp
{{ $dietPlan->name ?? 'Plan ' . ($index + 1) }} @if(($dietPlan->days ?? null) && is_array($dietPlan->days) && count($dietPlan->days)) ({{ implode(', ', array_map(fn($d) => $dayLabels[$d] ?? strtoupper(substr($d, 0, 3)), $dietPlan->days)) }}) @endif
PROTEÍNAS {{ number_format($planP, 1) }}g CARBOHIDRATOS {{ number_format($planC, 1) }}g GRASAS {{ number_format($planF, 1) }}g CALORÍAS {{ number_format(round($planCals)) }}
@php // Split meal types into rows of 4 columns $mealChunks = array_chunk($mealTypes, 4); @endphp @foreach($mealChunks as $chunk)
@foreach($chunk as $mealType) @php $items = $grouped[$mealType]; $mealCals = $items->sum('calories'); @endphp
{{ $allMealLabels[$mealType] ?? strtoupper(str_replace('_', ' ', $mealType)) }} {{ number_format(round($mealCals)) }} kcal
@foreach($items as $item)
{{ $item->food->name ?? 'Alimento' }}
{{ rtrim(rtrim(number_format($item->quantity, 2), '0'), '.') }} {{ $item->unit ?? 'g' }}
P: {{ number_format($item->proteins ?? 0, 1) }}g C: {{ number_format($item->carbs ?? 0, 1) }}g G: {{ number_format($item->fats ?? 0, 1) }}g
@endforeach
P: {{ number_format($items->sum('proteins'), 1) }}g C: {{ number_format($items->sum('carbs'), 1) }}g G: {{ number_format($items->sum('fats'), 1) }}g
@endforeach {{-- Fill empty columns if fewer than 4 --}} @for($i = count($chunk); $i < 4; $i++)
@endfor
@endforeach @if($index < count($dietPlans) - 1)
@endif @endforeach @if(empty($dietPlans) || count($dietPlans) === 0)

No hay planes de dieta configurados.

@endif
💧 Recomendaciones de Hidratación
{{ $mealPlan->description ?? 'Se recomienda consumir mínimo 2-3 litros de agua al día. Aumentar la ingesta en días de entrenamiento intenso. Evitar bebidas azucaradas y limitar el consumo de alcohol.' }}
@if(trim(strip_tags($mealPlan->notes ?? '')) !== '')
📝 Notas del Coach
{{ trim(strip_tags($mealPlan->notes)) }}
@endif
⚠️ Este plan nutricional es personalizado. No compartir ni seguir sin supervisión profesional. Los resultados pueden variar según cada individuo.
@endsection