VERSION 5.00
Begin VB.Form Form_liberar_folios 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Liberar folios"
   ClientHeight    =   1980
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   4365
   Icon            =   "Form_liberar_folios.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   1980
   ScaleWidth      =   4365
   Begin VB.Frame Frame1 
      Caption         =   "Ingrese rango de folios"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1695
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   4095
      Begin VB.CommandButton cmd_salir 
         Caption         =   "Salir"
         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        =   4
         Top             =   1080
         Width           =   1455
      End
      Begin VB.CommandButton cmd_eliminar 
         Caption         =   "Eliminar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   480
         TabIndex        =   3
         Top             =   1080
         Width           =   1455
      End
      Begin VB.TextBox txt_final 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   2280
         TabIndex        =   2
         Top             =   480
         Width           =   1455
      End
      Begin VB.TextBox txt_inicial 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   480
         TabIndex        =   1
         Top             =   480
         Width           =   1455
      End
   End
End
Attribute VB_Name = "Form_liberar_folios"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_eliminar_Click()
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim min_folio As Long
    Dim max_folio As Long
    Dim accion_detalle As String
    Dim run_alu As String
    Dim run_apo As String
    Dim permiso As Integer
    
    'Falta dar permiso en tabla usuarios
    permiso = Val(devuelvecampo("usuarios", "", "liberacion_folios", "aut_nombre_usuario = '" & Nom_usu_ses & "'", conn))
    If permiso = 0 Then
        MsgBox "Ud. no tiene privilegios para realizar cambios en este modulo", vbInformation
        Exit Sub
    End If
    
    'Valido Cantidad de folios
    If (txt_final.Text - txt_inicial.Text) > 20 Then
        MsgBox "Ud. no puede eliminar un rango de mas de 20 folios"
        limpiar
        Exit Sub
    End If
    
    'Valido que exista ese rango
     var_sql = "SELECT min(folio_blta_fisico) as minimo,max(folio_blta_fisico) as maximo,max(folio_blta_fisico) as total FROM fnza_boletas" _
            & " WHERE folio_blta_fisico >= " & txt_inicial.Text & " AND folio_blta_fisico <= " & txt_final.Text
     objRS.Open var_sql, conn
     If objRS.RecordCount < 1 Then
        MsgBox "No existe ese rango de folios", vbInformation
        limpiar
        Exit Sub
     Else
        min_folio = objRS("minimo")
        max_folio = objRS("maximo")
     End If
     objRS.Close
            
    'Valido que NOOOOO sean nulas
     var_sql = "SELECT * FROM fnza_boletas" _
            & " WHERE folio_blta_fisico >= " & txt_inicial.Text & " AND folio_blta_fisico <= " & txt_final.Text & " and estado_blta <> 'nula'"
     objRS.Open var_sql, conn
     If objRS.RecordCount > 0 Then
        MsgBox "Los folios NO se pueden liberar si las boletas no se encuentran nulas", vbInformation
        limpiar
        Exit Sub
     End If
     objRS.Close
               
    'Valido que NOOOOO sean nulas
    var_sql = "SELECT * FROM fnza_movimientos_mensualidad WHERE folio_mvto IN (SELECT folio_mvto FROM fnza_dtll_mvto" _
            & " WHERE folio_blta IN (SELECT folio_blta  FROM fnza_boletas" _
            & " WHERE folio_blta_fisico >= " & txt_inicial.Text & " AND folio_blta_fisico <= " & txt_final.Text & "))" _
            & " and estado_pago <> 'nula'"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        MsgBox "Los folios NO se pueden liberar si las boletas no se encuentran nulas", vbInformation
        limpiar
        Exit Sub
    End If
    objRS.Close
        
    'Elimino boletas
    var_sql = "delete FROM fnza_movimientos_mensualidad WHERE folio_mvto IN (SELECT folio_mvto FROM fnza_dtll_mvto" _
            & " WHERE folio_blta IN (SELECT folio_blta  FROM fnza_boletas" _
            & " WHERE folio_blta_fisico >= " & txt_inicial.Text & " AND folio_blta_fisico <= " & txt_final.Text & "))"
    conn.Execute var_sql
    var_sql = "delete FROM fnza_dtll_mvto WHERE folio_blta IN (SELECT folio_blta  FROM fnza_boletas" _
            & " WHERE folio_blta_fisico >= " & txt_inicial.Text & " AND folio_blta_fisico <= " & txt_final.Text & ")"
    conn.Execute var_sql
    var_sql = "DELETE FROM fnza_boletas WHERE folio_blta_fisico >= " & txt_inicial.Text & " AND folio_blta_fisico <= " & txt_final.Text
    conn.Execute var_sql
       
    'Log de liberacion
    accion_detalle = "Se han liberado los folios desde el " & min_folio & " hasta el " & max_folio
    Call Inserta_Vitacora_Finanza(run_alu, run_apo, "Liberación de folios", CStr(accion_detalle), min_folio, max_folio)
            
    limpiar
    MsgBox "Los folios fueron liberados satisfactoriamente", vbInformation
           
End Sub

Private Sub cmd_salir_Click()
    Unload Me
End Sub

Private Sub txt_inicial_Change()
    txt_final.Text = txt_inicial.Text
End Sub

Private Sub limpiar()
    txt_final.Text = ""
    txt_inicial.Text = ""
End Sub
