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_COBRANZAS"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Public Function EliminarTmpCtacte(ByVal DblCorrelativo As Double, Optional VarAux As Variant)

     Dim cmd As ADODB.Command
     Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = " Ar_EliminarTemporalesCtaCte " & DblCorrelativo
          
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_AR_CUENTASCOBRAR.EliminarTmpCtacte", Err.Description

End Function

Public Function GrabarResumenenTmp_Ar_resumen(ByVal DblCorrelativo As Double, ByVal IntFormato As Integer, _
                                              ByVal StrMoneda As String, ByVal StrUsuario As String, Optional VarAux As Variant)

     Dim cmd As ADODB.Command
     Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = " Ar_GrabarResumenenTmp_Ar_Resumen " & DblCorrelativo & "," & IntFormato & ",'" & StrMoneda & "','" & StrUsuario & "'"
     
     
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_AR_CUENTASCOBRAR.GrabarResumenenTmp_Ar_resumen", Err.Description

End Function

Public Function GrabarDatosCtaCteenTemporal(ByVal StrCara As String, ByVal DblCorrelativo As Double, _
                                            ByVal IntNumeroDocumento As Integer, ByVal StrCodigoArticulo As String, _
                                            ByVal StrCodigoMoneda As String, ByVal IntCierreZ As Integer, _
                                            ByVal IntCierreX As Integer, ByVal IntNumeroTurno As Integer, _
                                            ByVal StrNumeroTransacion As String, ByVal DblDescuento1 As Double, ByVal DblDescuento2 As Double, _
                                            ByVal DblDesMonBase As Double, ByVal DblDesMonExtranjera As Double, ByVal DBlPorcentajeIgv As Double, _
                                            ByVal DBlPorcentajeISC As Double, ByVal DblTotalBase As Double, ByVal DblTotalExt As Double, _
                                            ByVal MontoImpuestoBase As Double, ByVal MontoImpuestoExt As Double, ByVal IntInventariable As Integer, _
                                            ByVal IntTomadeInventario As Integer, ByVal DblPrecioVenta As Double, ByVal DblPrecioFactu As Double, _
                                            ByVal DblCostoBase As Double, ByVal DblCostoExt As Double, _
                                            ByVal StrCodigoBarra As String, ByVal StrDescripcion As String, ByVal DblCantidad As Double, _
                                            ByVal strUSERID As String, ByVal IntKit As Integer, ByVal IntCombustible As Integer, ByVal StrPtoVta As String, ByVal StrUnidadMedida As String, Optional VarAux As Variant)
                                            
     Dim cmd As ADODB.Command
     Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = " Ar_EmitirDocumentoCtacteProc " & StrCara & "'," & DblCorrelativo & "," & IntNumeroDocumento & ",'" & _
                                                          StrCodigoArticulo & "','" & StrCodigoMoneda & "'," & IntCierreZ & "," & _
                                                          IntCierreX & "," & IntNumeroTurno & ",'" & StrNumeroTransacion & "'," & DblDescuento1 & "," & _
                                                          DblDescuento2 & "," & DblDesMonBase & "," & DblDesMonExtranjera & "," & DBlPorcentajeIgv & "," & _
                                                          DBlPorcentajeISC & "," & DblTotalBase & "," & DblTotalExt & "," & MontoImpuestoBase & "," & _
                                                          MontoImpuestoExt & "," & IntInventariable & "," & IntTomadeInventario & "," & DblPrecioVenta & "," & _
                                                          DblPrecioFactu & "," & DblCostoBase & "," & DblCostoExt & ",'" & StrCodigoBarra & "','" & StrDescripcion & "'," & DblCantidad & ",'" & _
                                                          strUSERID & "'," & IntKit & "," & IntCombustible & ",'" & StrPtoVta & "','" & StrUnidadMedida & "'"

     
     
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_AR_CUENTASCOBRAR.GrabarDatosCtaCteenTemporal", Err.Description
 
End Function

Public Function GenerarDocumentosCtaCte(ByVal IntTodosSeleccion As Integer, ByVal IntFactura As Integer, ByVal IntNcredito As Integer, _
                                        ByVal IntNseriesFac As String, ByVal IntNDocuFac As String, ByVal IntNseriesNc As String, _
                                        ByVal IntIntNDocuFac As String, _
                                        ByVal IntContadoCred As Integer, ByVal DblCorrelativo As Double, _
                                        ByVal StrCodigoMoneda As String, ByVal StrcodigoVendedor As String, ByVal StrCodigoUsuario As String, _
                                        ByVal StrImpuesto1 As String, ByVal StrImpuesto2 As String, ByVal DblTotalMonBase As Double, ByVal DblTotalMonExt As Double, _
                                        ByVal DblSubTotMonBase As Double, ByVal DblSubTotMonExt As Double, ByVal DblMontoImp1MonBase As Double, ByVal DblMontoImp1MonExt As Double, _
                                        ByVal DblMontoImp2MonBase As Double, ByVal DblMontoImp2MonExt As Double, ByVal DblTotNoAfecMonBase As Double, ByVal DblTotNoAfecMonExt As Double, _
                                        ByVal DblPorcendscto1 As Double, ByVal DblPorcendscto2 As Double, DblTotaDescMonBase As Double, ByVal DblTotaDescMonExt As Double, ByVal DblVueltoMonBase As Double, ByVal DblVueltoMonExt As Double, _
                                        ByVal DblTotEfectivoMonBase As Double, ByVal DblTotEfectivoMonExt As Double, ByVal StrCodigoCliente As String, ByVal StrRuc As String, ByVal StrNombre As String, _
                                        ByVal StrPlaca As String, ByVal StrTipodeCambio As String, ByVal DblMontoTipoCambio As Double, ByVal IntCierreZ As Integer, ByVal IntCierreX As Integer, ByVal StrPromoCard As String, _
                                        ByVal IntPuntosTransacc As Integer, ByVal StrPuntoVenta As String, ByVal Strterminal As String, ByVal IntKilometraje As Double, ByVal StrDireccion As String, ByVal StrCodigoTarjeta As String, ByVal StrNumeroTarjeta As String, _
                                        ByVal StrCodMonedaTarjeta As String, ByVal StrDescripcionTarjeta As String, Optional VarAux As Variant)
 
     Dim cmd As ADODB.Command
     Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
     
     cmd.CommandText = " Ar_EmitirDocumentoCtacteProc " & IntTodosSeleccion & "," & IntFactura & "," & IntNcredito & ",'" & _
                                                          IntNseriesFac & "','" & IntNDocuFac & "','" & IntNseriesNc & "','" & _
                                                          IntIntNDocuFac & "'," & IntContadoCred & "," & DblCorrelativo & ",'" & _
                                                          StrCodigoMoneda & "','" & StrcodigoVendedor & "','" & StrCodigoUsuario & "','" & _
                                                          StrImpuesto1 & "','" & StrImpuesto2 & "'," & DblTotalMonBase & "," & DblTotalMonExt & "," & _
                                                          DblSubTotMonBase & "," & DblSubTotMonExt & "," & DblMontoImp1MonBase & "," & DblMontoImp1MonExt & "," & _
                                                          DblMontoImp2MonBase & "," & DblMontoImp2MonExt & "," & DblTotNoAfecMonBase & "," & DblTotNoAfecMonExt & "," & _
                                                          DblPorcendscto1 & "," & DblPorcendscto2 & "," & DblTotaDescMonBase & "," & DblTotaDescMonExt & "," & DblVueltoMonBase & "," & _
                                                          DblVueltoMonExt & "," & DblTotEfectivoMonBase & "," & DblTotEfectivoMonExt & ",'" & StrCodigoCliente & "','" & _
                                                          StrRuc & "','" & StrNombre & "','" & StrPlaca & "','" & StrTipodeCambio & "'," & _
                                                          DblMontoTipoCambio & "," & IntCierreZ & "," & IntCierreX & ",'" & StrPromoCard & "'," & _
                                                          IntPuntosTransacc & ",'" & StrPuntoVenta & "','" & Strterminal & "'," & IntKilometraje & ",'" & StrDireccion & "','" & _
                                                          StrCodigoTarjeta & "','" & StrNumeroTarjeta & "','" & StrCodMonedaTarjeta & "','" & StrDescripcionTarjeta & "','" & Format(VarAux(1, 1), "yyyymmdd") & "'"
                                                
                                                                                                
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_AR_CUENTASCOBRAR.GenerarDocumentosCtaCte", Err.Description

End Function

Public Function ObtenerFechaVencimiento(ByVal StrCodCliente As String, ByVal StrTerms As String, _
                                        ByVal DatFechaDocumento As Date, Optional VarAux As Variant) As String
   
   Dim cmd As ADODB.Command
   Dim rs As ADODB.Recordset
   Dim con As ADODB.Connection
   Dim prm As ADODB.Parameter
   Dim StrSql As String
   
   
   On Error GoTo TrataError
   
    StrSql = "AR_Calc_Dias_de_PagoProc '" & StrCodCliente & "','" & StrTerms & "','" & DatFechaDocumento & "'"
             
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
    If Not rs.EOF Then
       ObtenerFechaVencimiento = rs!FechaVencimiento
    End If

    '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 prm Is Nothing Then
        Set prm = 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_INV_TOMADEINVENTARIO.ObtenerFechaVencimiento", LStrMensajeError
     
End Function

Public Function EliminarTmpAlmacenes(ByVal DblCorrNbr As Double, Optional VarAux As Variant)
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = " AR_EliminarTempoAlmacenesProc " & DblCorrNbr
    
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.EliminarTmpAlmacenes", Err.Description


End Function

Public Function EliminarTmpClientes(ByVal DblCorrNbr As Double, Optional VarAux As Variant)
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = "EliminarTempoClientesProc " & DblCorrNbr
    
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.EliminarTmpClientes", Err.Description

End Function

Public Function EliminarTmpDocumentos(ByVal DblCorrNbr As Double, Optional VarAux As Variant)
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = "EliminarTempoDocumentosProc " & DblCorrNbr
    
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.EliminarTmpDocumentos", Err.Description
     
End Function

Public Function GrabarTmpClientes(ByVal DblCorrNbr As Double, ByVal StrCliente As String, Optional VarAux As Variant)
  
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = "GrabarTempoClientesProc " & DblCorrNbr & ",'" & StrCliente & "'"
    
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.GrabarTmpClientes", Err.Description
     
End Function

Public Function GrabarTmpDocumentos(ByVal DblCorrNbr As Double, ByVal StrDocumentos As String, Optional VarAux As Variant)
  
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = "GrabarTempoDocumentosProc " & DblCorrNbr & ",'" & StrDocumentos & "'"
    
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.GrabarTmpDocumentos", Err.Description
     
End Function

Public Function GrabarTmpAlmacenes(ByVal DblCorrNbr As Double, ByVal StrAlmacen As String, Optional VarAux As Variant)
  
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
    
     cmd.CommandText = " AR_GrabarTempoAlmacenesProc " & DblCorrNbr & ",'" & StrAlmacen & "'"
    
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.GrabarTmpAlmacenes", Err.Description
     
End Function
Public Function CargarDatosResumenSeleccion(ByVal DblCorrNbr As Double, ByVal StrCodCliente As String, _
                                            ByVal DatDesde As Date, ByVal DatHasta As Date, ByVal StrMoneda As String, _
                                            ByVal StrTipoCambioCliente As String, ByVal IntRedondeo As Integer, Optional VarAux As Variant)

  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
     cmd.CommandTimeout = 0
     cmd.CommandText = " AR_GrabarsalesdetporSeleccionProc " & DblCorrNbr & ",'" & StrCodCliente & "','" & DatDesde & "','" & _
                                                               DatHasta & "','" & StrMoneda & "','" & StrTipoCambioCliente & "'," & _
                                                               IntRedondeo
     
     
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_AR_CUENTASCOBRAR.CargarDatosResumenSeleccion", Err.Description
     
End Function

Public Function CargarDatosResumen(ByVal DblCorrNbr As Double, ByVal StrCodCliente As String, _
                                   ByVal DatDesde As String, ByVal DatHasta As String, ByVal StrMoneda As String, _
                                   ByVal StrTipoCambioCliente As String, ByVal IntRedondeo As Integer, Optional VarAux As Variant)
  
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
     cmd.CommandTimeout = 0
     cmd.CommandText = " AR_CARGARVENTASPROC " & DblCorrNbr & ",'" & StrCodCliente & "','" & DatDesde & "','" & _
                                                 DatHasta & "','" & StrMoneda & "','" & StrTipoCambioCliente & "'," & _
                                                 IntRedondeo
     
     
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_AR_CUENTASCOBRAR.CargarDatosResumen", Err.Description
     
End Function

Public Function EliminarDatosResumen(ByVal DblCorrNbr As Double, Optional VarAux As Variant)
  
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
     cmd.CommandText = " AR_ELIMINARVENTASPROC " & DblCorrNbr
         
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.CargarDatosResumen", Err.Description
     
End Function

Public Function ObtenerDocumentosCtaCte(ByVal DblCorrelativo As Double, Optional VarAux As Variant) As ADODB.Recordset

   Dim rs As ADODB.Recordset
   Dim StrSql As String
   
   
   On Error GoTo TrataError
   
    StrSql = " Select SITEID,NAME,DOCTYPEID,TIPODOCUMENTO,NBRDOCUMENT," & _
             " DATEPROCESALES,DUEDATE,PLACA,TOTALPEN,TOTALUSD," & _
             " SUBTOTALPEN , SUBTOTALUSD, TAXIGVPEN, TAXIGVUSD," & _
             " TOTALNOTAFFECTPEN, TOTALNOTAFFECTUSD,SELECTED=CASE SELECTED WHEN 1 THEN 'Sí' WHEN 0 THEN 'No' END " & _
             " FROM TMP_AR_SALES where CORRNBR=" & DblCorrelativo
     
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
    Set ObtenerDocumentosCtaCte = 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_TOMADEINVENTARIO.ObtenerDocumentosCtaCte", Err.Description

End Function

Public Function ObtenerValesCtaCte(ByVal DblCorrelativo As Double, ByVal StrCodCliente As String, _
                                   ByVal DatFechaDesde As Date, ByVal DatFechaHasta As Date, Optional VarAux As Variant) As ADODB.Recordset
   
   Dim rs As ADODB.Recordset
   Dim StrSql As String
   
   
   On Error GoTo TrataError

   StrSql = " select SITEID,DOCTYPEID,DATEPROCESALES,NBRDOCUMENT,NBRBONUS from VW_OP_SALESCABONUS " & _
            " WHERE DATEPROCESALES BETWEEN '" & DatFechaDesde & "' AND '" & DatFechaHasta & "'" & _
            " AND custidss='" & StrCodCliente & "' AND SITEID IN " & _
            " (SELECT SITEID FROM TMP_AR_ALMACENES WHERE CORRNBR=" & DblCorrelativo & ")"

    
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
   Set ObtenerValesCtaCte = 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_TOMADEINVENTARIO.ObtenerValesCtaCte", Err.Description

End Function

Public Function ObtenerTotalesResumen(ByVal DblCorrelativo As Double, Optional VarAux As Variant) As ADODB.Recordset
  Dim rs As ADODB.Recordset
  Dim StrSql As String
    
  On Error GoTo TrataError
  
  StrSql = " Select sum(TOTALPEN) AS SUMTOTALPEN,sum(TOTALUSD) AS SUMTOTALUSD, " & _
           " sum(TAXPEN) AS SUMTAXPEN,sum(TAXUSD) AS SUMTAXUSD " & _
           " from tmp_ar_salesdet where CORRNBR =" & DblCorrelativo
                         
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
  Set ObtenerTotalesResumen = 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.ObtenerTotalesResumen", Err.Description
        
End Function

Public Function ObtenerTotalesGenerales(ByVal DblCorrelativo As Double, Optional VarAux As Variant) As ADODB.Recordset

   Dim rs As ADODB.Recordset
   Dim StrSql As String
   
   
   On Error GoTo TrataError

   StrSql = " select sum(TOTALPEN) as SUMTOTALPEN,sum(TOTALUSD) as SUMTOTALUSD, " & _
            " sum(SUBTOTALPEN) as SUMSUBTOTALPEN,sum(SUBTOTALUSD) as SUMSUBTOTALUSD, " & _
            " sum(TAXIGVPEN) as SUMTAXIGVPEN,sum(TAXIGVUSD) as SUMTAXIGVUSD, " & _
            " sum(TOTALNOTAFFECTPEN) as SUMTOTALNOTAFFECTPEN,SUM(TOTALNOTAFFECTUSD) as SUMTOTALNOTAFFECTUSD " & _
            " from tmp_ar_sales where CORRNBR=" & DblCorrelativo


   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
   Set ObtenerTotalesGenerales = 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_TOMADEINVENTARIO.ObtenerTotalesGenerales", Err.Description
     
End Function

Public Function ObtenerTotales(ByVal DblCorrelativo As Double, Optional VarAux As Variant) As ADODB.Recordset

   Dim rs As ADODB.Recordset
   Dim StrSql As String
   
   
   On Error GoTo TrataError

   StrSql = " select sum(TOTALPEN) as SUMTOTALPEN,sum(TOTALUSD) as SUMTOTALUSD, " & _
            " sum(SUBTOTALPEN) as SUMSUBTOTALPEN,sum(SUBTOTALUSD) as SUMSUBTOTALUSD, " & _
            " sum(TAXIGVPEN) as SUMTAXIGVPEN,sum(TAXIGVUSD) as SUMTAXIGVUSD, " & _
            " sum(TOTALNOTAFFECTPEN) as SUMTOTALNOTAFFECTPEN,SUM(TOTALNOTAFFECTUSD) as SUMTOTALNOTAFFECTUSD " & _
            " from tmp_ar_sales where CORRNBR=" & DblCorrelativo & " and selected=1"


   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
   Set ObtenerTotales = 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_TOMADEINVENTARIO.ObtenerValesCtaCte", Err.Description
     
End Function

Public Function ObtenerDetalleDocumentCtaCte(ByVal DblCorrelativo As Double, ByVal StrCodCliente As String, _
                                             ByVal DatFechaDesde As String, ByVal DatFechaHasta As String, Optional VarAux As Variant) As ADODB.Recordset
     
    Dim rs As ADODB.Recordset
    Dim StrSql As String
   
   
    On Error GoTo TrataError
    
    StrSql = " Select SITEID,DOCTYPEID,NBRDOCUMENT,TYPEPAYMENTID,INVTIDSKU,DESCR from VW_OP_SALESCABDET " & _
             " WHERE DATEPROCESALES BETWEEN '" & DatFechaDesde & "' AND '" & DatFechaHasta & "'" & _
             " AND custidss='" & StrCodCliente & "' AND SITEID IN " & _
             " (SELECT SITEID FROM TMP_AR_ALMACENES WHERE CORRNBR=" & DblCorrelativo & ")"
             
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
    Set ObtenerDetalleDocumentCtaCte = 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_TOMADEINVENTARIO.ObtenerDetalleDocumentCtaCte", Err.Description
      
End Function

Public Function ObtenerResumendeArticulos(DblCorrelativo As Double, Optional VarAux As Variant) As ADODB.Recordset
  Dim rs As ADODB.Recordset
  Dim StrSql As String
        
  On Error GoTo TrataError
   
  StrSql = " select siteid,[name],INVTIDSKU,DESCR, " & _
           " QTY,SLSPRICESALE,TOTALPEN,TOTALUSD, " & _
           " TAXPEN,TAXUSD  from tmp_ar_salesdet where CORRNBR =" & DblCorrelativo
     
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
  Set ObtenerResumendeArticulos = 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.ObtenerResumendeArticulos", Err.Description
        
End Function

Public Function ObtenerArticulosCtaCte(DblCorrelativo As Double, Optional VarAux As Variant) As ADODB.Recordset

   Dim rs As ADODB.Recordset
   Dim StrSql As String
   
   
   On Error GoTo TrataError
   
   StrSql = " select SITEID,INVTIDSKU,DESCR,QTY,SLSPRICESALE, " & _
            " TOTALPEN , TOTALUSD, TAXPEN, TAXUSD " & _
            " FROM TMP_AR_SALESDET where CORRNBR=" & DblCorrelativo
     
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
    Set ObtenerArticulosCtaCte = 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_TOMADEINVENTARIO.ObtenerArticulosCtaCte", Err.Description

End Function

Public Function ActualizarPrecioPromedio(ByVal DblCorrNbr As Double, ByVal StrMoneda As String, _
                                         ByVal IntRedondeo As Integer, Optional VarAux As Variant)
    Dim cmd As ADODB.Command
    Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
     cmd.CommandText = " Ar_Actualizar_PrecioPromProc " & DblCorrNbr & ",'" & StrMoneda & "'," & _
                                                         IntRedondeo
          
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_AR_CUENTASCOBRAR.ActualizarPrecios", Err.Description
    
End Function


Public Function ActualizarPrecios(ByVal DblCorrNbr As Double, ByVal StrMoneda As String, _
                                  ByVal StrAlmacen As String, ByVal StrArticulo As String, _
                                  ByVal DblPrecio As Double, ByVal StrTipodeCmabio As String, _
                                  ByVal StrCodCliente As String, Optional VarAux As Variant)
  
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
     cmd.CommandText = " Ar_Actualizar_PrecioProc " & DblCorrNbr & ",'" & StrMoneda & "','" & StrAlmacen & "','" & _
                                                      StrArticulo & "'," & DblPrecio & ",'" & StrTipodeCmabio & "','" & _
                                                      StrCodCliente & "'"
     
     
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.ActualizarPrecios", Err.Description
     
End Function

Public Function ActualizarSeleccion(ByVal DblCorrNbr As Double, ByVal StrTipoDocumento As String, _
                                    ByVal StrAlmacen As String, ByVal DblNumeroDocumento As Double, _
                                    ByVal IntSelected As Integer, Optional VarAux As Variant)
  
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
     cmd.CommandText = " AR_ActualizaSelectedProc " & DblCorrNbr & ",'" & StrTipoDocumento & "','" & StrAlmacen & "'," & _
                                                      DblNumeroDocumento & "," & IntSelected
     
     
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_ARTICULO.ActualizarSeleccion", Err.Description
     
End Function
 
Public Function ObtenerPrecioTpcArticulo(ByVal StrAlmacen As String, _
                                         ByVal StrArticulo As String, _
                                         ByVal StrCliente As String, Optional VarAux As Variant) As ADODB.Recordset

   Dim rs As ADODB.Recordset
   Dim StrSql As String
   
   
   On Error GoTo TrataError
   
   StrSql = " SELECT dbo.OP_CUSTOMER_PRCLVL.custidss,dbo.OP_PRCLVLCUST.PRCLVLCUSTID, " & _
            " dbo.OP_PRCLVLCUST.SITEID,dbo.OP_PRCLVLCUSTDET.INVTIDSKU,dbo.OP_PRCLVLCUSTDET.SLS_PRICECUST, " & _
            " dbo.OP_PRCLVLCUST.CURYID , dbo.OP_PRCLVLCUSTDET.SLS_PRICE " & _
            " From dbo.OP_CUSTOMER_PRCLVL " & _
            " INNER JOIN dbo.OP_PRCLVLCUST " & _
            " ON dbo.OP_CUSTOMER_PRCLVL.PRCLVLCUSTID = dbo.OP_PRCLVLCUST.PRCLVLCUSTID " & _
            " INNER JOIN  dbo.OP_PRCLVLCUSTDET " & _
            " ON dbo.OP_PRCLVLCUST.PRCLVLCUSTID = dbo.OP_PRCLVLCUSTDET.PRCLVLCUSTID AND " & _
            " dbo.OP_PRCLVLCUST.SITEID = dbo.OP_PRCLVLCUSTDET.SITEID " & _
            " WHERE STATUS=1 AND dbo.OP_PRCLVLCUST.SITEID='" & StrAlmacen & "' AND " & _
            " INVTIDSKU='" & StrArticulo & "' AND dbo.OP_CUSTOMER_PRCLVL.custidss='" & _
              StrCliente & "'"
     
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
    Set ObtenerPrecioTpcArticulo = 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.ObtenerPrecioTpcArticulo", Err.Description

End Function


Public Function BuscarDocumentos(ByVal strSITEID As String, ByVal datFECHAINI As Date, ByVal datFECHAFIN As Date, _
                                   ByVal bytAlmacen 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 Then  'TODOS LOS ALMACENES
        StrSql = " SELECT S.SITEID as Almacen,S.DOCTYPEID,D.MINDES as Doc,S.NBRDOCUMENT as Nro,S.TYPEPAYMENTID as Pago,S.DATEDOC as Fech_Docu,S.DATEPROCESALES as Fecha_Proc,S.DOCSTATUSID as Estado " & _
                 " FROM OP_SALES AS S JOIN DOCTYPE AS D " & _
                 " ON S.DOCTYPEID=D.DOCTYPEID " & _
                 " WHERE S.DATEPROCESALES>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND S.DATEPROCESALES<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' and " & _
                 " (TYPEPAYMENTID='10' or TYPEPAYMENTID='11') "
    Else
        
        StrSql = " SELECT S.SITEID as Almacen,S.DOCTYPEID,D.MINDES as Doc,S.NBRDOCUMENT as Nro,S.TYPEPAYMENTID as Pago,S.DATEDOC as Fech_Docu,S.DATEPROCESALES as Fecha_Proc,S.DOCSTATUSID as Estado " & _
                 " FROM OP_SALES AS S JOIN DOCTYPE AS D " & _
                 " ON S.DOCTYPEID=D.DOCTYPEID " & _
                 " WHERE S.DATEPROCESALES>='" & Format(datFECHAINI, "DD/MM/YYYY") & "' AND S.DATEPROCESALES<='" & Format(datFECHAFIN, "DD/MM/YYYY") & "' AND S.SITEID='" & strSITEID & "' and " & _
                 " (TYPEPAYMENTID='10' or TYPEPAYMENTID='11')"
    End If


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

End Function

Public Function ListarCabDocumento(ByVal strSITEID As String, ByVal strDOCTYPEID As String, ByVal dblNRODOCU As Double, Optional VarAux As Variant) As ADODB.Recordset
                               
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
        
    StrSql = " SELECT * " & _
             " FROM OP_SALES " & _
             " WHERE SITEID='" & strSITEID & "' AND DOCTYPEID='" & strDOCTYPEID & "' AND NBRDOCUMENT=" & dblNRODOCU

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

End Function
   
Public Function ListarDocumento(ByVal StrAlmacen As String, StrTipoDocumento As String, DblNumeroDocumento As Double, Optional VarAux As Variant) As ADODB.Recordset

    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
        
    StrSql = " SELECT OP_SALES.NBRDOCUMENT, OP_SALES.DATEDOC,OP_SALES.DATEPROCESALES,OP_SALES.CURYID, " & _
             " OP_SALES.PLACA,OP_SALES.custidss,OP_SALES.TOTALPEN,OP_SALES.TOTALUSD,OP_SALES.SUBTOTALPEN," & _
             " OP_SALES.SUBTOTALUSD,OP_SALES.TAXIGVPEN,OP_SALES.TAXIGVUSD,OP_SALES.TOTALNOTAFFECTPEN," & _
             " OP_SALES.TOTALNOTAFFECTUSD,OP_SALESDET.SEQUENCE,OP_SALESDET.INVTIDSKU,IN_INVENTORY.DESCR,OP_SALESDET.SLSPRICESALE, " & _
             " OP_SALESDET.QTY, OP_SALESDET.TOTALPEN AS TOTALPENDET,OP_SALESDET.TOTALUSD AS TOTALUSDDET," & _
             " OP_SALESDET.TAXPEN, dbo.OP_SALESDET.TAXUSD," & _
             " CUSTOMER.CUSTNAME,dbo.CUSTOMER.taxregnbr,CURRENCY.DESCR AS DESRCMONEDA,op_sales.DOCSTATUSID " & _
             " FROM (OP_SALES INNER JOIN OP_SALESDET ON OP_SALES.DOCTYPEID = OP_SALESDET.DOCTYPEID AND " & _
             " OP_SALES.NBRDOCUMENT = OP_SALESDET.NBRDOCUMENT AND " & _
             " OP_SALES.SITEID = OP_SALESDET.SITEID) INNER JOIN CURRENCY ON OP_SALES.CURYID=CURRENCY.CURYID " & _
             " INNER JOIN IN_INVENTORY ON OP_SALESDET.INVTIDSKU = dbo.IN_INVENTORY.INVTIDSKU " & _
             " Inner Join SITE ON OP_SALES.SITEID = SITE.SITEID INNER JOIN DOCTYPE ON " & _
             " OP_SALES.DOCTYPEID = DOCTYPE.DOCTYPEID INNER Join CUSTOMER ON OP_SALES.custidss = CUSTOMER.custidss " & _
             " WHERE (dbo.OP_SALES.SITEID = '" & StrAlmacen & "') AND " & _
             " (OP_SALES.DOCTYPEID = '" & StrTipoDocumento & "') AND (dbo.OP_SALES.NBRDOCUMENT = " & DblNumeroDocumento & ") AND " & _
             " (dbo.OP_SALES.TYPEPAYMENTID = '10' OR dbo.OP_SALES.TYPEPAYMENTID = '11') " & _
             " GROUP BY OP_SALES.NBRDOCUMENT, OP_SALES.DATEDOC,OP_SALES.DATEPROCESALES,OP_SALES.CURYID, " & _
             " OP_SALES.PLACA,OP_SALES.custidss,OP_SALES.TOTALPEN,OP_SALES.TOTALUSD,OP_SALES.SUBTOTALPEN," & _
             " OP_SALES.SUBTOTALUSD,OP_SALES.TAXIGVPEN,OP_SALES.TAXIGVUSD,OP_SALES.TOTALNOTAFFECTPEN," & _
             " OP_SALES.TOTALNOTAFFECTUSD,OP_SALESDET.SEQUENCE,OP_SALESDET.INVTIDSKU,IN_INVENTORY.DESCR,OP_SALESDET.SLSPRICESALE, " & _
             " OP_SALESDET.QTY, OP_SALESDET.TOTALPEN,OP_SALESDET.TOTALUSD," & _
             " OP_SALESDET.TAXPEN, dbo.OP_SALESDET.TAXUSD," & _
             " CUSTOMER.CUSTNAME,dbo.CUSTOMER.taxregnbr,CURRENCY.DESCR,op_sales.DOCSTATUSID "
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarDocumento = 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.ListarDocumento", Err.Description
End Function
   
Public Function ValidarFechaVencimiento(ByVal DblCorrNbr As Double, ByVal IntSeleccion As Integer, Optional VarAux As Variant) As Integer
    
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
        
    StrSql = " SELECT duedate FROM TMP_AR_SALES where TMP_AR_SALES.SELECTED=" & IntSeleccion & " and corrnbr=" & DblCorrNbr & _
             " group by duedate "



    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    If rs.EOF Then
       ValidarFechaVencimiento = 0
    Else
      If rs.RecordCount = 1 Then
         ValidarFechaVencimiento = 1
      Else
        If rs.RecordCount > 1 Then
           ValidarFechaVencimiento = 2
        End If
      End If
    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.ValidarFechaVencimiento", Err.Description

End Function
   
Public Function ListarDetDocumento(ByVal strSITEID As String, ByVal strDOCTYPEID As String, ByVal dblNRODOCU As Double, Optional VarAux As Variant) As ADODB.Recordset
                               
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
        
    StrSql = " SELECT S.SEQUENCE AS Item,S.INVTIDSKU as Codigo,I.DESCR AS Descripcion,S.QTY AS Cantidad,S.STDCOSTPEN AS CostPEN,S.STDCOSTUSD AS CostUSD " & _
             " FROM OP_SALESDET as S JOIN IN_INVENTORY AS I" & _
             " ON S.INVTIDSKU=I.INVTIDSKU " & _
             " WHERE S.SITEID='" & strSITEID & "' AND S.DOCTYPEID='" & strDOCTYPEID & "' AND S.NBRDOCUMENT=" & dblNRODOCU & " ORDER BY S.SEQUENCE "

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

End Function

Public Function AnularDocumentosCtaCte(ByVal StrTipoDocumento As String, ByVal DblNumeroDocumento As Double, _
                                       ByVal StrAlmacen As String, Optional VarAux As Variant)
  
  Dim cmd As ADODB.Command
  Dim con As ADODB.Connection
     
     On Error GoTo ErrorHandler
     
     Set cmd = New ADODB.Command
     cmd.CommandText = " Ar_AnularDocumentoCtacteProc '" & StrTipoDocumento & _
                                                       "'," & DblNumeroDocumento & ",'" & StrAlmacen & "'"
                                                               
     Set con = New ADODB.Connection
     con.Open "FILEDSN=Conexionsies"
    
     Set cmd.ActiveConnection = con
     cmd.Execute
    
     'GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     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_AR_CUENTASCOBRAR.AnularDocumentosCtaCte", Err.Description
     
End Function

Public Function ListarDocumentosCredito(Optional VarAux As Variant) As ADODB.Recordset
                               
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
        
    StrSql = "  Select DOCTYPEID,DESCR from doctype where DOCTYPEID in " & _
             " (Select DOCTYPEIDNC from op_setup union all " & _
             "  Select DOCTYPEIDFAC from op_setup) "
             
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarDocumentosCredito = 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.ListarDocumentosCredito", Err.Description

End Function


Public Function Auxiliar1(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    
    StrSql = " VALIDA_MES_CERRADO_PROC '" & VarAux1(1, 1) & "','" & Format(VarAux1(1, 2), "DD/MM/YYYY") & "'"
        
    Set rs = New Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
            
  
    Set Auxiliar1 = 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.C_COBRANZAS.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_COBRANZAS.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_COBRANZAS.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_COBRANZAS.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_COBRANZAS.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_COBRANZAS.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_COBRANZAS.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_COBRANZAS.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_COBRANZAS.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_COBRANZAS.Auxiliar10", Err.Description
End Function



