From 6522688beba2bd0e8110940e6e8d82d198bf5ccb Mon Sep 17 00:00:00 2001 From: Alessio Cialini Date: Tue, 9 Jan 2024 12:22:55 +0100 Subject: [PATCH] fix: grand total amount format --- .../service/impl/BizEventToReceiptServiceImpl.java | 4 +++- .../receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java | 7 +++++++ .../pagopa/receipt/pdf/helpdesk/ReceiptToReviewedTest.java | 4 ---- .../pdf/helpdesk/RecoverNotNotifiedReceiptTest.java | 4 ---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BizEventToReceiptServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BizEventToReceiptServiceImpl.java index a8337a2..5217cf4 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BizEventToReceiptServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/BizEventToReceiptServiceImpl.java @@ -27,10 +27,12 @@ import org.slf4j.LoggerFactory; import java.math.BigDecimal; +import java.math.RoundingMode; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.atomic.AtomicReference; +import static it.gov.pagopa.receipt.pdf.helpdesk.utils.BizEventToReceiptUtils.formatAmount; import static it.gov.pagopa.receipt.pdf.helpdesk.utils.BizEventToReceiptUtils.getItemSubject; public class BizEventToReceiptServiceImpl implements BizEventToReceiptService { @@ -261,7 +263,7 @@ public Receipt createCartReceipt(List bizEventList) { public static BigDecimal getAmount(BizEvent bizEvent) { if (bizEvent.getTransactionDetails() != null && bizEvent.getTransactionDetails().getTransaction() != null && bizEvent.getTransactionDetails().getTransaction().getGrandTotal() != 0) { - return new BigDecimal(bizEvent.getTransactionDetails().getTransaction().getGrandTotal()); + return formatAmount(bizEvent.getTransactionDetails().getTransaction().getGrandTotal()); } if (bizEvent.getPaymentInfo() != null && bizEvent.getPaymentInfo().getAmount() != null) { return new BigDecimal(bizEvent.getPaymentInfo().getAmount()); diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java index 1a43daf..64c23c5 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java @@ -26,6 +26,7 @@ import org.slf4j.Logger; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -410,5 +411,11 @@ public static MassiveRecoverCartResult massiveRecoverCartByStatus( .build(); } + public static BigDecimal formatAmount(long grandTotal) { + BigDecimal amount = new BigDecimal(grandTotal); + BigDecimal divider = new BigDecimal(100); + return amount.divide(divider, 2, RoundingMode.UNNECESSARY); + } + private BizEventToReceiptUtils() {} } diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/ReceiptToReviewedTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/ReceiptToReviewedTest.java index 57d646a..e584ee2 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/ReceiptToReviewedTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/ReceiptToReviewedTest.java @@ -82,10 +82,6 @@ void requestWithValidCartSaveReceiptErrorInReviewed() throws ReceiptNotFoundExce .build(); when(receiptCosmosClient.getReceiptError(BIZ_EVENT_ID)).thenReturn(receiptError); - when(request.getQueryParameters()).thenReturn(Collections.singletonMap("isCart","true")); - - when(receiptCosmosClient.getCartDocument(any())).thenReturn(generateCart()); - function = spy(new ReceiptToReviewed(receiptCosmosClient)); // test execution diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptTest.java index dbb4cbe..7eac105 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverNotNotifiedReceiptTest.java @@ -113,10 +113,6 @@ void recoverNotNotifiedCartReceiptSuccess() throws ReceiptNotFoundException, Car return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status); }).when(requestMock).createResponseBuilder(any(HttpStatus.class)); - when(requestMock.getQueryParameters()).thenReturn(Collections.singletonMap("isCart","true")); - - when(receiptCosmosServiceMock.getCart(any())).thenReturn(generateCart()); - // test execution HttpResponseMessage response = sut.run(requestMock, EVENT_ID, documentReceipts, executionContextMock);