Skip to content

Commit

Permalink
#464 reservation-page: add skip vat nr checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jul 4, 2018
1 parent 045dd64 commit 84ed7b1
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 225 deletions.
4 changes: 1 addition & 3 deletions src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ public String validateToOverview(@PathVariable("eventName") String eventName, @P
Configuration.ConfigurationPathKey invoiceOnlyKey = Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.GENERATE_ONLY_INVOICE);
boolean invoiceOnly = configurationManager.getBooleanConfigValue(invoiceOnlyKey, false);

final boolean companyVatChecked = invoiceOnly ? contactAndTicketsForm.isAddCompanyBillingDetails() : contactAndTicketsForm.isInvoiceRequested();

if(invoiceOnly && reservationCost.getPriceWithVAT() > 0) {
//override, that's why we save it
contactAndTicketsForm.setInvoiceRequested(true);
Expand All @@ -284,7 +282,7 @@ public String validateToOverview(@PathVariable("eventName") String eventName, @P
contactAndTicketsForm.getBillingAddressCompany(), contactAndTicketsForm.getBillingAddressLine1(), contactAndTicketsForm.getBillingAddressLine2(),
contactAndTicketsForm.getBillingAddressZip(), contactAndTicketsForm.getBillingAddressCity(), contactAndTicketsForm.getVatCountryCode(),
contactAndTicketsForm.getCustomerReference(), contactAndTicketsForm.getVatNr(), contactAndTicketsForm.isInvoiceRequested(),
contactAndTicketsForm.isAddCompanyBillingDetails(), false);
contactAndTicketsForm.canSkipVatNrCheck(), false);
assignTickets(event.getShortName(), reservationId, contactAndTicketsForm, bindingResult, request, true, true);
//

Expand Down
16 changes: 15 additions & 1 deletion src/main/java/alfio/controller/form/ContactAndTicketsForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class ContactAndTicketsForm implements Serializable {
private String billingAddressZip;
private String billingAddressCity;

private boolean addCompanyBillingDetails = false;
private Boolean skipVatNr;
private Boolean backFromOverview;

private static void rejectIfOverLength(BindingResult bindingResult, String field, String errorCode,
Expand Down Expand Up @@ -114,6 +114,15 @@ public void validate(BindingResult bindingResult, Event event, List<TicketFieldC

ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "billingAddressCity", "error.emptyField");
rejectIfOverLength(bindingResult, "billingAddressCity", "error.tooLong", billingAddressCity, 256);

ValidationUtils.rejectIfEmpty(bindingResult, "vatCountryCode", "error.emptyField");

if(StringUtils.trimToNull(billingAddressCompany) != null && !canSkipVatNrCheck()) {
ValidationUtils.rejectIfEmptyOrWhitespace(bindingResult, "vatNr", "error.emptyField");
}

//TODO: here add vat nr validation!
//
}

if (email != null && !email.contains("@") && !bindingResult.hasFieldErrors("email")) {
Expand Down Expand Up @@ -163,6 +172,7 @@ public static ContactAndTicketsForm fromExistingReservation(TicketReservation re
form.setBillingAddressLine2(additionalInfo.getBillingAddressLine2());
form.setBillingAddressZip(additionalInfo.getBillingAddressZip());
form.setBillingAddressCity(additionalInfo.getBillingAddressCity());
form.setSkipVatNr(additionalInfo.getSkipVatNr());
return form;
}

Expand All @@ -173,4 +183,8 @@ public boolean getHasVatCountryCode() {
public boolean isBackFromOverview() {
return Optional.ofNullable(backFromOverview).orElse(false);
}

public boolean canSkipVatNrCheck() {
return Optional.ofNullable(skipVatNr).orElse(false);
}
}
4 changes: 2 additions & 2 deletions src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ public void updateReservation(String reservationId, CustomerName customerName, S
String billingAddressZip, String billingAddressCity, String vatCountryCode, String customerReference,
String vatNr,
boolean isInvoiceRequested,
boolean addCompanyBillingDetails,
boolean skipVatNr,
boolean validated) {

String completeBillingAddress = StringUtils.trimToEmpty(billingAddressCompany)+"\n"+
Expand All @@ -1436,6 +1436,6 @@ public void updateReservation(String reservationId, CustomerName customerName, S
ticketReservationRepository.updateTicketReservationWithValidation(reservationId,
customerName.getFullName(), customerName.getFirstName(), customerName.getLastName(),
email, billingAddressCompany, billingAddressLine1, billingAddressLine2, billingAddressZip,
billingAddressCity, completeBillingAddress, vatCountryCode, vatNr, isInvoiceRequested, addCompanyBillingDetails, customerReference, validated);
billingAddressCity, completeBillingAddress, vatCountryCode, vatNr, isInvoiceRequested, skipVatNr, customerReference, validated);
}
}
10 changes: 5 additions & 5 deletions src/main/java/alfio/model/TicketReservationAdditionalInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ public class TicketReservationAdditionalInfo {
private final String billingAddressZip;
private final String billingAddressCity;
private final Boolean validated;
private final Boolean addCompanyBillingDetails;
private final Boolean skipVatNr;

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) {
@Column("skip_vat_nr") Boolean skipVatNr) {
this.billingAddressCompany = billingAddressCompany;
this.billingAddressLine1 = billingAddressLine1;
this.billingAddressLine2 = billingAddressLine2;
this.billingAddressZip = billingAddressZip;
this.billingAddressCity = billingAddressCity;
this.validated = validated;
this.addCompanyBillingDetails = addCompanyBillingDetails;
this.skipVatNr = skipVatNr;
}


public boolean hasBeenValidated() {
return Optional.ofNullable(validated).orElse(false);
}

public boolean hasAddCompanyBillingDetails() {
return Optional.ofNullable(addCompanyBillingDetails).orElse(false);
public boolean hasSkipVatNr() {
return Optional.ofNullable(skipVatNr).orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ int updateBillingData(@Bind("vatStatus") PriceContainer.VatStatus vatStatus,
" billing_address_line2 = :billingAddressLine2, " +
" billing_address_zip = :billingAddressZip, " +
" billing_address_city = :billingAddressCity, " +
" add_company_billing_details = :addCompanyBillingDetails, " +
" skip_vat_nr = :skipVatNr, " +
" customer_reference = :customerReference, "+
" validated_for_overview = :validated " +
" where id = :reservationId")
Expand All @@ -192,13 +192,13 @@ int updateTicketReservationWithValidation(@Bind("reservationId") String reservat
@Bind("vatCountry") String vatCountry,
@Bind("vatNr") String vatNr,
@Bind("invoiceRequested") boolean invoiceRequested,
@Bind("addCompanyBillingDetails") boolean addCompanyBillingDetails,
@Bind("skipVatNr") boolean skipVatNr,
@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")
" billing_address_zip, billing_address_city, validated_for_overview, skip_vat_nr from tickets_reservation where id = :id")
TicketReservationAdditionalInfo getAdditionalInfo(@Bind("id") String reservationId);

@Query("update tickets_reservation set validated_for_overview = :validated where id = :reservationId")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--
-- 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 skip_vat_nr boolean;
alter table tickets_reservation drop column add_company_billing_details;


drop view if exists reservation_and_ticket_and_tx;
drop view if exists ticket_and_reservation_and_tx;
3 changes: 2 additions & 1 deletion src/main/resources/alfio/i18n/public.properties
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,5 @@ reservation-page.city=City
reservation-page.invoice-details=Invoice details
reservation-page.if-applicable=if applicable
error.emptyField=This field is required
error.tooLong=The value is too long
error.tooLong=The value is too long
reservation-page.skipVatNr=I don''t have a {0} number
3 changes: 2 additions & 1 deletion src/main/resources/alfio/i18n/public_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,5 @@ reservation-page.city=[DE]-City
reservation-page.invoice-details=[DE]-Invoice details
reservation-page.if-applicable=[DE]-if applicable
error.emptyField=[DE]-This field is required
error.tooLong=[DE]-The value is too long
error.tooLong=[DE]-The value is too long
reservation-page.skipVatNr=[DE]-I don''t have a {0} number
3 changes: 2 additions & 1 deletion src/main/resources/alfio/i18n/public_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,5 @@ reservation-page.city=[FR]-City
reservation-page.invoice-details=[FR]-Invoice details
reservation-page.if-applicable=[FR]-if applicable
error.emptyField=[FR]-This field is required
error.tooLong=[FR]-The value is too long
error.tooLong=[FR]-The value is too long
reservation-page.skipVatNr=[FR]-I don''t have a {0} number
3 changes: 2 additions & 1 deletion src/main/resources/alfio/i18n/public_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,5 @@ reservation-page.city=[IT]-City
reservation-page.invoice-details=[IT]-Invoice details
reservation-page.if-applicable=[IT]-if applicable
error.emptyField=[IT]-This field is required
error.tooLong=[IT]-The value is too long
error.tooLong=[IT]-The value is too long
reservation-page.skipVatNr=[IT]-I don''t have a {0} number
3 changes: 2 additions & 1 deletion src/main/resources/alfio/i18n/public_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,5 @@ reservation-page.city=[NL]-City
reservation-page.invoice-details=[NL]-Invoice details
reservation-page.if-applicable=[NL]-if applicable
error.emptyField=[NL]-This field is required
error.tooLong=[NL]-The value is too long
error.tooLong=[NL]-The value is too long
reservation-page.skipVatNr=[NL]-I don''t have a {0} number
44 changes: 27 additions & 17 deletions src/main/webapp/WEB-INF/templates/event/reservation-page.ms
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,8 @@
</div>
<div class="row">
<div class="col-xs-12 {{#customerReferenceEnabled}}col-md-6{{/customerReferenceEnabled}}">
<div class="form-group">
<div class="form-group {{#field-has-error}}[vatCountryCode] has-error{{/field-has-error}}">
<label for="vatCountry">{{#i18n}}reservation-page-complete.country{{/i18n}}</label>

<select name="vatCountryCode" id="vatCountry" value="{{paymentForm.vatCountryCode}}" class="form-control field-required" required>
<option value="">{{#i18n}}reservation-page.country.select{{/i18n}}</option>
<optgroup label="{{#i18n}}reservation-page.eu-countries{{/i18n}}" id="optgroup-eu-countries-list">
Expand All @@ -188,6 +187,7 @@
{{/countriesForVat}}
</optgroup>
</select>
{{#field-has-error}}[vatCountryCode]<span class="help-block text-danger">{{#i18n}}{{#field-error}}vatCountryCode{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
{{#customerReferenceEnabled}}
Expand All @@ -198,20 +198,10 @@
</div>
{{/customerReferenceEnabled}}
</div>
<div class="row">
<div class="col-xs-12">
<input type="hidden" name="invoiceRequested" id="invoice-requested" value="true">
<div class="checkbox wMarginTop">
<label>
<input type="checkbox" name="addCompanyBillingDetails" id="add-company-billing-details" value="true" {{#paymentForm.addCompanyBillingDetails}}checked{{/paymentForm.addCompanyBillingDetails}}>
{{#i18n}}reservation.add-company-billing-details [{{vatTranslation}}]{{/i18n}}
</label>
</div>
</div>
</div>
<input type="hidden" name="invoiceRequested" id="invoice-requested" value="true">
<div class="row">
<div id="vat-number-container">
<div class="col-xs-12">
<div class="col-md-6">
<div class="form-group {{#field-has-error}}[vatNr] has-error{{/field-has-error}}">
<label for="vatNr">{{#i18n}}invoice.vat [{{vatTranslation}}]{{/i18n}}</label>
<div class="input-group">
Expand All @@ -221,6 +211,16 @@
{{#field-has-error}}[vatNr]<span class="help-block text-danger">{{#i18n}}{{#field-error}}vatNr{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<div class="form-check checkbox checkbox-in-form-group">
<label>
<input class="form-check-input" name="skipVatNr" id="skip-vat-nr" value="true" type="checkbox" {{#paymentForm.skipVatNr}}checked{{/paymentForm.skipVatNr}}>
{{#i18n}}reservation-page.skipVatNr [{{vatTranslation}}]{{/i18n}}
</label>
</div>
</div>
</div>
</div>
</div>
{{/onlyInvoice}}
Expand Down Expand Up @@ -282,9 +282,8 @@
</div>
<div class="row">
<div class="col-xs-12 {{#customerReferenceEnabled}}col-md-6{{/customerReferenceEnabled}}">
<div class="form-group">
<div class="form-group {{#field-has-error}}[vatCountryCode] has-error{{/field-has-error}}">
<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>
<optgroup label="{{#i18n}}reservation-page.eu-countries{{/i18n}}" id="optgroup-eu-countries-list">
Expand All @@ -298,6 +297,7 @@
{{/countriesForVat}}
</optgroup>
</select>
{{#field-has-error}}[vatCountryCode]<span class="help-block text-danger">{{#i18n}}{{#field-error}}vatCountryCode{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
{{#customerReferenceEnabled}}
Expand All @@ -310,7 +310,7 @@
</div>
<div class="row">
<div id="vat-number-container">
<div class="col-xs-12">
<div class="col-md-6">
<div class="form-group {{#field-has-error}}[vatNr] has-error{{/field-has-error}}">
<label for="vatNr">{{#i18n}}invoice.vat [{{vatTranslation}}]{{/i18n}}</label>
<div class="input-group">
Expand All @@ -320,6 +320,16 @@
{{#field-has-error}}[vatNr]<span class="help-block text-danger">{{#i18n}}{{#field-error}}vatNr{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<div class="form-check checkbox checkbox-in-form-group">
<label>
<input class="form-check-input" name="skipVatNr" id="skip-vat-nr" value="true" type="checkbox" {{#paymentForm.skipVatNr}}checked{{/paymentForm.skipVatNr}}>
{{#i18n}}reservation-page.skipVatNr [{{vatTranslation}}]{{/i18n}}
</label>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/main/webapp/resources/css/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,13 @@ html[lang=it] .alfio-lang a[lang=it] {

.form-horizontal .control-label.category-name {
text-align:left;
}

.checkbox-in-form-group {
margin-top:30px;
}

.checkbox-in-form-group label {
padding-left:20px;
font-weight:normal;
}

0 comments on commit 84ed7b1

Please sign in to comment.