class Origami::SurveysController < BaseOrigamiController
	def new
		@survey = Survey.new
		@id             = params[:id]

	    if(@id[0,3] == "SAL")
	       @sale             = Sale.find(@id)
	       @receipt_no       = @sale.receipt_no
	       @grand_total      = @sale.grand_total
	       @booking          = Booking.find_by_sale_id(@id)
	       @dining_facility  = DiningFacility.find(@booking.dining_facility_id)
	       @table_type       = @dining_facility.type
	    else
	       @dining_facility  = DiningFacility.find(@id)
	       @table_type       = @dining_facility.type
	       @receipt_no       = nil
	       @grand_total      = nil
	    end 
	end

	def create
		@dining_facility   = DiningFacility.find(params[:table_id])
		@url = "/origami/"+@dining_facility.type.downcase+"/"+params[:table_id]

		@survey = Survey.new(survey_params)
		@survey.foreigner = params["survey"]["foreigner"].to_json
		# respond_to do |format|
		  if @survey.save
		     redirect_to @url
		  end
		# end
	end
	
	private

    # Never trust parameters from the scary internet, only allow the white list through.
    def survey_params
      params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount)
    end
end
