Class: PartnerService::Reports::DineInService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/partner_service/reports/dine_in_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#params, #restaurants

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from CopperHelper

#copper_sort_restaurants

Constructor Details

This class inherits a constructor from PartnerService::Reports::BaseService

Instance Method Details

#build_reports_by_dayObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/services/partner_service/reports/dine_in_service.rb', line 34

def build_reports_by_day
  data_cache_key = cache_key("by_day:#{reservations_filter_by('day').cache_key}")

  Rails.cache.fetch(data_cache_key) do
    reservations = reservations_filter_by('day')
    reservations_group = reservations.group_by(&:date_format)
    dates = date_range(report_params[:start_date], report_params[:end_date])

    row_data = dates.map do |date|
      date_format = date.strftime('%d/%m/%Y')
      build_row_data(date, date_format, reservations_group)
    end

    total_data = build_total_data(reservations)

    [row_data, total_data]
  end
end

#build_reports_by_hourObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/partner_service/reports/dine_in_service.rb', line 4

def build_reports_by_hour
  data_cache_key = cache_key("by_hour:#{active_reservations_filter_by('hour').cache_key}")

  Rails.cache.fetch(data_cache_key) do
    reservations = active_reservations_filter_by('hour')
    reservations_group = reservations.group_by(&:start_time_format)
    hours = reservations_group.keys.sort

    total_seat_available = 0
    data = hours.map do |hour|
      seat_available = calculate_seat_available_for_all_restaurants(hour)
      total_seat_available += seat_available.to_i

      {
        hour: hour,
        count: count_reservations(reservations_group[hour], 'dine_in'),
        orders: orders_count(reservations_group[hour], 'dine_in'),
        adult: sum_group(reservations_group[hour], :adult),
        kids: sum_group(reservations_group[hour], :kids),
        seat_available: seat_available,
        covers: sum_group(reservations_group[hour], :party_size),
      }
    end

    total_data = build_total_data(reservations, total_seat_available, 'hour')

    [data, total_data]
  end
end