Skip to content

Commit

Permalink
#449 invoice enhancements (#450)
Browse files Browse the repository at this point in the history
* #449 - add total net price

* #449 - add category info to tickets in invoice
add creation timestamp on reservation

* #449 - mysql 5.5 compatibility

* #449 - better backward compatibility

* #449 - insert creation date
  • Loading branch information
cbellone committed May 22, 2018
1 parent ea523ba commit 6ea42cd
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/main/java/alfio/manager/AdminReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private Result<Pair<TicketReservation, List<Ticket>>> createReservation(Result<L
String reservationId = UUID.randomUUID().toString();
String specialPriceSessionId = UUID.randomUUID().toString();
Date validity = Date.from(arm.getExpiration().toZonedDateTime(event.getZoneId()).toInstant());
ticketReservationRepository.createNewReservation(reservationId, validity, null, arm.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
ticketReservationRepository.createNewReservation(reservationId, ZonedDateTime.now(event.getZoneId()), validity, null, arm.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
AdminReservationModification.CustomerData customerData = arm.getCustomerData();
ticketReservationRepository.updateTicketReservation(reservationId, TicketReservationStatus.PENDING.name(), customerData.getEmailAddress(), customerData.getFullName(), customerData.getFirstName(), customerData.getLastName(), arm.getLanguage(), null, null, null);

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public String createTicketReservation(Event event,

Optional<PromoCodeDiscount> discount = promotionCodeDiscount.flatMap((promoCodeDiscount) -> promoCodeDiscountRepository.findPromoCodeInEventOrOrganization(event.getId(), promoCodeDiscount));

ticketReservationRepository.createNewReservation(reservationId, reservationExpiration, discount.map(PromoCodeDiscount::getId).orElse(null), locale.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
ticketReservationRepository.createNewReservation(reservationId, ZonedDateTime.now(event.getZoneId()), reservationExpiration, discount.map(PromoCodeDiscount::getId).orElse(null), locale.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
list.forEach(t -> reserveTicketsForCategory(event, specialPriceSessionId, reservationId, t, locale, forWaitingQueue, discount.orElse(null)));

int ticketCount = list
Expand Down 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
8 changes: 8 additions & 0 deletions src/main/java/alfio/model/OrderSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package alfio.model;

import alfio.util.MonetaryUtil;
import lombok.Data;

import java.util.List;
Expand Down Expand Up @@ -69,4 +70,11 @@ public boolean isVatExempt() {
public String getRefundedAmount() {
return refundedAmount;
}

public String getTotalNetPrice() {
if(free) {
return null;
}
return MonetaryUtil.formatCents(originalTotalPrice.getPriceWithVAT() - originalTotalPrice.getVAT());
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
@QueryRepository
public interface TicketReservationRepository {

@Query("insert into tickets_reservation(id, validity, promo_code_id_fk, status, user_language, event_id_fk, used_vat_percent, vat_included) values (:id, :validity, :promotionCodeDiscountId, 'PENDING', :userLanguage, :eventId, :eventVat, :vatIncluded)")
int createNewReservation(@Bind("id") String id, @Bind("validity") Date validity,
@Query("insert into tickets_reservation(id, creation_ts, validity, promo_code_id_fk, status, user_language, event_id_fk, used_vat_percent, vat_included) values (:id, :creationTimestamp, :validity, :promotionCodeDiscountId, 'PENDING', :userLanguage, :eventId, :eventVat, :vatIncluded)")
int createNewReservation(@Bind("id") String id,
@Bind("creationTimestamp") ZonedDateTime creationTimestamp,
@Bind("validity") Date validity,
@Bind("promotionCodeDiscountId") Integer promotionCodeDiscountId, @Bind("userLanguage") String userLanguage,
@Bind("eventId") int eventId,
@Bind("eventVat") BigDecimal eventVat,
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
Loading

0 comments on commit 6ea42cd

Please sign in to comment.