From a437fc24ee0d555890ddb420a34ccdce88bd931f Mon Sep 17 00:00:00 2001 From: Du Peng Date: Mon, 26 Jun 2023 19:28:26 +0200 Subject: [PATCH] (wip) admin confirm payment of reservation pre-registration --- .../javascript/controllers/admin/events.js | 67 ++++++++++++++++++- .../admin/events/pay_reservation_modal.html | 18 +++++ .../templates/admin/events/reservations.html | 2 +- app/frontend/templates/events/show.html | 9 ++- .../reservations/_reservation.json.jbuilder | 1 + config/locales/app.admin.en.yml | 2 + config/locales/app.admin.fr.yml | 2 + config/locales/app.public.en.yml | 1 + config/locales/app.public.fr.yml | 1 + 9 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 app/frontend/templates/admin/events/pay_reservation_modal.html diff --git a/app/frontend/src/javascript/controllers/admin/events.js b/app/frontend/src/javascript/controllers/admin/events.js index 5e696df77..cf938866a 100644 --- a/app/frontend/src/javascript/controllers/admin/events.js +++ b/app/frontend/src/javascript/controllers/admin/events.js @@ -436,7 +436,7 @@ Application.Controllers.controller('AdminEventsController', ['$scope', '$state', /** * Controller used in the reservations listing page for a specific event */ -Application.Controllers.controller('ShowEventReservationsController', ['$scope', 'eventPromise', 'reservationsPromise', 'dialogs', 'SlotsReservation', 'growl', '_t', function ($scope, eventPromise, reservationsPromise, dialogs, SlotsReservation, growl, _t) { +Application.Controllers.controller('ShowEventReservationsController', ['$scope', 'eventPromise', 'reservationsPromise', 'dialogs', 'SlotsReservation', 'growl', '_t', 'Price', 'Wallet', '$uibModal', function ($scope, eventPromise, reservationsPromise, dialogs, SlotsReservation, growl, _t, Price, Wallet, $uibModal) { // retrieve the event from the ID provided in the current URL $scope.event = eventPromise; @@ -487,6 +487,71 @@ Application.Controllers.controller('ShowEventReservationsController', ['$scope', }); }); }; + + const mkCartItems = function (reservation, coupon) { + return { + customer_id: reservation.user_id, + items: [{ + reservation: { + ...reservation, + slots_reservations_attributes: reservation.slots_reservations_attributes.map(sr => ({ slot_id: sr.slot_id })) + } + }], + coupon_code: ((coupon ? coupon.code : undefined)), + payment_method: '' + }; + }; + + $scope.payReservation = function (reservation) { + $uibModal.open({ + templateUrl: '/admin/events/pay_reservation_modal.html', + size: 'sm', + resolve: { + reservation () { + return reservation; + }, + price () { + return Price.compute(mkCartItems(reservation)).$promise; + }, + wallet () { + return Wallet.getWalletByUser({ user_id: reservation.user_id }).$promise; + }, + cartItems () { + return mkCartItems(reservation); + } + }, + controller: ['$scope', '$uibModalInstance', 'reservation', 'price', 'wallet', 'cartItems', 'helpers', '$filter', '_t', + function ($scope, $uibModalInstance, reservation, price, wallet, cartItems, helpers, $filter, _t) { + // User's wallet amount + $scope.wallet = wallet; + + // Price + $scope.price = price.price; + + // Cart items + $scope.cartItems = cartItems; + + // price to pay + $scope.amount = helpers.getAmountToPay(price.price, wallet.amount); + + // Reservation + $scope.reservation = reservation; + + $scope.coupon = { applied: null }; + + // Button label + if ($scope.amount > 0) { + $scope.validButtonName = _t('app.admin.event_reservations.confirm_payment_of_html', { ROLE: $scope.currentUser.role, AMOUNT: $filter('currency')($scope.amount) }); + } else { + if ((price.price > 0) && ($scope.walletAmount === 0)) { + $scope.validButtonName = _t('app.admin.event_reservations.confirm_payment_of_html', { ROLE: $scope.currentUser.role, AMOUNT: $filter('currency')(price.price) }); + } else { + $scope.validButtonName = _t('app.shared.buttons.confirm'); + } + } + }] + }); + }; }]); /** diff --git a/app/frontend/templates/admin/events/pay_reservation_modal.html b/app/frontend/templates/admin/events/pay_reservation_modal.html new file mode 100644 index 000000000..3b92cae4e --- /dev/null +++ b/app/frontend/templates/admin/events/pay_reservation_modal.html @@ -0,0 +1,18 @@ + + + diff --git a/app/frontend/templates/admin/events/reservations.html b/app/frontend/templates/admin/events/reservations.html index 53e25a458..c44167264 100644 --- a/app/frontend/templates/admin/events/reservations.html +++ b/app/frontend/templates/admin/events/reservations.html @@ -55,7 +55,7 @@ - diff --git a/app/frontend/templates/events/show.html b/app/frontend/templates/events/show.html index 4d665f1e7..421ec4aa6 100644 --- a/app/frontend/templates/events/show.html +++ b/app/frontend/templates/events/show.html @@ -195,7 +195,7 @@ -
+
{{ 'app.shared.buttons.cancel' }}
-
{{ 'app.public.events_show.thank_you_your_payment_has_been_successfully_registered' | translate }}
+
{{ 'app.public.events_show.thank_you_your_payment_has_been_successfully_registered' | translate }}
+ {{ 'app.public.events_show.you_can_find_your_reservation_s_details_on_your_' | translate }} {{ 'app.public.events_show.dashboard' }} +
+
{{ 'app.public.events_show.thank_you_your_pre_registration_has_been_successfully_saved' | translate }}
{{ 'app.public.events_show.you_can_find_your_reservation_s_details_on_your_' | translate }} {{ 'app.public.events_show.dashboard' }}
@@ -257,7 +260,7 @@

- +
diff --git a/app/views/api/reservations/_reservation.json.jbuilder b/app/views/api/reservations/_reservation.json.jbuilder index 78558e924..8e91cc028 100644 --- a/app/views/api/reservations/_reservation.json.jbuilder +++ b/app/views/api/reservations/_reservation.json.jbuilder @@ -8,6 +8,7 @@ json.slots_reservations_attributes reservation.slots_reservations do |sr| json.id sr.id json.canceled_at sr.canceled_at&.iso8601 json.validated_at sr.validated_at&.iso8601 + json.slot_id sr.slot_id json.slot_attributes do json.id sr.slot_id json.start_at sr.slot.start_at.iso8601 diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 1341e26a1..68aceeacd 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -651,6 +651,8 @@ en: do_you_really_want_to_validate_this_reservation_this_apply_to_all_booked_tickets: "Do you really want to validate this reservation? This apply to ALL booked tickets." reservation_was_successfully_validated: "Reservation was successfully validated." validation_failed: "Validation failed." + confirm_payment: "Confirm payment" + confirm_payment_of_html: "{ROLE, select, admin{Cash} other{Pay}}: {AMOUNT}" #(contexte : validate a payment of $20,00) events_settings: title: "Settings" generic_text_block: "Editorial text block" diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index bcd882cef..467002598 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -651,6 +651,8 @@ fr: do_you_really_want_to_validate_this_reservation_this_apply_to_all_booked_tickets: "Êtes vous sur de vouloir valider cette réservation? Ceci s'applique à TOUTES les places réservées." reservation_was_successfully_validated: "La réservation a bien été validé." validation_failed: "La validation a échoué." + confirm_payment: "Confirmer le paiement" + confirm_payment_of_html: "{ROLE, select, admin{Encaisser} other{Payer}} : {AMOUNT}" #(contexte : validate a payment of $20,00) events_settings: title: "Paramètres" generic_text_block: "Bloc de texte rédactionnel" diff --git a/config/locales/app.public.en.yml b/config/locales/app.public.en.yml index 5771815b7..21c7a0b25 100644 --- a/config/locales/app.public.en.yml +++ b/config/locales/app.public.en.yml @@ -330,6 +330,7 @@ en: ticket: "{NUMBER, plural, one{ticket} other{tickets}}" make_a_gift_of_this_reservation: "Make a gift of this reservation" thank_you_your_payment_has_been_successfully_registered: "Thank you. Your payment has been successfully registered!" + thank_you_your_pre_registration_has_been_successfully_saved: "Thank you. Your pre-registration has been successfully saved!" 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}):" diff --git a/config/locales/app.public.fr.yml b/config/locales/app.public.fr.yml index 15f85a659..580a75f8a 100644 --- a/config/locales/app.public.fr.yml +++ b/config/locales/app.public.fr.yml @@ -330,6 +330,7 @@ fr: ticket: "{NUMBER, plural, =0{place} one{place} other{places}}" make_a_gift_of_this_reservation: "Offrir cette réservation" thank_you_your_payment_has_been_successfully_registered: "Merci. Votre paiement a bien été pris en compte !" + thank_you_your_pre_registration_has_been_successfully_saved: "Merci. Votre pré-inscription a bien été pris en compte !" 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}) :"