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 @@ +
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' %> +