use of alfio.model.TicketReservationInvoicingAdditionalInfo.ItalianEInvoicing in project alf.io by alfio-event.
the class EventApiController method exportLines.
private Stream<String[]> exportLines(String eventName, Principal principal, List<String> fields, Map<Integer, TicketCategory> categoriesMap, ZoneId eventZoneId) {
var username = principal.getName();
var eInvoicingEnabled = configurationManager.isItalianEInvoicingEnabled(eventManager.getEventAndOrganizationId(eventName, username));
return eventManager.findAllConfirmedTicketsForCSV(eventName, username).stream().map(trs -> {
Ticket t = trs.getTicket();
var currencyCode = t.getCurrencyCode();
TicketReservation reservation = trs.getTicketReservation();
List<String> line = new ArrayList<>();
if (fields.contains("ID")) {
line.add(t.getUuid());
}
if (fields.contains("Category")) {
line.add(categoriesMap.get(t.getCategoryId()).getName());
}
if (fields.contains("Event")) {
line.add(eventName);
}
if (fields.contains("Status")) {
line.add(t.getStatus().toString());
}
if (fields.contains("OriginalPrice")) {
line.add(MonetaryUtil.centsToUnit(t.getSrcPriceCts(), currencyCode).toString());
}
if (fields.contains("PaidPrice")) {
line.add(MonetaryUtil.centsToUnit(t.getFinalPriceCts(), currencyCode).toString());
}
if (fields.contains("Discount")) {
line.add(MonetaryUtil.centsToUnit(t.getDiscountCts(), currencyCode).toString());
}
if (fields.contains("VAT")) {
line.add(MonetaryUtil.centsToUnit(t.getVatCts(), currencyCode).toString());
}
if (fields.contains("ReservationID")) {
line.add(t.getTicketsReservationId());
}
if (fields.contains("Full Name")) {
line.add(t.getFullName());
}
if (fields.contains("First Name")) {
line.add(t.getFirstName());
}
if (fields.contains("Last Name")) {
line.add(t.getLastName());
}
if (fields.contains("E-Mail")) {
line.add(t.getEmail());
}
if (fields.contains("Locked")) {
line.add(String.valueOf(t.getLockedAssignment()));
}
if (fields.contains("Language")) {
line.add(String.valueOf(t.getUserLanguage()));
}
if (fields.contains("Confirmation")) {
line.add(reservation.getConfirmationTimestamp().withZoneSameInstant(eventZoneId).toString());
}
if (fields.contains("Billing Address")) {
line.add(reservation.getBillingAddress());
}
if (fields.contains("Country Code")) {
line.add(reservation.getVatCountryCode());
}
boolean paymentIdRequested = fields.contains("Payment ID");
boolean paymentGatewayRequested = fields.contains(PAYMENT_METHOD);
if ((paymentIdRequested || paymentGatewayRequested)) {
Optional<Transaction> transaction = trs.getTransaction();
if (paymentIdRequested) {
line.add(defaultString(transaction.map(Transaction::getPaymentId).orElse(null), transaction.map(Transaction::getTransactionId).orElse("")));
}
if (paymentGatewayRequested) {
line.add(transaction.map(tr -> tr.getPaymentProxy().name()).orElse(""));
}
}
if (eInvoicingEnabled) {
var billingDetails = trs.getBillingDetails();
var optionalInvoicingData = Optional.ofNullable(billingDetails.getInvoicingAdditionalInfo()).map(TicketReservationInvoicingAdditionalInfo::getItalianEInvoicing);
if (fields.contains(FISCAL_CODE)) {
line.add(optionalInvoicingData.map(ItalianEInvoicing::getFiscalCode).orElse(""));
}
if (fields.contains(REFERENCE_TYPE)) {
line.add(optionalInvoicingData.map(ItalianEInvoicing::getReferenceTypeAsString).orElse(""));
}
if (fields.contains("Addressee Code")) {
line.add(optionalInvoicingData.map(ItalianEInvoicing::getAddresseeCode).orElse(""));
}
if (fields.contains("PEC")) {
line.add(optionalInvoicingData.map(ItalianEInvoicing::getPec).orElse(""));
}
}
// obviously not optimized
Map<String, String> additionalValues = ticketFieldRepository.findAllValuesForTicketId(t.getId());
Predicate<String> contains = FIXED_FIELDS::contains;
fields.stream().filter(contains.negate()).filter(f -> f.startsWith(CUSTOM_FIELDS_PREFIX)).forEachOrdered(field -> {
String customFieldName = field.substring(CUSTOM_FIELDS_PREFIX.length());
line.add(additionalValues.getOrDefault(customFieldName, "").replace("\"", ""));
});
return line.toArray(new String[0]);
});
}
Aggregations