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_TARJETA_MONTO"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' Clase C_TARJETA_MONTO
' Funciones Básicas de Mantenimiento
'               AgregarTarjetaMonto
'               EliminarTarjetaMonto
'               ActualizarTarjetaMonto

Option Explicit

Public Sub AgregarTarjetaMonto(ByVal strSITEID As String, ByVal strCARDID As String, ByVal datDATEPOS As Date, _
                               ByVal datDATEPROCE As Date, ByVal strCURYID As String, ByVal dblTOTALCARD As Double, _
                               ByVal bytSTATUS As Byte, ByVal StrComentario As String, ByVal strUSERID 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 OP_CARD_MONTInsProc '" & strSITEID & "','" & strCARDID & "','" & Format(datDATEPOS, "YYYY/DD/MM") & "','" & _
                                            Format(datDATEPROCE, "YYYY/DD/MM") & "','" & strCURYID & "'," & dblTOTALCARD & "," & _
                                            bytSTATUS & ",'" & StrComentario & "','" & strUSERID & "'"
    
    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.AgregarTarjetaMonto", LStrMensajeError
    
End Sub

Public Sub EliminarTarjetaMonto(ByVal strSITEID As String, ByVal strCARDID As String, ByVal datDATEPOS As Date, _
                                ByVal datDATEPROCE As Date, Optional VarAux As Variant)
                               
    Dim con As ADODB.Connection
    Dim strSQL As String
    
    On Error GoTo TrataError
    
    strSQL = " EXEC OP_CARD_MONTDelProc '" & strSITEID & "','" & strCARDID & "','" & datDATEPOS & "','" & _
                                                datDATEPROCE & "'"
    
    Set con = New ADODB.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_MA_MANTENIMIENTOS.EliminarTarjetaMonto", LStrMensajeError

End Sub

Public Sub ActualizarTarjetaMonto(ByVal strSITEID As String, ByVal strCARDID As String, ByVal datDATEPOS As Date, _
                                  ByVal datDATEPROCE As Date, ByVal strCURYID As String, ByVal dblTOTALCARD As Double, _
                                  ByVal StrComentario As String, ByVal strUSERID As String, Optional VarAux As Variant)
                               
    Dim con As ADODB.Connection
    Dim strSQL As String
    
    On Error GoTo TrataError
    
    strSQL = " EXEC OP_CARD_MONTUpdProc '" & strSITEID & "','" & strCARDID & "','" & datDATEPOS & "','" & _
                                             datDATEPROCE & "','" & strCURYID & "'," & dblTOTALCARD & ",'" & _
                                             StrComentario & "','" & strUSERID & "'"
    
    Set con = New ADODB.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_MA_MANTENIMIENTOS.ActualizarTarjetaMonto", LStrMensajeError

End Sub

Public Function ListarTarjetaMonto(ByVal strSITEID As String, ByVal strCARDID As String, ByVal datFECHAINI As Date, ByVal datFECHAFIN As Date, _
                                   ByVal bytAlmacen As Byte, ByVal bytTarjeta 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 bytTarjeta = 1 Then 'TODOS LOS ALMACENES
        strSQL = " SELECT SITEID as Almacen,OP_CARD_MONT.CARDID as CodTarjeta,DESCR AS Tarjeta,DATEPOS as Fecha,DATEPROCE as Fech_Proc,CURYID as Moneda,TOTALCARD as Monto,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado,COMMENT" & _
                 " FROM OP_CARD_MONT INNER JOIN OP_CARD " & _
                 " ON OP_CARD_MONT.CARDID=OP_CARD.CARDID " & _
                 " INNER JOIN OP_BUSINESSTYPE ON OP_CARD_MONT.BUSINESSTYPE = OP_BUSINESSTYPE.BUSINESSTYPE " & _
                 " WHERE DATEPROCE>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCE<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "'"
    End If
    
    If bytAlmacen = 1 And bytTarjeta = 0 Then 'TODOS LOS ALMACENES
        strSQL = " SELECT SITEID as Almacen,OP_CARD_MONT.CARDID as CodTarjeta,DESCR AS Tarjeta,DATEPOS as Fecha,DATEPROCE as Fech_Proc,CURYID as Moneda,TOTALCARD as Monto,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado,COMMENT " & _
                 " FROM OP_CARD_MONT INNER JOIN OP_CARD " & _
                 " ON OP_CARD_MONT.CARDID=OP_CARD.CARDID " & _
                 " INNER JOIN OP_BUSINESSTYPE ON OP_CARD_MONT.BUSINESSTYPE = OP_BUSINESSTYPE.BUSINESSTYPE " & _
                 " WHERE DATEPROCE>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCE<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND OP_CARD_MONT.CARDID='" & strCARDID & "'"
    End If
    
    If bytAlmacen = 0 And bytTarjeta = 1 Then 'TODOS LOS ALMACENES
        strSQL = " SELECT SITEID as Almacen,OP_CARD_MONT.CARDID as CodTarjeta,DESCR AS Tarjeta,DATEPOS as Fecha,DATEPROCE as Fech_Proc,CURYID as Moneda,TOTALCARD as Monto,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado,COMMENT " & _
                 " FROM OP_CARD_MONT INNER JOIN OP_CARD " & _
                 " ON OP_CARD_MONT.CARDID=OP_CARD.CARDID " & _
                 " INNER JOIN OP_BUSINESSTYPE ON OP_CARD_MONT.BUSINESSTYPE = OP_BUSINESSTYPE.BUSINESSTYPE " & _
                 " WHERE DATEPROCE>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCE<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND SITEID='" & strSITEID & "'"
    End If

    If bytAlmacen = 0 And bytTarjeta = 0 Then 'TODOS LOS ALMACENES
        strSQL = " SELECT SITEID as Almacen,OP_CARD_MONT.CARDID as CodTarjeta,DESCR AS Tarjeta,DATEPOS as Fecha,DATEPROCE as Fech_Proc,CURYID as Moneda,TOTALCARD as Monto,CASE STATUS " & _
                 " WHEN 1 THEN 'APROBADO' WHEN 0 THEN 'PENDIENTE' END AS Estado,COMMENT" & _
                 " FROM OP_CARD_MONT INNER JOIN OP_CARD " & _
                 " ON OP_CARD_MONT.CARDID=OP_CARD.CARDID " & _
                 " INNER JOIN OP_BUSINESSTYPE ON OP_CARD_MONT.BUSINESSTYPE = OP_BUSINESSTYPE.BUSINESSTYPE " & _
                 " WHERE DATEPROCE>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCE<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND SITEID='" & strSITEID & "' AND OP_CARD_MONT.CARDID='" & strCARDID & "'"
    End If

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarTarjetaMonto = 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.ListarTarjetaMonto", Err.Description

End Function


' intUbicacion = 0 registros ingresados
' intUbicacion = 1 registros de ventas segun sistema
Public Function ObtenerRegistros(ByVal intUbicacion As Integer, ByVal strSITEID As String, ByVal datFECHAPROCESO As Date, Optional VarAux As Variant) As ADODB.Recordset
                               
    Dim strSQL As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    If intUbicacion = 0 Then
        strSQL = " SELECT CM.CARDID AS Codigo,C.DESCR as Descripcion,SUM(CM.TOTALCARD) AS Monto " & _
                 " FROM OP_CARD_MONT AS CM JOIN OP_CARD AS C " & _
                 " ON CM.CARDID=C.CARDID " & _
                 " WHERE CM.SITEID='" & strSITEID & "' AND CM.DATEPROCE='" & Format(datFECHAPROCESO, "DD/MM/YYYY") & "'" & _
                 " GROUP BY CM.CARDID,C.DESCR "
    Else
        strSQL = " SELECT CMS.CARDID AS Codigo,C.DESCR as Descripcion,SUM(CMS.TOTALPENSALES) AS Monto " & _
                 " FROM OP_CARD_MONTSALES AS CMS JOIN OP_CARD AS C " & _
                 " ON CMS.CARDID=C.CARDID " & _
                 " WHERE CMS.SITEID='" & strSITEID & "' AND CMS.DATEPROCE='" & Format(datFECHAPROCESO, "DD/MM/YYYY") & "'" & _
                 " GROUP BY CMS.CARDID,C.DESCR "
        
    End If
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open strSQL, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ObtenerRegistros = 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.ObtenerRegistros", 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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.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_OP_FACTURACION.C_CIERRE.Auxiliar10", Err.Description
End Function


