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_HIST_PRE_INV"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' Historial de Precios de Inventario
' Clase C_HIST_PRE_INV

Public Function AgregarHistorialPrecInv(ByVal strSITEID As String, ByVal strSITEIDSOURCE As String, ByVal strUSERIDAUTORIZED01 As String, ByVal datDATETIMEAUTORIZED01 As Date, _
                             ByVal strUSERIDAUTORIZED02 As String, ByVal datDATETIMEAUTORIZED02 As Date, ByVal strPRECLVID As String, _
                             ByVal datSTARTDATEPRICE As Date, ByVal datENDDATEPRICE As Date, ByVal strSTARTTIMEPRICE As String, _
                             ByVal strENDTIMEPRICE As String, ByVal lngCORREL As Long, 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_GrabarCabHistPrecInvProc '" & strSITEID & "','" & _
                                strSITEIDSOURCE & " ','" & strUSERIDAUTORIZED01 & "','" & Format(datDATETIMEAUTORIZED01, "YYYY/DD/MM") & "',NULL" & _
                                ",'" & IIf(Year(Format(datDATETIMEAUTORIZED02, "DD/MM/YYYY") < 1900), "1900/01/01", Format(datDATETIMEAUTORIZED02, "YYYY/DD/MM")) & "','" & strPRECLVID & "','" & _
                                Format(datSTARTDATEPRICE, "YYYY/DD/MM") & "','" & Format(datENDDATEPRICE, "YYYY/DD/MM") & "','" & strSTARTTIMEPRICE & "','" & _
                                strENDTIMEPRICE & "',NULL,NULL,NULL,NULL," & lngCORREL
                                

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

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, con, adOpenStatic
    
    AgregarHistorialPrecInv = rs!NUMEROLISTAPREINV
    
    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_MA_MANTENIMIENTOS.AgregarHistorialPrecInv", LStrMensajeError
     
End Function

Public Sub ModificarHistorialPrecInv(ByVal lngBATNBR As Long, ByVal strSITEID As String, _
                             ByVal datSTARTDATEPRICE As Date, ByVal datENDDATEPRICE As Date, ByVal strSTARTTIMEPRICE As String, _
                             ByVal strENDTIMEPRICE As String, ByVal lngCORREL As Long, 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_ModificarListaPrecioInvProc " & lngBATNBR & ",'" & strSITEID & "','" & _
                                Format(datSTARTDATEPRICE, "YYYY/DD/MM") & "','" & Format(datENDDATEPRICE, "YYYY/DD/MM") & "','" & strSTARTTIMEPRICE & "','" & _
                                strENDTIMEPRICE & "'," & lngCORREL
                                

    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_MA_MANTENIMIENTOS.ModificarHistorialPrecInv", LStrMensajeError
     
End Sub

Public Sub AprobarLista(ByVal stsSITEID As String, ByVal lngBATNBRPRICELEVELTEM As Long, ByVal strUSUARIO 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_AprobarListaPrecioInv '" & stsSITEID & "'," & _
                                               lngBATNBRPRICELEVELTEM & ",'" & strUSUARIO & "'"
    
    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_MA_MANTENIMIENTOS.AprobarLista", LStrMensajeError
End Sub

Public Sub ActualizaEstado(ByVal stsSITEID As String, ByVal lngBATNBRPRICELEVELTEM As Long, ByVal bitSTATUS As Byte, 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_ActualizaEstadoListaPrecioInv '" & stsSITEID & "'," & _
                                               lngBATNBRPRICELEVELTEM & "," & bitSTATUS
    
    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_MA_MANTENIMIENTOS.ActualizaEstado", LStrMensajeError
End Sub

Public Function BusquedaListadePrecio(ByVal strSITEID As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
        
    strSQL = " SELECT SITEID AS Almacen,BATNBRPRICELEVELTEM AS Nro_Lista,CASE STATUS WHEN 1 THEN 'SI' WHEN 0 THEN 'NO' END AS Activado,case STKPRICESEND WHEN 1 THEN 'SI' WHEN 0 THEN 'NO' END AS Aprobado " & _
             " FROM IN_PRICELEVELTEM " & _
             " WHERE SITEID='" & strSITEID & "'"
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenStatic
    
    Set BusquedaListadePrecio = rs
    
    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.BusquedaListadePrecio", Err.Description

End Function

Public Sub CopiarDetalleListaPrecInvAlTemporal(ByVal intCORRNBR As Long, ByVal strSITEID, ByVal lngBATNBRPRICELEVELTEM As Long, Optional VarAux As Variant)
    Dim strSQL As String
    Dim con As ADODB.Connection
    
    On Error GoTo TrataError
    
    strSQL = " EXEC IN_CopiaPriceLeveltemDetProc " & intCORRNBR & ",'" & strSITEID & "'," & lngBATNBRPRICELEVELTEM
    
    
    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_MA_MANTENIMIENTOS.CopiarDetalleListaPrecInvAlTemporal", Err.Description

End Sub


Public Function ListarArticuloPorAlmacen(ByVal strSITEID As String, ByVal strMONEDABASE As String, strPRECLVID As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset

    On Error GoTo TrataError
    'OBTENIENDO MONEDA DEL TIPO DE LISTA DE PRECIO
    strSQL = " SELECT CURYID FROM IN_PRICELEVELTYPE" & _
             " WHERE PRECLVID='" & strPRECLVID & "'"
             
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    If rs!CURYID = strMONEDABASE Then
        strSQL = " SELECT IN_INVENTORYDAT.INVTIDSKU,IN_INVENTORY.DESCR,IN_INVENTORYDAT.STDCOSTPEN AS COSTO,SLS_PRICE " & _
             " FROM IN_INVENTORY INNER JOIN IN_INVENTORYDAT " & _
             " ON IN_INVENTORY.INVTIDSKU=IN_INVENTORYDAT.INVTIDSKU " & _
             " WHERE SITEID='" & strSITEID & "'"
    Else
        strSQL = " SELECT IN_INVENTORYDAT.INVTIDSKU,IN_INVENTORY.DESCR,IN_INVENTORYDAT.STDCOSTUSD AS COSTO,SLS_PRICE " & _
             " FROM IN_INVENTORY INNER JOIN IN_INVENTORYDAT " & _
             " ON IN_INVENTORY.INVTIDSKU=IN_INVENTORYDAT.INVTIDSKU " & _
             " WHERE SITEID='" & strSITEID & "'"
    
    End If
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    Set ListarArticuloPorAlmacen = rs
    
    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.C_HIST_PRE_INV.ListarArticuloPorAlmacen", Err.Description

End Function

Public Sub AgregaEnTemporalDetallelleHistPrecInv(ByVal intCORRNBR As Double, ByVal strSITEID As String, ByVal intSEQUENCE As Integer, ByVal strINVTIDSKU As String, _
                                                 ByVal strDESCR As String, ByVal dblSTDCOST As Double, ByVal dblSLS_PRICE As Double, ByVal dblDISCMTO As Double, ByVal dblNEWSLS_PRICE As Double, Optional VarAux As Variant)
    Dim strSQL As String
    Dim con As ADODB.Connection
    
    On Error GoTo TrataError
    
    strSQL = " EXEC TMP_IN_PRICELEVELTEMDETInsProc " & intCORRNBR & ",'" & strSITEID & "'," & intSEQUENCE & ",'" & strINVTIDSKU & "','" & _
                                                    strDESCR & "'," & dblSLS_PRICE & "," & dblDISCMTO & "," & dblNEWSLS_PRICE & "," & dblSTDCOST
    
    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_MA_MANTENIMIENTOS.AgregaEnTemporalDetallelleHistPrecInv", Err.Description

End Sub


Public Sub EliminarItemEnTmpDetalleHistPrecInv(ByVal strINVTIDSKU As String, ByVal intCORRNBR As Double, Optional VarAux As Variant)
   
    Dim cmd As Command
    Dim con As Connection
    Dim strSQL As String

    On Error GoTo TrataError
    
    strSQL = " EXEC TMP_IN_PRICELEVELTEMDETDelProc '" & strINVTIDSKU & "'," & intCORRNBR
                                
    Set cmd = New Command
    cmd.CommandText = strSQL
      
    Set con = New 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_MA_MANTENIMIENTOS.EliminarItemEnTmpDetalleHistPrecInv", Err.Description
End Sub

Public Sub EliminarTodoEnTmpDetalleHistPrecInv(ByVal intCORRNBR As Double, Optional VarAux As Variant)
   
    Dim cmd As Command
    Dim con As Connection
    Dim strSQL As String

    On Error GoTo TrataError
    
    strSQL = " EXEC TMP_IN_PRICELEVELTEMDETDelTodoProc " & intCORRNBR
                                
    Set cmd = New Command
    cmd.CommandText = strSQL
      
    Set con = New 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_MA_MANTENIMIENTOS.EliminarTodoEnTmpDetalleHistPrecInv", Err.Description
End Sub

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

Public Sub ActualizaTmpDetalleHistPrecInv(ByVal strINVTIDSKU As String, ByVal intSEQUENCE As Integer, ByVal dblSLS_PRICE As Double, _
                                          ByVal dblNEWSLS_PRICE As Double, ByVal intCORRNBR As Double, Optional VarAux As Variant)
   
    Dim cmd As Command
    Dim con As Connection
    Dim strSQL As String

    On Error GoTo TrataError
    
    strSQL = " EXEC TMP_IN_PRICELEVELTEMDETUpdProc '" & strINVTIDSKU & "'," & intSEQUENCE & "," & dblSLS_PRICE - dblNEWSLS_PRICE & "," & dblNEWSLS_PRICE & "," & intCORRNBR
                                
    Set cmd = New Command
    cmd.CommandText = strSQL
      
    Set con = New 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_MA_MANTENIMIENTOS.ActualizaTmpDetalleHistPrecInv", Err.Description
End Sub

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

Public Sub ActualizaNumRegEnTmpDetalleHistPrecInv(ByVal intCORRNBR As Integer, Optional VarAux As Variant)
   
    Dim rs As ADODB.Recordset
    Dim i As Integer
    On Error GoTo TrataError
    
    Set rs = SeleccionaEnTemporalDetalleHistPrecInv(intCORRNBR)
    If rs.RecordCount > 0 Then
        rs.MoveFirst
    End If
    
    For i = 1 To rs.RecordCount
        Call ActualizaTmpDetalleHistPrecInv(rs!CODIGO, i, rs!Prec_ant, rs!Prec_Nuevo, intCORRNBR)
        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_MA_MANTENIMIENTOS.ActualizaNumRegEnTmpDetalleHistPrecInv", Err.Description
    
End Sub

Public Function ExisteArticulo(ByVal strINVTIDSKU As String, ByVal intCORRNBR As Double, Optional VarAux As Variant) As Boolean
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    ExisteArticulo = False
    
    On Error GoTo TrataError
    
    strSQL = " SELECT INVTIDSKU " & _
             " From TMP_IN_PRICELEVELTEMDET " & _
             " WHERE INVTIDSKU='" & strINVTIDSKU & "' AND CORRNBR=" & intCORRNBR & ""
    
    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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.ExisteArticulo", Err.Description

End Function

Public Function SeleccionaEnTemporalDetalleHistPrecInv(ByVal intCORRNBR As Double, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSQL = " SELECT SEQUENCE AS Item,INVTIDSKU as Codigo,DESCR as Descripcion,STDCOST as Costo,SLS_PRICE as Prec_Ant,NEWSLS_PRICE as Prec_Nuevo " & _
             " FROM TMP_IN_PRICELEVELTEMDET " & _
             " WHERE CORRNBR=" & intCORRNBR & " ORDER BY SEQUENCE ASC "
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    Set SeleccionaEnTemporalDetalleHistPrecInv = rs
    
    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.SeleccionaEnTemporalDetalleHistPrecInv", Err.Description

End Function

Public Function SeleccionaEnDetalle(ByVal strSITEID As String, ByVal lngBATNBRPRICELEVELTEM As Long, 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 SEQUENCE AS Item,INVTIDSKU as Codigo,DESCR as Descripcion,STDCOST AS Costo,SLS_PRICE as Prec_Ant,NEWSLS_PRICE as Prec_Nuevo " & _
             " FROM IN_PRICELEVELTEMDET " & _
             " WHERE SITEID='" & strSITEID & "' AND BATNBRPRICELEVELTEM=" & lngBATNBRPRICELEVELTEM & " ORDER BY SEQUENCE ASC "
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenStatic
    
    Set SeleccionaEnDetalle = 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.SeleccionaEnDetalle", Err.Description

End Function

Public Function SeleccionaEnCabecera(ByVal strSITEID As String, ByVal lngBATNBRPRICELEVELTEM As Long, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSQL = " SELECT * " & _
             " FROM IN_PRICELEVELTEM WHERE SITEID='" & strSITEID & "' AND BATNBRPRICELEVELTEM=" & lngBATNBRPRICELEVELTEM
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenStatic
        
    Set SeleccionaEnCabecera = 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.SeleccionaEnCabecera", Err.Description

End Function

'Public Function ValidaCodigoIngresado(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 = " SELECT IN_INVENTORY.INVTIDSKU,IN_INVENTORY.DESCR,IN_INVENTORYDAT.STDCOSTPEN,IN_INVENTORYDAT.STDCOSTUSD " & _
'             " FROM IN_INVENTORY JOIN IN_INVENTORYDAT " & _
'             " ON IN_INVENTORY.INVTIDSKU=IN_INVENTORYDAT.INVTIDSKU " & _
'             " WHERE IN_INVENTORYDAT.SITEID='" & strSITEID & "' AND IN_INVENTORYDAT.INVTIDSKU='" & strINVTIDSKU & "'"
'
'    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_MA_MANTENIMIENTOS.ValidaCodigoIngresado", Err.Description
'
'End Function

Public Function ValidaCodigoIngresado(ByVal strSITEID As String, ByVal strINVTIDSKU As String, ByVal strMONEDABASE As String, strPRECLVID As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset

    On Error GoTo TrataError
    'OBTENIENDO MONEDA DEL TIPO DE LISTA DE PRECIO
    strSQL = " SELECT CURYID FROM IN_PRICELEVELTYPE" & _
             " WHERE PRECLVID='" & strPRECLVID & "'"
             
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    If rs!CURYID = strMONEDABASE Then
        strSQL = " SELECT IN_INVENTORYDAT.INVTIDSKU,IN_INVENTORY.DESCR,IN_INVENTORYDAT.STDCOSTPEN AS COSTO,SLS_PRICE " & _
             " FROM IN_INVENTORY INNER JOIN IN_INVENTORYDAT " & _
             " ON IN_INVENTORY.INVTIDSKU=IN_INVENTORYDAT.INVTIDSKU " & _
             " WHERE SITEID='" & strSITEID & "' AND IN_INVENTORYDAT.INVTIDSKU='" & strINVTIDSKU & "'"
    Else
        strSQL = " SELECT IN_INVENTORYDAT.INVTIDSKU,IN_INVENTORY.DESCR,IN_INVENTORYDAT.STDCOSTUSD AS COSTO,SLS_PRICE " & _
             " FROM IN_INVENTORY INNER JOIN IN_INVENTORYDAT " & _
             " ON IN_INVENTORY.INVTIDSKU=IN_INVENTORYDAT.INVTIDSKU " & _
             " WHERE SITEID='" & strSITEID & "' AND IN_INVENTORYDAT.INVTIDSKU='" & strINVTIDSKU & "'"
    
    End If
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.ValidaCodigoIngresado", Err.Description

End Function

Public Function ConvertirValor(ByVal dblVALOR As Double, ByVal strSITEID As String, ByVal strINVTIDSKU As String, ByVal datFecha As Date, _
                               ByVal strPRECLVID As String, ByVal strCURYTYPEID As String, ByVal intREDONDEO As Integer, Optional VarAux As Variant) As Double
                                
    Dim strSQL As String
    Dim strMONEDA1 As String
    Dim strMONEDA2 As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSQL = " SELECT CURYID " & _
             " FROM IN_PRICELEVELTYPE " & _
             " WHERE PRECLVID=(SELECT PRECLVID FROM IN_INVENTORYDAT WHERE SITEID='" & strSITEID & "' AND INVTIDSKU='" & strINVTIDSKU & "')"
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    strMONEDA1 = rs!CURYID
    
        
    strSQL = " SELECT CURYID " & _
             " FROM IN_PRICELEVELTYPE " & _
             " WHERE PRECLVID='" & strPRECLVID & "'"
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    strMONEDA2 = rs!CURYID
                
    If strMONEDA1 = strMONEDA2 Then
        ConvertirValor = dblVALOR
    Else
    
        strSQL = " Exec ObtieneTipoCambioGeneralProc " & dblVALOR & ",'" & strMONEDA1 & "','" & strMONEDA2 & "','" & Format(datFecha, "YYYY/DD/MM") & "','" & strCURYTYPEID & "'," & intREDONDEO
        
        Set rs = New Recordset
        rs.CursorLocation = adUseClient
        rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
        ConvertirValor = rs!VALOR
    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_MONTENIMIENTOS.ConvertirValor", Err.Description

End Function


Public Function Auxiliar1(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
   Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
    Dim strSQL As String

    On Error GoTo TrataError
    
    
    strSQL = " EXEC ACTUALIZA_MAESTRA_ARTICULOS_PROC '" & VarAux1(1, 1) & "','" & VarAux1(1, 2) & "'"
                                               
    
    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 Function
    
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 Err.Number, "DB_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.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_MA_MANTENIMIENTOS.C_HIST_PRE_INV.Auxiliar10", Err.Description
End Function




