use of alfio.model.decorator.AdditionalServicePriceContainer in project alf.io by alfio-event.
the class TicketReservationManager method reserveAdditionalServicesForReservation.
private void reserveAdditionalServicesForReservation(int eventId, String transactionId, ASReservationWithOptionalCodeModification additionalServiceReservation, PromoCodeDiscount discount) {
Optional.ofNullable(additionalServiceReservation.getAdditionalServiceId()).flatMap(id -> additionalServiceRepository.getOptionalById(id, eventId)).filter(as -> additionalServiceReservation.getQuantity() > 0 && (as.isFixPrice() || Optional.ofNullable(additionalServiceReservation.getAmount()).filter(a -> a.compareTo(BigDecimal.ZERO) > 0).isPresent())).map(as -> Pair.of(eventRepository.findById(eventId), as)).ifPresent(pair -> {
Event e = pair.getKey();
AdditionalService as = pair.getValue();
IntStream.range(0, additionalServiceReservation.getQuantity()).forEach(i -> {
AdditionalServicePriceContainer pc = AdditionalServicePriceContainer.from(additionalServiceReservation.getAmount(), as, e, discount);
var currencyCode = pc.getCurrencyCode();
additionalServiceItemRepository.insert(UUID.randomUUID().toString(), ZonedDateTime.now(clockProvider.getClock()), transactionId, as.getId(), AdditionalServiceItemStatus.PENDING, eventId, pc.getSrcPriceCts(), unitToCents(pc.getFinalPrice(), currencyCode), unitToCents(pc.getVAT(), currencyCode), unitToCents(pc.getAppliedDiscount(), currencyCode), as.getCurrencyCode());
});
});
}
Aggregations