Tareas Programadas Edo Cuenta E119
This commit is contained in:
@@ -9902,6 +9902,7 @@ Namespace Modelos
|
||||
Public Property EsDistribuidor As Boolean
|
||||
Public Property CorreoCotizacion As String
|
||||
Public Property ImprimeNombreSucursal As Integer
|
||||
Public Property CobranzaCorreo As String
|
||||
End Class
|
||||
|
||||
<Serializable>
|
||||
|
||||
@@ -20,10 +20,12 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
Dim retorno As String = "no se encontro la variable"
|
||||
Try
|
||||
Dim metodo As String = ""
|
||||
|
||||
If context.Request("var") IsNot Nothing Then
|
||||
URLParametros = Parametros(context.Request("var"))
|
||||
metodo = URLParametros("metodo")
|
||||
ElseIf context.Request.Headers("Content-Type") IsNot Nothing AndAlso context.Request.Headers("Content-Type").Contains("json") AndAlso context.Request.InputStream IsNot Nothing Then
|
||||
'SI TRAE UN JSON COMO PARAMETRO
|
||||
ElseIf context.Request.Headers("Content-Type") IsNot Nothing AndAlso context.Request.Headers("Content-Type").Contains("json") AndAlso context.Request.InputStream IsNot Nothing AndAlso (context.Request("var") Is Nothing AndAlso context.Request("metodo") IsNot Nothing) Then
|
||||
context.Response.ContentType = "application/json"
|
||||
Using reader As New StreamReader(context.Request.InputStream)
|
||||
Dim json = reader.ReadToEnd()
|
||||
@@ -32,6 +34,8 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
metodo = JsonRequest("Metodo").ToString
|
||||
End If
|
||||
End Using
|
||||
ElseIf context.Request("metodo") IsNot Nothing Then
|
||||
metodo = context.Request("metodo").ToString()
|
||||
End If
|
||||
|
||||
Select Case metodo
|
||||
@@ -282,9 +286,13 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
|
||||
Retorno.Add(obj)
|
||||
Next
|
||||
|
||||
DtEmpresas.Dispose()
|
||||
End If
|
||||
|
||||
context.Response.Write(Retorno.ToString())
|
||||
GuardaLogEdoCuenta(Retorno.ToString())
|
||||
|
||||
context.Response.Write("True")
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -324,7 +332,8 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
|
||||
|
||||
Private Function EjecutarEnvioEstadoCuenta(UsuarioActual As Usuario, Optional pCveCliente As Integer = -1) As JObject
|
||||
Dim ClientesSinEnviar As New JArray()
|
||||
Dim ClientesSinEnviar As New JArray()
|
||||
Dim ClientesEdoEnviado As New JArray()
|
||||
|
||||
Dim Json As New JObject(
|
||||
New JProperty("Empresa", UsuarioActual.Empresa.Empresa),
|
||||
@@ -333,37 +342,80 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
)
|
||||
Dim DTClientes As DataTable = Nothing
|
||||
|
||||
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
|
||||
'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
|
||||
|
||||
Using ObjMov As New ClsMovimientos
|
||||
Dim FechaI As String = "-1"
|
||||
Dim FechaF As String = "-1"
|
||||
Dim FechaVI As String = "-1"
|
||||
Dim FechaVF As String = "-1"
|
||||
Dim TCEspecifico = -1
|
||||
|
||||
Dim CveCobranzaEstatus As Integer = -1
|
||||
Dim CveClienteClasificacion As Integer = -1
|
||||
Dim CveCliente As Integer = -1
|
||||
Dim AplicaAnticipos As Integer = 0
|
||||
|
||||
Dim CveSubProyecto As Integer = -1
|
||||
Dim CveVendedor As Integer = -1
|
||||
Dim Grupo As Integer = 5
|
||||
Dim TipoCambio As Integer = 1
|
||||
Dim TipoDocto As String = "-1"
|
||||
Dim FechaCorte As DateTime = New DateTime(Now.Year, 12, 31)
|
||||
|
||||
If ObjMov.GetCxC(FechaI, FechaF, CveCliente, CveSubProyecto, CveVendedor, -1, -1, "-1", UsuarioActual.CveEmpresa, Grupo, -1, TipoCambio, TCEspecifico, TipoDocto, FechaVI, FechaVF, FechaCorte:=FechaCorte,
|
||||
EstatusCliente:=1, CveUsuarioConsulta:=UsuarioActual.CveUsuario, CveCobranzaEstatus:=CveCobranzaEstatus, CveClienteClasificacion:=-1, TipoCliente:=-1, AplicaAnticiposPagados:=AplicaAnticipos) Then
|
||||
DTClientes = ObjMov.DtResultados.FiltraParametros("CveCliente > 0", DistinctColumns:={"CveCliente"})
|
||||
End If
|
||||
|
||||
End Using
|
||||
|
||||
If DTClientes IsNot Nothing Then
|
||||
For Each RowCliente As DataRow In DTClientes.Rows
|
||||
Dim CveCliente As Integer = RowCliente("CveCliente").ToString().ToEntero()
|
||||
Dim Correo As String = RowCliente("CobranzaCorreo").ToString()
|
||||
|
||||
'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)")
|
||||
|
||||
For Each RowCliente As DataRow In DTClientes.Rows
|
||||
|
||||
Dim CveCliente As Integer = RowCliente("CveCliente").ToString().ToEntero()
|
||||
Dim Cliente As New Modelos.ClienteModel(CveCliente, UsuarioActual.CveEmpresa)
|
||||
|
||||
Dim Envio = EnviarEstadoCuenta(UsuarioActual, Correo, Cliente)
|
||||
If Cliente IsNot Nothing Then
|
||||
Dim Correo As String = Cliente.CobranzaCorreo '"japmx95@gmail.com" 'RowCliente("CobranzaCorreo").ToString()
|
||||
|
||||
If Envio Then
|
||||
Using ObjBitacora As New ClsOIEventos
|
||||
ObjBitacora.AddEventoBitacora("Se envió correo con el estado de cuenta del cliente", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCliente:=Cliente.CveCliente)
|
||||
End Using
|
||||
Else
|
||||
ClientesSinEnviar.Add(New JObject(
|
||||
New JProperty("CveCliente", Cliente.CveCliente),
|
||||
New JProperty("Cliente", Cliente.Nombre)
|
||||
))
|
||||
End If
|
||||
Dim Envio As Boolean = False
|
||||
If Not String.IsNullOrEmpty(Correo) Then
|
||||
Envio = EnviarEstadoCuenta(UsuarioActual, Correo, Cliente)
|
||||
End If
|
||||
|
||||
If Envio Then
|
||||
|
||||
ClientesEdoEnviado.Add(New JObject(
|
||||
New JProperty("CveCliente", Cliente.CveCliente),
|
||||
New JProperty("Cliente", Cliente.Nombre)
|
||||
))
|
||||
|
||||
Using ObjBitacora As New ClsOIEventos
|
||||
ObjBitacora.AddEventoBitacora("Se envió correo con el estado de cuenta del cliente", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCliente:=Cliente.CveCliente)
|
||||
End Using
|
||||
Else
|
||||
ClientesSinEnviar.Add(New JObject(
|
||||
New JProperty("CveCliente", Cliente.CveCliente),
|
||||
New JProperty("Cliente", Cliente.Nombre)
|
||||
))
|
||||
End If
|
||||
End If
|
||||
|
||||
Next
|
||||
DTClientes.Dispose()
|
||||
End If
|
||||
Json.Add(New JProperty("ClientesSinEnviar", ClientesSinEnviar))
|
||||
Json.Add(New JProperty("ClientesSinEnviar", ClientesSinEnviar))
|
||||
Json.Add(New JProperty("ClientesEdoEnviado", ClientesEdoEnviado))
|
||||
|
||||
Return Json
|
||||
End Function
|
||||
@@ -616,10 +668,12 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
<br />
|
||||
<b>ESTE CORREO SE GENERO EN FORMA AUTOMATICA.</b>", Cliente.NombreComercial, UsuarioActual.Empresa.Empresa)
|
||||
|
||||
Retorno = MandaCorreo(ArchivoPDF, Correo, $"Estado Actual de Cartera {UsuarioActual.Empresa.Empresa}", Cuerpo)
|
||||
Dim Hilo As New System.Threading.Thread(Sub() MandaCorreo(ArchivoPDF, Correo, $"Estado Actual de Cartera {UsuarioActual.Empresa.Empresa}", Cuerpo))
|
||||
Hilo.Start()
|
||||
Retorno = True
|
||||
Catch ex As Exception
|
||||
Retorno = False
|
||||
OnError("Ocurrió un error al enviar el correo", ex)
|
||||
OnError("Ocurrió error al mandar el correo de estado de cuenta", ex)
|
||||
End Try
|
||||
Else
|
||||
Retorno = False
|
||||
@@ -683,17 +737,47 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
Return Bytes
|
||||
End Function
|
||||
|
||||
Private Function MandaCorreo(File As Byte(), Para As String, Asunto As String, Body As String) As Boolean
|
||||
Private Function MandaCorreo(File As Byte(), Para As String, Asunto As String, Body As String) As Boolean
|
||||
'Para = "japmx95@gmail.com"
|
||||
Try
|
||||
Dim a As String = String.Format("{0} -- {1} ---- -->", Asunto, Para)
|
||||
'a.GuardaLog()
|
||||
Dim Mail As New ClsSisMail()
|
||||
|
||||
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
|
||||
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = File, .NombreArchivo = "EstadoDeCuenta.pdf"})
|
||||
|
||||
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)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Dim a As String = String.Format("{0} -- {1} ---- -->", Asunto, Para)
|
||||
'a.GuardaLog()
|
||||
Dim Mail As New ClsSisMail()
|
||||
|
||||
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
|
||||
LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = File, .NombreArchivo = "EstadoDeCuenta.pdf"})
|
||||
|
||||
Return Mail.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Body, Archivos:=LSRutasMail)
|
||||
End Function
|
||||
|
||||
Public Sub GuardaLogEdoCuenta(Str As String)
|
||||
Dim ArchivoW As StreamWriter
|
||||
Dim strLineaTMP As String
|
||||
|
||||
' strLineaTMP = Chr(13) & Chr(10) & Day(Now) & "/" & Month(Now) & "/" & Year(Now) & " " & Hour(Now) & ":" & Minuto & ". " & Str & Chr(13) & Chr(10)
|
||||
strLineaTMP = String.Format("{0}{1}Log: {2}{3}:{4}", Chr(13), Chr(10), Str, DateTime.Now.ToShortDateString, DateTime.Now.ToShortTimeString)
|
||||
Try
|
||||
ArchivoW = New StreamWriter(String.Format("{0}\Log\LogEdoCuenta.txt", ModExtensiones.DirectorioBaseEmpresas), True, System.Text.Encoding.UTF8)
|
||||
Catch ex As UnauthorizedAccessException
|
||||
'Alert("No hay permisos para guardar en el Log.", Extensiones.TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
Catch ex As Exception
|
||||
Exit Sub
|
||||
End Try
|
||||
|
||||
Try
|
||||
ArchivoW.WriteLine(strLineaTMP)
|
||||
Catch
|
||||
End Try
|
||||
|
||||
ArchivoW.Close()
|
||||
ArchivoW.Dispose()
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user