Class: Ticket

Inherits:
ApplicationRecord show all
Defined in:
app/models/ticket.rb

Overview

Schema Information

Table name: tickets

id                     :bigint           not null, primary key
active                 :boolean          default(FALSE)
amount_cents           :integer          default(0), not null
amount_currency        :string(191)      default("THB"), not null
commision              :decimal(5, 2)
guest_detail           :text(65535)
name                   :string(191)
phone                  :string(191)
redeemed_at            :datetime
ticket_code            :string(191)
ticket_name            :string(255)
valid_end_date         :date
valid_start_date       :date
created_at             :datetime         not null
updated_at             :datetime         not null
custom_label_id        :bigint
guest_id               :bigint
package_type_id        :bigint
partner_ticket_code_id :bigint
ticket_group_id        :bigint
ticket_transaction_id  :bigint
user_id                :bigint

Indexes

index_tickets_on_custom_label_id         (custom_label_id)
index_tickets_on_guest_id                (guest_id)
index_tickets_on_package_type_id         (package_type_id)
index_tickets_on_partner_ticket_code_id  (partner_ticket_code_id)
index_tickets_on_ticket_code             (ticket_code)
index_tickets_on_ticket_group_id         (ticket_group_id)
index_tickets_on_ticket_transaction_id   (ticket_transaction_id)
index_tickets_on_user_id                 (user_id)

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


82
83
84
85
# File 'app/models/ticket.rb', line 82

def expired?
  now = Time.thai_time
  valid_end_date < now.to_date
end

#qrcode_data_urlObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/ticket.rb', line 65

def qrcode_data_url
  qrcode = RQRCode::QRCode.new(ticket_code.to_s)
  png = qrcode.as_png(
    bit_depth: 1,
    border_modules: 4,
    color_mode: ChunkyPNG::COLOR_GRAYSCALE,
    color: 'black',
    file: nil,
    fill: 'white',
    module_px_size: 6,
    resize_exactly_to: false,
    resize_gte_to: false,
    size: 500,
  )
  png.to_data_url
end