class Transactions::OrdersController < ApplicationController
	load_and_authorize_resource except: [:create]
	def index

		filter = params[:filter]
		from   = params[:from]
		to     = params[:to]

		if filter.nil? && from.nil? && to.nil?
		    orders = Order.order("order_id desc")
		else
		    orders = Order.search(filter,from,to)
		end    
		    
		if !orders.nil?
			@orders = Kaminari.paginate_array(orders).page(params[:page]).per(20)
		else
			@orders = []
		end

		@receipt_no = filter
    	@from       = from
    	@to         = to
		
		respond_to do |format|
			format.html # index.html.erb
			format.json { render json: @orders }
		end
	end
	
	def show

	    @order = Order.find(params[:id])
	    @dining = BookingOrder.find_by_order_id(@order.order_id).booking.dining_facility
	    respond_to do |format|
	      format.html # show.html.erb
	      format.json { render json: @order }
	    end
	end

end
