Class: SalesController

Inherits:
ArtfullyOseController show all
Includes:
CartFinder
Defined in:
app/controllers/sales_controller.rb

Instance Method Summary collapse

Methods included from CartFinder

#cart_name, #create_new_cart, #current_box_office_cart, #current_cart, #current_cart=, #current_sales_console_cart, #session_cart, #session_key

Instance Method Details

#checking_out?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/controllers/sales_controller.rb', line 68

def checking_out?
  params[:commit].present?
end

#createObject



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

def create
  current_box_office_cart.clear!

  @sale = Sale.new(@show, @show.chart.ticket_types.box_office, current_box_office_cart, params[:quantities], params[:order_notes])

  # handle donation
  if params[:donation].present? && params[:donation].to_i > 0
    donation                 = Donation.new
    donation.amount          = params[:donation].to_i * 100
    donation.organization_id = @event.organization_id
    current_box_office_cart.donations << donation
  end

  # handle discount
  begin
    discount = Discount.find_by_code_and_event_id(params[:discount].upcase, @event)
    discount.apply_discount_to_cart(current_box_office_cart)
  rescue RuntimeError => e
    discount_error = e.message
  rescue NoMethodError => e
    discount_error = "We could not find your discount. Please try again." if params[:discount].present?
  end

  if checking_out?
    if @sale.sell(payment)
      @sale.message = "Sold #{self.class.helpers.pluralize(@sale.tickets.length, 'ticket')}.  Order total was #{self.class.helpers.number_as_cents @sale.order.total}"

      if params[:auto_check_in].present?
        @sale.tickets.map {|t| t.reload; t.validate_ticket!(current_user)}
      end
    end
  end

  unless @sale.errors.empty?
    @sale.error = "#{@sale.errors.full_messages.to_sentence.capitalize}."
    flash[:error] = @sale.error
    Ticket.unlock(@sale.tickets, @sale.cart)
    render :js => "window.location = '#{new_event_show_sales_path(@event,@show,:render => 'boxoffice')}'"
    return
  end

  render :json => @sale.as_json
                       .merge(:total => @sale.cart.total)
                       .merge(:tickets_remaining => tickets_remaining)
                       .merge(:door_list_rows => door_list_rows)
                       .merge(:discount_error => discount_error)
                       .merge(:discount_amount => current_box_office_cart.discount_amount),
                       :status => 200
end

#door_listObject



91
92
93
94
# File 'app/controllers/sales_controller.rb', line 91

def door_list
  # create_door_list
  render :partial => "sales/doorlist"
end

#door_list_rowsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/sales_controller.rb', line 72

def door_list_rows
  door_list_rows = []

  @sale.tickets.each_with_index do |ticket, i|
    ticket.reload
    if ticket.sold? || ticket.comped?
      door_list_rows[i] = {}
      door_list_rows[i]['first_name'] = @sale.buyer.first_name
      door_list_rows[i]['last_name'] = @sale.buyer.last_name
      door_list_rows[i]['email'] = @sale.buyer.email
      door_list_rows[i]['ticket_type'] = ticket.ticket_type.name
      door_list_rows[i]['ticket_id'] = ticket.id
      door_list_rows[i]['payment_method'] = ticket.sold_item.order.payment_method
      door_list_rows[i]['price'] = ticket.sold_price
    end
  end
  door_list_rows
end

#newObject



10
11
12
13
14
15
16
# File 'app/controllers/sales_controller.rb', line 10

def new
  @person = Person.new
  @sale = Sale.new(@show, @show.chart.ticket_types.box_office, current_box_office_cart, {})
  @tickets_remaining = tickets_remaining
  setup_defaults
  response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" # http://stackoverflow.com/a/5493543/2063202
end

#showObject



6
7
8
# File 'app/controllers/sales_controller.rb', line 6

def show
  redirect_to new_event_show_sales_path(@event,@show,:render => 'boxoffice')
end