check product sale query
This commit is contained in:
@@ -851,10 +851,10 @@ def self.get_menu_item_query(order_by)
|
||||
query = MenuItem.unscoped.select("acc.id as account_id,
|
||||
acc.title as account_name,
|
||||
mii.item_instance_code as item_code, " +
|
||||
"(CASE WHEN si.qty != '' THEN SUM(si.qty) ELSE 0 END) as total_item," +
|
||||
"(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," +
|
||||
"(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," +
|
||||
"(CASE WHEN (si.qty * si.unit_price) > 0 THEN (si.qty * si.unit_price) ELSE 0 END) as grand_total," +
|
||||
"mii.price as unit_price, mii.item_instance_name as product_name,
|
||||
"(CASE WHEN si.qty IS NOT NULL THEN (SUM(si.qty) * si.unit_price) ELSE 0 END) as grand_total," +
|
||||
"mii.price as unit_price, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END) as product_name,
|
||||
mc.name as" +
|
||||
" menu_category_name,mc.id as menu_category_id, si.remark as status_type,
|
||||
si.price as price ")
|
||||
@@ -863,7 +863,8 @@ def self.get_menu_item_query(order_by)
|
||||
" LEFT JOIN accounts acc ON acc.id = menu_items.account_id" +
|
||||
" LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" +
|
||||
" LEFT JOIN sales s ON s.sale_id = si.sale_id")
|
||||
.group("mc.id, mii.item_instance_name, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)")
|
||||
.where("(CASE WHEN s.sale_status IS NOT NULL THEN s.sale_status='completed' ELSE 1 END)")
|
||||
.group("mc.id, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END)")
|
||||
.order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}")
|
||||
end
|
||||
#product sale report query
|
||||
|
||||
Reference in New Issue
Block a user