Class: CommissionRate

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/commission_rate.rb

Overview

== Schema Information

Table name: commission_rates
Database name: primary

id :integer not null, primary key
commission_rate :float not null
commission_tier_description :string
end_date :date
is_active :boolean not null
items_apply_commission :integer is an Array
max_profit :float
min_order_amount :integer default(0), not null
min_profit :float
start_date :date
created_at :datetime not null
updated_at :datetime not null
commission_tier_id :integer not null
creator_id :integer
employee_id :integer not null
updater_id :integer

Indexes

index_commission_rates_on_commission_tier_id (commission_tier_id)
index_commission_rates_on_employee_id (employee_id)
index_commission_rates_on_end_date (end_date)
index_commission_rates_on_is_active (is_active)
index_commission_rates_on_items_apply_commission (items_apply_commission)
index_commission_rates_on_min_order_amount (min_order_amount)
index_commission_rates_on_start_date (start_date)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Class 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 Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.activeActiveRecord::Relation<CommissionRate>

A relation of CommissionRates that are active. Active Record Scope

Returns:

See Also:



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

scope :active, -> { where(is_active: true) }

.sortedActiveRecord::Relation<CommissionRate>

A relation of CommissionRates that are sorted. Active Record Scope

Returns:

See Also:



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

scope :sorted, -> { order(is_active: :desc, employee_id: :asc, commission_tier_id: :asc) }

.with_description_tier_employee_sku_nameActiveRecord::Relation<CommissionRate>

A relation of CommissionRates that are with description tier employee sku name. Active Record Scope

Returns:

See Also:



39
40
41
42
43
# File 'app/models/commission_rate.rb', line 39

scope :with_description_tier_employee_sku_name, -> {
  select("commission_rates.*,
                                                            (select full_name from parties where id = employee_id) as employee_name,
                                                            (select array_agg(sku) as skus from items where id = any(items_apply_commission))")
}

Instance Method Details

#commission_tierCommissionTier



48
# File 'app/models/commission_rate.rb', line 48

belongs_to :commission_tier

#employeeEmployee

Returns:

See Also:



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

belongs_to :employee