class Origami::RoomsController < BaseOrigamiController
  def index
    @tables = Table.all.active.order('status desc')
    @rooms = Room.all.active.order('status desc')
    @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d'))
    @orders = Order.all.order('date desc')
    # @shift = ShiftSale.current_open_shift(current_user.id)
  end

  def show
    @tables = Table.all.active.order('status desc')
    @rooms = Room.all.active.order('status desc')
    @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d'))
    @orders = Order.all.order('date desc')

    @room = DiningFacility.find(params[:room_id])

    @status_order = ""
    @status_sale = ""
    @sale_array = Array.new

    @shop =  Shop::ShopDetail
    @membership = MembershipSetting::MembershipSetting
    @payment_methods = PaymentMethodSetting.all
    
    @room.bookings.active.each do |booking|
         if booking.sale_id.nil? && booking.booking_status != 'moved'
           @order_items = Array.new
           booking.booking_orders.each do |booking_order|
              order = Order.find(booking_order.order_id)
              @customer = order.customer
              if (order.status == "new")
                @obj_order = order
                
                @date = order.created_at
                @booking = booking
                order.order_items.each do |item|
                  @order_items.push(item)
                end
              end
           end
           @status_order = 'order'
         else
          sale = Sale.find(booking.sale_id)
           if sale.sale_status != "completed" && sale.sale_status != 'void'
             puts "enter"
             @sale_array.push(sale)
             if @status_order == 'order'
               @status_order = 'sale'
             end
             @booking = booking
             @date = sale.created_at
             @status_sale = 'sale'
             @obj_sale = sale
             @customer = sale.customer
           end
         end
     end

    # @room.bookings.each do |booking|
    #      if booking.sale_id.nil?
    #        @order_items = Array.new
           
    #        booking.booking_orders.each do |booking_order|
    #           order = Order.find(booking_order.order_id)
    #           @obj = order
    #           @customer = order.customer
    #           order.order_items.each do |item|
    #             @order_items.push(item)
    #           end
    #        end
    #        @status = 'order'
    #      else

    #       sale = Sale.find(booking.sale_id)
    #        if sale.sale_status != "completed"
    #         @sale_array.push(sale)
    #          @status = 'sale'
    #          @obj = sale
    #          @customer = sale.customer
    #        end
    #      end
    # end
  end


end
