<%# app/views/operacoes_dashboard/_espelho.html.erb %> <%# Tabela espelho da planilha da operação: uma linha por NF com resultado, ocorrência, motorista etc. Busca textual (param q) e paginação (param pg) são server-side; o restante da URL (modo/operação/período/cross-filters) é preservado nos links e no form. %> <% pg_path = ->(n) { operacoes_dashboard_path(request.query_parameters.merge('pg' => n)) } %> <% resultado_badge = ->(status) { if status == 'completed' ['Entregue', 'bg-green-500/10 text-green-400 border-green-500/30'] elsif Entrega::STATUS_FALHA.include?(status) ['Falha', 'bg-red-500/10 text-red-400 border-red-500/30'] else ['Pendente', 'bg-yellow-500/10 text-yellow-400 border-yellow-500/30'] end } %>

📋 Planilha da operação

Espelho por NF — pesquise por nota, motorista, unidade, ocorrência, veículo...

<% request.query_parameters.except('q', 'pg').each do |k, v| %> <% end %>
🔎
<% if @busca.present? %> <%= link_to '✕ Limpar', operacoes_dashboard_path(request.query_parameters.except('q', 'pg')), data: { turbo: false }, class: 'text-xs text-orange-400 hover:text-orange-300 whitespace-nowrap' %> <% end %>
<% if @espelho_linhas.blank? %>

<%= @busca.present? ? %(Nenhuma entrega encontrada para "#{@busca}".) : 'Nenhuma entrega para exibir.' %>

<% else %>
<% if @modo == 'global' %> <% end %> <% @espelho_linhas.each do |r| %> <% rotulo, badge_css = resultado_badge.(r['status']) %> <% data = r['checkout'] || r['planned_date'] %> <% endereco = r['endereco_completo'].presence || r['address'].presence %> <% if @modo == 'global' %> <% end %> <% end %>
Data NFOperaçãoDestinatário Unidade Motorista Veículo Resultado Ocorrência Status
<%= data.respond_to?(:strftime) ? data.strftime('%d/%m/%y %H:%M') : data.to_s.first(16) %> <%= r['reference_id'] %><%= r['operacao'] %> <%= (r['nome_completo'].presence || '—').truncate(28) %> <%= r['contact_name'].to_s.truncate(24).presence || '—' %> <%= r['driver'].presence || '—' %> <%= r['vehicle'].presence || '—' %> <%= rotulo %> <%= r['observation'].to_s.truncate(32).presence || '—' %> <%= r['status_gade'].presence || '—' %>
<%# Paginação: « 1 … janela em torno da atual … última » %>

<%= (@espelho_pagina - 1) * OperacoesDashboardController::ESPELHO_POR_PAGINA + 1 %>–<%= [(@espelho_pagina) * OperacoesDashboardController::ESPELHO_POR_PAGINA, @espelho_total].min %> de <%= @espelho_total %> entregas

<% if @espelho_paginas > 1 %>
<% if @espelho_pagina > 1 %> <%= link_to '‹', pg_path.(@espelho_pagina - 1), data: { turbo: false }, class: 'px-3 py-1.5 rounded-lg text-xs font-semibold bg-[#0a0a0a] text-gray-400 border border-white/5 hover:text-white' %> <% end %> <% janela = ([1, @espelho_pagina - 2].max..[@espelho_paginas, @espelho_pagina + 2].min).to_a %> <% paginas = ([1] + janela + [@espelho_paginas]).uniq %> <% anterior = 0 %> <% paginas.each do |p| %> <% if p > anterior + 1 %> <% end %> <% anterior = p %> <% if p == @espelho_pagina %> <%= p %> <% else %> <%= link_to p, pg_path.(p), data: { turbo: false }, class: 'px-3 py-1.5 rounded-lg text-xs font-semibold bg-[#0a0a0a] text-gray-400 border border-white/5 hover:text-white' %> <% end %> <% end %> <% if @espelho_pagina < @espelho_paginas %> <%= link_to '›', pg_path.(@espelho_pagina + 1), data: { turbo: false }, class: 'px-3 py-1.5 rounded-lg text-xs font-semibold bg-[#0a0a0a] text-gray-400 border border-white/5 hover:text-white' %> <% end %>
<% end %>
<% end %>