VERSION 5.00
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_man_cupon 
   Caption         =   "Mantención Cuponeras"
   ClientHeight    =   6795
   ClientLeft      =   3000
   ClientTop       =   2910
   ClientWidth     =   10020
   Icon            =   "Form_man_cupon.frx":0000
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   6795
   ScaleWidth      =   10020
   Begin VB.TextBox Txt_Arancel_Base 
      Height          =   285
      Left            =   8040
      TabIndex        =   43
      TabStop         =   0   'False
      Top             =   2160
      Visible         =   0   'False
      Width           =   1815
   End
   Begin VB.Frame Frame2 
      Caption         =   "Detalle Cuponera"
      ForeColor       =   &H00FF0000&
      Height          =   2295
      Left            =   120
      TabIndex        =   33
      Top             =   2520
      Width           =   8175
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid Grd_DetaCupon 
         Height          =   1815
         Left            =   120
         TabIndex        =   34
         Top             =   360
         Width           =   7935
         _ExtentX        =   13996
         _ExtentY        =   3201
         _Version        =   393216
         SelectionMode   =   1
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Detalle Alumnos del Apoderado"
      ForeColor       =   &H00FF0000&
      Height          =   1695
      Left            =   120
      TabIndex        =   31
      Top             =   4920
      Width           =   8175
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid Grd_AluxApo 
         Height          =   1335
         Left            =   120
         TabIndex        =   32
         TabStop         =   0   'False
         Top             =   240
         Width           =   7935
         _ExtentX        =   13996
         _ExtentY        =   2355
         _Version        =   393216
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin VB.ComboBox Cmb_ColegioCup 
      Height          =   315
      Left            =   1080
      Style           =   2  'Dropdown List
      TabIndex        =   30
      Top             =   2160
      Width           =   2895
   End
   Begin VB.CheckBox Chk_Todos_Cupones 
      Caption         =   "Mostrar todos los Movimientos realizados"
      Height          =   195
      Left            =   4440
      TabIndex        =   29
      Top             =   2160
      Width           =   5415
   End
   Begin VB.TextBox Txt_Conv_Bci 
      Height          =   285
      Left            =   9360
      TabIndex        =   27
      TabStop         =   0   'False
      Top             =   120
      Visible         =   0   'False
      Width           =   495
   End
   Begin VB.TextBox Txt_OpeCupon 
      Height          =   285
      Left            =   7320
      Locked          =   -1  'True
      TabIndex        =   26
      TabStop         =   0   'False
      Top             =   120
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.TextBox Txt_Fin_GCup 
      Height          =   285
      Left            =   8640
      Locked          =   -1  'True
      TabIndex        =   25
      TabStop         =   0   'False
      Top             =   120
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.TextBox Txt_Ini_GCup 
      Height          =   285
      Left            =   8040
      Locked          =   -1  'True
      TabIndex        =   24
      TabStop         =   0   'False
      Top             =   120
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.ListBox Lst_busq_nom 
      Height          =   1425
      Left            =   1560
      TabIndex        =   2
      Top             =   360
      Width           =   3855
   End
   Begin VB.ListBox Lst_busq_rut 
      Height          =   1425
      Left            =   5880
      TabIndex        =   4
      Top             =   360
      Width           =   1335
   End
   Begin VB.TextBox txt_nom_apo 
      Height          =   285
      Left            =   1560
      TabIndex        =   1
      Top             =   120
      Width           =   3855
   End
   Begin VB.CommandButton Btn_Salir 
      Caption         =   "Salir"
      Height          =   375
      Left            =   8400
      TabIndex        =   14
      Top             =   6240
      Width           =   1335
   End
   Begin VB.TextBox txt_rut_apo 
      Height          =   285
      Left            =   5880
      TabIndex        =   3
      Top             =   120
      Width           =   1335
   End
   Begin VB.Frame Frame_Busqueda 
      Caption         =   "Búsqueda"
      ForeColor       =   &H00FF0000&
      Height          =   1575
      Left            =   120
      TabIndex        =   16
      Top             =   480
      Width           =   9855
      Begin VB.ComboBox Cmb_Anho 
         Height          =   315
         Left            =   6720
         Style           =   2  'Dropdown List
         TabIndex        =   46
         Top             =   600
         Width           =   1095
      End
      Begin VB.Frame Frame_TipoBus 
         Height          =   975
         Index           =   1
         Left            =   2640
         TabIndex        =   19
         Top             =   480
         Width           =   3375
         Begin VB.ComboBox Cmb_Mes_Ini 
            BackColor       =   &H00FFFFFF&
            ForeColor       =   &H00404040&
            Height          =   315
            ItemData        =   "Form_man_cupon.frx":2A8B2
            Left            =   1680
            List            =   "Form_man_cupon.frx":2A8DD
            Style           =   2  'Dropdown List
            TabIndex        =   9
            Top             =   240
            Width           =   1575
         End
         Begin VB.ComboBox Cmb_Mes_Fin 
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "Form_man_cupon.frx":2A946
            Left            =   1680
            List            =   "Form_man_cupon.frx":2A948
            Style           =   2  'Dropdown List
            TabIndex        =   10
            Top             =   600
            Width           =   1575
         End
         Begin VB.Label Label3 
            Caption         =   "Cuota Mes Inicio"
            Height          =   255
            Left            =   120
            TabIndex        =   21
            Top             =   240
            Width           =   1455
         End
         Begin VB.Label Label5 
            Caption         =   "Cuota Mes Término"
            Height          =   255
            Left            =   120
            TabIndex        =   20
            Top             =   600
            Width           =   1575
         End
      End
      Begin VB.OptionButton Opt_TipoBus 
         Caption         =   "Por Rango de Meses"
         Height          =   255
         Index           =   1
         Left            =   2760
         TabIndex        =   6
         Top             =   240
         Width           =   2175
      End
      Begin VB.ComboBox cmb_Banco 
         Height          =   315
         Left            =   6720
         Style           =   2  'Dropdown List
         TabIndex        =   11
         Top             =   240
         Width           =   3015
      End
      Begin VB.CommandButton btn_can_bus 
         Caption         =   "Cancelar"
         Height          =   375
         Left            =   8160
         TabIndex        =   13
         Top             =   1080
         Width           =   1215
      End
      Begin VB.CommandButton btn_buscar 
         Caption         =   "Buscar"
         Height          =   375
         Left            =   6840
         TabIndex        =   12
         Top             =   1080
         Width           =   1215
      End
      Begin VB.Frame Frame_TipoBus 
         Height          =   975
         Index           =   0
         Left            =   120
         TabIndex        =   18
         Top             =   480
         Width           =   2415
         Begin VB.ComboBox Cmb_FinCupon 
            Height          =   315
            Left            =   1560
            Style           =   2  'Dropdown List
            TabIndex        =   8
            Top             =   600
            Width           =   735
         End
         Begin VB.ComboBox Cmb_IniCupon 
            Height          =   315
            ItemData        =   "Form_man_cupon.frx":2A94A
            Left            =   1560
            List            =   "Form_man_cupon.frx":2A96F
            Style           =   2  'Dropdown List
            TabIndex        =   7
            Top             =   240
            Width           =   735
         End
         Begin VB.Label Label2 
            Caption         =   "Nº Cupón Inicio"
            Height          =   255
            Left            =   120
            TabIndex        =   23
            Top             =   240
            Width           =   1335
         End
         Begin VB.Label Label4 
            Caption         =   "Nº Cupón Término"
            Height          =   255
            Left            =   120
            TabIndex        =   22
            Top             =   600
            Width           =   1455
         End
      End
      Begin VB.OptionButton Opt_TipoBus 
         Caption         =   "Por Nº de Cupón"
         Height          =   255
         Index           =   0
         Left            =   240
         TabIndex        =   5
         Top             =   240
         Width           =   2175
      End
      Begin VB.Label Label8 
         Caption         =   "Año"
         Height          =   255
         Left            =   6120
         TabIndex        =   47
         Top             =   600
         Width           =   615
      End
      Begin VB.Label Banco 
         Caption         =   "Banco"
         Height          =   255
         Left            =   6120
         TabIndex        =   17
         Top             =   240
         Width           =   615
      End
   End
   Begin VB.Frame Frame_Botones 
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   3495
      Left            =   8280
      TabIndex        =   28
      Top             =   2640
      Width           =   1575
      Begin VB.CommandButton Btn_MantCup 
         Caption         =   "Ver Cupón"
         Height          =   375
         Index           =   0
         Left            =   120
         TabIndex        =   41
         Top             =   0
         Width           =   1335
      End
      Begin VB.CommandButton Btn_Imprimir 
         Caption         =   "Imprimir"
         Height          =   375
         Left            =   120
         TabIndex        =   40
         Top             =   600
         Width           =   1335
      End
      Begin VB.CommandButton Btn_Cancelar 
         Caption         =   "Cancelar"
         Height          =   375
         Left            =   120
         TabIndex        =   39
         Top             =   1200
         Width           =   1335
      End
      Begin VB.CommandButton Btn_MantCup 
         Caption         =   "Modificar"
         Height          =   375
         Index           =   1
         Left            =   120
         TabIndex        =   38
         Top             =   1800
         Width           =   1335
      End
      Begin VB.CommandButton Btn_MantCup 
         Caption         =   "Eliminar"
         Height          =   375
         Index           =   2
         Left            =   120
         TabIndex        =   37
         Top             =   2400
         Width           =   1335
      End
      Begin VB.CommandButton Btn_MantCup 
         Caption         =   "Anular"
         Height          =   375
         Index           =   3
         Left            =   120
         TabIndex        =   36
         Top             =   3000
         Width           =   1335
      End
   End
   Begin VB.TextBox Txt_Cta_Cte 
      Height          =   285
      Left            =   8040
      Locked          =   -1  'True
      TabIndex        =   44
      Top             =   2160
      Visible         =   0   'False
      Width           =   1935
   End
   Begin VB.TextBox Txt_ListIndex 
      Height          =   285
      Left            =   7440
      TabIndex        =   42
      TabStop         =   0   'False
      Top             =   2160
      Visible         =   0   'False
      Width           =   495
   End
   Begin VB.Label Label7 
      Caption         =   "Cuenta Corriente :"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6480
      TabIndex        =   45
      Top             =   2160
      Visible         =   0   'False
      Width           =   1575
   End
   Begin VB.Label Label6 
      Caption         =   "Colegio : "
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   35
      Top             =   2160
      Width           =   1095
   End
   Begin VB.Label Rut 
      Caption         =   "Rut"
      Height          =   255
      Left            =   5520
      TabIndex        =   15
      Top             =   120
      Width           =   375
   End
   Begin VB.Label Label1 
      Caption         =   "Apoderado"
      Height          =   255
      Left            =   480
      TabIndex        =   0
      Top             =   120
      Width           =   855
   End
End
Attribute VB_Name = "Form_man_cupon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Abancos() As Variant, AColegios() As Variant, Alumnos As Integer
Dim Flag_Sub As Boolean, FilaCupon As Long
Dim MesIniCupon, MesFinCupon As Integer
Dim Inicupon, FinCupon As String
Dim CodColegio As String, CuentaCteCol As String, ConvBci As String
Private Sub btn_buscar_Click()
If (Me.Opt_TipoBus(0).Value And (Me.Cmb_IniCupon <> "" And Me.Cmb_FinCupon <> "")) Or (Me.Opt_TipoBus(1).Value And (Me.Cmb_Mes_Ini <> "" And Me.Cmb_Mes_Fin <> "")) And Me.cmb_banco <> "" And Me.Cmb_Anho <> "" Then
    ' llenar el combo
    Call Trae_Alumnos
    Me.Cmb_ColegioCup.Clear
    Call llenacomboconarreglo(Me.Cmb_ColegioCup, "fnza_cuponeras f, hist_cod_colegio h where f.colegio=h.colegio and f.rut_apo ='" & Me.txt_rut_apo & "'", "distinct h.nombre", "f.colegio", AColegios(), conn)
    If Me.Cmb_ColegioCup.ListCount > 0 Then
        Me.Cmb_ColegioCup.ListIndex = 0
    End If
Else
    MsgBox ("Faltan Opciones por seleccionar")
End If
End Sub

Private Sub btn_can_bus_Click()
Flag_Sub = False
Me.Opt_TipoBus(1).Value = True
Me.Frame_Busqueda.Enabled = False
Me.txt_nom_apo = "": Me.txt_rut_apo = ""
Me.txt_nom_apo.SetFocus
Me.Cmb_Anho.ListIndex = -1
Me.Chk_Todos_Cupones.Value = 0
Me.Cmb_ColegioCup.Clear
Call IniGrilla_Cupones
Call IniGrilla_AluxApo
'Me.cmb_Banco.ListIndex = -1
End Sub

Private Sub Btn_Cancelar_Click()
Call btn_can_bus_Click
End Sub

Private Sub Btn_Imprimir_Click()
    Call CreaBD(DirAplicacion & "\rpt\gestemp.mdb")
    Call CreaTabla(DirAplicacion & "\rpt\gestemp.mdb", "Detalles", "11,10")
    Call RptGrillaTextH(Grd_DetaCupon, Grd_DetaCupon.Rows - 1, "\rpt\gestemp.mdb", "Detalles")
    Titulo = "DETALLE DE CUPONERA"
    Nombrecol = devuelvecampo("establecimientos", "", "nom_est", "nom_est <> ''", conn)
    Direccol = devuelvecampo("establecimientos", "", "dir_est", "dir_est <> ''", conn)
    ComunaCol = devuelvecampo("establecimientos", "", "localidad_est", "localidad_est <> ''", conn)
    Form_main.CrystalReport.WindowTitle = Titulo
    Form_main.CrystalReport.Formulas(0) = "nomcol = '" & Nombrecol & "'"
    Form_main.CrystalReport.Formulas(1) = "dircol = '" & Direccol & "'"
    Form_main.CrystalReport.Formulas(2) = "comunacol = '" & ComunaCol & "'"
    Form_main.CrystalReport.Formulas(3) = "titulo= '" & Titulo & "'"
    Form_main.CrystalReport.Formulas(4) = "hora = '" & Time & "'"
    Form_main.CrystalReport.Formulas(5) = "nombreapo = '" & Me.txt_nom_apo & "'"
    Form_main.CrystalReport.Formulas(6) = "rutapo = '" & Me.txt_rut_apo & "'"
    Form_main.CrystalReport.Formulas(7) = "anho = '" & Me.Cmb_Anho & "'"
    Form_main.CrystalReport.Formulas(8) = "colegio = '" & UCase(Me.Cmb_ColegioCup) & "'"
    Form_main.CrystalReport.Formulas(9) = "banco = '" & UCase(Me.cmb_banco) & "'"
    
    For t = 1 To Alumnos
        Form_main.CrystalReport.Formulas(10 + t) = "Alumno" & t & " = '" & Me.Grd_AluxApo.TextMatrix(t, 0) & ".-" & Me.Grd_AluxApo.TextMatrix(t, 1) & "'"
        Form_main.CrystalReport.Formulas(11 + t) = "Curso" & t & " = '" & Me.Grd_AluxApo.TextMatrix(t, 3) & "'"
    Next t
    
    Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\DetaCuponera.rpt"
    Form_main.CrystalReport.DataFiles(0) = DirAplicacion & "\rpt\gestemp.mdb"
    Form_main.CrystalReport.WindowState = crptMaximized
    Form_main.CrystalReport.ReplaceSelectionFormula ("")
    Form_main.CrystalReport.Action = 1
    Form_main.CrystalReport.ReplaceSelectionFormula ("")
    Call LimpiaFormulas(Form_main.CrystalReport, 20)
    'Kill (DirAplicacion & "\rpt\gestemp.mdb")
End Sub

Private Sub Btn_MantCup_Click(Index As Integer)
If FilaCupon > 0 And Me.Grd_DetaCupon.TextMatrix(FilaCupon, 0) <> "" Then
    Select Case Index
        Case 0 ' Ver Cupón
            Me.Txt_OpeCupon = "VC"
        Case 1 'Modificar
            Me.Txt_OpeCupon = "MC"
        Case 2 'Eliminar
            Me.Txt_OpeCupon = "EC"
        Case 3 'Anular
            Me.Txt_OpeCupon = "AC"
    End Select
    If Me.Grd_DetaCupon.Row > Me.Grd_DetaCupon.RowSel Then
        Me.Txt_Ini_GCup = Me.Grd_DetaCupon.RowSel
        Me.Txt_Fin_GCup = Me.Grd_DetaCupon.Row
    ElseIf Me.Grd_DetaCupon.RowSel > Me.Grd_DetaCupon.Row Then
        Me.Txt_Ini_GCup = Me.Grd_DetaCupon.Row
        Me.Txt_Fin_GCup = Me.Grd_DetaCupon.RowSel
    Else
        Me.Txt_Ini_GCup = Me.Grd_DetaCupon.Row
        Me.Txt_Fin_GCup = Me.Grd_DetaCupon.RowSel
    End If
    Call VerCupon
Else
    MsgBox ("Debe Seleccionar uno o más Cupones")
End If
End Sub

Private Sub Btn_Salir_Click()
Unload Me
End Sub

Private Sub Cmb_ColegioCup_Click()
If Me.Cmb_ColegioCup.ListIndex > -1 Then
    Me.Txt_ListIndex = Me.Cmb_ColegioCup.ListIndex
    CodColegio = AColegios(Me.Cmb_ColegioCup.ListIndex)
    Me.Txt_Cta_Cte = devuelvecampo("fnza_cod_cta_cte", "", "cta_cte", "colegio ='" & CodColegio & "'", conn)
    Me.Txt_Conv_Bci = devuelvecampo("hist_cod_colegio", "", "cod_conv_bci", "colegio ='" & CodColegio & "'", conn)
    Me.Txt_Arancel_Base = devuelvecampo("fnza_descuento", "", "arancel_base", "colegio ='" & CodColegio & "'", conn)
    Call Trae_Cupones ' Según Colegio
    Call MensAlumnos
    Me.Grd_DetaCupon.Row = 0: FilaCupon = 0
End If
End Sub

Private Sub Cmb_FinCupon_Click()
    Inicupon = Me.Cmb_IniCupon.Text
    FinCupon = Me.Cmb_FinCupon.Text
End Sub

Private Sub Cmb_IniCupon_Click()
p = Me.Cmb_IniCupon.ListIndex
'D = 0
Me.Cmb_FinCupon.Clear
If p >= 0 Then
    For t = p To Me.Cmb_IniCupon.ListCount - 1
        Me.Cmb_FinCupon.AddItem Me.Cmb_IniCupon.List(t)
 '      D = D + 1
    Next t
    Me.Cmb_FinCupon.ListIndex = Me.Cmb_IniCupon.ListIndex - p
End If
End Sub

Private Sub Cmb_Mes_fin_Click()
    MesIniCupon = CInt(Me.Cmb_Mes_Ini.ItemData(Me.Cmb_Mes_Ini.ListIndex))
    MesFinCupon = CInt(Me.Cmb_Mes_Fin.ItemData(Me.Cmb_Mes_Fin.ListIndex))
End Sub

Private Sub Cmb_Mes_ini_Click()
p = Me.Cmb_Mes_Ini.ListIndex
D = 0
Me.Cmb_Mes_Fin.Clear
If p >= 0 Then
    For t = p To Me.Cmb_Mes_Ini.ListCount - 1
        Me.Cmb_Mes_Fin.AddItem Me.Cmb_Mes_Ini.List(t)
        Me.Cmb_Mes_Fin.ItemData(D) = Me.Cmb_Mes_Ini.ItemData(t)
        D = D + 1
    Next t
    Me.Cmb_Mes_Fin.ListIndex = Me.Cmb_Mes_Ini.ListIndex - p
End If
End Sub

Private Sub Form_Load()
    Dim Indbci As Integer
    Set Rs = New ADODB.Recordset
    Me.Height = 7200
    Me.Width = 10095
    Me.Frame_Busqueda.Enabled = False
    Me.Lst_busq_nom.Visible = False
    Me.Lst_busq_rut.Visible = False
    Call llenacomboconarreglo(Me.cmb_banco, "fnza_cod_banco", "descripcion", "banco", Abancos, conn)
    Indbci = ValorenArray(Abancos, "16")
    If Indbci >= 0 Then
        Me.cmb_banco.ListIndex = Indbci
    End If
    Call IniGrilla_Cupones
    Call IniGrilla_AluxApo
    Me.Cmb_Anho.AddItem Anno: Me.Cmb_Anho.AddItem Val(Anno + 1)
    Me.Cmb_Anho.ListIndex = 0
    Me.Frame_Botones.Enabled = False
    Me.Txt_OpeCupon = ""
    Me.Txt_Ini_GCup = "": Me.Txt_Fin_GCup = ""
    Flag_Sub = False
    Me.Opt_TipoBus(1).Value = True: Alumnos = 0
End Sub

Private Sub Grd_DetaCupon_SelChange()
FilaCupon = Me.Grd_DetaCupon.Row
If Me.Grd_DetaCupon.TextMatrix(FilaCupon, 0) <> "" Then
    If UCase(Me.Grd_DetaCupon.TextMatrix(FilaCupon, 6)) = "PENDIENTE" Then
        Call BotonesMant(True)
    ElseIf UCase(Me.Grd_DetaCupon.TextMatrix(FilaCupon, 6)) = "PAGADO" Then
        Call BotonesMant(False)
        MsgBox ("El Cupón se encuentra Pagado, por lo que no permite mantenciones")
    ElseIf UCase(Me.Grd_DetaCupon.TextMatrix(FilaCupon, 6)) = "ANULADO" Then
        Call BotonesMant(False)
        MsgBox ("El Cupón se encuentra Nulo, por lo que no permite mantenciones")
    Else
        Call BotonesMant(False)
        MsgBox ("El Cupón se encuentra eliminado, por lo que no permite mantenciones")
    End If
End If
End Sub

Private Sub Lst_busq_nom_DblClick()
    Me.txt_nom_apo.Text = Me.Lst_busq_nom.Text
    Me.Lst_busq_nom.Visible = False
    Me.Lst_busq_rut.Visible = False
    Me.Frame_Busqueda.Enabled = True
    Rs.CursorLocation = adUseClient
    Rs.Open "SELECT rut_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(Me.txt_nom_apo.Text) & ")='" & Me.txt_nom_apo.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    Rs.MoveFirst
    Flag_Sub = True
    Me.txt_rut_apo.Text = Rs("rut_apo")
    Flag_Sub = False
    Rs.Close
End Sub

Private Sub Lst_busq_rut_DblClick()
    Me.txt_rut_apo.Text = Me.Lst_busq_rut.Text
    Me.Lst_busq_rut.Visible = False
    Me.Lst_busq_nom.Visible = False
    Me.Frame_Busqueda.Enabled = True
    Rs.CursorLocation = adUseClient
    Rs.Open "SELECT CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo FROM apoderados where rut_apo='" & Me.txt_rut_apo.Text & "' ORDER BY rut_apo;", conn
    Rs.MoveFirst
    Flag_Sub = True
    If Rs.RecordCount > 0 Then
        Me.txt_nom_apo.Text = Rs("nombre_apo")
    End If
    Flag_Sub = False
    Rs.Close
End Sub

Private Sub txt_dig_apo_Change()

End Sub

Private Sub txt_ini_cupon_Change()

End Sub

Private Sub Opt_TipoBus_Click(Index As Integer)
Select Case Index
    Case 0
        Me.Cmb_Mes_Fin.Clear
        Me.Cmb_Mes_Ini.ListIndex = -1
        Me.Cmb_Mes_Ini.BackColor = &H80000005
        Me.Cmb_Mes_Fin.BackColor = &H80000005
        Me.Cmb_IniCupon.BackColor = &HC0FFFF
        Me.Cmb_FinCupon.BackColor = &HC0FFFF
    Case 1
        Me.Cmb_FinCupon.Clear
        Me.Cmb_IniCupon.ListIndex = -1
        Me.Cmb_IniCupon.BackColor = &H80000005
        Me.Cmb_FinCupon.BackColor = &H80000005
        Me.Cmb_Mes_Ini.BackColor = &HC0FFFF
        Me.Cmb_Mes_Fin.BackColor = &HC0FFFF
End Select
Dim Otroindice As Integer
Otroindice = (Index - 1) * -1
Me.Frame_TipoBus(Otroindice).Enabled = False
Me.Frame_TipoBus(Index).Enabled = True
End Sub

Private Sub txt_nom_apo_Change()
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_Sub Then Exit Sub
    Rs.CursorLocation = adUseClient
    Rs.Open "SELECT ape1_apo, ape2_apo, noms_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(Me.txt_nom_apo) & ")='" & Me.txt_nom_apo & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    Me.Lst_busq_nom.Clear
    While Not (Rs.EOF)
        Me.Lst_busq_nom.AddItem Rs("ape1_apo") & " " & Rs("ape2_apo") & " " & Rs("noms_apo")
        Rs.MoveNext
    Wend
    Rs.Close
    Me.Lst_busq_nom.Visible = True
End Sub

Private Sub txt_nom_apo_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If (Me.Lst_busq_nom.ListCount = 0) Then
            Exit Sub
        End If
        Lst_busq_nom.Selected(0) = True
        Flag_Sub = True
        Me.txt_nom_apo = Lst_busq_nom.Text
        Flag_Sub = False
        Call Lst_busq_nom_DblClick
    End If
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txt_rut_apo_Change()
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_Sub Then Exit Sub
    Rs.CursorLocation = adUseClient
    Rs.Open "SELECT rut_apo FROM apoderados WHERE left(rut_apo," & Len(Me.txt_rut_apo.Text) & ")='" & Me.txt_rut_apo.Text & "' ORDER BY rut_apo;", conn
    Me.Lst_busq_rut.Clear
    While Not (Rs.EOF)
        Me.Lst_busq_rut.AddItem Rs("rut_apo")
        Rs.MoveNext
    Wend
    Rs.Close
    Lst_busq_rut.Visible = True
End Sub
Sub Trae_Cupones()
    Dim EstadO As String, rango As String ' Cadena con intervalo de Meses
    Dim TCupones ' tipos de cupones a mostrar
    Call IniGrilla_Cupones
    If Me.Opt_TipoBus(0).Value Then
        rango = "and right(d.numero,2) >= '" & Inicupon & "' and right(d.numero,2) <= '" & FinCupon & "'"
    Else
        rango = "and d.mes >= " & MesIniCupon & " and d.mes <= " & MesFinCupon
    End If
    TCupones = IIf(Me.Chk_Todos_Cupones.Value, "", "and (ucase(d.estado)='PE' or ucase(d.estado)='PA')")
    Rs.CursorLocation = adUseClient
    Rs.Open "select * from fnza_cuponeras c, fnza_deta_cupones d where c.folio_cuponera=d.folio_cuponera and c.rut_apo='" & Trim(Me.txt_rut_apo) & "' " & rango & " and c.colegio ='" & CodColegio & "' " & TCupones & " and c.agno ='" & Me.Cmb_Anho & "' order by d.numero, d.folio_cupon", conn
    fila = 0
    If Rs.RecordCount > 0 Then
        For t = 1 To Rs.RecordCount
            fila = fila + 1
            If fila > 1 Then
                Me.Grd_DetaCupon.AddItem ""
            End If
            Me.Grd_DetaCupon.TextMatrix(fila, 0) = fila
            Me.Grd_DetaCupon.TextMatrix(fila, 1) = Rs!folio_cupon
            Me.Grd_DetaCupon.TextMatrix(fila, 2) = Rs!Numero
            Me.Grd_DetaCupon.TextMatrix(fila, 3) = MesATexto(Rs!Mes)
            Me.Grd_DetaCupon.TextMatrix(fila, 4) = Rs!Vcto
            Me.Grd_DetaCupon.TextMatrix(fila, 5) = Rs!Valor
            Select Case UCase(Rs!EstadO)
                    Case "PE"
                        EstadO = "Pendiente"
                    Case "PA"
                        EstadO = "Pagado"
                    Case "NU"
                        EstadO = "Anulado"
                    Case "EL"
                        EstadO = "Eliminado"
            End Select
            Me.Grd_DetaCupon.TextMatrix(fila, 6) = EstadO
            Me.Grd_DetaCupon.TextMatrix(fila, 7) = Rs!folio_cuponera
            Me.Grd_DetaCupon.TextMatrix(fila, 8) = Rs!fecha_gen
            Me.Grd_DetaCupon.TextMatrix(fila, 9) = Rs!Ubicacion
            Me.Grd_DetaCupon.TextMatrix(fila, 10) = Rs!Mes
            Me.Grd_DetaCupon.Refresh
            Rs.MoveNext
        Next t
        Me.Frame_Botones.Enabled = True
    Else
        Me.Frame_Botones.Enabled = False
    End If
    Rs.Close
'Eliminación de ultima fila
'If Fila > 1 Then
'    Me.Grd_DetaCupon.RemoveItem Me.Grd_DetaCupon.Rows - 1
'Else
'    If Me.Grd_DetaCupon.TextMatrix(1, 0) <> "" Then
'        Me.Grd_DetaCupon.RemoveItem Me.Grd_DetaCupon.Rows - 1
'    End If
'End If
End Sub
Sub Trae_Alumnos()
Call IniGrilla_AluxApo
Rs.CursorLocation = adUseClient
Rs.Open "select p.ci_alu, concat(p.ape_pat_alu,' ',p.ape_mat_alu,' ',p.nom_alu) as nombrealu, c.cod_des, ac.num_gra, ac.let_cur from postulantes p, apoderados a, apo_x_alu aa, alu_x_cur ac, codigos_ensenanza c WHERE a.rut_apo=aa.rut_apo AND aa.ci_alu=p.ci_alu AND aa.agno=ac.agno AND ac.agno=" & Cmb_Anho.Text & " and p.ci_alu=ac.ci_alu and ac.activo_alu='SI' and ac.cod_ens=c.cod_ens and a.rut_apo ='" & Trim(Me.txt_rut_apo) & "' order by c.ord_ens Desc", conn
fila = 0
If Rs.RecordCount > 0 Then
    For t = 1 To Rs.RecordCount
        Me.Grd_AluxApo.AddItem ""
        fila = fila + 1
        Me.Grd_AluxApo.TextMatrix(fila, 0) = fila
        Me.Grd_AluxApo.TextMatrix(fila, 1) = Rs!Ci_alu
        Me.Grd_AluxApo.TextMatrix(fila, 2) = Rs!nombrealu
        If UCase(Rs!cod_des) = "K" Or UCase(Rs!cod_des) = "PK" Then
                curso = UCase(Rs!cod_des)
        ElseIf UCase(Rs!cod_des) = "EB" Or UCase(Rs!cod_des) = "EM" Then
                curso = UCase(Rs!Num_Gra) & "º" & UCase(Rs!Let_Cur)
        End If
        Me.Grd_AluxApo.TextMatrix(fila, 3) = IIf(EselMayor(Rs!Ci_alu, Anno), "Mayor", "Menor")
        Me.Grd_AluxApo.TextMatrix(fila, 4) = curso
        Rs.MoveNext
    Next t
End If
Rs.Close
Alumnos = fila
End Sub

Sub IniGrilla_Cupones()
Me.Grd_DetaCupon.Redraw = True
Me.Grd_DetaCupon.Clear
Me.Grd_DetaCupon.Rows = 2
Me.Grd_DetaCupon.Cols = 11
Me.Grd_DetaCupon.FixedCols = 0
Me.Grd_DetaCupon.FixedRows = 1
                            '        0       1           2          3            4            5            6               7              8             9          10
Me.Grd_DetaCupon.FormatString = "^ Item |Folio Cupón |NºCupón |Mes Cupón   |Fecha Venc. |Valor Cupón |Estado Cupón |Folio Cuponera |Fecha Creación |Ubicación| Nº de Mes"
Me.Grd_DetaCupon.ColWidth(0) = 500 ' Item
Me.Grd_DetaCupon.ColWidth(1) = 0 ' Folio Cupón
Me.Grd_DetaCupon.ColWidth(2) = 1100 ' NºCupón
Me.Grd_DetaCupon.ColWidth(3) = 1000 ' Mes Cupón
Me.Grd_DetaCupon.ColWidth(4) = 1000 ' Fecha Venc.
Me.Grd_DetaCupon.ColWidth(5) = 1000 ' Valor Cupón
Me.Grd_DetaCupon.ColWidth(6) = 1100 ' Estado Cupón
Me.Grd_DetaCupon.ColWidth(7) = 0 ' Folio Cuponera
Me.Grd_DetaCupon.ColWidth(8) = 1100 ' Fecha Creación
Me.Grd_DetaCupon.ColWidth(9) = 900 ' Ubicacion
Me.Grd_DetaCupon.ColWidth(10) = 0 ' Nmes
End Sub
Sub IniGrilla_AluxApo()
Me.Grd_AluxApo.Clear
Me.Grd_AluxApo.Rows = 2
Me.Grd_AluxApo.Cols = 5
Me.Grd_AluxApo.FixedCols = 0
Me.Grd_AluxApo.FixedRows = 1
                            '        0       1           2          3         4
Me.Grd_AluxApo.FormatString = "^ Item |^ Rut Alumno |Nombre Alumno |Hijo   |Curso   "
Me.Grd_AluxApo.ColWidth(0) = 500 ' Item
Me.Grd_AluxApo.ColWidth(1) = 1000 ' RutAlumno
Me.Grd_AluxApo.ColWidth(2) = 3500 ' Nombre Alumno
Me.Grd_AluxApo.ColWidth(3) = 700 ' Mayor
Me.Grd_AluxApo.ColWidth(4) = 700 ' Curso

End Sub
Sub BotonesMant(EstadO As Boolean)
    Me.Btn_MantCup(1).Enabled = EstadO
    Me.Btn_MantCup(2).Enabled = EstadO
    Me.Btn_MantCup(3).Enabled = EstadO
End Sub
Sub VerCupon()
Me.Enabled = False
Load Form_man_cupon_show
End Sub

Sub MensAlumnos()
Dim TotalMes As Long
Me.Grd_AluxApo.TextMatrix(Me.Grd_AluxApo.Rows - 1, 1) = "TOTALES"
If Me.Grd_DetaCupon.Rows > 2 Then
    For t = 1 To Me.Grd_DetaCupon.Rows - 1
        Me.Grd_AluxApo.Cols = Me.Grd_AluxApo.Cols + 1
        Me.Grd_AluxApo.TextMatrix(0, t + 4) = Me.Grd_DetaCupon.TextMatrix(t, 3)
    Next t
    For t = 1 To Me.Grd_DetaCupon.Rows - 1
            TotalMes = 0
        For h = 1 To Me.Grd_AluxApo.Rows - 1
            Mensual = devuelvecampo("fnza_detalle_mensualidad", "", "sum(monto_tot_cuota)", "run_alu='" & Me.Grd_AluxApo.TextMatrix(h, 1) & "' and agno='" & Me.Cmb_Anho & "' and mes = " & Me.Grd_DetaCupon.TextMatrix(t, 10) & " group by mes", conn)
            Me.Grd_AluxApo.TextMatrix(h, t + 4) = (IIf(Mensual = "", 0, CStr(Mensual)))
            TotalMes = TotalMes + Val(Mensual)
        Next h
        Me.Grd_AluxApo.TextMatrix(Me.Grd_AluxApo.Rows - 1, t + 4) = TotalMes
    Next t
End If
For t = 0 To Me.Grd_AluxApo.Cols - 1
    Me.Grd_AluxApo.Row = Me.Grd_AluxApo.Rows - 1: Me.Grd_AluxApo.Col = t
    Me.Grd_AluxApo.CellBackColor = &HC0FFC0
Next t
End Sub
