From c111b004d05b5442acc5e6f36c11313ab10ff7d8 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 24 Jul 2018 13:48:57 +0630 Subject: [PATCH] receipt detail report --- app/models/sale.rb | 7 ++----- app/views/reports/receipt_no_detail/index.html.erb | 9 ++++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index d66fbeca..62354a4f 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1087,24 +1087,21 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay payment_type = " and sale_payments.payment_method = '#{payment_type}'" end - query = Sale.select("sales.*,dining_facilities.name as table_name,dining_facilities.type as table_type") + query = Sale.select("sales.*,bookings.dining_facility_id as table_id") if shift.present? query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .joins("join bookings on bookings.sale_id = sales.sale_id") - .joins("join dining_facilities on dining_facilities.id = bookings.dining_facility_id") + .joins("join bookings on bookings.sale_id = sales.sale_id") .group("sales.sale_id") elsif shift_sale_range.present? query = query.where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join bookings on bookings.sale_id = sales.sale_id") - .joins("join dining_facilities on dining_facilities.id = bookings.dining_facility_id") .group("sales.sale_id") else query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sale_payments.payment_amount != 0",from,to) .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join bookings on bookings.sale_id = sales.sale_id") - .joins("join dining_facilities on dining_facilities.id = bookings.dining_facility_id") .group("sales.sale_id") end return query diff --git a/app/views/reports/receipt_no_detail/index.html.erb b/app/views/reports/receipt_no_detail/index.html.erb index 08b61b89..ebabad70 100755 --- a/app/views/reports/receipt_no_detail/index.html.erb +++ b/app/views/reports/receipt_no_detail/index.html.erb @@ -45,10 +45,17 @@ <% grand_total = 0 %> <% @sale_data.each do |result| %> + <% table_name=nil + table_type =nil + if result.table_id.to_i>0 + table = DiningFacility.find(result.table_id) + table_type = table.type + table_name = table.name + end %> <% grand_total = grand_total.to_f + result.grand_total.to_f%> <%= @shift_from %> - <%= @shift_to %> - <%= result.table_type %> - <%= result.table_name %> + <%= table_type %> - <%= table_name %> <%= result.receipt_no rescue '-' %> <%= result.cashier_name rescue '-' %> <%=result.grand_total%>