Class: ReceiptDetail
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ReceiptDetail
- Includes:
- Models::Auditable, Models::TaxjarSubmittable
- Defined in:
- app/models/receipt_detail.rb
Overview
== Schema Information
Table name: receipt_details
Database name: primary
id :integer not null, primary key
amount :decimal(8, 2)
category :string(255)
discount :decimal(8, 2) default(0.0)
discount_code :string(255)
gl_date :date
remark :string
state :string(255)
tax_document_reference :string
taxjar_state :string
voided :boolean
write_off :decimal(8, 2) default(0.0)
write_off_code :string(255)
created_at :datetime
updated_at :datetime
business_unit_id :integer
creator_id :integer
credit_memo_id :integer
deleter_id :integer
invoice_id :integer
ledger_company_account_id :integer
ledger_detail_project_id :integer
receipt_id :integer
updater_id :integer
Indexes
by_iid_rid (invoice_id,receipt_id)
index_receipt_details_on_credit_memo_id (credit_memo_id)
receipt_id_category (receipt_id,category)
taxjar_state_created_at (taxjar_state,created_at)
Constant Summary collapse
- WRITE_OFF_CODE_DETAILS =
{ "Bad Debt" => {:account => BAD_DEBT_ACCOUNT, :business_unit => "accounting"}, "Rebate" => {:account => REBATES_ACCOUNT, :business_unit => "sales"}, "Minor Write Off" => {:account => MINOR_WRITE_OFF_ACCOUNT, :business_unit => "accounting"} }
- WRITE_OFF_CODES =
WRITE_OFF_CODE_DETAILS.keys.sort
- CATEGORIES =
["Invoice", "Credit Memo", "GL Account"]
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
-
#company_account_ref ⇒ Object
Returns the value of attribute company_account_ref.
-
#credit_memo_ref ⇒ Object
Returns the value of attribute credit_memo_ref.
-
#customer_name ⇒ Object
Returns the value of attribute customer_name.
-
#invoice_balance ⇒ Object
Returns the value of attribute invoice_balance.
-
#invoice_ref ⇒ Object
Returns the value of attribute invoice_ref.
-
#invoice_total ⇒ Object
Returns the value of attribute invoice_total.
-
#is_a_new_record ⇒ Object
Returns the value of attribute is_a_new_record.
-
#order_ref ⇒ Object
Returns the value of attribute order_ref.
-
#pos_amount ⇒ Object
Returns the value of attribute pos_amount.
-
#project_ref ⇒ Object
Returns the value of attribute project_ref.
Belongs to collapse
- #business_unit ⇒ BusinessUnit
- #credit_memo ⇒ CreditMemo
- #invoice ⇒ Invoice
- #ledger_company_account ⇒ LedgerCompanyAccount
- #ledger_detail_project ⇒ LedgerDetailProject
- #receipt ⇒ Receipt
Methods included from Models::Auditable
Class Method Summary collapse
-
.gl_accounts ⇒ ActiveRecord::Relation<ReceiptDetail>
A relation of ReceiptDetails that are gl accounts.
-
.invoices ⇒ ActiveRecord::Relation<ReceiptDetail>
A relation of ReceiptDetails that are invoices.
-
.non_voided ⇒ ActiveRecord::Relation<ReceiptDetail>
A relation of ReceiptDetails that are non voided.
Instance Method Summary collapse
- #applied_amount ⇒ Object
- #description(with_order = false) ⇒ Object
- #shipping_address ⇒ Object
- #tax_document ⇒ Object
Methods included from Models::TaxjarSubmittable
#customer_sync_instance, #delete_from_taxjar, #evaluate_taxjar_submission, #record_already_exists_on_taxjar?, #resubmit_to_taxjar, #should_be_submitted_to_taxjar?, #should_sync_customer_with_taxjar?, #submit_to_taxjar, #sync_customer_with_taxjar, #taxjar_customer_id, #taxjar_submission_instance
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::EventPublishable
Instance Attribute Details
#company_account_ref ⇒ Object
Returns the value of attribute company_account_ref.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def company_account_ref @company_account_ref end |
#credit_memo_ref ⇒ Object
Returns the value of attribute credit_memo_ref.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def credit_memo_ref @credit_memo_ref end |
#customer_name ⇒ Object
Returns the value of attribute customer_name.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def customer_name @customer_name end |
#invoice_balance ⇒ Object
Returns the value of attribute invoice_balance.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def invoice_balance @invoice_balance end |
#invoice_ref ⇒ Object
Returns the value of attribute invoice_ref.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def invoice_ref @invoice_ref end |
#invoice_total ⇒ Object
Returns the value of attribute invoice_total.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def invoice_total @invoice_total end |
#is_a_new_record ⇒ Object
Returns the value of attribute is_a_new_record.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def is_a_new_record @is_a_new_record end |
#order_ref ⇒ Object
Returns the value of attribute order_ref.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def order_ref @order_ref end |
#pos_amount ⇒ Object
Returns the value of attribute pos_amount.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def pos_amount @pos_amount end |
#project_ref ⇒ Object
Returns the value of attribute project_ref.
143 144 145 |
# File 'app/models/receipt_detail.rb', line 143 def project_ref @project_ref end |
Class Method Details
.gl_accounts ⇒ ActiveRecord::Relation<ReceiptDetail>
A relation of ReceiptDetails that are gl accounts. Active Record Scope
126 |
# File 'app/models/receipt_detail.rb', line 126 scope :gl_accounts, -> { where(:category => "GL Account") } |
.invoices ⇒ ActiveRecord::Relation<ReceiptDetail>
A relation of ReceiptDetails that are invoices. Active Record Scope
125 |
# File 'app/models/receipt_detail.rb', line 125 scope :invoices, -> { where(:category => "Invoice") } |
.non_voided ⇒ ActiveRecord::Relation<ReceiptDetail>
A relation of ReceiptDetails that are non voided. Active Record Scope
124 |
# File 'app/models/receipt_detail.rb', line 124 scope :non_voided, -> { where("state != 'voided'") } |
Instance Method Details
#applied_amount ⇒ Object
145 146 147 |
# File 'app/models/receipt_detail.rb', line 145 def applied_amount self.amount + self.discount + self.write_off end |
#business_unit ⇒ BusinessUnit
93 |
# File 'app/models/receipt_detail.rb', line 93 belongs_to :business_unit, optional: true |
#credit_memo ⇒ CreditMemo
90 |
# File 'app/models/receipt_detail.rb', line 90 belongs_to :credit_memo, :inverse_of => :receipt_details, optional: true |
#description(with_order = false) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/models/receipt_detail.rb', line 188 def description(with_order = false) case category when "Invoice" desc = invoice.reference_number desc += " (#{invoice.order.reference_number})" if with_order and invoice.order.present? desc when "Credit Memo" credit_memo.reference_number when "GL Account" nil end end |
#invoice ⇒ Invoice
88 |
# File 'app/models/receipt_detail.rb', line 88 belongs_to :invoice, :inverse_of => :receipt_details, optional: true |
#ledger_company_account ⇒ LedgerCompanyAccount
91 |
# File 'app/models/receipt_detail.rb', line 91 belongs_to :ledger_company_account, optional: true |
#ledger_detail_project ⇒ LedgerDetailProject
92 |
# File 'app/models/receipt_detail.rb', line 92 belongs_to :ledger_detail_project, optional: true |
#receipt ⇒ Receipt
89 |
# File 'app/models/receipt_detail.rb', line 89 belongs_to :receipt, :inverse_of => :receipt_details, optional: true |
#shipping_address ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 |
# File 'app/models/receipt_detail.rb', line 206 def shipping_address if invoice invoice.shipping_address elsif credit_memo credit_memo.shipping_address elsif tax_document tax_document.shipping_address else nil end end |
#tax_document ⇒ Object
201 202 203 204 |
# File 'app/models/receipt_detail.rb', line 201 def tax_document return nil if tax_document_reference.nil? Invoice.find_by(reference_number: tax_document_reference) || CreditMemo.find_by(reference_number: tax_document_reference) end |