Correções para funcionamento do dash,criar login do motorista senha, e gerar quelátório

This commit is contained in:
2026-06-16 15:33:36 -03:00
parent 9c663ee3da
commit 6efbb45b70
7 changed files with 50 additions and 25 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@@ -84,19 +84,34 @@ class DashboardController < ApplicationController
end end
def build_grafico_diario(entregas, preco_entrega) def build_grafico_diario(entregas, preco_entrega)
# Em períodos muito longos, agrupa o gráfico de forma a não gerar centenas de pontos.
dias = (@periodo_inicio..@periodo_fim).to_a dias = (@periodo_inicio..@periodo_fim).to_a
return { labels: [], valores: [], qtds: [] } if dias.size > MAX_DIAS_GRAFICO
contagem = entregas.pagas if dias.size <= MAX_DIAS_GRAFICO
.group("DATE(planned_date)") # Granularidade diária (períodos curtos)
.count contagem = entregas.pagas.group("DATE(planned_date)").count.transform_keys(&:to_s)
.transform_keys(&:to_s) labels = dias.map { |d| d.strftime('%d/%m') }
valores = dias.map { |d| ((contagem[d.to_s] || 0) * preco_entrega).round(2) }
labels = dias.map { |d| d.strftime('%d/%m') } qtds = dias.map { |d| contagem[d.to_s] || 0 }
valores = dias.map { |d| ((contagem[d.to_s] || 0) * preco_entrega).round(2) } else
qtds = dias.map { |d| contagem[d.to_s] || 0 } # Período longo: agrega por mês para o gráfico não ficar vazio nem poluído.
contagem = entregas.pagas.group("TO_CHAR(planned_date, 'YYYY-MM')").count
meses = meses_no_periodo
labels = meses.map { |m| Date.strptime(m, '%Y-%m').strftime('%m/%Y') }
valores = meses.map { |m| ((contagem[m] || 0) * preco_entrega).round(2) }
qtds = meses.map { |m| contagem[m] || 0 }
end
{ labels: labels, valores: valores, qtds: qtds } { labels: labels, valores: valores, qtds: qtds }
end end
# Meses ("YYYY-MM") do início ao fim do período selecionado, inclusive.
def meses_no_periodo
meses = []
cursor = @periodo_inicio.beginning_of_month
while cursor <= @periodo_fim
meses << cursor.strftime('%Y-%m')
cursor = cursor.next_month
end
meses
end
end end

View File

@@ -134,20 +134,21 @@
</div> </div>
<script> <script>
const roleSelect = document.querySelector('select[name="user[role]"]'); // IIFE: evita "Identifier already declared" quando o Turbo re-executa o script
const fieldsEmail = document.getElementById('fields-email'); // ao navegar (o que antes abortava o toggle e escondia o campo de PIN).
const fieldsPin = document.getElementById('fields-pin'); (function () {
const roleSelect = document.querySelector('select[name="user[role]"]');
const fieldsEmail = document.getElementById('fields-email');
const fieldsPin = document.getElementById('fields-pin');
if (!roleSelect || !fieldsEmail || !fieldsPin) return;
function toggleFields() { function toggleFields() {
if (roleSelect.value === 'motorista') { const motorista = roleSelect.value === 'motorista';
fieldsEmail.classList.add('hidden'); fieldsEmail.classList.toggle('hidden', motorista);
fieldsPin.classList.remove('hidden'); fieldsPin.classList.toggle('hidden', !motorista);
} else {
fieldsEmail.classList.remove('hidden');
fieldsPin.classList.add('hidden');
} }
}
roleSelect.addEventListener('change', toggleFields); roleSelect.addEventListener('change', toggleFields);
toggleFields(); // run on load toggleFields(); // estado inicial
})();
</script> </script>

View File

@@ -57,9 +57,11 @@
</button> </button>
<%= link_to '📄 Relatório Individual', <%= link_to '📄 Relatório Individual',
gerar_pdf_relatorio_consolidacao_path(@consolidacao, motorista: cm.motorista_nome), 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' %> 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', <%= link_to '🧾 Gerar Holerite',
gerar_pdf_holerite_consolidacao_path(@consolidacao, motorista: cm.motorista_nome), 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' %> 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> </div>
@@ -79,7 +81,7 @@
<div class="flex justify-center py-10"><div class="spinner w-10 h-10"></div></div> <div class="flex justify-center py-10"><div class="spinner w-10 h-10"></div></div>
</div> </div>
<div class="flex gap-3 px-6 py-4 border-t border-[#2a2a2a]"> <div class="flex gap-3 px-6 py-4 border-t border-[#2a2a2a]">
<a id="modal-confirmar" href="#" <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"> 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 ✓ Confirmar e baixar PDF
</a> </a>

View File

@@ -14,10 +14,11 @@
</div> </div>
<%# Filtro de calendário — seleciona uma faixa de datas %> <%# Filtro de calendário — seleciona uma faixa de datas %>
<form id="dashboard-filtro-form" method="get" action="<%= dashboard_path %>" class="flex items-center gap-2"> <form id="dashboard-filtro-form" method="get" action="<%= dashboard_path %>" data-turbo="false" class="flex items-center gap-2">
<div class="relative"> <div class="relative">
<span class="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-orange-500">📅</span> <span class="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2 text-orange-500">📅</span>
<input type="text" id="periodo-range" readonly placeholder="Selecione o período" <input type="text" id="periodo-range" readonly placeholder="Selecione o período"
value="<%= @periodo_inicio.strftime('%d/%m/%Y') %> até <%= @periodo_fim.strftime('%d/%m/%Y') %>"
class="cursor-pointer pl-4 pr-10 py-2.5 bg-[#1a1a1a] border border-white/10 rounded-xl class="cursor-pointer pl-4 pr-10 py-2.5 bg-[#1a1a1a] border border-white/10 rounded-xl
text-white text-sm w-[240px] focus:outline-none focus:border-orange-500 placeholder-gray-500"> text-white text-sm w-[240px] focus:outline-none focus:border-orange-500 placeholder-gray-500">
</div> </div>
@@ -189,7 +190,11 @@
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<script> <script>
// IIFE: evita "Identifier already declared" quando o Turbo re-executa o script
// ao navegar (o que antes fazia o gráfico não aparecer).
(function () {
const ctx = document.getElementById('grafico-diario'); const ctx = document.getElementById('grafico-diario');
if (!ctx || typeof Chart === 'undefined') return;
const labels = <%= raw @grafico_diario[:labels].to_json %>; const labels = <%= raw @grafico_diario[:labels].to_json %>;
const valores = <%= raw @grafico_diario[:valores].to_json %>; const valores = <%= raw @grafico_diario[:valores].to_json %>;
@@ -254,4 +259,5 @@
} }
} }
}); });
})();
</script> </script>

View File

@@ -53,6 +53,7 @@
<% if c.finalizada? %> <% if c.finalizada? %>
<%= link_to '⬇️ Baixar meu holerite', <%= link_to '⬇️ Baixar meu holerite',
gerar_pdf_holerite_consolidacao_path(c, motorista: current_user.nome), gerar_pdf_holerite_consolidacao_path(c, motorista: current_user.nome),
data: { turbo: false },
class: 'bg-orange-500 hover:bg-orange-600 text-black font-bold px-5 py-3.5 rounded-lg min-h-[48px] flex items-center justify-center text-center' %> class: 'bg-orange-500 hover:bg-orange-600 text-black font-bold px-5 py-3.5 rounded-lg min-h-[48px] flex items-center justify-center text-center' %>
<% else %> <% else %>
<span class="text-gray-500 text-sm px-4 py-3 border border-[#2a2a2a] rounded-lg text-center"> <span class="text-gray-500 text-sm px-4 py-3 border border-[#2a2a2a] rounded-lg text-center">