class Origami::PendingOrderController < BaseOrigamiController
  def index
    # @dining= DiningFacility.where("status = 'occupied'")
    # @order = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status = 'billed' and source = 'quick_service'",DateTime.now.strftime('%Y-%m-%d'))
    @sale = Sale.pending_sale
    @order = Sale.pending_order
    @completed = Sale.completed_sale
  end
  def show
    @sales  = Sale.pending_sale
    @orders = Sale.pending_order
    @completed = Sale.completed_sale
    @id     = params[:sale_id]
    if(@id[0,3] == "SAL")     
      @sale = Sale.find(@id)
      @order = SaleOrder.find_by_sale_id(@sale.sale_id).order_id
      @booking = BookingOrder.find_by_order_id(@order).booking_id
      @bookings = Booking.find(@booking)
      @status = "sale"
    else
      # @booking = BookingOrder.find_by_order_id(@order).booking_id
      @bookings = Booking.find(@id)
      @status = "order"

      @order_items = Array.new
      @bookings.booking_orders.each do |booking_order|
        @order = Order.find(booking_order.order_id)
        if (@order.status == "new")
          @order.order_items.each do |item|
            @order_items.push(item)
          end
        end
      end
    end
    puts @status
    if @bookings.dining_facility_id.to_i > 0
      @table_id = Booking.find(@bookings.booking_id).dining_facility_id
      @dining  = DiningFacility.find(@table_id)
    else
      @table_id = nil
      @dining  = nil
    end

  end

  def completed_sale
    @sales     = Sale.pending_sale
    @orders    = Sale.pending_order
    @completed = Sale.completed_sale
    @id        = params[:sale_id]
     
    @sale      = Sale.find(@id)
    @order     = SaleOrder.find_by_sale_id(@sale.sale_id).order_id
    @booking   = BookingOrder.find_by_order_id(@order).booking_id
    @bookings  = Booking.find(@booking)
    @status    = "sale"
    
    if @bookings.dining_facility_id.to_i > 0
      @table_id = Booking.find(@bookings.booking_id).dining_facility_id
      @dining  = DiningFacility.find(@table_id)
    else
      @table_id = nil
      @dining  = nil
    end
  end

  def cash_ins
    render "origami/cash_ins/new"
  end
  def cash_outs
    render "origami/cash_outs/new"
  end

end
