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_VENTASGENERAL"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Public Function Verificar_MontoConsumoVale(ByVal DblVale As Double, ByVal StrStatusBonus As String, _
                                           Optional VarAux As Variant) As Double
     Dim rs As ADODB.Recordset
     Dim cmd As ADODB.Command
     Dim StrSql As String
      
     On Error GoTo errhandler
       
     StrSql = "OP_Verificar_ConsumoVale " & DblVale & ", '" & StrStatusBonus & "' "
       
     Set rs = New ADODB.Recordset
     rs.CursorLocation = adUseClient
     rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
       
     If rs.EOF Then
        Verificar_MontoConsumoVale = 0
     Else
        Verificar_MontoConsumoVale = rs.Fields("MONTOBONUS")
     End If
     ''GetObjectContext.SetComplete
     Exit Function
errhandler:
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
        
     GetObjectContext.SetAbort
      
     Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASPLAYA.Verificar_MontoConsumoVale", Err.Description
End Function
Public Function Verificar_ConsumoVale(ByVal DblVale As Double, ByVal StrStatusBonus As String, _
                                      Optional VarAux As Variant) As Boolean
 Dim rs As ADODB.Recordset
 Dim cmd As ADODB.Command
 Dim StrSql As String
  
 On Error GoTo errhandler
   
 StrSql = "OP_Verificar_ConsumoVale " & DblVale & ", '" & StrStatusBonus & "' "
   
 Set rs = New ADODB.Recordset
 rs.CursorLocation = adUseClient
 rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
   
 If rs.EOF Then
    Verificar_ConsumoVale = False
 Else
    Verificar_ConsumoVale = True
 End If
 ''GetObjectContext.SetComplete
 Exit Function
errhandler:
    If Not rs Is Nothing Then
       Set rs = Nothing
    End If
    
    GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASPLAYA.Verificar_ConsumoVale", Err.Description
  
End Function

Public Function VerificarClienteconPlaca(ByVal strcodcliente As String, Optional VarAux As Variant) As Boolean
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "select CUSTIDSS,BADGE from op_custbadge where CUSTIDSS='" & strcodcliente & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   If rs.EOF Then
      VerificarClienteconPlaca = False
   Else
      VerificarClienteconPlaca = True
   End If
        
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.VerificarClienteconPlaca", Err.Description
End Function

Public Function Listarproductosventas(ByVal StrSITEID As String, bolsolotienda As Boolean, Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    
    If bolsolotienda Then
       StrSql = " select * from vw_productosventas where stkstore=1 and siteid= '" & StrSITEID & "'"
    Else
       StrSql = " select * from vw_productosventas where stkstore=0 and siteid= '" & StrSITEID & "'"
    End If
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    Set Listarproductosventas = 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_FACTURACION.ListarProductosventas", Err.Description

End Function
Public Function ListarClientesAyuda(Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = " SELECT CUSTIDSS,CUSTNAME,TAXREGNBR,ADDR1 FROM CUSTOMER order by CUSTNAME"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarClientesAyuda = 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_FACTURACION.ListarClientesAyuda", Err.Description

End Function

Public Function ListarClientesCtacteAyuda(ByVal IntTodos As Integer, Optional ByVal StrRucCliente As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    If IntTodos = 1 Then
       StrSql = " SELECT CUSTIDSS,CUSTNAME,TAXREGNBR,ADDR1,CUSTCLASSID,TERMIDSUM,CURYTYPEID,CURYID FROM CUSTOMER " & _
                " where CUSTCLASSID in ('01','02','03') " & _
                " order by CUSTNAME "
    Else
       StrSql = " SELECT CUSTIDSS,CUSTNAME,TAXREGNBR,ADDR1,CUSTCLASSID,TERMIDSUM,CURYTYPEID,CURYID FROM CUSTOMER " & _
                " where CUSTCLASSID in ('01','02','03') and TAXREGNBR='" & StrRucCliente & "'"
                
    End If
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarClientesCtacteAyuda = 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_FACTURACION.ListarClientesCtacteAyuda", Err.Description

End Function

Public Function ListarDatosdeClienteFactura(ByVal StrCodigoCliente As String, Optional VarAux As Variant) As ADODB.Recordset
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " Op_ObtenerDatosdelClienteProc '" & StrCodigoCliente & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ListarDatosdeClienteFactura = rs
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.ListarDatosdeClienteFactura", Err.Description
End Function

Public Function ConvertirMoneda(ByVal DblMontoOriginal As Double, ByVal StrMonedaOrigen As String, _
                                ByVal StrMonedaDestino As String, ByVal StrFechaProceso As String, _
                                ByVal StrTipodeCambio As String, ByVal IntRedondeo As Integer, Optional VarAux As Variant) As Double
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   If StrMonedaOrigen = StrMonedaDestino Then
      ConvertirMoneda = DblMontoOriginal
      GoTo ProcesoCulminado
   End If
   
   
   StrSql = "ObtieneTipoCambioGeneralProc " & DblMontoOriginal & ",'" & StrMonedaOrigen & "','" & _
                                              StrMonedaDestino & "','" & StrFechaProceso & "','" & _
                                              StrTipodeCambio & "'," & IntRedondeo
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
            
   If Not rs.EOF Then
     If IsNull(rs!valor) Then
        ConvertirMoneda = 0
     Else
        ConvertirMoneda = rs!valor
     End If
   Else
     ConvertirMoneda = 0
   End If
         
ProcesoCulminado:
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.ConvertirMoneda", Err.Description
End Function
Public Function ObtenerMontoTipodeCambio(ByVal StrMonedaOrigen As String, _
                                         ByVal StrMonedaDestino As String, ByVal StrFechaProceso As Date, _
                                         ByVal StrTipodeCambbio As String, Optional VarAux As Variant) As Double
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   If StrMonedaOrigen = StrMonedaDestino Then
      ObtenerMontoTipodeCambio = 0
      GoTo ProcesoCulminado
   End If
      
   StrSql = "ObtieneMontoTipoCambioGeneralProc '" & StrMonedaOrigen & "','" & _
                                                    StrMonedaDestino & "','" & _
                                                    StrFechaProceso & "','" & _
                                                    StrTipodeCambbio & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
            
   If Not rs.EOF Then
     If IsNull(rs!Rate) Then
        ObtenerMontoTipodeCambio = 0
     Else
        ObtenerMontoTipodeCambio = rs!Rate
     End If
   Else
     ObtenerMontoTipodeCambio = 0
   End If
         
ProcesoCulminado:
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.ObtenerMontoTipodeCambio", Err.Description
End Function
Public Function Validarvendedor(ByVal StrCodigoUsuario As String, ByVal StrPassWord As String, Optional VarAux As Variant) As Integer
       
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
    Validarvendedor = 0  'OK
    
    StrSql = "select SALESPERID,STATUSPERSONID,password from op_salesperson where SALESPERID='" & StrCodigoUsuario & "'"
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        Validarvendedor = 1  'USUARIO NO EXISTE
        Exit Function
    End If
    
    If Trim(rs!Password) <> Trim(StrPassWord) Then
        Validarvendedor = 2  'CLAVE INCORRECTA
    End If
      
    If Trim(rs!STATUSPERSONID) = "02" Then
        Validarvendedor = 4  'inactivo
    End If
    
    If Trim(rs!STATUSPERSONID) = "03" Then
        Validarvendedor = 5  'SUSPENDIDO
    End If
    
    'BUSCAR DERECHOS DEL USUARIO
    
 '''GetObjectContext.SetComplete
 
Exit Function
    
ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenerusuariovendedor(ByVal StrcodigoVendedor As String, Optional VarAux As Variant) As String
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
    
    StrSql = "select ACCESSUSERID from op_salesperson where SALESPERID='" & StrcodigoVendedor & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenerusuariovendedor = ""  'USUARIO NO EXISTE
    Else
        obtenerusuariovendedor = Trim(rs!ACCESSUSERID)
    End If
    
    'BUSCAR DERECHOS DEL USUARIO
    
 ''''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function

Public Function Listardeposit(strcorrelativo As Integer, Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = " SELECT CUSTIDSS,CUSTNAME,TAXREGNBR,ADDR1 FROM CUSTOMER"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set Listardeposit = 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_FACTURACION.ListarClientesAyuda", Err.Description

End Function
Public Function Listardepositdet(strcorrelativo As Integer, Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = "select * FROM VW_depositdet where batnbrdeposit =" + Str(strcorrelativo)
    
    Set rs = New ADODB.Recordset
    
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenDynamic, adLockBatchOptimistic
            
    Set Listardepositdet = 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_FACTURACION.ListarClientesAyuda", Err.Description

End Function
Public Function grabardeposit(ByVal intcorr As Integer, ByVal INTBATNBR As Integer, _
                                ByVal StrSITEID As String, ByVal intturn As Integer, _
                                ByVal datop As String, ByVal datproc As String, _
                                ByVal StrVendedor As String, ByVal struser As String, Optional VarAux As Variant) As Integer
   Dim cmd As ADODB.Command
   Dim con As ADODB.Connection
   Dim prm As ADODB.Parameter
   Dim StrSql As String
   
   On Error GoTo TrataError
   
   If IsNull(STRCUSTIDSS) Then
    STRCUSTIDSS = Empty
   End If
   
   If IsNull(strCARDID) Then
    strCARDID = Empty
   End If
   
StrSql = " EXEC op_grabar_cashdrop_PROC " + Str(intcorr) + "," + Str(INTBATNBR) + ",'" + _
                                        StrSITEID + "'," + Str(intturn) + ",'" + datop + "','" + _
                                        datproc + "','" + StrVendedor + "','" + struser + "'"
   
    Set cmd = New Command
   
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = StrSql
      
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
    cmd.Execute
    
    grabar_cashdrop_PROC = cmd("return")
    
    ''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_OP_FACTURACION.C_VENTASGENERAL", LStrMensajeError
     
End Function


Public Function ValidarUsuario(ByVal StrCodigoUsuario As String, Optional VarAux As Variant) As Integer
       
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
    ValidarUsuario = 0  'OK
    
    StrSql = "select userid,expired,status from se_userrec where userid='" & StrCodigoUsuario & "'"
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        ValidarUsuario = 1  'USUARIO NO EXISTE
        Exit Function
    End If
    
    ' If rs!expired < Date And StrCodigoUsuario <> "SYSADMIN" Then
    '    ValidarUsuario = 3  'expiro
    'End If
    
    If rs!Status = 0 Then
        ValidarUsuario = 4  'inactivo
    End If
    
''GetObjectContext.SetComplete
 
Exit Function
    
ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     If Not cmd Is Nothing Then
        Set cmd = Nothing
     End If
     If Not con Is Nothing Then
        LStrMensajeError = con.Errors(con.Errors.Count - 1).Description
        LVarNumeroError = con.Errors(con.Errors.Count - 1).NativeError
        Set con = Nothing
     End If
     
     GetObjectContext.SetAbort
     Err.Raise LVarNumeroError, "DB_OP_FACTURACION.ValidarUsuario", LStrMensajeError
          
End Function
Public Function ObtenerNombreVendedor(ByVal StrcodigoVendedor, Optional VarAux As Variant) As String
       
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
 
    StrSql = "select SALESPERNAME from op_salesperson where SALESPERID='" & StrcodigoVendedor & "'"
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        ObtenerNombreVendedor = "" 'Vendedor NO EXISTE
    Else
        ObtenerNombreVendedor = rs!SALESPERNAME
    End If
    
 ''GetObjectContext.SetComplete
 
Exit Function
    
ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function GRABAR_TMP_DEPOSITDET(ByVal INTCORRNBR As Integer, ByVal INTBATNBRDEPOSIT As Integer, _
                                    ByVal StrSITEID As String, ByVal INTSEQUENCE As Integer, _
                                    ByVal strCARDID As Variant, ByVal DOUTOTAL As Double, _
                                    ByVal STRCUSTIDSS As Variant, ByVal strcuryid As String, ByVal strdeposittypeid As String, Optional VarAux As Variant) As Integer
   Dim cmd As ADODB.Command
   Dim con As ADODB.Connection
   Dim prm As ADODB.Parameter
   Dim StrSql As String
   
   'On Error GoTo TrataError
   
   If IsNull(STRCUSTIDSS) Then
    STRCUSTIDSS = Empty
   End If
   
   If IsNull(strCARDID) Then
    strCARDID = Empty
   End If
   
StrSql = " EXEC AGREGAR_TMP_OP_DEPOSITDET_PROC " + Str(INTCORRNBR) + "," + Str(INTBATNBRDEPOSIT) + ",'" + StrSITEID + _
"'," + Str(INTSEQUENCE) + ",'" + strCARDID + "'," + Str(DOUTOTAL) + ",'" + STRCUSTIDSS + "','" + strcuryid + "','" + _
strdeposittypeid + "'"
   
   Set cmd = New Command
   
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = StrSql
      
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
    cmd.Execute
    
    GRABAR_TMP_DEPOSITDET = cmd("return")
    
    ''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_OP_FACTURACION.C_VENTASGENERAL", LStrMensajeError
     
End Function
Public Function obtenernombresite(ByVal StrSITEID As String, Optional VarAux As Variant) As String
       
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
 
    StrSql = "select NAME from site where siteid='" & StrSITEID & "'"
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenernombresite = "" 'site NO EXISTE
    Else
        obtenernombresite = rs!Name
    End If
    
 ''GetObjectContext.SetComplete
 
Exit Function
    
ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function ListarvendedorAyuda(Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = " SELECT SALESPERID,sALESPERNAME FROM op_salesperson"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarvendedorAyuda = 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_FACTURACION.ListarClientesAyuda", Err.Description

End Function
Public Function obtenercorrelativocashdrop(Optional VarAux As Variant) As String
       
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler

    StrSql = "select NBRCORELATIVE from op_corelative where TYPECORELATIVE='BATNBRDEPOSIT'"
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenercorrelativocashdrop = "1" ' NO EXISTE
    Else
        obtenercorrelativocashdrop = Str(rs!NBRCORELATIVE)
    End If
    
 ''GetObjectContext.SetComplete
 
Exit Function
    
ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function aumentarcorrelativocashdrop(Optional VarAux As Variant) As Integer

   Dim cmd As ADODB.Command
   Dim con As ADODB.Connection
   Dim prm As ADODB.Parameter
   Dim StrSql As String
   
   'On Error GoTo TrataError

   
StrSql = " UPDATE op_corelative SET NBRCORELATIVE =NBRCORELATIVE +1 where TYPECORELATIVE='BATNBRDEPOSIT'"
    Set cmd = New Command
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = StrSql
      
    Set con = New Connection
    con.Open "FILEDSN=conexionsies"
    cmd.ActiveConnection = con
    cmd.Execute
    
    aumentarcorrelativocashdrop = cmd("return")
    
    ''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_OP_FACTURACION.C_VENTASGENERAL", LStrMensajeError
     
End Function
Public Function ListarmonedaAyuda(Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = " SELECT CURYID,descr FROM CURRENCY "
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListarmonedaAyuda = 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_FACTURACION.ListarClientesAyuda", Err.Description

End Function
Public Function ListartipodepositoAyuda(Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = "select DEPOSITTYPEID,DESCRDEPOSTITYPE from op_deposittype "
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListartipodepositoAyuda = 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_FACTURACION.ListarClientesAyuda", Err.Description

End Function
Public Function ListartarjetaAyuda(Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = "SELECT CARDid,descr FROM Op_CARD"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    Set ListartarjetaAyuda = 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_FACTURACION.ListarClientesAyuda", Err.Description

End Function
Public Function obtenerruccliente(ByVal stridcliente As String, Optional VarAux As Variant) As String
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = " SELECT TAXREGNBR FROM CUSTOMER where CUSTIDSS='" + stridcliente + "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
            
    If rs.EOF Or rs.RecordCount = 0 Then
        obtenerruccliente = ""
    Else
        obtenerruccliente = rs!taxregnbr
    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_OP_FACTURACION.ListarClientesAyuda", Err.Description

End Function

Public Function ObtenerMonedaExtranjera(ByVal StrMonedaBase As String, Optional VarAux As Variant) As String
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " Select top 1 curyid from currency where curyid <> '" & StrMonedaBase & "'"
              
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   If rs.EOF Then
      ObtenerMonedaExtranjera = Empty
   Else
      ObtenerMonedaExtranjera = rs!CURYID
   End If
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACIONS.ObtenerMonedaExtranjera", Err.Description
End Function
Public Function obtenernombrepv(ByVal Strterminal As String, Optional VarAux As Variant) As String
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
    
    StrSql = "select salespoint from OP_SALESPOINTSETTING where terminalname='" & Strterminal & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenernombrepv = "" 'USUARIO NO EXISTE
    Else
        obtenernombrepv = Trim(rs!SALESPOINT)
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenertiponegocio(ByVal Strterminal As String, Optional VarAux As Variant) As String
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
    
    StrSql = "select businesstype from OP_SALESPOINTSETTING where terminalname='" & Strterminal & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenertiponegocio = "" 'USUARIO NO EXISTE
    Else
        obtenertiponegocio = Trim(rs!businesstype)
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenerprecio(ByVal StrCodigoCliente As String, ByVal stridproducto As String, Optional VarAux As Variant) As ADODB.Recordset
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "op_obtieneprecio_proc '" & StrCodigoCliente & "','" & stridproducto & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set obtenerprecio = rs
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.obtenerprecio", Err.Description
End Function
Public Function obtenertipoticket(Optional VarAux As Variant) As String
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
    
    StrSql = "select doctypeidticket from op_setup"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenertipoticket = "" 'no hay tipo registrado
    Else
        obtenertipoticket = rs!doctypeidticket
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenertipofactura(Optional VarAux As Variant) As String
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
    
    StrSql = "select DOCTYPEIDFAC from op_setup"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenertipofactura = "" 'no hay tipo registrado
    Else
        obtenertipofactura = rs!DOCTYPEIDFAC
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenernroticket(ByVal StrSALESPOINT As String, ByVal strtipodoc As String, Optional VarAux As Variant) As Double
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
StrSql = "select NBRTICKFAC,NBRTICKBOL from OP_SALESPOINTSETTING where SALESPOINT='" & StrSALESPOINT & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenernroticket = 0 'PUNTO DE VENTA NO ESTA REGISTRADA
    Else
        Select Case strtipodoc
            Case "TICKET FACTURA"
                obtenernroticket = rs!NBRTICKFAC
            Case "TICKET BOLETA"
                obtenernroticket = rs!NBRTICKBOL
            End Select
    End If
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenernrodocumento(ByVal strtipodoc As String, ByVal intseries As Integer, ByVal StrSITEID As String, Optional VarAux As Variant) As String
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String
Dim NBR As String
Dim STR_SERIE As String
Dim STR_NDOC As String

On Error GoTo ErrorHandler
    
StrSql = "select NBRSERIES,NBRDOC from OP_DOCSERIES where DOCTYPEID='" & strtipodoc & _
                                                       "' AND  NBRSERIES=" & intseries & _
                                                        " AND  SITEID='" & StrSITEID & "'"
                                                        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenernrodocumento = 0 'NO ESTA REGISTRADO UNA SERIE PARA ESE DOCUMENTO
    Else
        STR_SERIE = Trim(CStr(rs!NBRSERIES))
        STR_SERIE = String(3 - Len(STR_SERIE), "0") + STR_SERIE
        STR_NDOC = Trim(CStr(rs!NBRDOC))
        STR_NDOC = String(7 - Len(STR_NDOC), "0") + STR_NDOC
        NBR = STR_NDOC
        obtenernrodocumento = NBR
    End If
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function ListarDocumentosventas(ByVal StrSITEID As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    On Error GoTo TrataError
    StrSql = " op_listardocumentosventas '" & StrSITEID & "'"
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    Set ListarDocumentosventas = 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_FACTURACION.ListarDocumentos", Err.Description

End Function
Public Function obtenertiponc(Optional VarAux As Variant) As String
'devuelve el codigo del tipo de documento de NOTA DE CRedito
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = "select DOCTYPEIDNC from op_setup"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenertiponc = "" 'no hay tipo registrado
    Else
        obtenertiponc = rs!DOCTYPEIDNC
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenertipond(Optional VarAux As Variant) As String
'devuelve el codigo del tipo de documento de NOTA DE DEBITO
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler

    
    StrSql = "select DOCTYPEIDND from op_setup"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenertipond = "" 'no hay tipo registrado
    Else
        obtenertipond = rs!DOCTYPEIDND
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenerseriesdoc(ByVal strdocid As String, ByVal StrSITEID As String, Optional VarAux As Variant) As ADODB.Recordset
'buscar las series de cada documento para presentarlas en la facturacion manual
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = "select nbrseries from op_docseries where doctypeid='" & strdocid & "' and siteid='" & StrSITEID & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    Set obtenerseriesdoc = rs
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.Validarvendedor", LStrMensajeError
     
End Function
Public Function obtenernbrloadsale(ByVal StrSITEID As String, Optional VarAux As Variant) As Double
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "op_obtienenbrloadsales '" & StrSITEID & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
If rs.RecordCount = 0 Or rs.EOF Then
   obtenernbrloadsale = 0
Else
   obtenernbrloadsale = rs!nbrloadsale
End If

   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.obtenerprecio", Err.Description
End Function

Public Sub grabartransaccion(ByVal CORRNBR As Double, ByVal DOCTYPEID As String, _
                            ByVal NBRDOCUMENT As Double, ByVal TYPEPAYMENTID As String, _
                            ByVal STKINVENTORY As Byte, ByVal SITEID As String, _
                            ByVal CURYID As String, ByVal TERMID As String, _
                            ByVal SALESPERID As String, ByVal USERID As String, _
                            ByVal DATEDOC As String, ByVal DATEPROCESALES As String, _
                            ByVal PERPOST As String, ByVal TAXIGVID As String, _
                            ByVal TAXISCID As String, ByVal TOTALPEN As Double, _
                            ByVal TOTALUSD As Double, ByVal SUBTOTALPEN As Double, _
                            ByVal SUBTOTALUSD As Double, ByVal TAXIGVPEN As Double, _
                            ByVal TAXIGVUSD As Double, ByVal TAXISCPEN As Double, _
                            ByVal TAXISCUSD As Double, ByVal TOTALNOTAFFECTPEN As Double, _
                            ByVal TOTALNOTAFFECTUSD As Double, ByVal TOTRETURNEDPEN As Double, _
                            ByVal TOTRETURNEDUSD As Double, ByVal TOTCASHPEN As Double, _
                            ByVal TOTCASHUSD As Double, _
                            ByVal Custidss As String, ByVal taxregnbr As String, _
                            ByVal CUSTNAME As String, ByVal PLACA As String, _
                            ByVal NBRBONUS As Double, ByVal CURYTYPEID As String, _
                            ByVal CURYRATE As Double, ByVal PROMOTIONCARDID As String, _
                            ByVal POINTNUMBER As Integer, _
                            ByVal SALESPOINT As String, ByVal KILOMETRAJE As Integer, _
                            ByVal tipoventa As String, ByVal addr1 As String, ByVal STRTIPONEGOCIO As String, Optional VarAux As Variant)
                
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim prm As ADODB.Parameter
Dim StrSql As String
   
   On Error GoTo TrataError
   
StrSql = " EXEC OP_GRABARTRANSACCION " & CORRNBR & ",'" & DOCTYPEID & "','" & _
                                        NBRDOCUMENT & "','" & TYPEPAYMENTID & "'," & STKINVENTORY & ",'" & _
                                        SITEID & "','" & CURYID & "','" & TERMID & "','" & SALESPERID & "','" & _
                                        USERID & "','" & DATEDOC & "','" & DATEPROCESALES & "','" & _
                                        PERPOST & "','" & TAXIGVID & "','" & TAXISCID & "'," & TOTALPEN & "," & _
                                        TOTALUSD & "," & SUBTOTALPEN & "," & SUBTOTALUSD & "," & _
                                        TAXIGVPEN & "," & TAXIGVUSD & "," & TAXISCPEN & "," & TAXISCUSD & "," & _
                                        TOTALNOTAFFECTPEN & "," & TOTALNOTAFFECTUSD & "," & TOTRETURNEDPEN & "," & _
                                        TOTRETURNEDUSD & "," & TOTCASHPEN & "," & TOTCASHUSD & ",'" & _
                                        Custidss & "','" & taxregnbr & "','" & CUSTNAME & "','" & PLACA & "'," & _
                                        NBRBONUS & ",'" & CURYTYPEID & "'," & CURYRATE & ",'" & PROMOTIONCARDID & _
                                        "'," & POINTNUMBER & ",'" & SALESPOINT & "'," & KILOMETRAJE & ",'" & _
                                        tipoventa & "','" & addr1 & "','" & STRTIPONEGOCIO & "'"

   
    Set cmd = New Command
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = StrSql
      
    Set con = New 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 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_OP_FACTURACION.C_VENTASGENERAL GRABAR TRANSASCCION", LStrMensajeError
     
End Sub

Public Sub actualizatransaccion(ByVal CORRNBR As Double, ByVal DOCTYPEID As String, ByVal NBRDOCUMENT As Double, _
                            ByVal TYPEPAYMENTID As String, ByVal STKINVENTORY As Byte, ByVal SITEID As String, _
                            ByVal CURYID As String, ByVal TERMID As String, ByVal SALESPERID As String, _
                            ByVal USERID As String, ByVal DATEDOC As String, ByVal DATEPROCESALES As String, _
                            ByVal PERPOST As String, ByVal TAXIGVID As String, ByVal TAXISCID As String, _
                            ByVal TOTALPEN As Double, ByVal TOTALUSD As Double, ByVal SUBTOTALPEN As Double, _
                            ByVal SUBTOTALUSD As Double, ByVal TAXIGVPEN As Double, ByVal TAXIGVUSD As Double, _
                            ByVal TAXISCPEN As Double, ByVal TAXISCUSD As Double, ByVal TOTALNOTAFFECTPEN As Double, _
                            ByVal TOTALNOTAFFECTUSD As Double, ByVal TOTRETURNEDPEN As Double, _
                            ByVal TOTRETURNEDUSD As Double, ByVal TOTCASHPEN As Double, ByVal TOTCASHUSD As Double, _
                            ByVal Custidss As String, ByVal taxregnbr As String, ByVal CUSTNAME As String, _
                            ByVal PLACA As String, ByVal NBRBONUS As Double, ByVal CURYTYPEID As String, _
                            ByVal CURYRATE As Double, ByVal PROMOTIONCARDID As String, ByVal POINTNUMBER As Integer, _
                            ByVal SALESPOINT As String, ByVal KILOMETRAJE As Integer, _
                            ByVal tipoventa As String, ByVal addr1 As String, ByVal STRTIPONEGOCIO As String, Optional VarAux As Variant)
                
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim prm As ADODB.Parameter
Dim StrSql As String
   
   On Error GoTo TrataError
   
StrSql = " EXEC OP_actualizaTRANSACCION " & CORRNBR & ",'" & DOCTYPEID & "','" & _
                                        NBRDOCUMENT & "','" & TYPEPAYMENTID & "'," & STKINVENTORY & ",'" & _
                                        SITEID & "','" & CURYID & "','" & TERMID & "','" & SALESPERID & "','" & _
                                        USERID & "','" & DATEDOC & "','" & DATEPROCESALES & "','" & _
                                        PERPOST & "','" & TAXIGVID & "','" & TAXISCID & "'," & TOTALPEN & "," & _
                                        TOTALUSD & "," & SUBTOTALPEN & "," & SUBTOTALUSD & "," & _
                                        TAXIGVPEN & "," & TAXIGVUSD & "," & TAXISCPEN & "," & TAXISCUSD & "," & _
                                        TOTALNOTAFFECTPEN & "," & TOTALNOTAFFECTUSD & "," & TOTRETURNEDPEN & "," & _
                                        TOTRETURNEDUSD & "," & TOTCASHPEN & "," & TOTCASHUSD & ",'" & _
                                        Custidss & "','" & taxregnbr & "','" & CUSTNAME & "','" & PLACA & "'," & _
                                        NBRBONUS & ",'" & CURYTYPEID & "'," & CURYRATE & ",'" & PROMOTIONCARDID & _
                                        "'," & POINTNUMBER & ",'" & SALESPOINT & "'," & KILOMETRAJE & ",'" & _
                                        tipoventa & "','" & addr1 & "','" & STRTIPONEGOCIO & "'"

    Set cmd = New Command
   
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = StrSql
      
    Set con = New 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 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_OP_FACTURACION.C_VENTASGENERAL ACTUALIZAR TRANSACCION", LStrMensajeError
End Sub

Public Function obtenertransgrabadas(ByVal StrPuntoVenta As String, ByVal STRTIPOVENTA As String, Optional VarAux As Variant) As ADODB.Recordset
Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "op_obtenertransgrabadas '" & StrPuntoVenta & "','" & STRTIPOVENTA & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set obtenertransgrabadas = rs

   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.obtenerprecio", Err.Description
End Function
Public Function existecorrelativotemporal(ByVal corr As Double, Optional VarAux As Variant) As Boolean

'busca todas las transacciones grabadas
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = "select * from tmp_op_salescstore where CORRNBR= " & corr
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.EOF Or rs.RecordCount = 0 Then
        existecorrelativotemporal = False
    Else
        existecorrelativotemporal = True
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.existecorrelativotemporal", LStrMensajeError
     
End Function
Public Sub grabarsalescard(ByVal doucorrnbr, ByVal StrSITEID As String, ByVal strCARDID As String, _
                            ByVal strNBRCARD As String, ByVal strcuryid As String, _
                            ByVal TOTCARDPEN As Double, ByVal TOTCARDUSD As Double, Optional VarAux As Variant)
   
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "OP_GRABAR_TMPOPSALESCARD " & doucorrnbr & ",'" & _
                            StrSITEID & "','" & strCARDID & "','" & _
                            strNBRCARD & "','" & strcuryid & "'," & _
                            TOTCARDPEN & "," & TOTCARDUSD
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   ''GetObjectContext.SetComplete
   Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.obtenerprecio", Err.Description
End Sub

Public Function Listartmp_opsalescard(ByVal intcorr 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 tmp_op_salescard where corrnbr= '" & intcorr & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenKeyset, adLockBatchOptimistic
        
    Set Listartmp_opsalescard = 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_FACTURACION.Listartmp_opsalescard", Err.Description

End Function
Public Function obtenerturnoventas(Optional VarAux As Variant) As Integer
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    On Error GoTo TrataError
    
    StrSql = " select salespersonturn  from setup "

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
        
    If rs.EOF Or rs.RecordCount = 0 Then
        obtenerturnoventas = 0
    Else
        obtenerturnoventas = rs!salespersonturn
    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_OP_FACTURACION.obtenerturnoventas ", Err.Description

End Function
Public Sub salvartransaccion(ByVal CORRNBR As Double, ByVal TOTALPEN As Double, Optional VarAux As Variant)
                
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim prm As ADODB.Parameter
Dim StrSql As String
   
   On Error GoTo TrataError
   
StrSql = " EXEC OP_salvarTRANSACCION " & CORRNBR & "," & TOTALPEN

    Set cmd = New Command
   
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = StrSql
      
    Set con = New 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 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_OP_FACTURACION.C_VENTASGENERAL SALVAR TRANSACCION", LStrMensajeError
End Sub

Public Sub aumentarnroticket(ByVal StrSALESPOINT As String, ByVal strtipodoc As String, Optional VarAux As Variant)
                
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim prm As ADODB.Parameter
Dim StrSql As String

   On Error GoTo TrataError
   
Select Case strtipodoc
    Case "TICKET FACTURA"
        StrSql = " EXEC OP_aumentarnrofactura '" & StrSALESPOINT & "'"
    Case "TICKET BOLETA"
        StrSql = " EXEC OP_aumentarnroboleta '" & StrSALESPOINT & "'"
    End Select
            
    Set cmd = New Command
   
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = StrSql
      
    Set con = New 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 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_OP_FACTURACION.C_VENTASGENERAL SALVAR TRANSACCION", LStrMensajeError

End Sub
Public Sub aumentarnrodocumento(ByVal strtipodoc As String, ByVal intseries As Integer, _
                                ByVal StrSITEID As String, ByVal StrPtoVta As String, ByVal NBR As Double, Optional VarAux As Variant)
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim prm As ADODB.Parameter
Dim StrSql As String

'On Error GoTo ErrorHandler  ---->>> Antes apuntaba erroneamente a esta etiqueta
On Error GoTo TrataError

    
StrSql = "exec op_aumentarnrodocumento '" & strtipodoc & "'," & intseries & ",'" & _
                                        StrSITEID & "','" & StrPtoVta & "'," & NBR

    Set cmd = New Command
   
    Set prm = cmd.CreateParameter("return", adInteger, adParamReturnValue, , 0)
    cmd.Parameters.Append prm
   
    cmd.CommandText = StrSql
      
    Set con = New 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 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_OP_FACTURACION.C_VENTASGENERAL SALVAR TRANSACCION", LStrMensajeError

End Sub

Public Function ObtenerDatosTicket(Optional VarAux As Variant) As ADODB.Recordset
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "Select * from OP_TICKETFORM"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ObtenerDatosTicket = rs
           
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.ObtenerDatosTicket", Err.Description
End Function

Public Function op_obtenerventasayuda(ByVal StrSITEID As String, _
                                        ByVal datfechaini As Date, _
                                        ByVal datfechafin As Date, _
                                        ByVal DBLNDOC As Double, _
                                        ByVal STRTIPONEGOCIO As String, Optional VarAux As Variant) As ADODB.Recordset
Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " op_obtenerventasayuda '" + StrSITEID + "','" + CStr(datfechaini) + "','" + CStr(datfechafin) + "'," + CStr(DBLNDOC) + ",'" + STRTIPONEGOCIO + "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set op_obtenerventasayuda = rs

   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.obtenerprecio", Err.Description
End Function

Public Function obtenerventasdetayuda(ByVal strtipodoc As String, _
                                    ByVal DBLNDOC As Double, _
                                    ByVal StrSITEID As String, Optional VarAux As Variant) As ADODB.Recordset
Dim StrSql As String
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " op_Obtenerventasdetayuda '" + strtipodoc + "'," + CStr(DBLNDOC) + ",'" + StrSITEID + "'"
   
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set obtenerventasdetayuda = rs

   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.obtenerprecio", Err.Description
End Function
Public Function anularventa(ByVal strtipodoc As String, ByVal DBLNDOC As Double, _
                                    ByVal StrSITEID As String, strdocstatus As String, _
                                    ByVal strtipopago As String, ByVal strcodcliente As String, _
                                    ByVal doumontopen As Double, ByVal doumontousd As Double, Optional VarAux As Variant) As Integer
                                    
Dim StrSql As String
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " op_anularventa_proc '" + strtipodoc + "'," + CStr(DBLNDOC) + ",'" + _
                                    StrSITEID + "','" + strdocstatus + "','" + strtipopago + "','" + _
                                    strcodcliente + "'," + CStr(doumontopen) + "," + CStr(doumontousd)
      
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
    anularventa = rs.Fields(0)
   
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.obtenerprecio", Err.Description

End Function

Public Function eliminarventa(ByVal strtipodoc As String, ByVal DBLNDOC As Double, _
                                    ByVal StrSITEID As String, strdocstatus As String, _
                                    ByVal strtipopago As String, ByVal strcodcliente As String, _
                                    ByVal doumontopen As Double, ByVal doumontousd As Double, Optional VarAux As Variant) As Integer
Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " op_eliminarventa_proc '" + strtipodoc + "'," + CStr(DBLNDOC) + ",'" + _
                                    StrSITEID + "','" + strdocstatus + "','" + strtipopago + "','" + _
                                    strcodcliente + "'," + CStr(doumontopen) + "," + CStr(doumontousd)
   
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
    eliminarventa = rs.Fields(0)
    
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.obtenerprecio", Err.Description
End Function

Public Function FaltaCierreZ(Optional VarAux As Variant) As ADODB.Recordset
   Dim StrSql As String
   Dim rs As ADODB.Recordset

   On Error GoTo errhandler
   
   StrSql = " Select SALESPOINT,stkzetaok from op_salespointsetting WHERE STKTOFORCEZ=1 AND stkzetaok=0"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                   
   Set FaltaCierreZ = rs
            
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:

    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.FaltaCierreZ", Err.Description
End Function

Public Function CerraDiadeVentas(Optional VarAux As Variant)
   Dim cmd As ADODB.Command
    
   On Error GoTo errhandler
   
   StrSql = " OP_Cierre_Ventas_Proc "
   
   Set cmd = New Command
   cmd.CommandTimeout = 0
   cmd.CommandText = StrSql
      
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
   
   ''GetObjectContext.SetComplete
   
   Exit Function
errhandler:
    If Not cmd Is Nothing Then
       Set cmd = Nothing
    End If
        
   GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.CerraDiadeVentas", Err.Description
End Function
Public Function existereferencias(ByVal DOCTYPEIDREF As String, ByVal NBRDOCUMENTREF As Double, ByVal SITEID As String, Optional VarAux As Variant)
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = " OP_existereferencias '" & DOCTYPEIDREF & "'," & NBRDOCUMENTREF & ",'" & SITEID & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs!numero = 0 Then
        existereferencias = False
    Else
        existereferencias = True
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.existereferecnias", LStrMensajeError
     
End Function
Public Function obtenertipoboleta(Optional VarAux As Variant) As String
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
'Funcion de Encriptación del password
    
    StrSql = "select DOCTYPEIDbol from op_setup"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenertipoboleta = "" 'no hay tipo registrado
    Else
        obtenertipoboleta = rs!DOCTYPEIDbol
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.obtenertipoboleta", LStrMensajeError
     
End Function
Public Function ListarDocumentosnc(ByVal StrSITEID As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    On Error GoTo TrataError
    StrSql = " op_listardocumentosnc '" & StrSITEID & "'"
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    Set ListarDocumentosnc = 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_FACTURACION.ListarDocumentos", Err.Description

End Function

Public Function existedocumento(ByVal DOCTYPEID As String, ByVal NBRDOCUMENT As Double, ByVal SITEID As String, Optional VarAux As Variant)
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = " OP_existedocumento '" & DOCTYPEID & "'," & NBRDOCUMENT & ",'" & SITEID & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenStatic
    
    If rs!numero = 0 Then
        existedocumento = False
    Else
        existedocumento = True
    End If
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.existereferecnias", LStrMensajeError
     
End Function

Public Function obtenerdeletedoc(ByVal StrSALESPOINT As String, Optional VarAux As Variant) As Boolean
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
StrSql = "select stkdeletedoc from OP_SALESPOINTSETTING where SALESPOINT='" & StrSALESPOINT & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    If rs.RecordCount = 0 Or rs.EOF Then
        obtenerdeletedoc = False
    Else
        If rs!stkdeletedoc Then
            obtenerdeletedoc = True
        Else
            obtenerdeletedoc = False
        End If
            
    End If
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.obtenerdeletedoc", LStrMensajeError
     
End Function

Public Function obtenertarjetasventa(ByVal DOCTYPEID As String, ByVal NBRDOCUMENT As Double, ByVal SITEID As String, Optional VarAux As Variant) As ADODB.Recordset
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = " op_tarjetasventas_proc '" & DOCTYPEID & "'," & NBRDOCUMENT & ",'" & SITEID & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    Set obtenertarjetasventa = rs
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.obtenertarjetasventas. xistereferecnias", LStrMensajeError
End Function
Public Function Listartiposnegocio(Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    On Error GoTo TrataError
    StrSql = " select * from op_businesstype WHERE BUSINESSTYPE<>0"
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    Set Listartiposnegocio = 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_FACTURACION.ListarDocumentos", Err.Description

End Function

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

End Function


Public Function ListarPreciosaActualizar(Optional VarAux As Variant) As ADODB.Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    On Error GoTo TrataError
    StrSql = " SELECT IN_PRICELEVELTEM.SITEID as Cod_Almacén,SITE.NAME as [Almacen],IN_PRICELEVELTEMDET.INVTIDSKU as Cod_Artículo, " & _
             " IN_INVENTORY.DESCR as [Artículo],IN_PRICELEVELTEM.PRECLVID,IN_PRICELEVELTYPE.DESCR AS [Tipo_de _Precio], " & _
             " SLS_PRICE As [Pre._Actual], NEWSLS_PRICE As [Nuevo_Pre.]" & _
             " FROM (((IN_PRICELEVELTEM " & _
             " INNER JOIN IN_PRICELEVELTEMDET  ON  IN_PRICELEVELTEM.SITEID=IN_PRICELEVELTEMDET.SITEID " & _
             " AND IN_PRICELEVELTEM.BATNBRPRICELEVELTEM = IN_PRICELEVELTEMDET.BATNBRPRICELEVELTEM) " & _
             " INNER JOIN SITE ON SITE.SITEID=IN_PRICELEVELTEM.SITEID) " & _
             " INNER JOIN IN_PRICELEVELTYPE ON IN_PRICELEVELTYPE.PRECLVID=IN_PRICELEVELTEM.PRECLVID) " & _
             " INNER JOIN IN_INVENTORY ON IN_INVENTORY.INVTIDSKU=IN_PRICELEVELTEMDET.INVTIDSKU " & _
             " WHERE IN_PRICELEVELTEM.PRECLVID in('004','003') and IN_PRICELEVELTEM.STATUS=1 "
                 
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
              
    Set ListarPreciosaActualizar = 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_FACTURACION.ListarPreciosaActualizar", Err.Description
             
End Function
Public Function cargar_referencias(ByVal DOCTYPEID As String, _
                                    ByVal NBRDOCUMENT As Double, _
                                    ByVal SITEID As String, _
                                    ByVal corr As Double, Optional VarAux As Variant) As ADODB.Recordset
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = " OP_MostrarDetallenotacreditotemp '" & DOCTYPEID & "'," & NBRDOCUMENT & ",'" & SITEID & "'," & corr
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    Set cargar_referencias = rs
 
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.existereferecnias", LStrMensajeError
     
End Function
Public Sub Cargar_ResumendeVentas(ByVal StrSite As String, ByVal DblCorrelativo As Double, Optional VarAux As Variant)
                                        
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " Op_TmpResumenVentas_Proc '" & StrSite & "'," & DblCorrelativo
    
   Set cmd = New Command
   cmd.CommandTimeout = 0
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_OP_FACTURACION.Cargar_ResumendeVentas", LStrMensajeError
     
End Sub


Public Function ConsultarResumenVentas(ByVal DatFechaProceso As Date, ByVal StrAlmacen As String, Optional VarAux As Variant) As ADODB.Recordset

Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    
StrSql = " SELECT dbo.OP_SUMMARYSALES.SITEID,dbo.OP_SUMMARYSALES.DATEPROCE, " & _
         " dbo.OP_SUMMARYSALES.COMMENT,dbo.OP_SUMMARYSALES.STATUS, " & _
         " dbo.OP_SUMMARYSALESDET.SEQUENCE,dbo.OP_SUMMARYSALESDET.CLASSID, " & _
         " dbo.OP_SUMMARYSALESDET.custidss,dbo.OP_SUMMARYSALESDET.DESCR,dbo.OP_SUMMARYSALESDET.DOCSUMMARYTYPEIDNC, " & _
         " CASE STKGENERATEDNC WHEN 1 THEN 'Sí' Else 'No' END as [Generado]," & _
         " dbo.OP_SUMMARYSALESDET.REFERENCENC,dbo.OP_SUMMARYSALESDET.TOTALPENNC,dbo.OP_SUMMARYSALESDET.DOCSUMMARYTYPEIDFAC, " & _
         " CASE STKGENERATEDFC WHEN 1 THEN 'Sí' Else 'No' END as [Generado]," & _
         " dbo.OP_SUMMARYSALESDET.REFERENCEFAC,dbo.OP_SUMMARYSALESDET.TOTALPENFC, " & _
         " (dbo.OP_SUMMARYSALESDET.TOTALPENFC - dbo.OP_SUMMARYSALESDET.TOTALPENNC) AS [IMPORTE], " & _
         "  CASE WHEN CLASSID IS NULL AND ADELANT <> 1 THEN (dbo.OP_SUMMARYSALESDET.TOTALPENFC - dbo.OP_SUMMARYSALESDET.TOTALPENNC) " & _
         "  ELSE 0 END AS [CREDITO], " & _
         " ((dbo.OP_SUMMARYSALESDET.TOTALPENFC - dbo.OP_SUMMARYSALESDET.TOTALPENNC) - " & _
         " CASE WHEN (CLASSID IS NULL) OR (ADELANT=1) THEN (dbo.OP_SUMMARYSALESDET.TOTALPENFC - dbo.OP_SUMMARYSALESDET.TOTALPENNC) " & _
         " ELSE 0 END) AS [TOTAL],dbo.OP_SUMMARYSALESDET.TOTALBONUS,dbo.OP_SUMMARYSALESDET.DIFFERENCE " & _
         " FROM dbo.OP_SUMMARYSALES INNER JOIN " & _
         " dbo.OP_SUMMARYSALESDET ON dbo.OP_SUMMARYSALES.SITEID = dbo.OP_SUMMARYSALESDET.SITEID AND " & _
         " dbo.OP_SUMMARYSALES.DATEPROCE = dbo.OP_SUMMARYSALESDET.DATEPROCE " & _
         " WHERE dbo.OP_SUMMARYSALES.DATEPROCE='" & DatFechaProceso & "' AND dbo.OP_SUMMARYSALES.SITEID='" & StrAlmacen & "'"
        
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set ConsultarResumenVentas = rs
 
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     
     GetObjectContext.SetAbort
     Err.Raise Err.Number, "DB_OP_FACTURACION.ConsultarResumenVentas", Err.Description
         
End Function

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

Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    
    StrSql = " Select IDSUMARY,DESCR," & _
             " CASE PART WHEN 6 THEN 'Sí' ELSE '' END AS [GENERADA], " & _
             " NBRPHANTNC,MONTONCBASE,MONTONCEXTR, " & _
             " CASE PART WHEN 5 THEN 'Sí' ELSE '' END AS [GENERADA], " & _
             " NBRPHANTFC,MONTOFCBASE,MONTOFCEXTR, " & _
             " (MONTOFCBASE-MONTONCBASE) AS [IMPORTEBASE]," & _
             " (MONTOFCEXTR-MONTONCEXTR) AS [IMPORTEEXTR]," & _
             " CASE CONTCRED WHEN 0 THEN MONTOFCBASE-MONTONCBASE  WHEN 1 THEN 0 END AS [VTACREDBASE]," & _
             " CASE CONTCRED WHEN 0 THEN MONTOFCEXTR-MONTONCEXTR  WHEN 1 THEN 0 END AS [VTACREDEXTR]," & _
             " (MONTOFCBASE-MONTONCBASE)- (CASE CONTCRED WHEN 0 THEN MONTOFCBASE-MONTONCBASE  WHEN 1 THEN 0 END) as [TOTALBASE]," & _
             " (MONTOFCEXTR-MONTONCEXTR)-  CASE CONTCRED WHEN 0 THEN MONTOFCEXTR-MONTONCEXTR  WHEN 1 THEN 0 END AS [TOTALUSD]," & _
             " VALES,DIFERENCIA,CONTCRED,PART,DOCTYPEID,NBRDOCUMENT from TMP_RESUMEN_VENTAS " & _
             " where CORRNBR=" & DblCorrelativo & " and (MONTOFCBASE + MONTOFCEXTR + MONTONCBASE + MONTONCEXTR )<> 0 " & _
             " ORDER BY PART ASC "
             
                
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set MostrarResumenVentas = rs
 
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     
     GetObjectContext.SetAbort
     Err.Raise Err.Number, "DB_OP_FACTURACION.existereferecnias", Err.Description
         
End Function
Public Sub Actualizar_ResumendeVentas(ByVal DblCorrelativo As Double, ByVal StrCodigo As String, _
                                      ByVal DblVales As Double, ByVal DblDiferencia As Double, ByVal StrTipoDocumento As String, _
                                      ByVal DblNumeroDocumento As Double, Optional VarAux As Variant)
                                        
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " Op_ActualizaResumenVentas_Proc " & DblCorrelativo & ",'" & StrCodigo & "'," & DblVales & "," & _
                                             DblDiferencia & ",'" & StrTipoDocumento & "'," & DblNumeroDocumento
              
    
   Set cmd = New Command
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_OP_FACTURACION.Actualizar_ResumendeVentas", LStrMensajeError
     
End Sub

Public Sub Eliminar_TMPResumendeVentas(ByVal DblCorrelativo As Double, Optional VarAux As Variant)
                                        
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " Op_EliminarTmpResumenVentas_Proc " & DblCorrelativo
    
   Set cmd = New Command
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_FACTURACION.Eliminar_TMPResumendeVentas", LStrMensajeError
     
End Sub

Public Sub grabar_fondocaja(ByVal dat_DATEPROCE As String, ByVal str_SALESPOINT As String, _
                            ByVal str_SALESPERID As String, ByVal dat_DATEDOC As String, _
                            ByVal str_CURYID As String, ByVal dou_TOTALPEN As Double, _
                            ByVal dou_TOTALUSD As Double, Optional VarAux As Variant)
                                        
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " op_grabarfondocaja  '" & dat_DATEPROCE & "','" & str_SALESPOINT & "','" & str_SALESPERID & "','" & _
                                   dat_DATEDOC & "','" & str_CURYID & "'," & dou_TOTALPEN & "," & dou_TOTALUSD

    
   Set cmd = New Command
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_OP_FACTURACION.grabar fondo caja", LStrMensajeError
     
End Sub
Public Function cierres_pendientes(ByVal dat_fechaproceso As String, ByVal str_puntoventas As String, Optional VarAux As Variant) As String
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "op_cierrespendientes '" & dat_fechaproceso & "','" & str_puntoventas & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
    If rs.EOF Or rs.RecordCount = 0 Then
        cierres_pendientes = ""
   Else
        cierres_pendientes = rs!SALESPERNAME
   End If
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.cierres pendientes", Err.Description
End Function
Public Function cierreZPtovta(ByVal dat_fechaproceso As String, ByVal str_puntoventas As String, Optional VarAux As Variant) As Boolean
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " cierrezptovta '" & str_puntoventas & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   If IsNull(rs!fechazeta) Or rs!fechazeta < CDate(dat_fechaproceso) Then
       cierreZPtovta = False
   Else
       cierreZPtovta = True
   End If
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.cierres pendientes", Err.Description
End Function

Public Sub GenerarParteDiaro(ByVal DblCorrelativo As Double, ByVal StrAlmacen As String, _
                             ByVal StrComentario As String, ByVal StrMonedaBase As String, _
                             ByVal StrMonedaExtranjera As String, ByVal StrUserid As String, ByVal DblTotal As Double, Optional VarAux As Variant)
                             
                                        
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   
   StrSql = " OP_GenerarResumendeVentasProc " & DblCorrelativo & ",'" & StrAlmacen & "','" & _
                                                StrComentario & "','" & StrMonedaBase & "','" & _
                                                StrMonedaExtranjera & "','" & StrUserid & "'," & DblTotal
                                 
   Set cmd = New Command
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_OP_FACTURACION.GenerarParteDiaro", LStrMensajeError
     
End Sub
Public Sub CerrarParteDiario(ByVal StrAlmacen As String, ByVal StrMonedaBase As String, _
                             ByVal StrMonedaExtranjera, ByVal StrUserid As String, ByVal StrTipodeTipodeCambio As String, Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " OP_CerrarParteDiarioProc '" & StrAlmacen & "','" & StrMonedaBase & "','" & _
                                            StrMonedaExtranjera & "','" & StrUserid & "','" & StrTipodeTipodeCambio & "'"
                                 
   Set cmd = New Command
   cmd.CommandTimeout = 0
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_FACTURACION.CerrarParteDiario", LStrMensajeError
End Sub
  
Public Function ReprocesarParteDiario(ByVal StrAlmacen As String, ByVal StrUsuario As String, ByVal DatFechaProceso As Date, Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " OP_Reprocesar_ParteDiarioProc '" & StrUsuario & "','" & StrAlmacen & "','" & DatFechaProceso & "'"
                                 
   Set cmd = New Command
   cmd.CommandTimeout = 0
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
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_FACTURACION.ReprocesarParteDiario", LStrMensajeError
     
End Function
Public Function AprobarParteDiario(ByVal StrAlmacen As String, ByVal StrUsuario As String, Optional VarAux As Variant) As Variant
      
   Dim cmd As ADODB.Command
   Dim rs As ADODB.Recordset
   Dim con  As ADODB.Connection
   Dim LArray(1, 2) As Variant
   
   Dim StrCodArticulo As String
   Dim StrDescripcion As String
   Dim StrTarjeta As String
   Dim IntRetorno As Integer
   Dim StrCadenaRetorno As String
   Dim StrSql As String
      
   On Error GoTo TrataError
   
   Set cmd = New ADODB.Command
   Set rs = New ADODB.Recordset
   Set con = New ADODB.Connection
   
   
   
5   StrSql = " OP_AprobarParteDiario '" & StrAlmacen & "','" & StrUsuario & "','',''"
   
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.CommandText = StrSql
   Set rs = cmd.Execute
    
    
   StrCodArticulo = rs!codigo
   StrDescripcion = rs!descripcion
   StrTarjeta = rs!tarjeta
   IntRetorno = rs!opcion
    
   If IntRetorno = 1 Then
      StrCadenaRetorno = "El Artículo " & StrDescripcion & " No Fue Registrado por Gasboy " & _
                         Chr(13) & "Ingrese a la Opción Control de Combustibles/ Precio Combustibles"
   End If
    
   If IntRetorno = 2 Then
      StrCadenaRetorno = "El Artículo " & StrDescripcion & " No Fue Registrado en Titanium " & _
                         Chr(13) & "Ingrese a la Opción Control de Combustibles/ Precio Combustibles"
   End If
        
   If IntRetorno = 3 Then
      StrCadenaRetorno = "Cantidad despachada es diferente de cantidad facturada para el Artículo " & StrDescripcion & _
                         Chr(13) & "Ingrese a la Opción Control de Combustibles/ Precio Combustibles"
   End If
    
   If IntRetorno = 4 Then
      StrCadenaRetorno = "Total despachado diferente de Total facturado para el Artículo " & StrDescripcion & _
                         Chr(13) & "Ingrese a la Opción Control de Combustibles/ Precio Combustibles"

   End If
   If IntRetorno = 5 Then
      StrCadenaRetorno = "Total declarado en venta con tarjeta no cuadra con la Venta de tarjeta Facturado " & _
                         Chr(13) & "Ingrese a la Opción Parte Diario / Tarjetas de Crédito "
      
   End If
   If IntRetorno = 6 Then
      StrCadenaRetorno = "La Diferencia Excede la permitida "
   End If
         
   If IntRetorno = 7 Then
      StrCadenaRetorno = "Debe reprocesar el Resumen de Ventas porquese registraron nuevos Movimientos  "
   End If
   
   
   LArray(1, 1) = StrCadenaRetorno
   LArray(1, 2) = IntRetorno
                
    'AprobarParteDiario = StrCadenaRetorno
    AprobarParteDiario = LArray
    
    ''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 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_OP_FACTURACION.C_VENTASGENERAL.AprobarParteDiario", LStrMensajeError
     
End Function

Public Function obtenervales(ByVal DOCTYPEID As String, ByVal NBRDOCUMENT As Double, ByVal SITEID As String, Optional VarAux As Variant) As ADODB.Recordset
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = " op_tarjetasventas_proc '" & DOCTYPEID & "'," & NBRDOCUMENT & ",'" & SITEID & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenDynamic, adLockBatchOptimistic
    
    Set obtenervales = rs
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
Dim LStrMensajeError As String
Dim LVarNumeroError As Variant
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     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_FACTURACION.obtenertarjetasventas. xistereferecnias", LStrMensajeError
End Function

Public Function GenerarNotadeCredito(ByVal StrTipoDocuRef As String, ByVal DblNumeroDocuRef As Double, _
                                     ByVal DatFechaProceso As String, ByVal DatFechaDocumento As String, ByVal StrNseriesNc As String, ByVal StrNDocuNc As String, _
                                     ByVal StrTipodePago 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) As ADODB.Recordset
 
       
Dim rs As ADODB.Recordset
Dim StrSql As String
     
     On Error GoTo ErrorHandler
     
     Set rs = New ADODB.Recordset
    
     StrSql = " OP_EmitirNotaCreditoProc '" & StrTipoDocuRef & "'," & DblNumeroDocuRef & ",'" & DatFechaProceso & "','" & DatFechaDocumento & "','" & _
                                                      StrNseriesNc & "','" & StrNDocuNc & "','" & StrTipodePago & "'," & 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 & "'," & VarAux(1, 1) & "," & VarAux(1, 2)
                                                
      rs.Open StrSql, "Filedsn=conexionsies", adOpenStatic
                                                                                                    
      Set GenerarNotadeCredito = rs
      
     ''GetObjectContext.SetComplete

Exit Function
    
ErrorHandler:
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     
     GetObjectContext.SetAbort
     
     Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASGENERAL.GenerarNotadeCredito", Err.Description

End Function

Public Sub EliminarTemporalNotaCredito(ByVal DblCorrelativo As Double, Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " OP_EliminarTmpNotaCreditoProc " & DblCorrelativo
   
   Set cmd = New Command
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_FACTURACION.EliminarTemporalNotaCredito", LStrMensajeError
End Sub

Public Sub AnularNotaCredito(ByVal DblNumeroDocumento As Double, ByVal StrDOCTYPEID As String, _
                             ByVal StrSITEID As String, ByVal strcodcliente As String, ByVal StrCodMoneda As String, _
                             ByVal DblTotalPen As Double, ByVal DblTotalUsd As Double, ByVal IntContadoCredito, Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " OP_AnularNotadeCreditoProc '" & StrDOCTYPEID & "'," & DblNumeroDocumento & ",'" & _
                                              StrSITEID & "','" & strcodcliente & "','" & StrCodMoneda & "'," & _
                                              DblTotalPen & "," & DblTotalUsd & "," & IntContadoCredito
   
   Set cmd = New Command
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_FACTURACION.AnularNotaCredito", LStrMensajeError
End Sub

Public Function ObtenerNotadeCredito(ByVal DblNumeroDocumento As Double, ByVal DOCTYPEID As String, ByVal SITEID As String, Optional VarAux As Variant) As ADODB.Recordset

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = " Select OP_SALES.DATEDOC as FechaDocu ,OP_SALES.DATEPROCESALES as FechaProce," & _
             " OP_SALES.CURYRATE as TipoCambio,OP_SALES.custidss as CodCliente,OP_SALES.CURYID as Moneda, " & _
             " OP_SALES.DOCSTATUSID as EstadoDocu,TYPEPAYMENTID as TipodePago,OP_SALES.taxregnbr as Ruc," & _
             " OP_SALES.CUSTNAME as NomCliente ,CUSTOMER.addr1 as Direccion, " & _
             " OP_SALES.TOTALPEN as Totalpen,OP_SALES.TOTALUSD as TotalUsd,OP_SALES.SUBTOTALPEN as SubtotalPen,OP_SALES.SUBTOTALUSD as SubtotalUsd, " & _
             " OP_SALES.TAXIGVPEN as IgvPen,OP_SALES.TAXIGVUSD as IgvUsd,OP_SALES.TOTALNOTAFFECTPEN as NoAfectoPen,OP_SALES.TOTALNOTAFFECTUSD as NoAfectoUsd," & _
             " op_salesdet.SEQUENCE as Secuencia, INVTIDSKU, DESCRINVENTORY, SLSPRICESALE, QTY, PORCENTTAXIGV " & _
             " 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) " & _
             " LEFT JOIN CUSTOMER ON OP_SALES.custidss=CUSTOMER.custidss " & _
             " where op_sales.NBRDOCUMENT=" & DblNumeroDocumento & " and op_sales.DOCTYPEID='" & DOCTYPEID & "' and  " & _
             " op_sales.SITEID='" & SITEID & "'"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenStatic
    
    Set ObtenerNotadeCredito = rs
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
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_OP_FACTURACION.C_VENTASGENERAL.ObtenerNotadeCredito", LStrMensajeError
End Function
Public Function ObtenerDocumentoReferencia(ByVal DblNumeroDocumento As Double, ByVal StrDOCTYPEID As String, ByVal StrSITEID As String, Optional VarAux As Variant) As ADODB.Recordset

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim StrSql As String

On Error GoTo ErrorHandler
    
    StrSql = " Select NBRDOCUMENTREF,DESCR,DATEPROCESALES from (OP_DOCREFERENCE INNER JOIN DOCTYPE " & _
             " ON OP_DOCREFERENCE.DOCTYPEIDREF=DOCTYPE.DOCTYPEID) " & _
             " Inner join OP_SALES ON " & _
             " OP_DOCREFERENCE.DOCTYPEIDREF=OP_SALES.DOCTYPEID  AND " & _
             " OP_DOCREFERENCE.NBRDOCUMENTREF=OP_SALES.NBRDOCUMENT  AND " & _
             " OP_DOCREFERENCE.SITEID = OP_SALES.SITEID " & _
             " WHERE OP_DOCREFERENCE.DOCTYPEID='" & StrDOCTYPEID & "' AND " & _
             " OP_DOCREFERENCE.NBRDOCUMENT=" & DblNumeroDocumento & " AND " & _
             " OP_DOCREFERENCE.SITEID='" & StrSITEID & "' order by DESCR"
             
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Set con = New ADODB.Connection
    con.ConnectionString = "FILEDSN=conexionsies"
    con.Open
    rs.Open StrSql, con, adOpenStatic
    
    Set ObtenerDocumentoReferencia = rs
        
 ''GetObjectContext.SetComplete
 
Exit Function

ErrorHandler:
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_OP_FACTURACION.C_VENTASGENERAL.ObtenerDocumentoReferencia", LStrMensajeError
End Function
Public Function MostrarDocumentos(ByVal IntTodoslosAlmAcenes As Boolean, ByVal StrAlmacen As String, _
                                  ByVal StrTipoDocumento As String, ByVal DatFechaDesde As Date, _
                                  ByVal DatFechaHasta, Optional VarAux As Variant) As ADODB.Recordset
    
    Dim StrSql As String
    Dim StrAlmacenes As String
    Dim rs As ADODB.Recordset
    On Error GoTo TrataError
    
    If IntTodoslosAlmAcenes = True Then
       StrAlmacenes = ""
    Else
       StrAlmacenes = "AND OP_SALES.SITEID='" & StrAlmacen & "'"
    End If
    
    StrSql = " SELECT SITE.SITEID,SITE.NAME as Almacen, " & _
             " OP_SALES.DOCTYPEID,DOCTYPE.DESCR as Tipo_Doc,NBRDOCUMENT as Número " & _
             " ,DATEDOC as [Fec_Documento],DATEPROCESALES as [Fec_Proceso],DOCSTATUSID as Estado " & _
             " FROM (OP_SALES INNER JOIN DOCTYPE " & _
             " ON OP_SALES.DOCTYPEID=DOCTYPE.DOCTYPEID) INNER JOIN " & _
             " SITE ON OP_SALES.SITEID=SITE.SITEID " & _
             " WHERE OP_SALES.DOCTYPEID='" & StrTipoDocumento & "'" & _
               StrAlmacenes & " AND " & _
             " DATEPROCESALES Between '" & Format(DatFechaDesde, "yyyymmdd") & "' AND '" & Format(DatFechaHasta, "yyyymmdd") & "'"
    
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    Set MostrarDocumentos = 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_FACTURACION.MostrarDocumentos", Err.Description

End Function

Public Function MostrarNotadeCredito(ByVal IntTodoslosAlmAcenes As Boolean, ByVal StrAlmacen As String, _
                                     ByVal DatFechaDesde As Date, _
                                     ByVal DatFechaHasta, Optional VarAux As Variant) As ADODB.Recordset
    
    Dim StrSql As String
    Dim StrAlmacenes As String
    Dim rs As ADODB.Recordset
    On Error GoTo TrataError
    
    If IntTodoslosAlmAcenes = True Then
       StrAlmacenes = ""
    Else
       StrAlmacenes = "AND OP_SALES.SITEID='" & StrAlmacen & "'"
    End If
    
    StrSql = " SELECT SITE.SITEID,SITE.NAME as Almacen, " & _
             " OP_SALES.DOCTYPEID,DOCTYPE.DESCR as Tipo_Doc,NBRDOCUMENT as Número," & _
             " DATEDOC As Fec_Documento, DATEPROCESALES As Fec_Proceso, DOCSTATUSID As Estado " & _
             " FROM (OP_SALES INNER JOIN DOCTYPE " & _
             " ON OP_SALES.DOCTYPEID=DOCTYPE.DOCTYPEID) INNER JOIN " & _
             " SITE ON OP_SALES.SITEID=SITE.SITEID " & _
             " WHERE OP_SALES.DOCTYPEID=(Select DOCTYPEIDNC from op_setup) " & _
               StrAlmacenes & " AND " & _
             " DATEPROCESALES Between '" & Format(DatFechaDesde, "yyyymmdd") & "' AND '" & Format(DatFechaHasta, "yyyymmdd") & "'"
    
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenUnspecified, adLockUnspecified, adCmdUnspecified
    
    Set MostrarNotadeCredito = 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_FACTURACION.MostrarNotadeCredito", Err.Description

End Function

Public Function MostrarStatusParteDiario(ByVal StrAlmacen As String, Optional VarAux As Variant) As Boolean
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "select BATNBRDIARYSUMMARY from OP_SUMMARYDAY where SITEID='" & StrAlmacen & "' AND DATEPROCE=(Select DATEPROCE from setup)"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   If rs.EOF Then
      MostrarStatusParteDiario = False
   Else
      MostrarStatusParteDiario = True
   End If
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.MostrarStatusParteDiario", Err.Description
End Function

Public Function ObtenerTotales_TMP_AR_RESUMEN(ByVal DblCorrelativo As Double, ByVal IntSeleccionTodos As Integer, Optional VarAux As Variant) As ADODB.Recordset
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
                
   ' IntTodosSeleccion  1 resumen/ 0 seleccion
                
   If IntSeleccionTodos = 1 Then
      StrSql = " SELECT SUM(TOTALPENORI -TAXPENORI) AS SUBTOTALPENCAL," & _
               " SUM(TOTALUSDORI-TAXUSDORI) " & _
               " AS SUBTOTALUSDCAL FROM TMP_AR_RESUMEN " & _
               " WHERE CORRNBR=" & DblCorrelativo
   Else
     If IntSeleccionTodos = 0 Then
        StrSql = " SELECT SUM(TOTALPENORI -TAXPENORI) AS SUBTOTALPENCAL," & _
                 " SUM(TOTALUSDORI-TAXUSDORI) " & _
                 " AS SUBTOTALUSDCAL FROM TMP_AR_RESUMEN " & _
                 " WHERE CORRNBR=" & DblCorrelativo
     Else
        If IntSeleccionTodos = 2 Then
          StrSql = " SELECT SUM(TOTALPEN) AS TOTALPENCAL," & _
                   " SUM(TOTALUSD) " & _
                   " AS TOTALUSDCAL FROM TMP_AR_RESUMEN " & _
                   " WHERE CORRNBR=" & DblCorrelativo
        Else
           If IntSeleccionTodos = 3 Then
              StrSql = " SELECT SUM(TOTALPEN -TAXPEN) AS SUBTOTALPENCAL," & _
                       " SUM(TOTALUSD-TAXUSD) " & _
                       " AS SUBTOTALUSDCAL FROM TMP_AR_RESUMEN " & _
                       " WHERE CORRNBR=" & DblCorrelativo
           
           End If
        End If
     End If
   End If
                
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ObtenerTotales_TMP_AR_RESUMEN = rs
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.ObtenerTotales_TMP_AR_RESUMEN", Err.Description
End Function

Public Function ObtenerTotales_TMP_AR_SALES(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 " & _
           " from tmp_ar_sales where CORRNBR =" & DblCorrelativo
                         
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
  Set ObtenerTotales_TMP_AR_SALES = 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.ObtenerTotales_TMP_AR_SALES", Err.Description
        
End Function

Public Sub GrabarItemdeRedondeo(ByVal StrCara As String, ByVal DblCorrelativo As Double, _
                                ByVal StrTipoDocumento As String, _
                                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 DblTotalBaseOri As Double, ByVal DblTotalExtOri As Double, _
                                ByVal MontoImpuestoBase As Double, ByVal MontoImpuestoExt As Double, _
                                ByVal MontoImpuestoBaseOri As Double, ByVal MontoImpuestoExtOri As Double, _
                                ByVal DblSubtotalBase As Double, ByVal DblSubtotalExt As Double, ByVal DblNoAfectoBase As Double, ByVal DblNoAfectoUsd 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, _
                                ByVal StrRedondeo As String, Optional VarAux As Variant)
    
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
        
   StrSql = " AR_GrabarRegistroenDetalleTempProc '" & StrCara & "'," & DblCorrelativo & ",'" & StrTipoDocumento & "'," & _
                                IntNumeroDocumento & ",'" & StrCodigoArticulo & "','" & _
                                StrCodigoMoneda & "'," & IntCierreZ & "," & IntCierreX & "," & IntNumeroTurno & ",'" & _
                                StrNumeroTransacion & "'," & DblDescuento1 & "," & DblDescuento2 & "," & _
                                DblDesMonBase & "," & DblDesMonExtranjera & "," & DBlPorcentajeIgv & "," & _
                                DBlPorcentajeISC & "," & DblTotalBase & "," & DblTotalExt & "," & _
                                DblTotalBaseOri & "," & DblTotalExtOri & "," & MontoImpuestoBase & "," & MontoImpuestoExt & "," & _
                                MontoImpuestoBaseOri & "," & MontoImpuestoExtOri & "," & DblSubtotalBase & "," & DblSubtotalExt & "," & _
                                DblNoAfectoBase & "," & DblNoAfectoUsd & "," & IntInventariable & "," & IntTomadeInventario & "," & _
                                DblPrecioVenta & "," & DblPrecioFactu & "," & DblCostoBase & "," & DblCostoExt & ",'" & _
                                StrCodigoBarra & "','" & StrDescripcion & "'," & DblCantidad & ",'" & StrUserid & "'," & IntKit & "," & _
                                IntCombustible & ",'" & StrPtoVta & "','" & StrUnidadMedida & "','" & StrRedondeo & "'"

   Set cmd = New Command
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_FACTURACION.GrabarItemdeRedondeo", LStrMensajeError

End Sub

Public Function ExistenNoafectos_TMP_AR_RESUMEN(ByVal DblCorrelativo As Double, Optional VarAux As Variant) As Boolean
  Dim rs As ADODB.Recordset
  Dim StrSql As String
    
  On Error GoTo TrataError
  
  StrSql = " Select SUM(NOAFECTOPEN) AS NOAFECTOBASE,SUM(NOAFECTOUSD) AS NOAFECTOEXT " & _
           " from tmp_ar_RESUMEN where CORRNBR =" & DblCorrelativo
                         
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
     
     If rs!NOAFECTOBASE = 0 And rs!NOAFECTOEXT = 0 Then
       ExistenNoafectos_TMP_AR_RESUMEN = False
     Else
       ExistenNoafectos_TMP_AR_RESUMEN = True
     End If
     
    ''GetObjectContext.SetComplete
    
  Exit Function
    
TrataError:
    
     If Not rs Is Nothing Then
        Set rs = Nothing
     End If
     
     GetObjectContext.SetAbort
     
     Err.Raise Err.Number, "DB_AR_CUENTASCOBRAR.ExistenNoafectos_TMP_AR_RESUMEN", Err.Description
        
End Function

Public Sub LimpiarTemporalRegVentas(Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim StrSql As String

On Error GoTo ErrorHandler
    
   StrSql = " OP_LimpiarTemporalRegVentasProc "
   
   Set cmd = New Command
   cmd.CommandText = StrSql
       
   Set con = New Connection
   con.Open "FILEDSN=conexionsies"
   cmd.ActiveConnection = con
   cmd.Execute
      
 ''GetObjectContext.SetComplete
 
Exit Sub

ErrorHandler:
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_FACTURACION.LimpiarTemporalRegVentas", LStrMensajeError
     
End Sub

Public Function ObtenerDocumentosVencidosVG(ByVal StrCodigoCliente As String, Optional VarAux As Variant) As ADODB.Recordset
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "Op_ObtenerDocmuentosVencidosProc '" & StrCodigoCliente & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ObtenerDocumentosVencidosVG = rs
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
   
   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASGENERAL.ObtenerDocumentosVencidos.ObtenerDocumentosVencidosVG", 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
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " OP_ListarDocumentos_NC " & VarAux1(1, 1) & "," & VarAux1(1, 2) & ",'" & VarAux1(1, 3) & "','" & _
                                         VarAux1(1, 4) & "','" & VarAux1(1, 5) & "','" & VarAux1(1, 6) & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set Auxiliar1 = rs
      
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
   
   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASGENERAL.Auxiliar1", Err.Description
   
End Function

Public Function Auxiliar2(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
    On Error GoTo TrataError
      
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    If VarAux2 = 0 Then
        StrSql = " EXEC TMP_OP_DOCUMENTNCUpdProc " & VarAux1(1, 1) & "," & _
                                               VarAux1(1, 2) & "," & VarAux1(1, 3) & "," & VarAux1(1, 4)
        rs.Open StrSql, con, adOpenStatic
        Set Auxiliar2 = rs
    Else
        rs.Open "SELECT count(*) as CantReg,SUM(TOTALPEN) AS TOT FROM TMP_OP_DOCUMENTNC WHERE CORRNBR=" & VarAux1 & " AND SELECTED=1", con, adOpenStatic
        'Auxiliar2 = IIf(IsNull(rs!tot), 0, rs!tot)
        Set Auxiliar2 = rs
    End If
    
    ''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_OP_FACTURACION.C_VENTASGENERAL.Auxiliar2", LStrMensajeError

End Function

Public Function Auxiliar3(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    Dim con As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim StrSql As String
    
    On Error GoTo TrataError
      
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"
    
    Set cmd = New ADODB.Command
    Set cmd.ActiveConnection = con
    
    cmd.CommandTimeout = 0
    cmd.CommandText = " EXEC JUNTADETALLES_NC_PROC " & VarAux1(1, 1) & "," & _
                                               VarAux1(1, 2)
    cmd.Execute
    
    ''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 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 Err.Number, "DB_OP_FACTURACION.C_VENTASGENERAL.Auxiliar3", Err.Description
End Function

Public Function Auxiliar4(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    On Error GoTo TrataError
    
    rs.Open "select * from customer where custidss='" & VarAux1 & "'", "FILEDSN=conexionsies", adOpenStatic
    
    Set Auxiliar4 = rs
    
    ''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 Err.Number, "DB_OP_FACTURACION.C_VENTASGENERAL.Auxiliar3", Err.Description
End Function


Public Function Auxiliar5(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    Dim con As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim StrSql As String
    
    On Error GoTo TrataError
      
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"
    
    Set cmd = New ADODB.Command
    Set cmd.ActiveConnection = con
    
    cmd.CommandText = " ACTUALIZA_TODO_TMP_DET_NC " & VarAux1(1, 1) & "," & _
                                               VarAux1(1, 2)
    cmd.Execute
    
    ''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 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 Err.Number, "DB_OP_FACTURACION.C_VENTASGENERAL.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_VENTASGENERAL.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_VENTASGENERAL.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_VENTASGENERAL.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_VENTASGENERAL.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_VENTASGENERAL.Auxiliar10", Err.Description
End Function










Public Function ObtenerCredito(ByVal StrCliente As String, ByVal StrProducto As String, Optional VarAux As Variant) As ADODB.Recordset
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = "ObtenerCredito '" & _
                                StrCliente & "','" & _
                                StrProducto & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
            
   
    Set ObtenerCredito = rs

         
ProcesoCulminado:
   ''GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASGENERAL", Err.Description
End Function

