11package com .utp .meditrackapp .infrastructure .persistence .jdbc ;
22
33import com .utp .meditrackapp .core .config .DatabaseConfig ;
4+ import com .utp .meditrackapp .core .util .DateTimeProvider ;
45import com .utp .meditrackapp .core .validation .SedeAccessValidator ;
56import com .utp .meditrackapp .domain .ports .out .DashboardRepository ;
67
@@ -56,7 +57,7 @@ public int getLotesPorVencerCount(int dias) {
5657 String sedeId = SedeAccessValidator .getSedeParaConsulta ();
5758
5859 StringBuilder sql = new StringBuilder (
59- "SELECT COUNT(*) as total FROM lotes WHERE fecha_vencimiento <= DATEADD(day, ?, GETDATE()) AND fecha_vencimiento >= GETDATE() "
60+ "SELECT COUNT(*) as total FROM lotes WHERE fecha_vencimiento <= DATEADD(day, ?, ?) AND fecha_vencimiento >= ? "
6061 );
6162
6263 if (sedeId != null ) {
@@ -65,8 +66,11 @@ public int getLotesPorVencerCount(int dias) {
6566
6667 try (Connection conn = dbConfig .getConnection ();
6768 PreparedStatement ps = conn .prepareStatement (sql .toString ())) {
69+ java .sql .Timestamp now = Timestamp .valueOf (DateTimeProvider .now ());
6870 int i = 1 ;
6971 ps .setInt (i ++, dias );
72+ ps .setTimestamp (i ++, now );
73+ ps .setTimestamp (i ++, now );
7074 if (sedeId != null ) {
7175 ps .setString (i ++, sedeId );
7276 }
@@ -140,7 +144,7 @@ public int getVolumenMovimientos(int dias) {
140144 String sedeId = SedeAccessValidator .getSedeParaConsulta ();
141145
142146 StringBuilder sql = new StringBuilder (
143- "SELECT COUNT(*) as total FROM movimientos WHERE fecha_registro >= DATEADD(day, -?, GETDATE() )"
147+ "SELECT COUNT(*) as total FROM movimientos WHERE fecha_registro >= DATEADD(day, -?, ? )"
144148 );
145149
146150 if (sedeId != null ) {
@@ -151,6 +155,7 @@ public int getVolumenMovimientos(int dias) {
151155 PreparedStatement ps = conn .prepareStatement (sql .toString ())) {
152156 int i = 1 ;
153157 ps .setInt (i ++, dias );
158+ ps .setTimestamp (i ++, Timestamp .valueOf (DateTimeProvider .now ()));
154159 if (sedeId != null ) {
155160 ps .setString (i ++, sedeId );
156161 }
@@ -173,7 +178,7 @@ public List<Map<String, Object>> getTendenciaInventario(int meses) {
173178 " SUM(CASE WHEN m.tipo_id = 'MOV-T-01' THEN m.cantidad ELSE 0 END) - " +
174179 " SUM(CASE WHEN m.tipo_id = 'MOV-T-02' THEN m.cantidad ELSE 0 END) as total " +
175180 "FROM movimientos m " +
176- "WHERE m.fecha_registro >= DATEADD(month, -?, GETDATE() ) "
181+ "WHERE m.fecha_registro >= DATEADD(month, -?, ? ) "
177182 );
178183
179184 if (sedeId != null ) {
@@ -186,6 +191,7 @@ public List<Map<String, Object>> getTendenciaInventario(int meses) {
186191 PreparedStatement ps = conn .prepareStatement (sql .toString ())) {
187192 int i = 1 ;
188193 ps .setInt (i ++, meses );
194+ ps .setTimestamp (i ++, Timestamp .valueOf (DateTimeProvider .now ()));
189195 if (sedeId != null ) {
190196 ps .setString (i ++, sedeId );
191197 }
0 commit comments