136 lines
8.0 KiB
Plaintext
136 lines
8.0 KiB
Plaintext
<%# app/views/consolidacoes/index.html.erb %>
|
||
<% content_for :title, 'Consolidações' %>
|
||
|
||
<div class="flex items-center justify-between mb-6">
|
||
<h1 class="text-2xl font-bold text-white">📦 Consolidações</h1>
|
||
<div class="flex gap-2">
|
||
<%= link_to '📁 Arquivadas', 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? %>
|
||
<button type="button" data-action="notaAvulsa#abrir"
|
||
class="text-white border border-dashed border-orange-500/60 hover:border-orange-500 font-semibold px-4 py-3 rounded-lg min-h-[48px] flex items-center transition-colors">
|
||
➕ Nota avulsa
|
||
</button>
|
||
<% end %>
|
||
<%= link_to '+ Nova Consolidação', new_consolidacao_path,
|
||
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>
|
||
|
||
<%# ── Modal "Nota avulsa" — cria a consolidação direto a partir da NF ── %>
|
||
<% if policy(Consolidacao).create? %>
|
||
<div data-controller="notaAvulsa"
|
||
data-nota-avulsa-buscar-url-value="<%= buscar_nf_consolidacoes_path %>">
|
||
<div data-nota-avulsa-target="modal" data-action="click->notaAvulsa#fundo"
|
||
class="hidden fixed inset-0 z-50 bg-black/70 flex items-center justify-center p-4">
|
||
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-2xl w-full max-w-lg p-6 max-h-[90vh] overflow-y-auto">
|
||
<div class="flex items-center justify-between mb-1">
|
||
<h2 class="text-xl font-bold text-white">➕ Nota avulsa</h2>
|
||
<button type="button" data-action="notaAvulsa#fechar"
|
||
class="text-gray-500 hover:text-white text-2xl leading-none">✕</button>
|
||
</div>
|
||
<p class="text-gray-400 text-sm mb-4">Para uma nota que chegou por fora: busque a NF e crie uma consolidação já com o apontamento do motorista.</p>
|
||
|
||
<p data-nota-avulsa-target="erro" class="hidden bg-red-500/10 text-red-400 border border-red-500/30 rounded-lg px-3 py-2 text-sm mb-3"></p>
|
||
|
||
<%# Busca da NF %>
|
||
<div class="flex gap-2 mb-4">
|
||
<input data-nota-avulsa-target="nf" type="text" inputmode="numeric"
|
||
data-action="keydown.enter->notaAvulsa#buscar"
|
||
placeholder="Número da nota (NF)"
|
||
class="flex-1 bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-3 text-base focus:border-orange-500 focus:outline-none">
|
||
<button type="button" data-action="notaAvulsa#buscar"
|
||
class="bg-orange-500 hover:bg-orange-600 text-black font-bold px-5 rounded-lg min-h-[48px]">Buscar</button>
|
||
</div>
|
||
|
||
<%# Form de criação — radios (tracking_id) e tipos[] são enviados nativamente %>
|
||
<%= form_with url: avulsa_consolidacoes_path, method: :post, data: { action: 'submit->notaAvulsa#validar' } do %>
|
||
<div data-nota-avulsa-target="resultados" class="space-y-2 mb-4"></div>
|
||
|
||
<div data-nota-avulsa-target="confirmar" class="hidden border-t border-[#2a2a2a] pt-4">
|
||
<label class="block text-gray-400 text-sm mb-2">Classificar como <span class="text-gray-600">(pode marcar mais de uma)</span></label>
|
||
<div class="grid grid-cols-2 gap-2 mb-4">
|
||
<% [['entrega_normal', '🚚 Entrega Normal', Configuracao.preco_entrega],
|
||
['retirada', '📦 Retirada', Configuracao.preco_retirada],
|
||
['bonus', '⭐ Bônus', Configuracao.preco_bonus],
|
||
['desconto', '⚠️ Desconto', Configuracao.preco_desconto]].each do |tipo, label, preco| %>
|
||
<label class="flex items-center gap-2 bg-[#0a0a0a] border border-[#2a2a2a] rounded-lg px-3 py-3 cursor-pointer hover:border-orange-500 text-sm text-white">
|
||
<%= check_box_tag 'tipos[]', tipo, tipo == 'entrega_normal', id: nil, class: 'accent-orange-500' %>
|
||
<span><%= label %><br><span class="text-gray-500 text-xs"><%= moeda(preco) %></span></span>
|
||
</label>
|
||
<% end %>
|
||
</div>
|
||
<%= submit_tag 'Criar consolidação avulsa →',
|
||
class: 'w-full bg-green-600 hover:bg-green-500 text-white font-bold py-3.5 rounded-lg min-h-[48px] cursor-pointer' %>
|
||
</div>
|
||
<% end %>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<% end %>
|
||
|
||
<%# ── Filtros ──────────────────────────────────────────── %>
|
||
<%= form_with url: consolidacoes_path, method: :get,
|
||
class: 'bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-4 mb-6 grid grid-cols-1 md:grid-cols-6 gap-3' do |f| %>
|
||
<%= f.text_field :nome, value: params[:nome], placeholder: 'Buscar por nome…',
|
||
class: 'bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-2.5 focus:border-orange-500 focus:outline-none' %>
|
||
|
||
<%= f.select :status,
|
||
options_for_select([['Todos os status', ''], ['📝 Rascunho', 'rascunho'], ['✅ Finalizada', 'finalizada']], params[:status]),
|
||
{}, class: 'bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-2.5' %>
|
||
|
||
<%= f.select :pagamento,
|
||
options_for_select([['💵 Pagamento (todos)', ''], ['💰 Pagas', 'pago'], ['⏳ Parciais', 'parcial'], ['🕗 Pendentes', 'pendente']], params[:pagamento]),
|
||
{}, class: 'bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-2.5' %>
|
||
|
||
<%= f.date_field :inicio, value: params[:inicio],
|
||
class: 'bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-2.5' %>
|
||
|
||
<%= f.date_field :fim, value: params[:fim],
|
||
class: 'bg-[#0a0a0a] border border-[#2a2a2a] text-white rounded-lg px-3 py-2.5' %>
|
||
|
||
<div class="flex gap-2">
|
||
<%= f.submit 'Filtrar', class: 'flex-1 bg-orange-500 hover:bg-orange-600 text-black font-bold rounded-lg cursor-pointer' %>
|
||
<%= link_to 'Limpar', consolidacoes_path, class: 'px-4 py-2.5 text-gray-400 hover:text-white border border-[#2a2a2a] rounded-lg' %>
|
||
</div>
|
||
<% end %>
|
||
|
||
<%# ── Lista ────────────────────────────────────────────── %>
|
||
<% if @consolidacoes.any? %>
|
||
<div class="space-y-3">
|
||
<% @consolidacoes.each do |c| %>
|
||
<%= link_to consolidacao_path(c),
|
||
class: 'block bg-[#1a1a1a] border border-[#2a2a2a] hover:border-orange-500 rounded-xl p-5 transition-colors' do %>
|
||
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-3">
|
||
<div>
|
||
<div class="flex items-center gap-3 mb-1">
|
||
<h3 class="text-white font-bold text-lg"><%= c.nome %></h3>
|
||
<%= badge_status(c.status) %>
|
||
<% if c.finalizada? %><%= badge_pagamento(c.status_pagamento) %><% end %>
|
||
</div>
|
||
<p class="text-gray-400 text-sm">
|
||
📅 <%= l c.data_inicio, format: :short %> → <%= l c.data_fim, format: :short %>
|
||
· 👤 <%= 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>
|
||
<p class="text-gray-500 text-xs"><%= c.consolidacao_entregas.count %> entregas classificadas</p>
|
||
</div>
|
||
</div>
|
||
<% end %>
|
||
<% end %>
|
||
</div>
|
||
<% else %>
|
||
<div class="bg-[#1a1a1a] border border-[#2a2a2a] rounded-xl p-12 text-center">
|
||
<p class="text-5xl mb-4">📭</p>
|
||
<p class="text-gray-400 mb-4">Nenhuma consolidação encontrada.</p>
|
||
<%= link_to 'Criar primeira consolidação', new_consolidacao_path,
|
||
class: 'inline-block bg-orange-500 hover:bg-orange-600 text-black font-bold px-5 py-3 rounded-lg' %>
|
||
</div>
|
||
<% end %>
|