From 2f7d9523ec9c9571937703b51732562072d15955 Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 28 Feb 2018 16:26:40 +0630 Subject: [PATCH] check product sale --- app/models/sale.rb | 9 +++-- app/views/reports/product_sale/index.html.erb | 38 ++++++++++--------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index e433a999..4a12715f 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -851,18 +851,19 @@ 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 > 0 THEN SUM(si.qty) ELSE 0 END) as total_item," + + "(CASE WHEN si.qty != '' 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, menu_items.name as product_name, + "mii.price as unit_price, mii.item_instance_name as product_name, mc.name as" + - " menu_category_name,mc.id as menu_category_id, si.remark as status_type, si.price as price ") + " menu_category_name,mc.id as menu_category_id, si.remark as status_type, + si.price as price ") .joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" + " LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" + " 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("si.qty, mc.id, menu_items.name, (CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END)") + .group("mc.id, mii.item_instance_name, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)") .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") end #product sale report query diff --git a/app/views/reports/product_sale/index.html.erb b/app/views/reports/product_sale/index.html.erb index b8ab6598..a62e0d73 100755 --- a/app/views/reports/product_sale/index.html.erb +++ b/app/views/reports/product_sale/index.html.erb @@ -47,6 +47,7 @@ <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= t("views.right_panel.detail.unit_price") %> <%= t("views.right_panel.detail.total") %> + <%= t("views.right_panel.detail.remark") %> @@ -58,24 +59,25 @@ <% total_qty = 0 %> <% @sale_data.each do |sale| %> - <% if sale.status_type != "Discount" && sale.status_type != "foc" - total_qty += sale.total_item - grand_total += sale.grand_total - end %> - <% if sale.status_type == "foc" && sale.price > 0 - total_qty += sale.total_item - grand_total += sale.grand_total - end %> + <% if sale.status_type != "Discount" && sale.status_type != "foc" + total_qty += sale.total_item + grand_total += sale.grand_total + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + grand_total += sale.grand_total + end %> - -   - <%= sale.menu_category_name %> - <%= sale.item_code rescue '-' %> - <%= sale.product_name rescue '-' %> - <%= sale.total_item rescue '-' %> - <%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> - + +   + <%= sale.menu_category_name %> + <%= sale.item_code rescue '-' %> + <%= sale.product_name rescue '-' %> + <%= sale.total_item rescue '-' %> + <%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> + <%= sale.status_type rescue '' %> + <% end %> @@ -84,7 +86,7 @@ Total <%= total_qty %> - <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> + <%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %> <% end %>