VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Begin VB.Form Form_Boletas_Anular 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Anulacion de Boletas"
   ClientHeight    =   6765
   ClientLeft      =   4710
   ClientTop       =   2925
   ClientWidth     =   6300
   Icon            =   "Form_Boletas_Anular.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6765
   ScaleWidth      =   6300
   Begin VB.Frame Frame_anulbol 
      Caption         =   "Anulación de Boletas"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   6495
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6015
      Begin MSComctlLib.ProgressBar Progreso 
         Height          =   375
         Left            =   240
         TabIndex        =   25
         Top             =   4920
         Width           =   5535
         _ExtentX        =   9763
         _ExtentY        =   661
         _Version        =   393216
         Appearance      =   1
         MousePointer    =   12
         Min             =   1e-4
         Max             =   1
         Scrolling       =   1
      End
      Begin VB.Frame Frame6 
         Caption         =   "Colegio"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   735
         Left            =   240
         TabIndex        =   4
         Top             =   360
         Width           =   5535
         Begin MSComctlLib.ImageCombo Combo_Colegio 
            Height          =   345
            Left            =   240
            TabIndex        =   24
            Top             =   240
            Width           =   5055
            _ExtentX        =   8916
            _ExtentY        =   609
            _Version        =   393216
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
      End
      Begin VB.Frame Frame1 
         BorderStyle     =   0  'None
         Height          =   375
         Left            =   960
         TabIndex        =   21
         Top             =   4320
         Width           =   3855
         Begin VB.CommandButton Btn_Anular 
            Caption         =   "Anular"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   0
            TabIndex        =   23
            Top             =   0
            Width           =   1575
         End
         Begin VB.CommandButton btn_can_anulbol 
            Caption         =   "Cancelar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   2280
            TabIndex        =   22
            Top             =   0
            Width           =   1575
         End
      End
      Begin VB.Frame Frame_Ult_Folio 
         Caption         =   "Último Folio Anulado"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   855
         Left            =   240
         TabIndex        =   1
         Top             =   5400
         Width           =   5535
         Begin VB.Label Label_Colegio 
            Alignment       =   2  'Center
            Caption         =   "Label_Colegio"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   11.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   3
            Top             =   360
            Width           =   3735
         End
         Begin VB.Label Lbl_Ult_Fola 
            Alignment       =   2  'Center
            BackColor       =   &H00FFFFFF&
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00C00000&
            Height          =   255
            Left            =   3840
            TabIndex        =   2
            Top             =   360
            Width           =   1335
         End
      End
      Begin VB.Frame Frame2 
         Caption         =   "Forma"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   1215
         Left            =   4320
         TabIndex        =   5
         Top             =   1200
         Width           =   1455
         Begin VB.OptionButton Opt_AnulBol 
            Caption         =   "Una a una"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   0
            Left            =   120
            TabIndex        =   7
            Top             =   360
            Value           =   -1  'True
            Width           =   1215
         End
         Begin VB.OptionButton Opt_AnulBol 
            Caption         =   "Por Rango"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   1
            Left            =   120
            TabIndex        =   6
            Top             =   720
            Width           =   1215
         End
      End
      Begin VB.Frame Frame_TipAnul 
         Caption         =   "Por Rango"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   1215
         Index           =   1
         Left            =   240
         TabIndex        =   11
         Top             =   1200
         Width           =   3855
         Begin VB.TextBox Txt_FolioINI_anu 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   360
            TabIndex        =   13
            Top             =   600
            Width           =   1335
         End
         Begin VB.TextBox Txt_FolioFIN_anu 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2160
            TabIndex        =   12
            Top             =   600
            Width           =   1335
         End
         Begin VB.Label Label5 
            Caption         =   "Folio Inicial"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   240
            TabIndex        =   15
            Top             =   360
            Width           =   1335
         End
         Begin VB.Label Label6 
            Caption         =   "Folio Final"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   2160
            TabIndex        =   14
            Top             =   360
            Width           =   1335
         End
      End
      Begin VB.Frame Frame11 
         Caption         =   "Motivo de la Anulación"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   735
         Left            =   240
         TabIndex        =   16
         Top             =   2520
         Width           =   5535
         Begin MSComctlLib.ImageCombo Combo_Anulacion 
            Height          =   345
            Left            =   840
            TabIndex        =   17
            Top             =   240
            Width           =   3855
            _ExtentX        =   6800
            _ExtentY        =   609
            _Version        =   393216
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Locked          =   -1  'True
            Text            =   "Combo_Anulacion"
         End
      End
      Begin VB.Frame Frame3 
         Height          =   735
         Left            =   240
         TabIndex        =   18
         Top             =   3360
         Width           =   5535
         Begin MSComCtl2.DTPicker Dtp_Fech_Anul 
            Height          =   375
            Left            =   3000
            TabIndex        =   19
            Top             =   240
            Width           =   1335
            _ExtentX        =   2355
            _ExtentY        =   661
            _Version        =   393216
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Format          =   83886081
            CurrentDate     =   37861
         End
         Begin VB.Label Label19 
            Caption         =   "Fecha de anulación"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   1320
            TabIndex        =   20
            Top             =   300
            Width           =   1695
         End
      End
      Begin VB.Frame Frame_TipAnul 
         Caption         =   "Una a una"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   1215
         Index           =   0
         Left            =   240
         TabIndex        =   8
         Top             =   1200
         Width           =   3855
         Begin VB.TextBox Txt_AnulBol 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1920
            TabIndex        =   9
            Top             =   480
            Width           =   1455
         End
         Begin VB.Label Label4 
            Caption         =   "Ingrese Folio"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   360
            TabIndex        =   10
            Top             =   480
            Width           =   1575
         End
      End
   End
End
Attribute VB_Name = "Form_Boletas_Anular"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Btn_Anular_Click()
    'MsgBox "EN ESTE MÓDULO NO SE PUEDEN ANULAR BOLETAS EMITIDAS EL 2004 QUE PAGAN CUOTAS DEL 2004", vbCritical, "IMPORTANTE"
    Dim MSG As String
    Dim BolIni As Long
    Dim BolFin As Long
    
    If Opt_AnulBol(0).Value Then
        If Txt_AnulBol.Text = "" Then
            MsgBox "Falta especificar folio de boleta", vbCritical, "Alerta de Validación"
            Exit Sub
        End If
        BolIni = val(Txt_AnulBol.Text)
        BolFin = BolIni
    Else
        If (Txt_FolioINI_anu.Text = "" Or Txt_FolioFIN_anu.Text = "") Then
            MsgBox "Falta especificar rango de boletas.", vbCritical, "Alerta de Validación"
            Exit Sub
        End If
        BolIni = val(Txt_FolioINI_anu.Text)
        BolFin = val(Txt_FolioFIN_anu.Text)
    End If
        
    If Opt_AnulBol(0).Value Then
        MSG = "Está seguro de que desea anular la boleta Nº " & BolIni & "?"
    Else
        MSG = "El Rango de Anulación de las boletas es:" & vbCrLf & vbCrLf & "de la nº" & BolIni & " a la nº" & BolFin & vbCrLf & vbCrLf & "¿Es esto correcto?"
    End If
    If (MsgBox(MSG, vbYesNo + vbQuestion, "Confirmación de Folio") = vbNo) Then Exit Sub
        
    ' Bloquear Botones
    Frame1.Enabled = False
    ' iniciar anulación
    AnularBoletasMasivo BolIni, BolFin, Combo_Colegio.SelectedItem.Key
    ' desbloquear botones
    Frame1.Enabled = True
    ' Llenar ultimo folio nulo impreso
    Combo_Colegio_Click
    ' Mensaje de termino de Anulaciones
    MsgBox "La anulación de boletas ha finalizado", vbInformation, "Término de Proceso"
    ' borrado de variables
    progreso.Value = 0
    Txt_AnulBol.Text = ""
    Txt_FolioINI_anu.Text = ""
    Txt_FolioFIN_anu.Text = ""
End Sub

Private Sub btn_can_anulbol_Click()
Unload Me
End Sub

Private Sub Combo_Colegio_Click()
    Label_Colegio = Combo_Colegio.SelectedItem.Text
    Lbl_Ult_Fola.Caption = str(UltimoFolioNuloImpreso(Combo_Colegio.SelectedItem.Key, conn))
End Sub

Private Sub Form_Load()
    ' LLenar combo Colegio
    LlenarColegio Combo_Colegio, conn
    ' Llenar combo Motivo de Anulacion
    LlenarMotivoAnulacion Combo_Anulacion, conn
    ' Llenar ultimo folio nulo impreso
    Combo_Colegio_Click
    ' Fijar la fecha del DTpicker a la fecha de hoy
    Dtp_Fech_Anul.Value = Date
    ' Estado inicial de los Option
    Opt_AnulBol(0).Value = True
    Opt_AnulBol(1).Value = False
    Frame_TipAnul(0).Visible = True
    Frame_TipAnul(1).Visible = False
    'MsgBox "EN ESTE MÓDULO NO SE PUEDEN ANULAR BOLETAS EMITIDAS EL 2004 QUE PAGAN CUOTAS DEL 2004", vbCritical, "IMPORTANTE"
End Sub

Private Sub LlenarColegio(ByRef Combo As ImageCombo, ByRef CNX As ADODB.Connection)
    ' llenar un imagecombo con los datos del colegio
On Error GoTo Controlerror:
    Dim RC As ADODB.Recordset
    Dim QR As String
    
    Set RC = New ADODB.Recordset
    ' Extraigo la lista de codigos de colegio en el establecimiento
    QR = "SELECT col.colegio, col.nombre FROM (SELECT hcc.* FROM establecimientos e, hist_cod_colegio hcc WHERE hcc.cod_rbd=e.rdb) d, hist_cod_colegio col WHERE left(col.colegio,6)=d.colegio;"
    RC.Open QR, CNX
    ' ¿Llenar el combo item?
    If Not (RC.RecordCount = 0) Then
        ' Borrar del ImageCombo los comboitems
        Combo.ComboItems.Clear
        For i = 1 To RC.RecordCount
            ' Añadir nuevo comboitem
            Combo.ComboItems.Add i, RC!colegio, RC!nombre
            RC.MoveNext
        Next i
        Set Combo.SelectedItem = Combo.ComboItems.Item(1)
        RC.Close
    Else
        RC.Close
        Err.Raise vbObjectError + 700, "Form_Boletas_Anular.LlenaColegio", "No se encontraron establecimientos."
    End If
    
    Set RC = Nothing
    
    Exit Sub
Controlerror:
    Set RC = Nothing
    Err.Raise Err.Number, Err.Source & vbCrLf & "Form_Boletas_Anular.LlenarColegio", Err.Description
End Sub

Private Sub LlenarMotivoAnulacion(ByRef Combo As ImageCombo, ByRef CNX As ADODB.Connection)
    ' llenar un imagecombo con los datos del colegio
On Error GoTo Controlerror:
    Dim RC As ADODB.Recordset
    Dim QR As String
    
    Set RC = New ADODB.Recordset
    ' Extraigo la lista de codigos de colegio en el establecimiento
    QR = "SELECT cod_anul, txt_anul FROM fnza_cod_anulacion;"
    RC.Open QR, CNX
    ' ¿Llenar el combo item?
    If Not (RC.RecordCount = 0) Then
        ' Borrar del ImageCombo los comboitems
        Combo.ComboItems.Clear
        For i = 1 To RC.RecordCount
            ' Añadir nuevo comboitem
            Combo.ComboItems.Add i, RC!cod_anul, RC!txt_anul
            RC.MoveNext
        Next i
        Set Combo.SelectedItem = Combo.ComboItems.Item(1)
        RC.Close
    Else
        RC.Close
        Err.Raise vbObjectError + 700, "Form_Boletas_Anular.LlenarMotivoAnulacion", "No se encontraron Codigos de Anulación."
    End If
    
    Set RC = Nothing
    
    Exit Sub
Controlerror:
    Set RC = Nothing
    Err.Raise Err.Number, Err.Source & vbCrLf & "Form_Boletas_Anular.LlenarMotivoAnulacion", Err.Description
End Sub

Private Function UltimoFolioNuloImpreso(ByVal colegio As String, ByRef CNX As ADODB.Connection) As Long
On Error GoTo Controlerror:
    Dim RC As ADODB.Recordset
    Dim QR As String
    
    UltimoFolioNuloImpreso = 0
        
    QR = "SELECT folio_blta_fisico FROM fnza_boletas WHERE tipo_blta = 3 and colegio='" & colegio & "' AND estado_blta='nula' and tipo_doc = 'blta' ORDER by folio_blta_fisico DESC LIMIT 1;"
    Set RC = New ADODB.Recordset
    RC.Open QR, CNX
    If Not (RC.RecordCount = 0) Then
        RC.MoveFirst
        UltimoFolioNuloImpreso = RC!folio_blta_fisico
    End If
    RC.Close
    
    Set RC = Nothing
    
    Exit Function
Controlerror:
    Set RC = Nothing
    Err.Raise Err.Number, Err.Source & vbCrLf & "Form_Boletas_Anular.UltimoFolioNuloImpreso", Err.Description
End Function

Private Sub AnularBoletasMasivo(ByVal BolIni As Long, ByVal BolFin As Long, ByVal colegio As String)
    ' Anular las boletas desde el folio BolIni hasta el Folio BolFin
On Error GoTo Controlerror:
    ' Las Variables
    ' #############
    Dim CMD As ADODB.Command
    Dim RC As ADODB.Recordset
    Dim QR As String
    Dim FolioBltaFisico As Long
    Dim FolioBlta As Long
    Dim Bol As Long
    Dim Folio2004 As String
    Dim CodConvBci As String
    Dim Copias As String
    Dim accion_detalle As String
    
    ' Instrucciones
    ' #############
    If BolIni > BolFin Then
        MsgBox "El número de Boleta Inicial es menor que el número de Boleta Final.", vbCritical + vbOKOnly, "Alerta de Validación"
        Exit Sub
    End If
    
    If MsgBox("¿Tiene en su poder el ORIGINAL y la COPIA de la(s) boleta(s) por anular?", vbInformation + vbYesNo, "Verificación") = vbYes Then
        Copias = "SI"
    Else
        Copias = "NO"
    End If
    'crear tabla de log si no existe.
    conn.Execute "CREATE TABLE IF NOT EXISTS `fnza_log_anulacion_boletas` (`FOLIO_REG` bigint(20) unsigned NOT NULL auto_increment,`LOGIN_USUARIO` varchar(100) NOT NULL default '',`NOMBRE_USUARIO` varchar(100) NOT NULL default '',`FOLIO_BOL_FISICO` varchar(100) NOT NULL default '',`FEC_ANUL` datetime NOT NULL default '0000-00-00',`TIENE_COPIA` varchar(100) NOT NULL default '', PRIMARY KEY  (`FOLIO_REG`)) ENGINE=MyISAM;"
    
    progreso.Min = 0
    progreso.Value = 0
    progreso.Max = (BolFin - BolIni) + 1
    Set RC = New ADODB.Recordset
    
    For Bol = BolIni To BolFin
        FolioBlta = num_folio_blta(Bol, colegio, conn)
        If Trim(RetornaCampo("fnza_boletas", "estado_blta", "tipo_blta = 3 and folio_blta=" & FolioBlta, conn)) <> "devo" Then
            If Not (FolioBlta = 0) Then
                ' existe una boleta.
                QR = "SELECT fecha_blta,run_apo,run_alu,estado_blta FROM fnza_boletas WHERE tipo_blta = 3 and folio_blta=" & FolioBlta & ";"
                RC.Open QR, conn
                RC.MoveFirst
                ' que tipo de boleta es?
                If Not (RC!estado_blta = "nula") Then
                    If Not (RC!estado_blta = "2004") Then
                        ' si no es del 2004.
                        If Not (AnularBoleta(Bol, Dtp_Fech_Anul.Value, conn, Combo_Anulacion.SelectedItem.Key)) Then
                            MsgBox "No se pudo anular la boleta nº" & Bol & ".", vbOKOnly + vbExclamation, "ALERTA DE ANOMALÍA"
                        Else
                            '#################################
                            'Registrar quien anulo las boletas
                            '#################################
                            accion_detalle = "La boleta con folio " & Bol & " ha sido anulada, en el año " & Format(RC!fecha_blta, "yyyy")
                            Call Inserta_Vitacora_Finanza(RC!run_apo, RC!run_alu, "Anulación de Boleta", accion_detalle, 0, 0)
                            conn.Execute "INSERT INTO fnza_log_anulacion_boletas(login_usuario,nombre_usuario,folio_bol_fisico,fec_anul,tiene_copia) VALUES ('" & Nom_usu_ses & "','" & Nom_com_usu_ses & "'," & Bol & ",concat(current_date,' ',current_time),'" & Copias & "');"
                            '#################################
                        End If
                    Else
                            ' Anular una boleta del año 2004.
                            Folio2004 = Trim(FillconStr(CStr(Bol), 8, "0", "IZQ"))
                            CodConvBci = DevuelveCampo("hist_cod_colegio", "", "cod_conv_bci", "colegio='" & colegio & "'", conn)
                            If ExistReg("gescol2004.BOL_APO_X_ALU", "FOLIO ='" & Folio2004 & "' and cod_conv_bci ='" & CodConvBci & "'", conn) Then
                                conn.Execute "UPDATE gescol2004.bol_apo_x_alu SET nula='1', fec_nula='" & Format(Dtp_Fech_Anul.Value, "yyyy-mm-dd") & "', codigo_anulacion='" & Combo_Anulacion.SelectedItem.Key & "' WHERE FOLIO ='" & Folio2004 & "' and cod_conv_bci ='" & CodConvBci & "'"
                            Else
                                conn.Execute "INSERT INTO gescol2004.bol_apo_x_alu(RUT_APO, COD_CONV_BCI, CI_ALU, FOLIO, FEC_EMISION, FEC_NULA, NULA, PROCEDENCIA, CODIGO_ANULACION) VALUES('00000000-0', '" & CodConvBci & "','00000000-0', '" & Folio2004 & "', '" & Format(Dtp_Fech_Anul.Value, "yyyy-mm-dd") & "', '" & Format(Dtp_Fech_Anul.Value, "yyyy-mm-dd") & "', '1','0','" & Combo_Anulacion.SelectedItem.Key & "')"
                            End If
                            ' Se deben anular los abonos en el año 2004.
                            conn.Execute "DELETE FROM gescol2004.pagos WHERE folio='" & Folio2004 & "' and cod_conv_bci ='" & CodConvBci & "'"
                            
                            ' La venta del Mario regresa
                            conn.Execute "UPDATE fnza_boletas SET estado_blta='nula', cod_anulacion_blta='" & Combo_Anulacion.SelectedItem.Key & "' WHERE tipo_blta = 3 and folio_blta=" & FolioBlta & ";"
                            '#################################
                            'Registrar quien anulo las boletas
                            '#################################
                            accion_detalle = "La boleta con folio " & Bol & " a sido anulada, en el año " & Format(RC!fecha_blta, "yyyy")
                            Call Inserta_Vitacora_Finanza(RC!run_apo, RC!run_alu, "Anulación de Boleta", accion_detalle, 0, 0)
                            conn.Execute "INSERT INTO fnza_log_anulacion_boletas(login_usuario,nombre_usuario,folio_bol_fisico,fec_anul,tiene_copia) VALUES ('" & Nom_usu_ses & "','" & Nom_com_usu_ses & "'," & Bol & ",concat(current_date,' ',current_time),'" & Copias & "');"
                            '#################################
                    End If
                Else
                    MsgBox "La boleta ya está NULA.", vbOKOnly + vbExclamation, "ALERTA"
                End If
                RC.Close
            Else
                ' crear boleta nula.
                If Not (CrearBoletaNula(Bol, colegio, Combo_Anulacion.SelectedItem.Key, conn, Dtp_Fech_Anul.Value)) Then
                    MsgBox "No se pudo crear boleta nula nº" & Bol & ".", vbOKOnly + vbExclamation, "ALERTA DE ANOMALÍA"
                End If
            End If
        Else
            'boleta tiene devolucion
            MsgBox "La Boleta Folio " & Bol & " tiene una devolución asociada. Por lo tanto, no puede ser anulada.", vbInformation, "ALERTA"
        End If
        progreso.Value = (Bol - BolIni) + 1
        progreso.Refresh
    Next Bol
    Set RC = Nothing
    Exit Sub
Controlerror:
    Dim NumError As Long
    Dim DesError As String
    Dim SouError As String
    NumError = Err.Number
    SouError = Err.Source
    DesError = Err.Description
    
    If NumError = -2147220903 Then
        MsgBox "La boleta ya está NULA.", vbOKOnly + vbExclamation, "ALERTA"
        Resume Next
    End If
    MsgBox NumError & vbCrLf & SouError & vbCrLf & "Form_Boletas_Anular.AnularBoletas" & vbCrLf & vbCrLf & DesError, vbCritical, "ALERTA DE ANOMALÍA"
    'Resume
End Sub

Private Sub Opt_AnulBol_Click(Index As Integer)

    Select Case Index
        Case 0
            Opt_AnulBol(0).Value = True
            Opt_AnulBol(1).Value = False
            Frame_TipAnul(0).Visible = True
            Frame_TipAnul(1).Visible = False
        Case 1
            Opt_AnulBol(0).Value = False
            Opt_AnulBol(1).Value = True
            Frame_TipAnul(0).Visible = False
            Frame_TipAnul(1).Visible = True
        Case Else
            Err.Raise vbObjectError + 777, "Form_Boletas_Anular.Opt_AnulBol", " Indice fuera del intervalo esperado."
    End Select
    
End Sub

