Fases 4, 5 e 6 — Job 1h + Auditoria + Consolidação + Wizard de validação

This commit is contained in:
2026-06-11 12:02:50 -03:00
parent b77fc0122c
commit 90ed705ed8
29 changed files with 1617 additions and 616 deletions

View File

@@ -1,39 +1,55 @@
# app/models/configuracao.rb
class Configuracao < ApplicationRecord
TIPOS = %w[entrega retirada bonus desconto].freeze
# Chaves válidas do sistema
CHAVES = %w[
preco_entrega
preco_retirada
preco_bonus
preco_desconto
notificacao_whatsapp
notificacao_email
empresa_nome
empresa_logo
].freeze
enum tipo: { entrega: 0, retirada: 1, bonus: 2, desconto: 3 }
CHAVES_MOEDA = %w[
preco_entrega
preco_retirada
preco_bonus
preco_desconto
].freeze
validates :tipo, presence: true, uniqueness: true
validates :valor, presence: true,
numericality: { greater_than_or_equal_to: 0 }
validates :chave, presence: true, inclusion: { in: CHAVES }, uniqueness: true
validates :valor, presence: true
LABELS = {
'entrega' => 'Entrega Normal',
'retirada' => 'Retirada',
'bonus' => 'Bônus',
'desconto' => 'Desconto'
}.freeze
# ── Acesso rápido ───────────────────────────────────────────
ICONES = {
'entrega' => '🚚',
'retirada' => '📦',
'bonus' => '⭐',
'desconto' => '🔻'
}.freeze
def tipo_label
LABELS[tipo] || tipo.humanize
def self.valor(chave)
find_by(chave: chave)&.valor
end
def icone
ICONES[tipo] || '💰'
def self.preco_entrega
valor('preco_entrega').to_f
end
# Retorna um hash { entrega: 10.50, retirada: 8.00, bonus: 5.00, desconto: 2.00 }
def self.mapa_de_precos
all.each_with_object({}) do |c, h|
h[c.tipo.to_sym] = c.valor.to_f
end
def self.preco_retirada
valor('preco_retirada').to_f
end
def self.preco_bonus
valor('preco_bonus').to_f
end
def self.preco_desconto
valor('preco_desconto').to_f
end
def moeda?
CHAVES_MOEDA.include?(chave)
end
def valor_formatado
return "R$ #{format('%.2f', valor.to_f).gsub('.', ',')}" if moeda?
valor
end
end