VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_Pagos_PresencialesV2 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Pagos Presenciales V2"
   ClientHeight    =   8190
   ClientLeft      =   1800
   ClientTop       =   1590
   ClientWidth     =   11850
   FillStyle       =   0  'Solid
   Icon            =   "Form_Pagos_PresencialesV2.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   8190
   ScaleWidth      =   11850
   Begin VB.Frame Frame3 
      Height          =   6135
      Left            =   3480
      TabIndex        =   13
      Top             =   1800
      Visible         =   0   'False
      Width           =   5775
      Begin VB.Frame Frame_Glosa 
         Caption         =   "Glosa de Pago"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1095
         Left            =   240
         TabIndex        =   32
         Top             =   4200
         Width           =   5175
         Begin VB.TextBox Text8 
            Height          =   375
            Left            =   240
            TabIndex        =   33
            Top             =   480
            Width           =   4575
         End
      End
      Begin VB.Frame Frame_Transferencia 
         Caption         =   "Complete los Datos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1455
         Left            =   240
         TabIndex        =   27
         Top             =   1440
         Visible         =   0   'False
         Width           =   5175
         Begin VB.TextBox Text7 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2280
            TabIndex        =   31
            Top             =   960
            Width           =   2295
         End
         Begin VB.TextBox Text6 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2280
            TabIndex        =   30
            Top             =   600
            Width           =   2295
         End
         Begin VB.Label Label6 
            Caption         =   "Número Operación"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   240
            TabIndex        =   29
            Top             =   960
            Width           =   1815
         End
         Begin VB.Label Label5 
            Caption         =   "Número de Cuenta"
            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        =   28
            Top             =   600
            Width           =   1695
         End
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Cancelar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3360
         TabIndex        =   26
         Top             =   5640
         Width           =   1935
      End
      Begin VB.CommandButton Btn_Guardar_Cambios 
         Caption         =   "Registrar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         MaskColor       =   &H80000012&
         TabIndex        =   25
         Top             =   5640
         Width           =   1935
      End
      Begin VB.Frame Frame_Tarjeta 
         Caption         =   "Complete los Datos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1455
         Left            =   240
         TabIndex        =   19
         Top             =   1440
         Visible         =   0   'False
         Width           =   5175
         Begin VB.TextBox Text5 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2280
            TabIndex        =   24
            Top             =   960
            Width           =   2295
         End
         Begin VB.TextBox Text4 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2280
            TabIndex        =   23
            Top             =   600
            Width           =   2295
         End
         Begin VB.Label Label4 
            Caption         =   "Número Autorización"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   240
            TabIndex        =   22
            Top             =   960
            Width           =   1935
         End
         Begin VB.Label Label3 
            Caption         =   "Número Operación"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   240
            TabIndex        =   21
            Top             =   600
            Width           =   1815
         End
      End
      Begin VB.Frame Frame5 
         Caption         =   "Seleccione Medio de Pago"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   975
         Left            =   240
         TabIndex        =   15
         Top             =   240
         Width           =   5175
         Begin VB.OptionButton Option3 
            Caption         =   "Transferencia"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   3480
            TabIndex        =   18
            Top             =   480
            Width           =   1575
         End
         Begin VB.OptionButton Option2 
            Caption         =   "Tarjeta Master Card y Visa"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   1800
            TabIndex        =   17
            Top             =   480
            Width           =   1695
         End
         Begin VB.OptionButton Option1 
            Caption         =   "Tarjeta Débito"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   120
            TabIndex        =   16
            Top             =   480
            Width           =   1695
         End
      End
      Begin VB.Frame Frame4 
         Caption         =   "Ingrese Monto a Pagar"
         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        =   14
         Top             =   3120
         Width           =   3495
         Begin VB.TextBox Text3 
            Height          =   375
            Left            =   240
            TabIndex        =   20
            Top             =   360
            Width           =   2775
         End
      End
   End
   Begin VB.Frame Frame6 
      Caption         =   "Colegio"
      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            =   8520
      TabIndex        =   8
      Top             =   120
      Width           =   3135
      Begin MSComctlLib.ImageCombo ImageCombo2 
         Height          =   345
         Left            =   240
         TabIndex        =   6
         Top             =   360
         Width           =   2655
         _ExtentX        =   4683
         _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            =   "Lincoln College Huechuraba"
      End
   End
   Begin VB.ListBox List2 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   480
      Left            =   6840
      TabIndex        =   11
      TabStop         =   0   'False
      Top             =   720
      Width           =   1335
   End
   Begin VB.ListBox List1 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      Left            =   840
      TabIndex        =   12
      TabStop         =   0   'False
      Top             =   720
      Width           =   5295
   End
   Begin VB.Frame Frame13 
      Caption         =   "Año de Consulta"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   735
      Left            =   6840
      TabIndex        =   9
      Top             =   1320
      Width           =   1575
      Begin VB.ComboBox Combo1 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   240
         Style           =   2  'Dropdown List
         TabIndex        =   10
         Top             =   240
         Width           =   1215
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Alumno(s)"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   2055
      Left            =   120
      TabIndex        =   5
      Top             =   1320
      Width           =   6615
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid Grilla 
         Height          =   1695
         Left            =   120
         TabIndex        =   7
         Top             =   240
         Width           =   6375
         _ExtentX        =   11245
         _ExtentY        =   2990
         _Version        =   393216
         FixedCols       =   0
         BackColorSel    =   14737632
         ForeColorSel    =   16711680
         BackColorBkg    =   -2147483643
         FocusRect       =   0
         FillStyle       =   1
         GridLines       =   0
         GridLinesFixed  =   1
         GridLinesUnpopulated=   1
         ScrollBars      =   2
         SelectionMode   =   1
         RowSizingMode   =   1
         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
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
         _Band(0).GridLineWidthBand=   1
         _Band(0).TextStyleBand=   0
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Apoderado"
      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            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   8295
      Begin VB.TextBox Text2 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   6720
         TabIndex        =   4
         Top             =   360
         Width           =   1335
      End
      Begin VB.TextBox Text1 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   720
         TabIndex        =   2
         Top             =   360
         Width           =   5295
      End
      Begin VB.Label Label2 
         Caption         =   "Run"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   6240
         TabIndex        =   3
         Top             =   360
         Width           =   375
      End
      Begin VB.Label Label1 
         Caption         =   "Nombre"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   1
         Top             =   360
         Width           =   855
      End
   End
End
Attribute VB_Name = "Form_Pagos_PresencialesV2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Flag_sub As Boolean
Dim colegio As String
Dim RC As ADODB.Recordset
Dim CMD As ADODB.Command
Dim CuotasFix() As Boolean
Dim CuotasPag() As Boolean
Dim ResetPago As Boolean

Private Sub Btn_Guardar_Cambios_Click()
    ' Validar y Guardar Cambios
'    Dim Monto_Pagado As Integer
'    Dim QRY As String
'    Dim CMD As ADODB.Command
'    Dim objRS As ADODB.Recordset
'    Set objRS = New ADODB.Recordset
'    Dim var_sql As String
'    Dim log As Boolean
'    Dim Metodo_Pago As String
'    Dim Num_cta_transf As Integer
'    Dim Num_ope_transf As Integer
'    Dim Num_ope_tarj As Integer
'    Dim Num_auto_tarj As Integer
    
    
    Dim QRY As String
    Dim CMD As ADODB.Command
    Dim FechaIngreso As String
    Dim agno As Integer
    Dim nom_apo As String
    Dim rut_apo As String
    Dim Nom_Alu As String
    Dim Rut_ALu As String
    Dim Monto_Pagado As Double
    Dim Metodo_Pago As String
    Dim Num_cta_transf As String
    Dim Num_ope_transf As String
    Dim Num_ope_tarj As String
    Dim Num_auto_tarj As String
    Dim Glosa_Pago As String
    
    ' Valida el metodo de pago seleccionado
    If Not ((Option1.Value Or Option2.Value Or Option3.Value)) Then
        MsgBox "Debe seleccionar un medio de pago", vbInformation, "Metodos de Pago"
        Exit Sub
    End If
    
    ' Valida el monto ingresado
    If Not Len(Trim(Text3.Text)) > 0 Then
        MsgBox "Debe ingresar un monto", vbInformation, "Monto ingresado"
          Exit Sub
    End If
    
    ' Valida el monto ingresado
    If Not Len(Trim(Text8.Text)) > 0 Then
        MsgBox "Debe ingresar una Glosa de Pago", vbInformation, "Glosa de Pago"
          Exit Sub
    End If

    ' Valida los datos de numero cuenta, numero operacion
    If ((Option1.Value Or Option2.Value)) Then
            If Len(Trim(Text4.Text)) = 0 Or Len(Trim(Text5.Text)) = 0 Then
            MsgBox "Debe rellenar los campos de Número Operación y Número Autorización", vbInformation, "Datos de Tarjeta"
            Exit Sub
            End If
    End If
    
    ' Valida los datos de numero operacion, numero autorizacion
    If ((Option3.Value)) Then
           If Len(Trim(Text6.Text)) = 0 Or Len(Trim(Text7.Text)) = 0 Then
            MsgBox "Debe rellenar los campos de Número Cuenta y Número Operación", vbInformation, "Datos de Transferencia"
            Exit Sub
            End If
    End If
    
    Nom_Alu = Grilla.TextMatrix(Grilla.RowSel, 1)
    Rut_ALu = Grilla.TextMatrix(Grilla.RowSel, 0)
    
    FechaIngreso = Format(Now, "yyyy-mm-dd HH:MM:SS")

    ' Obtener los datos del formulario
    agno = val(Combo1.Text)  ' Año seleccionado en el Combo1
    rut_apo = Trim(Text2.Text) ' RUT del apoderado
    nom_apo = Trim(Text1.Text) ' Nombre del apoderado
'    Rut_Alu = Trim(Text3.Text) ' RUT del alumno
'    Nom_Alu = Trim(Text4.Text) ' Nombre del alumno
    Monto_Pagado = val(Trim(Text3.Text)) ' Monto a pagar
    Glosa_Pago = Trim(Text8.Text) ' Glosa de Pago
    

    ' Determinar el método de pago
    If Option1.Value Then
        Metodo_Pago = "Tarjeta Débito"
        Num_ope_tarj = Trim(Text4.Text)
        Num_auto_tarj = Trim(Text5.Text)
    ElseIf Option2.Value Then
        Metodo_Pago = "Tarjeta MasterCard/Visa"
        Num_ope_tarj = Trim(Text4.Text)
        Num_auto_tarj = Trim(Text5.Text)
    ElseIf Option3.Value Then
        Metodo_Pago = "Transferencia"
        Num_cta_transf = Trim(Text6.Text)
        Num_ope_transf = Trim(Text7.Text)
    Else
        MsgBox "Debe seleccionar un método de pago", vbInformation, "Error"
        Exit Sub
    End If

    ' Verificar conexión a la base de datos
    If conn Is Nothing Then
        MsgBox "Error: No hay conexión a la base de datos", vbCritical, "Error de Conexión"
        Exit Sub
    End If

    ' Construir la consulta SQL para insertar datos
'    QRY = "INSERT INTO fnza_pagos_manuales(nombre_apoderado, rut_apo, alumno, ci_alu, monto_pagado, metodo_pago, num_cta_transf, num_ope_transf, num_cta_tarj, num_auto_tarj, agno, fecha_pago, glosa_pago) VALUES " & _
'            "('" & nom_apo & "', '" & rut_apo & "', '" & Nom_Alu & "', '" & Rut_ALu & "', " & Monto_Pagado & ", '" & Metodo_Pago & "', " & _
'            "'" & Num_cta_transf & "', '" & Num_ope_transf & "', '" & Num_ope_tarj & "', '" & Num_auto_tarj & "', " & agno & ", '" & FechaIngreso & "', '" & Glosa_Pago & "')"

    QRY = "INSERT INTO fnza_pagos_manuales(nombre_apoderado, rut_apo, alumno, ci_alu, monto_pagado, metodo_pago, num_cta_transf, num_ope_transf, num_cta_tarj, num_auto_tarj, agno, fecha_pago, glosa_de_pago) VALUES " & _
      "('" & nom_apo & "', '" & rut_apo & "', '" & Nom_Alu & "', '" & Rut_ALu & "', " & Monto_Pagado & ", '" & Metodo_Pago & "', " & _
      "'" & Num_cta_transf & "', '" & Num_ope_transf & "', '" & Num_ope_tarj & "', '" & Num_auto_tarj & "', " & agno & ", '" & FechaIngreso & "', '" & Glosa_Pago & "')"

    ' Crear el objeto Command
    Set CMD = New ADODB.Command
    CMD.ActiveConnection = conn
    CMD.CommandText = QRY
    CMD.CommandType = adCmdText

    ' Ejecutar la consulta
    On Error GoTo ErrorHandler
    CMD.Execute

    ' Mensaje de confirmación
    MsgBox "Pago registrado correctamente.", vbInformation, "Registro Exitoso"

    ' Limpiar los campos después de registrar
    Call LimpiarCampos

    Exit Sub

ErrorHandler:
        MsgBox "Error al registrar el pago: " & Err.Description, vbCritical, "Error"
        Exit Sub
End Sub
    

Private Sub Combo1_Click()
    If (Text1.Text = "" Or Text2.Text = "") Then
        Exit Sub
    Else
        If Flag_sub Then Exit Sub
        'Call ReseteaSeleccionBoleta
        Flag_sub = True
        'Call LimpiaComboCol
        'Call LlenaComboCol
        Flag_sub = False
        'Call SeteaGrillaMens
        'Call LlenaGrillaMens
        Call SeteaGrilla
        Call LlenaGrilla
'        If Combo1.Text > 2021 Then Call recalcula_UF(Text2.Text, Format(dtp_fecha_uf.Value, "yyyy-mm-dd"), Combo1.Text)
''''''''        If Combo1.Text >= 2023 Then
''''''''            var_sql = "UPDATE fnza_mensualidad f,fnza_detalle_mensualidad ff,fnza_valor_matricula fv SET ff.monto_tot_cuota = fv.valor" _
''''''''                    & " WHERE f.folio_mens = ff.folio_mens AND" _
''''''''                    & " f.agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND concepto = 'ct00'" _
''''''''                    & " AND ff.run_alu = fv.ci_alu AND ff.agno = fv.agno"
''''''''            conn.Execute var_sql
''''''''        End If
'        Call LlenaGrilla
'        End If
'        'Call SeteaGrillaDtll
'        'Call SeteaGrillaBlta
    End If

End Sub

Private Sub Command2_Click()
    Frame1.Enabled = True
    Frame2.Enabled = True
    Frame3.Visible = False
End Sub

Private Sub Form_Load()
    ResetPago = False
    Me.Top = 0
    Me.Left = 0
    Flag_sub = True
    Text1.Text = ""
    Text2.Text = ""
    Flag_sub = False
    List1.Visible = False
    List2.Visible = False

    Call SeteaGrilla

    Set RC = New ADODB.Recordset
    'Frame3.Enabled = False
    Frame2.Enabled = False
    Call LlenaComboAgno
    
    'Tabla para guardar envios a cobranza desfazados.
    conn.Execute "CREATE TABLE IF NOT EXISTS fnza_elimina_cobranza (rut_apo varchar(10) NOT NULL default '', cab_bol varchar(100) NOT NULL default '', num_cup varchar(100) NOT NULL default '', fech_ven date NOT NULL default '0000-00-00', monto bigint(20) NOT NULL default '0', estado varchar(100) NOT NULL default '', PRIMARY KEY  (rut_apo,cab_bol,num_cup,fech_ven)) ENGINE=MyISAM;"
    
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set rs = Nothing
End Sub

'Private Sub Grilla_Click()
'
'    Dim Rut_Alu As String
'    Dim Nom_Alu As String
'
'    If Grilla.Row < 1 Then Exit Sub ' Evita errores si no hay selección
'
'    Rut_Alu = Grilla.TextMatrix(Grilla.Row, 0) ' Primera columna (run_alu)
'    Nom_Alu = Grilla.TextMatrix(Grilla.Row, 1) ' Segunda columna (nombre)
'
'    ' Guardamos los valores en variables globales o campos de texto
'    TextRutAlu.Text = Rut_Alu
'    TextNomAlu.Text = Nom_Alu

'End Sub

Private Sub Grilla_DblClick()
    Dim ddd As Integer
    Dim MyRow As Integer
    Dim MedioPago As String
    Dim FormaPago As String
    Dim colegio As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
     MyRow = Grilla.Row
    If Grilla.TextMatrix(MyRow, 0) = "" Then Exit Sub
'         Text5.Text = Grid1.TextMatrix(MyRow, 1)
'         Text6.Text = Grid1.TextMatrix(MyRow, 2)
'         Text7.Text = Grid1.TextMatrix(MyRow, 3)
'         Lbl_Anno_Mat.Caption = Trim(Grid1.TextMatrix(MyRow, 4))
'         Beca = val(Grid1.TextMatrix(MyRow, 7))
'         FormaPag = Trim(Grid1.TextMatrix(MyRow, 8))
         If MedioPago = "Tarjeta Débito" Then
            Option1.Value = True
            Frame5.Enabled = True
         ElseIf MedioPago = "Tarjeta Master Card y Visa" Then
            Option2.Value = True
            Frame5.Enabled = False
         ElseIf MedioPago = "Transferencia" Then
            Option3.Value = True
            Frame5.Enabled = False
         Else
            Option1.Value = False
            Option2.Value = False
            Option3.Value = False
            Frame5.Enabled = True
         End If
'         'Solo autorizados pueden modificar becas asignadas
'         If (CodPerfil = "#ADM#" Or CodPerfil = "#BEC#" Or CorPerfil = "#SBD#") Then
'            Frame9.Enabled = True
'         End If
    Frame1.Enabled = False
    Frame2.Enabled = False
    Frame3.Visible = True

End Sub

Private Sub Grilla_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        'Call Grilla_Click
    End If
End Sub


Private Sub ImageCombo2_Change()
    If Flag_sub = True Then Exit Sub
    Call SeteaGrilla
    Call LlenaGrilla
End Sub

Private Sub ImageCombo2_Click()
    If Flag_sub = True Then Exit Sub
    Call SeteaGrilla
    Call LlenaGrilla
End Sub

Private Sub List1_DblClick()
    Dim RC As ADODB.Recordset
    
    Text1.Text = List1.Text
    List1.Visible = False
    List2.Visible = False
    Set RC = New ADODB.Recordset
    RC.Open "SELECT rut_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(Text1.Text) & ")='" & Text1.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    RC.MoveFirst
    Flag_sub = True
    Text2.Text = RC("rut_apo")
    RC.Close
    'Call LimpiaComboCol
    'Call LlenaComboCol
    Flag_sub = False
    ImageCombo2.Refresh
    'Call SeteaGrillaMens
    'Call LlenaGrillaMens
    Call SeteaGrilla
    Call LlenaGrilla
    'Call SeteaGrillaDtll
    'Call SeteaGrillaBlta
    'Call LlenaGrillaDescuentos
End Sub

Private Sub List2_DblClick()
    Dim RC As ADODB.Recordset
    Text2.Text = List2.Text
    List2.Visible = False
    List1.Visible = False
    Set RC = New ADODB.Recordset
    RC.Open "SELECT CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo FROM apoderados where rut_apo='" & Text2.Text & "' ORDER BY rut_apo;", conn
    RC.MoveFirst
    Flag_sub = True
    Text1.Text = RC("nombre_apo")
    RC.Close
    'Call LimpiaComboCol
    'Call LlenaComboCol
    Flag_sub = False
    ImageCombo2.Refresh
    'Call SeteaGrillaMens
    'Call LlenaGrillaMens
    Call SeteaGrilla
    Call LlenaGrilla
    'Call SeteaGrillaDtll
    'Call SeteaGrillaBlta
    'Call LlenaGrillaDescuentos
End Sub

Private Sub Option1_Click()
    Call LimpiarCampos
    Frame_Transferencia.Visible = False
    Frame_Tarjeta.Visible = True
End Sub

Private Sub Option2_Click()
    Call LimpiarCampos
    Frame_Transferencia.Visible = False
    Frame_Tarjeta.Visible = True
End Sub

Private Sub Option3_Click()
    Call LimpiarCampos
    Frame_Transferencia.Visible = True
    Frame_Tarjeta.Visible = False
End Sub

Private Sub Text1_Change()
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If Text1.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
    
    'Frame3.Enabled = False
    Frame2.Enabled = False
    Frame6.Enabled = False
    
    RC.Open "SELECT DISTINCT a.ape1_apo, a.ape2_apo, a.noms_apo FROM apoderados a, fnza_mensualidad fm where left(CONCAT(a.ape1_apo,' ',a.ape2_apo,' ',a.noms_apo)," & Len(Text1.Text) & ")='" & Text1.Text & "' and a.rut_apo=fm.run_apo ORDER BY a.ape1_apo, a.ape2_apo, a.noms_apo;", conn
    List1.Clear
    While Not (RC.EOF)
        List1.AddItem RC("ape1_apo") & " " & RC("ape2_apo") & " " & RC("noms_apo")
        RC.MoveNext
    Wend
    RC.Close
    List1.Visible = True
    List2.Visible = False
    
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If (List1.ListCount = 0) Then
            Exit Sub
        End If
        List1.Selected(0) = True
        Flag_sub = True
        Text1.Text = List1.Text
        Flag_sub = False
        Call List1_DblClick
    End If
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub Text2_Change()
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If Text2.Text = "" Then Exit Sub
    
    'Frame3.Enabled = False
    Frame2.Enabled = False
    Frame6.Enabled = False
    Dim Str_Query As String
    RC.CursorLocation = adUseClient
    Str_Query = "SELECT DISTINCT fm.run_apo FROM apoderados a, fnza_mensualidad fm WHERE left(a.rut_apo," & Len(Text2.Text) & ")='" & Text2.Text & "' AND a.rut_apo=fm.run_apo ORDER BY a.rut_apo;"
    RC.Open Str_Query, conn
    List2.Clear
    While Not (RC.EOF)
        List2.AddItem RC("run_apo")
        RC.MoveNext
    Wend
    RC.Close
    List2.Visible = True
    List1.Visible = False
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If (List2.ListCount = 0) Then
            Exit Sub
        End If
        List2.Selected(0) = True
        Flag_sub = True
        Text2.Text = List2.Text
        Flag_sub = False
        Call List2_DblClick
    End If
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub LlenaGrilla()
    Dim QR As String
    Dim RC As ADODB.Recordset
    Dim agno As Integer
    Set RC = New ADODB.Recordset
    
    agno = val(Combo1.Text)
    
    
    QR = "SELECT DISTINCT fdm.run_alu, CONCAT(p.ape_pat_alu,' ',p.ape_mat_alu,' ',p.nom_alu) as nombre " & _
     "FROM fnza_mensualidad fm, fnza_detalle_mensualidad fdm, postulantes p " & _
     "WHERE fm.folio_mens = fdm.folio_mens " & _
     "AND fm.run_apo = '" & Text2.Text & "' " & _
     "AND p.ci_alu = fdm.run_alu " & _
     "AND fm.agno = fdm.agno " & _
     "AND fdm.agno = " & agno & " " & _
     "ORDER BY fdm.run_alu"
     
    RC.Open QR, conn
    If RC.RecordCount = 0 Then
        RC.Close
        Exit Sub
    End If
    For i = 1 To RC.RecordCount
        Grilla.AddItem RC("run_alu") & Chr(9) & RC("nombre") & Chr(9) & CursoAlumno(RC("run_alu"), val(Combo1.Text), conn), i
        RC.MoveNext
    Next i
    RC.Close
    Frame2.Enabled = True
    Grilla.SetFocus
End Sub

Private Sub LimpiaComboCol()
    ImageCombo2.ComboItems.Clear
End Sub

Private Sub LlenaComboCol()
    Dim QR As String
    Dim RunApo As String
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    
    RunApo = Text2.Text
    QR = "SELECT DISTINCT hc.colegio,hc.nombre FROM hist_cod_colegio hc, fnza_mensualidad fm WHERE fm.run_apo='" & RunApo & "' AND fm.agno=" & Trim(Me.Combo1.Text) & " AND hc.colegio=fm.colegio Order By colegio"
    RC.Open QR, conn
    If RC.RecordCount = 0 Then
        ImageCombo2.ComboItems.Add 1, "none", "Sin Alumnos para el año " & Trim(Me.Combo1.Text)
        Set ImageCombo2.SelectedItem = ImageCombo2.ComboItems.Item(1)
        ImageCombo2.Refresh
        ImageCombo2.Enabled = False
        Btn_Recalcula.Enabled = False
        RC.Close
        Exit Sub
    Else
        'Btn_Recalcula.Enabled = True
    End If
    Frame6.Enabled = True
    RC.MoveFirst
    For i = 1 To RC.RecordCount
        ImageCombo2.ComboItems.Add i, RC("colegio"), RC("nombre")
        RC.MoveNext
    Next i
    RC.Close
    Set ImageCombo2.SelectedItem = ImageCombo2.ComboItems.Item(1)
    ImageCombo2.Refresh
    If ImageCombo2.ComboItems.count <= 1 Then
        ImageCombo2.Enabled = False
    Else
        ImageCombo2.Enabled = True
    End If
End Sub

Private Sub SeteaGrilla()
    Grilla.ClearStructure
    Grilla.Rows = 2
    Grilla.FormatString = "<RUN|<Nombre|<Curso"
    Grilla.ColWidth(0) = 1200
    Grilla.ColWidth(1) = 4100
    Grilla.ColWidth(2) = 1000
End Sub

Function CursoAlumno(ByVal RunAlu As String, ByVal agno As Integer, CNX As ADODB.Connection) As String
On Error GoTo Controlerror:
    Dim RC As ADODB.Recordset
    Dim QR As String
    Dim Ens As String
    Dim gra As String
    Dim Codens As Integer
    
    CursoAlumno = ""
    QR = "SELECT ce.cod_des,m.cod_ens,m.num_gra FROM matriculas m, codigos_ensenanza ce WHERE m.cod_ens=ce.cod_ens AND m.ci_alu='" & RunAlu & "' AND m.anno_mat='" & agno & "' ORDER BY m.fec_mat DESC LIMIT 1;"
    Set RC = New ADODB.Recordset
    RC.Open QR, CNX
    If RC.RecordCount = 0 Then
        CursoAlumno = "" '"No encontrado"
    Else
        RC.MoveFirst
        Codens = val(RC!Cod_Ens)
        Ens = RC!cod_des
        gra = RC!Num_Gra
        If Not (Codens = 996) Then
            CursoAlumno = gra & " " & Ens
        Else
            CursoAlumno = Ens
        End If
        RC.Close
        'QR = "SELECT let_cur FROM alu_x_cur WHERE ci_alu='" & RunAlu & "' AND DATE_FORMAT(fec_mat,'%Y')='" & agno & "' AND fec_cam='1111-11-11' LIMIT 1;"
        QR = "SELECT let_cur" _
           & " FROM alu_x_cur WHERE ci_alu='" & RunAlu & "' AND agno = " & Combo1.Text & " and activo_alu = 'SI';"
        RC.Open QR, CNX
        If RC.RecordCount = 0 Then
            RC.Close
            Set RC = Nothing
            Exit Function
        End If
        If (Codens = 996) Or (Codens = 10) Then
            CursoAlumno = Ens & " " & RC!Let_Cur
        Else
            CursoAlumno = gra & "º " & RC!Let_Cur & " " & Ens
        End If
    End If
    RC.Close
    Set RC = Nothing
    
    Exit Function
Controlerror:
    Set RC = Nothing
    
    If Err.Number = 0 Then
    Else
        Err.Raise Err.Number, Err.Source, Err.Description
    End If
End Function

Private Sub LlenaComboAgno()
    If Year(Date) < 2005 Then
        Combo1.AddItem ("2005")
    Else
        For i = Year(Date) + 1 To 2005 Step -1
            Combo1.AddItem (str(i))
        Next i
    End If
    Flag_sub = True
    Combo1.ListIndex = 1
    Flag_sub = False
End Sub

Private Sub LimpiarCampos()
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    Text7.Text = ""
    Text8.Text = ""
End Sub
