Class: Admin::InventoriesController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- ApplicationController
- BaseController
- Admin::InventoriesController
- Defined in:
- app/controllers/admin/inventories_controller.rb
Overview
typed: ignore frozen_string_literal: true
Constant Summary
Constants inherited from BaseController
BaseController::INTERNAL_SERVER_ERROR_MESSAGE
Instance Method Summary collapse
Methods inherited from BaseController
#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session
Methods included from LogrageCustomLogger
Methods included from AdminHelper
#dynamic_pricings_formatter, #link_to_admin_reservations_path_by_id, #link_to_admin_restaurants_path_by_id, #link_to_log, #optional_locales, #optional_locales_with_labels, #staff_signed_in?
Methods included from UpdateLocaleConcern
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
#edit_seats ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/controllers/admin/inventories_controller.rb', line 12 def edit_seats @restaurants = Restaurant.includes(:translations).order('restaurant_translations.name').find_each.map do |restaurant| ["#{restaurant.id} - #{restaurant.name_en}", restaurant.id] end render layout: nil end |
#override_report ⇒ Object
5 6 7 8 9 10 |
# File 'app/controllers/admin/inventories_controller.rb', line 5 def override_report @grid = Admin::Inventories::OverrideGrid.new(params[:admin_inventories_override_grid]) do |scope| scope.page(params[:page]) end return unless stale_etag? @grid.assets end |
#undo ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/admin/inventories_controller.rb', line 57 def undo inventory_type = params.require(:service_type) UpdatedInventory.transaction do upd_inventory = UpdatedInventory.find(params[:inventory_id]) restaurant = upd_inventory.restaurant if restaurant.use_third_party_inventory? flash[:alert] = "#{restaurant.name}:" + I18n.t('inventory.tc_inventory.tc_dashboard') else HH_LOGGER.info('inventory:undo_changes_by_admin', upd_inventory.attributes) upd_inventory.destroy! Restaurant.generate_schedule restaurant.id, { inventory_type: inventory_type } flash[:notice] = 'System is recreating the inventories right now, please wait for a minute' end rescue StandardError => e APMErrorHandler.report 'Unable to restore inventory', error: e flash[:alert] = 'Something went wrong' raise ActiveRecord::Rollback, e end redirect_back fallback_location: back_fallback_location end |
#update_seats ⇒ Object
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 |
# File 'app/controllers/admin/inventories_controller.rb', line 20 def update_seats start_time = Time.zone.parse "#{valid_params[:start_date]} #{valid_params[:start_time]}" end_time = Time.zone.parse "#{valid_params[:end_date]} #{valid_params[:end_time]}" if start_time >= end_time redirect_back(fallback_location: back_fallback_location, alert: 'Please provide valid time') return end inventory_type = params[:service_type] restaurant = Restaurant.find(valid_params[:restaurant_id].to_i) if restaurant.use_third_party_inventory? redirect_back(fallback_location: back_fallback_location, alert: "#{restaurant.name}:" + I18n.t('inventory.tc_inventory.tc_dashboard')) elsif !restaurant.is_dine_in? && inventory_type == 'dine_in' redirect_back(fallback_location: back_fallback_location, alert: "#{restaurant.name} doesn't have #{inventory_type} inventory type") elsif !restaurant.is_take_away? && inventory_type == 'take_away' redirect_back(fallback_location: back_fallback_location, alert: "#{restaurant.name} doesn't have #{inventory_type} inventory type") else operation = InventoryUpdater.call({ restaurant_id: valid_params[:restaurant_id].to_i, start_date: valid_params[:start_date].to_date, end_date: valid_params[:end_date].to_date, start_time: valid_params[:start_time], end_time: valid_params[:end_time], quantity_available: valid_params[:quantity_available], }, inventory_type: params[:service_type]) if operation.success? redirect_back(fallback_location: back_fallback_location, notice: operation['result.success_message']) else redirect_back(fallback_location: back_fallback_location, alert: operation['result.fail_message']) end end end |