Update validacionCompra.php

This commit is contained in:
lizandrogd
2025-02-27 20:15:18 -05:00
parent 4bcfc03168
commit c6e9bdbfd3
+19
View File
@@ -39,6 +39,7 @@ class validacionCompra extends Command
//$hora_antes = Carbon::now()->subHours(100)->format('Y-m-d H:i:s'); // 24 horas antes
$hora_antes = Carbon::now()->subMinutes(15)->format('Y-m-d H:i:s');
$this->validarSaldosNegativos($hora_antes, $fecha_ahora);
$resultados = Historiale::select('vendedor_id')
->selectRaw('COUNT(*) as total')
@@ -177,4 +178,22 @@ class validacionCompra extends Command
return response()->json(['error' => 'Error al corregir: ' . $e->getMessage()], 500);
}
}
public function validarSaldosNegativos($anterior,$actual)
{
$consultaLog = Log_general::whereBetween('created_at', [$anterior, $actual])
->where('detalle', 'LIKE', '%disponible: $-%')
->get();
//dd($consultaLog);
if (!$consultaLog->isEmpty()) {
foreach ($consultaLog as $log) {
$historial = Historiale::find($log->historial_id);
$usuario = User::find($historial->vendedor_id);
$email = $usuario->email;
$mensaje = "⚠️ Saldo Negativo ⚠️\nUsuario: {$email}\nFecha: {$log->created_at}\nDetalle: {$log->detalle}";
$this->enviarTelegram($mensaje);
}
}
return;
}
}