Skip to content

Commit

Permalink
#449 - add category info to tickets in invoice
Browse files Browse the repository at this point in the history
add creation timestamp on reservation
  • Loading branch information
cbellone committed May 21, 2018
1 parent 3539cc1 commit d75e6fe
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 15 deletions.
10 changes: 8 additions & 2 deletions src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,19 @@ public void deleteOfflinePayment(Event event, String reservationId, boolean expi
@Transactional(readOnly = true)
public Map<String, Object> prepareModelForReservationEmail(Event event, TicketReservation reservation, Optional<String> vat, OrderSummary summary) {
Organization organization = organizationRepository.getById(event.getOrganizationId());
List<Ticket> tickets = findTicketsInReservation(reservation.getId());
String reservationUrl = reservationUrl(reservation.getId());
String reservationShortID = getShortReservationID(event, reservation.getId());
Optional<String> invoiceAddress = configurationManager.getStringConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.INVOICE_ADDRESS));
Optional<String> bankAccountNr = configurationManager.getStringConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.BANK_ACCOUNT_NR));
Optional<String> bankAccountOwner = configurationManager.getStringConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.BANK_ACCOUNT_OWNER));
return TemplateResource.prepareModelForConfirmationEmail(organization, event, reservation, vat, tickets, summary, reservationUrl, reservationShortID, invoiceAddress, bankAccountNr, bankAccountOwner);
Map<Integer, List<Ticket>> ticketsByCategory = ticketRepository.findTicketsInReservation(reservation.getId())
.stream()
.collect(groupingBy(Ticket::getCategoryId));
List<TicketWithCategory> ticketsWithCategory = ticketCategoryRepository.findByIds(ticketsByCategory.keySet())
.stream()
.flatMap(tc -> ticketsByCategory.get(tc.getId()).stream().map(t -> new TicketWithCategory(t, tc)))
.collect(Collectors.toList());
return TemplateResource.prepareModelForConfirmationEmail(organization, event, reservation, vat, ticketsWithCategory, summary, reservationUrl, reservationShortID, invoiceAddress, bankAccountNr, bankAccountOwner);
}

@Transactional(readOnly = true)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/alfio/model/FullTicketInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public FullTicketInfo(@Column("t_id") int id,
@Column("tr_invoice_requested") boolean invoiceRequested,
@Column("tr_used_vat_percent") BigDecimal usedVatPercent,
@Column("tr_vat_included") Boolean vatIncluded,
@Column("tr_creation_ts") ZonedDateTime reservationCreationTimestamp,
//
//
@Column("tc_id") int tcId,
Expand All @@ -102,7 +103,7 @@ public FullTicketInfo(@Column("t_id") int id,
lockedAssignment, userLanguage, ticketSrcPriceCts, ticketFinalPriceCts, ticketVatCts, ticketDiscountCts, extReference);
this.ticketReservation = new TicketReservation(trId, trValidity, trStatus, trFullName, trFirstName, trLastName, trEmail, trBillingAddress,
trConfirmationTimestamp, trLatestReminder, trPaymentMethod, trReminderSent, trPromoCodeDiscountId, trAutomatic, resUserLanguage,
directAssignment, invoiceNumber, invoiceModel, reservationVatStatus, vatNr, vatCountry, invoiceRequested, usedVatPercent, vatIncluded);
directAssignment, invoiceNumber, invoiceModel, reservationVatStatus, vatNr, vatCountry, invoiceRequested, usedVatPercent, vatIncluded, reservationCreationTimestamp);
this.ticketCategory = new TicketCategory(tcId, tcUtcInception, tcUtcExpiration, tcMaxTickets, tcName,
tcAccessRestricted, tcStatus, tcEventId, bounded, tcSrcPriceCts, code, validCheckInFrom, validCheckInTo,
ticketValidityStart, ticketValidityEnd);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/alfio/model/TicketCSVInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ public TicketCSVInfo(@Column("t_id") int id,
@Column("tr_vat_country") String vatCountry,
@Column("tr_invoice_requested") boolean invoiceRequested,
@Column("tr_used_vat_percent") BigDecimal usedVatPercent,
@Column("tr_vat_included") Boolean vatIncluded) {
@Column("tr_vat_included") Boolean vatIncluded,
@Column("tr_creation_ts") ZonedDateTime reservationCreationTimestamp) {

this.ticket = new Ticket(id, uuid, creation, categoryId, status, eventId, ticketsReservationId, fullName, firstName, lastName, email,
lockedAssignment, userLanguage, ticketSrcPriceCts, ticketFinalPriceCts, ticketVatCts, ticketDiscountCts, extReference);
this.ticketReservation = new TicketReservation(trId, trValidity, trStatus, trFullName, trFirstName, trLastName, trEmail, trBillingAddress,
trConfirmationTimestamp, trLatestReminder, trPaymentMethod, trReminderSent, trPromoCodeDiscountId, trAutomatic, resUserLanguage, directAssignment,
invoiceNumber, invoiceModel, reservationVatStatus, vatNr, vatCountry, invoiceRequested, usedVatPercent, vatIncluded);
invoiceNumber, invoiceModel, reservationVatStatus, vatNr, vatCountry, invoiceRequested, usedVatPercent, vatIncluded, reservationCreationTimestamp);
}
}
5 changes: 4 additions & 1 deletion src/main/java/alfio/model/TicketReservation.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public enum TicketReservationStatus {
private final boolean invoiceRequested;
private final BigDecimal usedVatPercent;
private final Boolean vatIncluded;
private final ZonedDateTime creationTimestamp;

public TicketReservation(@Column("id") String id,
@Column("validity") Date validity,
Expand All @@ -84,7 +85,8 @@ public TicketReservation(@Column("id") String id,
@Column("vat_country") String vatCountryCode,
@Column("invoice_requested") boolean invoiceRequested,
@Column("used_vat_percent") BigDecimal usedVatPercent,
@Column("vat_included") Boolean vatIncluded) {
@Column("vat_included") Boolean vatIncluded,
@Column("creation_ts") ZonedDateTime creationTimestamp) {
this.id = id;
this.validity = validity;
this.status = status;
Expand All @@ -109,6 +111,7 @@ public TicketReservation(@Column("id") String id,
this.invoiceRequested = invoiceRequested;
this.usedVatPercent = usedVatPercent;
this.vatIncluded = vatIncluded;
this.creationTimestamp = creationTimestamp;
}

public boolean isStuck() {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/alfio/model/TicketWithCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* This file is part of alf.io.
*
* alf.io is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* alf.io is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with alf.io. If not, see <http://www.gnu.org/licenses/>.
*/
package alfio.model;

import lombok.RequiredArgsConstructor;
import lombok.experimental.Delegate;

@RequiredArgsConstructor
public class TicketWithCategory {

@Delegate
private final Ticket ticket;
private final TicketCategory category;

public String getCategoryName() {
return category.getName();
}

public TicketCategory getCategory() {
return category;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public TicketWithReservationAndTransaction(@Column("t_id") Integer id,
@Column("tr_invoice_requested") boolean invoiceRequested,
@Column("tr_used_vat_percent") BigDecimal usedVadPercent,
@Column("tr_vat_included") Boolean vatIncluded,
@Column("tr_creation_ts") ZonedDateTime reservationCreationTimestamp,
//
@Column("bt_id") Integer btId,
@Column("bt_gtw_tx_id") String transactionId,
Expand All @@ -102,7 +103,7 @@ public TicketWithReservationAndTransaction(@Column("t_id") Integer id,
billingAddress, confirmationTimestamp, latestReminder, paymentMethod,
reminderSent, promoCodeDiscountId, automatic, trUserLanguage,
directAssignmentRequested, invoiceNumber, invoiceModel, vatStatus, vatNr, vatCountryCode, invoiceRequested,
usedVadPercent, vatIncluded);
usedVadPercent, vatIncluded, reservationCreationTimestamp);

if(btId != null) {
this.transaction = Optional.of(new Transaction(btId, transactionId, paymentId, reservationId,
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/alfio/repository/TicketCategoryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ch.digitalfondue.npjt.*;

import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -56,6 +57,9 @@ AffectedRowCountAndKey<Integer> insert(@Bind("inception") ZonedDateTime inceptio
@Query("select * from ticket_category where id = :id")
TicketCategory getById(@Bind("id") int id);

@Query("select * from ticket_category where id in(:ids)")
List<TicketCategory> findByIds(@Bind("ids") Collection<Integer> ids);

@Query("select * from ticket_category where event_id = :eventId and category_code = :code and tc_status = 'ACTIVE'")
Optional<TicketCategory> findCodeInEvent(@Bind("eventId") int eventId, @Bind("code") String code);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/alfio/repository/TicketRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public interface TicketRepository {
" tr.id tr_id, tr.validity tr_validity, tr.status tr_status, tr.full_name tr_full_name, tr.first_name tr_first_name, tr.last_name tr_last_name, tr.email_address tr_email_address, tr.billing_address tr_billing_address," +
" tr.confirmation_ts tr_confirmation_ts, tr.latest_reminder_ts tr_latest_reminder_ts, tr.payment_method tr_payment_method, " +
" tr.offline_payment_reminder_sent tr_offline_payment_reminder_sent, tr.promo_code_id_fk tr_promo_code_id_fk, tr.automatic tr_automatic, tr.user_language tr_user_language, tr.direct_assignment tr_direct_assignment, tr.invoice_number tr_invoice_number, tr.invoice_model tr_invoice_model, " +
" tr.vat_status tr_vat_status, tr.vat_nr tr_vat_nr, tr.vat_country tr_vat_country, tr.invoice_requested tr_invoice_requested, tr.used_vat_percent tr_used_vat_percent, tr.vat_included tr_vat_included, " +
" tr.vat_status tr_vat_status, tr.vat_nr tr_vat_nr, tr.vat_country tr_vat_country, tr.invoice_requested tr_invoice_requested, tr.used_vat_percent tr_used_vat_percent, tr.vat_included tr_vat_included, tr.creation_ts tr_creation_ts, " +
" tc.id tc_id, tc.inception tc_inception, tc.expiration tc_expiration, tc.max_tickets tc_max_tickets, tc.name tc_name, tc.src_price_cts tc_src_price_cts, tc.access_restricted tc_access_restricted, tc.tc_status tc_tc_status, tc.event_id tc_event_id, tc.bounded tc_bounded, tc.category_code tc_category_code, " +
" tc.valid_checkin_from tc_valid_checkin_from, tc.valid_checkin_to tc_valid_checkin_to, tc.ticket_validity_start tc_ticket_validity_start, tc.ticket_validity_end tc_ticket_validity_end" +
" from ticket t " +
Expand Down Expand Up @@ -211,7 +211,7 @@ public interface TicketRepository {
" tr.id tr_id, tr.validity tr_validity, tr.status tr_status, tr.full_name tr_full_name, tr.first_name tr_first_name, tr.last_name tr_last_name, tr.email_address tr_email_address, tr.billing_address tr_billing_address," +
" tr.confirmation_ts tr_confirmation_ts, tr.latest_reminder_ts tr_latest_reminder_ts, tr.payment_method tr_payment_method, tr.offline_payment_reminder_sent tr_offline_payment_reminder_sent, tr.promo_code_id_fk tr_promo_code_id_fk, tr.automatic tr_automatic, tr.user_language tr_user_language, tr.direct_assignment tr_direct_assignment, " +
" tr.vat_status tr_vat_status, tr.vat_nr tr_vat_nr, tr.vat_country tr_vat_country, tr.invoice_requested tr_invoice_requested, tr.used_vat_percent tr_used_vat_percent, tr.vat_included tr_vat_included, " +
" tr.invoice_number tr_invoice_number, tr.invoice_model tr_invoice_model from ticket t, tickets_reservation tr where t.event_id = :eventId and t.status in(" + CONFIRMED + ") and t.tickets_reservation_id = tr.id order by tr.confirmation_ts")
" tr.invoice_number tr_invoice_number, tr.invoice_model tr_invoice_model, tr.creation_ts tr_creation_ts from ticket t, tickets_reservation tr where t.event_id = :eventId and t.status in(" + CONFIRMED + ") and t.tickets_reservation_id = tr.id order by tr.confirmation_ts")
List<TicketCSVInfo> findAllConfirmedForCSV(@Bind("eventId") int eventId);

@Query("select a.*, b.confirmation_ts from ticket a, tickets_reservation b where a.event_id = :eventId and a.status in(" + CONFIRMED + ") and a.tickets_reservation_id = b.id order by b.confirmation_ts")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/alfio/repository/TicketSearchRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface TicketSearchRepository {
"tr_offline_payment_reminder_sent offline_payment_reminder_sent, tr_promo_code_id_fk promo_code_id_fk, tr_automatic automatic," +
"tr_user_language user_language, tr_direct_assignment direct_assignment, tr_invoice_number invoice_number, tr_invoice_model invoice_model," +
"tr_vat_status vat_status, tr_vat_nr vat_nr, tr_vat_country vat_country, tr_invoice_requested invoice_requested, tr_used_vat_percent used_vat_percent," +
"tr_vat_included vat_included";
"tr_vat_included vat_included, tr_creation_ts creation_ts";

@Query("select * from (" + FIND_ALL_MODIFIED_TICKETS_WITH_RESERVATION_AND_TRANSACTION + " limit :pageSize offset :page) as d_tbl order by tr_confirmation_ts asc, tr_id, t_uuid")
List<TicketWithReservationAndTransaction> findAllModifiedTicketsWithReservationAndTransaction(@Bind("eventId") int eventId,
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/alfio/util/TemplateResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ private static Ticket sampleTicket() {
return sampleTicket("Firstname", "Lastname", "[email protected]");
}

private static TicketCategory sampleCategory() {
return new TicketCategory(0, ZonedDateTime.now().minusDays(1), ZonedDateTime.now().plusDays(1), 100, "test category", false, TicketCategory.Status.ACTIVE,
0, true, 100, null, null, null, null, null);
}

private static Ticket sampleTicket(String firstName, String lastName, String email) {
return new Ticket(0, "597e7e7b-c514-4dcb-be8c-46cf7fe2c36e", ZonedDateTime.now(), 0, "ACQUIRED", 0,
"597e7e7b-c514-4dcb-be8c-46cf7fe2c36e", firstName + " " + lastName, firstName, lastName, email, false, "en",
Expand All @@ -214,13 +219,15 @@ private static Ticket sampleTicket(String firstName, String lastName, String ema
private static TicketReservation sampleTicketReservation() {
return new TicketReservation("597e7e7b-c514-4dcb-be8c-46cf7fe2c36e", new Date(), TicketReservation.TicketReservationStatus.COMPLETE,
"Firstname Lastname", "FirstName", "Lastname", "[email protected]", "billing address", ZonedDateTime.now(), ZonedDateTime.now(),
PaymentProxy.STRIPE, true, null, false, "en", false, null, null, null, "123456", "CH", false, new BigDecimal("8.00"), true);
PaymentProxy.STRIPE, true, null, false, "en", false, null, null, null, "123456",
"CH", false, new BigDecimal("8.00"), true,
ZonedDateTime.now().minusMinutes(1));
}

private static Map<String, Object> prepareSampleDataForConfirmationEmail(Organization organization, Event event) {
TicketReservation reservation = sampleTicketReservation();
Optional<String> vat = Optional.of("VAT-NR");
List<Ticket> tickets = Collections.singletonList(sampleTicket());
List<TicketWithCategory> tickets = Collections.singletonList(new TicketWithCategory(sampleTicket(), sampleCategory()));
OrderSummary orderSummary = new OrderSummary(new TotalPrice(1000, 80, 0, 0),
Collections.singletonList(new SummaryRow("Ticket", "10.00", "9.20", 1, "9.20", "9.20", 1000, SummaryRow.SummaryType.TICKET)), false, "10.00", "0.80", false, false, "8", PriceContainer.VatStatus.INCLUDED, "1.00");
String reservationUrl = "http://your-domain.tld/reservation-url/";
Expand All @@ -240,7 +247,7 @@ public static Map<String, Object> prepareModelForConfirmationEmail(Organization
Event event,
TicketReservation reservation,
Optional<String> vat,
List<Ticket> tickets,
List<TicketWithCategory> tickets,
OrderSummary orderSummary,
String reservationUrl,
String reservationShortID,
Expand All @@ -260,8 +267,8 @@ public static Map<String, Object> prepareModelForConfirmationEmail(Organization

model.put("hasRefund", StringUtils.isNotEmpty(orderSummary.getRefundedAmount()));

ZonedDateTime confirmationTimestamp = Optional.ofNullable(reservation.getConfirmationTimestamp()).orElseGet(ZonedDateTime::now);
model.put("confirmationDate", confirmationTimestamp.withZoneSameInstant(event.getZoneId()));
ZonedDateTime creationTimestamp = Optional.ofNullable(reservation.getCreationTimestamp()).orElseGet(ZonedDateTime::now);
model.put("confirmationDate", creationTimestamp.withZoneSameInstant(event.getZoneId()));

if (reservation.getValidity() != null) {
model.put("expirationDate", ZonedDateTime.ofInstant(reservation.getValidity().toInstant(), event.getZoneId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ create view reservation_and_ticket_and_tx as (select
tickets_reservation.used_vat_percent tr_used_vat_percent,
tickets_reservation.vat_included tr_vat_included,
tickets_reservation.event_id_fk tr_event_id,
tickets_reservation.creation_ts tr_creation_ts,

ticket.id t_id,
ticket.uuid t_uuid,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--
-- This file is part of alf.io.
--
-- alf.io is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- alf.io is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with alf.io. If not, see <http://www.gnu.org/licenses/>.
--

alter table tickets_reservation add column creation_ts timestamp with time zone;

update tickets_reservation set creation_ts = coalesce(confirmation_ts, (select event_time from auditing where reservation_id = id and event_type = 'RESERVATION_CREATE'))
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ create view reservation_and_ticket_and_tx as (select
tickets_reservation.used_vat_percent tr_used_vat_percent,
tickets_reservation.vat_included tr_vat_included,
tickets_reservation.event_id_fk tr_event_id,
tickets_reservation.creation_ts tr_creation_ts,

ticket.id t_id,
ticket.uuid t_uuid,
Expand Down
Loading

0 comments on commit d75e6fe

Please sign in to comment.