231 lines
13 KiB
Plaintext
231 lines
13 KiB
Plaintext
<%# app/views/consolidacoes/show.html.erb %>
|
||
<% content_for :title, @consolidacao.nome %>
|
||
<% formas_pagamento = [['PIX', 'pix'], ['Transferência', 'transferencia'], ['Dinheiro', 'dinheiro']] %>
|
||
<% pode_pagar = @consolidacao.finalizada? && policy(@consolidacao).registrar_pagamento? %>
|
||
|
||
<div class="max-w-4xl mx-auto">
|
||
|
||
<div class="mb-6">
|
||
<%= link_to '← Consolidações', consolidacoes_path, class: 'text-gray-500 hover:text-orange-500 text-sm' %>
|
||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-3 mt-2">
|
||
<div>
|
||
<div class="flex items-center gap-3 flex-wrap">
|
||
<h1 class="text-2xl font-bold text-white"><%= @consolidacao.nome %></h1>
|
||
<%= badge_status(@consolidacao.status) %>
|
||
<% if @consolidacao.finalizada? %><%= badge_pagamento(@consolidacao.status_pagamento) %><% end %>
|
||
</div>
|
||
<p class="text-gray-400 text-sm mt-1">
|
||
📅 <%= l @consolidacao.data_inicio, format: :short %> → <%= l @consolidacao.data_fim, format: :short %>
|
||
· Criada por <%= @consolidacao.criador.nome_display %>
|
||
<% if @consolidacao.finalizada? %>
|
||
· Finalizada por <%= @consolidacao.finalizador&.nome_display %> em <%= l @consolidacao.finalizado_em, format: :short %>
|
||
<% end %>
|
||
</p>
|
||
<% if @consolidacao.operacoes.present? %>
|
||
<p class="text-gray-400 text-sm mt-1">
|
||
🗂️ Operação:
|
||
<% @consolidacao.operacoes_label.each do |op| %>
|
||
<span class="inline-block bg-[#2a2a2a] text-gray-200 rounded-full px-2.5 py-0.5 text-xs"><%= op %></span>
|
||
<% end %>
|
||
</p>
|
||
<% end %>
|
||
</div>
|
||
<div class="flex gap-2">
|
||
<% if @consolidacao.rascunho? %>
|
||
<%= link_to '✏️ Continuar validação', wizard_consolidacao_path(@consolidacao),
|
||
class: 'bg-orange-500 hover:bg-orange-600 text-black font-bold px-5 py-3 rounded-lg min-h-[48px] flex items-center' %>
|
||
<% end %>
|
||
<%= link_to '📊 Relatório financeiro', gerar_pdf_financeiro_consolidacao_path(@consolidacao),
|
||
data: { turbo: false },
|
||
class: 'bg-[#1a1a1a] hover:bg-[#2a2a2a] text-white border border-orange-500 font-semibold px-4 py-3 rounded-lg min-h-[48px] flex items-center' %>
|
||
<% if policy(@consolidacao).destroy? && !@consolidacao.arquivada? %>
|
||
<%= button_to '📁 Arquivar', arquivar_consolidacao_path(@consolidacao), method: :post,
|
||
form: { data: { turbo_confirm: 'Arquivar esta consolidação? Ela não será excluída, apenas movida para o arquivo.' } },
|
||
class: 'text-gray-400 hover:text-white border border-[#2a2a2a] px-4 py-3 rounded-lg min-h-[48px]' %>
|
||
<% end %>
|
||
</div>
|
||
</div>
|
||
|
||
<%# ── Pagamento da operação inteira ─────────────────────── %>
|
||
<% if pode_pagar %>
|
||
<div class="flex flex-col sm:flex-row sm:items-center gap-2 mt-4 bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-4">
|
||
<span class="text-gray-400 text-sm font-medium mr-1">💵 Operação inteira:</span>
|
||
<% if @consolidacao.status_pagamento != :pago %>
|
||
<%= form_with url: registrar_pagamento_consolidacao_path(@consolidacao), method: :post,
|
||
data: { turbo_confirm: 'Marcar TODOS os motoristas pendentes desta consolidação como PAGOS?' },
|
||
class: 'flex items-center gap-2' do |f| %>
|
||
<%= f.select :forma_pagamento, options_for_select(formas_pagamento, 'pix'),
|
||
{}, class: 'bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-2.5 text-sm' %>
|
||
<%= f.submit '💰 Marcar tudo como pago',
|
||
class: 'bg-green-600 hover:bg-green-700 text-white font-bold px-4 py-2.5 rounded-lg text-sm cursor-pointer min-h-[44px]' %>
|
||
<% end %>
|
||
<% end %>
|
||
<% if @consolidacao.status_pagamento != :pendente %>
|
||
<%= button_to '↩ Estornar tudo', cancelar_pagamento_consolidacao_path(@consolidacao), method: :post,
|
||
data: { turbo_confirm: 'Estornar o pagamento de TODOS os motoristas?' },
|
||
class: 'text-gray-400 hover:text-white border border-[#2a2a2a] px-4 py-2.5 rounded-lg text-sm min-h-[44px]' %>
|
||
<% end %>
|
||
</div>
|
||
<% end %>
|
||
</div>
|
||
|
||
<%# Total geral %>
|
||
<div class="bg-[#1a1a1a] border border-orange-500 rounded-xl p-6 mb-6 text-center">
|
||
<p class="text-gray-400 text-sm">Valor total da consolidação</p>
|
||
<p class="text-orange-500 font-black text-4xl"><%= moeda(@consolidacao.valor_total) %></p>
|
||
</div>
|
||
|
||
<%# Motoristas + botões de PDF %>
|
||
<h2 class="text-white font-bold text-lg mb-3">👥 Motoristas</h2>
|
||
<div class="space-y-3">
|
||
<% @motoristas.each do |cm| %>
|
||
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-5">
|
||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||
<div>
|
||
<div class="flex items-center gap-2 flex-wrap">
|
||
<p class="text-white font-bold text-lg"><%= cm.motorista_nome %></p>
|
||
<% if @consolidacao.finalizada? %>
|
||
<%= badge_pagamento(cm.pago? ? :pago : :pendente) %>
|
||
<% end %>
|
||
</div>
|
||
<p class="text-orange-500 font-black text-xl"><%= moeda(cm.valor_total) %></p>
|
||
<% if cm.pago? %>
|
||
<p class="text-green-400 text-xs mt-1">
|
||
💰 Pago em <%= l cm.pago_em, format: :short %>
|
||
<% if cm.forma_pagamento.present? %>via <%= cm.forma_pagamento.humanize %><% end %>
|
||
<% if cm.pagador.present? %>por <%= cm.pagador.nome_display %><% end %>
|
||
</p>
|
||
<% end %>
|
||
|
||
<% if pode_pagar %>
|
||
<div class="mt-2">
|
||
<% if cm.pago? %>
|
||
<%= button_to '↩ Estornar pagamento', cancelar_pagamento_consolidacao_path(@consolidacao, consolidacao_motorista_id: cm.id), method: :post,
|
||
data: { turbo_confirm: "Estornar o pagamento de #{cm.motorista_nome}?" },
|
||
class: 'text-gray-400 hover:text-white border border-[#2a2a2a] px-3 py-2 rounded-lg text-xs min-h-[40px]' %>
|
||
<% else %>
|
||
<%= form_with url: registrar_pagamento_consolidacao_path(@consolidacao, consolidacao_motorista_id: cm.id), method: :post,
|
||
data: { turbo_confirm: "Marcar #{cm.motorista_nome} como pago?" },
|
||
class: 'flex items-center gap-2' do |f| %>
|
||
<%= f.select :forma_pagamento, options_for_select(formas_pagamento, 'pix'),
|
||
{}, class: 'bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-2 py-2 text-xs' %>
|
||
<%= f.submit '💰 Marcar pago',
|
||
class: 'bg-green-600 hover:bg-green-700 text-white font-bold px-3 py-2 rounded-lg text-xs cursor-pointer min-h-[40px]' %>
|
||
<% end %>
|
||
<% end %>
|
||
</div>
|
||
<% end %>
|
||
</div>
|
||
<div class="flex flex-wrap gap-2">
|
||
<%# Preview abre modal %>
|
||
<button onclick="abrirPreview('<%= preview_holerite_consolidacao_path(@consolidacao, motorista: cm.motorista_nome) %>')"
|
||
class="bg-[#0a0a0a] hover:bg-[#2a2a2a] text-white border border-orange-500 font-semibold px-4 py-3 rounded-lg text-sm min-h-[48px]">
|
||
👁️ Ver antes de gerar
|
||
</button>
|
||
<%= link_to '📄 Relatório Individual',
|
||
gerar_pdf_relatorio_consolidacao_path(@consolidacao, motorista: cm.motorista_nome),
|
||
data: { turbo: false },
|
||
class: 'bg-orange-800 hover:bg-orange-700 text-white font-semibold px-4 py-3 rounded-lg text-sm min-h-[48px] flex items-center' %>
|
||
<%= link_to '🧾 Gerar Holerite',
|
||
gerar_pdf_holerite_consolidacao_path(@consolidacao, motorista: cm.motorista_nome),
|
||
data: { turbo: false },
|
||
class: 'bg-orange-500 hover:bg-orange-600 text-black font-bold px-4 py-3 rounded-lg text-sm min-h-[48px] flex items-center' %>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<% end %>
|
||
</div>
|
||
|
||
<%# ── Apontamentos manuais (notas que chegaram por fora) ─────────────── %>
|
||
<% if @apontamentos.present? %>
|
||
<% pode_editar = !(@consolidacao.finalizada? && current_user.operador?) %>
|
||
<h2 class="text-white font-bold text-lg mt-8 mb-3">➕ Apontamentos manuais</h2>
|
||
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl overflow-hidden">
|
||
<table class="w-full text-sm">
|
||
<thead class="bg-[#0a0a0a] text-gray-400">
|
||
<tr>
|
||
<th class="text-left px-4 py-3">Nota / Motorista</th>
|
||
<th class="text-left px-4 py-3">Classificações</th>
|
||
<th class="text-right px-4 py-3">Valor</th>
|
||
<% if pode_editar %><th class="px-4 py-3"></th><% end %>
|
||
</tr>
|
||
</thead>
|
||
<tbody class="divide-y divide-[#2a2a2a]">
|
||
<% @apontamentos.each do |(motorista, _tracking), pilares| %>
|
||
<% entrega = pilares.first.entrega_original %>
|
||
<% total = pilares.sum { |p| p.desconto? ? -p.valor_aplicado : p.valor_aplicado } %>
|
||
<tr>
|
||
<td class="px-4 py-3">
|
||
<p class="text-white font-bold">NF <%= entrega&.numero_nf || '—' %></p>
|
||
<p class="text-gray-400 text-xs"><%= motorista %><% if entrega&.vehicle.present? %> · <%= entrega.vehicle %><% end %></p>
|
||
</td>
|
||
<td class="px-4 py-3">
|
||
<div class="flex flex-wrap gap-1">
|
||
<% pilares.each do |p| %>
|
||
<span class="<%= p.tipo_cor[:bg] %> <%= p.tipo_cor[:text] %> px-2 py-1 rounded text-xs font-bold"><%= p.tipo_cor[:label] %></span>
|
||
<% end %>
|
||
</div>
|
||
</td>
|
||
<td class="px-4 py-3 text-right font-bold <%= total.negative? ? 'text-red-400' : 'text-white' %>"><%= moeda(total) %></td>
|
||
<% if pode_editar %>
|
||
<td class="px-4 py-3 text-right">
|
||
<%= button_to '✕ Remover',
|
||
remover_apontamento_consolidacao_consolidacao_entregas_path(@consolidacao, tracking_id: pilares.first.tracking_id, motorista: motorista),
|
||
method: :delete,
|
||
form: { data: { turbo_confirm: "Remover o apontamento da NF #{entrega&.numero_nf} de #{motorista}?" } },
|
||
class: 'text-gray-400 hover:text-red-400 border border-[#2a2a2a] hover:border-red-500/50 px-3 py-2 rounded-lg text-xs min-h-[40px]' %>
|
||
</td>
|
||
<% end %>
|
||
</tr>
|
||
<% end %>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<% end %>
|
||
</div>
|
||
|
||
<%# ── Modal de Preview ─────────────────────────────────── %>
|
||
<div id="modal-preview" class="fixed inset-0 bg-black/80 z-50 hidden items-center justify-center p-4">
|
||
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-2xl max-w-2xl w-full max-h-[85vh] flex flex-col">
|
||
<div class="flex items-center justify-between px-6 py-4 border-b border-[#2a2a2a]">
|
||
<h3 class="text-white font-bold">👁️ Pré-visualização do Holerite</h3>
|
||
<button onclick="fecharPreview()" class="text-gray-400 hover:text-white text-2xl min-w-[44px] min-h-[44px]">✕</button>
|
||
</div>
|
||
<div id="modal-preview-conteudo" class="overflow-y-auto p-6 flex-1">
|
||
<div class="flex justify-center py-10"><div class="spinner w-10 h-10"></div></div>
|
||
</div>
|
||
<div class="flex gap-3 px-6 py-4 border-t border-[#2a2a2a]">
|
||
<a id="modal-confirmar" href="#" data-turbo="false"
|
||
class="flex-1 bg-orange-500 hover:bg-orange-600 text-black font-bold py-3 rounded-lg text-center min-h-[48px] flex items-center justify-center">
|
||
✓ Confirmar e baixar PDF
|
||
</a>
|
||
<button onclick="fecharPreview()"
|
||
class="px-6 py-3 text-gray-400 hover:text-white border border-[#2a2a2a] rounded-lg min-h-[48px]">
|
||
← Voltar
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
async function abrirPreview(url) {
|
||
const modal = document.getElementById('modal-preview');
|
||
const conteudo = document.getElementById('modal-preview-conteudo');
|
||
modal.classList.remove('hidden');
|
||
modal.classList.add('flex');
|
||
conteudo.innerHTML = '<div class="flex justify-center py-10"><div class="spinner w-10 h-10"></div></div>';
|
||
|
||
const resp = await fetch(url);
|
||
conteudo.innerHTML = await resp.text();
|
||
|
||
// O link de confirmar aponta para o PDF do mesmo motorista
|
||
document.getElementById('modal-confirmar').href =
|
||
url.replace('preview_holerite', 'gerar_pdf_holerite');
|
||
}
|
||
function fecharPreview() {
|
||
const modal = document.getElementById('modal-preview');
|
||
modal.classList.add('hidden');
|
||
modal.classList.remove('flex');
|
||
}
|
||
</script>
|