Files
Reem-Notas/app/models/entrega.rb
2026-06-10 20:12:20 -03:00

40 lines
1.0 KiB
Ruby

# app/models/entrega.rb
# ⚠️ READ-ONLY — tabela existente: public.db_reem_simplerout_2026
# NUNCA fazer DROP, TRUNCATE, DELETE ou migration nessa tabela.
class Entrega < ApplicationRecord
self.table_name = 'db_reem_simplerout_2026'
self.primary_key = 'tracking_id'
# Apenas leitura
def readonly?
true
end
# Scopes
scope :do_account, -> { where(account_id: 95907) }
scope :pagas, -> { where(status: 'completed').where.not(checkin: nil) }
scope :pendentes, -> { where.not(status: 'completed').or(where(checkin: nil)) }
scope :do_mes, ->(data = Date.today) {
do_account
.where(planned_date: data.beginning_of_month..data.end_of_month)
}
scope :do_dia, ->(data = Date.today) {
do_account.where(planned_date: data)
}
scope :do_motorista, ->(nome) {
where('LOWER(driver) = ?', nome.to_s.downcase)
}
# Helpers de instância
def paga?
status == 'completed' && checkin.present?
end
def data_formatada
planned_date&.strftime('%d/%m/%Y')
end
end