VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form_Listado_cartas 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Impresión Avisos Apoderados Sin Matricula y Sin Renuncia para el Proximo Año"
   ClientHeight    =   7125
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8790
   Icon            =   "Form_Listado_cartas.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   7125
   ScaleWidth      =   8790
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame Frame2 
      Caption         =   "Lista de Filtros"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   5415
      Left            =   120
      TabIndex        =   10
      Top             =   1560
      Width           =   8535
      Begin VB.CommandButton Command2 
         Caption         =   "&Imprimir para Todos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   6840
         TabIndex        =   13
         Top             =   4800
         Width           =   1575
      End
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   4335
         Left            =   120
         TabIndex        =   11
         Top             =   360
         Width           =   8295
         _ExtentX        =   14631
         _ExtentY        =   7646
         _Version        =   393216
         Cols            =   5
         FixedCols       =   0
         BackColorFixed  =   8404992
         ForeColorFixed  =   -2147483634
         BackColorSel    =   16761024
         ForeColorSel    =   0
         FillStyle       =   1
         ScrollBars      =   2
         SelectionMode   =   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
      End
      Begin VB.Label Label6 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000C0&
         Height          =   255
         Left            =   2160
         TabIndex        =   15
         Top             =   4920
         Width           =   495
      End
      Begin VB.Label Label5 
         Caption         =   "Alumnos a Procesar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   255
         Left            =   120
         TabIndex        =   14
         Top             =   4920
         Width           =   2055
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Seleccion de Cursos"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1335
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   8535
      Begin VB.CommandButton Command1 
         Caption         =   "&Buscar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   6840
         TabIndex        =   9
         Top             =   840
         Width           =   1575
      End
      Begin VB.ComboBox cmbagno 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         ItemData        =   "Form_Listado_cartas.frx":2A8B2
         Left            =   1440
         List            =   "Form_Listado_cartas.frx":2A8B4
         TabIndex        =   0
         Top             =   360
         Width           =   1215
      End
      Begin MSComctlLib.ImageCombo imclet 
         Height          =   345
         Left            =   3840
         TabIndex        =   5
         Top             =   840
         Width           =   1215
         _ExtentX        =   2143
         _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
      End
      Begin MSComctlLib.ImageCombo imcense 
         Height          =   345
         Left            =   3840
         TabIndex        =   2
         Top             =   360
         Width           =   3015
         _ExtentX        =   5318
         _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
      End
      Begin MSComctlLib.ImageCombo imcgra 
         Height          =   345
         Left            =   1440
         TabIndex        =   4
         Top             =   840
         Width           =   1215
         _ExtentX        =   2143
         _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
      End
      Begin VB.Label Label4 
         Caption         =   "Letra:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   2880
         TabIndex        =   8
         Top             =   840
         Width           =   495
      End
      Begin VB.Label Label3 
         Caption         =   "Curso:"
         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        =   7
         Top             =   840
         Width           =   495
      End
      Begin VB.Label Label2 
         Caption         =   "Enseñanza:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   2880
         TabIndex        =   6
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "Año de Curso:"
         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        =   3
         Top             =   360
         Width           =   1455
      End
   End
   Begin VB.Frame Frame4 
      Caption         =   "Opciones de Deuda"
      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            =   120
      TabIndex        =   12
      Top             =   1560
      Width           =   8535
   End
End
Attribute VB_Name = "Form_Listado_cartas"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Command1_Click()
Dim no As Boolean
Dim poniendo As ADODB.Recordset
Dim fila As Integer
Dim cuantos As Integer
fila = 1
cuantos = 0
no = False
If Me.imcense.Text = "" Or Me.imcgra.Text = "" Or Me.cmbagno.Text = "" Or Me.imclet.Text = "" Then
    MsgBox "Faltan Datos que Seleccionar", vbCritical, "Requeridos"
    Exit Sub
End If
Me.MSFlexGrid1.Rows = 1
sqlbuscar = "SELECT DISTINCT fz.estado_mens as estadom,a.rut_apo as rut_apo1,CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo," & _
            "       axc.ci_alu as ci_alu,CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as nombre_alu" & _
            " FROM   alu_x_cur as axc, apoderados as a, apo_x_alu as axa, postulantes as p, matriculas as m, fnza_mensualidad as fz" & _
            " WHERE  axc.cod_ens='" & Mid(Me.imcense.SelectedItem.Key, 1, 3) & "' AND axc.num_gra='" & Me.imcgra.Text & "' AND axc.let_cur='" & Me.imclet.Text & "' AND axc.ci_alu=axa.ci_alu AND axa.rut_apo=a.rut_apo" & _
            " AND    p.ci_alu=axc.ci_alu AND m.ci_alu=axc.ci_alu AND m.activo_alu='SI' AND m.fec_retiro='1111-11-11' AND m.anno_mat='" & Val(Me.cmbagno.Text) + 1 & "'" & _
            " AND    a.rut_apo=fz.run_apo AND fz.mes='2' AND fz.agno='" & Val(Me.cmbagno.Text) + 1 & "' AND fz.estado_mens='impg' group by axc.ci_alu"

Set poniendo = New ADODB.Recordset

poniendo.Open sqlbuscar, conn
'MsgBox str(poniendo.RecordCount)
While Not poniendo.EOF
    If EselMayoraxc2(poniendo!ci_alu, Me.cmbagno.Text) Then
       cuantos = cuantos + 1
    End If
    poniendo.MoveNext
Wend

If cuantos > 0 Then
    poniendo.MoveFirst
Else
    Exit Sub
End If
'MsgBox str(cuantos)
Label6.Caption = str(cuantos)
With Me.MSFlexGrid1
    .Rows = cuantos + 1

    While Not poniendo.EOF
        If EselMayoraxc2(poniendo!ci_alu, Me.cmbagno.Text) Then
            .Row = fila
            .Col = 0
            .Text = poniendo!rut_apo1
            .Col = 1
            .Text = poniendo!nombre_alu
            .Col = 2
            .Text = poniendo!nombre_apo
            .Col = 3
            .Text = poniendo!ci_alu
            .Col = 4
            .Text = poniendo!estadom
            fila = fila + 1
        End If
        poniendo.MoveNext
    Wend
End With
End Sub

Private Sub Command2_Click()
Me.Enabled = False
Dim fila As Integer
Dim final As Integer
Dim cnl As String

cnl = Trim(Mid(Me.imcense.SelectedItem.Key, 1, 3) & Me.imcgra.Text & Me.imclet.Text)

fila = 1
final = Me.MSFlexGrid1.Rows
With Me.MSFlexGrid1
While final > fila
        .Row = fila
        .Col = 0
        creacartaaviso2 .Text, Trim(str(Val(Me.cmbagno.Text) + 1)), cnl
        fila = fila + 1
Wend
End With
impcartaaviso2 Trim(str(Val(Me.cmbagno.Text) + 1)), Mid(Me.imcense.SelectedItem.Key, 1, 3) & Me.imcgra.Text & Me.imclet.Text
Me.Enabled = True
End Sub

Private Sub Form_Load()
Dim setyear As ADODB.Recordset


With Me.MSFlexGrid1
        .Row = 0
        .Col = 0
        .CellFontBold = True
        .Text = "Rut Apoderado"
        .ColWidth(0) = 0
        .Col = 1
        .CellFontBold = True
        .Text = "Nombre Alumno"
        .ColWidth(1) = 3800
        
        .Col = 2
        .CellFontBold = True
        .Text = "Nombre Apoderado"
        .ColWidth(2) = 3800
        .Col = 3
        .CellFontBold = True
        .Text = "Rut Alu"
        .ColWidth(3) = 0
        .Col = 4
        .CellFontBold = Truea
        .Text = "CUOTA 00"
        .ColWidth(4) = 0
End With
Set setyear = New ADODB.Recordset

setyear.Open "select DATE_FORMAT(CURRENT_DATE,'%Y') as agnoactual", conn
For i = setyear!agnoactual To setyear!agnoactual - 1 Step -1

    Me.cmbagno.AddItem i
Next i
Me.cmbagno.Text = setyear!agnoactual
setyear.Close
Me.Show
llenacmbimgsqlkey Me.imcense, "Select des_ens as texto, cod_ens as keyf from codigos_ensenanza order by ord_ens", True
Me.imcense.Text = ""
End Sub

Private Sub llenacmbimgsqlkey(cmbi As ImageCombo, constr As String, keyf As Boolean)
    Dim tablaconsulta As ADODB.Recordset
    Dim contador As Integer
    cmbi.ComboItems.Clear
    contador = 0
    
    Set tablaconsulta = New ADODB.Recordset

    tablaconsulta.Open constr, conn
    contador = 1
    cmbi.ComboItems.Clear
   While Not tablaconsulta.EOF
        If keyf Then
            cmbi.ComboItems.Add contador, tablaconsulta!keyf & "K", tablaconsulta!texto
        Else
            cmbi.ComboItems.Add contador, , tablaconsulta!texto
        End If
        contador = contador + 1
        
        tablaconsulta.MoveNext
    Wend
    tablaconsulta.Close
    Set cmbi.SelectedItem = cmbi.ComboItems.Item(1)
End Sub

Private Sub imcense_Click()
    Dim coens As String
    coens = Mid(Me.imcense.SelectedItem.Key, 1, 3)
    Me.imcgra.ComboItems.Clear
    llenacmbimgsqlkey Me.imcgra, "Select num_gra as texto from alu_x_cur where cod_ens='" & coens & "' group by num_gra order by num_gra", False
    Me.imclet.ComboItems.Clear
    Me.imclet.Text = ""
End Sub

Private Sub IMCgra_Click()
  Dim coens As String
    coens = Mid(Me.imcense.SelectedItem.Key, 1, 3)
    Me.imclet.ComboItems.Clear
    llenacmbimgsqlkey Me.imclet, "Select let_cur as texto from alu_x_cur where cod_ens='" & coens & "' and num_gra='" & Trim(Me.imcgra.Text) & "' group by let_cur order by let_cur", False
End Sub
Private Function EselMayoraxc2(Rutalu As String, AnhoMat As String) As Boolean
RutApo = devuelvecampo("apo_x_alu", "", "rut_apo", "ci_alu ='" & Rutalu & "'", conn)
Set RsFuncion = New ADODB.Recordset
RsFuncion.CursorLocation = adUseClient

a = " SELECT rut_apo,ci_alu FROM apo_x_alu WHERE cambio_apo='NO' AND ci_alu='" & Rutalu & "'" & _
    " Union " & _
    " SELECT rut_apo,ci_alu FROM apo_x_alu_temp WHERE ci_alu='" & Rutalu & "';"
RsFuncion.Open a, conn
RutApo = RsFuncion!Rut_apo
RsFuncion.Close
a = " select p.ci_alu, c.ord_ens , m.num_gra , p.fec_nacalu from postulantes p, apo_x_alu aa, matriculas m, codigos_ensenanza c left join alu_x_cur as axc on axc.ci_alu = p.ci_alu  where aa.ci_alu=p.ci_alu and p.ci_alu = m.ci_alu and m.cod_ens=c.cod_ens and aa.rut_apo = '" & RutApo & "' and m.anno_mat ='" & AnhoMat & "' and ucase(m.activo_alu) ='SI' and axc.let_cur is not null and aa.cambio_apo='NO' " & _
    " union " & _
    " select p.ci_alu, c.ord_ens , m.num_gra , p.fec_nacalu from postulantes p, apo_x_alu_temp aa, matriculas m, codigos_ensenanza c left join alu_x_cur as axc on axc.ci_alu  = p.ci_alu  where aa.ci_alu=p.ci_alu and p.ci_alu = m.ci_alu and m.cod_ens=c.cod_ens and aa.rut_apo = '" & RutApo & "' and m.anno_mat ='" & AnhoMat & "' and ucase(m.activo_alu) ='SI' and axc.let_cur is not null " & _
    " order by ord_ens DESC, num_gra DESC, fec_nacalu"
RsFuncion.Open a, conn
If RsFuncion.RecordCount > 0 Then
    If RsFuncion!ci_alu = Rutalu Then
        EselMayoraxc2 = True
    Else
        EselMayoraxc2 = False
    End If
Else
    ' MsgBox ("No encontro datos para el rut del alumno " & Rutalu)
End If
RsFuncion.Close
Set RsFuncion = Nothing
End Function


