Class: Dashboard::V2::Group::VoucherMarketplacesController

Inherits:
VoucherMarketplacesController show all
Defined in:
app/controllers/dashboard/v2/group/voucher_marketplaces_controller.rb

Overview

typed: ignore

Instance Method Summary collapse

Methods inherited from VoucherMarketplacesController

#check_owner_ticket, #check_voucher, #get_redeem_history, #get_redeem_list, #redeem_history, #redeem_list, #self_redeem, #self_redeem_form

Methods inherited from MainController

#default_fallback_location, #default_url_options, #kiosque_callback

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from Stimulus::TagController

#stimulus

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

#edit_historyObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/dashboard/v2/group/voucher_marketplaces_controller.rb', line 55

def edit_history
  ActiveRecord::Base.transaction do
    ticket = Ticket.find_by(ticket_code: params[:code])
    if ticket.present?
      ticket.name = params[:name]
      ticket.phone = params[:phone]
      if ticket.save!
        redirect_to :history_dashboard_v2_group_voucher_marketplaces, notice: 'Data Updated'
      else
        redirect_to :history_dashboard_v2_group_voucher_marketplaces, notice: 'Failed to Update'
      end
    else
      redirect_to :history_dashboard_v2_group_voucher_marketplaces, notice: 'Failed to Update'
    end
  end
end

#historyObject



37
38
39
40
41
# File 'app/controllers/dashboard/v2/group/voucher_marketplaces_controller.rb', line 37

def history
  @data = Ticket.joins(:ticket_transaction).
    where(ticket_transactions: { restaurant_id: current_owner.restaurant_ids }).
    where.not(redeemed_at: nil)
end

#listObject



6
7
8
9
# File 'app/controllers/dashboard/v2/group/voucher_marketplaces_controller.rb', line 6

def list
  @data = TicketGroup.joins(:restaurants).
    where(ticket_group_restaurants: { restaurant_id: current_owner.restaurant_ids })
end

#redeemObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/dashboard/v2/group/voucher_marketplaces_controller.rb', line 22

def redeem
  service = TicketService::Redeem.new(
    code: params[:code],
    name: params[:name],
    phone: params[:phone],
    guest_detail: params[:guest_detail],
  )

  if service.execute
    redirect_to :list_dashboard_v2_group_voucher_marketplaces, notice: 'Voucher has been redeemed successfully'
  else
    redirect_to :list_dashboard_v2_group_voucher_marketplaces, alert: service.errors.full_messages.to_sentence
  end
end

#search_historyObject



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/dashboard/v2/group/voucher_marketplaces_controller.rb', line 43

def search_history
  if params[:restaurant_id] == 'all'
    @data = history
  elsif current_owner.restaurant_ids.include? params[:restaurant_id].to_i
    @data = Ticket.joins(:ticket_transaction).
      where(ticket_transactions: { restaurant_id: params[:restaurant_id] }).
      where.not(redeemed_at: nil)
  else
    redirect_to :history_dashboard_v2_group_voucher_marketplaces, notice: 'Restaurant not found'
  end
end

#search_listObject



11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/dashboard/v2/group/voucher_marketplaces_controller.rb', line 11

def search_list
  if params[:restaurant_id] == 'all'
    @data = list
  elsif current_owner.restaurant_ids.include? params[:restaurant_id].to_i
    @data = TicketGroup.joins(:restaurants).
      where(ticket_group_restaurants: { restaurant_id: params[:restaurant_id] })
  else
    redirect_to :list_dashboard_v2_group_voucher_marketplaces, notice: 'Restaurant not found'
  end
end