Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant

This commit is contained in:
Yan
2017-06-22 18:05:38 +06:30
18 changed files with 177 additions and 91 deletions

View File

@@ -9,12 +9,30 @@ class Booking < ApplicationRecord
belongs_to :sale, :optional => true
has_many :booking_orders
has_many :orders, :through => :booking_orders
scope :active, -> {where("booking_status != 'moved'")}
def self.update_dining_facility(booking_arr, newd, old)
booking_arr.each do |booking|
booking.dining_facility_id = newd
booking.save
end
table = DiningFacility.find(newd)
exist = table.get_booking
if exist
# order exists
booking_arr.each do |booking|
booking.dining_facility_id = newd
booking.booking_status = 'moved'
booking.save
booking.booking_orders.each do |bo|
bo.booking_id = exist.booking_id
bo.save
end
end
else
# new table
booking_arr.each do |booking|
booking.dining_facility_id = newd
booking.save
end
end
new_dining = DiningFacility.find(newd)
new_dining.make_occupied
old_dining = DiningFacility.find(old)

View File

@@ -34,7 +34,7 @@ class Customer < ApplicationRecord
end
return response;
end
def self.get_membership_transactions(customer)
@@ -58,13 +58,13 @@ class Customer < ApplicationRecord
end
return response;
end
def self.search(search)
if search
# find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"])
where("name LIKE ? OR contact_no LIKE ? OR card_no LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%",)
where("name LIKE ? OR contact_no LIKE ? OR card_no LIKE ?", "%#{search}%", "%#{search}%", "%#{search}%",)
else
find(:all)
end
@@ -80,8 +80,8 @@ class Customer < ApplicationRecord
end
WALKIN = "CUS-000000000001"
TAKEAWAY = "CUS-000000000002"
WALKIN = "CUS-000000000001"
TAKEAWAY = "CUS-000000000002"
private
def generate_custom_id

View File

@@ -18,6 +18,19 @@ class DiningFacility < ApplicationRecord
self.save
end
def get_booking
booking = self.get_current_booking
puts "is bookig?"
puts booking
if booking
if booking.dining_facility_id.to_i == self.id
if booking.booking_status == 'assign'
return booking
end
end
end
end
def get_current_booking
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)

View File

@@ -251,9 +251,11 @@ class SalePayment < ApplicationRecord
table = DiningFacility.find(booking.dining_facility_id)
bookings = table.bookings
bookings.each do |tablebooking|
if tablebooking.booking_status != 'moved'
if tablebooking.sale.sale_status != 'completed'
status = false
end
end
end
if status
table.status = "available"