Criação da visão geral da consolidação por motorista

This commit is contained in:
2026-08-26 11:15:52 -03:00
parent 8d24a57579
commit cd99a22553
12 changed files with 841 additions and 3 deletions

View File

@@ -6,6 +6,8 @@
<div class="flex items-center justify-between mb-6">
<h1 class="text-2xl font-bold text-white flex items-center gap-2"><%= icone :consolidacoes, espaco: false %> Consolidações</h1>
<div class="flex gap-2">
<%= link_to rotulo(:motorista, 'Totais por motorista', cor: nil), totais_consolidacoes_path,
class: 'text-gray-400 hover:text-white border border-[#2a2a2a] px-4 py-3 rounded-lg min-h-[48px] flex items-center transition-colors' %>
<%= link_to rotulo(:arquivadas, 'Arquivadas', cor: nil), arquivadas_consolidacoes_path,
class: 'text-gray-400 hover:text-white border border-[#2a2a2a] px-4 py-3 rounded-lg min-h-[48px] flex items-center transition-colors' %>
<% if policy(Consolidacao).create? %>

View File

@@ -0,0 +1,191 @@
<%# app/views/consolidacoes/totais.html.erb — Total por motorista no período %>
<% content_for :title, 'Totais por motorista' %>
<div class="flex flex-wrap items-center justify-between gap-3 mb-6">
<div>
<h1 class="text-2xl font-bold text-white flex items-center gap-2"><%= icone :motorista, espaco: false %> Totais por motorista</h1>
<p class="text-gray-400 text-sm mt-0.5">
Consolidações <%= @incluir_rascunhos ? 'de qualquer status' : 'finalizadas' %>
com período dentro de <%= l @inicio, format: :short %> → <%= l @fim, format: :short %>
</p>
</div>
<div class="flex flex-wrap gap-2">
<%= link_to rotulo(:consolidacoes, 'Consolidações', cor: nil), consolidacoes_path,
class: 'text-gray-400 hover:text-white border border-[#2a2a2a] px-4 py-3 rounded-lg min-h-[48px] flex items-center transition-colors' %>
<%= link_to rotulo(:baixar, 'Baixar relatório (PDF)', cor: nil),
totais_pdf_consolidacoes_path(inicio: @inicio, fim: @fim, rascunhos: (@incluir_rascunhos ? '1' : nil), motorista: @motorista),
data: { turbo: false },
class: 'bg-orange-500 hover:bg-orange-600 text-black font-bold px-5 py-3 rounded-lg min-h-[48px] flex items-center transition-colors' %>
</div>
</div>
<%# ── Filtros ──────────────────────────────────────────── %>
<%= form_with url: totais_consolidacoes_path, method: :get,
class: 'bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-4 mb-6 flex flex-wrap items-center gap-3' do |f| %>
<%# O motorista clicado viaja junto para o filtro não fechar o drill-down. %>
<%= hidden_field_tag :motorista, @motorista if @motorista %>
<%= f.date_field :inicio, value: @inicio.strftime('%Y-%m-%d'),
class: 'flex-1 basis-36 max-w-[13rem] min-w-0 bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-2.5' %>
<%= f.date_field :fim, value: @fim.strftime('%Y-%m-%d'),
class: 'flex-1 basis-36 max-w-[13rem] min-w-0 bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-2.5' %>
<label class="flex items-center gap-2 text-sm text-gray-300 whitespace-nowrap">
<%= check_box_tag :rascunhos, '1', @incluir_rascunhos, class: 'accent-orange-500' %>
Incluir rascunhos
</label>
<div class="flex gap-2 shrink-0">
<%= f.submit 'Filtrar', class: 'bg-orange-500 hover:bg-orange-600 text-black font-bold rounded-lg cursor-pointer px-5 py-2.5 whitespace-nowrap' %>
<%= link_to 'Limpar', totais_consolidacoes_path, class: 'px-4 py-2.5 text-gray-400 hover:text-white border border-[#2a2a2a] rounded-lg whitespace-nowrap' %>
</div>
<% end %>
<%# ── KPIs do período ──────────────────────────────────── %>
<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4 mb-6">
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-5">
<p class="text-gray-400 text-xs uppercase tracking-wide"><%= icone :dinheiro %> Total do período</p>
<p class="text-orange-500 font-black text-3xl mt-1 whitespace-nowrap"><%= moeda(@totais.total_geral) %></p>
<p class="text-gray-500 text-xs mt-1"><%= @totais.total_consolidacoes %> consolidação(ões) · <%= @totais.linhas.size %> motorista(s)</p>
</div>
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-5">
<p class="text-gray-400 text-xs uppercase tracking-wide"><%= icone :sucesso, cor: 'text-green-400' %> Pago</p>
<p class="text-green-400 font-black text-3xl mt-1 whitespace-nowrap"><%= moeda(@totais.total_pago) %></p>
</div>
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-5">
<p class="text-gray-400 text-xs uppercase tracking-wide"><%= icone :parcial, cor: 'text-amber-400' %> A pagar</p>
<p class="text-amber-400 font-black text-3xl mt-1 whitespace-nowrap"><%= moeda(@totais.total_pendente) %></p>
</div>
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-5">
<p class="text-gray-400 text-xs uppercase tracking-wide"><%= icone :ticket %> Média por motorista</p>
<p class="text-white font-black text-3xl mt-1 whitespace-nowrap">
<%= moeda(@totais.linhas.any? ? @totais.total_geral / @totais.linhas.size : 0) %>
</p>
</div>
</div>
<% if @totais.vazio? %>
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-12 text-center">
<p class="mb-4"><%= icone :vazio, tamanho: 'w-12 h-12', cor: 'text-gray-600', espaco: false %></p>
<p class="text-gray-400">Nenhuma consolidação <%= @incluir_rascunhos ? '' : 'finalizada ' %>com período dentro dessa faixa.</p>
<p class="text-gray-500 text-sm mt-1">Amplie o período ou marque "Incluir rascunhos".</p>
</div>
<% else %>
<%# ── Tabela: total por motorista (clique abre a composição) ── %>
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl overflow-hidden mb-6">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead class="bg-[#0a0a0a] text-gray-400 uppercase text-xs">
<tr>
<th class="text-left px-4 py-3">Motorista</th>
<th class="text-right px-4 py-3">Consolidações</th>
<th class="text-right px-4 py-3">Lançamentos</th>
<th class="text-right px-4 py-3">Pago</th>
<th class="text-right px-4 py-3">A pagar</th>
<th class="text-right px-4 py-3">Total</th>
</tr>
</thead>
<tbody>
<% @totais.linhas.each do |l| %>
<% aberto = @motorista == l[:motorista] %>
<tr class="border-t border-[#2a2a2a] <%= 'bg-orange-500/10' if aberto %> hover:bg-[#222]">
<%# O nome é um LINK de verdade (e não um <tr onclick>): abre/fecha
a composição daquele motorista e continua acessível pelo teclado. %>
<td class="px-4 py-3 whitespace-nowrap">
<%= link_to totais_consolidacoes_path(inicio: @inicio, fim: @fim,
rascunhos: (@incluir_rascunhos ? '1' : nil),
motorista: (aberto ? nil : l[:motorista])),
class: 'text-white font-semibold hover:text-orange-500 flex items-center gap-1' do %>
<%= icone(aberto ? :expandir : :avancar, cor: 'text-gray-500', espaco: false) %><%= l[:motorista] %>
<% end %>
</td>
<td class="px-4 py-3 text-right text-gray-300"><%= l[:consolidacoes] %></td>
<td class="px-4 py-3 text-right text-gray-300"><%= l[:lancamentos] %></td>
<td class="px-4 py-3 text-right text-green-400"><%= moeda(l[:valor_pago]) %></td>
<td class="px-4 py-3 text-right text-amber-400"><%= moeda(l[:valor_pendente]) %></td>
<td class="px-4 py-3 text-right text-orange-500 font-black whitespace-nowrap"><%= moeda(l[:valor_total]) %></td>
</tr>
<% end %>
</tbody>
<tfoot class="bg-[#0a0a0a] text-white font-bold">
<tr>
<td class="px-4 py-3">TOTAL</td>
<td class="px-4 py-3 text-right"><%= @totais.total_consolidacoes %></td>
<td class="px-4 py-3"></td>
<td class="px-4 py-3 text-right text-green-400"><%= moeda(@totais.total_pago) %></td>
<td class="px-4 py-3 text-right text-amber-400"><%= moeda(@totais.total_pendente) %></td>
<td class="px-4 py-3 text-right text-orange-500"><%= moeda(@totais.total_geral) %></td>
</tr>
</tfoot>
</table>
</div>
<div class="flex flex-wrap items-center justify-between gap-2 px-4 py-3 border-t border-[#2a2a2a]">
<p class="text-gray-500 text-xs">
<%= icone :dica %> Clique num motorista para ver as consolidações que compõem o total dele.
</p>
<%# PDF sem a composição de cada motorista — para períodos com muita gente,
quando só o resumo interessa. %>
<%= link_to 'Baixar só o resumo (PDF)',
totais_pdf_consolidacoes_path(inicio: @inicio, fim: @fim, rascunhos: (@incluir_rascunhos ? '1' : nil), detalhar: '0'),
data: { turbo: false },
class: 'text-gray-400 hover:text-orange-500 text-xs underline whitespace-nowrap' %>
</div>
</div>
<%# ── Drill-down: as consolidações que compõem o total ── %>
<% if @detalhe %>
<div class="bg-[#1a1a1a] border border-orange-500/40 rounded-xl p-5">
<div class="flex flex-wrap items-center justify-between gap-3 mb-4">
<div>
<h2 class="text-white font-bold text-lg flex items-center gap-2">
<%= icone :composicao, espaco: false %> Composição de <%= @motorista %>
</h2>
<p class="text-gray-400 text-sm mt-0.5">
<%= @detalhe.size %> consolidação(ões) no período ·
<span class="text-orange-500 font-bold"><%= moeda(@detalhe.sum { |cm| cm.valor_total || 0 }) %></span>
</p>
</div>
<div class="flex flex-wrap gap-2">
<%= link_to rotulo(:baixar, 'PDF deste motorista', cor: nil),
totais_pdf_consolidacoes_path(inicio: @inicio, fim: @fim, rascunhos: (@incluir_rascunhos ? '1' : nil), motorista: @motorista),
data: { turbo: false },
class: 'bg-orange-500 hover:bg-orange-600 text-black font-bold px-4 py-2.5 rounded-lg flex items-center' %>
<%= link_to rotulo(:fechar, 'Fechar', cor: nil),
totais_consolidacoes_path(inicio: @inicio, fim: @fim, rascunhos: (@incluir_rascunhos ? '1' : nil)),
class: 'text-gray-400 hover:text-white border border-[#2a2a2a] px-4 py-2.5 rounded-lg flex items-center' %>
</div>
</div>
<% if @detalhe.empty? %>
<p class="text-gray-400 text-sm">Nenhuma consolidação desse motorista neste período.</p>
<% end %>
<div class="space-y-3">
<% @detalhe.each do |cm| %>
<% c = cm.consolidacao %>
<%= link_to consolidacao_path(c),
class: 'block bg-[#0a0a0a] border border-[#2a2a2a] hover:border-orange-500 rounded-xl p-4 transition-colors' do %>
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-2">
<div>
<div class="flex items-center gap-2 flex-wrap">
<span class="text-white font-bold"><%= c.nome %></span>
<%= badge_status(c.status) %>
<%= badge_pagamento(cm.pago? ? :pago : :pendente) %>
</div>
<p class="text-gray-400 text-sm mt-1">
<%= icone :calendario %> <%= l c.data_inicio, format: :short %> → <%= l c.data_fim, format: :short %>
<% if cm.pago? %>
· <%= icone :dinheiro, cor: 'text-green-400' %> Pago em <%= l cm.pago_em.to_date, format: :short %>
<% if cm.forma_pagamento.present? %>via <%= cm.forma_pagamento.humanize %><% end %>
<% if cm.nota_fiscal.present? %>· NF <%= cm.nota_fiscal %><% end %>
<% end %>
</p>
</div>
<p class="text-orange-500 font-black text-2xl whitespace-nowrap"><%= moeda(cm.valor_total) %></p>
</div>
<% end %>
<% end %>
</div>
</div>
<% end %>
<% end %>

View File

@@ -43,12 +43,14 @@
<%# Consolidações — só quem pode consolidar (exclui o externo) %>
<% if current_user.pode_consolidar? %>
<%= nav_link_to 'Consolidações', consolidacoes_path, icon: :consolidacoes %>
<%= nav_link_to 'Totais por motorista', totais_consolidacoes_path, icon: :motorista %>
<%= nav_link_to 'Arquivadas', arquivadas_consolidacoes_path, icon: :arquivadas %>
<% end %>
<%# Motorista %>
<% if current_user.motorista? %>
<%= nav_link_to 'Meu Painel', motorista_dashboard_path, icon: :painel %>
<%= nav_link_to 'Meu total do período', motorista_totais_path, icon: :dinheiro %>
<% end %>
<%# Admin/Gerente — Configurações %>

View File

@@ -51,14 +51,18 @@
</p>
</div>
<%# Card 2 — Valor Consolidado (BRANCO) %>
<div class="bg-white rounded-2xl p-6">
<%# Card 2 — Valor Consolidado (BRANCO). Clicável: leva ao total POR PERÍODO,
com as consolidações que compõem o valor e o PDF do período. %>
<%= link_to motorista_totais_path, class: 'block bg-white rounded-2xl p-6 hover:ring-2 hover:ring-orange-500 transition' do %>
<p class="text-gray-600 font-bold uppercase tracking-wide flex items-center gap-2"><%= icone :sucesso, cor: 'text-green-600', espaco: false %> Valor fechado para pagamento</p>
<p class="text-black font-black text-4xl sm:text-5xl mt-2 leading-tight whitespace-nowrap"><%= moeda(@valor_consolidado) %></p>
<p class="text-gray-600 text-base mt-2">
Soma dos pagamentos já confirmados pela empresa
</p>
</div>
<p class="text-orange-600 font-bold text-base mt-3">
<%= icone :avancar, cor: 'text-orange-600' %> Ver por período e baixar o PDF
</p>
<% end %>
</div>
<%# ── Lista de consolidações ──────────────────────────── %>

View File

@@ -0,0 +1,95 @@
<%# app/views/motorista/dashboard/totais.html.erb — Meu total no período %>
<% content_for :title, 'Meu total no período' %>
<div class="max-w-2xl mx-auto">
<div class="flex items-center justify-between gap-3 mb-4">
<h1 class="text-2xl font-bold text-white">Meu total no período</h1>
<%= link_to rotulo(:voltar, 'Voltar', cor: nil), motorista_dashboard_path,
class: 'text-gray-300 hover:text-white border border-[#2a2a2a] px-4 py-3 rounded-xl min-h-[48px] flex items-center' %>
</div>
<%# ── Período ──────────────────────────────────────────── %>
<%= form_with url: motorista_totais_path, method: :get,
class: 'bg-[#1a1a1a] border border-[#2a2a2a] rounded-2xl p-4 mb-5 flex flex-wrap items-end gap-3' do |f| %>
<div class="flex-1 basis-40 min-w-0">
<label class="block text-gray-400 text-sm mb-1">De</label>
<%= f.date_field :inicio, value: @inicio.strftime('%Y-%m-%d'),
class: 'w-full bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-xl px-3 py-3 text-base' %>
</div>
<div class="flex-1 basis-40 min-w-0">
<label class="block text-gray-400 text-sm mb-1">Até</label>
<%= f.date_field :fim, value: @fim.strftime('%Y-%m-%d'),
class: 'w-full bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-xl px-3 py-3 text-base' %>
</div>
<%= f.submit 'Ver', class: 'bg-orange-500 hover:bg-orange-600 text-black font-bold rounded-xl cursor-pointer px-6 py-3 min-h-[48px]' %>
<% end %>
<%# ── Total fechado ────────────────────────────────────── %>
<div class="bg-white rounded-2xl p-6 mb-5">
<p class="text-gray-600 font-bold uppercase tracking-wide flex items-center gap-2">
<%= icone :sucesso, cor: 'text-green-600', espaco: false %> Total fechado no período
</p>
<p class="text-gray-600 text-sm mt-1"><%= icone :calendario, cor: 'text-gray-500' %> <%= l @inicio, format: :short %> a <%= l @fim, format: :short %></p>
<p class="text-black font-black text-4xl sm:text-5xl mt-2 leading-tight whitespace-nowrap"><%= moeda(@totais.total_geral) %></p>
<div class="flex flex-wrap gap-x-6 gap-y-1 mt-3 text-base">
<span class="text-green-700 font-bold"><%= icone :dinheiro, cor: 'text-green-700' %> Já pago: <%= moeda(@totais.total_pago) %></span>
<span class="text-amber-700 font-bold"><%= icone :parcial, cor: 'text-amber-700' %> A receber: <%= moeda(@totais.total_pendente) %></span>
</div>
<p class="text-gray-600 text-sm mt-3">
Soma de <%= @consolidacoes.size %> fechamento(s) da empresa neste período.
</p>
</div>
<%= link_to rotulo(:baixar, 'Baixar relatório em PDF', cor: nil),
motorista_totais_pdf_path(inicio: @inicio, fim: @fim),
data: { turbo: false },
class: 'w-full bg-orange-500 hover:bg-orange-600 text-black font-bold text-base px-6 py-4 rounded-xl min-h-[52px] flex items-center justify-center mb-6' %>
<%# ── O que compõe o valor ─────────────────────────────── %>
<h2 class="text-white font-bold text-xl mb-1 flex items-center gap-2"><%= icone :composicao, espaco: false %> O que forma esse valor</h2>
<p class="text-gray-400 text-base mb-3">Cada fechamento abaixo entra na soma acima.</p>
<% if @consolidacoes.any? %>
<div class="space-y-3">
<% @consolidacoes.each do |cm| %>
<% c = cm.consolidacao %>
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-2xl 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"><%= c.nome %></p>
<%= badge_pagamento(cm.pago? ? :pago : :pendente) %>
</div>
<p class="text-gray-300 text-base mt-1">
<%= icone :calendario %> <%= l c.data_inicio, format: :short %> a <%= l c.data_fim, format: :short %>
</p>
<p class="text-orange-500 font-black text-3xl mt-1 whitespace-nowrap"><%= moeda(cm.valor_total) %></p>
<% if cm.pago? %>
<p class="text-green-400 text-sm mt-1">
<%= icone :dinheiro, cor: 'text-green-400' %> Pago em <%= l cm.pago_em.to_date, format: :short %>
<% if cm.forma_pagamento.present? %>via <%= cm.forma_pagamento.humanize %><% end %>
</p>
<% if cm.nota_fiscal.present? %>
<p class="text-gray-300 text-sm mt-0.5"><%= icone :nota_fiscal %> Nota Fiscal: <%= cm.nota_fiscal %></p>
<% end %>
<% else %>
<p class="text-amber-400 text-sm mt-1"><%= icone :parcial, cor: 'text-amber-400' %> Ainda não pago</p>
<% end %>
</div>
<%= link_to rotulo(:baixar, 'Extrato deste fechamento', cor: nil),
gerar_pdf_extrato_consolidacao_path(c, motorista: current_user.nome),
data: { turbo: false },
class: 'w-full md:w-auto bg-[#0a0a0a] border border-[#2a2a2a] hover:border-orange-500 text-white font-bold text-base px-5 py-4 rounded-xl min-h-[52px] flex items-center justify-center text-center' %>
</div>
</div>
<% end %>
</div>
<% else %>
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-2xl p-10 text-center">
<p class="mb-3"><%= icone :vazio, tamanho: 'w-12 h-12', cor: 'text-gray-600', espaco: false %></p>
<p class="text-gray-200 text-lg">Nenhum fechamento neste período.</p>
<p class="text-gray-400 text-base mt-1">Escolha outro período acima — o fechamento aparece aqui quando a empresa finaliza a consolidação.</p>
</div>
<% end %>
</div>