internetee-registry/app/models/account_activity.rb
2015-07-07 12:57:56 +03:00

37 lines
746 B
Ruby

require 'csv'
class AccountActivity < ActiveRecord::Base
include Versions
belongs_to :account
belongs_to :bank_transaction
belongs_to :invoice
CREATE = 'create'
RENEW = 'renew'
ADD_CREDIT = 'add_credit'
after_create :update_balance
def update_balance
account.balance += sum
account.save
end
class << self
def types_for_select
[CREATE, RENEW, ADD_CREDIT].map { |x| [I18n.t(x), x] }
end
def to_csv
attributes = %w(description activity_type created_at sum)
CSV.generate(headers: true) do |csv|
csv << %w(description activity_type receipt_date sum)
all.find_each do |x|
csv << attributes.map { |attr| x.send(attr) }
end
end
end
end
end