|
|
|
@ -35,6 +35,7 @@ class Scheme < ApplicationRecord |
|
|
|
if scopes.any? |
|
|
|
if scopes.any? |
|
|
|
filtered_records = filtered_records |
|
|
|
filtered_records = filtered_records |
|
|
|
.left_outer_joins(:scheme_deactivation_periods) |
|
|
|
.left_outer_joins(:scheme_deactivation_periods) |
|
|
|
|
|
|
|
.joins(:owning_organisation) |
|
|
|
.merge(scopes.reduce(&:or)) |
|
|
|
.merge(scopes.reduce(&:or)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -45,36 +46,48 @@ class Scheme < ApplicationRecord |
|
|
|
where.not(confirmed: true) |
|
|
|
where.not(confirmed: true) |
|
|
|
.or(where(confirmed: nil)) |
|
|
|
.or(where(confirmed: nil)) |
|
|
|
.or(where.not(id: Location.select(:scheme_id).where(confirmed: true).distinct)) |
|
|
|
.or(where.not(id: Location.select(:scheme_id).where(confirmed: true).distinct)) |
|
|
|
|
|
|
|
.where.not(id: joins(:owning_organisation).deactivated_by_organisation.pluck(:id)) |
|
|
|
|
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).deactivated_directly.pluck(:id)) |
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).reactivating_soon.pluck(:id)) |
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).reactivating_soon.pluck(:id)) |
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).deactivated.pluck(:id)) |
|
|
|
|
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).deactivating_soon.pluck(:id)) |
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).deactivating_soon.pluck(:id)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
scope :deactivated, lambda { |
|
|
|
scope :deactivated, lambda { |
|
|
|
|
|
|
|
deactivated_by_organisation |
|
|
|
|
|
|
|
.or(deactivated_directly) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scope :deactivated_by_organisation, lambda { |
|
|
|
|
|
|
|
merge(Organisation.filter_by_inactive) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scope :deactivated_directly, lambda { |
|
|
|
merge(SchemeDeactivationPeriod.deactivations_without_reactivation) |
|
|
|
merge(SchemeDeactivationPeriod.deactivations_without_reactivation) |
|
|
|
.where("scheme_deactivation_periods.deactivation_date <= ?", Time.zone.now) |
|
|
|
.where("scheme_deactivation_periods.deactivation_date <= ?", Time.zone.now) |
|
|
|
.or("scheme.organisation.active", false) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
scope :deactivating_soon, lambda { |
|
|
|
scope :deactivating_soon, lambda { |
|
|
|
merge(SchemeDeactivationPeriod.deactivations_without_reactivation) |
|
|
|
merge(SchemeDeactivationPeriod.deactivations_without_reactivation) |
|
|
|
.where("scheme_deactivation_periods.deactivation_date > ? AND scheme_deactivation_periods.deactivation_date < ? ", Time.zone.now, 6.months.from_now) |
|
|
|
.where("scheme_deactivation_periods.deactivation_date > ? AND scheme_deactivation_periods.deactivation_date < ? ", Time.zone.now, 6.months.from_now) |
|
|
|
|
|
|
|
.where.not(id: joins(:owning_organisation).deactivated_by_organisation.pluck(:id)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
scope :reactivating_soon, lambda { |
|
|
|
scope :reactivating_soon, lambda { |
|
|
|
where.not("scheme_deactivation_periods.reactivation_date IS NULL") |
|
|
|
where.not("scheme_deactivation_periods.reactivation_date IS NULL") |
|
|
|
.where("scheme_deactivation_periods.reactivation_date > ?", Time.zone.now) |
|
|
|
.where("scheme_deactivation_periods.reactivation_date > ?", Time.zone.now) |
|
|
|
|
|
|
|
.where.not(id: joins(:owning_organisation).deactivated_by_organisation.pluck(:id)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
scope :activating_soon, lambda { |
|
|
|
scope :activating_soon, lambda { |
|
|
|
where("startdate > ?", Time.zone.now) |
|
|
|
where("schemes.startdate > ?", Time.zone.now) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
scope :active_status, lambda { |
|
|
|
scope :active_status, lambda { |
|
|
|
where.not(id: joins(:scheme_deactivation_periods).reactivating_soon.pluck(:id)) |
|
|
|
where.not(id: joins(:scheme_deactivation_periods).reactivating_soon.pluck(:id)) |
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).deactivated.pluck(:id)) |
|
|
|
|
|
|
|
.where.not(id: incomplete.pluck(:id)) |
|
|
|
.where.not(id: incomplete.pluck(:id)) |
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).deactivating_soon.pluck(:id)) |
|
|
|
.where.not(id: joins(:scheme_deactivation_periods).deactivating_soon.pluck(:id)) |
|
|
|
|
|
|
|
.where.not(id: joins(:owning_organisation).deactivated_by_organisation.pluck(:id)) |
|
|
|
|
|
|
|
.where.not(id: joins(:owning_organisation).joins(:scheme_deactivation_periods).deactivated_directly.pluck(:id)) |
|
|
|
.where.not(id: activating_soon.pluck(:id)) |
|
|
|
.where.not(id: activating_soon.pluck(:id)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|