Erweiterungen
This commit is contained in:
@@ -77,14 +77,16 @@ public final class AdminLayout extends AppLayout {
|
|||||||
|
|
||||||
// Only admin-specific menu items
|
// Only admin-specific menu items
|
||||||
SideNavItem dashboard = new SideNavItem("Dashboard", "admin-dashboard", new Icon(VaadinIcon.DASHBOARD));
|
SideNavItem dashboard = new SideNavItem("Dashboard", "admin-dashboard", new Icon(VaadinIcon.DASHBOARD));
|
||||||
SideNavItem systemSettings = new SideNavItem("Systemeinstellungen", "admin-settings", new Icon(VaadinIcon.COG));
|
SideNavItem pdfTest = new SideNavItem("PDF Test", "pdf-test", new Icon(VaadinIcon.FILE_TEXT_O));
|
||||||
SideNavItem userManagement = new SideNavItem("Benutzerverwaltung", "admin-users", new Icon(VaadinIcon.USERS));
|
//SideNavItem systemSettings = new SideNavItem("Systemeinstellungen", "admin-settings", new Icon(VaadinIcon.COG));
|
||||||
SideNavItem systemLogs = new SideNavItem("System-Logs", "admin-logs", new Icon(VaadinIcon.FILE_TEXT));
|
//SideNavItem userManagement = new SideNavItem("Benutzerverwaltung", "admin-users", new Icon(VaadinIcon.USERS));
|
||||||
|
//SideNavItem systemLogs = new SideNavItem("System-Logs", "admin-logs", new Icon(VaadinIcon.FILE_TEXT));
|
||||||
|
|
||||||
nav.addItem(dashboard);
|
nav.addItem(dashboard);
|
||||||
nav.addItem(systemSettings);
|
nav.addItem(pdfTest);
|
||||||
nav.addItem(userManagement);
|
//nav.addItem(systemSettings);
|
||||||
nav.addItem(systemLogs);
|
//nav.addItem(userManagement);
|
||||||
|
//nav.addItem(systemLogs);
|
||||||
|
|
||||||
// Create a vertical layout to hold menu items
|
// Create a vertical layout to hold menu items
|
||||||
VerticalLayout navContainer = new VerticalLayout();
|
VerticalLayout navContainer = new VerticalLayout();
|
||||||
|
|||||||
211
src/main/java/de/assecutor/votianlt/pages/view/PdfTestView.java
Normal file
211
src/main/java/de/assecutor/votianlt/pages/view/PdfTestView.java
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
package de.assecutor.votianlt.pages.view;
|
||||||
|
|
||||||
|
import com.vaadin.flow.component.button.Button;
|
||||||
|
import com.vaadin.flow.component.button.ButtonVariant;
|
||||||
|
import com.vaadin.flow.component.html.Anchor;
|
||||||
|
import com.vaadin.flow.component.html.Div;
|
||||||
|
import com.vaadin.flow.component.html.H1;
|
||||||
|
import com.vaadin.flow.component.html.H3;
|
||||||
|
import com.vaadin.flow.component.html.Main;
|
||||||
|
import com.vaadin.flow.component.html.Paragraph;
|
||||||
|
import com.vaadin.flow.component.icon.VaadinIcon;
|
||||||
|
import com.vaadin.flow.component.notification.Notification;
|
||||||
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||||
|
import com.vaadin.flow.router.Menu;
|
||||||
|
import com.vaadin.flow.router.PageTitle;
|
||||||
|
import com.vaadin.flow.router.Route;
|
||||||
|
import com.vaadin.flow.server.StreamResource;
|
||||||
|
import com.vaadin.flow.theme.lumo.LumoUtility;
|
||||||
|
import de.assecutor.votianlt.model.InvoiceData;
|
||||||
|
import de.assecutor.votianlt.service.InvoicePdfGenerator;
|
||||||
|
import jakarta.annotation.security.RolesAllowed;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@Route(value = "pdf-test", layout = de.assecutor.votianlt.pages.base.ui.view.AdminLayout.class)
|
||||||
|
@PageTitle("PDF Test")
|
||||||
|
@RolesAllowed("ADMIN")
|
||||||
|
@Menu(order = 2, icon = "lumo:edit")
|
||||||
|
@Slf4j
|
||||||
|
public class PdfTestView extends Main {
|
||||||
|
|
||||||
|
private final InvoicePdfGenerator invoicePdfGenerator;
|
||||||
|
private final VerticalLayout contentLayout;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public PdfTestView(InvoicePdfGenerator invoicePdfGenerator) {
|
||||||
|
this.invoicePdfGenerator = invoicePdfGenerator;
|
||||||
|
|
||||||
|
setSizeFull();
|
||||||
|
addClassNames(LumoUtility.BoxSizing.BORDER, LumoUtility.Display.FLEX,
|
||||||
|
LumoUtility.FlexDirection.COLUMN, LumoUtility.Padding.MEDIUM);
|
||||||
|
|
||||||
|
// Header
|
||||||
|
H1 title = new H1("PDF Test");
|
||||||
|
title.addClassNames(LumoUtility.Margin.Bottom.MEDIUM, LumoUtility.Margin.Top.NONE);
|
||||||
|
|
||||||
|
Paragraph description = new Paragraph(
|
||||||
|
"Hier können Sie den InvoicePdfGenerator mit Testdaten testen. " +
|
||||||
|
"Klicken Sie auf 'PDF generieren', um eine Test-Rechnung zu erstellen."
|
||||||
|
);
|
||||||
|
|
||||||
|
// Generate PDF button
|
||||||
|
Button generateButton = new Button("PDF generieren", VaadinIcon.FILE_TEXT_O.create());
|
||||||
|
generateButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
|
||||||
|
generateButton.addClickListener(e -> generateTestPdf());
|
||||||
|
|
||||||
|
// Content layout for results
|
||||||
|
contentLayout = new VerticalLayout();
|
||||||
|
contentLayout.setPadding(false);
|
||||||
|
contentLayout.setSpacing(true);
|
||||||
|
|
||||||
|
add(title, description, generateButton, contentLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateTestPdf() {
|
||||||
|
try {
|
||||||
|
log.info("Generating test PDF with InvoicePdfGenerator");
|
||||||
|
|
||||||
|
// Create test invoice data
|
||||||
|
InvoiceData testData = createTestInvoiceData();
|
||||||
|
|
||||||
|
// Generate PDF
|
||||||
|
byte[] pdfBytes = invoicePdfGenerator.generateInvoicePdf(testData);
|
||||||
|
|
||||||
|
// Clear previous content
|
||||||
|
contentLayout.removeAll();
|
||||||
|
|
||||||
|
// Create download link
|
||||||
|
StreamResource resource = new StreamResource("test-rechnung.pdf",
|
||||||
|
() -> new ByteArrayInputStream(pdfBytes));
|
||||||
|
resource.setContentType("application/pdf");
|
||||||
|
|
||||||
|
Anchor downloadLink = new Anchor(resource, "");
|
||||||
|
downloadLink.getElement().setAttribute("download", true);
|
||||||
|
downloadLink.add(new Button("PDF herunterladen", VaadinIcon.DOWNLOAD.create()));
|
||||||
|
|
||||||
|
// Success message
|
||||||
|
H3 successTitle = new H3("PDF erfolgreich generiert!");
|
||||||
|
successTitle.addClassName(LumoUtility.TextColor.SUCCESS);
|
||||||
|
|
||||||
|
Paragraph info = new Paragraph(
|
||||||
|
String.format("PDF-Größe: %d KB", pdfBytes.length / 1024)
|
||||||
|
);
|
||||||
|
|
||||||
|
// PDF preview container
|
||||||
|
Div pdfContainer = new Div();
|
||||||
|
pdfContainer.addClassName(LumoUtility.Background.CONTRAST_5);
|
||||||
|
pdfContainer.getStyle()
|
||||||
|
.set("border-radius", "8px")
|
||||||
|
.set("padding", "1rem")
|
||||||
|
.set("margin-top", "1rem");
|
||||||
|
|
||||||
|
// Embed PDF for preview
|
||||||
|
String pdfDataUrl = "data:application/pdf;base64," +
|
||||||
|
java.util.Base64.getEncoder().encodeToString(pdfBytes);
|
||||||
|
|
||||||
|
pdfContainer.getElement().setProperty("innerHTML",
|
||||||
|
"<embed src=\"" + pdfDataUrl + "\" type=\"application/pdf\" " +
|
||||||
|
"width=\"100%\" height=\"600px\" style=\"border-radius: 4px;\">");
|
||||||
|
|
||||||
|
contentLayout.add(successTitle, info, downloadLink, pdfContainer);
|
||||||
|
|
||||||
|
Notification.show("PDF erfolgreich generiert!", 3000, Notification.Position.BOTTOM_CENTER);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error generating test PDF", e);
|
||||||
|
|
||||||
|
contentLayout.removeAll();
|
||||||
|
|
||||||
|
H3 errorTitle = new H3("Fehler beim Generieren des PDFs");
|
||||||
|
errorTitle.addClassName(LumoUtility.TextColor.ERROR);
|
||||||
|
|
||||||
|
Paragraph errorMsg = new Paragraph("Fehler: " + e.getMessage());
|
||||||
|
|
||||||
|
contentLayout.add(errorTitle, errorMsg);
|
||||||
|
|
||||||
|
Notification.show("Fehler beim PDF-Generieren: " + e.getMessage(),
|
||||||
|
5000, Notification.Position.BOTTOM_CENTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private InvoiceData createTestInvoiceData() {
|
||||||
|
InvoiceData data = new InvoiceData();
|
||||||
|
|
||||||
|
// Invoice details
|
||||||
|
data.setInvoiceNumber("TEST-2024-001");
|
||||||
|
data.setInvoiceDate(LocalDate.now());
|
||||||
|
data.setDueDate(LocalDate.now().plusDays(14));
|
||||||
|
|
||||||
|
// Company information
|
||||||
|
data.setCompanyName("VotianLT Logistics GmbH");
|
||||||
|
data.setCompanyStreet("Musterstraße");
|
||||||
|
data.setCompanyHouseNumber("123");
|
||||||
|
data.setCompanyZip("12345");
|
||||||
|
data.setCompanyCity("Berlin");
|
||||||
|
data.setCompanyPhone("+49 30 12345678");
|
||||||
|
data.setCompanyEmail("info@votianlt.de");
|
||||||
|
data.setCompanyWebsite("www.votianlt.de");
|
||||||
|
|
||||||
|
// Tax information
|
||||||
|
data.setTaxNumber("12/345/67890");
|
||||||
|
data.setVatId("DE123456789");
|
||||||
|
data.setCommercialRegister("HRB 12345 B");
|
||||||
|
data.setManagingDirector("Max Mustermann");
|
||||||
|
|
||||||
|
// Bank details
|
||||||
|
data.setBankName("Deutsche Bank AG");
|
||||||
|
data.setIban("DE89 3704 0044 0532 0130 00");
|
||||||
|
data.setBic("COBADEFFXXX");
|
||||||
|
|
||||||
|
// Customer information
|
||||||
|
data.setCustomerName("Musterkunde GmbH");
|
||||||
|
data.setCustomerStreet("Kundenstraße");
|
||||||
|
data.setCustomerHouseNumber("456");
|
||||||
|
data.setCustomerZip("54321");
|
||||||
|
data.setCustomerCity("Hamburg");
|
||||||
|
data.setCustomerCountry("Deutschland");
|
||||||
|
|
||||||
|
// Invoice items
|
||||||
|
data.setItems(Arrays.asList(
|
||||||
|
new InvoiceData.InvoiceItem(
|
||||||
|
"Transport Hamburg - Berlin",
|
||||||
|
new BigDecimal("1"),
|
||||||
|
"Stück",
|
||||||
|
new BigDecimal("250.00"),
|
||||||
|
new BigDecimal("19")
|
||||||
|
),
|
||||||
|
new InvoiceData.InvoiceItem(
|
||||||
|
"Zusätzliche Wartezeit",
|
||||||
|
new BigDecimal("2.5"),
|
||||||
|
"Stunden",
|
||||||
|
new BigDecimal("45.00"),
|
||||||
|
new BigDecimal("19")
|
||||||
|
),
|
||||||
|
new InvoiceData.InvoiceItem(
|
||||||
|
"Verpackungsmaterial",
|
||||||
|
new BigDecimal("5"),
|
||||||
|
"Stück",
|
||||||
|
new BigDecimal("12.50"),
|
||||||
|
new BigDecimal("19")
|
||||||
|
),
|
||||||
|
new InvoiceData.InvoiceItem(
|
||||||
|
"Expressaufschlag",
|
||||||
|
new BigDecimal("1"),
|
||||||
|
"Stück",
|
||||||
|
new BigDecimal("75.00"),
|
||||||
|
new BigDecimal("19")
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
// VAT rate
|
||||||
|
data.setVatRate(new BigDecimal("19.0"));
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user