Class: Dashboard::V2::ReportsController
- Inherits:
-
MainController
- Object
- ActionController::Base
- ApplicationController
- MainController
- Dashboard::V2::ReportsController
- Includes:
- ReportsShared
- Defined in:
- app/controllers/dashboard/v2/reports_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
Methods included from ReportsShared
#download_menu_report, #index, #report_branch_covers_by_hour, #report_by_day, #report_by_hour, #report_cover_dine_in_by_day, #report_package_by_day, #report_package_by_hour, #report_sales_and_rating, #report_service_type_by_day, #report_service_type_by_hour, #report_sold_out, #report_sold_out_per_date, #sync_package_solds
Methods included from CopperHelper
Methods included from Modules::Owners::Reports::DineInCoversReport
#build_reports_dine_in_covers_by_day
Methods included from Modules::Owners::Reports::SoldOutReport
#build_sold_out_report, #status_seat_by
Methods included from Modules::Owners::Reports::SalesAndRatingReport
#build_package_sales, #build_ratings
Methods included from Modules::Owners::Reports::ServiceTypeReport
#build_reports_service_type_by_day, #build_reports_service_type_by_hour, #service_type_report_by
Methods included from Modules::Owners::Reports::PackageReport
#build_package_reports_by_day, #build_package_reports_by_hour, #package_report_by
Methods included from Modules::Owners::Reports::DineInReport
#build_reports_by_day, #build_reports_by_hour
Methods included from Modules::Owners::Reports::BranchCoversReport
#build_reports_branch_covers_by_day
Methods inherited from MainController
#default_fallback_location, #default_url_options, #kiosque_callback
Methods included from LogrageCustomLogger
Methods included from Stimulus::TagController
Methods included from OwnerLoginMode
#current_owner, #group_owner_type?, #request_path_contain_group?, #single_owner_type?
Methods included from OwnerDashboardsHelper
#events_ajax_previous_link, #show_source
Methods inherited from ApplicationController
#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=
Methods included from ControllerHelpers
#check_boolean_param, #get_banners, #inventory_params, #reservation_params
Instance Method Details
#packages_name ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/controllers/dashboard/v2/reports_controller.rb', line 122 def packages_name packages = {} if restaurant.respond_to?(:restaurant_packages) restaurant.restaurant_packages.includes(package: :translations).each do |res| packages[res.id] = { name: res.package.name, type: res.package_type } end else restaurant.restaurants.each do |restaurant| restaurant.restaurant_packages.each do |res| packages[res.id] = { name: res.package.name, type: res.package_type } end end end render(json: packages) end |
#revenue ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/controllers/dashboard/v2/reports_controller.rb', line 89 def revenue cache_key = "#{self.class}:revenue:#{restaurant_cache_key}:#{CityHash.hash32(params)}" return unless stale? template: false, etag: cache_key query = Rails.cache.fetch(cache_key, expires_in: CACHEFLOW.generate_expiry) do case params.require(:time) when 'current_month' beginning_of_month = Date.current_date.beginning_of_month end_of_month = Date.current_date.end_of_month when 'last_month' beginning_of_month = Date.current_date.prev_month.beginning_of_month end_of_month = beginning_of_month.end_of_month when 'month_before' beginning_of_month = Date.current_date.prev_month.prev_month.beginning_of_month end_of_month = beginning_of_month.end_of_month else raise ::NotImplementedError end ids = restaurant.is_a?(RestaurantGroup) ? restaurant.restaurant_ids : restaurant.id ReservationProperty.select('SUM(price_cents) revenue'). joins(:reservation). where.not(reservations: { restaurant_id: nil }). where(reservations: { restaurant_id: ids, active: true, no_show: false, is_temporary: false, for_locking_system: false }). where.not(package: nil). where('reservations.date between ? and ?', beginning_of_month, end_of_month) end revenue = query[0]['revenue'] money = Money.new revenue, 'THB' render json: { revenue: money.format } end |
#summary ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/dashboard/v2/reports_controller.rb', line 17 def summary cache_key = "#{self.class}:summary:#{restaurant_cache_key}:#{CityHash.hash32(params)}" return unless stale? template: false, etag: cache_key type = params.require(:type) result = Rails.cache.fetch(cache_key, expires_in: CACHEFLOW.generate_expiry) do case params.require(:time) when 'yesterday' res = restaurant.reservations.active_and_show_scope.where(date: Date.current_date.yesterday).exclude_temporary res = filter_channel(res) if type == 'bookings' res.count else res.sum(:party_size) end when 'today' res = restaurant.reservations.active_and_show_scope.where(date: Date.current_date).exclude_temporary res = filter_channel(res) if type == 'bookings' res.count else res.sum(:party_size) end when 'next_7_days' next_7_days = Date.current_date + 7.days res = restaurant.reservations.active_and_show_scope.where(date: Date.current_date.tomorrow..next_7_days).exclude_temporary res = filter_channel(res) if type == 'bookings' res.count else res.sum(:party_size) end when 'current_month' beginning_of_month = Date.current_date.beginning_of_month end_of_month = Date.current_date.end_of_month res = restaurant.reservations.active_and_show_scope.where(date: beginning_of_month..end_of_month).exclude_temporary res = filter_channel(res) if type == 'bookings' res.count else res.sum(:party_size) end when 'last_month' beginning_of_month = Date.current_date.prev_month.beginning_of_month end_of_month = beginning_of_month.end_of_month res = restaurant.reservations.active_and_show_scope.where(date: beginning_of_month..end_of_month).exclude_temporary res = filter_channel(res) if type == 'bookings' res.count else res.sum(:party_size) end when 'month_before' beginning_of_month = Date.current_date.prev_month.prev_month.beginning_of_month end_of_month = beginning_of_month.end_of_month res = restaurant.reservations.active_and_show_scope.where(date: beginning_of_month..end_of_month).exclude_temporary res = filter_channel(res) if type == 'bookings' res.count else res.sum(:party_size) end else raise ::NotImplementedError end end render json: result end |
#total ⇒ Object
13 14 15 |
# File 'app/controllers/dashboard/v2/reports_controller.rb', line 13 def total render json: 0 end |