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_CANCELACION"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Public Function ObtenerDocPorCancelar(Optional VarAux As Variant) As ADODB.Recordset
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " SELECT AR_CCDOC.DOCTYPEID,MINDES AS Doc,NBRDOCUMENT as Numero,DATEPROCESALES as Fech_Emision, " & _
            " DUEDATE as Fech_Venc,TOTALPEN AS Monto_PEN,TOTALUSD AS Monto_USD,DOCVALPEN as Saldo_PEN,DOCVALUSD as Saldo_USD,0 as Monto_Pagar,custidss " & _
            " FROM AR_CCDOC JOIN DOCTYPE ON AR_CCDOC.DOCTYPEID=DOCTYPE.DOCTYPEID" & _
            " WHERE DOCSTATUSID NOT IN ('AN','CA') "
            
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   Set ObtenerDocPorCancelar = rs
   ''GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   ''''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ObtenerDocPorCancelar", Err.Description
    
End Function

Public Function ObtenerDocCancelados(ByVal strSITEID As String, ByVal dblCORREL As Double, Optional VarAux As Variant) As ADODB.Recordset
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " SELECT MINDES AS Doc,NBRDOCUMENT as Numero,PAIDMENTPEN AS MOnto_PEN,PAIDMENTUSD as Monto_USD " & _
            " FROM AR_CCDOCDET JOIN DOCTYPE " & _
            " ON AR_CCDOCDET.DOCTYPEID=DOCTYPE.DOCTYPEID  " & _
            " WHERE SITEID='" & strSITEID & "' AND BATNBRAR_CCDOCDET=" & dblCORREL & " ORDER BY NBRDOCUMENT "
            
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   Set ObtenerDocCancelados = rs
   ''GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   ''''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ObtenerDocCancelados", Err.Description
    
End Function

Public Function ObtenerCabDocCancelados(ByVal strSITEID As String, ByVal dblCORREL As Double, Optional VarAux As Variant) As ADODB.Recordset
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " SELECT * " & _
            " FROM AR_CCDOCDET JOIN DOCTYPE " & _
            " ON AR_CCDOCDET.DOCTYPEID=DOCTYPE.DOCTYPEID  " & _
            " WHERE SITEID='" & strSITEID & "' AND BATNBRAR_CCDOCDET=" & dblCORREL & " ORDER BY NBRDOCUMENT "
            
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   Set ObtenerCabDocCancelados = rs
   ''GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   ''''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ObtenerCabDocCancelados", Err.Description
    
End Function

Public Function ObtenerDocReferencias(ByVal strCUSTIDSS As String, Optional VarAux As Variant) As ADODB.Recordset
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " SELECT NBRDOCUMENT AS Numero,DOCVALPEN AS Saldo_PEN," & _
            " DOCVALUSD AS Saldo_USD,DATEPROCESALES AS Fech_Emision,  " & _
            " TOTALPEN AS ORIPEN,TOTALUSD AS ORIUSD " & _
            " FROM AR_CCDOC " & _
            " WHERE DOCTYPEID='07' AND CUSTIDSS='" & strCUSTIDSS & "' AND DOCSTATUSID NOT IN ('AN','CA') "
                        
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   Set ObtenerDocReferencias = rs
   ''GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   ''''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ObtenerDocReferencias", Err.Description
    
End Function

Public Function ObtenerPagos(ByVal strCUSTIDSS As String, ByVal IntMonBase As Integer, ByVal IntPagoAjuste As Integer, Optional VarAux As Variant) As ADODB.Recordset
  
  Dim StrSql As String
  Dim rs As ADODB.Recordset
        
        
  If IntPagoAjuste = 0 Then
    If IntMonBase = 0 Then
      StrSql = " SELECT DEPOSITPASSWORD as Deposito,TOTALPEN as PAGO_ORIGINAL," & _
               " DOCBALPEN As SALDO, DATEDEPOSIT As Fech_Deposito,BATNBRAR_CCDOCDET " & _
               " From AR_CCDOC_PAYMENT WHERE  CUSTIDSS='" & strCUSTIDSS & "'" & _
               " AND DOCBALPEN <> 0 " & _
               " AND SITEID=(SELECT SOURCESITE FROM SETUP) "
    Else
      StrSql = " SELECT DEPOSITPASSWORD as Deposito,TOTALUSD as PAGO_ORIGINAL," & _
               " DOCBALUSD As SALDO, DATEDEPOSIT As Fech_Deposito,BATNBRAR_CCDOCDET " & _
               " From AR_CCDOC_PAYMENT WHERE  CUSTIDSS='" & strCUSTIDSS & "'" & _
               " AND DOCBALUSD <> 0 " & _
               " AND SITEID=(SELECT SOURCESITE FROM SETUP) "
    End If
  Else
    If IntMonBase = 0 Then
      StrSql = " SELECT DEPOSITPASSWORD as Deposito,TOTALPEN as PAGO_ORIGINAL," & _
               " DOCBALPEN As SALDO, DATEDEPOSIT As Fech_Deposito,BATNBRAR_CCDOCDET " & _
               " From AR_CCDOC_PAYMENT WHERE  CUSTIDSS='" & strCUSTIDSS & "'" & _
               " AND DOCBALPEN <> 0 AND DOCTYPEIDPAID =(Select DOCTYPEIDNCAJUSTE  from OP_SETUP) " & _
               " AND SITEID=(SELECT SOURCESITE FROM SETUP) "
    Else
      StrSql = " SELECT DEPOSITPASSWORD as Deposito,TOTALUSD as PAGO_ORIGINAL," & _
               " DOCBALUSD As SALDO, DATEDEPOSIT As Fech_Deposito,BATNBRAR_CCDOCDET " & _
               " From AR_CCDOC_PAYMENT WHERE  CUSTIDSS='" & strCUSTIDSS & "'" & _
               " AND DOCBALUSD <> 0 AND DOCTYPEIDPAID =(Select DOCTYPEIDNCAJUSTE  from OP_SETUP) " & _
               " AND SITEID=(SELECT SOURCESITE FROM SETUP) "
    End If
  End If
       
       
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
  
  Set ObtenerPagos = rs
   'GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   '''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ObtenerPagos", Err.Description
     
End Function

Public Function ObtenerDepositos(ByVal strCUSTIDSS As String, Optional VarAux As Variant) As ADODB.Recordset
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " SELECT DEPOSITPASSWORD AS Deposito,TOTALPEN AS Monto_PEN,TOTALUSD AS Monto_USD,DATEDEPOSIT AS Fech_Deposito FROM OP_DEPOSITSITEDET " & _
            " WHERE CUSTIDSS='" & strCUSTIDSS & "' AND DEPOSITPASSWORD NOT IN (SELECT DEPOSITPASSWORD FROM AR_CCDOCDET WHERE CUSTIDSS='" & strCUSTIDSS & "')"
                        
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   Set ObtenerDepositos = rs
   'GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   '''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ObtenerDepositos", Err.Description
    
End Function

Public Function ObtieneTipoCambio(ByVal datDATEPROCE As Date, ByVal StrMoneda As String, Optional VarAux As Variant) As Double
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = " SELECT RATE AS RATE FROM CURYRATE " & _
             " WHERE " & _
             " CURYDATE=(SELECT MAX(CURYDATE) FROM " & _
             " CURYRATE WHERE CURYDATE<='" & Format(datDATEPROCE, "yyyymmdd") & "' AND CURYTYPEID=(SELECT CURYTYPEIDSALES FROM SETUP)) " & _
             " AND FROMCURYID='" & StrMoneda & "' AND CURYTYPEID=(SELECT CURYTYPEIDSALES FROM SETUP) "
             
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    If Not rs.EOF Then
        ObtieneTipoCambio = rs!Rate
    Else
        ObtieneTipoCambio = 0
    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_AR_CUENTASCOBRAR.ObtieneTipoCambio", Err.Description

End Function


Public Sub CARGA_TEMPORAL(ByVal lngCORRNBR As Long, ByVal StrCliente 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 CARGA_TMP_COBRANZAS_PROC " & lngCORRNBR & ",'" & StrCliente & "'"
                                                
    
    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_OP_MANTENIMIENTOS.CARGA_TEMPORAL", LStrMensajeError
    
End Sub

Public Sub ANULAR_COBRANZA(ByVal dblBATNBRAR_CCDOCDET As Double, ByVal strCURYID As String, ByVal strSITEID As String, _
                           ByVal StrCliente As String, ByVal dblTOTAL As Double, 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 ANULAR_COBRANZA_PROC " & dblBATNBRAR_CCDOCDET & ",'" & strCURYID & "','" & strSITEID & "','" & _
                                        StrCliente & "'," & dblTOTAL & ",'" & 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_OP_MANTENIMIENTOS.ANULAR_COBRANZA", LStrMensajeError
    
End Sub

Public Sub ACTUALIZA_TEMPORAL(ByVal lngCORRNBR As Long, ByVal strDOCTYPEID As String, _
                              ByVal dblNBRDOCUMENT As Double, ByVal DblMonto As Double, 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_AR_COBRANZASUpd_Proc " & lngCORRNBR & ",'" & strDOCTYPEID & "'," & _
                                            dblNBRDOCUMENT & "," & DblMonto
                                                
    
    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_OP_MANTENIMIENTOS.ACTUALIZA_TEMPORAL", LStrMensajeError
    
End Sub

Public Function SeleccionaEnTemporal(ByVal lngCORRNBR As Long, Optional VarAux As Variant) As ADODB.Recordset
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " SELECT TMP_AR_COBRANZAS.DOCTYPEID,MINDES AS Doc,NBRDOCUMENT as Numero,DATEPROCESALES as Fech_Emision, " & _
            " DUEDATE as Fech_Venc,TOTALPEN AS Monto_PEN,TOTALUSD AS Monto_USD,DOCVALPEN as Saldo_PEN,DOCVALUSD as Saldo_USD,PAGOPEN as Monto_Pagar,custidss " & _
            " FROM TMP_AR_COBRANZAS JOIN DOCTYPE ON TMP_AR_COBRANZAS.DOCTYPEID=DOCTYPE.DOCTYPEID" & _
            " WHERE CORRNBR='" & lngCORRNBR & "'"
            
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   Set SeleccionaEnTemporal = rs
   'GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   '''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.SeleccionaEnTemporal", Err.Description
    
End Function

Public Function ListarCondicionesPago(Optional VarAux As Variant) As ADODB.Recordset
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " SELECT TYPEPAYMENTID,descr FROM TYPEPAYMENT WHERE SHOW=1 "
            
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   Set ListarCondicionesPago = rs
   'GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   '''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ListarCondicionesPago", Err.Description
    
End Function

Public Function OntenerTotal(ByVal lngCORRNBR As Long, Optional VarAux As Variant) As Double
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " SELECT SUM(PAGOPEN) AS TOTAL FROM TMP_AR_COBRANZAS " & _
            " WHERE CORRNBR='" & lngCORRNBR & "'"
            
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   OntenerTotal = rs!TOTAL
   'GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   '''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.OntenerTotal", Err.Description
    
End Function

Public Function OntenerTotalPago(ByVal dblCORREL As Double, ByVal strSITEID As String, ByVal strCURYID As String, Optional VarAux As Variant) As Double
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
    
   On Error GoTo ErrorHandler
      
      
   StrSql = " OBTIENE_TOTAL_PAGO " & dblCORREL & ",'" & strSITEID & "','" & strCURYID & "'"
            
            
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                    
   OntenerTotalPago = rs!TOTAL
   'GetObjectContext.SetComplete
   
   Exit Function
ErrorHandler:
   If Not rs Is Nothing Then
      Set rs = Nothing
   End If
   '''GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.OntenerTotalPago", Err.Description
    
End Function

Public Function EFECTUAR_PAGO(ByVal lngCORRNBR As Long, ByVal strSITEID As String, ByVal strDOCTYPEIDPAID As String, _
                         ByVal dblNBRDOCUMENTPAID As Double, ByVal strDEPOSITPASSWORD As String, ByVal strCURYTYPEID As String, _
                         ByVal datDATEPROCEPAIDMENT As Date, ByVal datDATEDEPOSIT As Date, ByVal strCURYID As String, ByVal DblMonto As Double, ByVal dblCURYRATE As Double, _
                         ByVal strCUSTIDSS As String, ByVal strTAXREGNBR As String, ByVal strUSERID As String, ByVal DblCorrelativoPago As Double, _
                         ByVal DblMontoOriPenNc As Double, ByVal DblMontoOriUSDNc As Double, ByVal DblMontoSinDeposito As Double, Optional VarAux As Variant) As String
                         
    
    Dim rs As ADODB.Recordset
    Dim con As ADODB.Connection
    Dim StrSql As String

    On Error GoTo TrataError
    
    
    StrSql = " EXEC AR_APLICAR_PAGOS_PROC " & lngCORRNBR & ",'" & strSITEID & "','" & strDOCTYPEIDPAID & "'," & _
                                            dblNBRDOCUMENTPAID & ",'" & strDEPOSITPASSWORD & "','" & strCURYTYPEID & "','" & _
                                            Format(datDATEPROCEPAIDMENT, "DD/MM/YYYY") & "','" & _
                                            Format(datDATEDEPOSIT, "DD/MM/YYYY") & "','" & _
                                            strCURYID & "'," & DblMonto & "," & dblCURYRATE & ",'" & _
                                            strCUSTIDSS & "','" & strTAXREGNBR & "','" & strUSERID & "'," & DblCorrelativoPago & "," & _
                                            DblMontoOriPenNc & "," & DblMontoOriUSDNc & "," & DblMontoSinDeposito
                                        
                                                
    
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, con, adOpenStatic
    
    EFECTUAR_PAGO = rs!CORRELATIVO
    
    '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_AR_CUENTASCOBRAR.EFECTUAR_PAGO", LStrMensajeError
    
End Function

Public Function ListarDatosClientes(ByVal strCUSTIDSS As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = " SELECT CURYID,TAXREGNBR FROM CUSTOMER WHERE CUSTIDSS='" & strCUSTIDSS & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarDatosClientes = rs
    
    'GetObjectContext.SetComplete
    
    Exit Function
    
TrataError:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    '''GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ListarClientesAyudaTPC", Err.Description

End Function


Public Function ListarPagos(ByVal strSITEID As String, ByVal strCUSTIDSS As String, ByVal datFECHAINI As Date, ByVal datFECHAFIN As Date, _
                                   ByVal bytAlmacen As Byte, ByVal bytCliente 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 bytCliente = 1 Then 'TODOS LOS ALMACENES
        StrSql = " SELECT SITEID as Almacen,BATNBRAR_CCDOCDET as Nro_Pago,AR_CCDOCDET.DOCTYPEID,MINDES AS Doc,NBRDOCUMENT as Nro_Doc, " & _
                 " DEPOSITPASSWORD as Nro_Deposito,DATEPROCEPAIDMENT as Fech_Proceso,AR_CCDOCDET.CUSTIDSS,CUSTNAME AS Cliente, " & _
                 " CASE DOCSTATUSID WHEN 'OK' THEN 'PROCESADO' WHEN 'AN' THEN 'ANULADO'  END as Estado " & _
                 " FROM (AR_CCDOCDET JOIN DOCTYPE " & _
                 " ON AR_CCDOCDET.DOCTYPEID=DOCTYPE.DOCTYPEID) JOIN CUSTOMER " & _
                 " ON AR_CCDOCDET.CUSTIDSS=CUSTOMER.CUSTIDSS " & _
                 " WHERE DATEPROCEPAIDMENT>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCEPAIDMENT<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' ORDER BY BATNBRAR_CCDOCDET "
    End If
    
    If bytAlmacen = 1 And bytCliente = 0 Then 'TODOS LOS ALMACENES
        StrSql = " SELECT SITEID as Almacen,BATNBRAR_CCDOCDET as Nro_Pago,AR_CCDOCDET.DOCTYPEID,MINDES AS Doc,NBRDOCUMENT as Nro_Doc, " & _
                 " DEPOSITPASSWORD as Nro_Deposito,DATEPROCEPAIDMENT as Fech_Proceso,AR_CCDOCDET.CUSTIDSS,CUSTNAME AS Cliente, " & _
                 " CASE DOCSTATUSID WHEN 'OK' THEN 'PROCESADO' WHEN 'AN' THEN 'ANULADO'  END as Estado " & _
                 " FROM (AR_CCDOCDET JOIN DOCTYPE " & _
                 " ON AR_CCDOCDET.DOCTYPEID=DOCTYPE.DOCTYPEID) JOIN CUSTOMER " & _
                 " ON AR_CCDOCDET.CUSTIDSS=CUSTOMER.CUSTIDSS " & _
                 " WHERE DATEPROCEPAIDMENT>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCEPAIDMENT<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND AR_CCDOCDET.CUSTIDSS='" & strCUSTIDSS & "' ORDER BY BATNBRAR_CCDOCDET "
    End If
    
    If bytAlmacen = 0 And bytCliente = 1 Then 'TODOS LOS ALMACENES
        StrSql = " SELECT SITEID as Almacen,BATNBRAR_CCDOCDET as Nro_Pago,AR_CCDOCDET.DOCTYPEID,MINDES AS Doc,NBRDOCUMENT as Nro_Doc, " & _
                 " DEPOSITPASSWORD as Nro_Deposito,DATEPROCEPAIDMENT as Fech_Proceso,AR_CCDOCDET.CUSTIDSS,CUSTNAME AS Cliente, " & _
                 " CASE DOCSTATUSID WHEN 'OK' THEN 'PROCESADO' WHEN 'AN' THEN 'ANULADO'  END as Estado " & _
                 " FROM (AR_CCDOCDET JOIN DOCTYPE " & _
                 " ON AR_CCDOCDET.DOCTYPEID=DOCTYPE.DOCTYPEID) JOIN CUSTOMER " & _
                 " ON AR_CCDOCDET.CUSTIDSS=CUSTOMER.CUSTIDSS " & _
                 " WHERE DATEPROCEPAIDMENT>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCEPAIDMENT<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND SITEID='" & strSITEID & "' ORDER BY BATNBRAR_CCDOCDET "
    End If

    If bytAlmacen = 0 And bytCliente = 0 Then 'TODOS LOS ALMACENES
        StrSql = " SELECT SITEID as Almacen,BATNBRAR_CCDOCDET as Nro_Pago,AR_CCDOCDET.DOCTYPEID,MINDES AS Doc,NBRDOCUMENT as Nro_Doc, " & _
                 " DEPOSITPASSWORD as Nro_Deposito,DATEPROCEPAIDMENT as Fech_Proceso,AR_CCDOCDET.CUSTIDSS,CUSTNAME AS Cliente, " & _
                 " CASE DOCSTATUSID WHEN 'OK' THEN 'PROCESADO' WHEN 'AN' THEN 'ANULADO'  END as Estado " & _
                 " FROM (AR_CCDOCDET JOIN DOCTYPE " & _
                 " ON AR_CCDOCDET.DOCTYPEID=DOCTYPE.DOCTYPEID) JOIN CUSTOMER " & _
                 " ON AR_CCDOCDET.CUSTIDSS=CUSTOMER.CUSTIDSS " & _
                 " WHERE DATEPROCEPAIDMENT>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND DATEPROCEPAIDMENT<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND SITEID='" & strSITEID & "' AND AR_CCDOCDET.CUSTIDSS='" & strCUSTIDSS & "' ORDER BY BATNBRAR_CCDOCDET "
    End If

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

    '''GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ListarPagos", 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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.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_AR_CUENTASCOBRAR.C_CANCELACION.Auxiliar10", Err.Description
End Function




