1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-30 19:52:20 +01:00

(bug) admin valid/pay event reservaiton error

This commit is contained in:
Du Peng 2023-07-31 10:18:15 +02:00
parent cc46103eca
commit 2a2c451d6e
6 changed files with 45 additions and 18 deletions

View File

@ -47,15 +47,15 @@ export const EventReservationItem: React.FC<EventReservationItemProps> = ({ rese
const preRegistrationStatus = () => { const preRegistrationStatus = () => {
if (!_.isBoolean(reservation.is_valid) && !reservation.canceled_at && !reservation.is_paid) { if (!_.isBoolean(reservation.is_valid) && !reservation.canceled_at && !reservation.is_paid) {
return t('app.logged.event_reservation_item.in_the_process_of_validation'); 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'); 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'); return t('app.logged.event_reservation_item.registered');
} else if (!reservation.is_valid && !reservation.canceled_at) { } else if (!reservation.is_valid && !reservation.canceled_at) {
return t('app.logged.event_reservation_item.not_validated'); 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'); 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'); return t('app.logged.event_reservation_item.present');
} else if (reservation.canceled_at) { } else if (reservation.canceled_at) {
return t('app.logged.event_reservation_item.canceled'); return t('app.logged.event_reservation_item.canceled');

View File

@ -460,10 +460,35 @@ Application.Controllers.controller('ShowEventReservationsController', ['$scope',
$scope.isValidated = function (reservation) { $scope.isValidated = function (reservation) {
return reservation.slots_reservations_attributes[0].is_valid === true || reservation.slots_reservations_attributes[0].is_valid === 'true'; 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) { $scope.isInvalidated = function (reservation) {
return reservation.slots_reservations_attributes[0].is_valid === false || reservation.slots_reservations_attributes[0].is_valid === 'false'; 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 * Callback to validate a reservation
* @param reservation {Reservation} * @param reservation {Reservation}
@ -628,7 +653,7 @@ Application.Controllers.controller('ShowEventReservationsController', ['$scope',
if (r.id === reservation.id) { if (r.id === reservation.id) {
return reservation; return reservation;
} }
if ($scope.event.amount === 0) { if ($scope.reservationAmount(reservation) === 0) {
growl.success(_t('app.admin.event_reservations.reservation_was_successfully_present')); growl.success(_t('app.admin.event_reservations.reservation_was_successfully_present'));
} else { } else {
growl.success(_t('app.admin.event_reservations.reservation_was_successfully_paid')); growl.success(_t('app.admin.event_reservations.reservation_was_successfully_paid'));

View File

@ -70,10 +70,11 @@ export interface Reservation {
end_at: TDateISO, end_at: TDateISO,
event_type?: string, event_type?: string,
event_title?: string, event_title?: string,
event_pre_registration?: boolean event_pre_registration?: boolean,
canceled_at?: TDateISO, canceled_at?: TDateISO,
is_valid?: boolean, is_valid?: boolean,
is_paid?: boolean, is_paid?: boolean,
amount?: number
} }
export interface ReservationIndexFilter extends ApiFilter { export interface ReservationIndexFilter extends ApiFilter {

View File

@ -1,10 +1,10 @@
<div class="modal-header"> <div class="modal-header">
<img ng-src="{{logoBlack.custom_asset_file_attributes.attachment_url}}" alt="{{logo.custom_asset_file_attributes.attachment}}" class="modal-logo"/> <img ng-src="{{logoBlack.custom_asset_file_attributes.attachment_url}}" alt="{{logo.custom_asset_file_attributes.attachment}}" class="modal-logo"/>
<h1 translate ng-show="reservation && event.amount !== 0">{{ 'app.admin.event_reservations.confirm_payment' }}</h1> <h1 translate ng-show="reservation && amount !== 0">{{ 'app.admin.event_reservations.confirm_payment' }}</h1>
<h1 translate ng-show="reservation && event.amount === 0">{{ 'app.admin.event_reservations.confirm_present' }}</h1> <h1 translate ng-show="reservation && amount === 0">{{ 'app.admin.event_reservations.confirm_present' }}</h1>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<div ng-show="event.amount !== 0"> <div ng-show="amount !== 0">
<div class="row" ng-show="!offered"> <div class="row" ng-show="!offered">
<wallet-info current-user="currentUser" <wallet-info current-user="currentUser"
cart="cartItems" cart="cartItems"
@ -41,12 +41,12 @@
</div> </div>
</div> </div>
<div ng-if="event.amount === 0"> <div ng-if="amount === 0">
<p translate>{{ 'app.admin.event_reservations.confirm_present_info' }}</p> <p translate>{{ 'app.admin.event_reservations.confirm_present_info' }}</p>
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-info" ng-if="event.amount !== 0" ng-click="ok()" ng-disabled="attempting || !payment" ng-bind-html="validButtonName"></button> <button class="btn btn-info" ng-if="amount !== 0" ng-click="ok()" ng-disabled="attempting || !payment" ng-bind-html="validButtonName"></button>
<button class="btn btn-info" ng-if="event.amount === 0" ng-click="ok()" ng-disabled="attempting" ng-bind-html="validButtonName"></button> <button class="btn btn-info" ng-if="amount === 0" ng-click="ok()" ng-disabled="attempting" ng-bind-html="validButtonName"></button>
<button class="btn btn-default" ng-click="cancel()" translate>{{ 'app.shared.buttons.cancel' }}</button> <button class="btn btn-default" ng-click="cancel()" translate>{{ 'app.shared.buttons.cancel' }}</button>
</div> </div>

View File

@ -48,11 +48,11 @@
</td> </td>
<td ng-if="event.pre_registration"> <td ng-if="event.pre_registration">
<span ng-if="!isValidated(reservation) && !isInvalidated(reservation) && !isCancelled(reservation) && !reservation.is_paid" class="v-middle badge text-sm bg-info" translate="">{{ 'app.admin.event_reservations.event_status.pre_registered' }}</span> <span ng-if="!isValidated(reservation) && !isInvalidated(reservation) && !isCancelled(reservation) && !reservation.is_paid" class="v-middle badge text-sm bg-info" translate="">{{ 'app.admin.event_reservations.event_status.pre_registered' }}</span>
<span ng-if="event.amount !== 0 && isValidated(reservation) && !isCancelled(reservation) && !reservation.is_paid" class="v-middle badge text-sm bg-stage" translate="">{{ 'app.admin.event_reservations.event_status.to_pay' }}</span> <span ng-if="reservationAmount(reservation) !== 0 && isValidated(reservation) && !isCancelled(reservation) && !reservation.is_paid" class="v-middle badge text-sm bg-stage" translate="">{{ 'app.admin.event_reservations.event_status.to_pay' }}</span>
<span ng-if="event.amount === 0 && isValidated(reservation) && !isCancelled(reservation) && !reservation.is_paid" class="v-middle badge text-sm bg-stage" translate="">{{ 'app.admin.event_reservations.event_status.registered' }}</span> <span ng-if="reservationAmount(reservation) === 0 && isValidated(reservation) && !isCancelled(reservation) && !reservation.is_paid" class="v-middle badge text-sm bg-stage" translate="">{{ 'app.admin.event_reservations.event_status.registered' }}</span>
<span ng-if="isInvalidated(reservation) && !isCancelled(reservation) && !reservation.is_paid" class="v-middle badge text-sm bg-event" translate="">{{ 'app.admin.event_reservations.event_status.not_validated' }}</span> <span ng-if="isInvalidated(reservation) && !isCancelled(reservation) && !reservation.is_paid" class="v-middle badge text-sm bg-event" translate="">{{ 'app.admin.event_reservations.event_status.not_validated' }}</span>
<span ng-if="event.amount !== 0 && reservation.is_paid && !isCancelled(reservation)" class="v-middle badge text-sm bg-success" translate="">{{ 'app.admin.event_reservations.event_status.paid' }}</span> <span ng-if="reservationAmount(reservation) !== 0 && reservation.is_paid && !isCancelled(reservation)" class="v-middle badge text-sm bg-success" translate="">{{ 'app.admin.event_reservations.event_status.paid' }}</span>
<span ng-if="event.amount === 0 && reservation.is_paid && !isCancelled(reservation)" class="v-middle badge text-sm bg-success" translate="">{{ 'app.admin.event_reservations.event_status.present' }}</span> <span ng-if="reservationAmount(reservation) === 0 && reservation.is_paid && !isCancelled(reservation)" class="v-middle badge text-sm bg-success" translate="">{{ 'app.admin.event_reservations.event_status.present' }}</span>
<span ng-if="isCancelled(reservation)" class="v-middle badge text-sm bg-event" translate="">{{ 'app.admin.event_reservations.event_status.canceled' }}</span> <span ng-if="isCancelled(reservation)" class="v-middle badge text-sm bg-event" translate="">{{ 'app.admin.event_reservations.event_status.canceled' }}</span>
</td> </td>
<td ng-if="event.pre_registration"> <td ng-if="event.pre_registration">
@ -68,8 +68,8 @@
</label> </label>
</div> </div>
<button class="btn btn-default" ng-click="payReservation(reservation)" ng-if="isValidated(reservation) && !isCancelled(reservation) && !reservation.is_paid"> <button class="btn btn-default" ng-click="payReservation(reservation)" ng-if="isValidated(reservation) && !isCancelled(reservation) && !reservation.is_paid">
<span ng-if="event.amount !== 0" translate>{{ 'app.admin.event_reservations.pay' }}</span> <span ng-if="reservationAmount(reservation) !== 0" translate>{{ 'app.admin.event_reservations.pay' }}</span>
<span ng-if="event.amount === 0" translate>{{ 'app.admin.event_reservations.present' }}</span> <span ng-if="reservationAmount(reservation) === 0" translate>{{ 'app.admin.event_reservations.present' }}</span>
</button> </button>
</div> </div>
</td> </td>

View File

@ -89,6 +89,7 @@ json.events_reservations @member.reservations.where(reservable_type: 'Event').jo
json.event_pre_registration sr.reservation.reservable.pre_registration json.event_pre_registration sr.reservation.reservable.pre_registration
json.is_valid sr.is_valid json.is_valid sr.is_valid
json.is_paid sr.reservation.invoice_items.count.positive? json.is_paid sr.reservation.invoice_items.count.positive?
json.amount sr.reservation.invoice_items.sum(:amount)
json.canceled_at sr.canceled_at json.canceled_at sr.canceled_at
json.booking_users_attributes sr.reservation.booking_users.order(booked_type: :desc) do |bu| json.booking_users_attributes sr.reservation.booking_users.order(booked_type: :desc) do |bu|
json.id bu.id json.id bu.id