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 Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #amount ⇒ Object 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 Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#amount ⇒ Object (readonly)
38 |
# File 'app/models/outgoing_payment_item.rb', line 38 validates :amount, :presence => true, :numericality => true |
Class Method Details
.applied ⇒ ActiveRecord::Relation<OutgoingPaymentItem>
A relation of OutgoingPaymentItems that are applied. Active Record Scope
43 |
# File 'app/models/outgoing_payment_item.rb', line 43 scope :applied, -> { where(:state => "applied") } |
.not_voided ⇒ ActiveRecord::Relation<OutgoingPaymentItem>
A relation of OutgoingPaymentItems that are not voided. Active Record Scope
44 |
# File 'app/models/outgoing_payment_item.rb', line 44 scope :not_voided, -> { where(:state => ["draft", "applied"]) } |
Instance Method Details
#credit_memo ⇒ CreditMemo
35 |
# File 'app/models/outgoing_payment_item.rb', line 35 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.
164 165 166 167 168 169 170 171 172 |
# File 'app/models/outgoing_payment_item.rb', line 164 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.
136 137 138 139 140 141 142 143 144 |
# File 'app/models/outgoing_payment_item.rb', line 136 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.
121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/outgoing_payment_item.rb', line 121 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
33 |
# File 'app/models/outgoing_payment_item.rb', line 33 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.
106 107 108 109 110 111 112 113 114 |
# File 'app/models/outgoing_payment_item.rb', line 106 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
36 |
# File 'app/models/outgoing_payment_item.rb', line 36 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.
150 151 152 153 154 155 156 157 158 |
# File 'app/models/outgoing_payment_item.rb', line 150 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.
203 204 205 206 207 208 209 |
# File 'app/models/outgoing_payment_item.rb', line 203 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/outgoing_payment_item.rb', line 70 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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/outgoing_payment_item.rb', line 87 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
34 |
# File 'app/models/outgoing_payment_item.rb', line 34 belongs_to :voucher_item, optional: true |
#voucher_number ⇒ String?
Reference number of the parent Voucher (when this line settles a
voucher item).
178 179 180 181 182 183 184 |
# File 'app/models/outgoing_payment_item.rb', line 178 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.
191 192 193 194 195 196 197 |
# File 'app/models/outgoing_payment_item.rb', line 191 def voucher_upload if voucher_item.present? and voucher_item.voucher.uploads.any? voucher_item.voucher.uploads.first else nil end end |