fix timezone - time with local timezone to default timezone

This commit is contained in:
pyaephyoeaung
2022-05-19 14:20:55 +06:30
parent 7598a96e60
commit 214712fd2d
48 changed files with 294 additions and 305 deletions

View File

@@ -56,7 +56,7 @@ class AssignedOrderItem < ApplicationRecord
left join booking_orders as bo on bo.order_id = assigned_order_items.order_id
left join bookings as bk on bk.booking_id = bo.booking_id
left join dining_facilities as df on df.id = bk.dining_facility_id")
.where("assigned_order_items.order_id = '#{order_id}' AND assigned_order_items.delivery_status = false AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}' ")
.where("assigned_order_items.order_id = '#{order_id}' AND assigned_order_items.delivery_status = false AND assigned_order_items.created_at >= '#{Time.current.beginning_of_day.utc}' ")
.order("assigned_order_items.assigned_order_item_id desc")
.group("assigned_order_items.assigned_order_item_id")
return order_item

View File

@@ -60,7 +60,7 @@ class Booking < ApplicationRecord
end
scope :active, -> { where('booking_status != ?', 'moved') }
scope :today, -> { where('created_at >= ?', Time.now) }
scope :today, -> { where('created_at >= ?', Time.current) }
scope :assign, -> { where(booking_status: 'assign') }
def self.sync_booking_records(bookings)
@@ -128,9 +128,9 @@ class Booking < ApplicationRecord
end
if from.present? && to.present?
booking = Booking.joins(" LEFT JOIN dining_facilities df ON df.id=bookings.dining_facility_id")
.where("DATE_FORMAT(bookings.created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(bookings.created_at,'%d-%m-%Y') <= ? and NOT bookings.booking_status = 'void' ", from,to)
query = booking.where(keyword)
booking = Booking.joins(" LEFT JOIN dining_facilities df ON df.id=bookings.dining_facility_id")
.where("bookings.created_at BETWEEN ? AND ? and NOT bookings.booking_status = 'void' ", from,to)
query = booking.where(keyword)
else
joins(" LEFT JOIN dining_facilities df ON df.id=bookings.dining_facility_id")
.where("booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}' OR df.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")

View File

@@ -54,22 +54,22 @@ class DiningFacility < ApplicationRecord
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
free_time_min = 0
if !lookup_checkout_time.empty?
now = Time.now.utc
now = Time.current
lookup_checkout_time.each do |checkout_time|
arr_time = checkout_time[0].split("-")
start_time = Time.parse(arr_time[0].strip).utc.strftime("%H:%M%p")
end_time = Time.parse(arr_time[1].strip).utc.strftime("%H:%M%p")
start_time = Time.zone.parse(arr_time[0].strip).strftime("%H:%M%p")
end_time = Time.zone.parse(arr_time[1].strip).strftime("%H:%M%p")
if start_time <= now && now <= end_time
free_time_min = checkout_time[1].to_i
end
end
end
now = Time.now.utc
now = Time.current
hr = (now.strftime("%H").to_i).to_int
min = (now.strftime("%M").to_i).to_int
if !booking.checkout_at.nil?
checkout_at = booking.checkout_at.utc
checkout_at = booking.checkout_at
checkout_at_hr = (checkout_at.strftime("%H").to_i).to_int
checkout_at_min = (checkout_at.strftime("%M").to_i).to_int
checkout_at_min -= min
@@ -93,11 +93,11 @@ class DiningFacility < ApplicationRecord
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
free_time_min = 0
if !lookup_checkout_time.empty?
now = Time.now.utc
now = Time.current
lookup_checkout_time.each do |checkout_time|
arr_time = checkout_time[0].split("-")
start_time = Time.parse(arr_time[0].strip).utc.strftime("%H:%M%p")
end_time = Time.parse(arr_time[1].strip).utc.strftime("%H:%M%p")
start_time = Time.zone.parse(arr_time[0].strip).utc.strftime("%H:%M%p")
end_time = Time.zone.parse(arr_time[1].strip).utc.strftime("%H:%M%p")
if start_time <= now && now <= end_time
free_time_min = checkout_time[1].to_i
end
@@ -105,11 +105,11 @@ class DiningFacility < ApplicationRecord
end
bookings.each do |booking|
now = Time.now.utc
now = Time.current
hr = (now.strftime("%H").to_i).to_int
min = (now.strftime("%M").to_i).to_int
if !booking.checkout_at.nil?
checkout_at = booking.checkout_at.utc
checkout_at = booking.checkout_at
checkout_at_hr = (checkout_at.strftime("%H").to_i).to_int
checkout_at_min = (checkout_at.strftime("%M").to_i).to_int
checkout_at_min -= min
@@ -155,8 +155,8 @@ class DiningFacility < ApplicationRecord
def check_time(time, booking = nil, type)
status = true
today = Time.now.utc.strftime("%Y-%m-%d %H:%M")
check_time = time.strftime("%Y-%m-%d %H:%M")
today = Time.current.utc.strftime("%Y-%m-%d %H:%M")
check_time = time.utc.strftime("%Y-%m-%d %H:%M")
if type.downcase == "checkin"
if check_time < today
status = false

View File

@@ -182,33 +182,33 @@ class License
def expired?
if renewal_date_str = read_license("renewable_date")
renewal_date = DateTime.parse(renewal_date_str)
renewal_date < Date.today
renewal_date = Time.zone.parse(renewal_date_str)
renewal_date < Date.current
end
end
def expire_in?(days)
if renewal_date_str = read_license("renewable_date")
renewal_date = DateTime.parse(renewal_date_str)
renewal_date = Time.zone.parse(renewal_date_str)
renewal_date < days.days.from_now
end
end
def days_to_expire
if renewal_date_str = read_license("renewable_date")
Date.today - DateTime.parse(renewal_date_str).to_date
Date.current - Time.zone.parse(renewal_date_str).to_date
end
end
# Check License expired date from PROVISION SERVER
def check_expired(renewal_date_str)
expired_date_str = read_license("renewable_date")
renewal_date = DateTime.parse(renewal_date_str)
renewal_date = Time.zone.parse(renewal_date_str)
if(renewal_date_str != expired_date_str)
update_license("renewable_date", renewal_date_str)
end
if (renewal_date < Date.today)
if (renewal_date < Date.current)
return true
else
return false

View File

@@ -40,9 +40,9 @@ class MenuCategory < ApplicationRecord
def valid_time
menu = self.menu
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.strftime("%H:%M:%S"))
from_t = Time.zone.parse(menu.valid_time_from.strftime("%H:%M:%S"))
to_t = Time.zone.parse(menu.valid_time_to.strftime("%H:%M:%S"))
current_t = Time.zone.parse(Time.current.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
@@ -73,7 +73,7 @@ class MenuCategory < ApplicationRecord
end
end
day = Date.today.wday
day = Date.current.wday
dayresult = menu.valid_days.include?(day.to_s)

View File

@@ -29,12 +29,12 @@ class Order < ApplicationRecord
#add extra time
if self.is_extra_time && self.extra_time
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
:checkin_at => Time.now.utc, :checkout_at => Time.now.utc + self.extra_time.to_i,
:checkin_at => Time.current, :checkout_at => Time.current + self.extra_time.to_i,
:checkin_by => self.employee_name,
:booking_status => "assign" })
else
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
:checkin_at => Time.now.utc, :checkin_by => self.employee_name,
:checkin_at => Time.current, :checkin_by => self.employee_name,
:booking_status => "assign" })
end
#end extra time
@@ -84,7 +84,7 @@ class Order < ApplicationRecord
if self.new_booking
booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking",
:checkin_at => Time.now.utc, :checkin_by => self.employee_name,
:checkin_at => Time.current, :checkin_by => self.employee_name,
:booking_status => "assign" })
table = DiningFacility.find(self.table_id)
table.status = "occupied"
@@ -316,8 +316,8 @@ class Order < ApplicationRecord
#Origami: Cashier : to view orders
def self.get_orders
from = Time.now.beginning_of_day.utc
to = Time.now.end_of_day.utc
from = Time.current.beginning_of_day.utc
to = Time.current.end_of_day.utc
orders=Booking.select("sales.receipt_no, sales.sale_status as sale_status, orders.status as order_status,
orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id,
bookings.booking_id,orders.customer_id as customer_id,
@@ -353,7 +353,7 @@ class Order < ApplicationRecord
end
if from.present? && to.present?
order = Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ?", from,to)
order = Order.where("date BETWEEN ? AND ?", from, to)
query = order.where(keyword)
else
where("order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%")
@@ -449,7 +449,7 @@ class Order < ApplicationRecord
end
def set_order_date
self.date = Time.now.utc
self.date = Time.current
end
def self.sync_order_records(orders)

View File

@@ -32,7 +32,7 @@ class OrderReservation < ApplicationRecord
customer.contact_no = params[:contact_no] ? params[:contact_no] : ''
customer.gender = gender
customer.address = params[:address] ? params[:address] : ''
customer.date_of_birth = params[:date_of_birth] ? Time.parse(params[:date_of_birth]).strftime("%Y-%m-%d") : ''
customer.date_of_birth = params[:date_of_birth] ? Time.zone.parse(params[:date_of_birth]).strftime("%Y-%m-%d") : ''
customer.membership_id = params[:membership_id]
customer.customer_type = "Doemal"
customer.tax_profiles = ["2"]
@@ -426,7 +426,7 @@ class OrderReservation < ApplicationRecord
else
shop_code = ''
end
order_reservation = OrderReservation.where("status='accepted' and requested_time <= '#{Time.now.utc}'")
order_reservation = OrderReservation.where("status='accepted' and requested_time <= '#{Time.current.utc}'")
if order_reservation.length > 0
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
@@ -444,7 +444,7 @@ class OrderReservation < ApplicationRecord
else
shop_code = ''
end
order_reservation = OrderReservation.where("status='send_to_kitchen' and requested_time <= '#{Time.now.utc}'")
order_reservation = OrderReservation.where("status='send_to_kitchen' and requested_time <= '#{Time.current.utc}'")
if order_reservation.length > 0
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain

View File

@@ -12,13 +12,13 @@ class Promotion < ApplicationRecord
PROMO_TYPE4 = "Percentage"
def is_promo_day
promo_day.include? Date.today.wday.to_s
promo_day.include? Date.current.wday.to_s
end
def self.promo_activate(saleObj)
current_day = Time.now.strftime("%Y-%m-%d")
current_time = Time.now.strftime('%H:%M:%S')
day = Date.today.wday
current_day = Time.current.strftime("%Y-%m-%d")
current_time = Time.current.strftime('%H:%M:%S')
day = Date.current.wday
promoList = is_between_promo_datetime(current_day,current_time)
promoList.each do |promo|

View File

@@ -36,7 +36,7 @@ class Sale < ApplicationRecord
scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) }
scope :sale_payments_with_audit_except_void_between, -> (from, to) do
joins(sanitize_sql_array(["LEFT JOIN sale_payments ON sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to]))
joins(sanitize_sql_array(["LEFT JOIN sale_payments ON sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from.utc, to.utc]))
.joins("LEFT JOIN sale_audits ON sale_audits.sale_id = sale_payments.sale_id AND SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id")
end
@@ -91,7 +91,7 @@ class Sale < ApplicationRecord
def self.generate_invoice_from_booking(booking, requested_by, cashier, order_source = nil, in_duties_count = 0)
Sale.transaction do
if booking
current = Time.now
current = Time.current
#get all order attached to this booking and combine into 1 invoice
sale = booking.sale || booking.build_sale(
{
@@ -735,9 +735,9 @@ class Sale < ApplicationRecord
if from.present? && to.present?
if shift.blank?
sale = Sale.where("DATE_FORMAT(receipt_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(receipt_date,'%Y-%m-%d') <= ? and NOT sale_status = 'new' ", from,to)
sale = Sale.where("receipt_date BETWEEN ? AND ? and NOT sale_status = 'new'", from,to)
else
sale = Sale.where("(DATE_FORMAT(receipt_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(receipt_date,'%Y-%m-%d') <= ? and NOT sale_status = 'new') and shift_sale_id = '#{shift.id}'", from,to)
sale = Sale.where("receipt_date BETWEEN ? AND ? and NOT sale_status = 'new' and shift_sale_id = '#{shift.id}'", from,to)
end
query = sale.where(keyword)
else
@@ -1588,7 +1588,7 @@ end
if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1615,7 +1615,7 @@ end
if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1652,7 +1652,7 @@ end
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1673,7 +1673,7 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1698,7 +1698,7 @@ end
if (!from.nil? && !to.nil?)
query = query.merge(Sale.receipt_date_between(from, to))
else
query = query.merge(Sale.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day))
query = query.merge(Sale.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day))
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1719,7 +1719,7 @@ end
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1741,7 +1741,7 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1772,7 +1772,7 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1826,7 +1826,7 @@ end
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1848,7 +1848,7 @@ end
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1916,7 +1916,7 @@ end
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1938,7 +1938,7 @@ end
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1960,7 +1960,7 @@ end
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -1983,7 +1983,7 @@ end
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
@@ -2060,7 +2060,7 @@ end
query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id")
.joins("join orders as orders on orders.order_id = sale_orders.order_id")
query = query.where("sales.sale_status != 'new' AND orders.status = 'billed' #{type}")
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
.group("sales.sale_id")
end
@@ -2138,7 +2138,7 @@ def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
if !from.nil? && !to.nil?
query = query.receipt_date_between(from, to)
else
query = query.receipt_date_between(Time.now.beginning_of_day, Time.now.end_of_day)
query = query.receipt_date_between(Time.current.beginning_of_day, Time.current.end_of_day)
end
if !shift.nil?
@@ -2162,8 +2162,8 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
receipt_date = "sales.receipt_date between '#{from}' and '#{to}'"
query = self.get_hourly_item_query(type,filter,true)
else
start_time = Time.parse(start_time).utc
end_time = Time.parse(end_time).utc
start_time = Time.zone.parse(start_time).utc
end_time = Time.zone.parse(end_time).utc
receipt_date = "sales.receipt_date between '#{start_time}' and '#{end_time}'"
query = self.get_hourly_item_query(type,filter,false)
end

View File

@@ -223,7 +223,7 @@ class ShiftSale < ApplicationRecord
end
if from.present? && to.present?
booking = ShiftSale.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ? and NOT booking_status = 'void' ", from,to)
booking = ShiftSale.where("created_at BETWEEN ? AND ? and NOT booking_status = 'void' ", from, to)
query = booking.where(keyword)
else
where("booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")

View File

@@ -4,8 +4,8 @@ class StockCheck < ApplicationRecord
def create(user, reason, item_list)
self.reason = reason
self.check_by = user.id
self.check_start = Time.now
self.check_end = Time.now
self.check_start = Time.current
self.check_end = Time.current
save
item_list.each do |item|
stockItem = StockCheckItem.new

View File

@@ -8,7 +8,7 @@ class Survey < ApplicationRecord
end
if from.present? && to.present?
survey = Survey.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ?", from,to)
survey = Survey.where("created_at BETWEEN ? AND ?", from, to)
query = survey.where(keyword)
else
where("dining_name LIKE ?", "%#{filter}%")