Attribute VB_Name = "Module1"
Public Sub AgregaCarasVendedor(ByVal strSITEID As String, ByVal datDATEPROCE As Date, ByVal datDATESALES As Date, ByVal intNUMBERTURN As Integer, _
                               ByVal strSALESPERID As String, ByVal lngCORRNBR As Long, ByVal BitSTATUS As Byte, Optional VarAux As Variant)

    Dim strSQL As String
    Dim con As ADODB.Connection
    
    On Error GoTo TrataError
                    
    strSQL = " EXEC OP_TURNVSSIDEInsProc '" & strSITEID & "','" & Format(datDATEPROCE, "YYYY/DD/MM") & "','" & Format(datDATESALES, "YYYY/DD/MM") & "'," & intNUMBERTURN & ",'" & _
                                              strSALESPERID & "'," & lngCORRNBR & ", " & BitSTATUS & ""
                                                    
        
    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_OP_MANTENIMIENTOS.AgregaCarasVendedor", LStrMensajeError
End Sub


Public Sub EliminaCarasVendedor(ByVal strSITEID As String, ByVal datDATEPROCE As Date, ByVal datDATESALES As Date, ByVal intNUMBERTURN As Integer, _
                               ByVal strSALESPERID As String, Optional VarAux As Variant)

    Dim strSQL As String
    Dim con As ADODB.Connection
    
    On Error GoTo TrataError
                    
    strSQL = " EXEC OP_TURNVSSIDEEliProc '" & strSITEID & "','" & Format(datDATEPROCE, "YYYY/DD/MM") & "','" & Format(datDATESALES, "YYYY/DD/MM") & "'," & intNUMBERTURN & ",'" & _
                                              strSALESPERID & "'"
                                                    
        
    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_OP_MANTENIMIENTOS.AgregaCarasVendedor", LStrMensajeError
End Sub



Public Function ListarCarasVendedor(ByVal strSITEID As String, ByVal strSALESPERID As String, ByVal datFECHAINI As Date, ByVal datFECHAFIN As Date, _
                                   ByVal bytAlmacen As Byte, ByVal bytVendedor As Byte, Optional VarAux As Variant) As ADODB.Recordset
                               
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    If bytAlmacen = 1 And bytVendedor = 1 Then 'TODOS LOS ALMACENES
        strSQL = " SELECT OP_TURNVSSIDE.SITEID as Almacen,OP_TURNVSSIDE.SALESPERID as CodVendedor,SALESPERNAME AS Vendedor,DATEPROCE as Fech_Proc,DATESALES AS Fech_Vta,NUMBERTURN as Turno,SIDE as Cara,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado " & _
                 " FROM OP_TURNVSSIDE INNER JOIN OP_SALESPERSON " & _
                 " ON OP_TURNVSSIDE.SALESPERID=OP_SALESPERSON.SALESPERID " & _
                 " WHERE DATEPROCE>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCE<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "'"
    End If
    
    If bytAlmacen = 1 And bytVendedor = 0 Then 'TODOS LOS ALMACENES
        strSQL = " SELECT OP_TURNVSSIDE.SITEID as Almacen,OP_TURNVSSIDE.SALESPERID as CodVendedor,SALESPERNAME AS Vendedor,DATEPROCE as Fech_Proc,DATESALES AS Fech_Vta,NUMBERTURN as Turno,SIDE as Cara,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado " & _
                 " FROM OP_TURNVSSIDE INNER JOIN OP_SALESPERSON " & _
                 " ON OP_TURNVSSIDE.SALESPERID=OP_SALESPERSON.SALESPERID " & _
                 " WHERE DATEPROCE>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCE<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND OP_TURNVSSIDE.SALESPERID='" & strSALESPERID & "'"
    End If
    
    If bytAlmacen = 0 And bytVendedor = 1 Then 'TODOS LOS ALMACENES
        strSQL = " SELECT OP_TURNVSSIDE.SITEID as Almacen,OP_TURNVSSIDE.SALESPERID as CodVendedor,SALESPERNAME AS Vendedor,DATEPROCE as Fech_Proc,DATESALES AS Fech_Vta,NUMBERTURN as Turno,SIDE as Cara,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado " & _
                 " FROM OP_TURNVSSIDE INNER JOIN OP_SALESPERSON " & _
                 " ON OP_TURNVSSIDE.SALESPERID=OP_SALESPERSON.SALESPERID " & _
                 " WHERE DATEPROCE>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCE<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND OP_TURNVSSIDE.SITEID='" & strSITEID & "'"
    End If

    If bytAlmacen = 0 And bytVendedor = 0 Then 'TODOS LOS ALMACENES
        strSQL = " SELECT OP_TURNVSSIDE.SITEID as Almacen,OP_TURNVSSIDE.SALESPERID as CodVendedor,SALESPERNAME AS Vendedor,DATEPROCE as Fech_Proc,DATESALES AS Fech_Vta,NUMBERTURN as Turno,SIDE as Cara,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado " & _
                 " FROM OP_TURNVSSIDE INNER JOIN OP_SALESPERSON " & _
                 " ON OP_TURNVSSIDE.SALESPERID=OP_SALESPERSON.SALESPERID " & _
                 " WHERE DATEPROCE>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCE<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND OP_TURNVSSIDE.SITEID='" & strSITEID & "' AND OP_TURNVSSIDE.SALESPERID='" & strSALESPERID & "'"
    End If

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

    'GetObjectContext.SetAbort
    
    'Err.Raise Err.Number, "DB_OP_MANTENIMIENTOS.ListarCarasVendedor", Err.Description

End Function


Public Function ListarCarasVendedorOnLine(ByVal strSITEID As String, ByVal datFECHAINI As Date, ByVal datDATESALES As Date, Optional VarAux As Variant) As ADODB.Recordset
                               
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    

        strSQL = " SELECT OP_TURNVSSIDE.SITEID as Almacen,OP_TURNVSSIDE.SALESPERID as CodVendedor,SALESPERNAME AS Vendedor,DATEPROCE as Fech_Proc,NUMBERTURN as Turno,SIDE as Cara,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado " & _
                 " FROM OP_TURNVSSIDE INNER JOIN OP_SALESPERSON " & _
                 " ON OP_TURNVSSIDE.SALESPERID=OP_SALESPERSON.SALESPERID " & _
                 " WHERE DATEPROCE='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATESALES='" & Format(datDATESALES, "DD/MM/YYYY") & "' AND OP_TURNVSSIDE.SITEID='" & strSITEID & "' ORDER BY NUMBERTURN,SIDE "

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

    'GetObjectContext.SetAbort
    
   ' Err.Raise Err.Number, "DB_OP_MANTENIMIENTOS.ListarCarasVendedorOnLine", Err.Description

End Function



