VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "msdatgrd.ocx"
Begin VB.Form frmAnularTransaccionCtaCte 
   Caption         =   "Anular Documento"
   ClientHeight    =   3390
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8085
   LinkTopic       =   "Form3"
   MaxButton       =   0   'False
   ScaleHeight     =   3390
   ScaleWidth      =   8085
   StartUpPosition =   2  'CenterScreen
   Begin VB.TextBox txtsupervisor 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "Courier New"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   4320
      MaxLength       =   6
      TabIndex        =   6
      Top             =   2640
      Visible         =   0   'False
      Width           =   1230
   End
   Begin MSDataGridLib.DataGrid dgdDetalle 
      Height          =   1455
      Left            =   240
      TabIndex        =   5
      Top             =   960
      Width           =   7575
      _ExtentX        =   13361
      _ExtentY        =   2566
      _Version        =   393216
      BackColor       =   -2147483624
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   10250
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   10250
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.CommandButton cmdCargar 
      Caption         =   "Cargar Doc."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   6600
      TabIndex        =   3
      Top             =   240
      Width           =   1215
   End
   Begin VB.TextBox txtNumero 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   5160
      MaxLength       =   6
      TabIndex        =   2
      Top             =   240
      Width           =   1215
   End
   Begin VB.ComboBox cboTipoDocumento 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   2040
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   240
      Width           =   1935
   End
   Begin VB.TextBox txtSerie 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   4200
      MaxLength       =   4
      TabIndex        =   1
      Top             =   240
      Width           =   735
   End
   Begin VB.CommandButton cmdSalir 
      Caption         =   "Cancelar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   6600
      TabIndex        =   8
      Top             =   2640
      Width           =   1215
   End
   Begin VB.CommandButton cmdAceptar 
      Caption         =   "Aceptar"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   240
      TabIndex        =   7
      Top             =   2640
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "Tipo Documento:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   240
      TabIndex        =   4
      Top             =   240
      Width           =   1815
   End
End
Attribute VB_Name = "frmAnularTransaccionCtaCte"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public sTipo As String
Public sNroDoc As String
Public sNroSerie As String
Public iTipo As Integer
Public bAcceso As Boolean

Dim lstarjeta As String
Dim iTipoVenta As Integer
Dim bContinuar As Boolean
Dim sTexto0 As String 'Bloques para la impresion
Dim sTransaccion As String, strMonto As String, strMoneda As String
Dim dFecha As Date

Private Sub CargarDetalle(ByVal nTipoDoc As Integer, ByVal sSerieDoc As String, ByVal sNroDoc As String)
  Dim cnSQL As ADODB.Connection
  Dim ADORS As ADODB.Recordset
  Dim STRSQL As String, sTipoDoc As String
  
  If Not IsNumeric(sNroDoc) Then
    Call MsgBox("Valor de Numero no válido", vbInformation + vbOKOnly, "Mensaje")
    txtNumero.SetFocus
    Set dgdDetalle.DataSource = Nothing
    Exit Sub
  End If

  If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir

  If nTipoDoc = 0 Or nTipoDoc = 1 Then
    'STRSQL = "select v.DscCliente as Cliente, 'Local'=case v.idLocal when 1 then 'Sur' when 2 then 'Norte' end,Moneda=case v.cCodMoneda  when 'N' then 'Soles' when 'E' then 'Dolares' end, " _
    '& "v.TotVta,v.TotVtaUSD,v.FechaEmision, " _
    '& "TotalPagos=round(isnull((select sum(case p.moneda when 'N' then p.monto when 'E' then p.monto*p.ntipocambio end)from pagos p Where p.cSerieDoc = v.cSerieDoc and p.nrodoc=v.NroDoc  and p.fechaanulacion is null group by p.tipodoc,p.cseriedoc,p.nrodoc),0),2) " _
    '& "from venta01  v Where v.fechaanulacion Is Null " _
    '& "and cSerieDoc='" & Trim(sSerieDoc) & "' and CONVERT(INT,NroDoc)=" & Trim(sNroDoc) & " "
    
    sTipoDoc = "0" + CStr(nTipoDoc + 1)
    STRSQL = "select v.DscCliente as Cliente, 'Local'=case v.idLocal when 1 then 'Sur' when 2 then 'Norte' end,Moneda=case v.cCodMoneda  when 'N' then 'Soles' when 'E' then 'Dolares' end, " _
    & "v.TotVta,v.TotVtaUSD,v.FechaEmision, " _
    & "TotalPagos=round(isnull((select sum(case p.moneda when 'N' then p.monto when 'E' then p.monto*p.ntipocambio end)from pagos p Where p.cSerieDoc = v.cSerieDoc and p.nrodoc=v.NroDoc and p.TipoDoc=v.TipoDoc and p.fechaanulacion is null),0),2) " _
    & "from venta01  v Where v.fechaanulacion Is Null " _
    & "and cSerieDoc='" & Trim(sSerieDoc) & "' and CONVERT(INT,NroDoc)=" & Trim(sNroDoc) & " and TipoDoc = '" & sTipoDoc & "' "
  Else
    STRSQL = "select cSerieDoc,NroDoc,'Forma Pago'=(select vDscTipoPago from tipoformapago where cCodTipoPago=pagos.FormaPago), " _
    & "FechaPago as Fecha,Monto,Moneda=case Moneda  when 'N' then 'Soles' when 'E' then 'Dolares' end From pagos " _
    & "where fechaanulacion Is Null and cSerieDocPago='" & Trim(sSerieDoc) & "'  and CONVERT(INT,NroDocPago)= " & Trim(sNroDoc) & " "
  End If

  If Not oDBAdmin.EjecutarConsulta(cnSQL, STRSQL, ADORS) Then GoTo Salir
  If ADORS.RecordCount > 0 Then
    
    Set dgdDetalle.DataSource = ADORS
    If nTipoDoc = 0 Or nTipoDoc = 1 Then
        strMonto = LeerCampo(ADORS("TotVta"))
        strMoneda = LeerCampo(ADORS("Moneda"))
        dFecha = ADORS!fechaemision
        
        dgdDetalle.Columns(0).Width = 3000
        dgdDetalle.Columns(1).Width = 700
        dgdDetalle.Columns(2).Width = 700
        dgdDetalle.Columns(3).Width = 750
        dgdDetalle.Columns(4).Width = 750
        dgdDetalle.Columns(5).Width = 1200
        dgdDetalle.Columns(6).Width = 0
    Else
        strMonto = LeerCampo(ADORS("Monto"))
        strMoneda = LeerCampo(ADORS("Moneda"))
        dFecha = ADORS!fecha
        
        dgdDetalle.Columns(0).Width = 1000
        dgdDetalle.Columns(1).Width = 1000
        dgdDetalle.Columns(2).Width = 1000
        dgdDetalle.Columns(3).Width = 1000
        dgdDetalle.Columns(4).Width = 1000
        dgdDetalle.Columns(5).Width = 1000
    End If
    
    Call ValidarDocumentoAnulado
  Else
    Set dgdDetalle.DataSource = Nothing
    MsgBox "Documento no existe o no es válido", vbInformation + vbOKOnly, "Mensaje"
  End If

Salir:
  Set cnSQL = Nothing
End Sub

Private Sub ValidarDocumentoAnulado()
  On Error GoTo LineaError
  
  Dim sSQL As String
  Dim cnSQL As ADODB.Connection
  Dim ADORS As ADODB.Recordset
  Dim sTotal As String, sTipoDoc As String, cCodVta As String
  
  sTipoDoc = "0" & CStr(iTipo + 1)
  
  If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir
  
  If iTipo = 0 Or iTipo = 1 Then
    sSQL = "SELECT COUNT(1) TOTAL FROM venta01 WHERE FechaAnulacion IS NOT NULL AND cSerieDoc='" & txtSerie.Text & "' AND CONVERT(INT,NroDoc)=" & txtNumero.Text & " AND TipoDoc='" & sTipoDoc & "' "
  Else
    sSQL = "SELECT COUNT(1) TOTAL FROM pagos WHERE FechaAnulacion IS NOT NULL AND cSerieDocPago='" & txtSerie.Text & "' AND CONVERT(INT,NroDocPago)=" & txtNumero.Text & ""
  End If
  
  If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
  sTotal = LeerCampo(ADORS("TOTAL"))
  
  If sTotal <> "0" Then
    Call MsgBox("El documento seleccionado ya se encuentra anulado", vbInformation + vbOKOnly, "Mensaje")
    Unload Me
  End If
  
  If iTipo = 0 Or iTipo = 1 Then
    sSQL = "SELECT COUNT(1) TOTAL FROM pagos WHERE cSerieDoc='" & txtSerie.Text & "' AND CONVERT(INT,NroDoc)=" & txtNumero.Text & " AND TIPODOC='" & sTipoDoc & "' AND FechaAnulacion IS NULL "
    If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
    
    sTotal = LeerCampo(ADORS("TOTAL"))
    If sTotal <> "0" Then
      Call MsgBox("El documento seleccionado no se puede anular por presentar Pagos asociados sin anular.", vbInformation + vbOKOnly, "Mensaje")
      Unload Me
    End If
    
    If sTotal = "0" Then
      sSQL = "SELECT cCodVta FROM venta01 WHERE cSerieDoc='" & txtSerie.Text & "' AND CONVERT(INT,NroDoc)=" & txtNumero.Text & " AND TipoDoc='" & sTipoDoc & "' "
      If Not oDBAdmin.EjecutarConsulta(cnSQL, sSQL, ADORS) Then GoTo Salir
      cCodVta = LeerCampo(ADORS("cCodVta"))
      
      sSQL = "SELECT COUNT(1) AS TOTAL FROM OPERACIONPARALELA WHERE cOperCodeRela=" & cCodVta & " AND cOperCodeAnul=0 "
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
      
      sTotal = LeerCampo(ADORS("TOTAL"))
      If sTotal <> "0" Then
        Call MsgBox("El documento seleccionado no se puede anular por presentar Notas de Consumo asociadas sin anular.", vbInformation + vbOKOnly, "Mensaje")
        Unload Me
      End If
    End If
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
End Sub

Private Sub ImprimirAnulacion(Optional ByVal sSerie As String, Optional ByVal sNro As String)
  On Error GoTo LineaError
  
  Dim sFecha As String, sTexto As String
  Dim iCodOper As Long
  Dim iSigno As Integer
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim i As Long
  Dim iTransaccion As Long
  Dim p As Integer
  
  bAcceso = False
 
  ConfiguraImpresora kPAR_IMPRESORA
  p = 1
  
   
   'SE OBTIENE FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL - version 2.0.5
   
   Dim cnFECHASQL As ADODB.Connection
   Dim sqlFECHASIS As String
   Dim rsFEchaSis As ADODB.Recordset
      
   If oDBAdmin.AbrirBD(cnFECHASQL, psConnectString, False) = True Then
     
     sqlFECHASIS = "select convert(varchar,getdate(),120) as fechasis"
     If oDBAdmin.EjecutarConsulta(cnFECHASQL, sqlFECHASIS, rsFEchaSis) = True Then
         
         If rsFEchaSis!fechasis <> "" Then
             sFecha = rsFEchaSis!fechasis
         End If

     Else
         'no pudo abrir el rs: que consulte al access
         'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
         sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
         'Unload Me
     End If

     Set cnFECHASQL = Nothing

   Else
     'no pudo conectarse al sql: que consulte al access
      'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
      sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
      'Unload Me
   End If
   
   'FIN FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL



  'sFecha = Format(Now(), "DD/MM/YYYY hh:mm")

  Set ADORS = Nothing
    
  Call CabeceraImpresion
  
  sTexto0 = ""
  For i = 0 To UBound(sCabecera) - 1
    If Not Trim(sCabecera(i)) = "" Then
      sTexto0 = sTexto0 + Right(Space(60) + sCabecera(i), Int(Len(Space(40) + sCabecera(i)) / 2)) + vbCrLf
    End If
  Next
  
  sTexto = ""
  sTexto = sTexto + sTexto0 + vbCrLf
  sTexto = sTexto + "             " + Format(CStr(Now()), "DD/MM/YYYY (DDD)") + vbCrLf
  sTexto = sTexto + Right(Space(20) & "TRANSACCION ANULADA", Int(Len("TRANSACCION ANULADA") / 2) + 20) + vbCrLf
  sTexto = sTexto + "             " + Format(CStr(dFecha), "DD/MM/YYYY (DDD)") + vbCrLf
  
  If Left(UCase(sSerie), 2) = "PA" Then
    sTexto = sTexto + Right("                  PADE", Int(Len("PADE") / 2) + 20) + vbCrLf
  Else
    sTexto = sTexto + Right("                  PADV", Int(Len("PADV") / 2) + 20) + vbCrLf
  End If
  
  sTexto = sTexto + "---------------------------------------" + vbCrLf + vbCrLf
  sTexto = sTexto + "CASH/TL  " + IIf(strMoneda = "Dolares", "$  ", "S/.") + Right(Space(26) & "*" + Format(CStr(CDbl(strMonto)), "###,###,##0.00"), 26) + vbCrLf
  sTexto = sTexto + "   ITEM  " + Right(Space(28) & "*" + Format(CStr(1), "###,##0.00"), 29) + vbCrLf + vbCrLf
  sTexto = sTexto + Space(10) & "Documento:" + UCase(sSerie) + "-" + Right("0000000" & sNro, 7) + vbCrLf + vbCrLf
  sTexto = sTexto + Right(Space(20) & "TRANSACCION ANULADA", Int(Len("TRANSACCION ANULADA") / 2) + 20) + vbCrLf + vbCrLf
  
  sTexto = sTexto + " " + Left(psUsuario_Descripcion, 10) + " "  'Usuario: 10 + 1
  sTexto = sTexto + Format(CStr(Now()), "hh:mm") + " " 'Hora: 6 + 1
  sTexto = sTexto + vbCrLf + "Supervisor: " + Left(txtsupervisor, 10) + " " 'supervisor: 10 + 1
  sTexto = sTexto + vbCrLf + "CAJA: " + kPAR_CAJA + "   TURNO: " + kPAR_TURNO
  sTexto = sTexto + vbCrLf & "Correlativo: " & ObtenerCorrelativo(p)
  
  If p = 1 Then
  Select Case KImpresora
    Case 1
      Call CortePapel(sTexto, p, CStr(iCodOper))
    Case 0
      printer.Print sTexto
      printer.Print " "
      printer.Print " "
      printer.EndDoc
    End Select
  Else
    Select Case KImpresoraALT
      Case 1
        Call CortePapel(sTexto, p)
      Case 0
        printer.Print sTexto
        printer.Print " "
        printer.Print " "
        printer.EndDoc
    End Select
  End If
  
  If Trim(lstarjeta) <> "" Then
    lstarjeta = ""
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
End Sub

Private Sub AnularDocumento(ByVal sSerieDoc As String, ByVal sNroDoc As String)
  Dim cnSQL As ADODB.Connection
  Dim sSQL As String, sTipoDoc As String
  If Not oDBAdmin.AbrirBD(cnSQL, psConnectString) Then GoTo Salir

  'If Left(UCase(sSerieDoc), 1) = "F" Or Left(UCase(sSerieDoc), 1) = "B" Then
  If iTipo = 0 Or iTipo = 1 Then
    sTipoDoc = "0" & CStr(iTipo + 1)
    sSQL = "UPDATE venta01 SET FechaAnulacion = getdate() WHERE cSerieDoc='" & sSerieDoc & "' AND CONVERT(INT,NroDoc)=" & sNroDoc & " AND TipoDoc='" & sTipoDoc & "' "
  Else
    sSQL = "UPDATE pagos SET FechaAnulacion = getdate() WHERE cSerieDocPago='" & sSerieDoc & "' AND CONVERT(INT,NroDocPago)=" & sNroDoc & ""
  End If

  If Not oDBAdmin.EjecutarSentencia(cnSQL, sSQL) Then GoTo Salir

  If iTipo = 2 Then
    Call AnularOperacion
  End If
  
  Call MsgBox("Se anuló el documento!", vbInformation + vbOKOnly, "Mensaje")
  
  'If sTipo = "P" Then
  '  frmCajaFacturacionPagos.LimpiarPagos
  'End If
  
  Set cnSQL = Nothing
  Exit Sub
Salir:
  Set cnSQL = Nothing
End Sub

Private Sub AnularOperacion()
  On Error GoTo LineaError
  
  Dim sFecha As String, sTexto As String, sLCodRela As String
  Dim iCodOper As Long
  Dim iSigno As Integer
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim iTransaccion As Long

  Call BuscarDocumento
  
  If Not bContinuar Then GoTo Salir
  
  iTransaccion = CLng(sTransaccion)
  
  'Recogiendo valores para actualizar
  sSQL = " SELECT O.cOperCode, O.cUserDesc, O.nTarjNumb, O.dOperFech, O.cOperTipo," & _
         " O.cOperCodeRela, O.nVueltoSoles, O.nEfectivoSoles, B.cAlmaCode, B.cProdCode, B.nProdCant," & _
         " B.nProdPrecUnit, B.nDscto, B.sProdDescCrta, B.nServicio" & _
         " FROM OperacionParalela AS O LEFT JOIN" & _
         " (SELECT A.cOperCode, A.cProdCode, A.nProdCant, A.nProdPrecUnit, A.nDscto," & _
         " P.sProdDescCrta, A.cAlmaCode, A.nServicio FROM OperacionParalelaProducto as A INNER JOIN Producto AS P" & _
         " ON A.cProdCode = P.cProdCode ) AS B ON O.cOperCode = B.cOperCode" & _
         " WHERE O.cOperCode = $ AND O.cEstado IN ('1') and o.cOperFlagAbierto=1 "
  sSQL = VBsprintf(sSQL, CStr(iTransaccion))
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  If ADORS.RecordCount < 1 Then GoTo Salir
  
  iTipoVenta = LeerCampo(ADORS("cOperTipo"))
  lstarjeta = LeerCampo(ADORS!nTarjNumb)
  
  'Registra Anulacion
  sSQL = "SELECT MAX(cOperCode) AS maximo FROM OperacionParalela"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
  If ADORS.RecordCount = 1 Then
    If IsNull(ADORS("maximo")) Then
      iCodOper = 1
    Else
      iCodOper = LeerCampo(ADORS("maximo")) + 1
    End If
  End If

    'SE OBTIENE FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL - version 2.0.5
   
   Dim cnFECHASQL As ADODB.Connection
   Dim sqlFECHASIS As String
   Dim rsFEchaSis As ADODB.Recordset
      
   If oDBAdmin.AbrirBD(cnFECHASQL, psConnectString, False) = True Then
     
     sqlFECHASIS = "select convert(varchar,getdate(),120) as fechasis"
     If oDBAdmin.EjecutarConsulta(cnFECHASQL, sqlFECHASIS, rsFEchaSis) = True Then
         
         If rsFEchaSis!fechasis <> "" Then
             sFecha = rsFEchaSis!fechasis
         End If

     Else
         'no pudo abrir el rs: que consulte al access
         'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
         sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
         'Unload Me
     End If

     Set cnFECHASQL = Nothing

   Else
     'no pudo conectarse al sql: que consulte al access
      'MsgBox "No se pudo obtener la fecha, hay problemas de conexión de la red con la Base de Datos Principal", vbOKOnly + vbExclamation, "Aviso"
      sFecha = Format(Now(), "DD/MM/YYYY hh:mm")
      'Unload Me
   End If
   
   'FIN FECHA DEL SISTEMA DE LA BASE DE DATOS DE SQL


  'sFecha = Format(Now(), "DD/MM/YYYY hh:mm")

  Set ADORS = Nothing
  
  iSigno = -1
  
  sSQL = " INSERT INTO OPERACIONPARALELA (cOperCode, cOperTipo, dOperFech, " & _
         " sGlosa, cEstado, cCajaCodi, cTurnoCodi, cUserDesc)" & _
         " VALUES" & _
         " ($, $, '$', '$', '$', '$', '$', '$')"
  sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTipoVenta), sFecha, "ANULACION", CStr(0), _
           kPAR_CAJA, kPAR_TURNO, psUsuario_Descripcion)
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    
  sSQL = " UPDATE OPERACIONPARALELA" & _
         " SET cEstado = '0', cOpercodeAnul = $" & _
         " WHERE cOperCode = $"
  sSQL = VBsprintf(sSQL, CStr(iCodOper), CStr(iTransaccion))
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    
  sSQL = "DELETE FROM Operacion " & _
         "WHERE cOpercode= $ AND cOperFlagAbierto=1 AND cDocTipo in ('10', '14')"
  sSQL = VBsprintf(sSQL, CStr(CStr(iTransaccion)))
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  
  If iTipoVenta = 3 Or iTipoVenta = 20 Then
    sSQL = "SELECT cOperCodeRela as CodRela " & _
           "FROM OperacionParalela " & _
           "WHERE cOperCode =$" & _
           "  AND cOperFlagAbierto = 1 "
    
    sSQL = VBsprintf(sSQL, CStr(iTransaccion))
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
        
    If val("0" & (ADORS!codRela)) <> 0 Then
      If Not ADORS.EOF Then sLCodRela = LeerCampo(ADORS!codRela)
      
      sSQL = "UPDATE OperacionParalela SET cEstado= '1', cOperCodeRela=0 " & _
             "WHERE cOperTipo <> 20 AND cOpercodeRela= $ "
      sSQL = VBsprintf(sSQL, sLCodRela)
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
            
      sSQL = "DELETE FROM OperacionParalela " & _
             "WHERE cOpercode= $ AND cOperFlagAbierto=1"
      sSQL = VBsprintf(sSQL, sLCodRela)
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
            
      sSQL = "DELETE FROM Operacion " & _
             "WHERE cOpercode= $ AND cOperFlagAbierto=1"
      sSQL = VBsprintf(sSQL, sLCodRela)
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
    End If
  End If
  
  GoTo Salir
  
LineaError:
  Screen.MousePointer = vbDefault
  lstarjeta = ""
Salir:
  Set ADORS = Nothing
  lstarjeta = ""
End Sub

Public Sub BuscarDocumento()
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  bContinuar = True
  
  sSQL = "Select distinct cdocTipo, cdocSerie, cDocCodigo, cOpercode " & _
         "From OperacionParalela " & _
         "Where (cOperFlagAbierto = 1 OR cestado='1') " & _
         "  And cdocSerie = '" & Trim(txtSerie.Text) & "'" & _
         "  And cDocCodigo = " & CStr(CInt(Trim(txtNumero.Text)))

  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
  If ADORS.RecordCount > 0 Then
    If ADORS.RecordCount = 1 Then
      bContinuar = True
      sTransaccion = "0" & (ADORS!cOperCode)
    Else
      bContinuar = False
    End If
  Else
    bContinuar = True
    sTransaccion = ""
  End If

  Set ADORS = Nothing
  bContinuar = True
  
  Exit Sub
Salir:
  bContinuar = False
End Sub

Private Sub CargarCombo()
  cboTipoDocumento.AddItem "FADE", 0
  cboTipoDocumento.AddItem "BADE", 1
  cboTipoDocumento.AddItem "PADE", 2
  
  cboTipoDocumento.ListIndex = iTipo
  cboTipoDocumento.Enabled = False
  
  If iTipo = 2 Then
    txtSerie.Text = sNroSerie
    txtNumero.Text = sNroDoc
    
    txtSerie.Enabled = False
    txtNumero.Enabled = False
    cmdCargar.Enabled = False
    
    Call cmdCargar_Click
  End If
End Sub

Private Sub cboTipoDocumento_Click()
  txtSerie.Text = ""
  txtNumero.Text = ""
  Set dgdDetalle.DataSource = Nothing
End Sub

Private Sub cmdaceptar_Click()
  Dim nVal As Integer

  nVal = cboTipoDocumento.ListIndex
  'If dgdDetalle.Columns.Count = 2 Then
  If nVal = 0 Or nVal = 1 Then
    If dgdDetalle.Row = -1 Then
      MsgBox "Debe cargar el documento a anular", vbInformation + vbOKOnly, "Mensaje"
      Exit Sub
    End If
  End If

  If MsgBox("Esta seguro de anular el documento?", vbQuestion + vbYesNo, "Confirme") = vbYes Then
    bAcceso = False
    Load frmAutorizarOperacion
    Set frmAutorizarOperacion.frmPadre = Me
    frmAutorizarOperacion.Show vbModal
    If Not bAcceso Then
        Exit Sub
    Else
        Call AnularDocumento(Trim(txtSerie.Text), Trim(txtNumero.Text))
        Call ImprimirAnulacion(Trim(txtSerie.Text), Trim(txtNumero.Text))
        
        Unload Me
    End If
  End If
End Sub

Private Sub cmdCargar_Click()
  If cboTipoDocumento.Text <> "" And txtNumero <> "" And txtSerie <> "" Then
    Call CargarDetalle(cboTipoDocumento.ListIndex, txtSerie.Text, txtNumero.Text)
  Else
    Set dgdDetalle.DataSource = Nothing
  End If
End Sub

Private Sub cmdsalir_Click()
  Unload Me
End Sub

Private Sub Form_Load()
  Call CargarCombo
  
  If iTipo = 2 Then
    Call ValidarDocumentoAnulado
  End If
End Sub
