Skip to content

Commit

Permalink
Merge pull request #778 from cbellone/add-counter-for-additional-items
Browse files Browse the repository at this point in the history
display a counter for sold additional items
  • Loading branch information
cbellone committed Sep 25, 2019
2 parents f99072e + a6b81ac commit 16d0065
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/java/alfio/manager/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private Integer findAdditionalService(EventAndOrganizationId event, EventModific
as.getVatType(),
Optional.ofNullable(as.getPrice()).map(MonetaryUtil::unitToCents).orElse(0),
as.getType(),
as.getSupplementPolicy()).getChecksum();
as.getSupplementPolicy(), null).getChecksum();
return additionalServiceRepository.loadAllForEvent(eventId).stream().filter(as1 -> as1.getChecksum().equals(checksum)).findFirst().map(AdditionalService::getId).orElse(null);
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/alfio/model/AdditionalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public boolean isValid(int quantity, AdditionalService as, int selectionCount) {
private final SupplementPolicy supplementPolicy;

private final Integer srcPriceCts;
private final Integer countConfirmed;

public AdditionalService(@Column("id") int id,
@Column("event_id_fk") int eventId,
Expand All @@ -92,7 +93,8 @@ public AdditionalService(@Column("id") int id,
@Column("vat_type") VatType vatType,
@Column("src_price_cts") Integer srcPriceCts,
@Column("service_type") AdditionalServiceType type,
@Column("supplement_policy") SupplementPolicy supplementPolicy) {
@Column("supplement_policy") SupplementPolicy supplementPolicy,
@Column("count_confirmed") Integer countConfirmed) {
this.id = id;
this.eventId = eventId;
this.fixPrice = fixPrice;
Expand All @@ -106,6 +108,7 @@ public AdditionalService(@Column("id") int id,
this.srcPriceCts = srcPriceCts;
this.type = type;
this.supplementPolicy = supplementPolicy;
this.countConfirmed = countConfirmed;
}

public ZonedDateTime getInception(ZoneId zoneId) {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/alfio/model/modification/EventModification.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ public static class AdditionalService {
private final String currencyCode;
private final alfio.model.AdditionalService.AdditionalServiceType type;
private final alfio.model.AdditionalService.SupplementPolicy supplementPolicy;
private final Integer countConfirmed;

@JsonCreator
public AdditionalService(@JsonProperty("id") Integer id,
Expand All @@ -330,7 +331,7 @@ public AdditionalService(@JsonProperty("id") Integer id,
@JsonProperty("description") List<AdditionalServiceText> description,
@JsonProperty("type")alfio.model.AdditionalService.AdditionalServiceType type,
@JsonProperty("supplementPolicy")alfio.model.AdditionalService.SupplementPolicy supplementPolicy) {
this(id, price, fixPrice, ordinal, availableQuantity, maxQtyPerOrder, inception, expiration, vat, vatType, additionalServiceFields, title, description, null, null, type, supplementPolicy);
this(id, price, fixPrice, ordinal, availableQuantity, maxQtyPerOrder, inception, expiration, vat, vatType, additionalServiceFields, title, description, null, null, type, supplementPolicy, null);
}

private AdditionalService(Integer id,
Expand All @@ -349,7 +350,8 @@ private AdditionalService(Integer id,
BigDecimal finalPrice,
String currencyCode,
alfio.model.AdditionalService.AdditionalServiceType type,
alfio.model.AdditionalService.SupplementPolicy supplementPolicy) {
alfio.model.AdditionalService.SupplementPolicy supplementPolicy,
Integer countConfirmed) {
this.id = id;
this.price = price;
this.fixPrice = fixPrice;
Expand All @@ -367,6 +369,7 @@ private AdditionalService(Integer id,
this.currencyCode = currencyCode;
this.type = type;
this.supplementPolicy = supplementPolicy;
this.countConfirmed = countConfirmed;
}

public static Builder from(alfio.model.AdditionalService src) {
Expand Down Expand Up @@ -411,7 +414,7 @@ public AdditionalService build() {
String currencyCode = priceContainer.map(PriceContainer::getCurrencyCode).orElse("");
return new AdditionalService(src.getId(), Optional.ofNullable(src.getSrcPriceCts()).map(MonetaryUtil::centsToUnit).orElse(BigDecimal.ZERO),
src.isFixPrice(), src.getOrdinal(), src.getAvailableQuantity(), src.getMaxQtyPerOrder(), DateTimeModification.fromZonedDateTime(src.getInception(zoneId)),
DateTimeModification.fromZonedDateTime(src.getExpiration(zoneId)), src.getVat(), src.getVatType(), additionalServiceFields, title, description, finalPrice, currencyCode, src.getType(), src.getSupplementPolicy());
DateTimeModification.fromZonedDateTime(src.getExpiration(zoneId)), src.getVat(), src.getVatType(), additionalServiceFields, title, description, finalPrice, currencyCode, src.getType(), src.getSupplementPolicy(), src.getCountConfirmed());
}

}
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/alfio/repository/AdditionalServiceRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
@QueryRepository
public interface AdditionalServiceRepository {

@Query("select * from additional_service where event_id_fk = :eventId order by ordinal")
String SELECT_PREFIX = "select distinct(ads.*), sum(case asi.status when 'ACQUIRED' then 1 else 0 end) as count_confirmed from additional_service ads left join additional_service_item asi on asi.additional_service_id_fk = ads.id where ads.event_id_fk = :eventId";
String SELECT_SUFFIX = " group by ads.id order by ads.ordinal";

@Query(SELECT_PREFIX + SELECT_SUFFIX)
List<AdditionalService> loadAllForEvent(@Bind("eventId") int eventId);

NamedParameterJdbcTemplate getJdbcTemplate();
Expand All @@ -43,10 +46,13 @@ default Map<Integer, Integer> getCount(int eventId) {
return res;
}

@Query("select * from additional_service where id = :id and event_id_fk = :eventId")
@Query(SELECT_PREFIX + " and ads.supplement_policy = :supplementPolicy" + SELECT_SUFFIX)
List<AdditionalService> findAllInEventWithPolicy(@Bind("eventId") int eventId, @Bind("supplementPolicy") AdditionalService.SupplementPolicy policy);

@Query(SELECT_PREFIX + " and ads.id = :id" + SELECT_SUFFIX)
AdditionalService getById(@Bind("id") int id, @Bind("eventId") int eventId);

@Query("select * from additional_service where id = :id and event_id_fk = :eventId")
@Query(SELECT_PREFIX + " and ads.id = :id" + SELECT_SUFFIX)
Optional<AdditionalService> getOptionalById(@Bind("id") int id, @Bind("eventId") int eventId);

@Query("delete from additional_service where id = :id and event_id_fk = :eventId")
Expand All @@ -69,6 +75,4 @@ int update(@Bind("id") int id, @Bind("fixPrice") boolean fixPrice,
@Bind("inceptionTs") ZonedDateTime inception, @Bind("expirationTs") ZonedDateTime expiration, @Bind("vat") BigDecimal vat,
@Bind("vatType") AdditionalService.VatType vatType, @Bind("srcPriceCts") int srcPriceCts);

@Query("select * from additional_service where event_id_fk = :eventId and supplement_policy = :supplementPolicy order by ordinal")
List<AdditionalService> findAllInEventWithPolicy(@Bind("eventId") int eventId, @Bind("supplementPolicy") AdditionalService.SupplementPolicy policy);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ <h3><i class="fa {{ctrl.icon}}"></i> {{ctrl.title}}</h3>
<div class="panel-heading">
<div class="panel-title">
<div class="row">
<div class="col-xs-9">
<div class="h4"><span data-ng-repeat="pair in item.zippedTitleAndDescriptions" title="{{pair[0].locale}}"><span ng-class="{'text-danger': pair[0].value === ''}">{{pair[0] | showMissingASText}}</span> <span data-ng-if="!$last"> / </span></span></div>
<div class="col-xs-7">
<div class="h4">
<span data-ng-repeat="pair in item.zippedTitleAndDescriptions" title="{{pair[0].locale}}"><span ng-class="{'text-danger': pair[0].value === ''}">{{pair[0] | showMissingASText}}</span> <span data-ng-if="!$last"> / </span></span>
</div>
</div>
<div class="col-xs-3">
<div class="col-xs-2 col-md-1">
<div class="h4">
<span class="label label-sm label-success" data-ng-if="item.countConfirmed > 0"><span class="hidden visible-md-inline visible-lg-inline">Confirmed: </span>{{item.countConfirmed}}</span></div>
</div>
<div class="col-xs-3 col-md-4">
<div class="pull-right">
<button class="btn btn-sm btn-default" title="edit" data-ng-click="ctrl.edit(item)" type="button"><i class="fa fa-edit"></i> edit</button>
<button class="btn btn-sm btn-default" ng-if="!(ctrl.additionalServiceUseCount[item.id] > 0)" title="delete" data-ng-click="ctrl.delete(item)" type="button"><i class="fa fa-trash"></i> delete</button>
Expand Down

0 comments on commit 16d0065

Please sign in to comment.