Class: VoucherItem
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 =
['S', 'U', 'V', 'N/A']
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
#due_date ⇒ Object
45
|
# File 'app/models/voucher_item.rb', line 45
validates :gross_amount, :due_date, :tax_type, presence: true
|
#gl_offset_account_ref ⇒ Object
Returns the value of attribute gl_offset_account_ref.
66
67
68
|
# File 'app/models/voucher_item.rb', line 66
def gl_offset_account_ref
@gl_offset_account_ref
end
|
#gross_amount ⇒ Object
45
|
# File 'app/models/voucher_item.rb', line 45
validates :gross_amount, :due_date, :tax_type, presence: true
|
#payee_type ⇒ Object
Returns the value of attribute payee_type.
66
67
68
|
# File 'app/models/voucher_item.rb', line 66
def payee_type
@payee_type
end
|
53
|
# File 'app/models/voucher_item.rb', line 53
validates :remark, length: { maximum: 255 }
|
#tax_amount ⇒ Object
47
|
# File 'app/models/voucher_item.rb', line 47
validates :taxable_amount, :tax_amount, :tax_rate_percentage, presence: { unless: :tax_not_applicable }
|
#tax_rate_id ⇒ Object
46
|
# File 'app/models/voucher_item.rb', line 46
validates :tax_rate_id, presence: { if: :requires_tax_rate }
|
#tax_rate_name ⇒ Object
Returns the value of attribute tax_rate_name.
66
67
68
|
# File 'app/models/voucher_item.rb', line 66
def tax_rate_name
@tax_rate_name
end
|
#tax_rate_percentage ⇒ Object
47
|
# File 'app/models/voucher_item.rb', line 47
validates :taxable_amount, :tax_amount, :tax_rate_percentage, presence: { unless: :tax_not_applicable }
|
#tax_type ⇒ Object
45
|
# File 'app/models/voucher_item.rb', line 45
validates :gross_amount, :due_date, :tax_type, presence: true
|
#taxable_amount ⇒ Object
47
|
# File 'app/models/voucher_item.rb', line 47
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
62
|
# File 'app/models/voucher_item.rb', line 62
scope :approved, -> { where(state: 'approved') }
|
.available_to_apply ⇒ ActiveRecord::Relation<VoucherItem>
A relation of VoucherItems that are available to apply. Active Record Scope
64
|
# File 'app/models/voucher_item.rb', line 64
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
63
|
# File 'app/models/voucher_item.rb', line 63
scope :for_company_id, ->(company_id) { joins(:voucher).where(vouchers: { company_id: }) }
|
Instance Method Details
#amount_paid_in_full? ⇒ Boolean
118
119
120
|
# File 'app/models/voucher_item.rb', line 118
def amount_paid_in_full?
outgoing_payment_items.applied.sum(:amount) == gross_amount
end
|
#amount_partially_paid? ⇒ Boolean
122
123
124
|
# File 'app/models/voucher_item.rb', line 122
def amount_partially_paid?
outgoing_payment_items.applied.sum(:amount) != 0
end
|
#available_statuses ⇒ Object
142
143
144
145
146
147
148
|
# File 'app/models/voucher_item.rb', line 142
def available_statuses
if status_locked?
%w[approved on_hold partially_paid fully_paid]
else
%w[approved on_hold]
end
end
|
#balance ⇒ Object
130
131
132
|
# File 'app/models/voucher_item.rb', line 130
def balance
gross_amount - outgoing_payment_items.applied.sum(:amount)
end
|
41
|
# File 'app/models/voucher_item.rb', line 41
belongs_to :business_unit, optional: true
|
39
|
# File 'app/models/voucher_item.rb', line 39
belongs_to :gl_offset_account, class_name: 'LedgerCompanyAccount', optional: true
|
#no_payment_made? ⇒ Boolean
126
127
128
|
# File 'app/models/voucher_item.rb', line 126
def no_payment_made?
outgoing_payment_items.applied.sum(:amount) == 0
end
|
#outgoing_payment_items ⇒ ActiveRecord::Relation<OutgoingPaymentItem>
43
|
# File 'app/models/voucher_item.rb', line 43
has_many :outgoing_payment_items
|
40
|
# File 'app/models/voucher_item.rb', line 40
belongs_to :payee, class_name: 'Party', optional: true
|
#payee_name ⇒ Object
110
111
112
|
# File 'app/models/voucher_item.rb', line 110
def payee_name
payee.try(:full_name)
end
|
#spiff_enrollment ⇒ Object
104
105
106
107
108
|
# File 'app/models/voucher_item.rb', line 104
def spiff_enrollment
return unless voucher.order.present?
voucher.order.spiff_enrollment
end
|
#status_locked? ⇒ Boolean
138
139
140
|
# File 'app/models/voucher_item.rb', line 138
def status_locked?
partially_paid? or fully_paid?
end
|
38
|
# File 'app/models/voucher_item.rb', line 38
belongs_to :tax_rate, optional: true
|
37
|
# File 'app/models/voucher_item.rb', line 37
belongs_to :voucher, inverse_of: :voucher_items, optional: true
|