55 lines
1.8 KiB
Ruby
55 lines
1.8 KiB
Ruby
class Api::SurveyController < Api::ApiController
|
|
|
|
# before_action :authenticate
|
|
|
|
def index
|
|
dining_facility = DiningFacility.find(params[:id])
|
|
survey_data = Survey.find_by_dining_name(dining_facility.name)
|
|
countries = Lookup.collection_of("country")
|
|
if !countries.nil? || !survey_data.nil?
|
|
render :json => { :status => true, :data => { :countries => countries, :survey_data => survey_data} }
|
|
else
|
|
render :json => { :status => true, :error_message => "There is no data" }
|
|
end
|
|
end
|
|
|
|
def create
|
|
dining_facility = DiningFacility.find(params[:id])
|
|
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
|
current_shift = ShiftSale.current_shift(Shop.current_shop.shop_code)
|
|
current_shift_user =Employee.find_by_id(current_shift.employee_id)
|
|
if open_cashier.count>0
|
|
shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0])
|
|
else
|
|
shift_by_terminal = ShiftSale.current_open_shift(current_shift_user)
|
|
end
|
|
|
|
if params[:survey][:id]>0
|
|
survey = Survey.find(params[:survey][:id])
|
|
else
|
|
survey = Survey.new
|
|
end
|
|
survey.dining_name = dining_facility.name
|
|
survey.shift_id = shift_by_terminal.id
|
|
survey.child = params[:child]
|
|
survey.adult = params[:adult]
|
|
survey.male = params[:male]
|
|
survey.female = params[:female]
|
|
survey.local = params[:local]
|
|
survey.created_by = current_login_employee.name
|
|
survey.total_customer = params[:total_customer]
|
|
survey.total_amount = params[:total_amount]
|
|
survey.foreigner = params[:foreigner].to_json
|
|
survey.save!
|
|
|
|
render :json => { :status => true }
|
|
end
|
|
|
|
# private
|
|
# def survey_params
|
|
# params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner,
|
|
# :dining_name,:created_by,:total_customer,:total_amount)
|
|
# end
|
|
|
|
end
|