Skip to content

Commit

Permalink
#573 persist new data
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Dec 31, 2018
1 parent bd971a8 commit 657fae2
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/main/java/alfio/controller/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ public String validateToOverview(@PathVariable("eventName") String eventName, @P
contactAndTicketsForm.getBillingAddressZip(), contactAndTicketsForm.getBillingAddressCity(), contactAndTicketsForm.getVatCountryCode(),
contactAndTicketsForm.getCustomerReference(), contactAndTicketsForm.getVatNr(), contactAndTicketsForm.isInvoiceRequested(),
contactAndTicketsForm.canSkipVatNrCheck(), false);
ticketReservationManager.updateReservationInvoicingAdditionalInformations(reservationId,
new TicketReservationInvoicingAdditionalInfo(
new BillingDetails.ItalianEInvoicing(contactAndTicketsForm.getItalyEInvoicingFiscalCode(),
contactAndTicketsForm.getItalyEInvoicingReferenceType(),
contactAndTicketsForm.getItalyEInvoicingReferenceAddresseeCode(),
contactAndTicketsForm.getItalyEInvoicingReferencePEC())
)
);
assignTickets(event.getShortName(), reservationId, contactAndTicketsForm, bindingResult, request, true, true);
//

Expand Down
39 changes: 35 additions & 4 deletions src/main/java/alfio/controller/form/ContactAndTicketsForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package alfio.controller.form;

import alfio.manager.EuVatChecker;
import alfio.model.Event;
import alfio.model.TicketFieldConfiguration;
import alfio.model.TicketReservation;
import alfio.model.TicketReservationAdditionalInfo;
import alfio.model.*;
import alfio.model.result.ValidationResult;
import alfio.util.ErrorsCode;
import alfio.util.Validator;
Expand Down Expand Up @@ -67,6 +64,14 @@ public class ContactAndTicketsForm implements Serializable {

private Boolean skipVatNr;
private Boolean backFromOverview;
//

// https://github.com/alfio-event/alf.io/issues/573
private String italyEInvoicingFiscalCode;
private BillingDetails.ItalianEInvoicing.ReferenceType italyEInvoicingReferenceType;
private String italyEInvoicingReferenceAddresseeCode;
private String italyEInvoicingReferencePEC;
//

private static void rejectIfOverLength(BindingResult bindingResult, String field, String errorCode,
String value, int maxLength) {
Expand Down Expand Up @@ -177,6 +182,18 @@ public static ContactAndTicketsForm fromExistingReservation(TicketReservation re
form.setBillingAddressZip(additionalInfo.getBillingAddressZip());
form.setBillingAddressCity(additionalInfo.getBillingAddressCity());
form.setSkipVatNr(additionalInfo.getSkipVatNr());

//todo: simplify code, can avoid a level with map
//https://github.com/alfio-event/alf.io/issues/573
Optional.ofNullable(additionalInfo.getInvoicingAdditionalInfo()).ifPresent(i ->
Optional.ofNullable(i.getItalianEInvoicing()).ifPresent(iei -> {
form.setItalyEInvoicingFiscalCode(iei.getFiscalCode());
form.setItalyEInvoicingReferenceType(iei.getReferenceType());
form.setItalyEInvoicingReferenceAddresseeCode(iei.getAddresseeCode());
form.setItalyEInvoicingReferencePEC(iei.getPec());
})
);

return form;
}

Expand All @@ -195,4 +212,18 @@ public boolean canSkipVatNrCheck() {
public boolean isBusiness() {
return StringUtils.isNotBlank(billingAddressCompany) && !canSkipVatNrCheck() && invoiceRequested;
}

// https://github.com/alfio-event/alf.io/issues/573
public boolean getItalyEInvoicingTypeAddresseeCode() {
return italyEInvoicingReferenceType == BillingDetails.ItalianEInvoicing.ReferenceType.ADDRESSEE_CODE;
}

public boolean getItalyEInvoicingTypePEC() {
return italyEInvoicingReferenceType == BillingDetails.ItalianEInvoicing.ReferenceType.PEC;
}

public boolean getItalyEInvoicingTypeNone() {
return italyEInvoicingReferenceType == BillingDetails.ItalianEInvoicing.ReferenceType.NONE;
}
//
}
8 changes: 7 additions & 1 deletion src/main/java/alfio/manager/TicketReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,12 @@ 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, skipVatNr, customerReference, validated);
billingAddressCity, completeBillingAddress, vatCountryCode, vatNr, isInvoiceRequested, skipVatNr,
customerReference,
validated);
}

public void updateReservationInvoicingAdditionalInformations(String reservationId, TicketReservationInvoicingAdditionalInfo ticketReservationInvoicingAdditionalInfo) {
ticketReservationRepository.updateInvoicingAdditionalInformations(reservationId, Json.toJson(ticketReservationInvoicingAdditionalInfo));
}
}
3 changes: 2 additions & 1 deletion src/main/java/alfio/model/BillingDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum ReferenceType {

private final String fiscalCode;
private final ReferenceType referenceType;
private final String reference;
private final String addresseeCode;
private final String pec;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package alfio.model;

import alfio.util.Json;
import ch.digitalfondue.npjt.ConstructorAnnotationRowMapper.Column;
import lombok.Getter;

Expand All @@ -31,21 +32,25 @@ public class TicketReservationAdditionalInfo {
private final String billingAddressCity;
private final Boolean validated;
private final Boolean skipVatNr;
private final TicketReservationInvoicingAdditionalInfo invoicingAdditionalInfo;

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("skip_vat_nr") Boolean skipVatNr) {
@Column("skip_vat_nr") Boolean skipVatNr,
@Column("invoicing_additional_informations") String invoicingAdditionalInformations) {
this.billingAddressCompany = billingAddressCompany;
this.billingAddressLine1 = billingAddressLine1;
this.billingAddressLine2 = billingAddressLine2;
this.billingAddressZip = billingAddressZip;
this.billingAddressCity = billingAddressCity;
this.validated = validated;
this.skipVatNr = skipVatNr;
this.invoicingAdditionalInfo = invoicingAdditionalInformations == null ? new TicketReservationInvoicingAdditionalInfo(null) :
Json.fromJson(invoicingAdditionalInformations, TicketReservationInvoicingAdditionalInfo.class);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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/>.
*/
package alfio.model;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class TicketReservationInvoicingAdditionalInfo {

private final BillingDetails.ItalianEInvoicing italianEInvoicing;
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ int updateTicketReservationWithValidation(@Bind("reservationId") String reservat


@Query("select billing_address_company, billing_address_line1, billing_address_line2, " +
" billing_address_zip, billing_address_city, validated_for_overview, skip_vat_nr from tickets_reservation where id = :id")
" billing_address_zip, billing_address_city, validated_for_overview, skip_vat_nr, invoicing_additional_informations 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 All @@ -227,4 +227,7 @@ default Integer countTicketsInReservationForCategories(String reservationId, Col

@Query("select billing_address_company, billing_address_line1, billing_address_line2, billing_address_zip, billing_address_city, vat_nr, vat_country from tickets_reservation where id = :reservationId")
BillingDetails getBillingDetailsForReservation(@Bind("reservationId") String reservationId);

@Query("update tickets_reservation set invoicing_additional_informations = :info::json where id = :id")
int updateInvoicingAdditionalInformations(@Bind("id") String reservationId, @Bind("info") String info);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--
-- 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 invoicing_additional_informations jsonb;
12 changes: 6 additions & 6 deletions src/main/webapp/WEB-INF/templates/event/invoice-fields.ms
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<div class="col-md-12">
<div class="form-group {{#field-has-error}}[italyEInvoicingFiscalCode] has-error{{/field-has-error}}">
<label for="italyEInvoicingFiscalCode">{{#i18n}}invoice-fields.fiscalCode{{/i18n}}</label>
<input id="italyEInvoicingFiscalCode" type="text" name="italyEInvoicingFiscalCode" class="form-control">
<input id="italyEInvoicingFiscalCode" type="text" name="italyEInvoicingFiscalCode" value="{{paymentForm.italyEInvoicingFiscalCode}}" class="form-control">
</div>
</div>
<div class="col-md-12">
Expand All @@ -107,19 +107,19 @@
</div>
<div class="col-md-12">
<div class="form-group {{#field-has-error}}[italyEInvoicingReferenceAddresseeCode] has-error{{/field-has-error}}">
<label><input type="radio" name="italyEInvoicingReferenceType"><span class="label-after-radio">{{#i18n}}invoice-fields.addressee-code{{/i18n}}</span></label>
<input type="text" class="form-control" name="italyEInvoicingReferenceAddresseeCode">
<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}}">
</div>
</div>
<div class="col-md-12">
<div class="form-group {{#field-has-error}}[italyEInvoicingReferencePEC] has-error{{/field-has-error}}">
<label><input type="radio" name="italyEInvoicingReferenceType"><span class="label-after-radio">{{#i18n}}invoice-fields.pec{{/i18n}}</span></label>
<input type="text" class="form-control" name="italyEInvoicingReferencePEC">
<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}}">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label><input type="radio" name="italyEInvoicingReferenceType"><span class="label-after-radio">{{#i18n}}invoice.fields.neither{{/i18n}}</span></label>
<label><input {{#paymentForm.italyEInvoicingTypeAddresseeNone}}checked{{/paymentForm.italyEInvoicingTypeAddresseeNone}} type="radio" value="NONE" name="italyEInvoicingReferenceType"><span class="label-after-radio">{{#i18n}}invoice.fields.neither{{/i18n}}</span></label>
</div>
</div>
</div>
Expand Down

0 comments on commit 657fae2

Please sign in to comment.