Class: OwnerDashboardsController

Inherits:
ApplicationController show all
Includes:
UpdateLocaleConcern
Defined in:
app/controllers/owner_dashboards_controller.rb

Overview

typed: ignore frozen_string_literal: true

Instance Method Summary collapse

Methods included from UpdateLocaleConcern

#setup_locale

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 LogrageCustomLogger

#append_info_to_payload

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Instance Method Details

#accountObject



108
109
110
111
112
# File 'app/controllers/owner_dashboards_controller.rb', line 108

def 
  if current_owner.restaurant.present? && current_owner.restaurant.translations.blank?
    current_owner.restaurant.translations.build
  end
end

#customersObject



73
74
75
76
77
78
# File 'app/controllers/owner_dashboards_controller.rb', line 73

def customers
  @owners = []
  @users  = []

  @info_json = []
end

#indexObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/owner_dashboards_controller.rb', line 59

def index
  if current_owner.restaurant.present?
    res = current_owner.restaurant.reservations
    # disable all reservations
    @res_today = res.where('1 = 0')
    @res_yesterday = res.where('1 = 0')
    @res_next_7_days = res.where('1 = 0')

    @res_manual = res.where('1 = 0')
    @res_normal = res.where('1 = 0')
    @res_total = res.where('1 = 0')
  end
end

#inventoriesObject



93
94
95
96
97
98
99
100
101
# File 'app/controllers/owner_dashboards_controller.rb', line 93

def inventories
  @date = if params[:date].present?
            Date.strptime(params[:date], '%d-%m-%Y').strftime('%Y-%m-%d')
          else
            Time.zone.today.strftime('%Y-%m-%d')
          end
  @inventories = current_owner.restaurant.inventories.by_date(@date)
  @date = Date.parse(@date).strftime('%d-%m-%Y')
end

#inventoryObject



103
104
105
106
# File 'app/controllers/owner_dashboards_controller.rb', line 103

def inventory
  @inventory = current_owner.restaurant.inventories.find(params[:id])
  render 'owner_dashboards/inventories/show'
end

#remake_inventoryObject



114
115
116
117
118
119
120
121
122
# File 'app/controllers/owner_dashboards_controller.rb', line 114

def remake_inventory
  if params[:restaurant].present?
    restaurant = Restaurant.find params[:restaurant]
    Restaurant.generate_schedule(restaurant.id, remake: true, inventory_type: :dine_in)
    Restaurant.generate_schedule(restaurant.id, remake: true, inventory_type: :delivery)
  end
  redirect_to inventory_template_groups_path,
              notice: 'Please wait, the inventory is updating, please refresh this page in few minutes too see the updated data.'
end

#reportsObject



88
89
90
91
# File 'app/controllers/owner_dashboards_controller.rb', line 88

def reports
  @res = current_owner.restaurant.reservations.by_month_year(params[:date])
  @reports = []
end

#reservationObject



84
85
86
# File 'app/controllers/owner_dashboards_controller.rb', line 84

def reservation
  render 'owner_dashboards/reservations/form'
end

#reservationsObject



80
81
82
# File 'app/controllers/owner_dashboards_controller.rb', line 80

def reservations
  @reservations = []
end

#unblock_inventoryObject

the UI of this action is `Delete Inventory` button so it's not unblocking, but deleting



126
127
128
129
130
131
132
# File 'app/controllers/owner_dashboards_controller.rb', line 126

def unblock_inventory
  HH_LOGGER.info('inventory:delete_all_inventories_by_dashboard_v1', {
    restaurant_id: current_owner.restaurant.id,
  })
  DeleteInventoryWorker.perform_async(current_owner.restaurant.id)
  redirect_to inventory_template_groups_path, notice: 'System is deleting Inventory, please wait for few minutes.'
end

#update_ownerObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/owner_dashboards_controller.rb', line 9

def update_owner
  if params[:owner].present?
    if current_owner.valid_password?(params[:owner][:current_password])
      params[:owner].delete(:current_password)

      if params[:owner][:password].blank?
        params[:owner].delete(:password)
        params[:owner].delete(:password_confirmation)
      end
      if current_owner.update_attributes(params[:owner].permit!)
         current_owner if params[:owner][:password].present?
        redirect_to(, notice: 'Account updated successfully')
      else
        redirect_to(, alert: 'Failed to update your account')
      end
    else
      redirect_to(, alert: 'Password is invalid')
    end
  else
    redirect_to(, alert: 'Invalid data')
  end
end

#update_restaurantObject



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
# File 'app/controllers/owner_dashboards_controller.rb', line 32

def update_restaurant
  @restaurant = current_owner.restaurant || current_owner.build_restaurant
  respond_to do |format|
    restaurant_params = params[:restaurant].except(:require_credit_card).permit!.tap do |param|
      if param[:restaurant_tag_ids].present?
        param[:restaurant_tag_ids] =
          param[:restaurant_tag_ids].select(&:present?).map(&:to_i).concat(@restaurant.hashtag_tags.pluck(:id)).uniq
      end
    end
    if @restaurant.update_attributes(restaurant_params)
      if request.env['HTTP_REFERER'].include? 'inventory_template_groups'
        format.html do
          redirect_back fallback_location: root_path, notice: 'Restaurant schedule was successfully updated.'
        end
      else
        format.html { redirect_to , notice: 'Restaurant was successfully updated.' }
        format.json { head :no_content }
      end
    else
      format.html do
        redirect_to , alert: @restaurant.errors.full_messages.to_sentence
      end
      format.json { render json: @restaurant.errors, status: :unprocessable_entity }
    end
  end
end