Attribute VB_Name = "C_VENTASPLAYA"
Public Function Verificar_ExisteVale(ByVal strcodcliente As String, ByVal DblVale As Double, 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_ExisteVale '" & strcodcliente & "', " & DblVale
   
 Set rs = New ADODB.Recordset
 rs.CursorLocation = adUseClient
 rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
   
 If rs.EOF Then
    Verificar_ExisteVale = False
 Else
    Verificar_ExisteVale = 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_ExisteVale", Err.Description
  
End Function
Public Function ObtenerDocumentosVencidos(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 ObtenerDocumentosVencidos = 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.ObtenerDocumentosVencidos", Err.Description
End Function

Public Function ObtenerDatosTemporal(ByVal DblCorrelativo As Double, ByVal IntRedondeo 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
             
   StrSql = "OP_MostrarDetalleVentasCombProc " & DblCorrelativo & "," & IntRedondeo
                
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ObtenerDatosTemporal = 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.ObtenerDatosTemporal", 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 VerificarPlacadeCliente(ByVal strcodcliente As String, ByVal StrPlaca 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 BADGE from op_custbadge where CUSTIDSS='" & strcodcliente & "' and " & _
            " BADGE='" & StrPlaca & "'"
   
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   If rs.EOF Then
      VerificarPlacadeCliente = False
   Else
      VerificarPlacadeCliente = 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.VerificarPlacadeCliente", Err.Description
End Function

Public Function VerificarValedeCliente(ByVal strcodcliente As String, ByVal IntVale As Double, 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 NBRBONUS from op_bonus where CUSTIDSS='" & strcodcliente & "' and " & _
            " NBRBONUS=" & IntVale
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   If rs.EOF Then
      VerificarValedeCliente = False
   Else
      VerificarValedeCliente = 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_FACTURACIONS.VerificarValedeCliente", Err.Description
End Function
Public Function GrabarenCabeceraenTemporal(ByVal IntContadoCred As Integer, ByVal StrCara As String, ByVal DblCorrelativo As Double, ByVal IntNumeroDocumento As Integer, _
                                           ByVal strtipopago As String, 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 IntTipoCliente As Integer, _
                                           ByVal StrDesTipoCliente As String, ByVal StrIdEstado As String, ByVal StrDescEstado As String, ByVal StrMonedaCredito As String, ByVal strTipoCambio As String, ByVal DblMontoTipoCamb As Double, _
                                           ByVal IntDiasGracias As Integer, ByVal DblLimitCred As Double, ByVal DblDeuda As Double, ByVal DblExtra As Double, ByVal IntAfecto As Integer, ByVal StrCodigoTarj As String, ByVal StrNumeroTarj As String, _
                                           ByVal StrCodMonedaTarj As String, ByVal StrDescripcionTarjeta As String, Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command
                    
cmd.CommandText = " OP_GrabarDocumnetoenTemporalProc " & IntContadoCred & ",'" & StrCara & "'," & DblCorrelativo & "," & IntNumeroDocumento & ",'" & _
                                                       strtipopago & "','" & StrCodigoMoneda & "','" & StrcodigoVendedor & "','" & StrCodigoUsuario & "','" & _
                                                       StrImpuesto1 & "','" & StrImpuesto2 & "'," & DblTotalMonBase & "," & DblTotalMonExt & "," & _
                                                       DblSubTotMonBase & "," & DblSubTotMonExt & "," & DblMontoImp1MonBase & "," & DblMontoImp2MonBase & "," & _
                                                       DblMontoImp1MonExt & "," & 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 & "'," & IntTipoCliente & ",'" & _
                                                       StrDesTipoCliente & "','" & StrIdEstado & "','" & StrDescEstado & "','" & StrMonedaCredito & "','" & strTipoCambio & "'," & _
                                                       DblMontoTipoCamb & "," & IntDiasGracias & "," & DblLimitCred & "," & DblDeuda & "," & DblExtra & "," & IntAfecto & ",'" & _
                                                       StrCodigoTarj & "','" & StrNumeroTarj & "','" & StrCodMonedaTarj & "','" & StrDescripcionTarjeta & "'"

Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.GrabarenCabeceraenTemporal", LStrMensajeError

End Function

Public Function GrabarRegistroenDetalleTemporal(ByVal StrCara As String, ByVal DblCorrelativo As Double, _
                                                ByVal IntNumeroDocumento As Integer, ByVal StrCodigoArticulo As String, _
                                                ByVal StrCodigoMoneda As String, ByVal IntCierreZ As Integer, _
                                                ByVal IntCierreX As Integer, ByVal IntNumeroTurno As Integer, _
                                                ByVal StrNumeroTransacion As String, ByVal DblDescuento1 As Double, ByVal DblDescuento2 As Double, _
                                                ByVal DblDesMonBase As Double, ByVal DblDesMonExtranjera As Double, ByVal DBlPorcentajeIgv As Double, _
                                                ByVal DBlPorcentajeISC As Double, ByVal DblTotalBase As Double, ByVal DblTotalExt As Double, _
                                                ByVal MontoImpuestoBase As Double, ByVal MontoImpuestoExt As Double, ByVal IntInventariable As Integer, _
                                                ByVal IntTomadeInventario As Integer, ByVal DblPrecioVenta As Double, ByVal DblPrecioFactu As Double, _
                                                ByVal DblCostoBase As Double, ByVal DblCostoExt As Double, _
                                                ByVal StrCodigoBarra As String, ByVal StrDescripcion As String, ByVal DblCantidad As Double, _
                                                ByVal StrUserid As String, ByVal IntKit As Integer, ByVal IntCombustible As Integer, ByVal StrPtoVta As String, ByVal StrUnidadMedida As String, ByVal IntDescI As Integer, ByVal IntDesD As Integer, ByVal IntDescIDP As Integer, ByVal DblDISCMTOPENDI As Double, ByVal DblDISCMTOPEND As Double, Optional VarAux As Variant)
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command
                    
cmd.CommandText = " Op_GrabarRegistroenDetalleTempProc '" & StrCara & "'," & DblCorrelativo & "," & IntNumeroDocumento & ",'" & _
                                                        StrCodigoArticulo & "','" & StrCodigoMoneda & "'," & IntCierreZ & "," & _
                                                        IntCierreX & "," & IntNumeroTurno & ",'" & StrNumeroTransacion & "'," & DblDescuento1 & "," & _
                                                        DblDescuento2 & "," & DblDesMonBase & "," & DblDesMonExtranjera & "," & DBlPorcentajeIgv & "," & _
                                                        DBlPorcentajeISC & "," & DblTotalBase & "," & DblTotalExt & "," & MontoImpuestoBase & "," & _
                                                        MontoImpuestoExt & "," & IntInventariable & "," & IntTomadeInventario & "," & DblPrecioVenta & "," & _
                                                        DblPrecioFactu & "," & DblCostoBase & "," & DblCostoExt & ",'" & StrCodigoBarra & "','" & StrDescripcion & "'," & DblCantidad & ",'" & _
                                                        StrUserid & "'," & IntKit & "," & IntCombustible & ",'" & StrPtoVta & "','" & StrUnidadMedida & "'," & IntDescI & "," & IntDesD & "," & IntDescIDP & "," & DblDISCMTOPENDI & "," & DblDISCMTOPEND


Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.GrabarRegistroenDetalleTemporal", LStrMensajeError

End Function


Public Function VerificarTransacPendientes(ByVal StrNumerodeCara 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 NBRSIDE from tmp_op_sales where NBRSIDE='" & StrNumerodeCara & "'"
              
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   If rs.EOF Then
      VerificarTransacPendientes = False
   Else
      VerificarTransacPendientes = 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.ObtenerDatosTemporal", Err.Description
End Function

Public Function ObtenerListadodeArticulos(StrCodigoAlmacen As String, StrCodigoMoneda 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_ListadodeArticulosProc '" & StrCodigoAlmacen & "','" & StrCodigoMoneda & "'"
              
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ObtenerListadodeArticulos = 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.ObtenerDatosTemporal", Err.Description
End Function

Public Function EliminarRegistroenDetalleTemporal(ByVal DblCorrelativo As Double, ByVal IntSecuencia As Integer, Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command
'OP_EliminarTodosRegistroDetalleProc
cmd.CommandText = " Op_EliminarRegistroenDetalleTempProc " & DblCorrelativo & "," & IntSecuencia


Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.EliminarRegistroenDetalleTemporal", LStrMensajeError

End Function

Public Function ActualizarRegistroenDetalleTemporal(ByVal DblCorrelativo As Double, ByVal StrCodigoArticulo As String, _
                                                    ByVal IntSecuencia As Integer, ByVal StrCodigoMoneda As String, ByVal DBlPorcentajeIgv As Double, _
                                                    ByVal DBlPorcentajeISC As Double, ByVal DblTotalBase As Double, ByVal DblTotalExt As Double, _
                                                    ByVal MontoImpuestoBase As Double, ByVal MontoImpuestoExt As Double, ByVal IntInventariable As Integer, _
                                                    ByVal IntTomadeInventario As Integer, ByVal DblPrecioVenta As Double, ByVal DblPrecioFactu As Double, _
                                                    ByVal StrCodigoBarra As String, ByVal DblCantidad As Double, ByVal BolDescI As Integer, ByVal BolDescD As Integer, BolDescIDP As Integer, _
                                                    ByVal DblDescSolesI As Double, ByVal DblDescDolaresI As Double, ByVal DblDescSolesD As Double, ByVal DblDescDolaresD As Double, ByVal DblPorcDesc As Double, Optional VarAux As Variant)
                                                    
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command
                    
cmd.CommandText = " Op_ActualizarRegistroenDetalleTempProc " & DblCorrelativo & ",'" & StrCodigoArticulo & "'," & _
                                                                IntSecuencia & ",'" & StrCodigoMoneda & "'," & DBlPorcentajeIgv & "," & _
                                                                DBlPorcentajeISC & "," & DblTotalBase & "," & DblTotalExt & "," & _
                                                                MontoImpuestoBase & "," & MontoImpuestoExt & "," & IntInventariable & "," & _
                                                                IntTomadeInventario & "," & DblPrecioVenta & "," & DblPrecioFactu & ",'" & _
                                                                StrCodigoBarra & "'," & DblCantidad & " ," & BolDescI & "," & BolDescD & "," & BolDescIDP & "," & DblDescSolesI & "," & DblDescDolaresI & "," & DblDescSolesD & " , " & DblDescDolaresD & "," & DblPorcDesc & ""



Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.ActualizarRegistroenDetalleTemporal", LStrMensajeError

End Function

Public Function ActualizarRegistroCreditoTemporal(ByVal DblCorrelativo As Double, ByVal StrCodigoArticulo As String, ByVal IntSecuencia As Integer, _
                                                    ByVal DBlPorcentajeIgv As Double, ByVal DBlPorcentajeISC As Double, ByVal DblTotalBase As Double, _
                                                    ByVal DblTotalExt As Double, ByVal MontoImpuestoBase As Double, ByVal MontoImpuestoExt As Double, _
                                                    ByVal BolDescI As Integer, ByVal BolDescD As Integer, BolDescIDP As Integer, ByVal DblDescSolesI As Double, _
                                                    ByVal DblDescDolaresI As Double, ByVal DblDescSolesD As Double, ByVal DblDescDolaresD As Double, _
                                                    ByVal DblPorcDesc As Double, Optional VarAux As Variant)
                                                    
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command
                    
cmd.CommandText = " Op_ActualizarCreditoTempProc " & DblCorrelativo & ",'" & StrCodigoArticulo & "'," & IntSecuencia & ", " & _
                                                                DBlPorcentajeIgv & "," & DBlPorcentajeISC & "," & DblTotalBase & "," & _
                                                                DblTotalExt & "," & MontoImpuestoBase & "," & MontoImpuestoExt & "," & _
                                                                BolDescI & "," & BolDescD & "," & BolDescIDP & "," & DblDescSolesI & "," & _
                                                                DblDescDolaresI & "," & DblDescSolesD & " , " & DblDescDolaresD & "," & DblPorcDesc & ""



Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.ActualizarRegistroenDetalleTemporal", LStrMensajeError

End Function


Public Function ListarDatosCabeceraTemporal(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
   'select CORRNBR from TMP_OP_SALES where NBRSIDE=@NBRSIDE
   StrSql = " SELECT CORRNBR,NBRSIDE AS Cara,TAXREGNBR as RUC,CUSTNAME as Razon_Social," & _
            " CASE TYPEPAYMENTID WHEN '01' THEN 'EFECTIVO' " & _
            " WHEN '02' THEN 'TARJETA DE CREDITO' " & _
            " WHEN '06' THEN 'CREDITO' " & _
            " WHEN '14' THEN 'ADELANTO' " & _
            " Else 'OTROS' END  AS [Tipo_de_Pago] " & _
            " FROM TMP_OP_SALES "
                
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ListarDatosCabeceraTemporal = 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.ObtenerDatosCabeceraTemporal", Err.Description
End Function

Public Function ObtenerDatosCabeceraTemporal(ByVal DblCorrelativo As Double, 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 TMP_OP_SALES WHERE CORRNBR=" & DblCorrelativo
                              
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ObtenerDatosCabeceraTemporal = 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.ObtenerDatosCabeceraTemporal", Err.Description
End Function

Public Function ActualizarenCabeceraenTemporal(ByVal IntContadoCred As Integer, ByVal StrCara As String, ByVal DblCorrelativo As Double, _
                                               ByVal strtipopago As String, 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 IntTipoCliente As Integer, _
                                               ByVal StrDesTipoCliente As String, ByVal StrIdEstado As String, ByVal StrDescEstado As String, ByVal StrMonedaCredito As String, ByVal strTipoCambio As String, ByVal DblMontoTipoCamb As Double, _
                                               ByVal IntDiasGracias As Integer, ByVal DblLimitCred As Double, ByVal DblDeuda As Double, ByVal DblExtra As Double, ByVal IntAfecto As Integer, _
                                               ByVal StrCodigoTarj As String, ByVal StrNumeroTarj As String, ByVal StrCodMonedaTarj As String, ByVal StrDescTarjeta As String, Optional VarAux As Variant)
'ActualizarenCabeceraenTemporal

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command

cmd.CommandText = " OP_ActualizarDocumnetoenTemporalProc " & IntContadoCred & ",'" & StrCara & "'," & DblCorrelativo & ",'" & _
                                                       strtipopago & "','" & StrCodigoMoneda & "','" & StrcodigoVendedor & "','" & StrCodigoUsuario & "','" & _
                                                       StrImpuesto1 & "','" & StrImpuesto2 & "'," & DblTotalMonBase & "," & DblTotalMonExt & "," & _
                                                       DblSubTotMonBase & "," & DblSubTotMonExt & "," & DblMontoImp1MonBase & "," & DblMontoImp2MonBase & "," & _
                                                       DblMontoImp1MonExt & "," & 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 & "'," & IntTipoCliente & ",'" & _
                                                       StrDesTipoCliente & "','" & StrIdEstado & "','" & StrDescEstado & "','" & StrMonedaCredito & "','" & strTipoCambio & "'," & _
                                                       DblMontoTipoCamb & "," & IntDiasGracias & "," & DblLimitCred & "," & DblDeuda & "," & DblExtra & "," & IntAfecto & ",'" & _
                                                       StrCodigoTarj & "','" & StrNumeroTarj & "','" & StrCodMonedaTarj & "','" & StrDescTarjeta & "'"

Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.OP_ActualizarDocumnetoenTemporalProc", LStrMensajeError

End Function

Public Function EliminarTransTemporal(ByVal DblCorrelativo As Double)
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command

cmd.CommandText = " Op_EliminarTransTemporalProc " & DblCorrelativo

Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.EliminarTransTemporal", LStrMensajeError

End Function

Public Function ListarTransacPendientesTemp(ByVal StrCara 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 = " select CORRNBR,CURYID,CURYTYPEID,CUSTIDSS,CUSTNAME,TAXREGNBR,ADDRESS,AFECTO,TYPEPAYMENTID " & _
            " from TMP_OP_SALES where NBRSIDE='" & StrCara & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ListarTransacPendientesTemp = 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.ListarTransacPendientesTemp", Err.Description
End Function

Public Function ListarTransacPendientesDetTemp(ByVal MDblCorrelativo As Double, ByVal StrCodigoArticulo 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 = " select CORRNBR,SEQUENCE " & _
            " from TMP_OP_SALESDET where INVTIDSKU='" & StrCodigoArticulo & "' and  CORRNBR=" & MDblCorrelativo & ""
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ListarTransacPendientesDetTemp = 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.ListarTransacPendientesTemp", Err.Description
End Function


Public Function ObtenerDatosdeArticulo(ByVal StrCodigoCliente As String, ByVal StrCodigoArticulo 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 & "','" & StrCodigoArticulo & "'"
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ObtenerDatosdeArticulo = 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.ObtenerDatosdeArticulo", Err.Description
End Function

Public Function EmitirDocumentodeVenta(ByVal StrCara As String, ByVal StrNumeroTrans As String, ByVal IntRecibeTotales As Integer, ByVal IntEnlazado As Integer, ByVal IntContadoCred As Integer, ByVal DblCorrelativo As Double, _
                                       ByVal strtipopago As String, 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 cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR
Dim StrSql As String
Dim StrNumeroDocumento As String


On Error GoTo ErrorHandler ''' grava
 
Set rs = New ADODB.Recordset

'StrCodigoMoneda = "PEN"
'strTIPOPAGO = "01"
           
StrSql = " OP_EmitirDocumentodeVentaProc " & IntRecibeTotales & "," & IntEnlazado & "," & IntContadoCred & "," & DblCorrelativo & ",'" & _
                                            strtipopago & "','" & 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) & "','" & VarAux(1, 3) & "','" & VarAux(1, 4) & "','" & VarAux(1, 5) & "','" & _
                                            VarAux(1, 6) & "','" & VarAux(1, 7) & "','" & VarAux(1, 8) & "','" & VarAux(1, 9) & "','" & VarAux(1, 10) & "'"
'rs.CursorLocation = adUseClient
rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic

   
        

''con.Open "FILEDSN=conexionsies"
 'Dim LobjDispensador As DB_UT_MANTENIMIENTOS.C_DISPENSADORES
 'Set LobjDispensador = GetObjectContext.CreateInstance("DB_UT_MANTENIMIENTOS.C_DISPENSADORES")
 'LobjDispensador.ActualizarEstadoTransa(StrCara,StrNumeroTrans,StrNumeroDocumento)

' Parte que Actualiza las Caras
If Trim(StrCara) <> Empty Then
 If Not rs.EOF Then
    If Trim(rs!numerodocumento) <> Empty Then
       If Trim(rs!STATUSSTOCK) = Empty And Trim(rs!TOMAINVENTARIO) = Empty Then
          ' No se Hace Nada
       Else
        If Trim(rs!STATUSSTOCK) = "SNEGATIVO" Or Trim(rs!TOMAINVENTARIO) = "IFISICO" Then
          'Hay que Eliminar la transaccion del tmp_opsalesdet
           StrSql = "OP_EliminarRegistroDetalleProc '" & StrNumeroTrans & "'"
           Set con = New ADODB.Connection
           con.Open "FILEDSN=conexionsies"
           Set cmd = New ADODB.Command
           Set cmd.ActiveConnection = con
           cmd.CommandText = StrSql
           cmd.Execute
        End If
       End If
    End If
    Set EmitirDocumentodeVenta = rs
 Else
      Err.Raise Err.Number, "DB_OP_FACTURACION.DB_OP_FACTURACION.EmitirDocumentodeVenta", "No se pudo Obtener Número de Documento"
 End If
Else
  Set EmitirDocumentodeVenta = rs
End If
'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 rs Is Nothing Then
        LStrMensajeError = Err.Description
        LVarNumeroError = Err.Number
        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.EmitirDocumentodeVenta", LStrMensajeError

End Function
Public Function LimpiarTemporalCombustible(ByVal StrPuntodeVenta As String, Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command

cmd.CommandText = " OP_LimpiarTemporalesVentasCombProc '" & StrPuntodeVenta & "'"

Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.LimpiarTemporalCombustible", LStrMensajeError

End Function

Public Function ExisteArticuloenDetalle(ByVal StrCodigoArticulo As String, ByVal DblCorrelativo As Double, 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 INVTIDSKU from TMP_OP_SALESDET where INVTIDSKU='" & StrCodigoArticulo & "' and CORRNBR=" & DblCorrelativo
   
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   If rs.EOF Then
     ExisteArticuloenDetalle = False
   Else
     ExisteArticuloenDetalle = 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.ExisteArticuloenDetalle", Err.Description
End Function

Public Function EliminarTodosRegDetalleTemporal(ByVal DblCorrelativo As Double, Optional VarAux As Variant)

Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command

cmd.CommandText = " OP_EliminarTodosRegistroDetalleProc " & DblCorrelativo

Set con = New ADODB.Connection
con.Open "FILEDSN=conexionsies"

Set 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.EliminarTodosRegDetalleTemporal", LStrMensajeError

End Function

Public Function EliminarRegistrosenBlanco(ByVal StrCara As String, Optional VarAux As Variant)
Dim cmd As ADODB.Command
Dim con As ADODB.Connection
Dim ERROR As ADODB.ERROR

On Error GoTo ErrorHandler
 
Set cmd = New ADODB.Command

cmd.CommandText = " DELETE FROM TRAN" & Trim(StrCara) & _
                  " WHERE NUMERO='' OR SOLES='' OR PRODUCTO='' OR PRECIO='' OR GALONES='' OR CARA='' "

Set con = New ADODB.Connection
con.Open "FILEDSN=GASBOY"

Set 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.EliminarRegistrosenBlanco", LStrMensajeError

End Function

Public Function ObtenerDatosTemporalparaImpresion(ByVal DblCorrelativo As Double, 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 SEQUENCE,INVTIDSKU,DESCRINVENTORY,QTY,SLS_PRICE,SLSPRICESALE,TOTALPEN,TOTALUSD " & _
            " FROM  TMP_OP_SALESDET WHERE CORRNBR=" & DblCorrelativo
                
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                
   Set ObtenerDatosTemporalparaImpresion = 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.ObtenerDatosTemporalparaImpresion", Err.Description
End Function

Public Function ObtenerTurnoaCambiar(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 = " Select SALESPERSONTURN,QTYSALESPERSONTURN from setup "
                
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                   
   If Not rs.EOF Then
     'If rs!salespersonturn + 1 > rs!QTYSALESPERSONTURN Then
     '   ObtenerTurnoaCambiar = 1
     'Else
     '   ObtenerTurnoaCambiar = rs!salespersonturn + 1
     'End If
      ObtenerTurnoaCambiar = rs!salespersonturn
   Else
     ObtenerTurnoaCambiar = -1
   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.ObtenerTurnoaCambiar", Err.Description
End Function

Public Function ObtenerVendedordeCara(StrCara 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 = " SELECT OP_TURNVSSIDE.SALESPERID AS SALESPERID,op_salesperson.ACCESSUSERID AS USERID,SALESPERNAME " & _
            " FROM OP_TURNVSSIDE INNER JOIN op_salesperson " & _
            " ON OP_TURNVSSIDE.SALESPERID=op_salesperson.SALESPERID " & _
            " WHERE OP_TURNVSSIDE.SITEID=(SELECT SOURCESITE FROM SETUP) AND " & _
            " DATEPROCE=(SELECT DATEPROCESALES FROM OP_SETUP) AND " & _
            " NUMBERTURN=(SELECT SALESPERSONTURN FROM SETUP) AND  SIDE='" & StrCara & "' AND STATUS=1"
                                     
                                     
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                         
  
   Set ObtenerVendedordeCara = 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.ObtenerVendedordeCara", Err.Description
   
End Function

Public Function Validarvendedor(ByVal StrCodigoUsuario As String, Optional 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 UCase(Trim(rs!PASSWORD)) <> UCase(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
            
 '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 Sub ActualizarTurno(Optional VarAux As Variant)
   Dim StrSql As String
   Dim cmd As ADODB.Command
   
   StrSql = " OP_ACTUALIZAR_TURNO_Proc "
   
   Set con = New ADODB.Connection
   con.Open "FILEDSN=conexionsies"
   
   Set cmd = New ADODB.Command
   Set cmd.ActiveConnection = con
   cmd.CommandText = StrSql
   cmd.Execute
      
   'GetObjectContext.SetComplete
   Exit Sub
errhandler:
   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.ActualizarTurno", Err.Description
   
End Sub


Public Function ObtenerTurnoActual(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 = " Select SALESPERSONTURN from setup "
                
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                   
   If rs.EOF Then
      ObtenerTurnoActual = -1
   Else
      ObtenerTurnoActual = rs!salespersonturn
   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.ObtenerTurnoActual", Err.Description
End Function

Public Sub GrabarenTranSql(ByVal StrNumero As String, ByVal StrSoles As String, ByVal StrProducto As String, _
                           ByVal StrPrecio As String, ByVal StrGalones As String, ByVal StrCara As String, _
                           ByVal strFecha As String, ByVal StrHora As String, ByVal strTurno As String, _
                           ByVal StrEstado As String, ByVal DblDocumento As Double, Optional VarAux As Variant)
   Dim StrSql As String
   Dim con As ADODB.Connection
   Dim cmd As ADODB.Command
    
   On Error GoTo errhandler
   
   StrSql = "OP_GrabarDatosenTran '" & StrNumero & "','" & StrSoles & "','" & StrProducto & "','" & _
                                       StrPrecio & "','" & StrGalones & "','" & StrCara & "','" & _
                                       strFecha & "','" & StrHora & "','" & strTurno & "','" & _
                                       StrEstado & "'," & DblDocumento
  
                     
   Set con = New ADODB.Connection
   con.Open "FILEDSN=conexionsies"
   
   Set cmd = New ADODB.Command
   Set cmd.ActiveConnection = con
   cmd.CommandText = StrSql
   cmd.Execute
   
   
   'GetObjectContext.SetComplete
   Exit Sub
errhandler:
    
    If Not cmd Is Nothing Then
       Set cmd = Nothing
    End If

   GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.GrabarenTranSql", Err.Description
End Sub
Public Function ExisteTran(ByVal StrNumero As String, ByVal StrProducto As String, _
                           ByVal StrGalones As String, ByVal StrCara As String, _
                           ByVal strFecha As String, ByVal StrHora As String, ByVal strTurno As String, Optional VarAux As Variant) As Boolean
                           
   Dim StrSql As String
   
   Dim rs As ADODB.Recordset
    
   On Error GoTo errhandler
   
   StrSql = " Select NUMERO from OP_TRAN where numero='" & StrNumero & "' and producto='" & StrProducto & "' and galones='" & StrGalones & "' " & _
            " and cara='" & StrCara & "' and fecha='" & strFecha & "' and hora='" & StrHora & "' and turno='" & strTurno & "'"
  
                     
   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
                   
   If rs.EOF Then
      ExisteTran = False
   Else
      ExisteTran = 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.ExisteTran", Err.Description
End Function

Public Function Cargar_Datos_Impresora(ByVal StrPuntoVenta As String, Optional VarAux As Variant) As ADODB.Recordset
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    Dim PrinterTypeID As String
    
On Error GoTo errhandler

    StrSql = " SELECT OP_SALESPOINTSETTING.PRINTERTYPEID,DESCRPRINTER,JUMPLINES,IDCUTPAPER,WIDELINES " & _
             " FROM OP_SALESPOINTSETTING INNER JOIN OP_PRINTERTYPE ON " & _
             " OP_SALESPOINTSETTING.PrinterTypeID = OP_PRINTERTYPE.PrinterTypeID " & _
             " WHERE SALESPOINT='" & StrPuntoVenta & "'"

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

Public Function FaltanCierreX(Optional VarAux As Variant) As ADODB.Recordset
  Dim rs As ADODB.Recordset
  Dim StrSql As String
  
On Error GoTo errhandler
      
  StrSql = "Select SALESPOINT FROM OP_SALESPOINTSETTING where BUSINESSTYPE=1 and STKTURNOK=0 "
  
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
   
  Set FaltanCierreX = 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_VENTASPLAYA.FaltanCierreX", Err.Description
End Function

Public Sub GrabarVale_Temporal(ByVal DblCorrelativo As Double, ByVal strcodcliente As String, _
                               ByVal DblVale As Double, StrDOCTYPEID As String, _
                               ByVal DblDocumento As Double, ByVal DblMontoVale As Double, _
                               Optional VarAux As Variant)

 Dim con As ADODB.Connection
 Dim cmd As ADODB.Command
 Dim StrSql As String
  
 On Error GoTo errhandler
   
 StrSql = "OP_GrabarTmp_Op_BonusProc " & DblCorrelativo & ",'" & strcodcliente & "', " & DblVale & " ,'" & StrDOCTYPEID & "'," & DblDocumento & ", " & DblMontoVale
   
 Set con = New ADODB.Connection
 con.Open "FILEDSN=conexionsies"
   
 Set cmd = New ADODB.Command
 Set cmd.ActiveConnection = con
 cmd.CommandText = StrSql
 cmd.Execute
  
 '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.C_VENTASPLAYA.GrabarVale_Temporal", Err.Description
  
End Sub

Public Function ObtenerValesdeTemp(ByVal DblCorrelativo As Double, Optional VarAux As Variant) As ADODB.Recordset
 Dim rs As ADODB.Recordset
 Dim StrSql As String
  
  On Error GoTo errhandler
      
  StrSql = "SELECT custidss,NBRBONUS AS [Número_de_Vale], MONTOBONUS AS [Monto_de_Vale] FROM TMP_OP_BONUS WHERE CORRNBR=" & DblCorrelativo
  
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
   
  Set ObtenerValesdeTemp = 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_VENTASPLAYA.ObtenerValesdeTemp", Err.Description
   
End Function

Public Function VerificarValesenTemp(ByVal DblCorrelativo As Double, ByVal DblNumeroBonus As Double, Optional VarAux As Variant) As Boolean
 Dim rs As ADODB.Recordset
 Dim StrSql As String
  
  On Error GoTo errhandler
      
  StrSql = " SELECT NBRBONUS FROM TMP_OP_BONUS WHERE CORRNBR=" & DblCorrelativo & " and " & _
           " NBRBONUS=" & DblNumeroBonus
  
  
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
   
  If rs.EOF Then
     VerificarValesenTemp = False
  Else
     VerificarValesenTemp = 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.ObtenerValesenTemp", Err.Description
   
End Function

Public Sub EliminarVale_Temporal(ByVal IntTodos As Integer, ByVal DblCorrelativo As Double, _
                                 ByVal DblVale As Double, Optional VarAux As Variant)
 Dim con As ADODB.Connection
 Dim cmd As ADODB.Command
 Dim StrSql As String
  
 On Error GoTo errhandler
   
 StrSql = " OP_EliminarTmp_Op_BonusProc " & IntTodos & "," & DblCorrelativo & "," & DblVale
   
 Set con = New ADODB.Connection
 con.Open "FILEDSN=conexionsies"
   
 Set cmd = New ADODB.Command
 Set cmd.ActiveConnection = con
 cmd.CommandText = StrSql
 cmd.Execute
  
 'GetObjectContext.SetComplete
 
 Exit Sub
errhandler:
    If Not cmd Is Nothing Then
       Set cmd = Nothing
    End If
    If Not con Is Nothing Then
       Set con = Nothing
    End If
    GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASPLAYA.EliminarVale_Temporal", Err.Description
  
End Sub

Public Function ObtenerNombreVendedor(ByVal StrVendedor As String, Optional VarAux As Variant) As String
 Dim rs As ADODB.Recordset
 Dim StrSql As String
  
  On Error GoTo errhandler
      
  StrSql = " SELECT SALESPERNAME FROM OP_SALESPERSON where SALESPERID='" & StrVendedor & "'"
  
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
   
  If rs.EOF Then
     ObtenerNombreVendedor = Empty
  Else
     ObtenerNombreVendedor = 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.C_VENTASPLAYA.ObtenerNombreVendedor", Err.Description
   
End Function



Public Function Auxiliar1(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASPLAYA.Auxiliar1", Err.Description
End Function

Public Function Auxiliar2(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASPLAYA.Auxiliar2", Err.Description
End Function

Public Function Auxiliar3(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASPLAYA.Auxiliar3", Err.Description
End Function

Public Function Auxiliar4(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASPLAYA.Auxiliar4", Err.Description
End Function

Public Function Auxiliar5(Optional ByVal VarAux1 As Variant, Optional ByVal VarAux2 As Variant) As Variant
    ' Funcion
    
    On Error GoTo errhandler
    
    
    
    'GetObjectContext.SetComplete
    
    Exit Function
errhandler:
    GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.C_VENTASPLAYA.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_VENTASPLAYA.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_VENTASPLAYA.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_VENTASPLAYA.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_VENTASPLAYA.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_VENTASPLAYA.Auxiliar10", Err.Description
End Function




