From 9fb947f0c0789e33442bd0a3e7d8233e181448ab Mon Sep 17 00:00:00 2001
From: hamzaelbakkouri <hamza.elbakkouri@marketingconfort.com>
Date: Tue, 4 Mar 2025 10:37:22 +0000
Subject: [PATCH 1/3] MYS-739/fix sales sessions details

---
 .../controllers/SaleSessionController.java    | 10 +++++-
 .../repositories/SaleSessionRepository.java   |  3 ++
 .../services/SaleSessionService.java          |  1 +
 .../services/impl/SaleSessionServiceImp.java  | 31 +++++++++++++------
 4 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java b/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java
index 73842d3..2fddd43 100644
--- a/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java
+++ b/src/main/java/com/marketingconfort/mydressin/controllers/SaleSessionController.java
@@ -41,6 +41,13 @@ public class SaleSessionController {
         return new ResponseEntity<>(saleSessions, HttpStatus.OK);
     }
 
+    @GetMapping("/rangeSaleSessions/{start}/{end}")
+    @PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
+    public ResponseEntity<List<SaleSessionDTO>> rangeSaleSessions(@PathVariable LocalDateTime start,@PathVariable LocalDateTime end, @RequestHeader String requestAuthorization) {
+        List<SaleSessionDTO> saleSessions = saleSessionService.exportSaleSessions(start, end);
+        return new ResponseEntity<>(saleSessions, HttpStatus.OK);
+    }
+
     @PostMapping("/addProductToCartFromLive")
     @PreAuthorize("@securityCustomExpressions.isClientTrusted(#requestAuthorization)")
     public CompletableFuture<ResponseEntity<?>> addProductToCartFromLive(
@@ -125,7 +132,7 @@ public class SaleSessionController {
 
     @DeleteMapping("/deleteSession/{id}")
     @PreAuthorize("hasRole('ADMIN') and @securityCustomExpressions.isClientTrusted(#requestAuthorization)")
-    public ResponseEntity<Void> deleteSaleSessionById(@PathVariable Long id,@RequestHeader String requestAuthorization) {
+    public ResponseEntity<Void> deleteSaleSessionById(@PathVariable Long id, @RequestHeader String requestAuthorization) {
         try {
             saleSessionService.deleteSaleSessionById(id);
             return ResponseEntity.noContent().build();
@@ -133,6 +140,7 @@ public class SaleSessionController {
             return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
         }
     }
+
     @PutMapping("/restock/{sessionId}")
     public ResponseEntity<SaleSessionDTO> restockSaleSession(@PathVariable Long sessionId) {
         SaleSessionDTO updatedSession = saleSessionService.restockSaleSession(sessionId);
diff --git a/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java b/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java
index 650fb3f..fe9fbd2 100644
--- a/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java
+++ b/src/main/java/com/marketingconfort/mydressin/repositories/SaleSessionRepository.java
@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 
+import java.time.LocalDateTime;
 import java.util.List;
 
 @Repository
@@ -68,4 +69,6 @@ public interface SaleSessionRepository extends JpaRepository<SaleSession, Long>
             "JOIN so.itemCart ic " +
             "WHERE ss.id = :sessionId")
     Long getTotalPaidProducts(@Param("sessionId") Long sessionId);
+
+    List<SaleSession> findByStartedDateBetween(LocalDateTime startDate, LocalDateTime endDate);
 }
diff --git a/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java b/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java
index 14bff7e..db0d951 100644
--- a/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java
+++ b/src/main/java/com/marketingconfort/mydressin/services/SaleSessionService.java
@@ -17,6 +17,7 @@ public interface SaleSessionService {
     SaleSessionDTO createSaleSession(SaleSession saleSession);
 
     List<SaleSessionDTO> getAllSaleSessions();
+    List<SaleSessionDTO> exportSaleSessions(LocalDateTime startDate, LocalDateTime endDate);
 
     SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession);
 
diff --git a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java
index cc5ef6a..3c7f6d0 100644
--- a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java
+++ b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java
@@ -19,6 +19,7 @@ import com.marketingconfort.mydressin.repositories.SaleSessionRepository;
 import com.marketingconfort.mydressin.repositories.SessionOrderRepository;
 import com.marketingconfort.mydressin.services.*;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -34,6 +35,7 @@ import java.util.stream.Collectors;
 
 @AllArgsConstructor
 @Service
+@Slf4j
 public class SaleSessionServiceImp implements SaleSessionService {
     private final SaleSessionRepository saleSessionRepository;
     private final SaleSessionMapper saleSessionMapper;
@@ -59,6 +61,13 @@ public class SaleSessionServiceImp implements SaleSessionService {
                 .collect(Collectors.toList());
     }
 
+    @Override
+    public List<SaleSessionDTO> exportSaleSessions(LocalDateTime startDate, LocalDateTime endDate) {
+        return saleSessionRepository.findByStartedDateBetween(startDate, endDate).stream()
+                .map(this::getSaleSessionStatistics)
+                .collect(Collectors.toList());
+    }
+
 
     @Override
     public SaleSessionDTO getSaleSessionStatistics(SaleSession saleSession) {
@@ -70,11 +79,13 @@ public class SaleSessionServiceImp implements SaleSessionService {
         );
         Long totalOrderProducts = saleSessionRepository.getTotalOrderProducts(saleSessionDTO.getId());
         Integer totalClientsCount = saleSessionRepository.getTotalClientsCount(saleSessionDTO.getId());
-        Double totalSalesAmount = saleSessionRepository.getTotalSalesAmount(saleSessionDTO.getId(),excludedStatuses);
+        Double totalSalesAmount = saleSessionRepository.getTotalSalesAmount(saleSessionDTO.getId(), excludedStatuses);
         Long totalConsultedProducts = saleSessionRepository.getTotalConsultedProducts(saleSessionDTO.getId());
         Long totalDeletedProducts = saleSessionRepository.getTotalDeletedProducts(saleSessionDTO.getId());
         Long totalPaidProducts = saleSessionRepository.getTotalPaidProducts(saleSessionDTO.getId());
 
+
+
         saleSessionDTO.setOrderProductsNumber(totalOrderProducts != null ? totalOrderProducts : 0);
         saleSessionDTO.setClientsNumber(totalClientsCount != null ? totalClientsCount : 0);
         saleSessionDTO.setTotalSales(totalSalesAmount != null ? totalSalesAmount : 0.0);
@@ -134,18 +145,18 @@ public class SaleSessionServiceImp implements SaleSessionService {
         if (cart instanceof Cart) {
             existingItemCart = ((Cart) cart).getItems().stream()
                     .filter(item -> item.getProductId().equals(request.getProductId())
-                        && item.getSource() == ItemSource.LIVE
-                        && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
-                        && item.getStatus() != ItemCartStatus.DELETED_BO
-                        && item.getStatus() != ItemCartStatus.DELETED_SITE)
+                            && item.getSource() == ItemSource.LIVE
+                            && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
+                            && item.getStatus() != ItemCartStatus.DELETED_BO
+                            && item.getStatus() != ItemCartStatus.DELETED_SITE)
                     .findFirst();
         } else {
             existingItemCart = ((UnregisteredCart) cart).getItems().stream()
                     .filter(item -> item.getProductId().equals(request.getProductId())
-                        && item.getSource() == ItemSource.LIVE
-                        && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
-                        && item.getStatus() != ItemCartStatus.DELETED_BO
-                        && item.getStatus() != ItemCartStatus.DELETED_SITE)
+                            && item.getSource() == ItemSource.LIVE
+                            && Objects.equals(item.getOrder().getSaleSession().getId(), request.getSessionId())
+                            && item.getStatus() != ItemCartStatus.DELETED_BO
+                            && item.getStatus() != ItemCartStatus.DELETED_SITE)
                     .findFirst();
         }
         ItemCart itemCart;
@@ -169,7 +180,7 @@ public class SaleSessionServiceImp implements SaleSessionService {
         itemCart.setProduct(stockResult.getProductDTO());
         if (itemCart.getProduct() != null) {
             double price = (itemCart.getProduct().getPromoPrice() != 0) ? itemCart.getProduct().getPromoPrice() : itemCart.getProduct().getRegularPrice();
-            order.setOrderPrice(price* itemCart.getQuantity());
+            order.setOrderPrice(price * itemCart.getQuantity());
         }
         orderRepository.save(order);
 
-- 
GitLab


From 88dbaa5fd75bf333e8c01dc1e67b5fb71e108ade Mon Sep 17 00:00:00 2001
From: hamzaelbakkouri <hamza.elbakkouri@marketingconfort.com>
Date: Tue, 4 Mar 2025 11:44:12 +0000
Subject: [PATCH 2/3] MYD-739/Fix List with sale sessions stats

---
 .../mydressin/services/impl/SaleSessionServiceImp.java          | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java
index 6b07a74..2bcc906 100644
--- a/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java
+++ b/src/main/java/com/marketingconfort/mydressin/services/impl/SaleSessionServiceImp.java
@@ -265,7 +265,7 @@ public class SaleSessionServiceImp implements SaleSessionService {
         Pageable pageable = PageRequest.of(page, size, Sort.by(direction, sortBy));
 
         return saleSessionRepository.getSaleSessionsPage(type,name,startDate,endDate,pageable)
-                .map(saleSessionMapper::toDTO);
+                .map(this::getSaleSessionStatistics);
     }
 
     @Override
-- 
GitLab


From 29339dcca616589507d200c6dda4884f6b5c3a76 Mon Sep 17 00:00:00 2001
From: hamzaelbakkouri <hamza.elbakkouri@marketingconfort.com>
Date: Tue, 4 Mar 2025 11:45:34 +0000
Subject: [PATCH 3/3] MYD-739/Fix List with sale sessions stats

---
 CHANGELOG.md | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 97721a4..2f5bee3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,22 @@
+## [1.0.73-RELEASE]
+### Added
+- MYD-739/Fix List with sale sessions stats
+
+### Changed
+- Changes in existing functionality.
+
+### Deprecated
+- Soon-to-be removed features.
+
+### Removed
+- Features that have been removed.
+
+### Fixed
+- fix item count
+
+### Security
+- Any security improvements.
+
 ## [1.0.72-RELEASE]
 ### Added
 - MYD-628/add pagination, sort and search for deleted sale session
-- 
GitLab