Class: OutgoingPaymentItem
Overview
== Schema Information
Table name: outgoing_payment_items
Database name: primary
id :integer not null, primary key
amount :decimal(10, 2)
state :string(255)
created_at :datetime
updated_at :datetime
creator_id :integer
credit_memo_id :integer
outgoing_payment_id :integer
receipt_id :integer
updater_id :integer
voucher_item_id :integer
Indexes
credit_memo_id_outgoing_payment_id (credit_memo_id,outgoing_payment_id)
index_outgoing_payment_items_on_outgoing_payment_id (outgoing_payment_id)
index_outgoing_payment_items_on_receipt_id (receipt_id)
index_outgoing_payment_items_on_voucher_item_id (voucher_item_id)
state_credit_memo_id (state,credit_memo_id)
state_receipt_id (state,receipt_id)
state_voucher_item_id (state,voucher_item_id)
Constant Summary
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
#creator, #updater
Class Method Summary
collapse
Instance Method Summary
collapse
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#amount ⇒ Object
37
|
# File 'app/models/outgoing_payment_item.rb', line 37
validates :amount, :presence => true, :numericality => true
|
Class Method Details
A relation of OutgoingPaymentItems that are applied. Active Record Scope
42
|
# File 'app/models/outgoing_payment_item.rb', line 42
scope :applied, -> { where(:state => "applied") }
|
A relation of OutgoingPaymentItems that are not voided. Active Record Scope
43
|
# File 'app/models/outgoing_payment_item.rb', line 43
scope :not_voided, -> { where(:state => ["draft", "applied"]) }
|
Instance Method Details
34
|
# File 'app/models/outgoing_payment_item.rb', line 34
belongs_to :credit_memo, optional: true
|
#gross_amount ⇒ Object
134
135
136
137
138
139
140
141
142
|
# File 'app/models/outgoing_payment_item.rb', line 134
def gross_amount
if credit_memo.present?
credit_memo.total
elsif voucher_item.present?
voucher_item.gross_amount
elsif receipt.present?
receipt.amount
end
end
|
#invoice_date ⇒ Object
114
115
116
117
118
119
120
121
122
|
# File 'app/models/outgoing_payment_item.rb', line 114
def invoice_date
if credit_memo.present?
credit_memo.document_date
elsif voucher_item.present?
voucher_item.voucher.invoice_date
elsif receipt.present?
receipt.receipt_date
end
end
|
#invoice_number(with_prefix = false) ⇒ Object
103
104
105
106
107
108
109
110
111
112
|
# File 'app/models/outgoing_payment_item.rb', line 103
def invoice_number(with_prefix=false)
prefix, ref = if credit_memo.present?
["DM", credit_memo.reference_number]
elsif voucher_item.present?
["INV", voucher_item.voucher.invoice_number]
elsif receipt.present?
["R", receipt.id]
end
with_prefix ? "#{prefix} #{ref}" : ref
end
|
32
|
# File 'app/models/outgoing_payment_item.rb', line 32
belongs_to :outgoing_payment, :inverse_of => :outgoing_payment_items, optional: true
|
#payee ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'app/models/outgoing_payment_item.rb', line 93
def payee
if credit_memo.present?
credit_memo.billing_customer
elsif voucher_item.present?
voucher_item.payee || voucher_item.voucher.supplier
elsif receipt.present?
receipt.customer
end
end
|
35
|
# File 'app/models/outgoing_payment_item.rb', line 35
belongs_to :receipt, :inverse_of => :outgoing_payment_items, optional: true
|
124
125
126
127
128
129
130
131
132
|
# File 'app/models/outgoing_payment_item.rb', line 124
def
if credit_memo.present?
credit_memo.
elsif voucher_item.present?
voucher_item.
elsif receipt.present?
receipt.
end
end
|
#spiff_enrollment ⇒ Object
160
161
162
163
164
165
166
|
# File 'app/models/outgoing_payment_item.rb', line 160
def spiff_enrollment
if voucher_item.present?
voucher_item.spiff_enrollment
else
nil
end
end
|
#update_resource_state ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/models/outgoing_payment_item.rb', line 63
def update_resource_state
if voucher_item.present?
voucher_item.paid
return true
elsif credit_memo.present?
credit_memo.offset!
credit_memo.rma.sync_state if credit_memo.rma.present?
return true
elsif receipt.present?
receipt.apply
else
return false
end
end
|
#void_resource ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/models/outgoing_payment_item.rb', line 78
def void_resource
if voucher_item.present?
voucher_item.state_event = "unpaid"
voucher_item.save!
elsif credit_memo.present?
credit_memo.state_event = "unoffset"
credit_memo.save!
elsif receipt.present?
receipt.state_event = "unapply"
receipt.save!
else
return false
end
end
|
33
|
# File 'app/models/outgoing_payment_item.rb', line 33
belongs_to :voucher_item, optional: true
|
#voucher_number ⇒ Object
144
145
146
147
148
149
150
|
# File 'app/models/outgoing_payment_item.rb', line 144
def voucher_number
if voucher_item.present?
voucher_item.voucher.reference_number
else
nil
end
end
|
#voucher_upload ⇒ Object
152
153
154
155
156
157
158
|
# File 'app/models/outgoing_payment_item.rb', line 152
def voucher_upload
if voucher_item.present? and voucher_item.voucher.uploads.any?
voucher_item.voucher.uploads.first
else
nil
end
end
|