Skip to content

Commit

Permalink
#110 - don't apply discounts to donations
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Aug 8, 2016
1 parent 9e1aea5 commit a6e42ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public int getSrcPriceCts() {

@Override
public Optional<PromoCodeDiscount> getDiscount() {
return Optional.ofNullable(promoCodeDiscount);
return Optional.ofNullable(promoCodeDiscount).filter(x -> getType() != AdditionalService.AdditionalServiceType.DONATION);
}

@Override
Expand Down Expand Up @@ -123,7 +123,7 @@ public String getFormattedFinalPrice() {
}

public boolean getSupportsDiscount() {
return isFixPrice() && promoCodeDiscount != null;
return getType() != AdditionalService.AdditionalServiceType.DONATION && isFixPrice() && promoCodeDiscount != null;
}

public boolean getUserDefinedPrice() {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public String createTicketReservation(Event event,

ticketReservationRepository.createNewReservation(reservationId, reservationExpiration, discount.map(PromoCodeDiscount::getId).orElse(null), locale.getLanguage());
list.forEach(t -> reserveTicketsForCategory(event, specialPriceSessionId, reservationId, t, locale, forWaitingQueue, discount.orElse(null)));
additionalServices.forEach(as -> reserveAdditionalServicesForReservation(event.getId(), reservationId, as, locale));
additionalServices.forEach(as -> reserveAdditionalServicesForReservation(event.getId(), reservationId, as, locale, discount.orElse(null)));
return reservationId;
}

Expand Down Expand Up @@ -238,8 +238,7 @@ void reserveTicketsForCategory(Event event, Optional<String> specialPriceSession
ticketRepository.updateTicketPrice(reservedForUpdate, category.getId(), event.getId(), category.getSrcPriceCts(), MonetaryUtil.unitToCents(priceContainer.getFinalPrice()), MonetaryUtil.unitToCents(priceContainer.getVAT()), MonetaryUtil.unitToCents(priceContainer.getAppliedDiscount()));
}

private void reserveAdditionalServicesForReservation(int eventId, String transactionId, ASReservationWithOptionalCodeModification additionalServiceReservation, Locale locale) {
//FIXME we don't need to apply discount codes to a donation, therefore this feature is not yet implemented.
private void reserveAdditionalServicesForReservation(int eventId, String transactionId, ASReservationWithOptionalCodeModification additionalServiceReservation, Locale locale, PromoCodeDiscount discount) {
Optional.ofNullable(additionalServiceReservation.getAdditionalServiceId())
.flatMap(id -> optionally(() -> additionalServiceRepository.getById(id, eventId)))
.filter(as -> additionalServiceReservation.getQuantity() > 0 && (as.isFixPrice() || Optional.ofNullable(additionalServiceReservation.getAmount()).filter(a -> a.compareTo(BigDecimal.ZERO) > 0).isPresent()))
Expand All @@ -249,7 +248,7 @@ private void reserveAdditionalServicesForReservation(int eventId, String transac
AdditionalService as = pair.getValue();
IntStream.range(0, additionalServiceReservation.getQuantity())
.forEach(i -> {
AdditionalServicePriceContainer pc = AdditionalServicePriceContainer.from(additionalServiceReservation.getAmount(), as, e, null);
AdditionalServicePriceContainer pc = AdditionalServicePriceContainer.from(additionalServiceReservation.getAmount(), as, e, discount);
additionalServiceItemRepository.insert(UUID.randomUUID().toString(), ZonedDateTime.now(Clock.systemUTC()), transactionId,
as.getId(), AdditionalServiceItemStatus.PENDING, eventId, pc.getSrcPriceCts(), unitToCents(pc.getFinalPrice()), unitToCents(pc.getVAT()), unitToCents(pc.getAppliedDiscount()));
});
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/alfio/model/AdditionalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public enum VatType {
CUSTOM_EXCLUDED
}

public enum AdditionalServiceType {
DONATION
}

private final int id;
private final int eventId;
private final boolean fixPrice;
Expand All @@ -46,6 +50,7 @@ public enum VatType {
private final ZonedDateTime utcExpiration;
private final BigDecimal vat;
private final VatType vatType;
private final AdditionalServiceType type = AdditionalServiceType.DONATION;

private final Integer srcPriceCts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public int getSrcPriceCts() {

@Override
public Optional<PromoCodeDiscount> getDiscount() {
return Optional.ofNullable(promoCodeDiscount);
return Optional.ofNullable(promoCodeDiscount).filter(d -> additionalService.getType() != AdditionalService.AdditionalServiceType.DONATION);
}

@Override
Expand Down

0 comments on commit a6e42ac

Please sign in to comment.