Class: VoucherItem
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- VoucherItem
- Includes:
- Models::Auditable
- Defined in:
- app/models/voucher_item.rb
Overview
== Schema Information
Table name: voucher_items
Database name: primary
id :integer not null, primary key
due_date :date
gross_amount :decimal(8, 2)
jde_line :integer
remark :string(255)
state :string(255)
tax_amount :decimal(8, 2)
tax_only :boolean
tax_rate_percentage :decimal(6, 4)
tax_type :string(255)
taxable_amount :decimal(8, 2)
created_at :datetime
updated_at :datetime
business_unit_id :integer
creator_id :integer
gl_offset_account_id :integer
payee_id :integer
tax_rate_id :integer
updater_id :integer
voucher_id :integer
Indexes
index_voucher_items_on_payee_id (payee_id)
voucher_id_state (voucher_id,state)
Constant Summary collapse
- VOUCHER_TAX_TYPES =
Recognised voucher tax types.
['S', 'U', 'V', 'N/A'].freeze
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #due_date ⇒ Object readonly
- #gross_amount ⇒ Object readonly
- #remark ⇒ Object readonly
- #tax_amount ⇒ Object readonly
- #tax_rate_id ⇒ Object readonly
- #tax_rate_percentage ⇒ Object readonly
- #tax_type ⇒ Object readonly
- #taxable_amount ⇒ Object readonly
Belongs to collapse
- #business_unit ⇒ BusinessUnit
- #gl_offset_account ⇒ LedgerCompanyAccount
- #payee ⇒ Party
- #tax_rate ⇒ TaxRate
- #voucher ⇒ Voucher
Methods included from Models::Auditable
Has many collapse
Class Method Summary collapse
-
.approved ⇒ ActiveRecord::Relation<VoucherItem>
A relation of VoucherItems that are approved.
-
.available_to_apply ⇒ ActiveRecord::Relation<VoucherItem>
A relation of VoucherItems that are available to apply.
-
.for_company_id ⇒ ActiveRecord::Relation<VoucherItem>
A relation of VoucherItems that are for company id.
Instance Method Summary collapse
- #amount_paid_in_full? ⇒ Boolean
- #amount_partially_paid? ⇒ Boolean
-
#available_statuses ⇒ Array<String>
State values an AP user is allowed to pick from in the UI.
-
#balance ⇒ BigDecimal
Outstanding amount still owed to the vendor on this line.
-
#gl_offset_account_ref ⇒ String?
Human-readable identifier of the GL offset account (
gl_offset_account.identifier), used in CSV/import flows. - #gl_offset_account_ref=(identifier) ⇒ Object
- #no_payment_made? ⇒ Boolean
-
#payee_name ⇒ String?
Display name of the line-level payee (an alternate Party that supersedes the voucher-level supplier when the supplier delegates payment, e.g. installer commissions).
-
#payee_type ⇒ String?
Polymorphic class name of the payee Party.
-
#spiff_enrollment ⇒ SpiffEnrollment?
SPIFF enrollment inherited from the Order that produced the voucher.
-
#status_locked? ⇒ Boolean
True once any payment has been applied; AP locks editable status transitions in that case.
-
#tax_rate_name ⇒ String?
Short tax-rate label (for AP grids).
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
#due_date ⇒ Object (readonly)
47 |
# File 'app/models/voucher_item.rb', line 47 validates :gross_amount, :due_date, :tax_type, presence: true |
#gross_amount ⇒ Object (readonly)
47 |
# File 'app/models/voucher_item.rb', line 47 validates :gross_amount, :due_date, :tax_type, presence: true |
#remark ⇒ Object (readonly)
55 |
# File 'app/models/voucher_item.rb', line 55 validates :remark, length: { maximum: 255 } |
#tax_amount ⇒ Object (readonly)
49 |
# File 'app/models/voucher_item.rb', line 49 validates :taxable_amount, :tax_amount, :tax_rate_percentage, presence: { unless: :tax_not_applicable } |
#tax_rate_id ⇒ Object (readonly)
48 |
# File 'app/models/voucher_item.rb', line 48 validates :tax_rate_id, presence: { if: :requires_tax_rate } |
#tax_rate_percentage ⇒ Object (readonly)
49 |
# File 'app/models/voucher_item.rb', line 49 validates :taxable_amount, :tax_amount, :tax_rate_percentage, presence: { unless: :tax_not_applicable } |
#tax_type ⇒ Object (readonly)
47 |
# File 'app/models/voucher_item.rb', line 47 validates :gross_amount, :due_date, :tax_type, presence: true |
#taxable_amount ⇒ Object (readonly)
49 |
# File 'app/models/voucher_item.rb', line 49 validates :taxable_amount, :tax_amount, :tax_rate_percentage, presence: { unless: :tax_not_applicable } |
Class Method Details
.approved ⇒ ActiveRecord::Relation<VoucherItem>
A relation of VoucherItems that are approved. Active Record Scope
64 |
# File 'app/models/voucher_item.rb', line 64 scope :approved, -> { where(state: 'approved') } |
.available_to_apply ⇒ ActiveRecord::Relation<VoucherItem>
A relation of VoucherItems that are available to apply. Active Record Scope
66 |
# File 'app/models/voucher_item.rb', line 66 scope :available_to_apply, -> { joins(:voucher).where(voucher: { state: 'unpaid' }).where(state: %w[approved partially_paid]) } |
.for_company_id ⇒ ActiveRecord::Relation<VoucherItem>
A relation of VoucherItems that are for company id. Active Record Scope
65 |
# File 'app/models/voucher_item.rb', line 65 scope :for_company_id, ->(company_id) { joins(:voucher).where(vouchers: { company_id: }) } |
Instance Method Details
#amount_paid_in_full? ⇒ Boolean
131 132 133 |
# File 'app/models/voucher_item.rb', line 131 def amount_paid_in_full? outgoing_payment_items.applied.sum(:amount) == gross_amount end |
#amount_partially_paid? ⇒ Boolean
135 136 137 |
# File 'app/models/voucher_item.rb', line 135 def amount_partially_paid? outgoing_payment_items.applied.sum(:amount) != 0 end |
#available_statuses ⇒ Array<String>
State values an AP user is allowed to pick from in the UI. Once
payments are applied, paid/partially_paid become legal options too.
165 166 167 168 169 170 171 |
# File 'app/models/voucher_item.rb', line 165 def available_statuses if status_locked? %w[approved on_hold partially_paid fully_paid] else %w[approved on_hold] end end |
#balance ⇒ BigDecimal
Outstanding amount still owed to the vendor on this line.
146 147 148 |
# File 'app/models/voucher_item.rb', line 146 def balance gross_amount - outgoing_payment_items.applied.sum(:amount) end |
#business_unit ⇒ BusinessUnit
43 |
# File 'app/models/voucher_item.rb', line 43 belongs_to :business_unit, optional: true |
#gl_offset_account ⇒ LedgerCompanyAccount
41 |
# File 'app/models/voucher_item.rb', line 41 belongs_to :gl_offset_account, class_name: 'LedgerCompanyAccount', optional: true |
#gl_offset_account_ref ⇒ String?
Returns human-readable identifier of the GL offset
account (gl_offset_account.identifier), used in CSV/import flows.
175 176 177 |
# File 'app/models/voucher_item.rb', line 175 def gl_offset_account_ref gl_offset_account&.identifier end |
#gl_offset_account_ref=(identifier) ⇒ Object
179 180 181 |
# File 'app/models/voucher_item.rb', line 179 def gl_offset_account_ref=(identifier) self.gl_offset_account = LedgerCompanyAccount.get_by_identifier(identifier) end |
#no_payment_made? ⇒ Boolean
139 140 141 |
# File 'app/models/voucher_item.rb', line 139 def no_payment_made? outgoing_payment_items.applied.sum(:amount) == 0 end |
#outgoing_payment_items ⇒ ActiveRecord::Relation<OutgoingPaymentItem>
45 |
# File 'app/models/voucher_item.rb', line 45 has_many :outgoing_payment_items |
#payee ⇒ Party
42 |
# File 'app/models/voucher_item.rb', line 42 belongs_to :payee, class_name: 'Party', optional: true |
#payee_name ⇒ String?
Display name of the line-level payee (an alternate Party that
supersedes the voucher-level supplier when the supplier delegates
payment, e.g. installer commissions).
122 123 124 |
# File 'app/models/voucher_item.rb', line 122 def payee_name payee.try(:full_name) end |
#payee_type ⇒ String?
Returns Polymorphic class name of the payee Party.
127 128 129 |
# File 'app/models/voucher_item.rb', line 127 def payee_type payee.try(:class).try(:to_s) end |
#spiff_enrollment ⇒ SpiffEnrollment?
SPIFF enrollment inherited from the Order that produced the voucher.
AP uses this to attribute commission/incentive payouts back to the
originating sale.
111 112 113 114 115 |
# File 'app/models/voucher_item.rb', line 111 def spiff_enrollment return if voucher.order.blank? voucher.order.spiff_enrollment end |
#status_locked? ⇒ Boolean
Returns true once any payment has been applied; AP locks
editable status transitions in that case.
157 158 159 |
# File 'app/models/voucher_item.rb', line 157 def status_locked? partially_paid? or fully_paid? end |
#tax_rate ⇒ TaxRate
40 |
# File 'app/models/voucher_item.rb', line 40 belongs_to :tax_rate, optional: true |
#tax_rate_name ⇒ String?
Returns short tax-rate label (for AP grids).
151 152 153 |
# File 'app/models/voucher_item.rb', line 151 def tax_rate_name tax_rate.try(:short_name) end |
#voucher ⇒ Voucher
39 |
# File 'app/models/voucher_item.rb', line 39 belongs_to :voucher, inverse_of: :voucher_items, optional: true |