From e8e258b9ff0aa0305d1bd3fa8e08a69cf504fe41 Mon Sep 17 00:00:00 2001 From: HennaCH <2132132@champlaincollege.qc.ca> Date: Mon, 23 Oct 2023 22:12:36 -0400 Subject: [PATCH] feat/BILL-CPC-933_Implement_Button_To_Calculate_Bill_With_Tax (#572) JIRA: https://champlainsaintlambert.atlassian.net/browse/CPC-933 ## Context: We need to see the amount to pay including taxes ## Changes - Added taxedAmount field in BillResponseDTO and Bill - Added tax calculation in BillServiceImpl and BillServiceClient - I modified the BillResponseDTP in the tests so that they include the taxedAmount - Made the button to display the taxed amount ## Before and After UI (Required for UI-impacting PRs) Before ![Screenshot (1130)](https://github.com/cgerard321/champlain_petclinic/assets/104155362/685a193c-94ce-4f2f-8c3c-2a381b43fe13) After ![Screenshot (1144)](https://github.com/cgerard321/champlain_petclinic/assets/104155362/c3dc172a-0c33-448f-a8c2-f2944a8f3bd5) ___________________________________________________________ ![Screenshot (1145)](https://github.com/cgerard321/champlain_petclinic/assets/104155362/804e1831-86ed-43b0-9a38-ee9a4bb6b1e1) ## Dev notes (Optional) - I am not sure if my changes in the test sections are good --- .../domainclientlayer/BillServiceClient.java | 4 +++- .../bffapigateway/dtos/Bills/BillDetails.java | 1 + .../dtos/Bills/BillResponseDTO.java | 1 + .../bill-details/bill-details.template.html | 6 ++++++ .../BillServiceClientIntegrationTest.java | 3 +++ .../ApiGatewayControllerTest.java | 16 ++++++++-------- .../billing/businesslayer/BillServiceImpl.java | 4 +++- .../com/petclinic/billing/datalayer/Bill.java | 1 + .../billing/datalayer/BillResponseDTO.java | 1 + 9 files changed, 27 insertions(+), 10 deletions(-) diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java index 2fbe287ef4..4972edb84e 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClient.java @@ -33,7 +33,9 @@ public Mono getBilling(final String billId) { return webClientBuilder.build().get() .uri(billServiceUrl + "/{billId}", billId) .retrieve() - .bodyToMono(BillResponseDTO.class); + .bodyToMono(BillResponseDTO.class) + .doOnNext(t -> t.setTaxedAmount(((t.getAmount() * 15)/100)+ t.getAmount())) + .doOnNext(t -> t.setTaxedAmount(Math.round(t.getTaxedAmount() * 100.0) / 100.0)); } public Flux getBillsByOwnerId(final String customerId) { return webClientBuilder.build().get() diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Bills/BillDetails.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Bills/BillDetails.java index bace697802..f4838ecc2c 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Bills/BillDetails.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Bills/BillDetails.java @@ -14,6 +14,7 @@ public class BillDetails { private String vetId; private String visitType; private double amount; + private double taxedAmount; private BillStatus billStatus; private LocalDate dueDate; } diff --git a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Bills/BillResponseDTO.java b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Bills/BillResponseDTO.java index 1c2f50a768..f5c45506cc 100644 --- a/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Bills/BillResponseDTO.java +++ b/api-gateway/src/main/java/com/petclinic/bffapigateway/dtos/Bills/BillResponseDTO.java @@ -19,6 +19,7 @@ public class BillResponseDTO { private String vetId; private LocalDate date; private double amount; + private double taxedAmount; private BillStatus billStatus; private LocalDate dueDate; } diff --git a/api-gateway/src/main/resources/static/scripts/bill-details/bill-details.template.html b/api-gateway/src/main/resources/static/scripts/bill-details/bill-details.template.html index a16cd4e878..7a3bdb6e5b 100644 --- a/api-gateway/src/main/resources/static/scripts/bill-details/bill-details.template.html +++ b/api-gateway/src/main/resources/static/scripts/bill-details/bill-details.template.html @@ -42,6 +42,8 @@
Due Date: {{$ctrl.bills.dueDate}}


Final Amount Due: {{$ctrl.bills.amount}}
+
Final Amount Including Taxes: {{$ctrl.bills.taxedAmount}}
+

@@ -78,6 +80,10 @@
Final Amount Due: {{$ctrl.bills.amount}}
window.print(); } + + function changeShow(){ + show = !show; + } diff --git a/api-gateway/src/test/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClientIntegrationTest.java b/api-gateway/src/test/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClientIntegrationTest.java index 90ca330f43..cf701cd71d 100644 --- a/api-gateway/src/test/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClientIntegrationTest.java +++ b/api-gateway/src/test/java/com/petclinic/bffapigateway/domainclientlayer/BillServiceClientIntegrationTest.java @@ -59,6 +59,7 @@ private void prepareResponse(Consumer consumer) { private final BillResponseDTO billResponseDTO = BillResponseDTO.builder() .billId("1") .amount(100.0) + .taxedAmount(115.0) .customerId("1") .vetId("1") .visitType("Check up") @@ -70,6 +71,7 @@ private void prepareResponse(Consumer consumer) { private final BillResponseDTO billResponseDTO2 = BillResponseDTO.builder() .billId("2") .amount(150.0) + .taxedAmount(172.5) .customerId("2") .vetId("2") .visitType("Check up") @@ -81,6 +83,7 @@ private void prepareResponse(Consumer consumer) { private final BillResponseDTO billResponseDTO3 = BillResponseDTO.builder() .billId("3") .amount(250.0) + .taxedAmount(287.5) .customerId("3") .vetId("3") .visitType("Check up") diff --git a/api-gateway/src/test/java/com/petclinic/bffapigateway/presentationlayer/ApiGatewayControllerTest.java b/api-gateway/src/test/java/com/petclinic/bffapigateway/presentationlayer/ApiGatewayControllerTest.java index c914bd01a1..8bdbeff094 100755 --- a/api-gateway/src/test/java/com/petclinic/bffapigateway/presentationlayer/ApiGatewayControllerTest.java +++ b/api-gateway/src/test/java/com/petclinic/bffapigateway/presentationlayer/ApiGatewayControllerTest.java @@ -1921,10 +1921,10 @@ void shouldThrowMethodNotAllowedWhenDeletePetsIsMissingPetId(){ @Test void shouldGetAllBills() { - BillResponseDTO billResponseDTO = new BillResponseDTO("BillUUID","1","Test type","1",null,25.00, BillStatus.PAID,null); + BillResponseDTO billResponseDTO = new BillResponseDTO("BillUUID","1","Test type","1",null,25.00, 28.75,BillStatus.PAID,null); - BillResponseDTO billResponseDTO2 = new BillResponseDTO("BillUUID2","2","Test type","2",null,27.00, BillStatus.UNPAID,null); + BillResponseDTO billResponseDTO2 = new BillResponseDTO("BillUUID2","2","Test type","2",null,27.00, 31.05,BillStatus.UNPAID,null); when(billServiceClient.getAllBilling()).thenReturn(Flux.just(billResponseDTO,billResponseDTO2)); client.get() @@ -1940,9 +1940,9 @@ void shouldGetAllBills() { @Test void shouldGetAllPaidBills() { - BillResponseDTO billResponseDTO = new BillResponseDTO("BillUUID","1","Test type","1",null,25.00, BillStatus.PAID,null); + BillResponseDTO billResponseDTO = new BillResponseDTO("BillUUID","1","Test type","1",null,25.00, 28.75,BillStatus.PAID,null); - BillResponseDTO billResponseDTO2 = new BillResponseDTO("BillUUID2","2","Test type","2",null,27.00, BillStatus.PAID,null); + BillResponseDTO billResponseDTO2 = new BillResponseDTO("BillUUID2","2","Test type","2",null,27.00, 31.05, BillStatus.PAID,null); when(billServiceClient.getAllPaidBilling()).thenReturn(Flux.just(billResponseDTO,billResponseDTO2)); client.get() @@ -1958,9 +1958,9 @@ void shouldGetAllPaidBills() { @Test void shouldGetAllUnpaidBills() { - BillResponseDTO billResponseDTO = new BillResponseDTO("BillUUID","1","Test type","1",null,25.00, BillStatus.UNPAID, null); + BillResponseDTO billResponseDTO = new BillResponseDTO("BillUUID","1","Test type","1",null,25.00, 28.75, BillStatus.UNPAID, null); - BillResponseDTO billResponseDTO2 = new BillResponseDTO("BillUUID2","2","Test type","2",null,27.00, BillStatus.UNPAID,null); + BillResponseDTO billResponseDTO2 = new BillResponseDTO("BillUUID2","2","Test type","2",null,27.00, 31.05,BillStatus.UNPAID,null); when(billServiceClient.getAllUnpaidBilling()).thenReturn(Flux.just(billResponseDTO,billResponseDTO2)); client.get() @@ -1976,9 +1976,9 @@ void shouldGetAllUnpaidBills() { @Test void shouldGetAllOverdueBills() { - BillResponseDTO billResponseDTO = new BillResponseDTO("BillUUID","1","Test type","1",null,25.00, BillStatus.OVERDUE,null); + BillResponseDTO billResponseDTO = new BillResponseDTO("BillUUID","1","Test type","1",null,25.00, 28.75, BillStatus.OVERDUE,null); - BillResponseDTO billResponseDTO2 = new BillResponseDTO("BillUUID2","2","Test type","2",null,27.00, BillStatus.OVERDUE, null); + BillResponseDTO billResponseDTO2 = new BillResponseDTO("BillUUID2","2","Test type","2",null,27.00, 31.05, BillStatus.OVERDUE, null); when(billServiceClient.getAllOverdueBilling()).thenReturn(Flux.just(billResponseDTO,billResponseDTO2)); client.get() diff --git a/billing-service/src/main/java/com/petclinic/billing/businesslayer/BillServiceImpl.java b/billing-service/src/main/java/com/petclinic/billing/businesslayer/BillServiceImpl.java index f0441ea102..e8d8dcf3ed 100644 --- a/billing-service/src/main/java/com/petclinic/billing/businesslayer/BillServiceImpl.java +++ b/billing-service/src/main/java/com/petclinic/billing/businesslayer/BillServiceImpl.java @@ -21,7 +21,9 @@ public class BillServiceImpl implements BillService{ @Override public Mono getBillByBillId(String billUUID) { - return billRepository.findByBillId(billUUID).map(EntityDtoUtil::toBillResponseDto); + return billRepository.findByBillId(billUUID).map(EntityDtoUtil::toBillResponseDto) + .doOnNext(t -> t.setTaxedAmount(((t.getAmount() * 15)/100)+ t.getAmount())) + .doOnNext(t -> t.setTaxedAmount(Math.round(t.getTaxedAmount() * 100.0) / 100.0)); } @Override diff --git a/billing-service/src/main/java/com/petclinic/billing/datalayer/Bill.java b/billing-service/src/main/java/com/petclinic/billing/datalayer/Bill.java index e797e31e91..85658eb340 100644 --- a/billing-service/src/main/java/com/petclinic/billing/datalayer/Bill.java +++ b/billing-service/src/main/java/com/petclinic/billing/datalayer/Bill.java @@ -22,6 +22,7 @@ public class Bill { private String vetLastName; private LocalDate date; private double amount; + private double taxedAmount; private BillStatus billStatus; private LocalDate dueDate; diff --git a/billing-service/src/main/java/com/petclinic/billing/datalayer/BillResponseDTO.java b/billing-service/src/main/java/com/petclinic/billing/datalayer/BillResponseDTO.java index 9c18cbec36..ef30e5fab6 100644 --- a/billing-service/src/main/java/com/petclinic/billing/datalayer/BillResponseDTO.java +++ b/billing-service/src/main/java/com/petclinic/billing/datalayer/BillResponseDTO.java @@ -17,6 +17,7 @@ public class BillResponseDTO { private String vetId; private LocalDate date; private double amount; + private double taxedAmount; private BillStatus billStatus; private LocalDate dueDate;