forked from siwapp/siwapp-ror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment.rb
66 lines (57 loc) · 1.42 KB
/
payment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
class Payment < ActiveRecord::Base
acts_as_paranoid
belongs_to :invoice
belongs_to :payment_receiver, optional: true
has_one :customer, through: :invoice
validates :date, presence: true
validates :amount, presence: true, numericality: true
before_save do
self.amount = self.amount.round self.invoice.currency_precision
end
after_save do
invoice.save
end
after_destroy do
invoice.save
end
def complete?
status == Payment.statuses[:complete]
end
def self.statuses
::Enum.new(
initial: 1,
pending: 2,
complete: 3
)
end
def to_jbuilder
Jbuilder.new do |json|
json.(self, :date, :amount, :notes)
end
end
end
# == Schema Information
#
# Table name: payments
#
# id :bigint not null, primary key
# amount :decimal(53, 15)
# date :date
# deleted_at :datetime
# notes :text
# status :integer default(1)
# created_at :datetime not null
# updated_at :datetime not null
# invoice_id :integer not null
# payment_receiver_id :bigint
#
# Indexes
#
# index_payments_on_deleted_at (deleted_at)
# index_payments_on_payment_receiver_id (payment_receiver_id)
# invoice_id_idx (invoice_id)
#
# Foreign Keys
#
# fk_rails_... (payment_receiver_id => payment_receivers.id)
#