Skip to content

Commit

Permalink
Add reset billing info (#448)
Browse files Browse the repository at this point in the history
* initial commit

* wire up the reset billing info functionality in the client

* add missing translations, fix button size

* fix typo; reset button to previous text
  • Loading branch information
syjer authored and cbellone committed May 21, 2018
1 parent b343912 commit ea523ba
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 9 deletions.
21 changes: 21 additions & 0 deletions src/main/java/alfio/controller/api/ReservationApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ public Map<String, Object> assignTicketToPerson(@PathVariable("eventName") Strin
return result;
}

@PostMapping("/event/{eventName}/reservation/{reservationId}/reset-billing-info")
@Transactional
public ResponseEntity<Boolean> resetVat(@PathVariable("eventName") String eventName,
@PathVariable("reservationId") String reservationId) {
boolean res = eventRepository
.findOptionalByShortName(eventName)
.flatMap(e -> ticketReservationRepository.findOptionalReservationById(reservationId).map(r -> Pair.of(e, r)))
.filter(eventAndReservation -> eventAndReservation.getRight().getStatus() == TicketReservation.TicketReservationStatus.PENDING)
.map(eventAndReservation -> {
Event event = eventAndReservation.getLeft();
TicketReservation tr = eventAndReservation.getRight();
ticketReservationRepository.resetBillingData(tr.getId());

OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event, Locale.forLanguageTag(tr.getUserLanguage()));
ticketReservationRepository.addReservationInvoiceOrReceiptModel(reservationId, Json.toJson(orderSummary));
return true;
}).orElse(false);

return new ResponseEntity<>(res, res ? HttpStatus.OK : HttpStatus.BAD_REQUEST);
}

@RequestMapping(value = "/event/{eventName}/reservation/{reservationId}/vat-validation", method = RequestMethod.POST)
@Transactional
public ResponseEntity<VatDetail> validateEUVat(@PathVariable("eventName") String eventName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ int updateBillingData(@Bind("vatStatus") PriceContainer.VatStatus vatStatus,
@Bind("invoiceRequested") boolean invoiceRequested,
@Bind("reservationId") String reservationId);

@Query("update tickets_reservation set invoice_requested = false, vat_status = null, vat_nr = null, vat_country = null, billing_address = null where id = :reservationId")
int resetBillingData(@Bind("reservationId") String reservationId);


@Query("select count(ticket.id) ticket_sold, to_char(trunc(confirmation_ts), 'yyyy-MM-dd') as day from ticket " +
"inner join tickets_reservation on tickets_reservation_id = tickets_reservation.id where " +
Expand Down
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 @@ -357,4 +357,6 @@ reservation-page.privacy.link.text=privacy policy
reservation-page.privacy.suffix=.
reservation-page.country.select=Please select the Country
reservation-page.eu-countries=EU countries
reservation-page.all-countries=All the countries
reservation-page.all-countries=All the countries
reservation-page.reset-billing-informations=Reset Billing Information
common.apply=Apply
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 @@ -348,3 +348,5 @@ reservation-page.privacy.link.text=Datenschutzerkl\u00E4rung
reservation-page.privacy.suffix=.
reservation-page.eu-countries=EU Staaten
reservation-page.all-countries=alle Länder
common.apply=Anwenden
reservation-page.reset-billing-informations=Rechnungsinformationen löschen
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 @@ -357,4 +357,6 @@ 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.eu-countries=Pays UE
reservation-page.all-countries=Tout les pays
reservation-page.all-countries=Tout les pays
common.apply=Appliquer
reservation-page.reset-billing-informations=Effacer les données de facturation
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 @@ -342,3 +342,5 @@ reservation-page.privacy.suffix=.
reservation-page.country.select=Seleziona una nazione
reservation-page.eu-countries=Paesi UE
reservation-page.all-countries=Tutti i paesi
common.apply=Applica
reservation-page.reset-billing-informations=Cancella i dati di fatturazione
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 @@ -352,4 +352,5 @@ reservation-page.privacy.suffix=.
reservation-page.country.select=Selecteer alstublieft een land
reservation-page.eu-countries=EU landen
reservation-page.all-countries=alle landen

common.apply=Toepassen
reservation-page.reset-billing-informations=Factureringsinformatie verwijderen
19 changes: 16 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 @@ -263,7 +263,7 @@
{{/vatNrIsLinked}}
{{/invoiceIsAllowed}}

<div id="invoice" class="wMarginTop {{#invoiceIsAllowed}}{{^paymentForm.invoiceRequested}}hidden{{/paymentForm.invoiceRequested}}{{/invoiceIsAllowed}}">
<div id="invoice" class="wMarginTop {{#invoiceIsAllowed}}{{^paymentForm.invoiceRequested}}hidden{{/paymentForm.invoiceRequested}}{{/invoiceIsAllowed}}" {{#euVatCheckingEnabled}}data-eu-vat-checking-enabled="true"{{/euVatCheckingEnabled}}>
{{#euVatCheckingEnabled}}
{{^vatNrIsLinked}}
<div class="row">
Expand All @@ -272,7 +272,7 @@
<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}}">
<optgroup label="{{#i18n}}reservation-page.eu-countries{{/i18n}}" id="optgroup-eu-countries-list">
{{#euCountriesForVat}}
<option value="{{left}}">{{left}} - {{right}}</option>
{{/euCountriesForVat}}
Expand All @@ -293,7 +293,9 @@
<div class="input-group">
<input id="vatNr" type="text" required name="vatNr" class="form-control" value="{{paymentForm.vatNr}}"/>
<div class="input-group-btn">
<button type="button" class="btn btn-warning btn-block" data-validation-url="{{request.contextPath}}/event/{{event.shortName}}/reservation/{{reservation.id}}/vat-validation" id="validateVAT" data-text="{{#i18n}}invoice.validate.vat [{{vatTranslation}}]{{/i18n}}">{{#i18n}}invoice.validate.vat [{{vatTranslation}}]{{/i18n}}</button>
<button type="button" class="btn btn-warning btn-block" data-validation-url="{{request.contextPath}}/event/{{event.shortName}}/reservation/{{reservation.id}}/vat-validation" id="validateVAT"
data-text="{{#i18n}}invoice.validate.vat [{{vatTranslation}}]{{/i18n}}"
data-text-non-eu="{{#i18n}}common.apply{{/i18n}}">{{#i18n}}invoice.validate.vat [{{vatTranslation}}]{{/i18n}}</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -336,6 +338,17 @@
{{#field-has-error}}[billingAddress]<span class="help-block text-danger">{{#i18n}}{{#field-error}}billingAddress{{/field-error}}{{/i18n}}</span>{{/field-has-error}}
</div>
</div>
{{#euVatCheckingEnabled}}{{#vatNrIsLinked}}
<div class="col-md-6 col-md-push-6 col-xs-12">
<div class="form-group">
<button type="button" id="reset-billing-information" class="btn btn-warning btn-block"
data-reset-billing-information-url="{{request.contextPath}}/event/{{event.shortName}}/reservation/{{reservation.id}}/reset-billing-info">
{{#i18n}}reservation-page.reset-billing-informations{{/i18n}}
</button>
</div>
</div>
{{/vatNrIsLinked}}{{/euVatCheckingEnabled}}

</div>
</div>
{{/orderSummary.free}}
Expand Down
34 changes: 31 additions & 3 deletions src/main/webapp/resources/js/event/reservation-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
element.removeClass('hidden');
euBillingCountry.change();
if(euBillingCountry.length === 0) {
$('#billing-address-container').removeClass(hiddenClasses);
//$('#billing-address-container').removeClass(hiddenClasses);
$('#billing-address').attr('required', true).removeAttr('disabled');
}
} else {
Expand All @@ -320,12 +320,17 @@
});


$(function() {
if($("#invoice[data-eu-vat-checking-enabled=true]").length === 1 && $("input[type=hidden][name=vatNr]").length === 0) {
$("#billing-address-container").addClass(hiddenClasses);
}
})


var euBillingCountry = $('#vatCountry');
euBillingCountry.change(function() {
if($(this).val() === '') {
$('#billing-address-container').removeClass(hiddenClasses);
//$('#billing-address-container').removeClass(hiddenClasses);
$('#billing-address').attr('required', true).removeAttr('disabled');
$('#validation-result-container, #vat-number-container, #validateVAT').addClass(hiddenClasses);
$('#vatNr').attr('required', false).attr('disabled', '');
Expand All @@ -336,6 +341,14 @@
$('#billing-address').attr('required', false).attr('disabled');
$('#vatNr').attr('required', true).removeAttr('disabled');
$("#vatCountryCode").attr('required', true).removeAttr('disabled', '');

var countryCode = $(this).val();
var validateVATButton = $("#validateVAT");
if($("#optgroup-eu-countries-list option[value="+countryCode+"]").length === 1) {
validateVATButton.text(validateVATButton.attr('data-text'));
} else {
validateVATButton.text(validateVATButton.attr('data-text-non-eu'));
}
}
});

Expand All @@ -350,6 +363,7 @@
var resultContainer = $('#validation-result');
if(vatNr !== '' && country !== '') {
var btn = $(this);
var previousText = btn.text();
btn.html('<i class="fa fa-circle-o-notch fa-spin"></i>');
$('#continue-button').attr('disabled', true);
jQuery.ajax({
Expand All @@ -369,13 +383,27 @@
}
},
complete: function(xhr) {
btn.html(btn.attr('data-text'));
btn.text(previousText);
$('#continue-button').attr('disabled', false);
}

});
}
})

$('#reset-billing-information').click(function() {
var action = $(this).attr('data-reset-billing-information-url');
var frm = $(this.form);
jQuery.ajax({
url: action,
type:'POST',
success: function() {
window.location.reload();
},
data:frm.serialize()
});
});

});

window.recaptchaLoadCallback = function() {
Expand Down

0 comments on commit ea523ba

Please sign in to comment.