fix: refine invoice visibility in jobs and invoices

This commit is contained in:
2026-03-10 11:59:28 +01:00
parent 5a23671ae2
commit 1445c23c0b
2 changed files with 22 additions and 10 deletions

View File

@@ -75,6 +75,7 @@ public class InvoicesView extends VerticalLayout implements HasDynamicTitle {
private void loadInvoices() {
String currentUserId = securityService.getCurrentUserId().toHexString();
List<CustomerInvoice> invoices = customerInvoiceRepository.findByUserId(currentUserId).stream()
.filter(this::hasPdfData)
.sorted((left, right) -> {
if (left.getInvoiceDate() == null && right.getInvoiceDate() == null) {
return 0;
@@ -120,6 +121,10 @@ public class InvoicesView extends VerticalLayout implements HasDynamicTitle {
}
}
private boolean hasPdfData(CustomerInvoice invoice) {
return invoice != null && invoice.getPdfData() != null && invoice.getPdfData().length > 0;
}
private String getRecipientLabel(CustomerInvoice invoice) {
return firstNonBlank(invoice.getRecipientCompany(), invoice.getRecipientName(), "");
}

View File

@@ -138,9 +138,9 @@ public class ShowJobsView extends VerticalLayout implements HasDynamicTitle {
// Invoice column - only show for completed jobs
grid.addComponentColumn(job -> {
if (job.getStatus() == JobStatus.COMPLETED) {
Button invoiceBtn = new Button(new Icon(VaadinIcon.DOLLAR));
invoiceBtn.addThemeVariants(ButtonVariant.LUMO_TERTIARY, ButtonVariant.LUMO_SUCCESS);
if (job.getInvoiceId() != null) {
if (hasInvoice(job)) {
Button invoiceBtn = new Button(new Icon(VaadinIcon.FILE_TEXT_O));
invoiceBtn.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
invoiceBtn.setTooltipText(getTranslation("jobs.tooltip.showinvoice"));
invoiceBtn.addClickListener(e -> {
e.getSource().getElement().getNode();
@@ -153,14 +153,17 @@ public class ShowJobsView extends VerticalLayout implements HasDynamicTitle {
}
}, () -> getUI().ifPresent(ui -> ui.navigate("create_invoice/" + job.getId().toHexString())));
});
} else {
invoiceBtn.setTooltipText(getTranslation("jobs.tooltip.createinvoice"));
invoiceBtn.addClickListener(e -> {
return invoiceBtn;
}
Button createInvoiceBtn = new Button(new Icon(VaadinIcon.DOLLAR));
createInvoiceBtn.addThemeVariants(ButtonVariant.LUMO_TERTIARY, ButtonVariant.LUMO_SUCCESS);
createInvoiceBtn.setTooltipText(getTranslation("jobs.tooltip.createinvoice"));
createInvoiceBtn.addClickListener(e -> {
e.getSource().getElement().getNode();
getUI().ifPresent(ui -> ui.navigate("create_invoice/" + job.getId().toHexString()));
});
}
return invoiceBtn;
return createInvoiceBtn;
}
return new com.vaadin.flow.component.html.Span();
}).setHeader("").setWidth("60px").setFlexGrow(0);
@@ -357,6 +360,10 @@ public class ShowJobsView extends VerticalLayout implements HasDynamicTitle {
return value;
}
private boolean hasInvoice(Job job) {
return job.getInvoiceId() != null && !job.getInvoiceId().isBlank();
}
private String extractCompanyName(String customerSelection) {
if (customerSelection == null || customerSelection.isBlank()) {
return "";