Correção da data do dash principal

This commit is contained in:
2026-06-17 18:29:13 -03:00
parent 4b728c0c4d
commit 076bd42973
7 changed files with 49 additions and 32 deletions

View File

@@ -27,6 +27,14 @@ class Entrega < ApplicationRecord
where(planned_date: inicio.to_date.beginning_of_day..fim.to_date.end_of_day)
}
# Período pela DATA REAL da entrega (checkout) — usada nas análises financeiras
# ("quando a entrega foi concluída"). Comparação naïve com Date (intervalo
# meio-aberto: >= início e < fim+1), SEM conversão de fuso — bate com a análise
# feita direto no banco. Só faz sentido sobre entregas .pagas (checkout != nil).
scope :no_periodo_checkout, ->(inicio, fim) {
where('checkout >= ? AND checkout < ?', inicio.to_date, fim.to_date + 1)
}
scope :do_motorista, ->(nome) {
where(driver: nome)
}
@@ -98,9 +106,10 @@ class Entrega < ApplicationRecord
base.distinct.order(:vehicle).pluck(:vehicle).compact.reject(&:empty?)
end
# Contagem de entregas pagas para cálculo estimado
# Contagem de entregas pagas para cálculo estimado.
# Período pela DATA REAL da entrega (checkout) — ver no_periodo_checkout.
def self.contar_pagas(inicio:, fim:, motorista: nil, vehicle: nil, operacoes: nil)
base = pagas.da_conta_gade.no_periodo(inicio, fim)
base = pagas.da_conta_gade.no_periodo_checkout(inicio, fim)
base = base.do_motorista(motorista) if motorista.present?
base = base.da_veiculo(vehicle) if vehicle.present?
base = base.da_operacoes(operacoes) if operacoes.present?