Merge branch 'master' into cloud

This commit is contained in:
Yan
2017-12-14 10:25:41 +06:30
4 changed files with 19 additions and 12 deletions

View File

@@ -16,6 +16,6 @@ class BaseOrigamiController < ActionController::Base
end
def checkin_process
CheckinJob.set(wait: 30.seconds).perform_later()
CheckinJob.set(wait: 1.minute).perform_later()
end
end

View File

@@ -72,7 +72,7 @@ class HomeController < ApplicationController
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
# .sum(:grand_total)
@employee_sales = Sale.employee_sales(today).sum('total_amount')
@employee_sales = Sale.employee_sales(today).sum('payment_amount')
@inventories = StockJournal.inventory_balances(today).sum(:balance)
@total_sale = Sale.total_sale(today)

View File

@@ -78,15 +78,18 @@ class DiningFacility < ApplicationRecord
def get_checkout_booking
booking = self.get_current_checkout_booking
if booking
now = Time.now.utc.getlocal
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?
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) && (checkout_at_min <= 15)
if (checkout_at_hr < hr)
return booking
elsif (checkout_at_hr == hr && checkout_at_min <= 15)
return booking
else
return nil
@@ -110,7 +113,9 @@ class DiningFacility < ApplicationRecord
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) && (checkout_at_min <= 15)
if (checkout_at_hr < hr)
arr_booking.push({'table_id' => booking.dining_facility_id})
elsif (checkout_at_hr == hr && checkout_at_min <= 15)
arr_booking.push({'table_id' => booking.dining_facility_id})
end
end

View File

@@ -984,11 +984,11 @@ end
end
def self.employee_sales(today)
query = Sale.select("e.name as employee_name,(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE sp.payment_amount END) as total_amount")
.where('sales.payment_status="paid" and sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',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")
.group("sp.payment_method","e.name")
.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')
end
@@ -1043,20 +1043,22 @@ end
end
def self.total_customer(today)
query = Sale.select("count(distinct sales.customer_id) as total_cus")
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()
end
def self.total_dinein(today)
query = Sale.select("count(distinct sales.customer_id) as total_dinein_cus")
query = Sale.select("count(sales.customer_id) as total_dinein_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 = "Dinein" and c.membership_id is null',today)
.first()
end
def self.total_takeaway(today)
query = Sale.select("count(distinct sales.customer_id) as total_take_cus")
query = Sale.select("count(sales.customer_id) as total_take_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 null',today)
.first()