update menu valid date and limit time ,addorder for parent order item id
This commit is contained in:
@@ -2,7 +2,7 @@ class Menu < ApplicationRecord
|
||||
has_many :menu_categories, dependent: :destroy
|
||||
|
||||
validates_presence_of :name, :valid_days, :valid_time_from, :valid_time_to
|
||||
validates_format_of :valid_days, :with => /\A([0-7]{1}(,[0-7]{1})*)?\Z/i
|
||||
# validates_format_of :valid_days, :with => /\A([0-7]{1}(,[0-7]{1})*)?\Z/i
|
||||
#Default Scope to pull the active version only
|
||||
default_scope { where(is_active: true).order("created_at desc") }
|
||||
|
||||
|
||||
@@ -41,19 +41,41 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
menu_category = MenuCategory.find(self.id)
|
||||
menu = Menu.find(menu_category.menu_id)
|
||||
from = menu.valid_time_from.strftime("%H:%M:%S")
|
||||
to = menu.valid_time_to.strftime("%H:%M:%S")
|
||||
current = Time.now.utc.getlocal.strftime("%H:%M:%S")
|
||||
|
||||
from = from.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
|
||||
to = to.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
|
||||
current = current.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
|
||||
from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S"))
|
||||
to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S"))
|
||||
current_t = Time.parse(Time.now.utc.getlocal.strftime("%H:%M:%S"))
|
||||
|
||||
from = from_t.hour * 3600 + from_t.min*60 + from_t.sec
|
||||
to = to_t.hour * 3600 + to_t.min* 60 + to_t.sec
|
||||
current = current_t.hour * 3600 + current_t.min*60+current_t.sec
|
||||
if from > to
|
||||
h = to_t.hour
|
||||
if h < 12 # before noon
|
||||
if h = 0
|
||||
to = 24
|
||||
to = to * 3600 + to_t.min* 60 + to_t.sec
|
||||
end
|
||||
else # (after) noon
|
||||
if h > 12
|
||||
to -= 12
|
||||
to = to * 3600 + to_t.min* 60 + to_t.sec
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if current.between?(from, to)
|
||||
# from = from.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
|
||||
# to = to.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
|
||||
# current = current.split(':').map { |a| a.to_i }.inject(0) { |a, b| a * 60 + b}
|
||||
|
||||
day = Date.today.wday
|
||||
dayresult = menu.valid_days.include?(day.to_s)
|
||||
|
||||
if current.between?(from, to) && menu.valid_days.include?(day.to_s)
|
||||
return true
|
||||
else
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user