diff --git a/app/frontend/src/javascript/components/events/event-reservation-item.tsx b/app/frontend/src/javascript/components/events/event-reservation-item.tsx index b186fd508..7075c367d 100644 --- a/app/frontend/src/javascript/components/events/event-reservation-item.tsx +++ b/app/frontend/src/javascript/components/events/event-reservation-item.tsx @@ -47,15 +47,15 @@ export const EventReservationItem: React.FC = ({ rese const preRegistrationStatus = () => { if (!_.isBoolean(reservation.is_valid) && !reservation.canceled_at && !reservation.is_paid) { return t('app.logged.event_reservation_item.in_the_process_of_validation'); - } else if (reservation.is_valid && !reservation.canceled_at && !reservation.is_paid && reservation.reservable.amount !== 0) { + } else if (reservation.is_valid && !reservation.canceled_at && !reservation.is_paid && reservation.amount !== 0) { return t('app.logged.event_reservation_item.settle_your_payment'); - } else if (reservation.is_valid && !reservation.canceled_at && !reservation.is_paid && reservation.reservable.amount === 0) { + } else if (reservation.is_valid && !reservation.canceled_at && !reservation.is_paid && reservation.amount === 0) { return t('app.logged.event_reservation_item.registered'); } else if (!reservation.is_valid && !reservation.canceled_at) { return t('app.logged.event_reservation_item.not_validated'); - } else if (reservation.is_paid && !reservation.canceled_at && reservation.reservable.amount !== 0) { + } else if (reservation.is_paid && !reservation.canceled_at && reservation.amount !== 0) { return t('app.logged.event_reservation_item.paid'); - } else if (reservation.is_paid && !reservation.canceled_at && reservation.reservable.amount === 0) { + } else if (reservation.is_paid && !reservation.canceled_at && reservation.amount === 0) { return t('app.logged.event_reservation_item.present'); } else if (reservation.canceled_at) { return t('app.logged.event_reservation_item.canceled'); diff --git a/app/frontend/src/javascript/controllers/admin/events.js b/app/frontend/src/javascript/controllers/admin/events.js index de6c414bf..420097e01 100644 --- a/app/frontend/src/javascript/controllers/admin/events.js +++ b/app/frontend/src/javascript/controllers/admin/events.js @@ -460,10 +460,35 @@ Application.Controllers.controller('ShowEventReservationsController', ['$scope', $scope.isValidated = function (reservation) { return reservation.slots_reservations_attributes[0].is_valid === true || reservation.slots_reservations_attributes[0].is_valid === 'true'; }; + + /** + * Test if the provided reservation has been invalidated + * @param reservation {Reservation} + * @returns {boolean} + */ $scope.isInvalidated = function (reservation) { return reservation.slots_reservations_attributes[0].is_valid === false || reservation.slots_reservations_attributes[0].is_valid === 'false'; }; + /** + * Get the price of a reservation + * @param reservation {Reservation} + */ + $scope.reservationAmount = function (reservation) { + let amount = 0; + for (const user of reservation.booking_users_attributes) { + if (user.event_price_category_id) { + const price_category = _.find($scope.event.event_price_categories_attributes, { id: user.event_price_category_id }); + if (price_category) { + amount += price_category.amount; + } + } else { + amount += $scope.event.amount; + } + } + return amount; + }; + /** * Callback to validate a reservation * @param reservation {Reservation} @@ -628,7 +653,7 @@ Application.Controllers.controller('ShowEventReservationsController', ['$scope', if (r.id === reservation.id) { return reservation; } - if ($scope.event.amount === 0) { + if ($scope.reservationAmount(reservation) === 0) { growl.success(_t('app.admin.event_reservations.reservation_was_successfully_present')); } else { growl.success(_t('app.admin.event_reservations.reservation_was_successfully_paid')); diff --git a/app/frontend/src/javascript/models/reservation.ts b/app/frontend/src/javascript/models/reservation.ts index dca86afa8..3c6eb0a6a 100644 --- a/app/frontend/src/javascript/models/reservation.ts +++ b/app/frontend/src/javascript/models/reservation.ts @@ -70,10 +70,11 @@ export interface Reservation { end_at: TDateISO, event_type?: string, event_title?: string, - event_pre_registration?: boolean + event_pre_registration?: boolean, canceled_at?: TDateISO, is_valid?: boolean, is_paid?: boolean, + amount?: number } export interface ReservationIndexFilter extends ApiFilter { diff --git a/app/frontend/templates/admin/events/pay_reservation_modal.html b/app/frontend/templates/admin/events/pay_reservation_modal.html index c1866fe17..b4059d18f 100644 --- a/app/frontend/templates/admin/events/pay_reservation_modal.html +++ b/app/frontend/templates/admin/events/pay_reservation_modal.html @@ -1,10 +1,10 @@