fix: refine invoice visibility in jobs and invoices
This commit is contained in:
@@ -75,6 +75,7 @@ public class InvoicesView extends VerticalLayout implements HasDynamicTitle {
|
|||||||
private void loadInvoices() {
|
private void loadInvoices() {
|
||||||
String currentUserId = securityService.getCurrentUserId().toHexString();
|
String currentUserId = securityService.getCurrentUserId().toHexString();
|
||||||
List<CustomerInvoice> invoices = customerInvoiceRepository.findByUserId(currentUserId).stream()
|
List<CustomerInvoice> invoices = customerInvoiceRepository.findByUserId(currentUserId).stream()
|
||||||
|
.filter(this::hasPdfData)
|
||||||
.sorted((left, right) -> {
|
.sorted((left, right) -> {
|
||||||
if (left.getInvoiceDate() == null && right.getInvoiceDate() == null) {
|
if (left.getInvoiceDate() == null && right.getInvoiceDate() == null) {
|
||||||
return 0;
|
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) {
|
private String getRecipientLabel(CustomerInvoice invoice) {
|
||||||
return firstNonBlank(invoice.getRecipientCompany(), invoice.getRecipientName(), "");
|
return firstNonBlank(invoice.getRecipientCompany(), invoice.getRecipientName(), "");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,9 +138,9 @@ public class ShowJobsView extends VerticalLayout implements HasDynamicTitle {
|
|||||||
// Invoice column - only show for completed jobs
|
// Invoice column - only show for completed jobs
|
||||||
grid.addComponentColumn(job -> {
|
grid.addComponentColumn(job -> {
|
||||||
if (job.getStatus() == JobStatus.COMPLETED) {
|
if (job.getStatus() == JobStatus.COMPLETED) {
|
||||||
Button invoiceBtn = new Button(new Icon(VaadinIcon.DOLLAR));
|
if (hasInvoice(job)) {
|
||||||
invoiceBtn.addThemeVariants(ButtonVariant.LUMO_TERTIARY, ButtonVariant.LUMO_SUCCESS);
|
Button invoiceBtn = new Button(new Icon(VaadinIcon.FILE_TEXT_O));
|
||||||
if (job.getInvoiceId() != null) {
|
invoiceBtn.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
|
||||||
invoiceBtn.setTooltipText(getTranslation("jobs.tooltip.showinvoice"));
|
invoiceBtn.setTooltipText(getTranslation("jobs.tooltip.showinvoice"));
|
||||||
invoiceBtn.addClickListener(e -> {
|
invoiceBtn.addClickListener(e -> {
|
||||||
e.getSource().getElement().getNode();
|
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())));
|
}, () -> getUI().ifPresent(ui -> ui.navigate("create_invoice/" + job.getId().toHexString())));
|
||||||
});
|
});
|
||||||
} else {
|
return invoiceBtn;
|
||||||
invoiceBtn.setTooltipText(getTranslation("jobs.tooltip.createinvoice"));
|
|
||||||
invoiceBtn.addClickListener(e -> {
|
|
||||||
e.getSource().getElement().getNode();
|
|
||||||
getUI().ifPresent(ui -> ui.navigate("create_invoice/" + job.getId().toHexString()));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
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 createInvoiceBtn;
|
||||||
}
|
}
|
||||||
return new com.vaadin.flow.component.html.Span();
|
return new com.vaadin.flow.component.html.Span();
|
||||||
}).setHeader("").setWidth("60px").setFlexGrow(0);
|
}).setHeader("").setWidth("60px").setFlexGrow(0);
|
||||||
@@ -357,6 +360,10 @@ public class ShowJobsView extends VerticalLayout implements HasDynamicTitle {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasInvoice(Job job) {
|
||||||
|
return job.getInvoiceId() != null && !job.getInvoiceId().isBlank();
|
||||||
|
}
|
||||||
|
|
||||||
private String extractCompanyName(String customerSelection) {
|
private String extractCompanyName(String customerSelection) {
|
||||||
if (customerSelection == null || customerSelection.isBlank()) {
|
if (customerSelection == null || customerSelection.isBlank()) {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
Reference in New Issue
Block a user