merge with chart
This commit is contained in:
@@ -843,6 +843,28 @@ end
|
||||
return tax
|
||||
end
|
||||
|
||||
def self.top_products(today)
|
||||
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||
" i.price as unit_price,mi.name as product_name")
|
||||
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
||||
.where("(i.qty > 0 ) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
||||
"and payment_status='paid' and sale_status= 'completed'")
|
||||
.group('mi.name')
|
||||
.order("SUM(i.qty) DESC").limit(5)
|
||||
end
|
||||
|
||||
def self.hourly_sales(today)
|
||||
query= Sale.select("grand_total").where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||
end
|
||||
|
||||
def self.employee_sales(today)
|
||||
query = Sale.select("e.name as employee_name,grand_total")
|
||||
.where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.joins("join employees e on e.id=sales.cashier_id")
|
||||
.group('e.name')
|
||||
.order('e.name ASC')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_custom_id
|
||||
|
||||
@@ -36,4 +36,12 @@ class StockJournal < ApplicationRecord
|
||||
journal.save
|
||||
end
|
||||
|
||||
def self.inventory_balances(today)
|
||||
query = StockJournal.select("mii.item_instance_name as item_instance_name,balance")
|
||||
.joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code")
|
||||
.where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'")
|
||||
.group("mii.item_instance_name")
|
||||
.order("mii.item_instance_name ASC")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user