@extends('layouts.app') @section('titulo','Órdenes') @section('contenido') @php // Códigos de estado que protegen la OT de borrado $protegidos = ['EJE','APR']; @endphp

Órdenes de trabajo {{ $clase ? '— '.ucfirst($clase) : '' }} {{ $registros->total() }} en total

@can('ordenes.crear') Nueva @endcan
@if($clase)@endif
{{-- Barra de acciones masivas (visible solo cuando hay selección) --}}
0 seleccionada(s) · 0 protegidas
@csrf
@forelse($registros as $o) @php $estaProtegida = in_array(optional($o->estado)->codigo, $protegidos); @endphp @empty @endforelse
CódigoClaseEquipoÁreaProgramada EstadoPrioridadResponsable Costo
{{ $o->codigo }} @if($estaProtegida)@endif {{ ucfirst($o->clase) }} {{ optional($o->equipo)->nombre }} {{ optional($o->area)->nombre }} {{ $o->fecha_programada?->format('d/m/Y') }} @if($o->estado){{ $o->estado->nombre }}@endif @if($o->prioridad){{ $o->prioridad->nombre }}@endif {{ optional($o->responsable)->nombre_completo }} {{ number_format($o->costo_total,2) }}
Sin órdenes
Mostrando {{ $registros->firstItem() ?? 0 }}–{{ $registros->lastItem() ?? 0 }} de {{ $registros->total() }} {{ $registros->links() }}
{{-- Modal de confirmación --}} @push('scripts_inline') const selectAll = document.getElementById('selectAll'); const checks = document.querySelectorAll('.chk-ot'); const barra = document.getElementById('barraAcciones'); const contadorSel = document.getElementById('contadorSel'); const contadorProt = document.getElementById('contadorProt'); function actualizarBarra() { const seleccionadas = [...checks].filter(c => c.checked); const total = seleccionadas.length; const protegidas = seleccionadas.filter(c => c.dataset.protegida === '1').length; contadorSel.textContent = total; if (protegidas > 0) { contadorProt.textContent = protegidas + ' protegida(s)'; contadorProt.classList.remove('d-none'); } else { contadorProt.classList.add('d-none'); } barra.classList.toggle('d-none', total === 0); } function limpiarSeleccion() { checks.forEach(c => c.checked = false); selectAll.checked = false; actualizarBarra(); } selectAll.addEventListener('change', () => { checks.forEach(c => c.checked = selectAll.checked); actualizarBarra(); }); checks.forEach(c => c.addEventListener('change', () => { selectAll.checked = [...checks].every(c => c.checked); actualizarBarra(); })); // Cuando se abre el modal, calcular cuántas se eliminarán vs protegidas document.getElementById('modalEliminar').addEventListener('show.bs.modal', () => { const sel = [...checks].filter(c => c.checked); const total = sel.length; const protegidas = sel.filter(c => c.dataset.protegida === '1'); const eliminables = sel.filter(c => c.dataset.protegida !== '1'); document.getElementById('modalContador').textContent = total; const block = document.getElementById('modalProtegidasBlock'); const lista = document.getElementById('modalProtegidasLista'); if (protegidas.length > 0) { block.classList.remove('d-none'); document.getElementById('modalProtegidasCount').textContent = protegidas.length; lista.innerHTML = ''; protegidas.slice(0, 8).forEach(p => { const li = document.createElement('li'); li.innerHTML = `${p.dataset.codigo} — ${p.dataset.estadoNombre}`; lista.appendChild(li); }); if (protegidas.length > 8) { const li = document.createElement('li'); li.textContent = `... y ${protegidas.length - 8} más`; lista.appendChild(li); } } else { block.classList.add('d-none'); } const elimBlock = document.getElementById('modalEliminarBlock'); if (eliminables.length > 0) { elimBlock.classList.remove('d-none'); document.getElementById('modalEliminarCount').textContent = eliminables.length; } else { elimBlock.classList.add('d-none'); } // Si todas son protegidas, deshabilitar el botón const btn = document.getElementById('btnConfirmarEliminar'); btn.disabled = eliminables.length === 0; }); @endpush @endsection