Skip to content

Commit

Permalink
#433 show iso country when selecting the vat validation + fix for GR/…
Browse files Browse the repository at this point in the history
…EL+UK->GB (#442)

(cherry picked from commit 10c9c63)
  • Loading branch information
syjer authored and cbellone committed May 20, 2018
1 parent c8e0d15 commit 9e0e266
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import alfio.model.TicketReservation.TicketReservationStatus;
import alfio.model.result.ValidationResult;
import alfio.model.system.Configuration;
import alfio.model.system.ConfigurationKeys;
import alfio.model.transaction.PaymentProxy;
import alfio.model.user.Organization;
import alfio.repository.EventRepository;
Expand Down Expand Up @@ -59,6 +60,7 @@
import java.util.*;
import java.util.stream.Collectors;

import static alfio.model.system.Configuration.getSystemConfiguration;
import static alfio.model.system.ConfigurationKeys.*;
import static java.util.stream.Collectors.toList;

Expand Down Expand Up @@ -150,7 +152,7 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
if(orderSummary.getFree() || activePaymentMethods.stream().anyMatch(p -> p == PaymentProxy.OFFLINE || p == PaymentProxy.ON_SITE)) {
boolean captchaForOfflinePaymentEnabled = configurationManager.isRecaptchaForOfflinePaymentEnabled(event);
model.addAttribute("captchaRequestedForOffline", captchaForOfflinePaymentEnabled)
.addAttribute("recaptchaApiKey", configurationManager.getStringConfigValue(Configuration.getSystemConfiguration(RECAPTCHA_API_KEY), null))
.addAttribute("recaptchaApiKey", configurationManager.getStringConfigValue(getSystemConfiguration(RECAPTCHA_API_KEY), null))
.addAttribute("captchaRequestedFreeOfCharge", orderSummary.getFree() && captchaForOfflinePaymentEnabled);
}

Expand All @@ -166,6 +168,8 @@ public String showPaymentPage(@PathVariable("eventName") String eventName,
.addAttribute("expressCheckoutEnabled", isExpressCheckoutEnabled(event, orderSummary))
.addAttribute("useFirstAndLastName", event.mustUseFirstAndLastName())
.addAttribute("countries", TicketHelper.getLocalizedCountries(locale))
.addAttribute("countriesForVat", TicketHelper.getLocalizedCountriesForVat(locale))
.addAttribute("euCountriesForVat", TicketHelper.getLocalizedEUCountriesForVat(locale, configurationManager.getRequiredValue(getSystemConfiguration(ConfigurationKeys.EU_COUNTRIES_LIST))))
.addAttribute("euVatCheckingEnabled", vatChecker.isVatCheckingEnabledFor(event.getOrganizationId()))
.addAttribute("invoiceIsAllowed", invoiceAllowed)
.addAttribute("vatNrIsLinked", orderSummary.isVatExempt() || paymentForm.getHasVatCountryCode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public boolean deleteKey(@PathVariable("key") String key) {
}

@RequestMapping(value = "/configuration/eu-countries", method = GET)
public List<Pair<String, String>> loadEUCountries(Locale locale) {
return TicketHelper.getLocalizedEUCountries(locale, configurationManager.getRequiredValue(getSystemConfiguration(ConfigurationKeys.EU_COUNTRIES_LIST)));
public List<Pair<String, String>> loadEUCountries() {
return TicketHelper.getLocalizedEUCountriesForVat(Locale.ENGLISH, configurationManager.getRequiredValue(getSystemConfiguration(ConfigurationKeys.EU_COUNTRIES_LIST)));
}

@RequestMapping(value = "/configuration/platform-mode/status/{organizationId}", method = GET)
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/alfio/controller/api/support/TicketHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,25 @@ public static List<Pair<String, String>> getLocalizedCountries(Locale locale) {
return mapISOCountries(Stream.of(Locale.getISOCountries()), locale);
}

public static List<Pair<String, String>> getLocalizedEUCountries(Locale locale, String euCountries) {
return mapISOCountries(Stream.of(Locale.getISOCountries()).filter(isoCode -> StringUtils.contains(euCountries, isoCode)), locale);
public static List<Pair<String, String>> getLocalizedEUCountriesForVat(Locale locale, String euCountries) {
return fixVAT(mapISOCountries(Stream.of(Locale.getISOCountries())
.filter(isoCode -> StringUtils.contains(euCountries, isoCode) || "GR".equals(isoCode)), locale));
}

public static List<Pair<String, String>> getLocalizedCountriesForVat(Locale locale) {
return fixVAT(mapISOCountries(Stream.of(Locale.getISOCountries()), locale));
}

private static List<Pair<String, String>> fixVAT(List<Pair<String, String>> countries) {
return countries.stream()
.map(kv -> Pair.of(FIX_ISO_CODE_FOR_VAT.getOrDefault(kv.getKey(), kv.getKey()), kv.getValue()))
.collect(Collectors.toList());
}


//
public static final Map<String, String> FIX_ISO_CODE_FOR_VAT = Collections.singletonMap("GR", "EL");

private static List<Pair<String, String>> mapISOCountries(Stream<String> isoCountries, Locale locale) {
return isoCountries
.map(isoCode -> Pair.of(isoCode, new Locale("", isoCode).getDisplayCountry(locale)))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--
-- 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/>.
--

delete from configuration where c_key = 'EU_COUNTRIES_LIST';
insert into configuration(c_key, c_value, description) values('EU_COUNTRIES_LIST', 'BE,EL,LT,PT,BG,ES,LU,RO,CZ,FR,HU,SI,DK,HR,MT,SK,DE,IT,NL,FI,EE,CY,AT,SE,IE,LV,PL,GB', '');
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--
-- 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/>.
--

delete from configuration where c_key = 'EU_COUNTRIES_LIST';
insert into configuration(c_key, c_value, description) values('EU_COUNTRIES_LIST', 'BE,EL,LT,PT,BG,ES,LU,RO,CZ,FR,HU,SI,DK,HR,MT,SK,DE,IT,NL,FI,EE,CY,AT,SE,IE,LV,PL,GB', '');
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--
-- 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/>.
--

delete from configuration where c_key = 'EU_COUNTRIES_LIST';
insert into configuration(c_key, c_value, description) values('EU_COUNTRIES_LIST', 'BE,EL,LT,PT,BG,ES,LU,RO,CZ,FR,HU,SI,DK,HR,MT,SK,DE,IT,NL,FI,EE,CY,AT,SE,IE,LV,PL,GB', '');
4 changes: 3 additions & 1 deletion src/main/resources/alfio/i18n/public.properties
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,6 @@ invoice.refund=This invoice has been updated after the cancellation of one or mo
reservation-page.privacy.prefix=I have read and agree to the
reservation-page.privacy.link.text=privacy policy
reservation-page.privacy.suffix=.
reservation-page.country.select=Please select the Country
reservation-page.country.select=Please select the Country
reservation-page.eu-countries=EU countries
reservation-page.all-countries=All the countries
2 changes: 2 additions & 0 deletions src/main/resources/alfio/i18n/public_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,5 @@ invoice.refund=Diese Rechnung wurde aktualisiert nach eine Storno/R\u00FCckzalun
reservation-page.privacy.prefix=Ich habe gelesen und stimme zur
reservation-page.privacy.link.text=Datenschutzerkl\u00E4rung
reservation-page.privacy.suffix=.
reservation-page.eu-countries=EU Staaten
reservation-page.all-countries=alle Länder
4 changes: 3 additions & 1 deletion src/main/resources/alfio/i18n/public_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,6 @@ invoice.refund=Cette facture a \u00E9t\u00E9 modifi\u00E9e suite \u00E0 l'annula
reservation-page.privacy.prefix=Vous avez lu et acc\u00E9ptez les
reservation-page.privacy.link.text=r\u00E8gles de confidentialit\u00E9
reservation-page.privacy.suffix=.
reservation-page.country.select=veuillez s\u00E9lectionner le pays
reservation-page.country.select=veuillez s\u00E9lectionner le pays
reservation-page.eu-countries=Pays UE
reservation-page.all-countries=Tout les pays
2 changes: 2 additions & 0 deletions src/main/resources/alfio/i18n/public_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,5 @@ reservation-page.privacy.prefix=Ho letto ed accetto
reservation-page.privacy.link.text=l''informativa sulla privacy
reservation-page.privacy.suffix=.
reservation-page.country.select=Seleziona una nazione
reservation-page.eu-countries=Paesi UE
reservation-page.all-countries=Tutti i paesi
3 changes: 3 additions & 0 deletions src/main/resources/alfio/i18n/public_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,6 @@ reservation-page.privacy.prefix=Ik ga akkoord met de
reservation-page.privacy.link.text=Privacybeleid
reservation-page.privacy.suffix=.
reservation-page.country.select=Selecteer alstublieft een land
reservation-page.eu-countries=EU landen
reservation-page.all-countries=alle landen

13 changes: 10 additions & 3 deletions src/main/webapp/WEB-INF/templates/event/reservation-page.ms
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,16 @@
<label for="vatCountry">{{#i18n}}reservation-page-complete.country{{/i18n}}</label>
<select name="vatCountryCode" id="vatCountry" value="{{paymentForm.vatCountryCode}}" class="form-control field-required">
<option value="">{{#i18n}}reservation-page.country.select{{/i18n}}</option>
{{#countries}}
<option value="{{left}}">{{right}}</option>
{{/countries}}
<optgroup label="{{#i18n}}reservation-page.eu-countries{{/i18n}}">
{{#euCountriesForVat}}
<option value="{{left}}">{{left}} - {{right}}</option>
{{/euCountriesForVat}}
</optgroup>
<optgroup label="{{#i18n}}reservation-page.all-countries{{/i18n}}">
{{#countriesForVat}}
<option value="{{left}}">{{left}} - {{right}}</option>
{{/countriesForVat}}
</optgroup>
</select>
</div>
</div>
Expand Down

0 comments on commit 9e0e266

Please sign in to comment.