Skip to content

Commit

Permalink
conditinner l'affchage de l'encart 'PAYE' sur la facture en fonction …
Browse files Browse the repository at this point in the history
…du statut de la commande
  • Loading branch information
benjaminpochat committed Oct 11, 2024
1 parent b709735 commit 98a336c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private String getOrderInvoice(ProducerCustomerOrderItems producerCustomerOrderI
getTotalPriceWithoutTax(orderItems),
getTotalTax(orderItems),
getTotalPriceWithTax(orderItems),
sale.getDeliveryStart()
sale.getDeliveryStart(),
getPayedStampStyleClass(orderItems)
);
}

Expand All @@ -128,6 +129,13 @@ private float getItemPriceWithoutTax(OrderItem item) {
return item.getUnitPrice() * item.getPackageLot().getNetWeight() / 1.055f;
}

private String getPayedStampStyleClass(List<OrderItem> orderItems) {
boolean allOrdersPayed = orderItems.stream()
.map(OrderItem::getOrder)
.allMatch(order -> (List.of(PAYMENT_COMPLETED, DELIVERED)).contains(order.getStatus()));
return allOrdersPayed ? "payed" : "not-payed";
}

record ProducerCustomerOrderItems(Producer producer, Customer customer, List<OrderItem> orderItems) {
}
}
4 changes: 4 additions & 0 deletions backend/app/src/main/resources/html/pdf/invoice_template.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ body {
text-align: center;
transform: rotate(10deg);
width: 3cm;
}

.not-payed {
visibility: collapse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</div>
</td>
<td>
<div class="payed">PAYÉ</div>
<div class="%17$s">PAYÉ</div>
</td>
</tr>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import de.redsix.pdfcompare.CompareResult;
import de.redsix.pdfcompare.PdfComparator;
import eu.viandeendirect.model.BeefProduction;
import eu.viandeendirect.model.Order;
import eu.viandeendirect.model.PackageLot;
import eu.viandeendirect.model.Sale;
import eu.viandeendirect.model.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -29,6 +26,7 @@

import static eu.viandeendirect.domains.order.OrderTestUtils.*;
import static eu.viandeendirect.domains.order.OrderTestUtils.createCustomer;
import static eu.viandeendirect.model.OrderStatus.BOOKED_WITHOUT_PAYMENT;
import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
Expand Down Expand Up @@ -59,6 +57,7 @@ void generatePDF_should_produce_a_correct_pdf() throws IOException, URISyntaxExc

Order order1 = createOrder(123, createCustomer("Valentine", "DURAND", "0601020304"), Map.of(packageLot1, 1, packageLot2, 2));
Order order2 = createOrder(124, createCustomer("Thibaut", "ENCOSTUME-MONFISS", "0304050607"), Map.of(packageLot1, 2));
order2.setStatus(BOOKED_WITHOUT_PAYMENT);
sale.setOrders(List.of(order1, order2));

// when
Expand Down
Binary file modified backend/app/src/test/resources/pdf/expected_invoices.pdf
Binary file not shown.

0 comments on commit 98a336c

Please sign in to comment.