@php $pxPerCm = 0.92; // same scale used in app $seatDiameterCm = 50; $seatSize = (int) round($seatDiameterCm * $pxPerCm); $minX = null; $minY = null; $maxX = 0; $maxY = 0; $computed = []; foreach ($tables as $name => $meta) { $type = is_array($meta) ? ($meta['type'] ?? 'round') : 'round'; $capacity = is_array($meta) ? ($meta['capacity'] ?? 8) : (int) $meta; $posX = is_array($meta) ? (int)($meta['x'] ?? 40) : 40; $posY = is_array($meta) ? (int)($meta['y'] ?? 40) : 40; if ($type === 'round') { $diameterCm = (int)($meta['dims']['diameter_cm'] ?? 160); $diameterPx = (int) round($diameterCm * $pxPerCm); $radiusTable = $diameterPx / 2; $radiusSeats = (int) round($radiusTable + ($seatSize / 1.35)); $container = (int) ceil(($radiusSeats + ($seatSize/2) + 16) * 2); $computed[$name] = ['type'=>'round','x'=>$posX,'y'=>$posY,'w'=>$container,'h'=>$container,'capacity'=>$capacity,'diameterPx'=>$diameterPx,'seatSize'=>$seatSize]; $w=$container; $h=$container; } else { $widthCm = (int)($meta['dims']['width_cm'] ?? 200); $heightCm = (int)($meta['dims']['height_cm'] ?? 90); $rectW = (int) round($widthCm * $pxPerCm); $rectH = (int) round($heightCm * $pxPerCm); $edgePad = 20; $rows = ($type === 'rect-2') ? 2 : 1; $containerW = (int) max($rectW + 2*($seatSize + $edgePad), 300); $containerH = (int) max($rectH + ($rows * ($seatSize + $edgePad)) + 60, 220); $computed[$name] = ['type'=>$type,'x'=>$posX,'y'=>$posY,'w'=>$containerW,'h'=>$containerH,'rectW'=>$rectW,'rectH'=>$rectH,'angle_deg'=>(int)($meta['angle_deg'] ?? 0),'seatSize'=>$seatSize]; $w=$containerW; $h=$containerH; } $minX = is_null($minX) ? $posX : min($minX, $posX); $minY = is_null($minY) ? $posY : min($minY, $posY); $maxX = max($maxX, $posX + $w); $maxY = max($maxY, $posY + $h); } if (is_null($minX)) { $minX = 0; $minY = 0; } // Safety margin (px) from controller or default $safe = isset($safe) ? (int)$safe : 100; $contentW = max(1, ($maxX - $minX) + 2*$safe); $contentH = max(1, ($maxY - $minY) + 2*$safe); // A4 px approx at 96dpi $isLandscape = !empty($landscape) && $landscape; $pageW = $isLandscape ? 1122 : 794; $pageH = $isLandscape ? 794 : 1122; // Reserve fixed header height (px) $headerH = 180; $usableH = max(1, $pageH - $headerH); $scale = min(1.0, min($pageW / $contentW, $usableH / $contentH)); // Center after scaling and offset to include safe margin $offsetX = -$minX + $safe; $offsetY = -$minY + $safe; $finalW = $contentW * $scale; $finalH = $contentH * $scale; $centerX = ($pageW - $finalW) / 2; $centerY = $headerH + (($usableH - $finalH) / 2); @endphp
@if(!empty($logoPath)) @endif @if(!empty($headerTitle))
{{ $headerTitle }}
@endif @if(!empty($headerDate))
Plano de Mesas - Fecha del evento: {{ $headerDate }}
@endif
@php $byTable = $byTable ?? []; @endphp @foreach($computed as $name => $info) @php $left = ($info['x'] - $minX + $safe); $top = ($info['y'] - $minY + $safe); $w = $info['w']; $h = $info['h']; $ss = $info['seatSize']; @endphp @php $assigned = $byTable[$name] ?? []; @endphp @if($info['type'] === 'round') @php $diameterPx = $info['diameterPx']; $radiusTable = $diameterPx / 2; $radiusSeats = (int) round($radiusTable + ($ss / 1.35)); $container = max($w, $h); $center = $container / 2; // Build seat map from assigned as in UI $seatMap = array_fill(0, max(1, ($tables[$name]['capacity'] ?? 8)), null); $pending = []; foreach ($assigned as $it) { $s = $it['seat'] ?? null; if ($s !== null && is_numeric($s)) { $si = (int)$s; if ($si >= 0 && $si < count($seatMap) && $seatMap[$si] === null) { $seatMap[$si] = $it; } else { $pending[] = $it; } } else { $pending[] = $it; } } for ($fi=0,$pi=0; $fi
{{ $name }}
@for($i=0; $i<$capacity; $i++) @php $angle = (2 * M_PI * $i) / max(1,$capacity); $x = $center + $radiusSeats * cos($angle) - $ss/2; $y = $center + $radiusSeats * sin($angle) - $ss/2; $occ = $seatMap[$i] ?? null; $nameWords = $occ ? preg_split('/\s+/', (string)($occ['label'] ?? ''), -1, PREG_SPLIT_NO_EMPTY) : []; @endphp
@if($occ)
avatar
@else {{ $i+1 }} @endif
@if($occ && !empty($nameWords)) @php $labelLeft = (int) round($x + ($ss / 2)); $labelTop = (int) round($y + $ss + 5); @endphp
@foreach($nameWords as $w) {{ $w }} @endforeach
@endif @endfor
@else @php $capacity = $tables[$name]['capacity'] ?? 8; $type = $info['type']; $rectW = $info['rectW']; $rectH = $info['rectH']; $angleDeg = (int)($info['angle_deg'] ?? 0); $edgePad = 20; $rows = ($type === 'rect-2') ? 2 : 1; $containerW = $w; $containerH = $h; $rectX = ($containerW - $rectW) / 2; $rectY = ($containerH - $rectH) / 2; $originX = (int) round($rectW / 2); $originY = (int) round($rectH / 2); $transform = sprintf('translate(%dpx, %dpx) rotate(%ddeg) translate(-%dpx, -%dpx)', $originX, $originY, $angleDeg, $originX, $originY); // compute seats distribution if ($type === 'rect-2') { $topCount = (int) ceil($capacity / 2); $bottomCount = $capacity - $topCount; } else { $topCount = $capacity; $bottomCount = 0; } $computeRowXs = function($n) use($rectW,$ss){ if ($n <= 0) return []; if ($n === 1) { return [ ($rectW - $ss)/2 ]; } $gap = ($rectW - $ss) / max(1, ($n-1)); $xs = []; for ($i=0; $i<$n; $i++) { $xs[] = $i*$gap; } return $xs; }; $topXs = $computeRowXs($topCount); $bottomXs = $computeRowXs($bottomCount); $topRowYRel = (int) -($ss + 10); $bottomRowYRel = (int) ($rectH + 10); // Build seat map for this table $seatMap = array_fill(0, max(1, $capacity), null); $pending = []; foreach (($assigned ?? []) as $it){ $s = $it['seat'] ?? null; if ($s!==null && is_numeric($s)){ $si=(int)$s; if ($si>=0 && $si<$capacity && $seatMap[$si]===null) $seatMap[$si]=$it; else $pending[]=$it; } else { $pending[]=$it; } } for ($fi=0,$pi=0; $fi<$capacity && $pi= 30 && $a <= 130) || ($a >= 230 && $a <= 315); @endphp
{{ $name }}
@for($i=0; $i<$topCount; $i++) @php $x = $topXs[$i] ?? 0; $occ = $seatMap[$i] ?? null; @endphp
@if($occ)
avatar
@php $nameWords = preg_split('/\s+/', (string)($occ['label'] ?? ''), -1, PREG_SPLIT_NO_EMPTY); @endphp @if(!empty($nameWords))
@foreach($nameWords as $w) {{ $w }} @endforeach
@endif
@else {{ $i+1 }} @endif
@endfor @for($j=0; $j<$bottomCount; $j++) @php $x = $bottomXs[$j] ?? 0; $global = $topCount + $j; $occ = $seatMap[$global] ?? null; @endphp
@if($occ)
avatar
@php $nameWords = preg_split('/\s+/', (string)($occ['label'] ?? ''), -1, PREG_SPLIT_NO_EMPTY); @endphp @if(!empty($nameWords))
@foreach($nameWords as $w) {{ $w }} @endforeach
@endif
@else {{ $global+1 }} @endif
@endfor
@endif @endforeach