use of alfio.model.BillingDocument.Type in project alf.io by alfio-event.
the class BillingDocumentManager method prepareModelForBillingDocument.
private Map<String, Object> prepareModelForBillingDocument(PurchaseContext purchaseContext, TicketReservation reservation, OrderSummary summary, BillingDocument.Type type) {
Organization organization = organizationRepository.getById(purchaseContext.getOrganizationId());
String creditNoteNumber = null;
if (type == CREDIT_NOTE) {
// override credit note number
creditNoteNumber = generateCreditNoteNumber(purchaseContext, reservation);
}
var bankingInfo = configurationManager.getFor(Set.of(VAT_NR, INVOICE_ADDRESS, BANK_ACCOUNT_NR, BANK_ACCOUNT_OWNER), purchaseContext.getConfigurationLevel());
Optional<String> invoiceAddress = bankingInfo.get(INVOICE_ADDRESS).getValue();
Optional<String> bankAccountNr = bankingInfo.get(BANK_ACCOUNT_NR).getValue();
Optional<String> bankAccountOwner = bankingInfo.get(BANK_ACCOUNT_OWNER).getValue();
Optional<String> vat = bankingInfo.get(VAT_NR).getValue();
Map<Integer, List<Ticket>> ticketsByCategory = ticketRepository.findTicketsInReservation(reservation.getId()).stream().collect(groupingBy(Ticket::getCategoryId));
final List<TicketWithCategory> ticketsWithCategory;
if (!ticketsByCategory.isEmpty()) {
ticketsWithCategory = ticketCategoryRepository.findByIds(ticketsByCategory.keySet()).stream().flatMap(tc -> ticketsByCategory.get(tc.getId()).stream().map(t -> new TicketWithCategory(t, tc))).collect(toList());
} else {
ticketsWithCategory = Collections.emptyList();
}
var reservationShortId = configurationManager.getShortReservationID(purchaseContext, reservation);
Map<String, Object> model = TemplateResource.prepareModelForConfirmationEmail(organization, purchaseContext, reservation, vat, ticketsWithCategory, summary, "", "", reservationShortId, invoiceAddress, bankAccountNr, bankAccountOwner, Map.of());
boolean euBusiness = StringUtils.isNotBlank(reservation.getVatCountryCode()) && StringUtils.isNotBlank(reservation.getVatNr()) && configurationManager.getForSystem(ConfigurationKeys.EU_COUNTRIES_LIST).getRequiredValue().contains(reservation.getVatCountryCode()) && PriceContainer.VatStatus.isVatExempt(reservation.getVatStatus());
model.put("isEvent", purchaseContext.ofType(PurchaseContextType.event));
model.put("euBusiness", euBusiness);
model.put("publicId", configurationManager.getPublicReservationID(purchaseContext, reservation));
var additionalInfo = ticketReservationRepository.getAdditionalInfo(reservation.getId());
model.put("invoicingAdditionalInfo", additionalInfo.getInvoicingAdditionalInfo());
model.put("billingDetails", additionalInfo.getBillingDetails());
if (type == CREDIT_NOTE) {
model.put(CREDIT_NOTE_NUMBER, creditNoteNumber);
}
return model;
}
Aggregations