Skip to content

Commit

Permalink
#573 first stab at validation+ui/ux
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jan 2, 2019
1 parent 2f381f8 commit 65b1e6b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,13 @@ public String validateToOverview(@PathVariable("eventName") String eventName, @P
assignTickets(event.getShortName(), reservationId, contactAndTicketsForm, bindingResult, request, true, true);
//

boolean italyEInvoicing = configurationManager.getBooleanConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ENABLE_ITALY_E_INVOICING), false);
Map<ConfigurationKeys, Boolean> formValidationParameters = Collections.singletonMap(ENABLE_ITALY_E_INVOICING, italyEInvoicing);
//
contactAndTicketsForm.validate(bindingResult, event, ticketFieldRepository.findAdditionalFieldsForEvent(event.getId()), new SameCountryValidator(vatChecker, event.getOrganizationId(), event.getId(), reservationId));
contactAndTicketsForm.validate(bindingResult, event,
ticketFieldRepository.findAdditionalFieldsForEvent(event.getId()),
new SameCountryValidator(vatChecker, event.getOrganizationId(), event.getId(), reservationId),
formValidationParameters);
//

if(bindingResult.hasErrors()) {
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/alfio/controller/form/ContactAndTicketsForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import alfio.manager.EuVatChecker;
import alfio.model.*;
import alfio.model.result.ValidationResult;
import alfio.model.system.ConfigurationKeys;
import alfio.util.ErrorsCode;
import alfio.util.Validator;
import lombok.Data;
Expand Down Expand Up @@ -82,7 +83,7 @@ private static void rejectIfOverLength(BindingResult bindingResult, String field



public void validate(BindingResult bindingResult, Event event, List<TicketFieldConfiguration> fieldConf, EuVatChecker.SameCountryValidator vatValidator) {
public void validate(BindingResult bindingResult, Event event, List<TicketFieldConfiguration> fieldConf, EuVatChecker.SameCountryValidator vatValidator, Map<ConfigurationKeys, Boolean> formValidationParameters) {



Expand Down Expand Up @@ -134,6 +135,27 @@ public void validate(BindingResult bindingResult, Event event, List<TicketFieldC

}

// https://github.com/alfio-event/alf.io/issues/573
// only for IT and only if enabled!
if (formValidationParameters.getOrDefault(ConfigurationKeys.ENABLE_ITALY_E_INVOICING, false) && "IT".equals(vatCountryCode)) {

// mandatory
ValidationUtils.rejectIfEmpty(bindingResult, "italyEInvoicingFiscalCode", "error.emptyField");
rejectIfOverLength(bindingResult, "italyEInvoicingFiscalCode", "error.tooLong", italyEInvoicingFiscalCode, 256);
//

//
ValidationUtils.rejectIfEmpty(bindingResult, "italyEInvoicingReferenceType", "error.italyEInvoicingReferenceTypeSelectValue");
//
if (BillingDetails.ItalianEInvoicing.ReferenceType.ADDRESSEE_CODE == italyEInvoicingReferenceType) {
ValidationUtils.rejectIfEmpty(bindingResult, "italyEInvoicingReferenceAddresseeCode", "error.emptyField");
}
if (BillingDetails.ItalianEInvoicing.ReferenceType.PEC == italyEInvoicingReferenceType) {
ValidationUtils.rejectIfEmpty(bindingResult, "italyEInvoicingReferencePEC", "error.emptyField");
}

}

if (email != null && !email.contains("@") && !bindingResult.hasFieldErrors("email")) {
bindingResult.rejectValue("email", ErrorsCode.STEP_2_INVALID_EMAIL);
}
Expand Down
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 @@ -388,4 +388,5 @@ invoice-fields.fiscalCode=Fiscal Code
invoice-fields.i-have=I have
invoice-fields.addressee-code=Addressee code
invoice-fields.pec=PEC
invoice.fields.neither=Neither
invoice.fields.neither=Neither
error.italyEInvoicingReferenceTypeSelectValue=Select of the 3 value (Fiscal Code, PEC, Neither)
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 @@ -375,4 +375,5 @@ reservation-page-waiting.invoice-will-be-sent=[DE] The invoice will be sent sepa
invoice-fields.fiscalCode=[DE] Fiscal Code
invoice-fields.i-have=[DE] I have
invoice-fields.addressee-code=[DE] Addressee code
invoice.fields.neither=[DE] Neither
invoice.fields.neither=[DE] Neither
error.italyEInvoicingReferenceTypeSelectValue=[DE] Select of the 3 value (Fiscal Code, PEC, Neither)
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 @@ -384,4 +384,5 @@ reservation-page-waiting.invoice-will-be-sent=[FR] The invoice will be sent sepa
invoice-fields.fiscalCode=[FR] Fiscal Code
invoice-fields.i-have=[FR] I have
invoice-fields.addressee-code=[FR] Addressee code
invoice.fields.neither=[FR] Neither
invoice.fields.neither=[FR] Neither
error.italyEInvoicingReferenceTypeSelectValue=[FR]-Select of the 3 value (Fiscal Code, PEC, Neither)
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 @@ -370,4 +370,5 @@ reservation-page-waiting.invoice-will-be-sent=[IT] The invoice will be sent sepa
invoice-fields.fiscalCode=Codice fiscale
invoice-fields.i-have=Ho un
invoice-fields.addressee-code=Codice destinatario
invoice.fields.neither=Nessuno dei due
invoice.fields.neither=Nessuno dei due
error.italyEInvoicingReferenceTypeSelectValue=Selezionate uno dei 3 valori (Codice Destinatario, PEC, Nessuno dei due)
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 @@ -359,4 +359,5 @@ reservation-page-waiting.invoice-will-be-sent=[NL] The invoice will be sent sepa
invoice-fields.fiscalCode=[NL] Fiscal Code
invoice-fields.i-have=[NL] I have
invoice-fields.addressee-code=[NL] Addressee code
invoice.fields.neither=[NL] Neither
invoice.fields.neither=[NL] Neither
error.italyEInvoicingReferenceTypeSelectValue=[NL] Select of the 3 value (Fiscal Code, PEC, Neither)
9 changes: 6 additions & 3 deletions src/main/webapp/WEB-INF/templates/event/invoice-fields.ms
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</div>
</div>
{{#enabledItalyEInvoicing}}
<div class="row">
<div class="row" id="italyEInvoicing">
<div>
<div class="col-md-12">
<div class="form-group {{#field-has-error}}[italyEInvoicingFiscalCode] has-error{{/field-has-error}}">
Expand All @@ -99,22 +99,25 @@
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<div class="form-group {{#field-has-error}}[italyEInvoicingReferenceType] has-error{{/field-has-error}}">
<label for="">
{{#i18n}}invoice-fields.i-have{{/i18n}}
</label>
{{#field-has-error}}[italyEInvoicingReferenceType]<span class="help-block text-danger">{{#i18n}}{{#field-error}}italyEInvoicingReferenceType{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
<div class="col-md-12">
<div class="form-group {{#field-has-error}}[italyEInvoicingReferenceAddresseeCode] has-error{{/field-has-error}}">
<label><input {{#paymentForm.italyEInvoicingTypeAddresseeCode}}checked{{/paymentForm.italyEInvoicingTypeAddresseeCode}} type="radio" value="ADDRESSEE_CODE" name="italyEInvoicingReferenceType"><span class="label-after-radio">{{#i18n}}invoice-fields.addressee-code{{/i18n}}</span></label>
<input type="text" class="form-control" name="italyEInvoicingReferenceAddresseeCode" value="{{paymentForm.italyEInvoicingReferenceAddresseeCode}}">
<input type="text" maxlength="7" class="form-control" name="italyEInvoicingReferenceAddresseeCode" value="{{paymentForm.italyEInvoicingReferenceAddresseeCode}}">
{{#field-has-error}}[italyEInvoicingReferenceAddresseeCode]<span class="help-block text-danger">{{#i18n}}{{#field-error}}italyEInvoicingReferenceAddresseeCode{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
<div class="col-md-12">
<div class="form-group {{#field-has-error}}[italyEInvoicingReferencePEC] has-error{{/field-has-error}}">
<label><input {{#paymentForm.italyEInvoicingTypePEC}}checked{{/paymentForm.italyEInvoicingTypePEC}} type="radio" value="PEC" name="italyEInvoicingReferenceType"><span class="label-after-radio">{{#i18n}}invoice-fields.pec{{/i18n}}</span></label>
<input type="text" class="form-control" name="italyEInvoicingReferencePEC" value="{{paymentForm.italyEInvoicingReferencePEC}}">
{{#field-has-error}}[italyEInvoicingReferencePEC]<span class="help-block text-danger">{{#i18n}}{{#field-error}}italyEInvoicingReferencePEC{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
<div class="col-md-12">
Expand Down
17 changes: 16 additions & 1 deletion src/main/webapp/resources/js/event/reservation-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,23 @@
}
});


var enabledItalyEInvoicing = $("#italyEInvoicing").length === 1;

$("#italyEInvoicing").hide();

$("#vatCountry").change(function() {
$("#selected-country-code").text($("#vatCountry").val());
var vatCountryValue = $("#vatCountry").val();
$("#selected-country-code").text(vatCountryValue);

if(enabledItalyEInvoicing && vatCountryValue === 'IT') {
$("#italyEInvoicing").show();
$("#italyEInvoicingFiscalCode").attr('required', true);
} else {
$("#italyEInvoicing").hide();
$("#italyEInvoicingFiscalCode").removeAttr('required');
}

});

function canSkipVatNr() {
Expand Down

0 comments on commit 65b1e6b

Please sign in to comment.