From 94e839f647cad9937012905918574dc2a7d4b6c2 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Wed, 14 Jun 2023 18:21:08 +0200 Subject: [PATCH] (feat) pre-book a event --- .../src/javascript/controllers/events.js.erb | 7 +++++- app/frontend/templates/events/show.html | 10 ++++++-- app/models/shopping_cart.rb | 25 +++++++++++++------ app/views/api/events/_event.json.jbuilder | 1 + app/views/api/invoices/_invoice.json.jbuilder | 4 +-- config/locales/app.public.en.yml | 3 +++ config/locales/app.public.fr.yml | 3 +++ 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/app/frontend/src/javascript/controllers/events.js.erb b/app/frontend/src/javascript/controllers/events.js.erb index 0c7a86483..7b983f7cb 100644 --- a/app/frontend/src/javascript/controllers/events.js.erb +++ b/app/frontend/src/javascript/controllers/events.js.erb @@ -298,10 +298,15 @@ Application.Controllers.controller('ShowEventController', ['$scope', '$state', ' }; $scope.isShowReserveEventButton = () => { - return $scope.event.nb_free_places > 0 && + const bookable = $scope.event.nb_free_places > 0 && !$scope.reserve.toReserve && $scope.now.isBefore($scope.eventEndDateTime) && helpers.isUserValidatedByType($scope.ctrl.member, $scope.settings, 'event'); + if ($scope.event.pre_registration) { + return bookable && $scope.event.pre_registration_end_date && $scope.now.isSameOrBefore($scope.event.pre_registration_end_date, 'day'); + } else { + return bookable; + } }; /** diff --git a/app/frontend/templates/events/show.html b/app/frontend/templates/events/show.html index 6a3c9652e..4d665f1e7 100644 --- a/app/frontend/templates/events/show.html +++ b/app/frontend/templates/events/show.html @@ -89,6 +89,8 @@
{{ 'app.public.events_show.opening_hours' | translate }}
{{ 'app.public.events_show.all_day' }}
{{ 'app.public.events_show.from_time' | translate }} {{event.start_time}} {{ 'app.public.events_show.to_time' | translate }} {{event.end_time}}
+
{{ 'app.public.events_show.pre_registration_end_date' | translate }}
+
{{ 'app.public.events_show.ending' | translate }} {{event.pre_registration_end_date | amDateFormat:'L'}}
@@ -220,7 +222,8 @@
-
{{ 'app.public.events_show.you_booked_DATE' | translate:{DATE:(reservation.created_at | amDateFormat:'L LT')} }}
+
{{ 'app.public.events_show.you_booked_DATE' | translate:{DATE:(reservation.created_at | amDateFormat:'L LT')} }}
+
{{ 'app.public.events_show.you_pre_booked_DATE' | translate:{DATE:(reservation.created_at | amDateFormat:'L LT')} }}
{{ 'app.public.events_show.full_price_' | translate }} {{reservation.nb_reserve_places}} {{ 'app.public.events_show.ticket' | translate:{NUMBER:reservation.nb_reserve_places} }}
{{ticket.event_price_category.price_category.name}} : {{ticket.booked}} {{ 'app.public.events_show.ticket' | translate:{NUMBER:ticket.booked} }} @@ -243,7 +246,10 @@ {{ 'app.public.events_show.thanks_for_coming' }} {{ 'app.public.events_show.view_event_list' }}
- +

diff --git a/app/models/shopping_cart.rb b/app/models/shopping_cart.rb index 31ed97e43..c9716fcdb 100644 --- a/app/models/shopping_cart.rb +++ b/app/models/shopping_cart.rb @@ -60,15 +60,26 @@ class ShoppingCart items.each do |item| objects.push(save_item(item)) end - update_credits(objects) - update_packs(objects) + event_reservation = objects.find { |o| o.is_a?(Reservation) && o.reservable_type == 'Event' } + if event_reservation&.reservable&.pre_registration + payment = Invoice.new( + invoicing_profile: @customer.invoicing_profile, + statistic_profile: @customer.statistic_profile, + operator_profile_id: @operator.invoicing_profile.id, + payment_method: @payment_method, + total: 0 + ) + else + update_credits(objects) + update_packs(objects) - payment = create_payment_document(price, objects, payment_id, payment_type) - WalletService.debit_user_wallet(payment, @customer) - next if Setting.get('prevent_invoices_zero') && price[:total].zero? + payment = create_payment_document(price, objects, payment_id, payment_type) + WalletService.debit_user_wallet(payment, @customer) + next if Setting.get('prevent_invoices_zero') && price[:total].zero? - payment.save - payment.post_save(payment_id, payment_type) + payment.save + payment.post_save(payment_id, payment_type) + end end success = !payment.nil? && objects.map(&:errors).flatten.map(&:empty?).all? && items.map(&:errors).map(&:blank?).all? diff --git a/app/views/api/events/_event.json.jbuilder b/app/views/api/events/_event.json.jbuilder index 1504914b1..2ab9cab33 100644 --- a/app/views/api/events/_event.json.jbuilder +++ b/app/views/api/events/_event.json.jbuilder @@ -1,6 +1,7 @@ # frozen_string_literal: true json.extract! event, :id, :title, :description, :event_type, :pre_registration, :pre_registration_end_date +json.pre_registration_end_date event.pre_registration_end_date&.to_date if event.event_image json.event_image_attributes do json.id event.event_image.id diff --git a/app/views/api/invoices/_invoice.json.jbuilder b/app/views/api/invoices/_invoice.json.jbuilder index 4ac46da9d..00754b59a 100644 --- a/app/views/api/invoices/_invoice.json.jbuilder +++ b/app/views/api/invoices/_invoice.json.jbuilder @@ -11,8 +11,8 @@ json.is_online_card invoice.paid_by_card? json.date invoice.is_a?(Avoir) ? invoice.avoir_date : invoice.created_at json.chained_footprint invoice.check_footprint json.main_object do - json.type invoice.invoice_items.find(&:main).object_type - json.id invoice.invoice_items.find(&:main).object_id + json.type invoice.invoice_items.find(&:main)&.object_type + json.id invoice.invoice_items.find(&:main)&.object_id end json.items invoice.invoice_items do |item| json.id item.id diff --git a/config/locales/app.public.en.yml b/config/locales/app.public.en.yml index 99d6d0f84..dc214f537 100644 --- a/config/locales/app.public.en.yml +++ b/config/locales/app.public.en.yml @@ -339,6 +339,7 @@ en: you_can_find_your_reservation_s_details_on_your_: "You can find your reservation's details on your" dashboard: "dashboard" you_booked_DATE: "You booked ({DATE}):" + you_pre_booked_DATE: "You pre-booked ({DATE}):" canceled_reservation_SEATS: "Reservation canceled ({SEATS} seats)" book: "Book" confirm_and_pay: "Confirm and pay" @@ -367,6 +368,8 @@ en: share_on_facebook: "Share on Facebook" share_on_twitter: "Share on Twitter" last_name_and_first_name: "Last name and first name" + pre_book: "Pre-book" + pre_registration_end_date: "Pre-registration end date" #public calendar calendar: calendar: "Calendar" diff --git a/config/locales/app.public.fr.yml b/config/locales/app.public.fr.yml index 9a4c93af9..0a876d9ca 100644 --- a/config/locales/app.public.fr.yml +++ b/config/locales/app.public.fr.yml @@ -339,6 +339,7 @@ fr: you_can_find_your_reservation_s_details_on_your_: "Vous pouvez retrouver le détail de votre réservation sur votre" dashboard: "tableau de bord" you_booked_DATE: "Vous avez réservé ({DATE}) :" + you_pre_booked_DATE: "Vous avez pré-réservé ({DATE}) :" canceled_reservation_SEATS: "Réservation annulée ({SEATS} places)" book: "Réserver" confirm_and_pay: "Valider et payer" @@ -367,6 +368,8 @@ fr: share_on_facebook: "Partager sur Facebook" share_on_twitter: "Partager sur Twitter" last_name_and_first_name: "Nom et prénom" + pre_book: "Pré-réserver" + pre_registration_end_date: "Date de fin de pré-réservation" #public calendar calendar: calendar: "Calendrier"