Class: OutgoingPaymentItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- OutgoingPaymentItem
- Includes:
- Models::Auditable
- Defined in:
- app/models/outgoing_payment_item.rb
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
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #amount ⇒ BigDecimal readonly
Belongs to collapse
- #credit_memo ⇒ CreditMemo?
- #outgoing_payment ⇒ OutgoingPayment?
- #receipt ⇒ Receipt?
- #voucher_item ⇒ VoucherItem?
Methods included from Models::Auditable
Class Method Summary collapse
-
.applied ⇒ ActiveRecord::Relation<OutgoingPaymentItem>
A relation of OutgoingPaymentItems that are applied.
-
.not_voided ⇒ ActiveRecord::Relation<OutgoingPaymentItem>
A relation of OutgoingPaymentItems that are not voided.
Instance Method Summary collapse
-
#gross_amount ⇒ BigDecimal?
Pre-discount face value of the source document; the #amount on this line may be smaller when discounts or partial payments apply.
-
#invoice_date ⇒ Date?
Document date of the source resource: vendor invoice date, credit memo date, or receipt date.
-
#invoice_number(with_prefix = false) ⇒ String?
Reference number of the source document (voucher invoice, credit memo, or receipt) this line settles.
-
#payee ⇒ Customer, ...
Party receiving (or netted against) this line.
-
#remark ⇒ String?
Free-text remark from the source resource, used on check stubs and AP reports.
-
#spiff_enrollment ⇒ SpiffEnrollment?
SPIFF enrollment associated with the underlying voucher item, used to link AP payouts back to commission/incentive programs.
-
#update_resource_state ⇒ Boolean?
Cascade the applied state to the linked accounts-payable resource.
-
#void_resource ⇒ Object
Reverse #update_resource_state when this line is voided so the voucher/credit memo/receipt returns to its open balance.
-
#voucher_number ⇒ String?
Reference number of the parent Voucher (when this line settles a voucher item).
-
#voucher_upload ⇒ Upload?
First attached upload (scanned vendor invoice etc.) on the parent Voucher; returns nil for credit-memo or receipt-backed lines or when the voucher has no uploads.
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#amount ⇒ BigDecimal (readonly)
43 |
# File 'app/models/outgoing_payment_item.rb', line 43 validates :amount, :presence => true, :numericality => true |
Class Method Details
.applied ⇒ ActiveRecord::Relation<OutgoingPaymentItem>
A relation of OutgoingPaymentItems that are applied. Active Record Scope
48 |
# File 'app/models/outgoing_payment_item.rb', line 48 scope :applied, -> { where(:state => "applied") } |
.not_voided ⇒ ActiveRecord::Relation<OutgoingPaymentItem>
A relation of OutgoingPaymentItems that are not voided. Active Record Scope
49 |
# File 'app/models/outgoing_payment_item.rb', line 49 scope :not_voided, -> { where(:state => ["draft", "applied"]) } |
Instance Method Details
#credit_memo ⇒ CreditMemo?
38 |
# File 'app/models/outgoing_payment_item.rb', line 38 belongs_to :credit_memo, optional: true |
#gross_amount ⇒ BigDecimal?
Pre-discount face value of the source document; the #amount on this
line may be smaller when discounts or partial payments apply.
169 170 171 172 173 174 175 176 177 |
# File 'app/models/outgoing_payment_item.rb', line 169 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 ⇒ Date?
Document date of the source resource: vendor invoice date, credit memo
date, or receipt date.
141 142 143 144 145 146 147 148 149 |
# File 'app/models/outgoing_payment_item.rb', line 141 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) ⇒ String?
Reference number of the source document (voucher invoice, credit memo,
or receipt) this line settles.
126 127 128 129 130 131 132 133 134 135 |
# File 'app/models/outgoing_payment_item.rb', line 126 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 |
#outgoing_payment ⇒ OutgoingPayment?
34 |
# File 'app/models/outgoing_payment_item.rb', line 34 belongs_to :outgoing_payment, :inverse_of => :outgoing_payment_items, optional: true |
#payee ⇒ Customer, ...
Party receiving (or netted against) this line. Vendor for a voucher
payment, customer for a credit memo offset or unapplied receipt.
111 112 113 114 115 116 117 118 119 |
# File 'app/models/outgoing_payment_item.rb', line 111 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 |
#receipt ⇒ Receipt?
40 |
# File 'app/models/outgoing_payment_item.rb', line 40 belongs_to :receipt, :inverse_of => :outgoing_payment_items, optional: true |
#remark ⇒ String?
Free-text remark from the source resource, used on check stubs and AP
reports.
155 156 157 158 159 160 161 162 163 |
# File 'app/models/outgoing_payment_item.rb', line 155 def remark if credit_memo.present? credit_memo.remark elsif voucher_item.present? voucher_item.remark elsif receipt.present? receipt.remark end end |
#spiff_enrollment ⇒ SpiffEnrollment?
SPIFF enrollment associated with the underlying voucher item, used to
link AP payouts back to commission/incentive programs.
208 209 210 211 212 213 214 |
# File 'app/models/outgoing_payment_item.rb', line 208 def spiff_enrollment if voucher_item.present? voucher_item.spiff_enrollment else nil end end |
#update_resource_state ⇒ Boolean?
Cascade the applied state to the linked accounts-payable resource.
Marks the VoucherItem paid, offsets a CreditMemo (and resyncs its
parent RMA), or applies the Receipt when unapplied funds are being
used to pay a voucher.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/outgoing_payment_item.rb', line 75 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
Reverse #update_resource_state when this line is voided so the
voucher/credit memo/receipt returns to its open balance.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/outgoing_payment_item.rb', line 92 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 |
#voucher_item ⇒ VoucherItem?
36 |
# File 'app/models/outgoing_payment_item.rb', line 36 belongs_to :voucher_item, optional: true |
#voucher_number ⇒ String?
Reference number of the parent Voucher (when this line settles a
voucher item).
183 184 185 186 187 188 189 |
# File 'app/models/outgoing_payment_item.rb', line 183 def voucher_number if voucher_item.present? voucher_item.voucher.reference_number else nil end end |
#voucher_upload ⇒ Upload?
First attached upload (scanned vendor invoice etc.) on the parent
Voucher; returns nil for credit-memo or receipt-backed lines or
when the voucher has no uploads.
196 197 198 199 200 201 202 |
# File 'app/models/outgoing_payment_item.rb', line 196 def voucher_upload if voucher_item.present? and voucher_item.voucher.uploads.any? voucher_item.voucher.uploads.first else nil end end |