Notificaciones en envio de estados de cuenta
This commit is contained in:
@@ -379,6 +379,67 @@ Public Class ClsMovimientos
|
||||
Return Retorno
|
||||
End Function
|
||||
|
||||
Public Function AddNotificacionEdoCuentaCliente(CveCliente As Integer, Fecha As DateTime) As Boolean
|
||||
Dim Retorno As Boolean = False
|
||||
|
||||
DataAdapter("PA_Sis_NotificacionesEdoCuentaClienteAdd")
|
||||
|
||||
With SqlAdapter.SelectCommand.Parameters
|
||||
.Add("@CveCliente", SqlDbType.Int).Value = CveCliente
|
||||
.Add("@Fecha", SqlDbType.DateTime).Value = Fecha
|
||||
End With
|
||||
|
||||
Try
|
||||
SqlAdapter.Fill(Data)
|
||||
Retorno = True
|
||||
Catch ex As SqlException
|
||||
OnError("Ocurrió un error al agregar notificaciones del estado de cuenta del Cliente.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo)
|
||||
End Try
|
||||
|
||||
Return Retorno
|
||||
End Function
|
||||
|
||||
Public Function GetNotificacionEdoCuentaCliente(CveEmpresa As Integer, CveCliente As Integer, Fecha As DateTime) As Boolean
|
||||
Dim Retorno As Boolean = False
|
||||
|
||||
DataAdapter("PA_Sis_NotificacionesEdoCuentaClienteGet")
|
||||
|
||||
With SqlAdapter.SelectCommand.Parameters
|
||||
.Add("@CveEmpresa", SqlDbType.Int).Value = CveEmpresa
|
||||
.Add("@CveCliente", SqlDbType.Int).Value = CveCliente
|
||||
.Add("@Fecha", SqlDbType.DateTime).Value = Fecha
|
||||
End With
|
||||
|
||||
Try
|
||||
SqlAdapter.Fill(Data)
|
||||
Retorno = True
|
||||
Catch ex As SqlException
|
||||
OnError("Ocurrió un error al obtener notificaciones del estado de cuenta del Cliente.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo)
|
||||
End Try
|
||||
|
||||
Return Retorno
|
||||
End Function
|
||||
|
||||
Public Function UpdateNotificacionEdoCuentaCliente(CveNotificacionBitacora As Integer, Notifico As Boolean) As Boolean
|
||||
Dim Retorno As Boolean = False
|
||||
|
||||
DataAdapter("PA_Sis_NotificacionesEdoCuentaClienteUpdate")
|
||||
|
||||
With SqlAdapter.SelectCommand.Parameters
|
||||
.Add("@CveNotificacionBitacora", SqlDbType.Int).Value = CveNotificacionBitacora
|
||||
.Add("@Notifico", SqlDbType.Bit).Value = Notifico
|
||||
End With
|
||||
|
||||
Try
|
||||
SqlAdapter.Fill(Data)
|
||||
Retorno = True
|
||||
Catch ex As SqlException
|
||||
OnError("Ocurrió un error al actualizar notificaciones del estado de cuenta del Cliente.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo)
|
||||
End Try
|
||||
|
||||
Return Retorno
|
||||
End Function
|
||||
|
||||
Public Function GetClienteAbonos(CveCliente As Integer, Optional CveMoneda As Integer = -1, Optional FechaVencimientoInicio As String = "-1", Optional FechaVencimientoFin As String = "-1", Optional CveUsuarioProgramo As Integer = -1, Optional Serie As String = "", Optional SelectTop As Integer = -1, Optional CveClienteSucursal As Integer = -1) As Boolean
|
||||
Dim Retorno As Boolean = False
|
||||
DataAdapter("PA_Vta_ClienteBancos")
|
||||
|
||||
@@ -20,6 +20,8 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
Dim retorno As String = "no se encontro la variable"
|
||||
Try
|
||||
Dim metodo As String = ""
|
||||
Dim FechaActual As DateTime = Now
|
||||
Dim FechaEnvio As DateTime = FechaActual
|
||||
|
||||
If context.Request("var") IsNot Nothing Then
|
||||
URLParametros = Parametros(context.Request("var"))
|
||||
@@ -36,6 +38,9 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
End Using
|
||||
ElseIf context.Request("metodo") IsNot Nothing Then
|
||||
metodo = context.Request("metodo").ToString()
|
||||
If context.Request("FechaEnvio") IsNot Nothing Then
|
||||
FechaEnvio = context.Request("FechaEnvio").ToString().ToDateTime()
|
||||
End If
|
||||
End If
|
||||
|
||||
Select Case metodo
|
||||
@@ -46,7 +51,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
context.Response.Write(retorno)
|
||||
Case "EstadosCuenta"
|
||||
'CargaEstadosCuenta(context, 119, 227774)
|
||||
CargaEstadosCuenta(context, 119, -1)
|
||||
CargaEstadosCuenta(context, 119, -1, FechaEnvio, FechaActual)
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
ex.GuardaLog(ex.ToString())
|
||||
@@ -270,7 +275,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
|
||||
|
||||
#Region "E S T A D O S D E C U E N T A"
|
||||
Private Sub CargaEstadosCuenta(ByVal context As HttpContext, pCveEmpresa As Integer, pCveCliente As Integer)
|
||||
Private Sub CargaEstadosCuenta(ByVal context As HttpContext, pCveEmpresa As Integer, pCveCliente As Integer, FechaEnvio As DateTime, FechaActual As DateTime)
|
||||
Dim Retorno As New JArray()
|
||||
Dim DtEmpresas As DataTable = Nothing
|
||||
Using ObjEmpresas As New ClsSisEmpresas()
|
||||
@@ -282,7 +287,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
If DtEmpresas IsNot Nothing Then
|
||||
For Each Row As DataRow In DtEmpresas.Rows
|
||||
Dim Usuario = ValidaUsuarioSistema(Row("CveEmpresa").ToString().ToEntero())
|
||||
Dim obj = EjecutarEnvioEstadoCuenta(Usuario, pCveCliente:=pCveCliente)
|
||||
Dim obj = EjecutarEnvioEstadoCuenta(Usuario, FechaEnvio, FechaActual, pCveCliente:=pCveCliente)
|
||||
|
||||
Retorno.Add(obj)
|
||||
Next
|
||||
@@ -331,7 +336,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
End Sub
|
||||
|
||||
|
||||
Private Function EjecutarEnvioEstadoCuenta(UsuarioActual As Usuario, Optional pCveCliente As Integer = -1) As JObject
|
||||
Private Function EjecutarEnvioEstadoCuenta(UsuarioActual As Usuario, FechaEnvio As DateTime, FechaActual As DateTime, Optional pCveCliente As Integer = -1) As JObject
|
||||
Dim ClientesSinEnviar As New JArray()
|
||||
Dim ClientesEdoEnviado As New JArray()
|
||||
|
||||
@@ -341,15 +346,13 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
New JProperty("Fecha", DateTime.Now.ToString("dd/MM/yyy HH:mm:ss"))
|
||||
)
|
||||
Dim DTClientes As DataTable = Nothing
|
||||
Dim EnviarPendientes As Boolean = False
|
||||
|
||||
'Using ObjCliente As New ClsClientes
|
||||
' If ObjCliente.GetClientes(pCveCliente, "-1", "-1", "-1", "-1", "-1", "-1", -1, UsuarioActual.CveEmpresa, TipoCliente:=-1, Estatus:=1) Then
|
||||
' If ObjCliente.DtResultados.Rows.Count > 0 Then
|
||||
' DTClientes = ObjCliente.DtResultados.Copy()
|
||||
' End If
|
||||
' End If
|
||||
'End Using
|
||||
If FechaActual <> FechaEnvio Then
|
||||
EnviarPendientes = True
|
||||
End If
|
||||
|
||||
If Not EnviarPendientes Then
|
||||
Using ObjMov As New ClsMovimientos
|
||||
Dim FechaI As String = "-1"
|
||||
Dim FechaF As String = "-1"
|
||||
@@ -375,18 +378,63 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
End If
|
||||
|
||||
End Using
|
||||
End If
|
||||
|
||||
If DTClientes IsNot Nothing Then
|
||||
|
||||
If DTClientes IsNot Nothing OrElse EnviarPendientes Then
|
||||
|
||||
'DTClientes = DTClientes.FiltraParametros("CveCliente IN (227289,227429,227733,227838,228181,228544,229176,229481,230029,230432,230860,230911,230918,231197,231576,232173,232185,233055,233295,233357,233588,236379,236460,237161,237635,238285,238530,238622,238724,239033,239099,239865,239895,239903,240202,240235,240236,240238,240303,240340,262404,262517,264765,264806,264825,264848,264930,265063,265180,265213,265214,265236,265344,265492,265555,265669,265797,265952,265963,266156,266182,268346,268396,268488,268535,268539,268558,268562,268706,268726,268787,268868,268889,268910,268925,269023,269081,269089,272066,272070,272657,273080,273084,275627,276259,276587,281115,283110,284664,285392,287653,288711,291374,292444,295578,296375,296598,302728,303936,306897,307183,311007,320060,320685,320800,323520,323772,325237,326996,327801,330630,331741,332118,337105,340502,341796,342807,343858,355862,358123,365794,371524,375391,377122,377948,378267,380167,381210,381878,383098,383250,383339,383650,384472,385321,385585,386630,387114,388987,396341,396405,396541,401995,404175,408306,416386,416819,420275,438732,447566,447636,450284,464150,464376,468051,475172,475932,476984,477997,478426)")
|
||||
Dim DtNotificaciones As DataTable = Nothing
|
||||
|
||||
Dim TieneErrorRegistro As Boolean = False
|
||||
|
||||
Dim ObjMovimientos As New ClsMovimientos
|
||||
ObjMovimientos.IniciaTransacSQL()
|
||||
|
||||
If Not EnviarPendientes Then
|
||||
Try
|
||||
For Each RowCliente As DataRow In DTClientes.Rows
|
||||
If Not ObjMovimientos.AddNotificacionEdoCuentaCliente(RowCliente("CveCliente").ToString().ToEntero(), FechaEnvio) Then
|
||||
GuardaLog("Ocurrio un error al agregar las notificaciones de edo cuenta. CveCliente: " + RowCliente("CveCliente").ToString())
|
||||
TieneErrorRegistro = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Catch ex As Exception
|
||||
GuardaLog("Ocurrio un error al agregar las notificaciones de edo cuenta" + ex.ToString())
|
||||
TieneErrorRegistro = True
|
||||
End Try
|
||||
End If
|
||||
|
||||
Dim CveCliente As Integer = RowCliente("CveCliente").ToString().ToEntero()
|
||||
If Not TieneErrorRegistro Then
|
||||
If ObjMovimientos.GetNotificacionEdoCuentaCliente(UsuarioActual.CveEmpresa, -1, FechaEnvio) Then
|
||||
DtNotificaciones = ObjMovimientos.DtResultados.Copy()
|
||||
Else
|
||||
TieneErrorRegistro = True
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
If Not TieneErrorRegistro Then
|
||||
ObjMovimientos.Commit()
|
||||
Else
|
||||
ObjMovimientos.RollBack()
|
||||
If DtNotificaciones IsNot Nothing Then
|
||||
DtNotificaciones.Clear()
|
||||
DtNotificaciones = Nothing
|
||||
End If
|
||||
End If
|
||||
ObjMovimientos.Dispose()
|
||||
DTClientes.Dispose()
|
||||
|
||||
Try
|
||||
If DtNotificaciones IsNot Nothing Then
|
||||
For Each Row As DataRow In DtNotificaciones.Rows
|
||||
Dim CveCliente As Integer = Row("CveCliente").ToString().ToEntero()
|
||||
Dim Cliente As New Modelos.ClienteModel(CveCliente, UsuarioActual.CveEmpresa)
|
||||
|
||||
If Cliente IsNot Nothing Then
|
||||
Dim Correo As String = Cliente.CobranzaCorreo '"japmx95@gmail.com" 'RowCliente("CobranzaCorreo").ToString()
|
||||
Dim Correo As String = Cliente.CobranzaCorreo
|
||||
|
||||
Dim Envio As Boolean = False
|
||||
If Not String.IsNullOrEmpty(Correo) Then
|
||||
@@ -395,6 +443,10 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
|
||||
If Envio Then
|
||||
|
||||
Using ObjMov As New ClsMovimientos
|
||||
ObjMov.UpdateNotificacionEdoCuentaCliente(Row("CveNotificacionBitacora").ToString().ToEntero(), Notifico:=True)
|
||||
End Using
|
||||
|
||||
ClientesEdoEnviado.Add(New JObject(
|
||||
New JProperty("CveCliente", Cliente.CveCliente),
|
||||
New JProperty("Cliente", Cliente.Nombre)
|
||||
@@ -410,9 +462,17 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
))
|
||||
End If
|
||||
End If
|
||||
|
||||
Next
|
||||
DTClientes.Dispose()
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
GuardaLog("Ocurrio un error al agregar las notificaciones de edo cuenta. " + ex.ToString())
|
||||
End Try
|
||||
|
||||
If DtNotificaciones IsNot Nothing Then
|
||||
DtNotificaciones.Dispose()
|
||||
End If
|
||||
|
||||
End If
|
||||
Json.Add(New JProperty("ClientesSinEnviar", ClientesSinEnviar))
|
||||
Json.Add(New JProperty("ClientesEdoEnviado", ClientesEdoEnviado))
|
||||
@@ -422,7 +482,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
|
||||
Private Function EnviarEstadoCuenta(UsuarioActual As Usuario, Correo As String, Cliente As Modelos.ClienteModel) As Boolean
|
||||
Dim Retorno As Boolean = True
|
||||
|
||||
Try
|
||||
Dim ArchivoPDF As Byte() = Nothing
|
||||
|
||||
Dim Formato As String = "PDF"
|
||||
@@ -465,7 +525,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
Catch ex As Exception
|
||||
Retorno = False
|
||||
dtt = Nothing
|
||||
OnError("Ocurrió un erro al obtener el CxC", ex)
|
||||
GuardaLog("Ocurrió un erro al obtener el CxC. " + ex.ToString())
|
||||
End Try
|
||||
|
||||
If Not Retorno Then
|
||||
@@ -602,7 +662,8 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
OnError("Ocurrió error al mandar MAIL de Orden de Compra", ex)
|
||||
ArchivoPDF = Nothing
|
||||
GuardaLog("Ocurrió un erro al obtener el CxC" + ex.ToString())
|
||||
End Try
|
||||
Else
|
||||
Dim lista = New List(Of CrystalParametro)
|
||||
@@ -653,7 +714,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
OnError("Ocurrió un error al generar el pdf", ex)
|
||||
GuardaLog("Ocurrió un error al generar el pdf" + ex.ToString())
|
||||
ArchivoPDF = Nothing
|
||||
End Try
|
||||
|
||||
@@ -668,16 +729,18 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
<br />
|
||||
<b>ESTE CORREO SE GENERO EN FORMA AUTOMATICA.</b>", Cliente.NombreComercial, UsuarioActual.Empresa.Empresa)
|
||||
|
||||
Dim Hilo As New System.Threading.Thread(Sub() MandaCorreo(ArchivoPDF, Correo, $"Estado Actual de Cartera {UsuarioActual.Empresa.Empresa}", Cuerpo))
|
||||
Hilo.Start()
|
||||
Retorno = True
|
||||
Retorno = MandaCorreo(ArchivoPDF, Correo, $"Estado Actual de Cartera {UsuarioActual.Empresa.Empresa}", Cuerpo)
|
||||
Catch ex As Exception
|
||||
Retorno = False
|
||||
OnError("Ocurrió error al mandar el correo de estado de cuenta", ex)
|
||||
GuardaLog("Ocurrió error al mandar el correo de estado de cuenta. " + ex.ToString())
|
||||
End Try
|
||||
Else
|
||||
Retorno = False
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Retorno = False
|
||||
GuardaLog("Ocurrió error al mandar el correo de estado de cuenta" + ex.ToString())
|
||||
End Try
|
||||
|
||||
Return Retorno
|
||||
End Function
|
||||
@@ -749,7 +812,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
|
||||
Return Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, Archivos:=LSRutasMail)
|
||||
Catch ex As Exception
|
||||
OnError("Ocurrió un error al enviar el correo de edo cuenta", ex)
|
||||
GuardaLog("Ocurrió error al mandar el correo de estado de cuenta. " + ex.ToString())
|
||||
Return False
|
||||
End Try
|
||||
|
||||
|
||||
Reference in New Issue
Block a user