2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2019-02-01 19:40:24 +00:00
|
|
|
class TicketLevel < ApplicationRecord
|
2019-08-06 14:08:15 +00:00
|
|
|
# :amount, #integer
|
|
|
|
# :amount_dollars, #accessor, string
|
|
|
|
# :name, #string
|
|
|
|
# :description, #text
|
|
|
|
# :quantity, #integer
|
|
|
|
# :deleted, #bool for soft delete
|
|
|
|
# :event_id,
|
|
|
|
# :admin_only, #bool, only admins can create tickets for this level
|
|
|
|
# :limit, #int: for limiting the number of tickets to be sold
|
|
|
|
# :order #int: order in which to be displayed
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
attr_accessor :amount_dollars
|
|
|
|
|
|
|
|
has_many :tickets
|
|
|
|
belongs_to :event
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
validates :name, presence: true
|
|
|
|
validates :event_id, presence: true
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
scope :not_deleted, -> { where(deleted: [false, nil]) }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
before_validation do
|
2019-07-30 21:29:24 +00:00
|
|
|
self.amount = Format::Currency.dollars_to_cents(amount_dollars) if amount_dollars.present?
|
|
|
|
self.amount = 0 if amount.nil?
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|