trabajando en la vista de peiddos

This commit is contained in:
2025-11-17 22:52:35 +01:00
parent 6ff5250d1b
commit 997741c3c9
17 changed files with 4119 additions and 34 deletions

View File

@ -1,9 +1,23 @@
package com.imprimelibros.erp.pedidos;
import java.time.LocalDateTime;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface PedidoRepository extends JpaRepository<Pedido, Long>, JpaSpecificationExecutor<Pedido> {
// Suma de "total" para un "createdBy" desde una fecha dada
@Query("""
SELECT COALESCE(SUM(p.total), 0)
FROM Pedido p
WHERE p.createdBy.id = :userId
AND p.createdAt >= :afterDate
""")
Double sumTotalByCreatedByAndCreatedAtAfter(@Param("userId") Long userId,
@Param("afterDate") LocalDateTime afterDate);
}