From b49f46a5c28f040cf524cfe0b7fff3f62faa6436 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 24 Nov 2017 18:57:01 +0630 Subject: [PATCH] update sale item report --- .../origami/discounts_controller.rb | 5 ++ .../reports/saleitem_controller.rb | 3 +- app/models/sale.rb | 3 +- app/views/reports/saleitem/index.html.erb | 63 ++++++++++++------- config/locales/en.yml | 2 + 5 files changed, 53 insertions(+), 23 deletions(-) mode change 100755 => 100644 app/views/reports/saleitem/index.html.erb diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 501c62be..cf723fd6 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -29,14 +29,19 @@ class Origami::DiscountsController < BaseOrigamiController # sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; # sale.save if discount_items.length > 0 + puts discount_items.to_json + puts "dddddddddddd" + #save sale item for discount discount_items.each do |di| origin_sale_item = SaleItem.find(di["id"]) + puts origin_sale_item.to_json sale_item = SaleItem.new sale_item.sale_id = sale_id sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id sale_item.product_name = di["name"] + sale_item.item_instance_code = origin_sale_item.item_instance_code sale_item.product_alt_name = "" sale_item.remark = "Discount" diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 00be65e6..bd933f83 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -16,7 +16,8 @@ class Reports::SaleitemController < BaseReportController end end @sale_data, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED) - + puts @sale_data.to_json + puts "SSSSSSSSSSS" @account_cate_count = Hash.new {|hash, key| hash[key] = 0} diff --git a/app/models/sale.rb b/app/models/sale.rb index dde592e3..7cacedf3 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -623,6 +623,7 @@ def self.get_item_query() query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + + "i.remark as status_type,"+ " i.unit_price as unit_price,i.product_name as product_name, mc.name as" + " menu_category_name,mc.id as menu_category_id ") @@ -635,7 +636,7 @@ def self.get_item_query() 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("i.item_instance_code").order("mi.account_id, mi.menu_category_id") + query = query.group("i.product_name").order("mi.account_id, mi.menu_category_id") end def self.get_by_shift_items(shift_sale_range, shift, from, to, status) diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb old mode 100755 new mode 100644 index 8fc915c9..f9f85a3e --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -59,18 +59,21 @@ <% acc_arr = Array.new %> <% cate_arr = Array.new %> - <% sub_total = 0.0 %> - <% count = 0%> - <% total_price = 0.0 %> + <% sub_total = 0 %> + <% count = 0 %> + <% total_price = 0 %> <% cate_count = 0 %> - <% acc_count = 0%> - <% grand_total = 0%> - <% total_qty = 0%> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> <% total_amount = 0 %> - <% discount = 0%> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0 %> <% @sale_data.each do |sale| %> - <% total_qty += sale.total_item %> + + <% total_qty += sale.total_item %> <% if !acc_arr.include?(sale.account_id) %> @@ -102,30 +105,32 @@ <%= sale.total_item rescue '-' %> <%= sale.unit_price rescue '-' %> <%= sale.grand_total rescue '-' %> - - <% @menu_cate_count.each do |key,value| %> <% if sale.menu_category_id == key %> - <% count = count + 1 %> - <% sub_total += sale.grand_total %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> <% if count == value %>   <%= t("views.right_panel.detail.sub_total") %> <%= sub_total %> - + <% if sale.status_type === "foc" + total_item_foc += sale.grand_total + end %> + + <% if sale.status_type === "Discount" + total_item_dis += sale.grand_total + end %> <% sub_total = 0.0%> <% count = 0%> <% end %> <% end %> <% end %> - - <% end %> @@ -137,20 +142,30 @@ <% end %> - + + + + +   + <%= t("views.right_panel.detail.foc_item") %> <%= t("views.right_panel.detail.amount") %> + <%= total_item_foc %> + + +   + <%= t("views.right_panel.detail.item_discount") %> <%= t("views.right_panel.detail.amount") %> + <%= total_item_dis %>   @@ -162,11 +177,17 @@ <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> <%= @discount_data %> + +   <%= t("views.right_panel.detail.grand_total") %> - <%= @grand_total - @change_amount%> + <%= grand_total + total_item_foc.abs+ total_item_dis.abs+ @foc_data+@discount_data%> diff --git a/config/locales/en.yml b/config/locales/en.yml index f6cf640b..ce493bc5 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -279,6 +279,7 @@ en: additional_parameters: "Additional parameters" title: "Title" discount: "Discount" + item_discount: "Item Discount" point: "Point" bonus: "Bonus" rebate: "Rebate" @@ -402,6 +403,7 @@ en: cash_sales: "Cash Sales" credit_sales: "Credit Sales" foc_sales: "FOC Sales" + foc_item: "Item FOC" net_amount: "Net Amount" sale_item_report: "Sale Item Report" select_period: "Select Period"