Merge branch 'crm' of bitbucket.org:code2lab/sxrestaurant
This commit is contained in:
@@ -17,6 +17,14 @@ class Sale < ApplicationRecord
|
||||
scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
|
||||
scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
|
||||
|
||||
REPORT_TYPE = {
|
||||
"daily" => 0,
|
||||
"monthly" => 1,
|
||||
"yearly" => 2
|
||||
}
|
||||
|
||||
SALE_STATUS_COMPLETED = "completed"
|
||||
|
||||
def generate_invoice_from_booking(booking_id, requested_by)
|
||||
booking = Booking.find(booking_id)
|
||||
status = false
|
||||
@@ -336,6 +344,40 @@ class Sale < ApplicationRecord
|
||||
return daily_total
|
||||
end
|
||||
|
||||
def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
|
||||
query = Sale.select("
|
||||
mi.item_code as code,(SUM(i.qty) * i.unit_price) as grand_total,
|
||||
SUM(i.qty) as total_item," +
|
||||
" i.unit_price as unit_price,
|
||||
mi.name as product_name,
|
||||
mc.name as menu_category_name,
|
||||
mc.id as menu_category_id ")
|
||||
.group('mi.id')
|
||||
.order("mi.menu_category_id")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN menu_items mi ON i.product_code = mi.item_code" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
|
||||
JOIN employees ea ON ea.id = sales.cashier_id")
|
||||
|
||||
|
||||
query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status)
|
||||
|
||||
|
||||
|
||||
case report_type.to_i
|
||||
when REPORT_TYPE["daily"]
|
||||
return query
|
||||
when REPORT_TYPE["monthly"]
|
||||
|
||||
return query.group("MONTH(date)")
|
||||
when REPORT_TYPE["yearly"]
|
||||
return query.group("YEAR(date)")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_custom_id
|
||||
|
||||
Reference in New Issue
Block a user