VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "C_inventario"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'CLASE TOMA INVENTARIO
'FUNCIONES
' 1              ACTIVAR INVENTARIO.
' 2              DESACTIVAR INVENTARIO.
' 3              CIERRE INVENTARIO.
' 4              ACTUALIZA_CATEGORIA.
' 6              ACTUALIZA_SUBCATEGORIA.
' 8              Actualiza ARTICULO.
' 1              CAT_DISPONIBLES
' 11             SUBCAT_DISPONIBLES
' 12             ART_DISPONIBLES
' 13             CAT_SELECCIONADAS
' 14             SCAT_SELECCIONADAS
' 15             ART_SELECCIONADOS
Option Explicit


Public Function ACTIVAR_TOMAINVENTARIO(Optional VarAux As Variant) As Integer
   Dim cmd As ADODB.Command
   Dim con As ADODB.Connection
   Dim prm As ADODB.Parameter
   Dim strSQL As String
   
   
   On Error GoTo TrataError
    strSQL = " EXEC in_inicioinventario_proc "
   
    Set cmd = New Command
   
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = strSQL
      
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
    cmd.Execute
    
    ACTIVAR_TOMAINVENTARIO = cmd("return")
    
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:

Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not prm Is Nothing Then
        Set prm = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.ACTIVAR_TOMAINVENTARIO", LStrMensajeError
     
End Function
Public Function ART_SELECCIONADOS_CODALTERNATIVOS()
'Permite seleccionar los articulos por sus Codigos Alternativos
'    Dim strSQL As String
'    Dim rs As ADODB.Recordset
'    Set rs = New ADODB.Recordset
'
' On Error GoTo TrataError
'
'    If STRGRUPO = "Categoria" Then
'        If inttodos = 1 Then
'            strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER order by classid,descr "
'        Else
'            strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER WHERE CLASSID IN (" + STRLISTA + ")  order by classid,descr "
'        End If
'    End If
'
'    If STRGRUPO = "Sub Categoria" Then
'        If inttodos = 1 Then
'            strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER order by classid,classubid,descr"
'        Else
'            strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER WHERE CLASSubID IN (" + STRLISTA + ")  order by classid,classubid,descr"
'        End If
'    End If
'
'    rs.CursorLocation = adUseClient
'    rs.Open strSQL, "FILEDSN=conexionsies", adOpenDynamic, adLockBatchOptimistic
'
'    Set ART_SELECCIONADOS_CLUSTER = rs
'
'    'GetObjectContext.SetComplete
'
'    Exit Function
'
'TrataError:
'    If Not rs Is Nothing Then
'       Set rs = Nothing
'    End If
'    'GetObjectContext.SetAbort
'
'    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ART_SELECCIONADOS_CLUSTER", Err.Description
End Function

Public Function DESACTIVAR_TOMAINVENTARIO(Optional VarAux As Variant) As Integer

  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
  Dim prm As ADODB.Parameter
  Dim strSQL As String
  
  On Error GoTo TrataError
    
    strSQL = " EXEC in_fininventario_proc "
    Set cmd = New Command
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = strSQL
      
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
    cmd.Execute
    DESACTIVAR_TOMAINVENTARIO = cmd("return")
    
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not prm Is Nothing Then
        Set prm = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.DESACTIVAR_TOMAINVENTARIO", LStrMensajeError

End Function
Public Sub ACTUALIZA_CATEGORIA(ByVal STRLISTA As String, Optional VarAux As Variant)
 
 Dim cmd As ADODB.Command
 Dim con As ADODB.Connection
 Dim prm As ADODB.Parameter
 Dim strSQL As String
    
 On Error GoTo TrataError
    
    strSQL = " EXEC in_actualizatoma_CAT_proc """ + STRLISTA + """"
    
    Set cmd = New Command
    Set con = New Connection
    
    cmd.CommandText = strSQL
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
    
'    strSQL = " EXEC in_actualizatoma_CAT_proc "
'    cmd.CommandType = adCmdStoredProc
    
    cmd.CommandText = strSQL
'    Set prm = cmd.CreateParameter("lista", adVarChar, adParamInput, 8000, STRLISTA)
'    cmd.Parameters.Append prm
    
    cmd.Execute
    
    'GetObjectContext.SetComplete
    
    Exit Sub
    
TrataError:
    
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.ACTUALIZA_CATEGORIA", LStrMensajeError


End Sub

Public Sub ACTUALIZA_SUBCATEGORIA(ByVal STRLISTA As String, Optional VarAux As Variant)

    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim prm As ADODB.Parameter
    Dim strSQL As String
    
On Error GoTo TrataError
   
    Set cmd = New Command
    Set con = New Connection
    
    cmd.CommandText = strSQL
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
     
    strSQL = " in_actualizatoma_SCAT_proc "
    cmd.CommandType = adCmdStoredProc
    
    cmd.CommandText = strSQL
    Set prm = cmd.CreateParameter("LISTA", adVarChar, adParamInput, 8000, STRLISTA)
    cmd.Parameters.Append prm
 
    cmd.Execute
    
     'GetObjectContext.SetComplete
    
    Exit Sub
    
TrataError:
    
 Dim LStrMensajeError As String
 Dim LVarNumeroError As Variant
    
     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not prm Is Nothing Then
        Set prm = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.ACTUALIZA_SUBCATEGORIA", LStrMensajeError

End Sub
Public Sub ACTUALIZA_articulo(ByVal STRLISTADEL As String, ByVal STRLISTAINS As String, Optional VarAux As Variant)
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim prm As ADODB.Parameter
    Dim strSQL As String
   
On Error GoTo TrataError

    Set cmd = New Command
    Set con = New Connection
    
    cmd.CommandText = strSQL
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
     
    strSQL = " in_actualizatoma_art_proc "

    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = strSQL
    Set prm = cmd.CreateParameter("LISTAD", adVarChar, adParamInput, 8000, STRLISTADEL)
    cmd.Parameters.Append prm
    Set prm = cmd.CreateParameter("LISTAI", adVarChar, adParamInput, 8000, STRLISTAINS)
    cmd.Parameters.Append prm
    cmd.Execute
    
     'GetObjectContext.SetComplete
    
    Exit Sub
    
TrataError:
 Dim LStrMensajeError As String
 Dim LVarNumeroError As Variant
    
     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not prm Is Nothing Then
        Set prm = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.ACTUALIZA_articulo", LStrMensajeError

End Sub

Public Function CAT_DISPONIBLES(Optional VarAux As Variant) As ADODB.Recordset
   Dim strSQL As String
   Dim rs As ADODB.Recordset
    
On Error GoTo TrataError
    
   strSQL = " SELECT * FROM VW_catdisponibles_cluster"
    
   Set rs = New Recordset
   rs.CursorLocation = adUseClient
   rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
   Set CAT_DISPONIBLES = rs
    
   'GetObjectContext.SetComplete
    
   Exit Function
    
TrataError:

    If Not rs Is Nothing Then
       Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.CAT_DISPONIBLES", Err.Description

End Function

Public Function ObtieneTipoCambio(ByVal datDATEPROCE As Date, ByVal strMONEDA As String, Optional VarAux As Variant) As Double
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSQL = " SELECT RATE FROM CURYRATE WHERE CURYTYPEID=(SELECT SOURCECURYTYPEID FROM SETUP) AND FROMCURYID='" & strMONEDA & "' AND CURYDATE='" & Format(datDATEPROCE, "YYYYMMDD") & "'"
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    If Not rs.EOF Then
        ObtieneTipoCambio = rs!Rate
    Else
        ObtieneTipoCambio = 0
    End If
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_MA_MANTENIMIENTOS.ObtieneTipoCambio", Err.Description

End Function

Public Function SCAT_DISPONIBLES(Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
On Error GoTo TrataError
    
    strSQL = " SELECT * FROM VW_subcatdisponibles_cluster"
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set SCAT_DISPONIBLES = rs
     
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
       Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.SCAT_DISPONIBLES", Err.Description

End Function

Public Function ART_DISPONIBLES(ByVal STRSUBCAT As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
On Error GoTo TrataError

    strSQL = " SELECT * FROM VW_ARTDISPONIBLES_CLUSTER WHERE CLASSUBID='" + STRSUBCAT + "'"
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    Set ART_DISPONIBLES = rs
    
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ART_DISPONIBLES", Err.Description

End Function

'******************************************************************
Public Function CAT_SELECCIONADAS(Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
On Error GoTo TrataError
    
    strSQL = " SELECT * FROM VW_catseleccionadas_cluster "
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set CAT_SELECCIONADAS = rs
    
    'GetObjectContext.SetComplete
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.CAT_SELECCIONADAS", Err.Description

End Function

Public Function SCAT_SELECCIONADAS(Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
On Error GoTo TrataError
    
    strSQL = " SELECT * FROM VW_subcatseleccionadas_cluster"
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
       
    Set SCAT_SELECCIONADAS = rs
    
    'GetObjectContext.SetComplete
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.SCAT_SELECCIONADAS", Err.Description

End Function

Public Function ART_SELECCIONADOS(ByVal STRSUBCAT As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
  On Error GoTo TrataError
    
    strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER WHERE CLASSUBID ='" + STRSUBCAT + "'"
    
    Set rs = New ADODB.Recordset
    
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    Set ART_SELECCIONADOS = rs
    
    'GetObjectContext.SetComplete
    
    Exit Function
TrataError:
    
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ART_SELECCIONADOS", Err.Description
    
End Function
Public Function ART_SELECCIONADOS_CLUSTER(ByVal STRGRUPO, ByVal inttodos As Integer, ByVal STRLISTA As String, Optional VarAux As Variant) As ADODB.Recordset
    
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    
 On Error GoTo TrataError
    If STRGRUPO = "Categoria" Then
        If inttodos = 1 Then
            strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER order by classid,descr "
        Else
            strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER WHERE CLASSID IN (" + STRLISTA + ")  order by classid,descr "
        End If
    End If
    If STRGRUPO = "Sub Categoria" Then
        If inttodos = 1 Then
            strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER order by classid,classubid,descr"
        Else
            strSQL = " SELECT * FROM VW_ARTSELECCIONADOS_CLUSTER WHERE CLASSubID IN (" + STRLISTA + ")  order by classid,classubid,descr"
        End If
    End If
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenDynamic, adLockBatchOptimistic
    Set ART_SELECCIONADOS_CLUSTER = rs
    'GetObjectContext.SetComplete
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
       Set rs = Nothing
    End If
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ART_SELECCIONADOS_CLUSTER", Err.Description
End Function


Public Function ART_SELECCIONADOS_PARA_AYUDA(ByVal STRGRUPO, ByVal inttodos As Integer, ByVal STRLISTA As String, Optional VarAux As Variant) As ADODB.Recordset
    
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    
 On Error GoTo TrataError
    
    If STRGRUPO = "Categoria" Then
        If inttodos = 1 Then
            strSQL = " SELECT INVTIDSKU,DESCR FROM VW_ARTSELECCIONADOS_CLUSTER order by classid,descr "
        Else
            strSQL = " SELECT INVTIDSKU,DESCR FROM VW_ARTSELECCIONADOS_CLUSTER WHERE CLASSID IN (" + STRLISTA + ")  order by classid,descr "
        End If
    End If
    
    If STRGRUPO = "Sub Categoria" Then
        If inttodos = 1 Then
            strSQL = " SELECT INVTIDSKU,DESCR FROM VW_ARTSELECCIONADOS_CLUSTER order by classid,classubid,descr"
        Else
            strSQL = " SELECT INVTIDSKU,DESCR FROM VW_ARTSELECCIONADOS_CLUSTER WHERE CLASSubID IN (" + STRLISTA + ")  order by classid,classubid,descr"
        End If
    End If
    
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenDynamic, adLockBatchOptimistic
    
    Set ART_SELECCIONADOS_PARA_AYUDA = rs
        
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
       Set rs = Nothing
    End If
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ART_SELECCIONADOS_PARA_AYUDA", Err.Description
End Function

Public Sub ACTUALIZA_stock_cluster(ByVal recs As ADODB.Recordset, Optional VarAux As Variant)
    
If (Not recs Is Nothing) Or (Not recs.EOF) Then
        
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim prm As ADODB.Parameter
    Dim rsx As ADODB.Recordset
    
    Dim strSQL As String
    Dim id As String
    Dim stock As Double
   
    On Error GoTo TrataError
 
    Set cmd = New ADODB.Command
    Set con = New ADODB.Connection
    
    cmd.CommandText = strSQL
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
    Set rsx = recs.Clone
    
    rsx.MoveFirst
    Do While Not rsx.EOF
        id = rsx!INVTIDSKU
        stock = rsx!stockphisical
        strSQL = " exec actualiza_stock_toma_proc '" + id + "'," + Str(stock)
        cmd.CommandText = strSQL
        cmd.Execute
        rsx.MoveNext
    Loop
    
     'GetObjectContext.SetComplete
End If
    Exit Sub
    
TrataError:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If
    If Not prm Is Nothing Then
        Set prm = Nothing
    End If
    If Not rsx Is Nothing Then
       Set rsx = Nothing
    End If
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ACTUALIZA_stock_cluster", Err.Description

End Sub

Public Function ajuste_automatico(ByVal strUSUARIO As String, Optional VarAux As Variant) As Integer
    
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim prm As ADODB.Parameter
    Dim strSQL As String
    
On Error GoTo TrataError
    
    Set cmd = New Command
    Set con = New Connection
    
    cmd.CommandText = strSQL
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
     
    strSQL = " IN_AJUSTEAUTOMATICO "

    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = strSQL
    
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
    
    Set prm = cmd.CreateParameter("usuario", adBSTR, adParamInput, , strUSUARIO)
    cmd.Parameters.Append prm
    cmd.Execute
   
    ajuste_automatico = cmd("return")
    
     'GetObjectContext.SetComplete
   
    Exit Function
    
TrataError:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If
    If Not prm Is Nothing Then
        Set prm = Nothing
    End If
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ajuste_automatico", Err.Description
    
End Function
Public Function inventario_historico(Optional VarAux As Variant) As Integer
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim prm As ADODB.Parameter
    Dim strSQL As String
   
 On Error GoTo TrataError
 
    Set cmd = New ADODB.Command
    Set con = New ADODB.Connection
    
    cmd.CommandText = strSQL
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
     
    strSQL = " in_agregarinventariohistorico_proc "
    
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
    
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = strSQL
    cmd.Execute
    
    inventario_historico = cmd("return")
    
     'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If
    If Not prm Is Nothing Then
        Set prm = Nothing
    End If
    
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.inventario_historico", Err.Description

End Function
Public Function actualiza_stock_fintomainventario(Optional VarAux As Variant) As Integer
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim prm As ADODB.Parameter
    Dim strSQL As String
    
 On Error GoTo TrataError
 
    Set cmd = New Command
    Set con = New Connection
    
    cmd.CommandText = strSQL
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
     
    strSQL = " in_actualiza_stock_fintomainventario_proc "
    
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
    
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = strSQL
    cmd.Execute
    
    actualiza_stock_fintomainventario = cmd("return")
    
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If
    If Not prm Is Nothing Then
       Set prm = Nothing
    End If
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.actualiza_stock_fintomainventario", Err.Description

End Function


Public Sub GrabarTomaInventario(ByVal strSITEID As String, ByVal strINVTIDSKU As String, ByVal dblSTOCKPHISICAL As Double, _
                                ByVal StrArchivoPdt As String, Optional VarAux As Variant)
    
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim strSQL As String

    On Error GoTo TrataError
        
    strSQL = " EXEC IN_INVENTPHISICAL2InsProc '" & strSITEID & "','" & strINVTIDSKU & "'," & dblSTOCKPHISICAL & ",'" & StrArchivoPdt & "'"
    
    Set cmd = New ADODB.Command
    cmd.CommandText = strSQL
      
      
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
       
    cmd.Execute
    
    'GetObjectContext.SetComplete
        
    Exit Sub
    
TrataError:
       
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant

     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.C_inventario.GrabarTomaInventario", LStrMensajeError
End Sub

Public Sub GrabarArchivoImportado(ByVal StrArchivoPdt As String, Optional VarAux As Variant)
    
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim strSQL As String

    On Error GoTo TrataError
    
    
    strSQL = " IN_GRABARARCHIVOPDTPROC '" & StrArchivoPdt & "'"
    
    Set cmd = New ADODB.Command
    cmd.CommandText = strSQL
      
      
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
       
    cmd.Execute
    
    'GetObjectContext.SetComplete
        
    Exit Sub
    
TrataError:
       
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant

     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.C_inventario.GrabarArchivoImportado", LStrMensajeError
End Sub

Public Sub GrabarDatosdeArchivoImportado(ByVal StrCodigoArt As String, ByVal StrArchivoPdt As String, ByVal DBLStock As Double, Optional VarAux As Variant)
    
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim strSQL As String

    On Error GoTo TrataError
    
    
    strSQL = "IN_GRABARDATOSDEPDTPROC '" & StrCodigoArt & "','" & StrArchivoPdt & "'," & DBLStock
    
    Set cmd = New ADODB.Command
    cmd.CommandText = strSQL
      
      
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
       
    cmd.Execute
    
    'GetObjectContext.SetComplete
        
    Exit Sub
    
TrataError:
       
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant

     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.C_inventario.GrabarDatosdeArchivoImportado", LStrMensajeError
     
End Sub

Public Function ObtenerArchivosImportados(Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
On Error GoTo TrataError
    
    strSQL = " SELECT FILENAMEPDT FROM TMP_FILEPDT " & _
             " WHERE DATEPROCE = (SELECT startdateinven from site where siteid=(SELECT SOURCESITE FROM SETUP))"

    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
       
    Set ObtenerArchivosImportados = rs
    
    'GetObjectContext.SetComplete
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ObtenerArchivosImportados", Err.Description

End Function

Public Function ObtenerArchivosExportados(Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
On Error GoTo TrataError
    
    strSQL = " SELECT FILENAMEPDT FROM TMP_FILEEXPPDT " & _
             " WHERE DATEPROCE = (SELECT startdateinven from site where siteid=(SELECT SOURCESITE FROM SETUP))"

    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
           
    Set ObtenerArchivosExportados = rs
    
    'GetObjectContext.SetComplete
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ObtenerArchivosExportados", Err.Description

End Function

Public Function ObtenerDatosTomaInventario(ByVal IntTipoSelec As Integer, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
On Error GoTo TrataError

    If IntTipoSelec = 1 Then ' Llenar el Flinve
       
       strSQL = " SELECT INVTIDSKU,DESCR FROM IN_INVENTORY WHERE CLASSID <> (SELECT CATEGORYFUEL FROM OP_SETUP) AND " & _
                " CLASSID <> (SELECT CATEGORYLUBES FROM OP_SETUP)"
    
    End If
    If IntTipoSelec = 2 Then ' LLenar el TBBARR
       
       strSQL = " SELECT INVTIDBARR,IN_INVENTORYALTER.INVTIDSKU " & _
                " FROM IN_INVENTORY INNER JOIN IN_INVENTORYALTER " & _
                " ON IN_INVENTORY.INVTIDSKU=IN_INVENTORYALTER.INVTIDSKU " & _
                " WHERE CLASSID <> (SELECT CATEGORYFUEL FROM OP_SETUP) AND " & _
                " CLASSID <> (SELECT CATEGORYLUBES FROM OP_SETUP)"
       
    End If
    If IntTipoSelec = 3 Then ' Llenar el TBSKUS
    
       strSQL = " SELECT INVTIDSKU,DESCR FROM IN_INVENTORY WHERE CLASSID <> (SELECT CATEGORYFUEL FROM OP_SETUP) AND " & _
                " CLASSID <> (SELECT CATEGORYLUBES FROM OP_SETUP)"
    
    End If
    
     
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
           
    Set ObtenerDatosTomaInventario = rs
 
    'GetObjectContext.SetComplete
 
    Exit Function

TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.ObtenerDatosTomaInventario", Err.Description

End Function

Public Sub GrabarArchivoExportado(ByVal StrArchivoPdt As String, Optional VarAux As Variant)
    
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim strSQL As String

    On Error GoTo TrataError
    
    
    strSQL = " IN_GRABARARCHIVOEXPPDTPROC '" & StrArchivoPdt & "'"
    
    Set cmd = New ADODB.Command
    cmd.CommandText = strSQL
      
      
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
       
    cmd.Execute
    
    'GetObjectContext.SetComplete
        
    Exit Sub
    
TrataError:
       
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant

     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 2).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 2).NativeError
        Set con = Nothing
     End If
     
     'GetObjectContext.SetAbort
     
     Err.Raise LVarNumeroError, "DB_INV_TOMADEINVENTARIO.C_inventario.GrabarArchivoExportado", LStrMensajeError
End Sub

Public Function VerificarArchivosExportados(ByVal StrArchivoPdt As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
On Error GoTo TrataError
    
    strSQL = " Select * from TMP_FILEEXPPDT where FILENAMEPDT='" & StrArchivoPdt & "' " & _
             " and DATEPROCE=(select startdateinven from site where siteid=(SELECT SOURCESITE FROM SETUP))"

    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
           
    Set VerificarArchivosExportados = rs
    
    'GetObjectContext.SetComplete
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.VerificarArchivosExportados", Err.Description

End Function


Public Function Auxiliar1(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar1", Err.Description
End Function


Public Function Auxiliar2(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar2", Err.Description
End Function

Public Function Auxiliar3(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar3", Err.Description
End Function

Public Function Auxiliar4(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar4", Err.Description
End Function

Public Function Auxiliar5(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar5", Err.Description
End Function


Public Function Auxiliar6(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar6", Err.Description
End Function

Public Function Auxiliar7(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar7", Err.Description
End Function

Public Function Auxiliar8(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar8", Err.Description
End Function

Public Function Auxiliar9(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar9", Err.Description
End Function

Public Function Auxiliar10(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_INV_TOMADEINVENTARIO.C_inventario.Auxiliar10", Err.Description
End Function



