Search in sources :

Example 1 with Category

use of alfio.model.modification.AdminReservationModification.Category in project alf.io by alfio-event.

the class AdminReservationManager method reserveForTicketsInfo.

private Result<List<Ticket>> reserveForTicketsInfo(Event event, AdminReservationModification arm, String reservationId, Pair<TicketCategory, TicketsInfo> pair) {
    TicketCategory category = pair.getLeft();
    TicketsInfo ticketsInfo = pair.getRight();
    int categoryId = category.getId();
    List<Attendee> attendees = ticketsInfo.getAttendees();
    List<Integer> reservedForUpdate = ticketReservationManager.reserveTickets(event.getId(), categoryId, attendees.size(), singletonList(Ticket.TicketStatus.FREE));
    if (reservedForUpdate.isEmpty() || reservedForUpdate.size() != attendees.size()) {
        return Result.error(ErrorCode.CategoryError.NOT_ENOUGH_SEATS);
    }
    var currencyCode = category.getCurrencyCode();
    ticketRepository.reserveTickets(reservationId, reservedForUpdate, category, arm.getLanguage(), event.getVatStatus(), i -> null);
    Ticket ticket = ticketRepository.findById(reservedForUpdate.get(0), categoryId);
    TicketPriceContainer priceContainer = TicketPriceContainer.from(ticket, null, event.getVat(), event.getVatStatus(), null);
    ticketRepository.updateTicketPrice(reservedForUpdate, categoryId, event.getId(), category.getSrcPriceCts(), unitToCents(priceContainer.getFinalPrice(), currencyCode), unitToCents(priceContainer.getVAT(), currencyCode), unitToCents(priceContainer.getAppliedDiscount(), currencyCode), currencyCode, priceContainer.getVatStatus());
    List<SpecialPrice> codes = category.isAccessRestricted() ? bindSpecialPriceTokens(categoryId, attendees) : Collections.emptyList();
    if (category.isAccessRestricted() && codes.size() < attendees.size()) {
        return Result.error(ErrorCode.CategoryError.NOT_ENOUGH_SEATS);
    }
    assignTickets(event, attendees, categoryId, reservedForUpdate, codes, reservationId, arm.getLanguage(), category.getSrcPriceCts());
    List<Ticket> tickets = reservedForUpdate.stream().map(id -> ticketRepository.findById(id, categoryId)).collect(toList());
    return Result.success(tickets);
}
Also used : alfio.repository(alfio.repository) PaymentProxy(alfio.model.transaction.PaymentProxy) TemplateProcessor(alfio.controller.support.TemplateProcessor) StringUtils.firstNonBlank(org.apache.commons.lang3.StringUtils.firstNonBlank) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AlfioMetadata(alfio.model.metadata.AlfioMetadata) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) UPDATE_TICKET(alfio.model.Audit.EventType.UPDATE_TICKET) ResultStatus(alfio.model.result.Result.ResultStatus) BigDecimal(java.math.BigDecimal) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Triple(org.apache.commons.lang3.tuple.Triple) TICKET(alfio.model.Audit.EntityType.TICKET) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) Organization(alfio.model.user.Organization) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) CANCEL_TICKET(alfio.model.Audit.EventType.CANCEL_TICKET) Stream(java.util.stream.Stream) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) MapBindingResult(org.springframework.validation.MapBindingResult) java.util(java.util) MonetaryUtil.unitToCents(alfio.util.MonetaryUtil.unitToCents) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) TransactionDefinition(org.springframework.transaction.TransactionDefinition) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Function(java.util.function.Function) alfio.util(alfio.util) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) Attendee(alfio.model.modification.AdminReservationModification.Attendee) DateTimeModification(alfio.model.modification.DateTimeModification) ReservationPriceCalculator(alfio.manager.system.ReservationPriceCalculator) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Collections.singletonMap(java.util.Collections.singletonMap) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) Notification(alfio.model.modification.AdminReservationModification.Notification) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) User(alfio.model.user.User) Result(alfio.model.result.Result) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) PaymentSpecification(alfio.manager.payment.PaymentSpecification) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) Category(alfio.model.modification.AdminReservationModification.Category) Wrappers.optionally(alfio.util.Wrappers.optionally) EventUtil.generateEmptyTickets(alfio.util.EventUtil.generateEmptyTickets) AdminReservationModification(alfio.model.modification.AdminReservationModification) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) Attendee(alfio.model.modification.AdminReservationModification.Attendee)

Example 2 with Category

use of alfio.model.modification.AdminReservationModification.Category in project alf.io by alfio-event.

the class AdminReservationManager method checkExistingCategory.

private Result<TicketCategory> checkExistingCategory(TicketsInfo ti, Event event, String username) {
    Category category = ti.getCategory();
    List<Attendee> attendees = ti.getAttendees();
    int tickets = attendees.size();
    int eventId = event.getId();
    TicketCategory existing = ticketCategoryRepository.getByIdAndActive(category.getExistingCategoryId(), eventId);
    int existingCategoryId = existing.getId();
    int freeTicketsInCategory = ticketRepository.countFreeTickets(eventId, existingCategoryId);
    int notAllocated = getNotAllocatedTickets(event);
    int missingTickets = Math.max(tickets - (freeTicketsInCategory + notAllocated), 0);
    Event modified = increaseSeatsIfNeeded(ti, event, missingTickets, event);
    if (freeTicketsInCategory < tickets && existing.isBounded()) {
        int maxTickets = existing.getMaxTickets() + (tickets - freeTicketsInCategory);
        TicketCategoryModification tcm = new TicketCategoryModification(existingCategoryId, existing.getName(), existing.getTicketAccessType(), maxTickets, fromZonedDateTime(existing.getInception(modified.getZoneId())), fromZonedDateTime(existing.getExpiration(event.getZoneId())), Collections.emptyMap(), existing.getPrice(), existing.isAccessRestricted(), "", true, existing.getCode(), fromZonedDateTime(existing.getValidCheckInFrom(modified.getZoneId())), fromZonedDateTime(existing.getValidCheckInTo(modified.getZoneId())), fromZonedDateTime(existing.getTicketValidityStart(modified.getZoneId())), fromZonedDateTime(existing.getTicketValidityEnd(modified.getZoneId())), 0, existing.getTicketCheckInStrategy(), null, AlfioMetadata.empty());
        return eventManager.updateCategory(existingCategoryId, modified, tcm, username, true);
    }
    return Result.success(existing);
}
Also used : Category(alfio.model.modification.AdminReservationModification.Category) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Attendee(alfio.model.modification.AdminReservationModification.Attendee)

Example 3 with Category

use of alfio.model.modification.AdminReservationModification.Category in project alf.io by alfio-event.

the class AdminReservationManager method createCategory.

private Result<TicketCategory> createCategory(TicketsInfo ti, Event event, AdminReservationModification reservation, String username) {
    Category category = ti.getCategory();
    List<Attendee> attendees = ti.getAttendees();
    DateTimeModification inception = fromZonedDateTime(event.now(clockProvider));
    int tickets = attendees.size();
    var accessType = event.getFormat() != Event.EventFormat.HYBRID ? TicketCategory.TicketAccessType.INHERIT : Objects.requireNonNull(category.getTicketAccessType());
    TicketCategoryModification tcm = new TicketCategoryModification(category.getExistingCategoryId(), category.getName(), accessType, tickets, inception, reservation.getExpiration(), Collections.emptyMap(), category.getPrice(), true, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty());
    int notAllocated = getNotAllocatedTickets(event);
    int missingTickets = Math.max(tickets - notAllocated, 0);
    Event modified = increaseSeatsIfNeeded(ti, event, missingTickets, event);
    return eventManager.insertCategory(modified, tcm, username).map(id -> ticketCategoryRepository.getByIdAndActive(id, event.getId()));
}
Also used : Category(alfio.model.modification.AdminReservationModification.Category) DateTimeModification(alfio.model.modification.DateTimeModification) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Attendee(alfio.model.modification.AdminReservationModification.Attendee)

Aggregations

Attendee (alfio.model.modification.AdminReservationModification.Attendee)3 Category (alfio.model.modification.AdminReservationModification.Category)3 TicketCategoryModification (alfio.model.modification.TicketCategoryModification)3 DateTimeModification (alfio.model.modification.DateTimeModification)2 TemplateProcessor (alfio.controller.support.TemplateProcessor)1 MessageSourceManager (alfio.manager.i18n.MessageSourceManager)1 PaymentSpecification (alfio.manager.payment.PaymentSpecification)1 DuplicateReferenceException (alfio.manager.support.DuplicateReferenceException)1 ReservationPriceCalculator (alfio.manager.system.ReservationPriceCalculator)1 alfio.model (alfio.model)1 RESERVATION (alfio.model.Audit.EntityType.RESERVATION)1 TICKET (alfio.model.Audit.EntityType.TICKET)1 CANCEL_TICKET (alfio.model.Audit.EventType.CANCEL_TICKET)1 UPDATE_TICKET (alfio.model.Audit.EventType.UPDATE_TICKET)1 PurchaseContextType (alfio.model.PurchaseContext.PurchaseContextType)1 TicketReservationStatus (alfio.model.TicketReservation.TicketReservationStatus)1 TicketPriceContainer (alfio.model.decorator.TicketPriceContainer)1 AlfioMetadata (alfio.model.metadata.AlfioMetadata)1 AdminReservationModification (alfio.model.modification.AdminReservationModification)1 Notification (alfio.model.modification.AdminReservationModification.Notification)1