merge with master

This commit is contained in:
Yan
2017-12-15 10:36:43 +06:30
30 changed files with 218 additions and 99 deletions

View File

@@ -78,8 +78,17 @@ class DiningFacility < ApplicationRecord
def get_checkout_booking
booking = self.get_current_checkout_booking
if booking
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
free_time_min = 0
if !lookup_checkout_time.nil?
if lookup_checkout_time[0][0] == 'min'
free_time_min = (lookup_checkout_time[0][1]).to_i
else
free_time_min = 15
end
end
now = Time.now.utc
puts now
hr = (now.strftime("%H").to_i).to_int
min = (now.strftime("%M").to_i).to_int
if !booking.checkout_at.nil?
@@ -89,7 +98,7 @@ class DiningFacility < ApplicationRecord
checkout_at_min -= min
if (checkout_at_hr < hr)
return booking
elsif (checkout_at_hr == hr && checkout_at_min <= 15)
elsif (checkout_at_hr == hr && checkout_at_min <= free_time_min)
return booking
else
return nil
@@ -104,18 +113,28 @@ class DiningFacility < ApplicationRecord
bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null")
arr_booking = Array.new
if bookings
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
free_time_min = 0
if !lookup_checkout_time.nil?
if lookup_checkout_time[0][0] == 'min'
free_time_min = (lookup_checkout_time[0][1]).to_i
else
free_time_min = 15
end
end
bookings.each do |booking|
now = Time.now.utc.getlocal
now = Time.now.utc
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.getlocal
checkout_at = booking.checkout_at.utc
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
if (checkout_at_hr < hr)
arr_booking.push({'table_id' => booking.dining_facility_id})
elsif (checkout_at_hr == hr && checkout_at_min <= 15)
elsif (checkout_at_hr == hr && checkout_at_min <= free_time_min)
arr_booking.push({'table_id' => booking.dining_facility_id})
end
end
@@ -123,4 +142,11 @@ class DiningFacility < ApplicationRecord
end
return arr_booking
end
#send order items and send to order queue
def self.check_in_booking(table_id)
table = DiningFacility.find(table_id)
#Send to background job for processing
CheckInBookingJob.perform_later(table)
end
end

View File

@@ -984,12 +984,11 @@ end
end
def self.employee_sales(today)
query = Sale.select('(CASE WHEN (sp.payment_method="mpu" or sp.payment_method="visa" or sp.payment_method="master" or sp.payment_method="jcb") THEN "card" ELSE sp.payment_method END) as payment_name, (CASE WHEN sp.payment_method="cash" THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount')
.joins("join employees e on e.id=sales.cashier_id")
.joins("join sale_payments sp on sp.sale_id=sales.sale_id")
.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'")
.group('payment_method','e.name')
.order('e.name')
query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'")
.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb') THEN 'card' ELSE sp.payment_method END)","e.name")
.order("e.name")
end
def self.total_sale(today)
@@ -1043,11 +1042,16 @@ end
end
def self.total_customer(today)
query = Sale.select("(CASE WHEN (c.customer_type='Dinein' or c.customer_type='Takeaway') THEN count(sales.customer_id) ELSE count(distinct sales.customer_id) END) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
.order('sales.sale_id ASC')
.first()
dinein_cnt = self.total_dinein(today)
takeaway_cnt = self.total_takeaway(today)
membership_cnt = self.total_membership(today)
total_cus = 0
if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil?
total_cus = dinein_cnt.total_dinein_cus.to_int + takeaway_cnt.total_take_cus.to_int + membership_cnt.total_memb_cus.to_int
end
return total_cus
end
def self.total_dinein(today)
@@ -1067,12 +1071,12 @@ end
def self.total_membership(today)
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is not null',today)
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
.first()
end
def self.total_other_customer(today)
query = Sale.select("count(distinct sales.customer_id) as total_cus")
query = Sale.select("count(sales.customer_id) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
.first()
@@ -1111,8 +1115,8 @@ end
def self.total_foc_items(today)
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.remark='foc' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.count()
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.sum("a.qty")
end
private

View File

@@ -27,10 +27,14 @@ class SaleItem < ApplicationRecord
end
def self.update_existing_item(qty, item, sale_id, type, item_price, price)
# Original Item to add remark
item.remark = type
item.save
sale_item = SaleItem.new
sale_item.product_code = item.product_code
sale_item.item_instance_code = item.item_instance_code
sale_item.product_name = item.product_name + "(#{type})"
sale_item.product_name = item.product_name + " (#{type.upcase})"
sale_item.product_alt_name = item.product_alt_name
sale_item.account_id = item.account_id
sale_item.remark = type