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_FORMULA"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' ***************************************************************************************************
' Programador : Enrique Franco
' Fecha :       2003/15/05 HR1114
' Se Modificó la Función
' Public Sub CopiarDetalleFormulaAlTemporal(ByVal strKITID As String, ByVal intCORRNBR As Double)
' Public Function SeleccionaEnTemporalDetalleFormula(ByVal strKITID As String, ByVal intCORRNBR As Double) As ADODB.Recordset
' Public Sub ActualizaDetalleFormula(ByVal strKITID As String, ByVal intCORRNBR As Double)
' Public Sub AgregaEnTemporalDetalleFormula(ByVal intCORRNBR As Double, ByVal strKITID As String, ByVal strINVTIDSKU As String, _
                                            ByVal intSEQUENCE As Integer, ByVal dblSTDCOSTPEN As Double, ByVal dblSTDCOSTUSD As Double, ByVal dblQTY As Double)
' Public Sub EliminarItemEnTmpDetalleFormula(ByVal strINVTIDSKU As String, ByVal intCORRNBR As Double)
' Public Sub EliminarTodoEnTmpDetalleFormula(ByVal intCORRNBR As Double)
' Public Sub ActualizaTmpDetalleFormula(ByVal strINVTIDSKU As String, ByVal intSEQUENCE As Integer, ByVal dlbQTY As Double, ByVal intCORRNBR As Double)
' Public Sub ActualizaNumRegEnTmpDetalleFormula(ByVal strKITID As String, ByVal intCORRNBR As Double)
' Public Function ExisteArticulo(ByVal strINVTIDSKU As String, ByVal intCORRNBR As Double) As Boolean
' Public Function ObtieneCostosTotalesEnFormulas(ByVal strKITID As String, ByVal intCORRNBR As Double, ByVal bytValor As Byte) As ADODB.Recordset
' ***************************************************************************************************

Public Function ListarFormulasAyuda(Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSQL = " SELECT INVTIDSKU,DESCR FROM IN_INVENTORY WHERE KIT=1"
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    Set ListarFormulasAyuda = 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_MANTENIMIENTOS.ListarFormulasAyuda", Err.Description

End Function

Public Function ListarFormulas(Optional VarAux As Variant) As ADODB.Recordset
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    strSQL = " SELECT * FROM IN_INVENTORY WHERE KIT=1"
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    Set ListarFormulas = 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_MANTENIMIENTOS.ListarFormulas", Err.Description

End Function

Public Function ListarDetalleDeFormulasPorID(ByVal strKITID 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_ObtieneDetalleDeFormulaProc '" & strKITID & "'"
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
        
    Set ListarDetalleDeFormulasPorID = 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_MANTENIMIENTOS.ListarDetalleDeFormulasPorID", Err.Description

End Function

Public Function ListarArticulosParaFormulas(ByVal strSITEID As String, ByVal strINVTIDSKU As String, Optional VarAux As Variant) 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 Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarArticulosParaFormulas = 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_MANTENIMIENTOS.ListarArticulosParaFormulas", Err.Description

End Function

Public Function ObtieneCostosTotalesEnFormulas(ByVal strKITID As String, ByVal intCORRNBR As Double, ByVal bytValor 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_ObtieneCostosTotalesEnFormulasProc '" & strKITID & "'," & intCORRNBR & "," & bytValor
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ObtieneCostosTotalesEnFormulas = 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_MANTENIMIENTOS.ObtieneCostosTotalesEnFormulas", Err.Description

End Function

Public Sub CopiarDetalleFormulaAlTemporal(ByVal strKITID As String, ByVal intCORRNBR As Double, Optional VarAux As Variant)
    Dim strSQL As String
    Dim con As ADODB.Connection
    
    On Error GoTo TrataError
    
    strSQL = " EXEC IN_CopiaKitComponentProc '" & strKITID & "'," & intCORRNBR
    
    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_MANTENIMIENTOS.CopiarDetalleFormulaAlTemporal", Err.Description

End Sub

Public Function SeleccionaEnTemporalDetalleFormula(ByVal strKITID As String, 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 = " EXEC TMP_IN_KitComponentSelProc '" & strKITID & "'," & intCORRNBR
    
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    Set SeleccionaEnTemporalDetalleFormula = 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_MANTENIMIENTOS.SeleccionaEnTemporalDetalleFormula", Err.Description

End Function

Public Sub ActualizaDetalleFormula(ByVal strKITID As String, ByVal intCORRNBR As Double, Optional VarAux As Variant)
    Dim strSQL As String
    Dim con As ADODB.Connection
    
    On Error GoTo TrataError
    
    strSQL = " EXEC IN_ActualizaKitComponentProc '" & strKITID & "'," & intCORRNBR
    
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    con.Execute strSQL
    
    'GetObjectContext.SetComplete
    
    Exit Sub
    
TrataError:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant

     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_MANTENIMIENTOS.ActualizaDetalleFormula", LStrMensajeError
   
End Sub

Public Sub AgregaEnTemporalDetalleFormula(ByVal intCORRNBR As Double, ByVal strKITID As String, ByVal strINVTIDSKU As String, _
                                           ByVal intSEQUENCE As Integer, ByVal dblSTDCOSTPEN As Double, ByVal dblSTDCOSTUSD As Double, ByVal dblQTY As Double, Optional VarAux As Variant)
    Dim strSQL As String
    Dim con As ADODB.Connection
    
    On Error GoTo TrataError
    
    strSQL = " EXEC TMP_IN_KitComponentInsProc " & intCORRNBR & ",'" & strKITID & "','" & strINVTIDSKU & "'," & _
                                                    intSEQUENCE & "," & dblSTDCOSTPEN & "," & dblSTDCOSTUSD & "," & dblQTY
    
    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_MANTENIMIENTOS.AgregaEnTemporalDetalleFormula", Err.Description

End Sub

' PROCEDIMIENTO QUE ELIMINA UN REGISTRO EN LA TABLA TEMPORAL DE DETALLE(TMP_IN_KITCOMPONENT)
' DE FORMULAS
' DATOS DE ENTRADA: CODIGO DEL ARTICULO
'                   CORRELATIVO IDENTITY

Public Sub EliminarItemEnTmpDetalleFormula(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_KitComponentDelProc '" & 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_INV_MANTENIMIENTOS.EliminarItemEnTmpDetalleFormula", Err.Description
End Sub

Public Sub EliminarTodoEnTmpDetalleFormula(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_KitComponentDelTodoProc " & 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_INV_MANTENIMIENTOS.EliminarTodoEnTmpDetalleFormula", 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 ActualizaTmpDetalleFormula(ByVal strINVTIDSKU As String, ByVal intSEQUENCE As Integer, ByVal dlbQTY 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_KitComponentUpdProc '" & strINVTIDSKU & "'," & intSEQUENCE & "," & dlbQTY & "," & 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_INV_MANTENIMIENTOS.ActualizaTmpDetalleFormula", 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 ActualizaNumRegEnTmpDetalleFormula(ByVal strKITID As String, ByVal intCORRNBR As Double, Optional VarAux As Variant)
   
    Dim rs As ADODB.Recordset
    Dim i As Integer
    On Error GoTo TrataError
    
    Set rs = SeleccionaEnTemporalDetalleFormula(strKITID, intCORRNBR)
    If rs.RecordCount > 0 Then
        rs.MoveFirst
    End If
    
    For i = 1 To rs.RecordCount
        Call ActualizaTmpDetalleFormula(rs!CODIGO, i, rs!Cantidad, 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_INV_MANTENIMIENTOS.ActualizaNumRegEnTmpDetalleFormula", Err.Description
    
End Sub

' funcion que devuelve True, si encontro el codigo de articulo en temporal de
' detalle de fórmulas de lo contario False

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 = " EXEC IN_BucaArticuloEntmpDetalleFormulaProc '" & strINVTIDSKU & "'," & 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_INV_MANTENIMIENTOS.C_FORMULA.ExisteArticulo", Err.Description

End Function

Public Function ValidaCodigoIngresado(ByVal strSITEID As String, ByVal strINVTIDSKU As String, Optional VarAux As Variant) 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_INV_MANTENIMIENTOS.C_FORMULA.ValidaCodigoIngresado", 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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.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_ARTICULO.C_ARTICULO.Auxiliar10", Err.Description
End Function
