1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(feat) admin cannot validate pre-registration > nb total places

This commit is contained in:
Du Peng 2023-07-12 15:07:14 +02:00
parent a2a970cba4
commit aa6aab48b2
5 changed files with 16 additions and 8 deletions

View File

@ -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', 'Price', 'Wallet', '$uibModal', function ($scope, eventPromise, reservationsPromise, dialogs, SlotsReservation, growl, _t, Price, Wallet, $uibModal) {
Application.Controllers.controller('ShowEventReservationsController', ['$scope', 'eventPromise', 'reservationsPromise', 'dialogs', 'SlotsReservation', 'growl', '_t', 'Price', 'Wallet', '$uibModal', 'Event', function ($scope, eventPromise, reservationsPromise, dialogs, SlotsReservation, growl, _t, Price, Wallet, $uibModal, Event) {
// retrieve the event from the ID provided in the current URL
$scope.event = eventPromise;
@ -472,6 +472,9 @@ Application.Controllers.controller('ShowEventReservationsController', ['$scope',
growl.success(_t('app.admin.event_reservations.reservation_was_successfully_validated'));
const index = $scope.reservations.indexOf(reservation);
$scope.reservations[index].slots_reservations_attributes[0].is_valid = true;
Event.get({ id: $scope.event.id }).$promise.then(function (event) {
$scope.event = event;
});
}, () => {
growl.warning(_t('app.admin.event_reservations.validation_failed'));
});
@ -488,6 +491,9 @@ Application.Controllers.controller('ShowEventReservationsController', ['$scope',
growl.success(_t('app.admin.event_reservations.reservation_was_successfully_invalidated'));
const index = $scope.reservations.indexOf(reservation);
$scope.reservations[index].slots_reservations_attributes[0].is_valid = false;
Event.get({ id: $scope.event.id }).$promise.then(function (event) {
$scope.event = event;
});
}, () => {
growl.warning(_t('app.admin.event_reservations.invalidation_failed'));
});

View File

@ -59,11 +59,11 @@
<div ng-if="!isCancelled(reservation) && !reservation.is_paid">
<label class="m-r-sm">
<span translate>{{ 'app.admin.event_reservations.negative' }}</span>
<input type="radio" name="validate" ng-value="false" ng-click="invalidateReservation(reservation)" ng-model="reservation.slots_reservations_attributes[0].is_valid" >
<input type="radio" name="invalidate-{{reservation.id}}" ng-value="false" ng-click="invalidateReservation(reservation)" ng-model="reservation.slots_reservations_attributes[0].is_valid" ng-disabled="reservation.total_booked_seats > event.nb_free_places && !reservation.slots_reservations_attributes[0].is_valid">
</label>
<label>
<span translate>{{ 'app.admin.event_reservations.affirmative' }}</span>
<input type="radio" name="validate" ng-value="true" ng-click="validateReservation(reservation)" ng-model="reservation.slots_reservations_attributes[0].is_valid" >
<input type="radio" name="validate-{{reservation.id}}" ng-value="true" ng-click="validateReservation(reservation)" ng-model="reservation.slots_reservations_attributes[0].is_valid" ng-disabled="reservation.total_booked_seats > event.nb_free_places && !reservation.slots_reservations_attributes[0].is_valid" >
</label>
</div>
<button class="btn btn-default" ng-click="payReservation(reservation)" ng-if="isValidated(reservation) && !isCancelled(reservation) && !reservation.is_paid">

View File

@ -17,10 +17,6 @@ class Slot < ApplicationRecord
# @param reservable [Machine,Space,Training,Event,NilClass]
# @return [Integer] the total number of reserved places
def reserved_places(reservable = nil)
p '-----------'
p id
p places
p reservable
if reservable.nil?
places.pluck('reserved_places').reduce(:+)
else

View File

@ -30,10 +30,14 @@ class Slots::PlacesCacheService
reservations = Slots::ReservationsService.reservations(slot.slots_reservations, [reservable])
pending = Slots::ReservationsService.pending_reservations(slot.cart_item_reservation_slots.map(&:id), [reservable])
reserved_places = (reservations[:reservations].count || 0) + (pending[:reservations].count || 0)
if slot.availability.available_type == 'event'
reserved_places = slot.availability.event.nb_total_places - slot.availability.event.nb_free_places
end
places.push({
reservable_type: reservable.class.name,
reservable_id: reservable.try(&:id),
reserved_places: (reservations[:reservations].count || 0) + (pending[:reservations].count || 0),
reserved_places: reserved_places,
user_ids: reservations[:user_ids] + pending[:user_ids]
})
end

View File

@ -29,6 +29,7 @@ class SlotsReservationsService
reservable.update_nb_free_places
reservable.save
end
Slots::PlacesCacheService.refresh(slot_reservation.slot)
NotificationCenter.call type: 'notify_member_reservation_validated',
receiver: slot_reservation.reservation.user,
attached_object: slot_reservation.reservation
@ -47,6 +48,7 @@ class SlotsReservationsService
reservable.update_nb_free_places
reservable.save
end
Slots::PlacesCacheService.refresh(slot_reservation.slot)
NotificationCenter.call type: 'notify_member_reservation_invalidated',
receiver: slot_reservation.reservation.user,
attached_object: slot_reservation.reservation