add foc , void and discount item in sale item report

This commit is contained in:
Aung Myo
2018-03-26 15:54:24 +06:30
parent 2a88bd4409
commit ac0ee37136
6 changed files with 573 additions and 147 deletions

View File

@@ -798,15 +798,27 @@ def self.get_by_shift_sale(from,to,status)
return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to)
end
def self.get_item_query()
def self.get_item_query(type)
if type == "revenue" || type.nil?
sale_type = "i.status IS NULL and i.qty >0 "
elsif type == "all"
sale_type = ""
elsif type == "discount"
sale_type = "i.status = 'Discount'"
elsif type == "foc"
sale_type = "i.status = 'foc' and i.qty > 0"
elsif type == "void"
sale_type = "i.status = 'void' and i.qty > 0"
elsif type == "other"
sale_type = "i.item_instance_code IS NULL"
end
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.status 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 ")
"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" +
@@ -815,7 +827,7 @@ def self.get_item_query()
" 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.where("#{sale_type}")
query = query.group("acc.title,mi.account_id,mi.menu_category_id,i.product_name,i.unit_price")
.order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, i.unit_price asc")
end
@@ -830,10 +842,15 @@ def self.get_other_charges()
query = query.group("i.sale_item_id")
end
def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type)
# date_type_selection = get_sql_function_for_report_type(report_type)
query = self.get_item_query()
if type == "other"
other_charges = self.get_other_charges()
query = self.get_item_query(type)
else
query = self.get_item_query(type)
end
discount_query = 0
total_card_amount = 0
total_cash_amount = 0