diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index 8e92ebb6..fd203791 100644 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -7,17 +7,19 @@ authorize_resource :class => false # else # @shift = ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to).take # end - puts "2017-07-07T10:46:09.000Z - 2017-07-07T11:12:51.000Z" - puts "2017-06-25 17:30:00 UTC 2017-07-02 17:29:59 UTC" -puts params[:shift_name] -puts from.utc -puts to.utc + # puts "2017-07-07T10:46:09.000Z - 2017-07-07T11:12:51.000Z" + # puts "2017-06-25 17:30:00 UTC 2017-07-02 17:29:59 UTC" +# puts params[:shift_name] +# puts from.utc +# puts to.utc if params[:shift_name].to_i != 0 - @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at =?',from,to).take - puts @shift.to_json - @sale_data = Sale.where('shift_sale_id = ? ',@shift.id) - @sale_taxes = Sale.get_separate_tax(from,to) + @shift = ShiftSale.where('shift_started_at >= ? and shift_closed_at <= ?',from,to).take + # puts @shift.to_json + if @shift.present? + @sale_data = Sale.where('shift_sale_id = ? ',@shift.id) + @sale_taxes = Sale.get_separate_tax(from,to) + end else @sale_data = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from.utc,to.utc) @sale_taxes = Sale.get_separate_tax(from.utc,to.utc) diff --git a/app/models/sale.rb b/app/models/sale.rb index 36ca6f31..2ffa5afd 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -583,7 +583,7 @@ def self.get_by_shift_sale(from,to,status) " grand_total AS grand_total, cash_sales AS cash," + "total_taxes AS total_tax,total_discounts As total_discount") .order("shift_sales.id DESC") - return query = query.where("shift_sales.shift_started_at between ? and ?" + " or shift_sales.shift_closed_at between ? and ?",from,to ,from,to ) + return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to) end def self.get_separate_tax(from,to,payment_type=nil) diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb index cf04c5aa..aa117624 100644 --- a/app/views/reports/receipt_no/index.html.erb +++ b/app/views/reports/receipt_no/index.html.erb @@ -61,7 +61,9 @@ <% total_nett = 0 %> <% rounding_adj = 0%> <% gov_tax = 0 %> <% service_charge = 0 %> - <% @sale_data.each do |result| %> + <% + if @sale_data!=nil + @sale_data.each do |result| %> <% grand_total = grand_total.to_f + result.grand_total.to_f %> <% total_tax += result.total_tax.to_f %> @@ -83,7 +85,10 @@ <%= result.grand_total_after_rounding() rescue '-'%> - <% end %> + <% + end + end + %>   <%= total_sum rescue '-'%>