From 0d9e3636485114c2e6c8b50bec49d3dc30f50534 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Mon, 18 Nov 2019 09:57:55 +0630 Subject: [PATCH] add staff meal --- .../reports/staff_meal_controller.rb | 133 ++++++ app/models/inventory_definition.rb | 15 +- app/models/order_item.rb | 12 +- app/models/sale.rb | 134 +++++- app/models/sale_item.rb | 107 +++-- app/views/layouts/_left_sidebar.html.erb | 6 + ...> _hourly_saleitem_report_filter.html.erb} | 4 +- .../reports/hourly_saleitem/index.html.erb | 2 +- .../reports/hourly_saleitem/index.xls.erb | 263 ++++++------ .../_staff_meal_report_filter.html.erb | 146 +++++++ app/views/reports/staff_meal/index.html.erb | 390 ++++++++++++++++++ app/views/reports/staff_meal/index.xls.erb | 277 +++++++++++++ config/routes.rb | 1 + 13 files changed, 1291 insertions(+), 199 deletions(-) create mode 100644 app/controllers/reports/staff_meal_controller.rb rename app/views/reports/hourly_saleitem/{_shift_sale_report_filter.html.erb => _hourly_saleitem_report_filter.html.erb} (97%) create mode 100644 app/views/reports/staff_meal/_staff_meal_report_filter.html.erb create mode 100644 app/views/reports/staff_meal/index.html.erb create mode 100644 app/views/reports/staff_meal/index.xls.erb diff --git a/app/controllers/reports/staff_meal_controller.rb b/app/controllers/reports/staff_meal_controller.rb new file mode 100644 index 00000000..b0a8b4d2 --- /dev/null +++ b/app/controllers/reports/staff_meal_controller.rb @@ -0,0 +1,133 @@ +class Reports::StaffMealController < BaseReportController + authorize_resource :class => false + def index + + @account = Account.all + from, to = get_date_range_from_params + + shift_sale_range = '' + + shift = '' + if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + end + + staff = Customer.where(customer_type: 'staff') + customer_id = Array.new + staff.each { |s| + customer_id.push(s.customer_id) + } + + account_type = params[:account_type] + + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_staff_meal_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,account_type,customer_id) + + @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) + + @account_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} + + + @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|cate| @menu_cate_count[cate.account_id] += 1} + + + @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + @from = from + @to = to + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + if shift.present? + shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + respond_to do |format| + format.html + format.xls + end + end + + def show + from, to, report_type = get_date_range_from_params + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end + + def get_period_name(period) + period_name = '-' + unless period.nil? or period.blank? + case period.to_i + when PERIOD["today"] + period_name = "Today" + + when PERIOD["yesterday"] + period_name = "Yesterday" + + when PERIOD["this_week"] + period_name = "This Week" + + when PERIOD["last_week"] + period_name = "Last Week" + + when PERIOD["last_7"] + period_name = "Last 7 days" + + when PERIOD["this_month"] + period_name = "This Month" + + when PERIOD["last_month"] + period_name = "Last Month" + + when PERIOD["last_30"] + period_name = "Last 30 Days" + + when PERIOD["this_year"] + period_name = "This Year" + + when PERIOD["last_year"] + period_name = "Last Year" + + end + end + return period_name + end + +end diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 4ff649e0..dd2f3c3c 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -23,7 +23,20 @@ class InventoryDefinition < ApplicationRecord end end - def self.find_product_in_inventory(item) + def self.find_product_in_inventory(item,instance_code) + unless instance_code.empty? + instance_code = instance_code.to_s + instance_code[0] = "" + instance_code = instance_code.chomp("]") + else + instance_code = '"0"' + end + + if prod = InventoryDefinition.where("item_code IN(#{instance_code})") + puts "found prodcut+++++++++++++++++++++++++++++++++++===" + puts prod.to_json + end + if product = InventoryDefinition.find_by_item_code(item.item_instance_code) if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code) return true, product diff --git a/app/models/order_item.rb b/app/models/order_item.rb index f265be2b..005bfe67 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -125,8 +125,18 @@ class OrderItem < ApplicationRecord end def update_stock_journal + if self.set_menu_items.present? + puts "set menu itemsssssssss???????????????????????????????" + puts items = JSON.parse(self.set_menu_items) + instance_code = Array.new + count = 0 + items.each { |i| + instance_code.push(i["item_instance_code"]) + } + print instance_code + end if self.qty != self.qty_before_last_save - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,instance_code) if found InventoryDefinition.check_balance(self, inventory_definition) end diff --git a/app/models/sale.rb b/app/models/sale.rb index 82ccff3d..29404ac9 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -942,6 +942,28 @@ def self.get_item_query(type) # query = query.order("i.menu_category_name asc, SUM(i.qty) desc") end +def self.get_staff_meal_query() + sale_type = "foc" + query = Sale.select("cus.name as staff_name,sales.sale_id,acc.title as account_name, + 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.remark as remark,"+ + "i.unit_price,i.price as price,i.product_name as product_name, " + + "i.menu_category_name,i.menu_category_code as menu_category_id, " + + "date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p') + as date_format") + + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id " + + "JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id " + + "JOIN customers cus ON cus.customer_id = sales.customer_id ") + query = query.joins(" JOIN accounts acc ON acc.id = i.account_id") + # query = query.where("#{sale_type}") + query = query.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price") + .order("acc.title desc, i.account_id desc, i.menu_category_code desc, i.item_instance_code asc, SUM(i.qty) desc, i.unit_price asc") + # query = query.order("i.menu_category_name asc, SUM(i.qty) desc") +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," + @@ -1048,6 +1070,111 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount end +def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_type,customer_id) + # date_type_selection = get_sql_function_for_report_type(report_type) + if account_type.blank? + account_type = '' + else + account_type = " and acc.title = '#{account_type}'" + end + + unless customer_id.empty? + customer_id = customer_id.to_s + customer_id[0] = "" + customer_id = customer_id.chomp("]") + else + customer_id = '"CUS-000000000000"' + end + + query = self.get_staff_meal_query() + + discount_query = 0 + total_card_amount = 0 + total_cash_amount = 0 + total_credit_amount = 0 + total_foc_amount = 0 + total_grand_total = 0 + other_charges = 0 + + # if type.nil? || type == 'all' || type == "other" + # other_charges = self.get_other_charges() + # end + product = self.get_product_sale() + + if shift.present? + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift.to_a) + # if type.nil? || type == 'all' || type == "other" + # other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + # end + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + ### => get all sales range in shift_sales + elsif shift_sale_range.present? + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift_sale_range.to_a) + # if type.nil? || type == 'all' || type == "other" + # other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + # end + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + else + query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",from,to) + # if type.nil? || type == 'all' || type == "other" + # other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + # end + product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + + discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) + change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + end + + return query, other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount +end + def self.get_product_sale() query = Sale.select("i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + @@ -1478,13 +1605,6 @@ end end def self.hourly_sales(today,current_user,from,to,from_time,to_time) - logger.debug 'hourly_sales<<<<<<<<<<<<<<<<<<<<<<<<' - logger.debug today - logger.debug current_user.to_json - logger.debug from - logger.debug to - logger.debug from_time - logger.debug to_time if (!from.nil? && !to.nil?) && (from != "" && to!="") if current_user.nil? query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time) diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 9a8c3d87..8473da78 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -225,6 +225,59 @@ class SaleItem < ApplicationRecord return sale_items end + # Loader Service SFTP Start + # Detail Sale Data + def self.get_detail_sale_data(transaction_date) + query = SaleItem.select(" + sale_items.sale_item_id as id, + sale_items.sale_id as parent_id, + s.receipt_no as check_num, + s.receipt_date as business_date, + s.receipt_date as transaction_date, + '' as item_seq, + sale_items.menu_category_code as category_code, + sale_items.menu_category_name as category_name, + '' as sub_category_code, + '' as sub_category_name, + '' as report_group_code, + '' as report_group_name, + sale_items.product_code as item_id, + sale_items.product_name as item_name, + sale_items.qty as qty, + CASE + WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales' + WHEN s.sale_status = 'waste' THEN 'Waste' + WHEN s.sale_status = 'spoile' THEN 'Spoil' + END as transaction_type, + sale_items.price as gross_sales, + '' as discount_code, + CASE + WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 + END as discount_amt, + (sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) as sales, + ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21) as tax_amt, + '' as service_charges, + ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21)) as net_sales, + '0' as is_set_item, + '0' as is_staff_meal, + '0' as is_raw_wastage, + '0' as is_semi_wastage, + CASE WHEN s.sale_status = 'waste' THEN 1 ELSE 0 END as is_wastage, + CASE WHEN s.sale_status = 'spoile' THEN 1 ELSE 0 END as is_spoilage, + '0' as is_sampling, + '1' as tax_able, + CASE + WHEN s.sale_status = 'void' THEN 1 ELSE 0 + END as is_void + ") + .joins("LEFT JOIN sales s ON s.sale_id = sale_items.sale_id") + .joins("LEFT JOIN sale_items i ON sale_items.sale_id = i.sale_id AND sale_items.item_instance_code = i.item_instance_code AND i.status = 'Discount' AND sale_items.qty = abs(i.qty)") + .where("DATE(s.receipt_date) = ? AND s.sale_status != 'void' AND (sale_items.status NOT IN('Discount', 'void','foc') OR sale_items.status IS NULL)", transaction_date) + .order("s.receipt_no") + end + + # Loader Service SFTP End + private def generate_custom_id if self.sale_item_id.nil? @@ -293,58 +346,4 @@ class SaleItem < ApplicationRecord end end end - - # Loader Service SFTP Start - # Detail Sale Data - def self.get_detail_sale_data(transaction_date) - query = SaleItem.select(" - sale_items.sale_item_id as id, - sale_items.sale_id as parent_id, - s.receipt_no as check_num, - s.receipt_date as business_date, - s.receipt_date as transaction_date, - '' as item_seq, - sale_items.menu_category_code as category_code, - sale_items.menu_category_name as category_name, - '' as sub_category_code, - '' as sub_category_name, - '' as report_group_code, - '' as report_group_name, - sale_items.product_code as item_id, - sale_items.product_name as item_name, - sale_items.qty as qty, - CASE - WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales' - WHEN s.sale_status = 'waste' THEN 'Waste' - WHEN s.sale_status = 'spoile' THEN 'Spoil' - END as transaction_type, - sale_items.price as gross_sales, - '' as discount_code, - CASE - WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 - END as discount_amt, - (sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) as sales, - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21) as tax_amt, - '' as service_charges, - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21)) as net_sales, - '0' as is_set_item, - '0' as is_staff_meal, - '0' as is_raw_wastage, - '0' as is_semi_wastage, - CASE WHEN s.sale_status = 'waste' THEN 1 ELSE 0 END as is_wastage, - CASE WHEN s.sale_status = 'spoile' THEN 1 ELSE 0 END as is_spoilage, - '0' as is_sampling, - '1' as tax_able, - CASE - WHEN s.sale_status = 'void' THEN 1 ELSE 0 - END as is_void - ") - .joins("LEFT JOIN sales s ON s.sale_id = sale_items.sale_id") - .joins("LEFT JOIN sale_items i ON sale_items.sale_id = i.sale_id AND sale_items.item_instance_code = i.item_instance_code AND i.status = 'Discount' AND sale_items.qty = abs(i.qty)") - .where("DATE(s.receipt_date) = ? AND s.sale_status != 'void' AND (sale_items.status NOT IN('Discount', 'void','foc') OR sale_items.status IS NULL)", transaction_date) - .order("s.receipt_no") - end - - # Loader Service SFTP End - end diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index c948964d..1dbb3b98 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -138,6 +138,9 @@
  • Induty
  • +
  • + Staff Meal +
  • Stock Check
  • @@ -324,6 +327,9 @@
  • Induty
  • +
  • + Staff Meal +
  • Stock Check
  • diff --git a/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/hourly_saleitem/_hourly_saleitem_report_filter.html.erb similarity index 97% rename from app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb rename to app/views/reports/hourly_saleitem/_hourly_saleitem_report_filter.html.erb index 4ca6ccf9..3814746e 100644 --- a/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb +++ b/app/views/reports/hourly_saleitem/_hourly_saleitem_report_filter.html.erb @@ -56,9 +56,9 @@ -
    +

    - +
    <% end %> diff --git a/app/views/reports/hourly_saleitem/index.html.erb b/app/views/reports/hourly_saleitem/index.html.erb index a42ce2b3..4d3316de 100644 --- a/app/views/reports/hourly_saleitem/index.html.erb +++ b/app/views/reports/hourly_saleitem/index.html.erb @@ -10,7 +10,7 @@
    - <%= render :partial=>'shift_sale_report_filter', + <%= render :partial=>'hourly_saleitem_report_filter', :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_hourly_saleitem_index_path} %>
    diff --git a/app/views/reports/hourly_saleitem/index.xls.erb b/app/views/reports/hourly_saleitem/index.xls.erb index df37f29e..831f6190 100644 --- a/app/views/reports/hourly_saleitem/index.xls.erb +++ b/app/views/reports/hourly_saleitem/index.xls.erb @@ -5,142 +5,139 @@ -
    -
    -
    -
    -
    -
    -
    +
    +
    +
    +
    + + <% time_arr = Array.new %> + <% acc_arr = Array.new %> + <% sale_item_count =0 %> + <% menu_cat_arr = Array.new %> + <% footer_arr = Array.new %> + <% count = 0 %> + <% waste_and_spoil_item_count = 0%> + <% total_qty = 0 %> + <% time_count = 0 %> + <% grand_total = 0 %> + <% @sale_data.each do |sale| %> + <% if !time_arr.include?(sale.date_format) %> + <% sale_item_count =1 %> + <% time_count = time_count + 1 %> + + + + + + + + + + + + + + + + + + <% time_arr.push(sale.date_format) %> + <% menu_cat_arr.clear %> + <% count = 0 %> + <% else %> + <% sale_item_count =sale_item_count +1 %> + <% end %> + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + + <% 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 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> -
     
    + Time :<%= sale.date_format %> +
    Menu CategoryItem CodeItem NameQtyPriceTotal Price
    - <% time_arr = Array.new %> - <% acc_arr = Array.new %> - <% sale_item_count =0 %> - <% menu_cat_arr = Array.new %> - <% footer_arr = Array.new %> - <% count = 0 %> - <% waste_and_spoil_item_count = 0%> - <% total_qty = 0 %> - <% time_count = 0 %> - <% grand_total = 0 %> - <% @sale_data.each do |sale| %> - <% if !time_arr.include?(sale.date_format) %> - <% sale_item_count =1 %> - <% time_count = time_count + 1 %> - - - - - - - - - - - - - - - - - - <% time_arr.push(sale.date_format) %> - <% menu_cat_arr.clear %> - <% count = 0 %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "promotion" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> + + <% grand_total += sale.grand_total %> + + <% if !sale.item_code.nil?%> + <% waste_and_spoil_item_count += sale.qty.to_i %> + + <% if !menu_cat_arr.include?(sale.menu_category_name) %> + + <% menu_cat_arr.push(sale.menu_category_name) %> + <% else %> + + <% end %> + + + + + + + + <% end %> + + <% count = count + 1 %> + <% @hourly_total_qty.each do |hr| %> + <% if hr["date"].to_s == sale.date_format.to_s && hr["total_qty"].to_i ==sale_item_count%> + + + + + + + + <% footer_arr.push(sale.sale_id) %> <% else %> - <% sale_item_count =sale_item_count +1 %> <% end %> - - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - - <% 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 - total_qty += sale.total_item - end %> - <% if sale.status_type == "Discount" - total_qty += sale.total_item*(-1) - end %> - <% if sale.status_type =="promotion" && @type == "promotion" - total_qty += sale.total_item*(-1) - end %> - - - <% if sale.status_type == "foc" && sale.grand_total < 0 - grand_total += sale.grand_total*(-1) - end %> - - <% if sale.status_type == "Discount" && sale.grand_total < 0 - grand_total += sale.grand_total*(-1) - end %> - - <% if sale.status_type == "promotion" && sale.grand_total < 0 - grand_total += sale.grand_total*(-1) - end %> - - <% grand_total += sale.grand_total %> - - <% if !sale.item_code.nil?%> - <% waste_and_spoil_item_count += sale.qty.to_i %> - - <% if !menu_cat_arr.include?(sale.menu_category_name) %> - - <% menu_cat_arr.push(sale.menu_category_name) %> - <% else %> - - <% end %> - - - - - - - - <% end %> - - <% count = count + 1 %> - <% @hourly_total_qty.each do |hr| %> - <% if hr["date"].to_s == sale.date_format.to_s && hr["total_qty"].to_i ==sale_item_count%> - - - - - - - - <% footer_arr.push(sale.sale_id) %> - <% else %> - <% end %> - <% end %> - <% end %> -
     
    - Time :<%= sale.date_format %> -
    Menu CategoryItem CodeItem NameQtyPriceTotal Price
    <%= sale.menu_category_name %> <%= sale.item_code %><%= sale.product_name %><%= sale.total_item.to_i %><%= number_with_precision(sale.unit_price.to_i, precision:precision.to_i,delimiter:delimiter) %><%= number_with_precision(sale.grand_total.to_i, precision:precision.to_i,delimiter:delimiter) %>
    Total Qty: + + <%= total_qty.to_i %> + <% total_qty = 0%> + Grand Total: + + <%= number_with_precision(grand_total.to_i, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total = 0 %> + +
    <%= sale.menu_category_name %> <%= sale.item_code %><%= sale.product_name %><%= sale.total_item.to_i %><%= sale.unit_price.to_i %><%= sale.grand_total.to_i %><%= sale.date_format %>
    Total Qty: - - <%= total_qty.to_i %> - <% total_qty = 0%> - Grand Total: - - <%= grand_total.to_i %> - <% grand_total = 0 %> - -
    -
    -
    -
    + + <% end %> + +
    +
    +
    +
    diff --git a/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb b/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb new file mode 100644 index 00000000..04108f48 --- /dev/null +++ b/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb @@ -0,0 +1,146 @@ +
    + <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
    +
    + + +
    + + +
    + + + +
    +
    + + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + <% end %> + + <% end %> +
    + + diff --git a/app/views/reports/staff_meal/index.html.erb b/app/views/reports/staff_meal/index.html.erb new file mode 100644 index 00000000..ea92f55c --- /dev/null +++ b/app/views/reports/staff_meal/index.html.erb @@ -0,0 +1,390 @@ + +
    +
    + <%= render :partial=>'staff_meal_report_filter', + :locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_staff_meal_index_path} %> + +
    + + + +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% 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 %> + <% row_count = 0 %> + <% total_price = 0 %> + <% cate_count = 0 %> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> + <% total_amount = 0 %> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + <% unless @sale_data.blank? %> + <% @sale_data.each do |sale| %> + <% row_count += 1 %> + + + <% 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 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + total_item_foc += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + total_item_dis += sale.grand_total*(-1) + end %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + <% if sale.status_type != "Discount" %> + + <%else%> + + <% end %> + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% 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.status_type == "promotion" && @type == "promotion" + sub_qty += sale.total_item*(-1) + end %> + <% if count == value %> + + + + + + + + <% sub_total = 0.0%> + <% sub_qty = 0 %> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% end %> + + <% if @product.present?%> + + + + + + + <% @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_sub_total += product.grand_total %> + + <% end %> + + + + + + + + + <%end%> + + + + + + + + + + + + + <% if @type =="" || @type =="all" || @type.nil? %> + + + <% end %> + <% end %> + <% if @type == "other"%> + + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
     <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
    <%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> + <% end %> + <% end %> +
     <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) 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 '-'%>
     Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Product 
     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 '-'%>
     Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    + +
    +
    +
    +
    +
    + + diff --git a/app/views/reports/staff_meal/index.xls.erb b/app/views/reports/staff_meal/index.xls.erb new file mode 100644 index 00000000..5bd390fd --- /dev/null +++ b/app/views/reports/staff_meal/index.xls.erb @@ -0,0 +1,277 @@ + + + + + + + +
    +
    +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% 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 %> + <% row_count = 0 %> + <% total_price = 0 %> + <% cate_count = 0 %> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> + <% total_amount = 0 %> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + <% unless @sale_data.blank? %> + <% @sale_data.each do |sale| %> + <% row_count += 1 %> + + + <% 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 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + total_item_foc += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + total_item_dis += sale.grand_total*(-1) + end %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + <% if sale.status_type != "Discount" %> + + <%else%> + + <% end %> + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% 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.status_type == "promotion" && @type == "promotion" + sub_qty += sale.total_item*(-1) + end %> + <% if count == value %> + + + + + + + + <% sub_total = 0.0%> + <% sub_qty = 0 %> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% end %> + + <% if @product.present?%> + + + + + + + <% @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_sub_total += product.grand_total %> + + <% end %> + + + + + + + + + <%end%> + + + + + + + + + + + + + <% if @type =="" || @type =="all" || @type.nil? %> + + + <% end %> + <% end %> + <% if @type == "other"%> + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
     <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
    <%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> + <% end %> + <% end %> +
     <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) 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 '-'%>
     Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Product 
     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 '-'%>
     Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    + +
    +
    +
    +
    +
    + + + diff --git a/config/routes.rb b/config/routes.rb index b3c5ff6e..933002d9 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -532,6 +532,7 @@ scope "(:locale)", locale: /en|mm/ do resources :dailysale, :only => [:index, :show] resources :saleitem, :only => [:index, :show] resources :hourly_saleitem, :only => [:index, :show] + resources :staff_meal, :only => [:index, :show] resources :shiftsale, :only => [:index, :show] resources :credit_payment, :only => [:index, :show] resources :void_sale, :only => [:index, :show]