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_MOVIMIENTOS"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' Programador : Edgar Cancho Ruiz
' Clase C_MOVIMIENTOS
' Funciones Básicas de para Ingresos Y Salidas

'               AgregarMovimiento : Agrega un nuevo movimiento
'               AgregarEnTmpIntraItem : inserta un registro en el tempòral de detalle
'               EliminarEnTmpIntraItem
'               EliminarTodoEnTmpIntraItem
'               ActualizaNumRegEnTmpIntraItem
'               ActualizaTmpIntraItem
'               SeleccionaEnTmpIntraItem
'               ExisteArticulo
'               ObtieneValorVenta
'               ObtieneValorVenta2
'               ObtieneEstadoDocumento
'               EmitirDocumento
'               AnularDocumento
'               SeleccionaEnIntraItem
'               SeleccionaEnIntraHead
'               ValidaCodigoIngresado
'               BusquedaMovimiento
'               PermiteStockNegativo
'               ExisteDocumento
'               ListarMovimientosGeneradosPorDesensamble
'               ObtenerGeneradorMovimientoPorDesensamble
'               ExistenDistintosValoresEnIGV
'               ExistenDistintosValoresEnIGV_2
'               HabilitarFechaProceso
'               ConvertirCosto

Option Explicit

Public Function AgregarMovimiento(ByVal strSITEID As String, _
                             ByVal strTYPEDOCID As String, ByVal strVENDIDSS As String, ByVal strDOCTYPEID As String, _
                             ByVal strDOCSTATUSID As String, ByVal strREFNBR As String, ByVal dblCURYRATE As Double, _
                             ByVal strTOCURYID As String, ByVal strFROMCURYID As String, ByVal strSITEPROCES As String, _
                             ByVal strNBRORDER As String, ByVal datNBRORDER As Date, ByVal strUSERIDORDER As String, _
                             ByVal datINTRDATE As Date, ByVal datINTRDATEPROCE As Date, ByVal strSITEDEST As String, _
                             ByVal dblINTRTOTPEN As Double, ByVal dblINTRTAXPEN As Double, ByVal dblINTROTUSD As Double, _
                             ByVal dblINTRTAXUSD As Double, ByVal strPERPOST As String, ByVal bytRLSED As Byte, _
                             ByVal bytDISASSEMBLE As Byte, ByVal dblINTRSUBTOTPEN As Double, ByVal dblINTRSUBTOTUSD As Double, _
                             ByVal strUSERID As String, ByVal datFechaRecepDoc As Date, ByVal lngCORREL As Long, ByVal strCOMMENT1 As String, _
                             ByVal strCOMMENT2 As String, ByVal strCOMMENT3 As String, ByVal strTipoCompra As String, Optional VarAux As Variant) As String
                             
   
    Dim con As ADODB.Connection
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " EXEC In_GrabarMovimientoProc '" & strSITEID & "','" & _
                                strTYPEDOCID & " ','" & strVENDIDSS & "','" & strDOCTYPEID & "','" & _
                                strDOCSTATUSID & "','" & strREFNBR & "'," & dblCURYRATE & ",'" & _
                                strTOCURYID & "','" & strFROMCURYID & "','" & strSITEPROCES & "','" & _
                                strNBRORDER & "','" & IIf(Year(Format(datNBRORDER, "DD/MM/YYYY") < 1900), "1900/01/01", Format(datNBRORDER, "DD/MM/YYYY")) & "','" & strUSERIDORDER & "','" & _
                                Format(datINTRDATE, "DD/MM/YYYY") & "','" & Format(datINTRDATEPROCE, "DD/MM/YYYY") & "','" & strSITEDEST & "'," & _
                                dblINTRTOTPEN & "," & dblINTRTAXPEN & "," & dblINTROTUSD & "," & _
                                dblINTRTAXUSD & ",'" & strPERPOST & "','" & bytRLSED & "'," & _
                                bytDISASSEMBLE & "," & dblINTRSUBTOTPEN & "," & dblINTRSUBTOTUSD & ",'" & _
                                strUSERID & "',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'" & Format(datFechaRecepDoc, "DD/MM/YYYY") & "'," & lngCORREL & ",'" & _
                                strCOMMENT1 & "','" & strCOMMENT2 & "','" & strCOMMENT3 & "','" & strTipoCompra & "'"
                                

    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, con, adOpenStatic
    
    AgregarMovimiento = rs!NUMEROMOVIMIENTO
    
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:

Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
     If Not rs Is Nothing Then
        Set rs = 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_MOVIMIENTOS.C_MOVIMIENTOS.AgregarMovimiento", LStrMensajeError
     
End Function

' PROCEDIMIENTO QUE INSERTA UN REGISTRO EN LA TABLA TEMPORAL DE DETALLE(TMP_IN_INTRAITEM)
' DE MOVIMIENTO (INGRESO O SALIDA)

Public Sub AgregarEnTmpIntraItem(ByVal lngCORRNBR As Long, ByVal strSITEID As String, _
                                 ByVal strTYPEDOCID As String, ByVal intSEQUENCE As Integer, ByVal strINVTIDSKU As String, _
                                 ByVal strINVTIDBARR As String, ByVal dlbQTY As Double, ByVal dblTAXIGV As Double, ByVal dblSTDCOSTPEN As Double, _
                                 ByVal dblSTDCOSTUSD As Double, ByVal bytSTKFISI As Byte, ByVal datINTRDATE As Date, _
                                 ByVal datINTRDATEPROCE As Date, ByVal bytRLSED As Byte, ByVal dblSTDCOSTPENOLD As Double, ByVal dblSTDCOSTUSDOLD As Double, Optional VarAux As Variant)
       
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim strSql As String

    On Error GoTo TrataError
    
    strSql = " EXEC ObtenerImpuestosProc '" & strINVTIDSKU & "'"
    
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, con, adOpenStatic
    
    strSql = " EXEC Tmp_In_IntraItemInsProc " & lngCORRNBR & ",'" & strSITEID & "','" & _
                                strTYPEDOCID & "'," & intSEQUENCE & ",'" & strINVTIDSKU & "','" & strINVTIDBARR & "'," & _
                                dlbQTY & "," & rs!IMPUESTO1 & "," & dblSTDCOSTPEN & "," & _
                                dblSTDCOSTUSD & ",'" & bytSTKFISI & "','" & Format(datINTRDATE, "DD/MM/YYYY") & "','" & _
                                Format(datINTRDATEPROCE, "DD/MM/YYYY") & "','" & bytRLSED & "'," & rs!IMPUESTO2 & "," & _
                                dblSTDCOSTPENOLD & "," & dblSTDCOSTUSDOLD

    Set cmd = New ADODB.Command
    cmd.CommandText = strSql
      
    cmd.ActiveConnection = con
    cmd.Execute
    
    'GetObjectContext.SetComplete
    
    Exit Sub
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If

    'GetObjectContext.SetAbort
   
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.AgregarEnTmpIntraItem", Err.Description
End Sub

Public Sub CopiarDetalleDeMovimientoAlTemporal(ByVal lngCORRNBR As Long, ByVal strSITEID, ByVal strBATNBR As String, Optional VarAux As Variant)
    Dim strSql As String
    Dim con As ADODB.Connection
    
    On Error GoTo TrataError
    
    strSql = " EXEC IN_CopiaDetalleMovimientoProc " & lngCORRNBR & ",'" & strSITEID & "','" & strBATNBR & "'"
    
    
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    con.Execute strSql
    
    'GetObjectContext.SetComplete
    
    Exit Sub
    
TrataError:
    If Not con Is Nothing Then
        Set con = Nothing
    End If
    
    
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.CopiarDetalleDeMovimientoAlTemporal", Err.Description

End Sub

' PROCEDIMIENTO QUE ELIMINA UN REGISTRO EN LA TABLA TEMPORAL DE DETALLE(TMP_IN_INTRAITEM)
' DE MOVIMIENTO (INGRESO O SALIDA)
' DATOS DE ENTRADA: CODIGO DEL ARTICULO
'                   CORRELATIVO IDENTITY

Public Sub EliminarEnTmpIntraItem(ByVal strINVTIDSKU As String, ByVal lngCORRNBR As Long, Optional VarAux As Variant)
   
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim strSql As String

    On Error GoTo TrataError
    
    strSql = " EXEC Tmp_In_IntraItemDelProc '" & strINVTIDSKU & "'," & lngCORRNBR
                                
    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:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If

    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.EliminarEnTmpIntraItem", Err.Description
End Sub

Public Sub EliminarTodoEnTmpIntraItem(ByVal lngCORRNBR As Long, Optional VarAux As Variant)
   
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim strSql As String

    On Error GoTo TrataError
    
    strSql = " EXEC Tmp_In_IntraItemDelTodoProc " & lngCORRNBR
                                
    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:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If

    'GetObjectContext.SetAbort
   
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.EliminarTodoEnTmpIntraItem", Err.Description
End Sub

' PROCEDIMIENTO QUE ACTUALIZA EL NUMERO DE REGISTRO QUE SE VISUALIZA EN EL DATAGRID
' DE DETALLE DE MOVIMIENTO CUANDO SE ELIMINA UN REGISTRO
' DATOS DE ENTRADA :    CODIGO DEL PROVEEDOR
'                       CORRELATIVO IDENTITY

Public Sub ActualizaNumRegEnTmpIntraItem(ByVal strVENDIDSS As String, ByVal lngCORRNBR As Long, ByVal strCURYID As String, Optional VarAux As Variant)
   
    Dim rs As ADODB.Recordset
    Dim i As Integer
    On Error GoTo TrataError
    
    Set rs = SeleccionaEnTmpIntraItem(strVENDIDSS, lngCORRNBR, strCURYID)
    If rs.RecordCount > 0 Then
        rs.MoveFirst
    End If
    
    For i = 1 To rs.RecordCount
        Call ActualizaTmpIntraItem(rs!CODIGO, i, rs!Cantidad, rs!COSTO, 0, lngCORRNBR, strCURYID)
        rs.MoveNext
    Next i
    
    'GetObjectContext.SetComplete
    
    Exit Sub
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.ActualizaNumRegEnTmpIntraItem", Err.Description
End Sub

' PROCEDIMIENTO QUE ACTUALIZA UN REGISTRO DE LA TABLA TMP_IN_INTRAITEM
' DATOS DE ENTRADA :    CODIGO DEL ARTICULO
'                       NUMERO DE REGISTRO
'                       CANTIDAD
'                       COST0
'                       CORRELATIVO IDENTITY

Public Sub ActualizaTmpIntraItem(ByVal strINVTIDSKU As String, ByVal intSEQUENCE As Integer, _
                ByVal dlbQTY As Double, dblSTDCOSTPEN As Double, dblSTDCOSTUSD As Double, ByVal lngCORRNBR As Long, _
                ByVal strCURYID, Optional VarAux As Variant)

    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim strSql As String

    On Error GoTo TrataError
    
    strSql = " EXEC Tmp_In_IntraItemUpdProc '" & strINVTIDSKU & "'," & intSEQUENCE & "," & dlbQTY & "," & dblSTDCOSTPEN & "," & dblSTDCOSTUSD & "," & lngCORRNBR & ",'" & strCURYID & "'"
                                
    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:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If

    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.ActualizaTmpIntraItem", Err.Description
End Sub

' FUNCION QUE DEVUELVE UN RECORDSET CON DATOS DEL TEMPORAL TMP_IN_INTRAIEM
' DATOS DE ENTRADA: CODIGO DEL PROVEEDOR
'                   CORRELATIVO IDENTITY
'                   CODIGO DE LA MONEDA
Public Function SeleccionaEnTmpIntraItem(ByVal strVENDIDSS As String, ByVal lngCORRNBR As Long, ByVal strCURYID As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " EXEC TMP_IN_INTRAITEMSelProc '" & strVENDIDSS & "'," & lngCORRNBR & ",'" & strCURYID & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set SeleccionaEnTmpIntraItem = 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_MOVIMIENTOS.SeleccionaEnTmpIntraItem", Err.Description

End Function

' funcion que devuelve True, si encontro el codigo de articulo en Tmp_In_IntraItem
' de lo contario False

Public Function ExisteArticulo(ByVal strINVTIDSKU As String, ByVal lngCORRNBR As Long, Optional VarAux As Variant) As Boolean
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    ExisteArticulo = False
    
    On Error GoTo TrataError
    
    strSql = " EXEC IN_BuscaArticuloProc '" & strINVTIDSKU & "'," & lngCORRNBR
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic

    If rs.RecordCount > 0 Then
        ExisteArticulo = True
    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_INV_MOVIMIENTOS.ExisteArticulo", Err.Description

End Function


Public Function ObtieneValorVenta(ByVal strCURYID As String, ByVal lngCORRNBR As Long, Optional VarAux As Variant) As ADODB.Recordset
    
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " EXEC IN_CALCULATOTALESProc '" & strCURYID & "'," & lngCORRNBR
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic

    Set ObtieneValorVenta = 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_MOVIMIENTOS.ObtieneValorVenta", Err.Description

End Function

Public Function ObtieneValorVenta2(ByVal strCURYID As String, ByVal strSITEID As String, ByVal strBATNBR As String, Optional VarAux As Variant) As ADODB.Recordset
    
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " EXEC IN_CalculaTotales_2Proc '" & strCURYID & "','" & strSITEID & "','" & strBATNBR & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic


    Set ObtieneValorVenta2 = 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_MOVIMIENTOS.ObtieneValorVenta2", Err.Description

End Function


Public Function ObtieneEstadoDocumento(ByVal strSITEID As String, ByVal strBATNBR As String, Optional VarAux As Variant) As Integer
   
    Dim rs As ADODB.Recordset
    Dim con As Connection
    Dim strSql As String

    On Error GoTo TrataError
    
    strSql = " SELECT RLSED FROM IN_INTRAHEAD WHERE SITEID='" & strSITEID & "' AND BATNBR='" & strBATNBR & " '"
                                
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    
    rs.Open strSql, con, adOpenStatic
    If rs.RecordCount <> 0 Then
        ObtieneEstadoDocumento = IIf(rs!rlsed = True, 1, 0)
    Else
        ObtieneEstadoDocumento = -1 ' no existe el documento en el site
    End If
    
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    If Not con Is Nothing Then
       Set con = Nothing
    End If

    'GetObjectContext.SetAbort
   
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.ObtieneEstadoDocumento", Err.Description
    
End Function

' PROCEDIMIENTO QUE EJECUTA LA EMISION DE UN DOCUMENTO, POR EL CUAL SE
' ACTUALIZAN LOS STOCK
' DATOS DE ENTRADA: CODIGO DEL ALMACEN
'                   CORRELATIVO DEL MOVIMIENTO (INGRESO O SALIDA)

Public Sub EmitirDocumento(ByVal strSITEID As String, ByVal strBATNBR As String, Optional VarAux As Variant)
    
    Dim con As ADODB.Connection
    Dim strSql As String
    Dim cmd As ADODB.Command
    
    On Error GoTo TrataError
    
    'ANTERIOR AL DESENSAMBLE strSQL = " EXEC In_EmitirDocumentoProc '" & strSITEID & "','" & strBATNBR & "'"
    strSql = "IN_EmisionDeDocumentoProc '" & strSITEID & "','" & strBATNBR & "'"
              
    Set cmd = New ADODB.Command
    cmd.CommandText = strSql
      
    Set con = New ADODB.Connection
    con.CursorLocation = adUseClient
    con.Open "FILEDSN=conexionsies"

    'cmd.CommandTimeout = 0
    
    
    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_MOVIMIENTOS.C_MOVIMIENTOS.EmitirDocumento", LStrMensajeError
    
End Sub

' PROCEDIMIENTO QUE EJECUTA LA ANULACION DE UN DOCUMENTO, POR EL CUAL SE
' ACTUALIZA EL ESTADO DEL DOCUMENTO. SOLO SE ANULA UN DOCUMENTO NO EMITIDO
' DATOS DE ENTRADA: CODIGO DEL ALMACEN
'                   CORRELATIVO DEL MOVIMIENTO (INGRESO O SALIDA)

Public Sub AnularDocumento(ByVal strSITEID As String, ByVal strBATNBR As String, Optional VarAux As Variant)
    
    Dim con As ADODB.Connection
    Dim strSql As String
    Dim cmd As ADODB.Command
    
    On Error GoTo TrataError
    
    strSql = " EXEC In_AnularDocumentoProc '" & strSITEID & "','" & strBATNBR & "'"
                                
                                

    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_MOVIMIENTOS.C_MOVIMIENTOS.AnularDocumento", LStrMensajeError
     End Sub

' FUNCION QUE DEVUELVE UN RECORDSET CON DATOS DE LA TABLA IN_INTRAIEM (DETALLE)
' DATOS DE ENTRADA: CODIGO DEL ALMACEN
'                   CORRELATIVO DEL MOVIMIENTO(INGRESO O SALIDA)


Public Function SeleccionaEnIntraItem(ByVal strSITEID As String, ByVal strBATNBR As String, ByVal strCURYID As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSql As String
    Dim strVENDIDSS As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = "SELECT VENDIDSS FROM IN_INTRAHEAD WHERE SITEID='" & strSITEID & "' AND BATNBR='" & strBATNBR & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
    If Not rs.EOF Then
        strVENDIDSS = rs!VENDIDSS
    End If
    
    Set rs = Nothing
    
    
    strSql = " EXEC IN_INTRAITEMSelProc '" & strSITEID & "','" & strBATNBR & "','" & strVENDIDSS & "','" & strCURYID & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set SeleccionaEnIntraItem = 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_MOVIMIENTOS.SeleccionaEnIntraItem", Err.Description

End Function

' FUNCION QUE DEVUELVE UN RECORDSET CON DATOS DE LA TABLA IN_INTRAHEAD (CABECERA)
' DATOS DE ENTRADA: CODIGO DEL ALMACEN
'                   CORRELATIVO DEL MOVIMIENTO(INGRESO O SALIDA)

Public Function SeleccionaEnIntraHead(ByVal strSITEID As String, ByVal strBATNBR As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    'strSQL = " SELECT BATNBR,TYPEDOCID,DOCSTATUSID,SITEID,VENDIDSS,DOCTYPEID,FROMCURYID,REFNBR,INTRDATE,INTRDATEPROCE,RLSED,DISASSEMBLE,SITEDEST,CURYRATE " & _
             " FROM IN_INTRAHEAD WHERE SITEID='" & strSITEID & "' AND BATNBR='" & strBATNBR & "'"
             
    strSql = " SELECT * " & _
             " FROM IN_INTRAHEAD WHERE SITEID='" & strSITEID & "' AND BATNBR='" & strBATNBR & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
        
    Set SeleccionaEnIntraHead = 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_MOVIMIENTOS.SeleccionaEnIntraHead", Err.Description

End Function

Public Function SeleccionaComentarios(ByVal strSITEID As String, ByVal strTYPEDOCID As String, ByVal strDOCTYPEID As String, ByVal strBATNBR 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 COMMENT WHERE SITEID='" & strSITEID & "' AND TYPEDOCID='" & strTYPEDOCID & "' AND DOCTYPEID='" & strDOCTYPEID & "' AND BATNBR='" & strBATNBR & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
        
    Set SeleccionaComentarios = 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_MOVIMIENTOS.SeleccionaComentarios", Err.Description

End Function

' FUNCION QUE DEVUELVE UN RECORDSET CON LOS DATOS PROVENIENTES DEL JOIN DE LAS
' TABLAS IN_INVENTORY,IN_INVENTORYALTER,IN_VENDORINVT
' DATOS DE ENTRADA :    CODIGO DEL PROVEEDOR
'                       CODIGO (QUE PUEDE SE EL CODIGO DEL ARTICULO,DE BARRA O DE COMPRA)

Public Function ValidaCodigoIngresado(ByVal strVENDIDSS As String, ByVal strCODIGO As String, ByVal strSITEID As String, ByVal bytVALOR1 As Byte, ByVal bytVALOR2 As Byte, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " EXEC IN_PROVEEDOR_ARTICULO_PROC '" & strVENDIDSS & "','" & strCODIGO & "','" & strSITEID & "'," & bytVALOR1 & "," & bytVALOR2
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set ValidaCodigoIngresado = 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_MOVIMIENTOS.ValidaCodigoIngresado", Err.Description

End Function

Public Function BusquedaMovimiento(ByVal strSITEID As String, ByVal datFECHAINI As Date, ByVal datFECHAFIN As Date, ByVal bytINOUT As Byte, ByVal intEstadoDoc As Integer, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
        
    strSql = " EXEC IN_BuscarMovimientoProc '" & strSITEID & "','" & Format(datFECHAINI, "DD/MM/YYYY") & "','" & Format(datFECHAFIN, "DD/MM/YYYY") & "'," & bytINOUT & "," & intEstadoDoc
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set BusquedaMovimiento = 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_MOVIMIENTOS.BusquedaMovimiento", Err.Description

End Function

' FUNCION BOOLEANA QUE DEVUELVE "TRUE" SI SE PERMITE DEJAR UN ARTICULO CON STOCK NEGATIVO
' CUANDO SE REALIZA UNA SALIDA, DE LO CONTRARIO "FALSE"
' SE CONSULTA LA TABLA IN_SETUP

Public Function PermiteStockNegativo(Optional VarAux As Variant) As Boolean
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " SELECT STKSTOCK " & _
             " FROM IN_SETUP "
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic

    PermiteStockNegativo = rs!STKSTOCK
    
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.PermiteStockNegativo", Err.Description

End Function

' funcion que devuelve True, si ya se grabo el número de documento asignado a un proveedor
' de lo contario False

Public Function ExisteDocumento(ByVal strTYPEDOCID As String, ByVal strVENDIDSS As String, ByVal strDOCTYPEID As String, ByVal strREFNBR As String, Optional VarAux As Variant) As Boolean
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    ExisteDocumento = False
    
    On Error GoTo TrataError
    
    strSql = " EXEC IN_BuscaNroDocumentoProc '" & strTYPEDOCID & "','" & strVENDIDSS & "','" & strDOCTYPEID & "','" & strREFNBR & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic

    If rs.RecordCount > 0 Then
       ExisteDocumento = True
    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_INV_MOVIMIENTOS.ExisteDocumento", Err.Description

End Function

Public Function ListarMovimientosGeneradosPorDesensamble(ByVal strVENDIDSS As String, ByVal strREFNBR As String, ByVal strTYPEDOCID As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " SELECT BATNBR FROM IN_INTRAHEAD WHERE VENDIDSS='" & strVENDIDSS & "' AND REFNBR='" & strREFNBR & "' AND TYPEDOCID<>'" & strTYPEDOCID & "' ORDER BY BATNBR"
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarMovimientosGeneradosPorDesensamble = 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_MOVIMIENTOS.ListarMovimientosGeneradosPorDesensamble", Err.Description

End Function

Public Function ObtenerGeneradorMovimientoPorDesensamble(ByVal strVENDIDSS As String, ByVal strREFNBR As String, ByVal strTYPEDOCID As String, Optional VarAux As Variant) As String
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " SELECT BATNBR FROM IN_INTRAHEAD WHERE VENDIDSS='" & strVENDIDSS & "' AND REFNBR='" & strREFNBR & "' AND TYPEDOCID<>'" & strTYPEDOCID & "'"
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    If Not rs.EOF Then
        ObtenerGeneradorMovimientoPorDesensamble = rs!BATNBR
    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_INV_MOVIMIENTOS.ObtenerGeneradorMovimientoPorDesensamble", Err.Description

End Function

Public Function ExistenDistintosValoresEnIGV(ByVal lngCORRNBR As Long, Optional VarAux As Variant) As Boolean
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    ExistenDistintosValoresEnIGV = False
    
    strSql = " SELECT DISTINCT TAXIGV FROM TMP_IN_INTRAITEM WHERE CORRNBR=" & lngCORRNBR
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    If rs.RecordCount >= 2 Then
        ExistenDistintosValoresEnIGV = True
    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_INV_MOVIMIENTOS.ExistenDistintosValoresEnIGV", Err.Description

End Function

Public Sub ModificarMovimiento(ByVal strBATNBR As String, ByVal strSITEID As String, ByVal strTYPEDOCID As String, ByVal strDOCTYPEID As String, ByVal lngCORREL As Long, _
                               ByVal strVENDIDSS As String, ByVal strFROMCURYID As String, ByVal strDOCSTATUSID As String, _
                               ByVal datINTRDATE As Date, ByVal datINTRDATEPROCE As Date, ByVal strREFNBR As String, ByVal bytDISASSEMBLE As Byte, _
                               ByVal dblINTRTOTPEN As Double, ByVal dblINTRTAXPEN As Double, ByVal dblINTROTUSD As Double, _
                               ByVal dblINTRTAXUSD As Double, ByVal dblINTRSUBTOTPEN As Double, ByVal dblINTRSUBTOTUSD As Double, _
                               ByVal strCOMMENT1 As String, ByVal strCOMMENT2 As String, ByVal strCOMMENT3 As String, ByVal datFechaRecepDoc As Date, Optional VarAux As Variant)
                             
   
    Dim con As ADODB.Connection
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " EXEC IN_ModificarMovimientoProc '" & strBATNBR & "','" & strSITEID & "','" & strTYPEDOCID & "','" & strDOCTYPEID & "'," & lngCORREL & _
                                                ",'" & strVENDIDSS & "','" & strFROMCURYID & "','" & strDOCSTATUSID & "','" & _
                                                Format(datINTRDATE, "DD/MM/YYYY") & "','" & Format(datINTRDATEPROCE, "DD/MM/YYYY") & "','" & strREFNBR & "'," & bytDISASSEMBLE & "," & _
                                                dblINTRTOTPEN & "," & dblINTRTAXPEN & "," & dblINTROTUSD & "," & _
                                                dblINTRTAXUSD & "," & dblINTRSUBTOTPEN & "," & dblINTRSUBTOTUSD & ",'" & strCOMMENT1 & "','" & strCOMMENT2 & "','" & strCOMMENT3 & "','" & Format(datFechaRecepDoc, "DD/MM/YYYY") & "'"
                                

    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, con, adOpenStatic
    

    'GetObjectContext.SetComplete
    
    Exit Sub
    
TrataError:

Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
     If Not rs Is Nothing Then
        Set rs = 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_MOVIMIENTO.ModificarMovimiento", LStrMensajeError
     
End Sub

Public Function ExistenDistintosValoresEnIGV_2(ByVal strSITEID As String, ByVal strBATNBR As String, Optional VarAux As Variant) As Boolean
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    ExistenDistintosValoresEnIGV_2 = False
    
    strSql = " SELECT DISTINCT TAXIGV FROM IN_INTRAITEM WHERE SITEID='" & strSITEID & "' AND BATNBR='" & strBATNBR & "'"
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    If rs.RecordCount >= 2 Then
        ExistenDistintosValoresEnIGV_2 = True
    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_INV_MOVIMIENTOS.ExistenDistintosValoresEnIGV_2", Err.Description

End Function


Public Function HabilitarFechaProceso(Optional VarAux As Variant) As Boolean
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    HabilitarFechaProceso = False
    
    strSql = " SELECT STKFISI FROM IN_SETUP "
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    HabilitarFechaProceso = rs!STKFISI

    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_INV_MOVIMIENTOS.HabilitarFechaProceso", Err.Description

End Function

Public Function ConvertirCosto(ByVal dblCOSTO As Double, ByVal strCURYID As String, ByVal datFECHA As Date, _
                               ByVal strINVTIDSKU As String, ByVal strVENDIDSS As String, Optional VarAux As Variant) As Double
                                
    Dim strSql As String
    Dim strOPERADOR As String
    Dim strMONEDA As String
    Dim dblCAMBIO As Double
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
        
    strSql = " SELECT CURYID FROM IN_VENDORINVT WHERE VENDIDSS='" & strVENDIDSS & "' AND INVTIDSKU='" & strINVTIDSKU & "'"
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    strMONEDA = rs!CURYID
            
    If Trim(strMONEDA) = Trim(strCURYID) Then
        ConvertirCosto = dblCOSTO
    Else
    
        strSql = " Exec ObtieneTipoCambioProc '" & strVENDIDSS & "','" & strMONEDA & "','" & Format(datFECHA, "YYYYMMDD") & "'"
        
        Set rs = New Recordset
        rs.CursorLocation = adUseClient
        rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
        strOPERADOR = rs!OPERADOR
        dblCAMBIO = rs!Rate
                
        strSql = " Exec ObtieneMontoCambioProc " & dblCOSTO & "," & dblCAMBIO & ",'" & strOPERADOR & "'"
        
        Set rs = New Recordset
        rs.CursorLocation = adUseClient
        rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
        ConvertirCosto = rs!COSTO
    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_INV_MOVIMIENTOS.ConvertirCosto", Err.Description

End Function

Public Function ExistenArticulosDesensamble(ByVal lngCORRNBR As Long, Optional VarAux As Variant) As Boolean
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    ExistenArticulosDesensamble = False
    
    strSql = " SELECT INVTIDSKU " & _
             " FROM TMP_IN_INTRAITEM " & _
             " WHERE CORRNBR=" & lngCORRNBR & " AND INVTIDSKU IN (SELECT INVTIDSKU FROM IN_INVENTORYDES) "
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    If rs.RecordCount > 0 Then
        ExistenArticulosDesensamble = True
    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_INV_MOVIMIENTOS.ExistenArticulosDesensamble", Err.Description

End Function

Public Function ValidaMesCerrado(ByVal strSITEID As String, ByVal datDATEPROCE As Date, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    
    strSql = " VALIDA_MES_CERRADO_PROC '" & strSITEID & "','" & Format(datDATEPROCE, "DD/MM/YYYY") & "'"
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
            
  
    Set ValidaMesCerrado = 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_MOVIMIENTOS.ValidaMesCerrado", Err.Description

End Function

Public Function Auxiliar1(Optional ByVal VarAux1 As Variant) As Variant
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    Auxiliar1 = False
    
    strSql = " SELECT INVTIDSKU FROM IN_INVENTORYDAT WHERE SITEID='" & VarAux1(1, 1) & "' AND INVTIDSKU='" & VarAux1(1, 2) & "'"
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
            
  
    'If rs.RecordCount > 0 Then
    '    Auxiliar1 = True
    'End If
    
    If Not rs.EOF Then
       Auxiliar1 = True
    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_INV_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.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_MOVIMIENTOS.C_MOVIMIENTOS.Auxiliar10", Err.Description
End Function


Public Function ObtieneSaldoInicialenKardex(ByVal datFECHA As Date, ByVal datFECHAINI_R As Date, ByVal datFECHAFIN_R As Date, ByVal strSITEID As String, ByVal strINVTIDSKU As String) As ADODB.Recordset
    
    Dim strSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSql = " EXEC SALDOINI_KARDEX_NV_X_ARTICULO_PROC '" & Format(datFECHA, "DD/MM/YYYY") & "','" & Format(datFECHAINI_R, "DD/MM/YYYY") & "','" & Format(datFECHAFIN_R, "DD/MM/YYYY") & "','" & strSITEID & "','" & strINVTIDSKU & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSql, "FILEDSN=conexionsies", adOpenStatic
        
    Set ObtieneSaldoInicialenKardex = 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_MOVIMIENTOS.C_MOVIMIENTOS.ObtieneSaldoInicialenKardex", Err.Description

End Function



