change query for dashboard
This commit is contained in:
@@ -72,7 +72,8 @@ class HomeController < ApplicationController
|
|||||||
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
|
@hourly_sales = Sale.hourly_sales(today).sum(:grand_total)
|
||||||
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
# .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p')
|
||||||
# .sum(:grand_total)
|
# .sum(:grand_total)
|
||||||
@employee_sales = Sale.employee_sales(today).sum('payment_amount')
|
@employee_sales = Sale.employee_sales(today)
|
||||||
|
.sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)')
|
||||||
@inventories = StockJournal.inventory_balances(today).sum(:balance)
|
@inventories = StockJournal.inventory_balances(today).sum(:balance)
|
||||||
|
|
||||||
@total_sale = Sale.total_sale(today)
|
@total_sale = Sale.total_sale(today)
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ class DiningFacility < ApplicationRecord
|
|||||||
booking = self.get_current_checkout_booking
|
booking = self.get_current_checkout_booking
|
||||||
if booking
|
if booking
|
||||||
now = Time.now.utc
|
now = Time.now.utc
|
||||||
puts now
|
|
||||||
hr = (now.strftime("%H").to_i).to_int
|
hr = (now.strftime("%H").to_i).to_int
|
||||||
min = (now.strftime("%M").to_i).to_int
|
min = (now.strftime("%M").to_i).to_int
|
||||||
if !booking.checkout_at.nil?
|
if !booking.checkout_at.nil?
|
||||||
|
|||||||
@@ -984,12 +984,11 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.employee_sales(today)
|
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')
|
query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id")
|
||||||
.joins("join employees e on e.id=sales.cashier_id")
|
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_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}'")
|
||||||
.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")
|
||||||
.group('payment_method','e.name')
|
.order("e.name")
|
||||||
.order('e.name')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.total_sale(today)
|
def self.total_sale(today)
|
||||||
@@ -1043,11 +1042,16 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.total_customer(today)
|
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")
|
dinein_cnt = self.total_dinein(today)
|
||||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
takeaway_cnt = self.total_takeaway(today)
|
||||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
membership_cnt = self.total_membership(today)
|
||||||
.order('sales.sale_id ASC')
|
|
||||||
.first()
|
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
|
end
|
||||||
|
|
||||||
def self.total_dinein(today)
|
def self.total_dinein(today)
|
||||||
@@ -1067,7 +1071,7 @@ end
|
|||||||
def self.total_membership(today)
|
def self.total_membership(today)
|
||||||
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
.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()
|
.first()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1111,8 +1115,8 @@ end
|
|||||||
|
|
||||||
def self.total_foc_items(today)
|
def self.total_foc_items(today)
|
||||||
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
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)
|
.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)
|
||||||
.count()
|
.sum("a.qty")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
<% if current_user.role == 'administrator' || current_user.role == 'manager' %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
|
<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
|
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
|
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
|
||||||
<% if !@summ_sale.nil? %>
|
<% if !@summ_sale.nil? %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||||
@@ -185,7 +185,7 @@
|
|||||||
<% if !@total_customer.nil? %>
|
<% if !@total_customer.nil? %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= t("views.right_panel.detail.total") %> <%= t :customer %> : </td>
|
<td><%= t("views.right_panel.detail.total") %> <%= t :customer %> : </td>
|
||||||
<td align="right"><%= @total_customer.total_cus %></td>
|
<td align="right"><%= @total_customer %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if !@total_dinein.nil? %>
|
<% if !@total_dinein.nil? %>
|
||||||
|
|||||||
Reference in New Issue
Block a user