@php $fmtH = function ($v) { if ($v === null || $v === '') { return ''; } if ($v instanceof \DateTimeInterface) { return $v->format('H:i'); } return substr((string) $v, 0, 5); }; $catOA = function ($u) { $c = mb_strtolower((string) ($u->contrato_categoria ?? '')); if (str_contains($c, 'ayud')) { return 'A'; } return 'O'; }; $lugar = $parte->lugar; $filasMat = collect(); foreach ($parte->registrosTrabajo as $reg) { foreach ($reg->materialesUtilizados as $mu) { $filasMat->push([ 'cod' => $mu->material->codigo_sku ?? '', 'nom' => $mu->material->nombre ?? '', 'ud' => $mu->cantidad_utilizada, ]); } } foreach ($parte->materialesAdicionales as $ad) { $filasMat->push([ 'cod' => $ad->material->codigo_sku ?? '', 'nom' => $ad->material->nombre ?? '', 'ud' => $ad->cantidad, ]); } $filasMatMostrar = $filasMat ->filter(function ($f) { $cod = trim((string) ($f['cod'] ?? '')); $nom = trim((string) ($f['nom'] ?? '')); $ud = $f['ud'] ?? null; return $cod !== '' || $nom !== '' || ($ud !== '' && $ud !== null); }) ->take(20) ->values(); $trabajoTexto = $parte->registrosTrabajo ->map(fn ($r) => trim((string) $r->descripcion_trabajo)) ->filter() ->unique() ->implode("\n"); $numParteFmt = str_pad((string) $parte->id, 4, '0', STR_PAD_LEFT); $empresaLineaDir = $empresa ? trim(implode(', ', array_filter([ $empresa->direccion, trim(implode(' ', array_filter([$empresa->cp, $empresa->poblacion]))), $empresa->provincia, ]))) : ''; $empresaTels = ($empresa && $empresa->telefono) ? $empresa->telefono : ''; $a4HuecosOperariosExtra = 2; @endphp
@if($empresa)

{{ strtoupper($empresa->nombre_comercial) }}

@if($empresa->razon_social && strcasecmp($empresa->razon_social, $empresa->nombre_comercial) !== 0)

{{ $empresa->razon_social }}

@endif

@if($empresa->nif) C.I.F. {{ $empresa->nif }}
@endif @if($empresaLineaDir !== '') {{ $empresaLineaDir }}
@endif @if($empresaTels !== '' || $empresa->email || filled($empresa->sitio_web ?? null)) @if($empresaTels !== '')T. {{ $empresaTels }}@endif @if($empresa->email)@if($empresaTels !== '') · @endif{{ $empresa->email }}@endif @if(filled($empresa->sitio_web ?? null))@if($empresaTels !== '' || $empresa->email) · @endif{{ $empresa->sitio_web }}@endif @endif

@else

EMPRESA

@endif
FECHA {{ $parte->fecha?->format('d/m/Y') ?? '—' }}
REF. {{ $numParteFmt }}
CONTROL @php $estadoTxt = trim((string) ($parte->estado ?? '')); $controlTxt = $estadoTxt !== '' ? $estadoTxt : ''; if (!empty($parte->fecha_verificacion)) { $controlTxt = 'Verificado'; } @endphp @if($controlTxt !== '') {{ $controlTxt }} @else   @endif

PARTE DE TRABAJO

Nº {{ $numParteFmt }}

CLIENTE {{ $lugar->nombre ?? '—' }} D.N.I./N.I.F.  
DIRECCIÓN {{ $parte->direccion ?: ($lugar->direccion ?? '') }} TELEF. {{ $lugar->telefono ?? '' }}
LOCALIDAD {{ $parte->poblacion ?: ($lugar->poblacion ?? '') }} CLAVE {{ $lugar->tipo ?? ($lugar->descripcion ?? '') }}

Trabajo realizado

{{ $trabajoTexto }}

Observaciones

{{ $parte->observaciones }}

Materiales

@forelse($filasMatMostrar as $fila) @empty @endforelse
Cod. Descripción Ud.
{{ $fila['cod'] }} {{ $fila['nom'] }} {{ $fila['ud'] !== '' && $fila['ud'] !== null ? $fila['ud'] : '' }}
Sin materiales registrados.

Horas de trabajo

@forelse($parte->registrosTrabajo as $registro) @empty @endforelse @for($i = $parte->registrosTrabajo->count(); $i < $parte->registrosTrabajo->count() + $a4HuecosOperariosExtra; $i++) @for($j = 0; $j < 7; $j++) @endfor @endfor
Operario Cat.
(O)/(A)
Mañana Tarde Total
horas
Empieza Termina Empieza Termina
{{ $registro->user?->nombreCompleto() ?? '—' }} {{ $catOA($registro->user) }} {{ $fmtH($registro->entrada_manana) }} {{ $fmtH($registro->salida_manana) }} {{ $fmtH($registro->entrada_tarde) }} {{ $fmtH($registro->salida_tarde) }} {{ number_format((float) $registro->horas_laborales, 2, ',', '') }}
Sin registros de trabajo.
 

Firmas