249 lines
9.3 KiB
Plaintext
249 lines
9.3 KiB
Plaintext
<%@ WebHandler Language="VB" Class="TareasProgramadas" %>
|
|
|
|
Imports System
|
|
Imports System.Web
|
|
Imports System.Data
|
|
Imports Newtonsoft.Json
|
|
Imports Extensiones
|
|
Imports System.IO
|
|
|
|
Public Class TareasProgramadas : Implements IHttpHandler
|
|
|
|
Private currentcontext As HttpContext
|
|
Private URLParametros As New Hashtable
|
|
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
|
|
context.Response.ContentType = "text/plain"
|
|
currentcontext = context
|
|
'timbrarNominab()
|
|
Dim retorno As String = "no se encontro la variable"
|
|
Try
|
|
URLParametros = Parametros(context.Request("var"))
|
|
Dim metodo As String = URLParametros("metodo")
|
|
Select Case metodo
|
|
Case "TimbrarNomina"
|
|
retorno = "Error Timbrado Nomina"
|
|
retorno = timbrarNomina()
|
|
retorno = ""
|
|
End Select
|
|
Catch ex As Exception
|
|
ex.GuardaLog(ex.ToString())
|
|
End Try
|
|
context.Response.Write(retorno)
|
|
End Sub
|
|
|
|
|
|
Public Sub timbrarNominab()
|
|
Dim cveEmpresa As String = "5"
|
|
|
|
|
|
Dim Dv As New DataView(DirectCast(currentcontext.Application("GlobalDTUsuarios"), DataTable), $"CveUsuario = 100 AND CveEmpresa ={cveEmpresa}", "", DataViewRowState.CurrentRows)
|
|
Dim GlobalDTUsuarios As DataTable = Dv.ToTable
|
|
Dv.Dispose()
|
|
Dim usuario As Usuario = Nothing
|
|
'Dim UsuarioAsignaciones As Usuario
|
|
|
|
|
|
If GlobalDTUsuarios.Rows.Count > 0 Then
|
|
Dim dtrow As DataRow = GlobalDTUsuarios.Rows(0)
|
|
Dim ObjUsuario As New ClsSisUsuarios
|
|
usuario = ObjUsuario.ValidaUsuario(dtrow("Usuario"), dtrow("Contraseña"), IMEI, cveEmpresa)
|
|
ObjUsuario.Dispose()
|
|
|
|
Dim ObjEmpresa As New ClsSisEmpresas()
|
|
If ObjEmpresa.GetEmpresas(cveEmpresa, "-1", "-1", "-1", "-1") Then
|
|
If ObjEmpresa.GetEmpresasFuncionalidades(cveEmpresa) Then
|
|
Dim dttmp As Data.DataTable = ObjEmpresa.DtResultados
|
|
|
|
Dim EmpresasFuncionalidades As New HybridDictionary
|
|
For Each Row As Data.DataRow In dttmp.Rows
|
|
EmpresasFuncionalidades.Add(Convert.ToInt32(Row("CveFuncionalidad")), Row("Valor").ToString)
|
|
Next
|
|
ObjEmpresa.Empresa.SetFuncionalidades(EmpresasFuncionalidades)
|
|
|
|
End If
|
|
|
|
usuario.Empresa = ObjEmpresa.Empresa
|
|
usuario.CveEmpresa = ObjEmpresa.Empresa.CveEmpresa
|
|
|
|
ADSSession.ADSSessionConfig.SessionManager(ADSSession.OpcionSession.CambiarEmpresa, Nothing, ObjEmpresa.Empresa.CveEmpresa)
|
|
Else
|
|
End If
|
|
ObjEmpresa.Dispose()
|
|
|
|
Dim StrErrores As New StringBuilder
|
|
Dim Msg As String = String.Empty
|
|
Dim CvePeriodo As Integer
|
|
Dim CveNomina As Integer
|
|
Dim CvePersonal As Integer
|
|
|
|
Dim SerieFolio As String
|
|
Dim DtNominas As New DataTable
|
|
Dim objnom As New ClsNominas
|
|
objnom.GetNom_porTimbrar(usuario.CveEmpresa)
|
|
DtNominas = objnom.DtResultados
|
|
'DtNominas = New DataTable
|
|
Dim noCiclos As Integer = 0
|
|
Dim noTotal As Integer = DtNominas.Rows.Count
|
|
|
|
Dim lognom As New LogicNominas
|
|
For Each Row As DataRow In DtNominas.Rows
|
|
'If noCiclos < 4 Then
|
|
noCiclos = noCiclos + 1
|
|
CveNomina = Row("CveNomina").ToString().ToEntero()
|
|
CvePersonal = Row("CvePersonal").ToString().ToEntero()
|
|
|
|
SerieFolio = Row("SerieFolio").ToString()
|
|
|
|
CvePeriodo = Row("CvePeriodo").ToString.ToEntero
|
|
|
|
If CveNomina > 0 Then
|
|
|
|
Msg = lognom.TimbrarNomina(CveNomina, CvePersonal, CvePeriodo, usuario)
|
|
|
|
If Msg.Trim <> String.Empty Then StrErrores.Append(Msg & "<br />")
|
|
End If
|
|
'Else
|
|
' Exit For
|
|
'End If
|
|
Next
|
|
GC.Collect()
|
|
StrErrores.ToString().GuardaLog()
|
|
|
|
If StrErrores.ToString().Length > 0 And CvePeriodo > 0 Then
|
|
Dim ObjPeriodo As New ClsNominas()
|
|
ObjPeriodo.CambiaEstatusPeriodo(CvePeriodo, enumNominasEstatus.Timbrada, usuario.CveUsuario, usuario.CveEmpresa)
|
|
ObjPeriodo.Dispose()
|
|
'EnvioMasivoCorreo()
|
|
'Dim temp As String = DdlPeriodo.SelectedValue
|
|
'CargaPeriodos()
|
|
'BtnEmitir.Visible = False
|
|
'DdlPeriodo.SelectedValue = temp
|
|
End If
|
|
End If
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
Private Function GetUsuario(CveEmpresa As Integer, Optional CveUsuario As Integer = -1, Optional username As String = "", Optional pass As String = "") As Usuario
|
|
Dim usuario As Usuario = Nothing
|
|
#Region "Valido que los campos usuario contraseña no sean nulos"
|
|
|
|
If IsNothing(username) Then
|
|
username = ""
|
|
End If
|
|
If IsNothing(pass) Then
|
|
pass = ""
|
|
End If
|
|
#End Region
|
|
#Region "Si el CveUsuario es mayor que cero asigno el username y pass la de la CveUsuario"
|
|
|
|
If CveUsuario > 0 Then
|
|
Using Dv As New DataView(DirectCast(currentcontext.Application("GlobalDTUsuarios"), DataTable), $"CveUsuario = 100 AND CveEmpresa ={CveEmpresa}", "", DataViewRowState.CurrentRows)
|
|
Using GlobalDTUsuarios As DataTable = Dv.ToTable()
|
|
If GlobalDTUsuarios.Rows.Count > 0 Then
|
|
Dim dtrow As DataRow = GlobalDTUsuarios.Rows(0)
|
|
username = dtrow("Usuario")
|
|
pass = dtrow("Contraseña")
|
|
End If
|
|
End Using
|
|
End Using
|
|
End If
|
|
#End Region
|
|
#Region "obtengo el usuario con el username y la pass"
|
|
|
|
Using ObjUsuario As New ClsSisUsuarios()
|
|
usuario = ObjUsuario.ValidaUsuario(username, pass, IMEI, CveEmpresa)
|
|
End Using
|
|
#End Region
|
|
#Region "Asigno la empresa al usuario"
|
|
If Not IsNothing(usuario) Then
|
|
Using ObjEmpresa As New ClsSisEmpresas()
|
|
|
|
If ObjEmpresa.GetEmpresas(CveEmpresa, "-1", "-1", "-1", "-1") Then
|
|
If ObjEmpresa.GetEmpresasFuncionalidades(CveEmpresa) Then
|
|
Dim dttmp As Data.DataTable = ObjEmpresa.DtResultados
|
|
|
|
Dim EmpresasFuncionalidades As New HybridDictionary
|
|
For Each Row As Data.DataRow In dttmp.Rows
|
|
EmpresasFuncionalidades.Add(Convert.ToInt32(Row("CveFuncionalidad")), Row("Valor").ToString)
|
|
Next
|
|
ObjEmpresa.Empresa.SetFuncionalidades(EmpresasFuncionalidades)
|
|
|
|
End If
|
|
|
|
usuario.Empresa = ObjEmpresa.Empresa
|
|
usuario.CveEmpresa = ObjEmpresa.Empresa.CveEmpresa
|
|
Else
|
|
End If
|
|
End Using
|
|
|
|
End If
|
|
#End Region
|
|
Return usuario
|
|
End Function
|
|
|
|
|
|
Public Function timbrarNomina() As String
|
|
Dim retorno As String = ""
|
|
Dim cveEmpresa As String = URLParametros("CveEmpresa").ToString().ToEntero()
|
|
|
|
Dim CvePeriodo As Integer = URLParametros("CvePeriodo").ToString().ToEntero()
|
|
Dim CveNomina As Integer = URLParametros("CveNomina").ToString().ToEntero()
|
|
Dim CvePersonal As Integer = URLParametros("CvePersonal").ToString().ToEntero()
|
|
|
|
Dim usuario As Usuario = GetUsuario(cveEmpresa, 100)
|
|
If Not IsNothing(usuario) Then
|
|
|
|
Dim StrErrores As New StringBuilder
|
|
Dim Msg As String = String.Empty
|
|
|
|
Dim lognom As New LogicNominas
|
|
If CveNomina > 0 Then
|
|
Msg = lognom.TimbrarNomina(CveNomina, CvePersonal, CvePeriodo, usuario)
|
|
If Msg.Trim() <> String.Empty Then StrErrores.Append(Msg)
|
|
retorno = Msg.Trim()
|
|
Else
|
|
retorno = "Nomina invalida periodo timbrar"
|
|
End If
|
|
'Using ObjPeriodo As New ClsNominas()
|
|
' If StrErrores.ToString().Length > 0 Then
|
|
' ObjPeriodo.CambiaEstatusPeriodo(CvePeriodo, enumNominasEstatus.ErrorEnTimbrado, usuario.CveUsuario, usuario.CveEmpresa)
|
|
' Else
|
|
' ObjPeriodo.CambiaEstatusPeriodo(CvePeriodo, enumNominasEstatus.Timbrada, usuario.CveUsuario, usuario.CveEmpresa)
|
|
|
|
' End If
|
|
'End Using
|
|
Else
|
|
retorno = "No se encontro el usuario"
|
|
|
|
Me.GuardaLog(String.Format("Error Timbrado Nomina CveEmpresa:{0} ", usuario.CveEmpresa))
|
|
End If
|
|
|
|
Return retorno
|
|
End Function
|
|
|
|
|
|
|
|
Private Function Parametros(Cadena As String) As Hashtable
|
|
Cadena = Decripta(Cadena)
|
|
Dim P1() As String = Cadena.Split("&"c)
|
|
Dim Tmp As String
|
|
Dim P2() As String
|
|
|
|
Dim URLParametros As New Hashtable
|
|
|
|
For Each Tmp In P1
|
|
P2 = Tmp.Replace("%26%", "&").Split("="c)
|
|
URLParametros.Add(P2(0).ToString(), P2(1))
|
|
Next
|
|
Return URLParametros
|
|
End Function
|
|
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
|
|
Get
|
|
Return False
|
|
End Get
|
|
End Property
|
|
|
|
End Class |