From 618d83220b98f68b04a12aa8afec58ba4bd5ac1b Mon Sep 17 00:00:00 2001 From: Sylvain Jermini Date: Sun, 24 Jun 2018 15:06:13 +0200 Subject: [PATCH] #464 import initial model changes --- .../alfio/controller/form/PaymentForm.java | 6 ++ .../manager/TicketReservationManager.java | 22 +++++++ .../TicketReservationAdditionalInfo.java | 59 +++++++++++++++++++ .../TicketReservationRepository.java | 38 ++++++++++++ .../V23_2.0.0.0__NEW_RESERVATION_FLOW.sql | 29 +++++++++ 5 files changed, 154 insertions(+) create mode 100644 src/main/java/alfio/model/TicketReservationAdditionalInfo.java create mode 100644 src/main/resources/alfio/db/PGSQL/V23_2.0.0.0__NEW_RESERVATION_FLOW.sql diff --git a/src/main/java/alfio/controller/form/PaymentForm.java b/src/main/java/alfio/controller/form/PaymentForm.java index cb9c255564..ee80ec108b 100644 --- a/src/main/java/alfio/controller/form/PaymentForm.java +++ b/src/main/java/alfio/controller/form/PaymentForm.java @@ -59,6 +59,12 @@ public class PaymentForm implements Serializable { private String vatNr; private boolean invoiceRequested = false; private Map tickets = new HashMap<>(); + // + private String billingAddressCompany; + private String billingAddressLine1; + private String billingAddressLine2; + private String billingAddressZip; + private String billingAddressCity; private static void rejectIfOverLength(BindingResult bindingResult, String field, String errorCode, String value, int maxLength) { diff --git a/src/main/java/alfio/manager/TicketReservationManager.java b/src/main/java/alfio/manager/TicketReservationManager.java index da7dba4bf0..bbe05a5e05 100644 --- a/src/main/java/alfio/manager/TicketReservationManager.java +++ b/src/main/java/alfio/manager/TicketReservationManager.java @@ -1412,4 +1412,26 @@ void revertTicketsToFreeIfAccessRestricted(int eventId) { } } } + + + public void updateReservation(String reservationId, CustomerName customerName, String email, + String billingAddressCompany, String billingAddressLine1, String billingAddressLine2, + String billingAddressZip, String billingAddressCity, String vatCountryCode, String customerReference, + String vatNr, + boolean isInvoiceRequested, + boolean addCompanyBillingDetails, + boolean validated) { + + String completeBillingAddress = StringUtils.trimToEmpty(billingAddressCompany)+"\n"+ + StringUtils.trimToEmpty(billingAddressLine1)+"\n"+ + StringUtils.trimToEmpty(billingAddressLine2)+"\n"+ + StringUtils.trimToEmpty(StringUtils.trimToEmpty(billingAddressZip)+" "+StringUtils.trimToEmpty(billingAddressCity)); + + completeBillingAddress = completeBillingAddress.replace("\n\n", "\n"); + + ticketReservationRepository.updateTicketReservationWithValidation(reservationId, + customerName.getFullName(), customerName.getFirstName(), customerName.getLastName(), + email, billingAddressCompany, billingAddressLine1, billingAddressLine2, billingAddressZip, + billingAddressCity, completeBillingAddress, vatCountryCode, vatNr, isInvoiceRequested, addCompanyBillingDetails, customerReference, validated); + } } diff --git a/src/main/java/alfio/model/TicketReservationAdditionalInfo.java b/src/main/java/alfio/model/TicketReservationAdditionalInfo.java new file mode 100644 index 0000000000..6a7a8545c0 --- /dev/null +++ b/src/main/java/alfio/model/TicketReservationAdditionalInfo.java @@ -0,0 +1,59 @@ +/** + * 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 . + */ +package alfio.model; + +import ch.digitalfondue.npjt.ConstructorAnnotationRowMapper.Column; +import lombok.Getter; + +import java.util.Optional; + +@Getter +public class TicketReservationAdditionalInfo { + + private final String billingAddressCompany; + private final String billingAddressLine1; + private final String billingAddressLine2; + private final String billingAddressZip; + private final String billingAddressCity; + private final Boolean validated; + private final Boolean addCompanyBillingDetails; + + public TicketReservationAdditionalInfo(@Column("billing_address_company") String billingAddressCompany, + @Column("billing_address_line1") String billingAddressLine1, + @Column("billing_address_line2") String billingAddressLine2, + @Column("billing_address_zip") String billingAddressZip, + @Column("billing_address_city") String billingAddressCity, + @Column("validated_for_overview") Boolean validated, + @Column("add_company_billing_details") Boolean addCompanyBillingDetails) { + this.billingAddressCompany = billingAddressCompany; + this.billingAddressLine1 = billingAddressLine1; + this.billingAddressLine2 = billingAddressLine2; + this.billingAddressZip = billingAddressZip; + this.billingAddressCity = billingAddressCity; + this.validated = validated; + this.addCompanyBillingDetails = addCompanyBillingDetails; + } + + + public boolean hasBeenValidated() { + return Optional.ofNullable(validated).orElse(false); + } + + public boolean hasAddCompanyBillingDetails() { + return Optional.ofNullable(addCompanyBillingDetails).orElse(false); + } +} \ No newline at end of file diff --git a/src/main/java/alfio/repository/TicketReservationRepository.java b/src/main/java/alfio/repository/TicketReservationRepository.java index c57c13733c..0762f459ad 100644 --- a/src/main/java/alfio/repository/TicketReservationRepository.java +++ b/src/main/java/alfio/repository/TicketReservationRepository.java @@ -165,4 +165,42 @@ int updateBillingData(@Bind("vatStatus") PriceContainer.VatStatus vatStatus, @Query("select * from tickets_reservation where id in (:ids)") List findByIds(@Bind("ids") Collection ids); + + @Query("update tickets_reservation set full_name = :fullName, first_name = :firstName, last_name = :lastName, email_address = :email, " + + " billing_address = :completeBillingAddress, vat_country = :vatCountry, vat_nr = :vatNr, " + + " invoice_requested = :invoiceRequested, " + + " billing_address_company = :billingAddressCompany, " + + " billing_address_line1 = :billingAddressLine1, " + + " billing_address_line2 = :billingAddressLine2, " + + " billing_address_zip = :billingAddressZip, " + + " billing_address_city = :billingAddressCity, " + + " add_company_billing_details = :addCompanyBillingDetails, " + + " customer_reference = :customerReference, "+ + " validated_for_overview = :validated " + + " where id = :reservationId") + int updateTicketReservationWithValidation(@Bind("reservationId") String reservationId, + @Bind("fullName") String fullName, + @Bind("firstName") String firstName, + @Bind("lastName") String lastName, + @Bind("email") String email, + @Bind("billingAddressCompany") String billingAddressCompany, + @Bind("billingAddressLine1") String billingAddressLine1, + @Bind("billingAddressLine2") String billingAddressLine2, + @Bind("billingAddressZip") String billingAddressZip, + @Bind("billingAddressCity") String billingAddressCity, + @Bind("completeBillingAddress") String completeBillingAddress, + @Bind("vatCountry") String vatCountry, + @Bind("vatNr") String vatNr, + @Bind("invoiceRequested") boolean invoiceRequested, + @Bind("addCompanyBillingDetails") boolean addCompanyBillingDetails, + @Bind("customerReference") String customerReference, + @Bind("validated") boolean validated); + + + @Query("select billing_address_company, billing_address_line1, billing_address_line2, " + + " billing_address_zip, billing_address_city, validated_for_overview, add_company_billing_details from tickets_reservation where id = :id") + TicketReservationAdditionalInfo getAdditionalInfo(@Bind("id") String reservationId); + + @Query("update tickets_reservation set validated_for_overview = :validated where id = :reservationId") + int updateValidationStatus(@Bind("reservationId") String reservationId, @Bind("validated") boolean validated); } diff --git a/src/main/resources/alfio/db/PGSQL/V23_2.0.0.0__NEW_RESERVATION_FLOW.sql b/src/main/resources/alfio/db/PGSQL/V23_2.0.0.0__NEW_RESERVATION_FLOW.sql new file mode 100644 index 0000000000..ed31dc711d --- /dev/null +++ b/src/main/resources/alfio/db/PGSQL/V23_2.0.0.0__NEW_RESERVATION_FLOW.sql @@ -0,0 +1,29 @@ +-- +-- 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 . +-- + +alter table tickets_reservation add column billing_address_company varchar(512); +alter table tickets_reservation add column billing_address_line1 varchar(512); +alter table tickets_reservation add column billing_address_line2 varchar(512); +alter table tickets_reservation add column billing_address_zip varchar(512); +alter table tickets_reservation add column billing_address_city varchar(512); +alter table tickets_reservation add column validated_for_overview boolean; +alter table tickets_reservation add column add_company_billing_details boolean; + + +drop view if exists reservation_and_ticket_and_tx; +drop view if exists ticket_and_reservation_and_tx; +alter table tickets_reservation alter column billing_address TYPE varchar(4096);