Implantação da função filtro de Operções exemplo UBS***
This commit is contained in:
@@ -55,6 +55,9 @@
|
||||
· 👤 <%= c.consolidacao_motoristas.count %> motorista(s)
|
||||
· Criada por <%= c.criador.nome_display %>
|
||||
</p>
|
||||
<% if c.operacoes.present? %>
|
||||
<p class="text-gray-500 text-xs mt-1">🗂️ <%= c.operacoes_label.join(' · ') %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<p class="text-orange-500 font-black text-2xl"><%= moeda(c.valor_total) %></p>
|
||||
|
||||
@@ -17,6 +17,28 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%# Operação — multi-select opcional (pré-preenche e filtra por NF) %>
|
||||
<div>
|
||||
<label class="block text-white font-semibold mb-2">
|
||||
🗂️ Operação <span class="text-gray-500 font-normal text-sm">(opcional — preenche motoristas, veículos e período, e filtra as entregas por nota fiscal)</span>
|
||||
</label>
|
||||
<div id="operacoes-lista"
|
||||
class="bg-[#0a0a0a] border border-[#2a2a2a] rounded-lg p-3 max-h-48 overflow-y-auto space-y-1">
|
||||
<% if @operacoes.any? %>
|
||||
<% @operacoes.each do |op| %>
|
||||
<label class="flex items-center gap-2 text-white hover:bg-[#1a1a1a] rounded px-2 py-2 cursor-pointer text-sm min-h-[44px]">
|
||||
<%= check_box_tag 'consolidacao[operacoes][]', op[:tabela], false,
|
||||
class: 'chk-operacao rounded text-orange-500 bg-[#1a1a1a] border-[#2a2a2a]', id: nil %>
|
||||
<%= op[:label] %>
|
||||
</label>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p class="text-gray-500 text-sm px-2 py-2">Nenhuma tabela de operação encontrada no banco.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
<p id="operacao-status" class="text-gray-500 text-xs mt-1"></p>
|
||||
</div>
|
||||
|
||||
<%# Nome %>
|
||||
<div>
|
||||
<%= f.label :nome, 'Nome da consolidação', class: 'block text-white font-semibold mb-2' %>
|
||||
@@ -159,6 +181,49 @@
|
||||
if (dataIni) dataIni.addEventListener('change', atualizarVeiculos);
|
||||
if (dataFim) dataFim.addEventListener('change', atualizarVeiculos);
|
||||
|
||||
// ── Operações: ao marcar, pré-preenche período + motoristas + veículos ──
|
||||
const opStatus = document.getElementById('operacao-status');
|
||||
const dadosOpUrl = '<%= dados_da_operacao_consolidacoes_path %>';
|
||||
|
||||
function operacoesSelecionadas() {
|
||||
return Array.from(document.querySelectorAll('.chk-operacao:checked')).map(c => c.value);
|
||||
}
|
||||
|
||||
async function aplicarOperacoes() {
|
||||
const ops = operacoesSelecionadas();
|
||||
if (!ops.length) { if (opStatus) opStatus.textContent = ''; return; }
|
||||
|
||||
if (opStatus) opStatus.textContent = 'Carregando dados da operação…';
|
||||
const params = new URLSearchParams();
|
||||
ops.forEach(o => params.append('operacoes[]', o));
|
||||
|
||||
try {
|
||||
const resp = await fetch(dadosOpUrl + '?' + params.toString(), { headers: { 'Accept': 'application/json' } });
|
||||
const data = await resp.json();
|
||||
|
||||
if (data.inicio && dataIni) dataIni.value = data.inicio;
|
||||
if (data.fim && dataFim) dataFim.value = data.fim;
|
||||
|
||||
const motset = new Set(data.motoristas || []);
|
||||
document.querySelectorAll('.chk-motorista').forEach(c => { if (motset.has(c.value)) c.checked = true; });
|
||||
|
||||
await atualizarVeiculos();
|
||||
const vehset = new Set(data.veiculos || []);
|
||||
lista.querySelectorAll('input[name="consolidacao[vehicle_ids][]"]').forEach(c => { if (vehset.has(c.value)) c.checked = true; });
|
||||
|
||||
if (opStatus) {
|
||||
opStatus.textContent = (data.motoristas || []).length + ' motorista(s) e ' +
|
||||
(data.veiculos || []).length + ' veículo(s) nesta(s) operação(ões).';
|
||||
}
|
||||
} catch (e) {
|
||||
if (opStatus) opStatus.textContent = 'Erro ao carregar dados da operação.';
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('change', function (e) {
|
||||
if (e.target.classList.contains('chk-operacao')) aplicarOperacoes();
|
||||
});
|
||||
|
||||
// Estado inicial (caso o form volte com motoristas já marcados após erro de validação)
|
||||
if (motoristasSelecionados().length) atualizarVeiculos();
|
||||
})();
|
||||
|
||||
@@ -21,6 +21,14 @@
|
||||
· 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? %>
|
||||
|
||||
Reference in New Issue
Block a user