@extends('layouts.app') @section('titulo','Orden de trabajo') @section('contenido') @php $editando = (bool) $orden->id; @endphp

{{ $editando?'Editar':'Nueva' }} orden ({{ ucfirst($orden->clase) }})

@csrf @if($editando) @method('PUT') @endif
{{-- ===== Conclusiones y recomendaciones (siempre visible) ===== --}}
Conclusiones y recomendaciones
Aparecen en el informe técnico. Recomendado llenarlos al cerrar la OT.
{{-- ===== Análisis de falla y causa raíz (solo correctivas) ===== --}}
Análisis de falla y causa raíz — solo correctivas
Cancelar
@push('scripts_inline') (function () { const planSel = document.querySelector('select[name="plan_id"]'); if (!planSel) return; const areaSel = document.querySelector('select[name="area_id"]'); const equipoSel = document.querySelector('select[name="equipo_id"]'); const respSel = document.querySelector('select[name="responsable_id"]'); const setVal = (sel, val) => { if (!sel || val === '' || val == null) return; if (sel.tomselect) sel.tomselect.setValue(String(val), true); else sel.value = String(val); }; const llenar = () => { const opt = planSel.options[planSel.selectedIndex]; if (!opt || !opt.value) return; setVal(areaSel, opt.dataset.area); setVal(equipoSel, opt.dataset.equipo); if (respSel && !respSel.value && opt.dataset.responsable) { setVal(respSel, opt.dataset.responsable); } }; planSel.addEventListener('change', llenar); })(); // === Auto-rellenar horometro_inicio según equipo + fecha programada (hora 08:00) === function calcularHorometroInicio(forzar = false) { const equipoSel = document.querySelector('select[name="equipo_id"]'); const fechaInput = document.querySelector('input[name="fecha_programada"]'); const horoInput = document.getElementById('horometroInicio'); const hint = document.getElementById('horometroHint'); if (!equipoSel || !fechaInput || !horoInput) return; const equipoId = equipoSel.value; const fecha = fechaInput.value; if (!equipoId || !fecha) return; // Si el usuario ya escribió algo manualmente, no sobrescribir (a menos que sea recálculo forzado) if (!forzar && horoInput.value !== '' && horoInput.dataset.auto !== '1') return; const url = '{{ route('ordenes.horometro-estimado') }}?equipo_id=' + encodeURIComponent(equipoId) + '&fecha=' + encodeURIComponent(fecha); fetch(url, { headers: { 'Accept': 'application/json' } }) .then(r => r.json()) .then(data => { if (data.horometro !== null && data.horometro !== undefined) { horoInput.value = data.horometro; horoInput.dataset.auto = '1'; hint.innerHTML = ' ' + data.fecha_calculada + ' · ' + data.horas_dia + ' h/d · ref. ' + data.fecha_referencia; } else if (data.mensaje) { hint.innerHTML = ' ' + data.mensaje; } }) .catch(() => { hint.textContent = ''; }); } // Marcar input como editado manualmente si el usuario lo cambia document.getElementById('horometroInicio')?.addEventListener('input', e => { e.target.dataset.auto = '0'; }); // Disparar cálculo cuando cambia equipo o fecha ['equipo_id', 'fecha_programada'].forEach(name => { const el = document.querySelector('[name="' + name + '"]'); if (el) el.addEventListener('change', () => calcularHorometroInicio(false)); }); // Cálculo inicial si ya hay equipo y fecha y el campo está vacío window.addEventListener('DOMContentLoaded', () => { const horoInput = document.getElementById('horometroInicio'); if (horoInput && horoInput.value === '') calcularHorometroInicio(false); }); @endpush @endsection