use of alfio.model.extension.CustomEmailText 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;
}
Aggregations