product sale
This commit is contained in:
@@ -785,7 +785,6 @@ end
|
||||
|
||||
def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
# date_type_selection = get_sql_function_for_report_type(report_type)
|
||||
|
||||
query = self.get_item_query()
|
||||
|
||||
discount_query = 0
|
||||
@@ -861,6 +860,52 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
return query,other_charges, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
|
||||
end
|
||||
|
||||
#product sale report query
|
||||
def self.get_product_item_query()
|
||||
query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " +
|
||||
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," +
|
||||
"i.remark as status_type,"+
|
||||
" i.unit_price,i.price as price,i.product_name as product_name, mc.name as" +
|
||||
" menu_category_name,mc.id as menu_category_id ")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" +
|
||||
" JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" +
|
||||
" JOIN menu_items mi ON mi.id = mii.menu_item_id" +
|
||||
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
|
||||
# "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
|
||||
query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id")
|
||||
# query = query.where("i.item_instance_code IS NOT NULL")
|
||||
query = query.group("acc.title,mi.account_id,mi.menu_category_id,mi.name,mii.price")
|
||||
.order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, mii.price asc")
|
||||
end
|
||||
|
||||
def self.get_by_items(shift_sale_range, shift, from, to)
|
||||
query = self.get_product_item_query()
|
||||
|
||||
puts "query"
|
||||
total_grand_total = 0
|
||||
|
||||
# if shift.present?
|
||||
# query = query.where("sales.shift_sale_id IN (?)",shift.to_a)
|
||||
|
||||
# # total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
# ### => get all sales range in shift_sales
|
||||
# elsif shift_sale_range.present?
|
||||
# query = query.where("sales.shift_sale_id IN (?)",shift_sale_range.to_a)
|
||||
|
||||
# # total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
# else
|
||||
# query = query.where("sales.receipt_date between ? and ?",from,to)
|
||||
# # total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
# end
|
||||
|
||||
return query, total_grand_total
|
||||
end
|
||||
#product sale report query
|
||||
|
||||
def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type)
|
||||
## => left join -> show all sales although no orders
|
||||
if payment_type.blank?
|
||||
|
||||
Reference in New Issue
Block a user