Search in sources :

Example 6 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION in project alf.io by alfio-event.

the class TicketReservationManager method prepareModelForReservationEmail.

@Transactional(readOnly = true)
public Map<String, Object> prepareModelForReservationEmail(PurchaseContext purchaseContext, TicketReservation reservation, Optional<String> vat, OrderSummary summary, List<Ticket> ticketsToInclude, Map<String, Object> initialOptions) {
    Organization organization = organizationRepository.getById(purchaseContext.getOrganizationId());
    String baseUrl = configurationManager.baseUrl(purchaseContext);
    var reservationId = reservation.getId();
    String reservationUrl = reservationUrl(reservationId);
    String reservationShortID = getShortReservationID(purchaseContext, reservation);
    var bankingInfo = configurationManager.getFor(Set.of(INVOICE_ADDRESS, BANK_ACCOUNT_NR, BANK_ACCOUNT_OWNER), ConfigurationLevel.purchaseContext(purchaseContext));
    Optional<String> invoiceAddress = bankingInfo.get(INVOICE_ADDRESS).getValue();
    Optional<String> bankAccountNr = bankingInfo.get(BANK_ACCOUNT_NR).getValue();
    Optional<String> bankAccountOwner = bankingInfo.get(BANK_ACCOUNT_OWNER).getValue();
    Map<Integer, List<Ticket>> ticketsByCategory = ticketsToInclude.stream().collect(groupingBy(Ticket::getCategoryId));
    final List<TicketWithCategory> ticketsWithCategory;
    if (!ticketsByCategory.isEmpty()) {
        ticketsWithCategory = ticketCategoryRepository.findByIds(ticketsByCategory.keySet()).stream().flatMap(tc -> ticketsByCategory.get(tc.getId()).stream().map(t -> new TicketWithCategory(t, tc))).collect(toList());
    } else {
        ticketsWithCategory = Collections.emptyList();
    }
    Map<String, Object> baseModel = new HashMap<>();
    baseModel.putAll(initialOptions);
    baseModel.putAll(extensionManager.handleReservationEmailCustomText(purchaseContext, reservation, ticketReservationRepository.getAdditionalInfo(reservationId)).map(CustomEmailText::toMap).orElse(Map.of()));
    Map<String, Object> model = TemplateResource.prepareModelForConfirmationEmail(organization, purchaseContext, reservation, vat, ticketsWithCategory, summary, baseUrl, reservationUrl, reservationShortID, invoiceAddress, bankAccountNr, bankAccountOwner, baseModel);
    boolean euBusiness = StringUtils.isNotBlank(reservation.getVatCountryCode()) && StringUtils.isNotBlank(reservation.getVatNr()) && configurationManager.getForSystem(ConfigurationKeys.EU_COUNTRIES_LIST).getRequiredValue().contains(reservation.getVatCountryCode()) && VatStatus.isVatExempt(reservation.getVatStatus());
    model.put("euBusiness", euBusiness);
    model.put("publicId", configurationManager.getPublicReservationID(purchaseContext, reservation));
    model.put("invoicingAdditionalInfo", loadAdditionalInfo(reservationId).getInvoicingAdditionalInfo());
    if (purchaseContext.getType() == PurchaseContextType.event) {
        var event = purchaseContext.event().orElseThrow();
        model.put("displayLocation", ticketsWithCategory.stream().noneMatch(tc -> EventUtil.isAccessOnline(tc.getCategory(), event)));
    } else {
        model.put("displayLocation", false);
    }
    if (ticketReservationRepository.hasSubscriptionApplied(reservationId)) {
        model.put("displaySubscriptionUsage", true);
        var subscription = subscriptionRepository.findAppliedSubscriptionByReservationId(reservationId).orElseThrow();
        if (subscription.getMaxEntries() > -1) {
            var subscriptionUsageDetails = UsageDetails.fromSubscription(subscription, ticketRepository.countSubscriptionUsage(subscription.getId(), null));
            model.put("subscriptionUsageDetails", subscriptionUsageDetails);
            model.put("subscriptionUrl", reservationUrl(subscription.getReservationId()));
        }
    }
    return model;
}
Also used : alfio.repository(alfio.repository) TicketMetadataContainer(alfio.model.metadata.TicketMetadataContainer) ZonedDateTime(java.time.ZonedDateTime) TicketCheckInUtil.ticketOnlineCheckInUrl(alfio.util.checkin.TicketCheckInUtil.ticketOnlineCheckInUrl) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) StringUtils(org.apache.commons.lang3.StringUtils) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) DateUtils.truncate(org.apache.commons.lang3.time.DateUtils.truncate) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) Arrays.asList(java.util.Arrays.asList) ASReservationWithOptionalCodeModification(alfio.model.modification.ASReservationWithOptionalCodeModification) Triple(org.apache.commons.lang3.tuple.Triple) TICKET(alfio.model.Audit.EntityType.TICKET) Organization(alfio.model.user.Organization) UserIdAndOrganizationId(alfio.model.support.UserIdAndOrganizationId) ZoneId(java.time.ZoneId) SubscriptionTimeUnit(alfio.model.subscription.SubscriptionDescriptor.SubscriptionTimeUnit) EventType(alfio.model.Audit.EventType) Stream(java.util.stream.Stream) Type(alfio.model.BillingDocument.Type) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) AdditionalServiceItemPriceContainer(alfio.model.decorator.AdditionalServiceItemPriceContainer) AdditionalServiceItemStatus(alfio.model.AdditionalServiceItem.AdditionalServiceItemStatus) AdditionalServiceReservationModification(alfio.model.modification.AdditionalServiceReservationModification) PromoCodeDiscount.categoriesOrNull(alfio.model.PromoCodeDiscount.categoriesOrNull) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) SummaryType(alfio.model.SummaryRow.SummaryType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) BindingResult(org.springframework.validation.BindingResult) ConfigurationManager(alfio.manager.system.ConfigurationManager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) WebhookHandler(alfio.model.transaction.capabilities.WebhookHandler) Status(alfio.model.SpecialPrice.Status) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) LinkedGroup(alfio.model.group.LinkedGroup) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) MonetaryUtil(alfio.util.MonetaryUtil) UserManager(alfio.manager.user.UserManager) WarningMessage(alfio.model.result.WarningMessage) Wrappers.optionally(alfio.util.Wrappers.optionally) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServerInitiatedTransaction(alfio.model.transaction.capabilities.ServerInitiatedTransaction) TemplateProcessor(alfio.controller.support.TemplateProcessor) DiscountType(alfio.model.PromoCodeDiscount.DiscountType) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) AdditionalServicePriceContainer(alfio.model.decorator.AdditionalServicePriceContainer) Mailer(alfio.manager.system.Mailer) TicketStatus(alfio.model.Ticket.TicketStatus) TicketCheckInUtil(alfio.util.checkin.TicketCheckInUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) OfflineProcessor(alfio.model.transaction.capabilities.OfflineProcessor) OrganizationRepository(alfio.repository.user.OrganizationRepository) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Role(alfio.model.user.Role) Principal(java.security.Principal) Entry(java.util.Map.Entry) CodeType(alfio.model.PromoCodeDiscount.CodeType) OnlineCheckInFullInfo(alfio.model.checkin.OnlineCheckInFullInfo) IntStream(java.util.stream.IntStream) CustomEmailText(alfio.model.extension.CustomEmailText) ChronoField(java.time.temporal.ChronoField) TransactionDefinition(org.springframework.transaction.TransactionDefinition) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) Function(java.util.function.Function) alfio.util(alfio.util) ReservationPriceCalculator(alfio.manager.system.ReservationPriceCalculator) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) ObjectUtils(org.apache.commons.lang3.ObjectUtils) alfio.model.transaction(alfio.model.transaction) UserDetails(org.springframework.security.core.userdetails.UserDetails) alfio.model.subscription(alfio.model.subscription) Collections.singletonMap(java.util.Collections.singletonMap) VatStatus(alfio.model.PriceContainer.VatStatus) ONCE_PER_EVENT(alfio.model.subscription.SubscriptionDescriptor.SubscriptionUsageType.ONCE_PER_EVENT) alfio.manager.support(alfio.manager.support) BankTransferManager(alfio.manager.payment.BankTransferManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) TicketMetadata(alfio.model.metadata.TicketMetadata) DateUtils.addHours(org.apache.commons.lang3.time.DateUtils.addHours) Component(org.springframework.stereotype.Component) PaymentSpecification(alfio.manager.payment.PaymentSpecification) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) PaymentMethodStatus(alfio.manager.PaymentManager.PaymentMethodDTO.PaymentMethodStatus) Clock(java.time.Clock) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) Organization(alfio.model.user.Organization) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CustomEmailText(alfio.model.extension.CustomEmailText) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION in project alf.io by alfio-event.

the class TicketReservationManager method acquireItems.

private List<Ticket> acquireItems(PaymentProxy paymentProxy, String reservationId, String email, CustomerName customerName, String userLanguage, String billingAddress, String customerReference, PurchaseContext purchaseContext, boolean sendTickets) {
    switch(purchaseContext.getType()) {
        case event:
            {
                acquireEventTickets(paymentProxy, reservationId, purchaseContext, purchaseContext.event().orElseThrow());
                break;
            }
        case subscription:
            {
                acquireSubscription(paymentProxy, reservationId, purchaseContext, customerName, email);
                break;
            }
        default:
            throw new IllegalStateException("not supported purchase context");
    }
    specialPriceRepository.updateStatusForReservation(singletonList(reservationId), Status.TAKEN.toString());
    ZonedDateTime timestamp = ZonedDateTime.now(clockProvider.getClock());
    int updatedReservation = ticketReservationRepository.updateTicketReservation(reservationId, TicketReservationStatus.COMPLETE.toString(), email, customerName.getFullName(), customerName.getFirstName(), customerName.getLastName(), userLanguage, billingAddress, timestamp, paymentProxy.toString(), customerReference);
    Validate.isTrue(updatedReservation == 1, "expected exactly one updated reservation, got " + updatedReservation);
    waitingQueueManager.fireReservationConfirmed(reservationId);
    // we must notify the plugins about ticket assignment and send them by email
    TicketReservation reservation = findById(reservationId).orElseThrow(IllegalStateException::new);
    List<Ticket> assignedTickets = findTicketsInReservation(reservationId);
    assignedTickets.stream().filter(ticket -> StringUtils.isNotBlank(ticket.getFullName()) || StringUtils.isNotBlank(ticket.getFirstName()) || StringUtils.isNotBlank(ticket.getEmail())).forEach(ticket -> {
        var event = purchaseContext.event().orElseThrow();
        Locale locale = LocaleUtil.forLanguageTag(ticket.getUserLanguage());
        var additionalInfo = retrieveAttendeeAdditionalInfoForTicket(ticket);
        if ((paymentProxy != PaymentProxy.ADMIN || sendTickets) && configurationManager.getFor(SEND_TICKETS_AUTOMATICALLY, ConfigurationLevel.event(event)).getValueAsBooleanOrDefault()) {
            sendTicketByEmail(ticket, locale, event, getTicketEmailGenerator(event, reservation, locale, additionalInfo));
        }
        extensionManager.handleTicketAssignment(ticket, ticketCategoryRepository.getById(ticket.getCategoryId()), additionalInfo);
    });
    return assignedTickets;
}
Also used : alfio.repository(alfio.repository) TicketMetadataContainer(alfio.model.metadata.TicketMetadataContainer) ZonedDateTime(java.time.ZonedDateTime) TicketCheckInUtil.ticketOnlineCheckInUrl(alfio.util.checkin.TicketCheckInUtil.ticketOnlineCheckInUrl) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) StringUtils(org.apache.commons.lang3.StringUtils) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) DateUtils.truncate(org.apache.commons.lang3.time.DateUtils.truncate) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) Arrays.asList(java.util.Arrays.asList) ASReservationWithOptionalCodeModification(alfio.model.modification.ASReservationWithOptionalCodeModification) Triple(org.apache.commons.lang3.tuple.Triple) TICKET(alfio.model.Audit.EntityType.TICKET) Organization(alfio.model.user.Organization) UserIdAndOrganizationId(alfio.model.support.UserIdAndOrganizationId) ZoneId(java.time.ZoneId) SubscriptionTimeUnit(alfio.model.subscription.SubscriptionDescriptor.SubscriptionTimeUnit) EventType(alfio.model.Audit.EventType) Stream(java.util.stream.Stream) Type(alfio.model.BillingDocument.Type) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) AdditionalServiceItemPriceContainer(alfio.model.decorator.AdditionalServiceItemPriceContainer) AdditionalServiceItemStatus(alfio.model.AdditionalServiceItem.AdditionalServiceItemStatus) AdditionalServiceReservationModification(alfio.model.modification.AdditionalServiceReservationModification) PromoCodeDiscount.categoriesOrNull(alfio.model.PromoCodeDiscount.categoriesOrNull) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) SummaryType(alfio.model.SummaryRow.SummaryType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) BindingResult(org.springframework.validation.BindingResult) ConfigurationManager(alfio.manager.system.ConfigurationManager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) WebhookHandler(alfio.model.transaction.capabilities.WebhookHandler) Status(alfio.model.SpecialPrice.Status) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) LinkedGroup(alfio.model.group.LinkedGroup) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) MonetaryUtil(alfio.util.MonetaryUtil) UserManager(alfio.manager.user.UserManager) WarningMessage(alfio.model.result.WarningMessage) Wrappers.optionally(alfio.util.Wrappers.optionally) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServerInitiatedTransaction(alfio.model.transaction.capabilities.ServerInitiatedTransaction) TemplateProcessor(alfio.controller.support.TemplateProcessor) DiscountType(alfio.model.PromoCodeDiscount.DiscountType) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) AdditionalServicePriceContainer(alfio.model.decorator.AdditionalServicePriceContainer) Mailer(alfio.manager.system.Mailer) TicketStatus(alfio.model.Ticket.TicketStatus) TicketCheckInUtil(alfio.util.checkin.TicketCheckInUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) OfflineProcessor(alfio.model.transaction.capabilities.OfflineProcessor) OrganizationRepository(alfio.repository.user.OrganizationRepository) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Role(alfio.model.user.Role) Principal(java.security.Principal) Entry(java.util.Map.Entry) CodeType(alfio.model.PromoCodeDiscount.CodeType) OnlineCheckInFullInfo(alfio.model.checkin.OnlineCheckInFullInfo) IntStream(java.util.stream.IntStream) CustomEmailText(alfio.model.extension.CustomEmailText) ChronoField(java.time.temporal.ChronoField) TransactionDefinition(org.springframework.transaction.TransactionDefinition) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) Function(java.util.function.Function) alfio.util(alfio.util) ReservationPriceCalculator(alfio.manager.system.ReservationPriceCalculator) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) ObjectUtils(org.apache.commons.lang3.ObjectUtils) alfio.model.transaction(alfio.model.transaction) UserDetails(org.springframework.security.core.userdetails.UserDetails) alfio.model.subscription(alfio.model.subscription) Collections.singletonMap(java.util.Collections.singletonMap) VatStatus(alfio.model.PriceContainer.VatStatus) ONCE_PER_EVENT(alfio.model.subscription.SubscriptionDescriptor.SubscriptionUsageType.ONCE_PER_EVENT) alfio.manager.support(alfio.manager.support) BankTransferManager(alfio.manager.payment.BankTransferManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) TicketMetadata(alfio.model.metadata.TicketMetadata) DateUtils.addHours(org.apache.commons.lang3.time.DateUtils.addHours) Component(org.springframework.stereotype.Component) PaymentSpecification(alfio.manager.payment.PaymentSpecification) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) PaymentMethodStatus(alfio.manager.PaymentManager.PaymentMethodDTO.PaymentMethodStatus) Clock(java.time.Clock) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) ZonedDateTime(java.time.ZonedDateTime)

Example 8 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION in project alf.io by alfio-event.

the class TicketReservationManager method cancelPendingPayment.

public boolean cancelPendingPayment(String reservationId, PurchaseContext purchaseContext) {
    var optionalReservation = findById(reservationId);
    if (optionalReservation.isEmpty()) {
        return false;
    }
    var optionalTransaction = transactionRepository.loadOptionalByReservationId(reservationId);
    if (optionalTransaction.isEmpty() || optionalTransaction.get().getStatus() != Transaction.Status.PENDING) {
        log.warn("Trying to cancel a non-pending transaction for reservation {}", reservationId);
        return false;
    }
    Transaction transaction = optionalTransaction.get();
    boolean remoteDeleteResult = paymentManager.lookupProviderByTransactionAndCapabilities(transaction, List.of(ServerInitiatedTransaction.class)).map(provider -> ((ServerInitiatedTransaction) provider).discardTransaction(optionalTransaction.get(), purchaseContext)).orElse(true);
    if (remoteDeleteResult) {
        reTransitionToPending(reservationId);
        auditingRepository.insert(reservationId, null, purchaseContext.event().map(Event::getId).orElse(null), RESET_PAYMENT, new Date(), RESERVATION, reservationId);
        return true;
    }
    log.warn("Cannot delete payment with ID {} for reservation {}", transaction.getPaymentId(), reservationId);
    return false;
}
Also used : alfio.repository(alfio.repository) TicketMetadataContainer(alfio.model.metadata.TicketMetadataContainer) ZonedDateTime(java.time.ZonedDateTime) TicketCheckInUtil.ticketOnlineCheckInUrl(alfio.util.checkin.TicketCheckInUtil.ticketOnlineCheckInUrl) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) StringUtils(org.apache.commons.lang3.StringUtils) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) DateUtils.truncate(org.apache.commons.lang3.time.DateUtils.truncate) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) Arrays.asList(java.util.Arrays.asList) ASReservationWithOptionalCodeModification(alfio.model.modification.ASReservationWithOptionalCodeModification) Triple(org.apache.commons.lang3.tuple.Triple) TICKET(alfio.model.Audit.EntityType.TICKET) Organization(alfio.model.user.Organization) UserIdAndOrganizationId(alfio.model.support.UserIdAndOrganizationId) ZoneId(java.time.ZoneId) SubscriptionTimeUnit(alfio.model.subscription.SubscriptionDescriptor.SubscriptionTimeUnit) EventType(alfio.model.Audit.EventType) Stream(java.util.stream.Stream) Type(alfio.model.BillingDocument.Type) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) AdditionalServiceItemPriceContainer(alfio.model.decorator.AdditionalServiceItemPriceContainer) AdditionalServiceItemStatus(alfio.model.AdditionalServiceItem.AdditionalServiceItemStatus) AdditionalServiceReservationModification(alfio.model.modification.AdditionalServiceReservationModification) PromoCodeDiscount.categoriesOrNull(alfio.model.PromoCodeDiscount.categoriesOrNull) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) SummaryType(alfio.model.SummaryRow.SummaryType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) BindingResult(org.springframework.validation.BindingResult) ConfigurationManager(alfio.manager.system.ConfigurationManager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) WebhookHandler(alfio.model.transaction.capabilities.WebhookHandler) Status(alfio.model.SpecialPrice.Status) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) LinkedGroup(alfio.model.group.LinkedGroup) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) MonetaryUtil(alfio.util.MonetaryUtil) UserManager(alfio.manager.user.UserManager) WarningMessage(alfio.model.result.WarningMessage) Wrappers.optionally(alfio.util.Wrappers.optionally) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServerInitiatedTransaction(alfio.model.transaction.capabilities.ServerInitiatedTransaction) TemplateProcessor(alfio.controller.support.TemplateProcessor) DiscountType(alfio.model.PromoCodeDiscount.DiscountType) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) AdditionalServicePriceContainer(alfio.model.decorator.AdditionalServicePriceContainer) Mailer(alfio.manager.system.Mailer) TicketStatus(alfio.model.Ticket.TicketStatus) TicketCheckInUtil(alfio.util.checkin.TicketCheckInUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) OfflineProcessor(alfio.model.transaction.capabilities.OfflineProcessor) OrganizationRepository(alfio.repository.user.OrganizationRepository) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Role(alfio.model.user.Role) Principal(java.security.Principal) Entry(java.util.Map.Entry) CodeType(alfio.model.PromoCodeDiscount.CodeType) OnlineCheckInFullInfo(alfio.model.checkin.OnlineCheckInFullInfo) IntStream(java.util.stream.IntStream) CustomEmailText(alfio.model.extension.CustomEmailText) ChronoField(java.time.temporal.ChronoField) TransactionDefinition(org.springframework.transaction.TransactionDefinition) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) Function(java.util.function.Function) alfio.util(alfio.util) ReservationPriceCalculator(alfio.manager.system.ReservationPriceCalculator) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) ObjectUtils(org.apache.commons.lang3.ObjectUtils) alfio.model.transaction(alfio.model.transaction) UserDetails(org.springframework.security.core.userdetails.UserDetails) alfio.model.subscription(alfio.model.subscription) Collections.singletonMap(java.util.Collections.singletonMap) VatStatus(alfio.model.PriceContainer.VatStatus) ONCE_PER_EVENT(alfio.model.subscription.SubscriptionDescriptor.SubscriptionUsageType.ONCE_PER_EVENT) alfio.manager.support(alfio.manager.support) BankTransferManager(alfio.manager.payment.BankTransferManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) TicketMetadata(alfio.model.metadata.TicketMetadata) DateUtils.addHours(org.apache.commons.lang3.time.DateUtils.addHours) Component(org.springframework.stereotype.Component) PaymentSpecification(alfio.manager.payment.PaymentSpecification) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) PaymentMethodStatus(alfio.manager.PaymentManager.PaymentMethodDTO.PaymentMethodStatus) Clock(java.time.Clock) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) ServerInitiatedTransaction(alfio.model.transaction.capabilities.ServerInitiatedTransaction) ServerInitiatedTransaction(alfio.model.transaction.capabilities.ServerInitiatedTransaction)

Example 9 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION in project alf.io by alfio-event.

the class BillingDocumentManager method prepareModelForBillingDocument.

private Map<String, Object> prepareModelForBillingDocument(PurchaseContext purchaseContext, TicketReservation reservation, OrderSummary summary, BillingDocument.Type type) {
    Organization organization = organizationRepository.getById(purchaseContext.getOrganizationId());
    String creditNoteNumber = null;
    if (type == CREDIT_NOTE) {
        // override credit note number
        creditNoteNumber = generateCreditNoteNumber(purchaseContext, reservation);
    }
    var bankingInfo = configurationManager.getFor(Set.of(VAT_NR, INVOICE_ADDRESS, BANK_ACCOUNT_NR, BANK_ACCOUNT_OWNER), purchaseContext.getConfigurationLevel());
    Optional<String> invoiceAddress = bankingInfo.get(INVOICE_ADDRESS).getValue();
    Optional<String> bankAccountNr = bankingInfo.get(BANK_ACCOUNT_NR).getValue();
    Optional<String> bankAccountOwner = bankingInfo.get(BANK_ACCOUNT_OWNER).getValue();
    Optional<String> vat = bankingInfo.get(VAT_NR).getValue();
    Map<Integer, List<Ticket>> ticketsByCategory = ticketRepository.findTicketsInReservation(reservation.getId()).stream().collect(groupingBy(Ticket::getCategoryId));
    final List<TicketWithCategory> ticketsWithCategory;
    if (!ticketsByCategory.isEmpty()) {
        ticketsWithCategory = ticketCategoryRepository.findByIds(ticketsByCategory.keySet()).stream().flatMap(tc -> ticketsByCategory.get(tc.getId()).stream().map(t -> new TicketWithCategory(t, tc))).collect(toList());
    } else {
        ticketsWithCategory = Collections.emptyList();
    }
    var reservationShortId = configurationManager.getShortReservationID(purchaseContext, reservation);
    Map<String, Object> model = TemplateResource.prepareModelForConfirmationEmail(organization, purchaseContext, reservation, vat, ticketsWithCategory, summary, "", "", reservationShortId, invoiceAddress, bankAccountNr, bankAccountOwner, Map.of());
    boolean euBusiness = StringUtils.isNotBlank(reservation.getVatCountryCode()) && StringUtils.isNotBlank(reservation.getVatNr()) && configurationManager.getForSystem(ConfigurationKeys.EU_COUNTRIES_LIST).getRequiredValue().contains(reservation.getVatCountryCode()) && PriceContainer.VatStatus.isVatExempt(reservation.getVatStatus());
    model.put("isEvent", purchaseContext.ofType(PurchaseContextType.event));
    model.put("euBusiness", euBusiness);
    model.put("publicId", configurationManager.getPublicReservationID(purchaseContext, reservation));
    var additionalInfo = ticketReservationRepository.getAdditionalInfo(reservation.getId());
    model.put("invoicingAdditionalInfo", additionalInfo.getInvoicingAdditionalInfo());
    model.put("billingDetails", additionalInfo.getBillingDetails());
    if (type == CREDIT_NOTE) {
        model.put(CREDIT_NOTE_NUMBER, creditNoteNumber);
    }
    return model;
}
Also used : alfio.repository(alfio.repository) java.util(java.util) AffectedRowCountAndKey(ch.digitalfondue.npjt.AffectedRowCountAndKey) ZonedDateTime(java.time.ZonedDateTime) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) ConfigurationManager(alfio.manager.system.ConfigurationManager) Mailer(alfio.manager.system.Mailer) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) Collections.singletonList(java.util.Collections.singletonList) Json(alfio.util.Json) CANCELLED(alfio.model.TicketReservation.TicketReservationStatus.CANCELLED) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Collections.singletonMap(java.util.Collections.singletonMap) TemplateResource(alfio.util.TemplateResource) OrganizationRepository(alfio.repository.user.OrganizationRepository) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) EXTERNAL_CREDIT_NOTE_NUMBER(alfio.model.Audit.EventType.EXTERNAL_CREDIT_NOTE_NUMBER) Organization(alfio.model.user.Organization) PENDING(alfio.model.TicketReservation.TicketReservationStatus.PENDING) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) EXTERNAL_INVOICE_NUMBER(alfio.model.Audit.EventType.EXTERNAL_INVOICE_NUMBER) Type(alfio.model.BillingDocument.Type) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) PaymentSpecification(alfio.manager.payment.PaymentSpecification) Log4j2(lombok.extern.log4j.Log4j2) ClockProvider(alfio.util.ClockProvider) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) Organization(alfio.model.user.Organization) Collections.singletonList(java.util.Collections.singletonList) Collectors.toList(java.util.stream.Collectors.toList)

Aggregations

PaymentSpecification (alfio.manager.payment.PaymentSpecification)9 alfio.model (alfio.model)9 RESERVATION (alfio.model.Audit.EntityType.RESERVATION)9 PurchaseContextType (alfio.model.PurchaseContext.PurchaseContextType)9 Organization (alfio.model.user.Organization)9 alfio.repository (alfio.repository)9 UserRepository (alfio.repository.user.UserRepository)9 java.util (java.util)9 Collections.singletonList (java.util.Collections.singletonList)9 Collections.singletonMap (java.util.Collections.singletonMap)9 Log4j2 (lombok.extern.log4j.Log4j2)9 ObjectUtils (org.apache.commons.lang3.ObjectUtils)9 StringUtils (org.apache.commons.lang3.StringUtils)9 Component (org.springframework.stereotype.Component)9 Transactional (org.springframework.transaction.annotation.Transactional)9 TemplateProcessor (alfio.controller.support.TemplateProcessor)8 MessageSourceManager (alfio.manager.i18n.MessageSourceManager)8 ReservationPriceCalculator (alfio.manager.system.ReservationPriceCalculator)8 TICKET (alfio.model.Audit.EntityType.TICKET)8 TicketReservationStatus (alfio.model.TicketReservation.TicketReservationStatus)5