diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index f7d637d6..d009ed90 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -1,6 +1,5 @@ class Origami::SurveysController < BaseOrigamiController def new - @survey = Survey.new @id = params[:id] if(@id[0,3] == "SAL") @@ -10,25 +9,50 @@ class Origami::SurveysController < BaseOrigamiController @booking = Booking.find_by_sale_id(@id) @dining_facility = DiningFacility.find(@booking.dining_facility_id) @table_type = @dining_facility.type + @survey = Survey.new() + # @survey = Survey.find_by_dining_name_and_receipt_no(@dining_facility.name, @receipt_no) else @dining_facility = DiningFacility.find(@id) @table_type = @dining_facility.type @receipt_no = nil @grand_total = nil + @survey = Survey.find_by_dining_name(@dining_facility.name) 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 + cashier_zone = CashierTerminalByZone.find_by_zone_id(@dining_facility.zone_id) + shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) + + if request.post? + @survey = Survey.new(survey_params) + @survey.shift_id = shift_by_terminal.id + @survey.foreigner = params["survey"]["foreigner"].to_json + # respond_to do |format| + if @survey.save + redirect_to @url + end + # end + else + survey = Survey.find_by_id(params[:survey_id]) + survey.child = params["survey"]["child"] + survey.adult = params["survey"]["adult"] + survey.male = params["survey"]["male"] + survey.female = params["survey"]["female"] + survey.local = params["survey"]["local"] + survey.dining_name = params["survey"]["dining_name"] + survey.receipt_no = params["survey"]["receipt_no"] + survey.shift_id = shift_by_terminal.id + survey.created_by = params["survey"]["created_by"] + survey.total_customer = params["survey"]["total_customer"] + survey.total_amount = params["survey"]["total_amount"] + survey.foreigner = params["survey"]["foreigner"].to_json + if survey.save! + redirect_to @url + end + end end def create_survey @@ -62,7 +86,7 @@ class Origami::SurveysController < BaseOrigamiController # 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) + params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount,:survey_id) end #Shop Name in Navbor diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 0c047e56..3cff783e 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -578,7 +578,7 @@ $("#survey").on('click', function () { var sale = $('#sale_id').val(); if (sale) { - var sale_id = sale + var sale_id = sale; } else { var sale_id = "<%= @dining.id %>"; } diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index b5e9e8e4..443efea2 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -41,6 +41,7 @@ + <%= f.input :dining_name, :as => :hidden, :input_html => { :value => @dining_facility.name } %> <%= f.input :created_by, :as => :hidden, :input_html => { :value => current_login_employee.name } %> diff --git a/config/routes.rb b/config/routes.rb index 0b21460f..3442997f 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -193,7 +193,7 @@ scope "(:locale)", locale: /en|mm/ do post '/:sale_id/get_customer' => "customers#get_customer" get '/:id/surveys', to: "surveys#new" - post '/:id/create_survey' => "surveys#create", :as => "create_surveys" + match '/:id/create_survey', to: "surveys#create", as: "create_surveys", via: [:post, :patch, :put] get '/addorders/get_menu_category/:id' => "addorders#get_menu_category",:as => "get_menu_category", :defaults => { :format => 'json' } get '/addorders/get_menu_sub_category/:id' => "addorders#get_menu_sub_category",:as => "get_menu_sub_category", :defaults => { :format => 'json' }