diff --git a/.env.example b/.env.example index 62f8f4d..65d7cbb 100644 --- a/.env.example +++ b/.env.example @@ -18,7 +18,12 @@ DB_PASSWORD=senha_segura # ── Tabela existente (apenas leitura — NÃO modificar) ──────── DB_EXISTING_TABLE=db_reem_simplerout_2026 DB_EXISTING_SCHEMA=public -DB_EXISTING_ACCOUNT_ID=95907 +# Conta(s) consideradas. A coluna account_id é texto e pode vir vazia. +# 95907 → só essa conta +# 95907,12345 → várias contas +# 95907, → essa conta + os registros de conta vazia +# all (ou vazio)→ NÃO filtra por conta (conta tudo da tabela) ← recomendado aqui +DB_EXISTING_ACCOUNT_ID=all # ── Rails Security ──────────────────────────────────────────── # Gere com: docker-compose exec app bundle exec rails secret diff --git a/app/models/entrega.rb b/app/models/entrega.rb index f384028..ce86d8a 100644 --- a/app/models/entrega.rb +++ b/app/models/entrega.rb @@ -36,8 +36,17 @@ class Entrega < ApplicationRecord where(planned_date: data.beginning_of_month..data.end_of_month) } + # Filtra pela(s) conta(s) configurada(s) em DB_EXISTING_ACCOUNT_ID. + # A coluna account_id é TEXTO e pode vir vazia, então comparamos como string. + # Aceita: "95907" (uma) | "95907,12345" (várias) | "all" ou vazio (sem filtro). + # Use "95907," (com vírgula) para incluir também os registros de conta vazia. scope :da_conta_gade, -> { - where(account_id: ENV.fetch('DB_EXISTING_ACCOUNT_ID', 95907).to_i) + contas = ENV.fetch('DB_EXISTING_ACCOUNT_ID', '95907').to_s.strip + if contas.empty? || contas.casecmp?('all') + all + else + where(account_id: contas.split(',', -1).map(&:strip)) + end } # ── Métodos de classe ────────────────────────────────────────