Implantação da função de controle de consolidaçoes pagas e pendentes

This commit is contained in:
2026-06-17 15:49:24 -03:00
parent 292ac31c66
commit e9def7e21a
17 changed files with 526 additions and 12 deletions

View File

@@ -1,5 +1,7 @@
<%# 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">
@@ -7,9 +9,10 @@
<%= 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">
<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 %>
@@ -31,6 +34,28 @@
<% 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 %>
@@ -46,8 +71,39 @@
<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>
<p class="text-white font-bold text-lg"><%= cm.motorista_nome %></p>
<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 %>