Separa heatmap mobile/desktop, opt-out analytics per operatori, dashboard costi con KPI e trend mensili. Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
791 B
Ruby
31 lines
791 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Admin
|
|
class CostsController < Admin::BaseController
|
|
def index
|
|
@month = parse_month(params[:month]) || Time.zone.today.beginning_of_month
|
|
analytics = Admin::CostAnalytics.new(month: @month)
|
|
@summary = analytics.summary
|
|
@trend = analytics.trend
|
|
@clubs = analytics.club_breakdown
|
|
@entries = PlatformCostEntry.for_month(@month).ordered
|
|
@month_options = month_options(@month)
|
|
end
|
|
|
|
private
|
|
|
|
def parse_month(value)
|
|
return nil if value.blank?
|
|
|
|
Date.strptime(value.to_s, "%Y-%m").beginning_of_month
|
|
rescue ArgumentError, TypeError
|
|
nil
|
|
end
|
|
|
|
def month_options(selected)
|
|
start = selected - 23.months
|
|
(0..23).map { |i| start + i.months }.reverse
|
|
end
|
|
end
|
|
end
|