diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index d009ed90..b49359e0 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -1,6 +1,7 @@ class Origami::SurveysController < BaseOrigamiController def new - @id = params[:id] + @survey = Survey.new() + @id = params[:id] if(@id[0,3] == "SAL") @sale = Sale.find(@id) @@ -9,14 +10,17 @@ 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) + @survey_data = Survey.find_by_dining_name(@dining_facility.name) + survey_process = Survey.find_by_receipt_no(@receipt_no) + if !survey_process.nil? + @survey_data = survey_process + end 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) + @survey_data = Survey.find_by_dining_name(@dining_facility.name) end end @@ -25,8 +29,8 @@ class Origami::SurveysController < BaseOrigamiController @url = "/origami/"+@dining_facility.type.downcase+"/"+params[:table_id] 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? + + if params[:survey_id].nil? || params[:survey_id] == "" @survey = Survey.new(survey_params) @survey.shift_id = shift_by_terminal.id @survey.foreigner = params["survey"]["foreigner"].to_json @@ -61,7 +65,7 @@ class Origami::SurveysController < BaseOrigamiController 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) - survey = Survey.find_by_receipt_no(params[:receipt_no]) + survey = Survey.find_by_dining_name(dining_facility.name) if survey.nil? survey = Survey.new @@ -73,6 +77,7 @@ class Origami::SurveysController < BaseOrigamiController survey.total_amount = params[:total_amount] survey.save! else + survey.receipt_no = params[:receipt_no] survey.total_customer = params[:total_customer] survey.save! end diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index 443efea2..459975ff 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -5,43 +5,79 @@ <%= simple_form_for(@survey, :url => origami_create_surveys_path) do |f| %> <%= f.error_notification %>
+ <% if !@survey_data.nil? %> + <%= f.input :child, input_html: { value: @survey_data.child, class: 'col-md-10' }%> + <%= f.input :adult, input_html: { value: @survey_data.adult, class: 'col-md-10' }%> + <%= f.input :male , input_html: { value: @survey_data.male, class: 'col-md-10' }%> + <%= f.input :female , input_html: { value: @survey_data.female, class: 'col-md-10' }%> + <%= f.input :total_customer, input_html: { value: @survey_data.total_customer, class: 'col-md-10'} %> + <%= f.input :local , input_html: { value: @survey_data.local, class: 'col-md-10' }%> - <%= f.input :child , input_html: { class: 'col-md-10' }%> - <%= f.input :adult , input_html: { class: 'col-md-10' }%> - <%= f.input :male , input_html: { class: 'col-md-10' }%> - <%= f.input :female , input_html: { class: 'col-md-10' }%> - <%= f.input :total_customer, input_html: { class: 'col-md-10'} %> - <%= f.input :local , input_html: { class: 'col-md-10' }%> - -
-
-
- - - +
+
+
+ + + +
-
-
-
- - +
+
+ + +
-
-
-
- +
+
+ +
-
+ <% else %> + <%= f.input :child , input_html: { class: 'col-md-10' }%> + <%= f.input :adult , input_html: { class: 'col-md-10' }%> + <%= f.input :male , input_html: { class: 'col-md-10' }%> + <%= f.input :female , input_html: { class: 'col-md-10' }%> + <%= f.input :total_customer, input_html: { class: 'col-md-10'} %> + <%= f.input :local , input_html: { class: 'col-md-10' }%> + +
+
+
+ + + +
+
+
+
+ + +
+
+
+
+ +
+
+ <% end %> - - + <% if !@survey_data.nil? %> + /> + <% else %> + + <% end %> <%= 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 } %>