diff --git a/app/controllers/spree/admin/guests_controller.rb b/app/controllers/spree/admin/guests_controller.rb index e76ae98a6..980ddbdf5 100644 --- a/app/controllers/spree/admin/guests_controller.rb +++ b/app/controllers/spree/admin/guests_controller.rb @@ -5,6 +5,7 @@ class GuestsController < Spree::Admin::ResourceController helper SpreeCmCommissioner::Admin::GuestHelper before_action :load_order + before_action :load_guest, only: %i[check_in uncheck_in] def model_class SpreeCmCommissioner::Guest @@ -42,14 +43,51 @@ def new def edit @kyc_fields = @object.line_item.kyc_fields + @check_in = @object.check_in end + def check_in + result = SpreeCmCommissioner::CheckInBulkCreator.call( + check_ins_attributes: [{ guest_id: @guest.id }], + check_in_by: spree_current_user + ) + + if result.success? + flash[:success] = "Guest #{@guest.full_name} has been checked in." + else + flash[:error] = result.message.to_s.titleize + end + + redirect_to collection_url + end + + def uncheck_in + result = SpreeCmCommissioner::CheckInDestroyer.call( + guest_ids: [@guest.id], + destroyed_by: spree_current_user + ) + + if result.success? + flash[:success] = "Guest #{@guest.full_name} has been unchecked." + else + flash[:error] = result.message.to_s.titleize + end + + redirect_to collection_url + end + + private + def permitted_resource_params params.require(object_name).permit(:first_name, :last_name, :gender, :dob, :occupation_id, :nationality_id, :age, :emergency_contact, :line_item_id, :seat_number, :phone_number ) end + + def load_guest + @guest = @order.guests.find(params[:id]) + end end end end diff --git a/app/views/spree/admin/guests/_check_in_status.html.erb b/app/views/spree/admin/guests/_check_in_status.html.erb new file mode 100644 index 000000000..6eb8ba42d --- /dev/null +++ b/app/views/spree/admin/guests/_check_in_status.html.erb @@ -0,0 +1,50 @@ +
+
+

<%= Spree.t(:check_in_states) %>

+
+ <% if @check_in.present? %> + + + + + <% else %> +
+ <%= Spree.t(:no_check_in_found) %> +
+ <% end %> +
diff --git a/app/views/spree/admin/guests/edit.html.erb b/app/views/spree/admin/guests/edit.html.erb index c715fc7dc..078398252 100644 --- a/app/views/spree/admin/guests/edit.html.erb +++ b/app/views/spree/admin/guests/edit.html.erb @@ -1,8 +1,43 @@ <% content_for :page_title do %> -<%= link_to plural_resource_name(SpreeCmCommissioner::Guest), spree.admin_order_guests_url(@order) %> / + <%= link_to plural_resource_name(SpreeCmCommissioner::Guest), spree.admin_order_guests_url(@order) %> / <%= Spree.t(:guest_infomation) %> <% end %> +<% content_for(:sidebar) do %> + <% if @object.check_in.present? %> + <%= render partial: 'check_in_status' %> + <% else %> +
+
+
<%= Spree.t(:check_in_status) %>
+

Click button below to manually check_in guest

+ <%= link_to 'Check In', check_in_admin_order_guest_path(@order, @object), method: :post, class: 'btn btn-outline-primary' %> +
+
+ <% end %> +<% end %> + + + + <%= form_with model: @object, url: { action: 'update' }, html: { multipart: true } do |f| %>
<%= render partial: 'form', locals: { f: f } %> diff --git a/config/routes.rb b/config/routes.rb index 9c1157e77..e26ae3cf4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -240,6 +240,10 @@ post :add_guest delete :remove_guest end + member do + post :check_in + post :uncheck_in + end end end