From ad4bf1451bfd716e9c9e2da183fef764ac0bc937 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 21 Jun 2018 14:39:34 +0630 Subject: [PATCH] promotion add in report --- app/models/promotion.rb | 1 + app/models/sale.rb | 9 ++- .../_shift_sale_report_filter.html.erb | 1 + app/views/reports/saleitem/index.html.erb | 11 +++- app/views/reports/saleitem/index.xls.erb | 57 +++++++++++++++++-- 5 files changed, 69 insertions(+), 10 deletions(-) diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 4271045e..b6bd063f 100755 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -165,6 +165,7 @@ class Promotion < ApplicationRecord sale_item = SaleItem.new sale_item.product_code = item.item_code + sale_item.item_instance_code = item.item_instance_code sale_item.product_name = item.item_name + "(promotion)" sale_item.product_alt_name = item.alt_name sale_item.account_id = item.account_id diff --git a/app/models/sale.rb b/app/models/sale.rb index 603d5156..1d7f740b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -878,13 +878,16 @@ def self.get_item_query(type) sale_type = "i.status = 'void' and i.item_instance_code IS NOT NULL and i.qty > 0" elsif type == "other" sale_type = "i.item_instance_code IS NULL" + elsif type == "promotion" + sale_type = "i.status = 'promotion'" 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.status as status_type,i.remark as remark,"+ + "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" + @@ -901,7 +904,7 @@ end def self.get_other_charges() query = Sale.select("i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + - "i.status as status_type,"+ + "i.status as status_type,i.remark as remark,"+ " i.unit_price as unit_price,i.product_name as product_name") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id") query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'") diff --git a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb index 068a3f58..d1a3ec5b 100755 --- a/app/views/reports/saleitem/_shift_sale_report_filter.html.erb +++ b/app/views/reports/saleitem/_shift_sale_report_filter.html.erb @@ -28,6 +28,7 @@ + diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index 9b617d06..744c792b 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -79,7 +79,7 @@ <% @sale_data.each do |sale| %> - <% if sale.status_type != "Discount" && sale.status_type != "foc" + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" total_qty += sale.total_item end %> <% if sale.status_type == "foc" && sale.price > 0 @@ -88,6 +88,9 @@ <% if sale.status_type == "Discount" total_qty += sale.total_item*(-1) end %> + <% if sale.remark =="promotion" + total_qty += sale.total_item + end %> <% if sale.status_type == "foc" && sale.grand_total < 0 @@ -140,12 +143,16 @@ <% count = count + 1 %> <% sub_total += sale.grand_total %> <% #sub_qty += sale.total_item %> - <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") + <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" sub_qty += sale.total_item end %> <% if sale.status_type =="Discount" sub_qty += sale.total_item*(-1) end %> + + <% if sale.remark == "promotion" + sub_qty += sale.total_item + end %> <% if count == value %>   diff --git a/app/views/reports/saleitem/index.xls.erb b/app/views/reports/saleitem/index.xls.erb index 78d0aaec..8f326e27 100755 --- a/app/views/reports/saleitem/index.xls.erb +++ b/app/views/reports/saleitem/index.xls.erb @@ -48,10 +48,11 @@ %> <% acc_arr = Array.new %> <% cate_arr = Array.new %> - + <% p_qty = 0 %> <% sub_qty = 0 %> <% sub_total = 0 %> <% other_sub_total = 0 %> + <% product_sub_total = 0 %> <% count = 0 %> <% total_price = 0 %> <% cate_count = 0 %> @@ -67,7 +68,7 @@ <% @sale_data.each do |sale| %> - <% if sale.status_type != "Discount" && sale.status_type != "foc" + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" total_qty += sale.total_item end %> <% if sale.status_type == "foc" && sale.price > 0 @@ -76,6 +77,9 @@ <% if sale.status_type == "Discount" total_qty += sale.total_item*(-1) end %> + <% if sale.remark =="promotion" + total_qty += sale.total_item + end %> <% if sale.status_type == "foc" && sale.grand_total < 0 @@ -128,12 +132,16 @@ <% count = count + 1 %> <% sub_total += sale.grand_total %> <% #sub_qty += sale.total_item %> - <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") + <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" sub_qty += sale.total_item end %> <% if sale.status_type =="Discount" sub_qty += sale.total_item*(-1) end %> + + <% if sale.remark == "promotion" + sub_qty += sale.total_item + end %> <% if count == value %>   @@ -150,8 +158,47 @@ <% end %> <% end %> + + <% if @product.present?%> + + + Product +   + + + <% @product.each do |product| %> + <% if product.total_item > 0 + total_qty += product.total_item + end %> + <% grand_total +=product.grand_total + p_qty += product.total_item%> + +   + Product + <%= product.product_code rescue '-' %> + <%= product.product_name rescue '-' %> + <%= product.total_item rescue '-' %> + <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%> + + + + <% product_sub_total += product.grand_total %> + + <% end %> + +   + Total Product Qty + <%= p_qty %> + + <%= t("views.right_panel.detail.sub_total") %> + <%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%> + + <%end%> + + - <% if @type == "other"%> + <% if @type == "other" || @other_charges.present?%> Other Charges @@ -205,7 +252,7 @@ end %> <% grand_total +=other.grand_total%> -   +   Other Charges <%= other.item_code rescue '-' %> <%= other.product_name rescue '-' %>