Class: VoucherItem

Inherits:
ApplicationRecord show all
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 =
['S', 'U', 'V', 'N/A']

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#publish_event

Instance Attribute Details

#due_dateObject (readonly)



45
# File 'app/models/voucher_item.rb', line 45

validates :gross_amount, :due_date, :tax_type, presence: true

#gl_offset_account_refObject

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
end

#gross_amountObject (readonly)



45
# File 'app/models/voucher_item.rb', line 45

validates :gross_amount, :due_date, :tax_type, presence: true

#payee_typeObject

Returns the value of attribute payee_type.



66
67
68
# File 'app/models/voucher_item.rb', line 66

def payee_type
  @payee_type
end

#remarkObject (readonly)



53
# File 'app/models/voucher_item.rb', line 53

validates :remark, length: { maximum: 255 }

#tax_amountObject (readonly)



47
# File 'app/models/voucher_item.rb', line 47

validates :taxable_amount, :tax_amount, :tax_rate_percentage, presence: { unless: :tax_not_applicable }

#tax_rate_idObject (readonly)



46
# File 'app/models/voucher_item.rb', line 46

validates :tax_rate_id, presence: { if: :requires_tax_rate }

#tax_rate_nameObject

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_percentageObject (readonly)



47
# File 'app/models/voucher_item.rb', line 47

validates :taxable_amount, :tax_amount, :tax_rate_percentage, presence: { unless: :tax_not_applicable }

#tax_typeObject (readonly)



45
# File 'app/models/voucher_item.rb', line 45

validates :gross_amount, :due_date, :tax_type, presence: true

#taxable_amountObject (readonly)



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

.approvedActiveRecord::Relation<VoucherItem>

A relation of VoucherItems that are approved. Active Record Scope

Returns:

See Also:



62
# File 'app/models/voucher_item.rb', line 62

scope :approved, -> { where(state: 'approved') }

.available_to_applyActiveRecord::Relation<VoucherItem>

A relation of VoucherItems that are available to apply. Active Record Scope

Returns:

See Also:



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_idActiveRecord::Relation<VoucherItem>

A relation of VoucherItems that are for company id. Active Record Scope

Returns:

See Also:



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

Returns:

  • (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

Returns:

  • (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_statusesObject



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

#balanceObject



130
131
132
# File 'app/models/voucher_item.rb', line 130

def balance
  gross_amount - outgoing_payment_items.applied.sum(:amount)
end

#business_unitBusinessUnit



41
# File 'app/models/voucher_item.rb', line 41

belongs_to :business_unit, optional: true

#gl_offset_accountLedgerCompanyAccount



39
# File 'app/models/voucher_item.rb', line 39

belongs_to :gl_offset_account, class_name: 'LedgerCompanyAccount', optional: true

#no_payment_made?Boolean

Returns:

  • (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_itemsActiveRecord::Relation<OutgoingPaymentItem>

Returns:

See Also:



43
# File 'app/models/voucher_item.rb', line 43

has_many :outgoing_payment_items

#payeeParty

Returns:

See Also:



40
# File 'app/models/voucher_item.rb', line 40

belongs_to :payee, class_name: 'Party', optional: true

#payee_nameObject



110
111
112
# File 'app/models/voucher_item.rb', line 110

def payee_name
  payee.try(:full_name)
end

#spiff_enrollmentObject



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

Returns:

  • (Boolean)


138
139
140
# File 'app/models/voucher_item.rb', line 138

def status_locked?
  partially_paid? or fully_paid?
end

#tax_rateTaxRate

Returns:

See Also:



38
# File 'app/models/voucher_item.rb', line 38

belongs_to :tax_rate, optional: true

#voucherVoucher

Returns:

See Also:



37
# File 'app/models/voucher_item.rb', line 37

belongs_to :voucher, inverse_of: :voucher_items, optional: true