class Api::BillController < Api::ApiController #Create invoice based on booking #Output and invoice def create @status = false @error_message = "Order ID or Booking ID is require to request for a bill." #create Bill by Booking ID if (params[:booking_id]) booking = Booking.find(params[:booking_id]) if booking if booking.sale_id.nil? @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee) else @status = true @sale_id = booking.sale_id end end elsif (params[:order_id]) @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee) end @sale_data = Sale.find_by_sale_id(@sale_id) @sale_items = SaleItem.where("sale_id=?",@sale_id) unique_code = "ReceiptBillPdf" customer= Customer.where('customer_id=' + @sale_data.customer_id) # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) # Calculate Food and Beverage Total food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items) printer = Printer::ReceiptPrinter.new(print_settings) printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total) end private def bill_params params.permit(:booking_id, :order_id) end end