Class: VoucherGroup

Inherits:
ApplicationRecord show all
Includes:
Counter::CounterCache, IdentityCache
Defined in:
app/models/voucher_group.rb

Overview

Schema Information

Table name: voucher_groups

id         :bigint           not null, primary key
name       :string(191)
created_at :datetime         not null
updated_at :datetime         not null

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Instance Method Details

#humanized_amountObject



32
33
34
# File 'app/models/voucher_group.rb', line 32

def humanized_amount
  Money.new(amount * 100, 'THB').format(symbol: true, no_cents: true)
end

#humanized_total_used_amountObject



36
37
38
# File 'app/models/voucher_group.rb', line 36

def humanized_total_used_amount
  Money.new(total_used_amount * 100, 'THB').format(symbol: true, no_cents: true)
end

#update_members(voucher_params, id = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/voucher_group.rb', line 40

def update_members(voucher_params, id = nil)
  voucher_params.each do |voucher_param|
    if voucher_param[:_destroy] == 'false'
      voucher = ::Voucher.find(voucher_param['id'])
      vouchers << voucher
    elsif id
      vouchers.delete(voucher_param['id'])
    end
  end
  true
end