mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 16:53:37 +02:00
parent
8916eee169
commit
f76e1259fc
11 changed files with 106 additions and 65 deletions
|
@ -6,18 +6,19 @@ module Admin
|
|||
helper_method :zones
|
||||
helper_method :operation_categories
|
||||
helper_method :durations
|
||||
helper_method :statuses
|
||||
|
||||
def index
|
||||
@search = OpenStruct.new(search_params)
|
||||
|
||||
unless @search.validity
|
||||
@search.validity = 'unexpired'
|
||||
unless @search.status
|
||||
@search.status = default_status
|
||||
end
|
||||
|
||||
prices = ::Billing::Price.all
|
||||
|
||||
if @search.validity.present?
|
||||
prices = ::Billing::Price.send(@search.validity)
|
||||
if @search.status.present?
|
||||
prices = ::Billing::Price.send(@search.status)
|
||||
end
|
||||
|
||||
@q = prices.search(params[:q])
|
||||
|
@ -81,7 +82,7 @@ module Admin
|
|||
|
||||
def search_params
|
||||
allowed_params = %i[
|
||||
validity
|
||||
status
|
||||
]
|
||||
params.fetch(:search, {}).permit(*allowed_params)
|
||||
end
|
||||
|
@ -102,6 +103,14 @@ module Admin
|
|||
durations = ::Billing::Price::durations
|
||||
durations.collect { |duration| [duration.sub('mon', 'month'), duration] }
|
||||
end
|
||||
|
||||
def statuses
|
||||
::Billing::Price.statuses
|
||||
end
|
||||
|
||||
def default_status
|
||||
'effective'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,6 +12,7 @@ module Billing
|
|||
validates :operation_category, inclusion: { in: Proc.new { |price| price.class.operation_categories } }
|
||||
validates :duration, inclusion: { in: Proc.new { |price| price.class.durations } }
|
||||
|
||||
alias_attribute :effect_time, :valid_from
|
||||
alias_attribute :expire_time, :valid_to
|
||||
monetize :price_cents, allow_nil: true, numericality: { greater_than_or_equal_to: 0 }
|
||||
after_initialize :init_values
|
||||
|
@ -22,22 +23,37 @@ module Billing
|
|||
|
||||
def self.durations
|
||||
[
|
||||
'3 mons',
|
||||
'6 mons',
|
||||
'9 mons',
|
||||
'1 year',
|
||||
'2 years',
|
||||
'3 years',
|
||||
'4 years',
|
||||
'5 years',
|
||||
'6 years',
|
||||
'7 years',
|
||||
'8 years',
|
||||
'9 years',
|
||||
'10 years',
|
||||
'3 mons',
|
||||
'6 mons',
|
||||
'9 mons',
|
||||
'1 year',
|
||||
'2 years',
|
||||
'3 years',
|
||||
'4 years',
|
||||
'5 years',
|
||||
'6 years',
|
||||
'7 years',
|
||||
'8 years',
|
||||
'9 years',
|
||||
'10 years',
|
||||
]
|
||||
end
|
||||
|
||||
def self.statuses
|
||||
%w[pending effective expired]
|
||||
end
|
||||
|
||||
def self.pending
|
||||
where("#{attribute_alias(:effect_time)} > ?", Time.zone.now)
|
||||
end
|
||||
|
||||
def self.effective
|
||||
condition = "#{attribute_alias(:effect_time)} <= :now " \
|
||||
" AND (#{attribute_alias(:expire_time)} >= :now" \
|
||||
" OR #{attribute_alias(:expire_time)} IS NULL)"
|
||||
where(condition, now: Time.zone.now)
|
||||
end
|
||||
|
||||
def self.valid
|
||||
where('valid_from <= ? AND (valid_to >= ? OR valid_to IS NULL)', Time.zone.now.end_of_day,
|
||||
Time.zone.now.beginning_of_day)
|
||||
|
|
|
@ -2,10 +2,6 @@ module Concerns::Billing::Price::Expirable
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def unexpired
|
||||
where("#{attribute_alias(:expire_time)} >= ?", Time.zone.now)
|
||||
end
|
||||
|
||||
def expired
|
||||
where("#{attribute_alias(:expire_time)} < ?", Time.zone.now)
|
||||
end
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
<%= form_for :search, url: admin_prices_path, method: :get, html: { class: 'form-horizontal' } do |f| %>
|
||||
<div class="form-group">
|
||||
<%= f.label :validity, class: 'col-sm-2 control-label' %>
|
||||
<%= f.label :status, class: 'col-sm-2 control-label' %>
|
||||
|
||||
<div class="col-sm-3">
|
||||
<%= f.select :validity, options_for_select(%w[unexpired expired], search.validity),
|
||||
{ include_blank: true },
|
||||
<%= f.select :status, options_for_select(statuses, search.status), { include_blank: true },
|
||||
class: 'form-control' %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue