class Oqs::PrintController < ApplicationController
  # Print Order Item
  def print
  	unique_code="OrderItemPdf"
  	assigned_item_id = params[:id]
    options = params[:options]
    assigned_item = AssignedOrderItem.find(assigned_item_id)  	
    assigned_items = AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'");

    # order queue stations
    oqs = assigned_item.order_queue_station

    # Check Printed
    print_status = assigned_item.print_status == true ? " (Re-Print)" : ""

    # print when complete click 
  	print_settings = PrintSetting.find_by_unique_code(unique_code)
    order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
  	order_queue_printer.print_order_item(print_settings,oqs, assigned_item.order_id, assigned_item.item_code, print_status, options )
  	
    # update print status for completed same order items
    assigned_items.each do |ai|
      ai.print_status=true
      ai.save       
    end                 
  end

  # Print Order Details with booking id
  def print_order_summary
    unique_code="OrderSummaryPdf"
    assigned_item_id = params[:id]
    table_name = params[:table_name]
    assigned_item = AssignedOrderItem.find(assigned_item_id)    
    assigned_items = AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'");

    # order queue stations
    oqs = assigned_item.order_queue_station

    # Check Printed
    print_status = assigned_item.print_status == true ? " (Re-Print)" : ""

    # get dining
    dining = DiningFacility.find_by_name(table_name);
    booking = Booking.find_by_dining_facility_id(dining.id)
    
    # print when complete click 
    print_settings = PrintSetting.find_by_unique_code(unique_code)
    order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
    order_queue_printer.print_booking_summary(print_settings,oqs, booking.booking_id, print_status)

     # update print status for completed same order items
    assigned_items.each do |ai|
      ai.print_status = true
      ai.save       
    end              
  end
end
