VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Begin VB.Form Form_alumnos_patriculados_por_fecha 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Alumnos matriculados por fecha"
   ClientHeight    =   8835
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   13125
   Icon            =   "Form_alumnos_patriculados_por_fecha.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   8835
   ScaleWidth      =   13125
   Begin MSComCtl2.DTPicker dtp_hasta 
      Height          =   375
      Left            =   3600
      TabIndex        =   11
      Top             =   960
      Width           =   1575
      _ExtentX        =   2778
      _ExtentY        =   661
      _Version        =   393216
      Format          =   50135041
      CurrentDate     =   42304
   End
   Begin MSComCtl2.DTPicker dtp_desde 
      Height          =   375
      Left            =   1080
      TabIndex        =   10
      Top             =   960
      Width           =   1575
      _ExtentX        =   2778
      _ExtentY        =   661
      _Version        =   393216
      Format          =   50135041
      CurrentDate     =   42304
   End
   Begin VB.Frame Frame1 
      Caption         =   "Listado de alumnos"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   7095
      Left            =   120
      TabIndex        =   2
      Top             =   120
      Width           =   12855
      Begin VB.Frame Frame2 
         Caption         =   "Frame2"
         Height          =   2175
         Left            =   2160
         TabIndex        =   5
         Top             =   3360
         Visible         =   0   'False
         Width           =   9015
         Begin VB.Label Label2 
            Caption         =   "En proceso"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   48
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   975
            Left            =   2040
            TabIndex        =   6
            Top             =   600
            Width           =   5175
         End
      End
      Begin VB.Frame Frame3 
         Caption         =   "Seleccione rango de fechas"
         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        =   3
         Top             =   480
         Width           =   12615
         Begin VB.CommandButton Command1 
            Caption         =   "Listar alumnos matriculados"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   9960
            TabIndex        =   4
            Top             =   360
            Width           =   2535
         End
         Begin VB.Label Label4 
            Caption         =   "Hasta"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   2760
            TabIndex        =   13
            Top             =   360
            Width           =   735
         End
         Begin VB.Label Label3 
            Caption         =   "Desde"
            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        =   12
            Top             =   360
            Width           =   615
         End
      End
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   5055
         Left            =   120
         TabIndex        =   7
         Top             =   1920
         Width           =   12615
         _ExtentX        =   22251
         _ExtentY        =   8916
         _Version        =   393216
      End
   End
   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          =   855
      Left            =   9960
      Picture         =   "Form_alumnos_patriculados_por_fecha.frx":2A8B2
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   7800
      Width           =   1575
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Exportar Excel"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   1560
      Picture         =   "Form_alumnos_patriculados_por_fecha.frx":2AED8
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   7800
      Width           =   1575
   End
   Begin ComctlLib.ProgressBar pgbar 
      Height          =   255
      Left            =   120
      TabIndex        =   8
      Top             =   7440
      Width           =   12855
      _ExtentX        =   22675
      _ExtentY        =   450
      _Version        =   327682
      Appearance      =   1
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   495
      Left            =   6000
      TabIndex        =   9
      Top             =   3600
      Width           =   1215
   End
End
Attribute VB_Name = "Form_alumnos_patriculados_por_fecha"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Rec2Grid(ByRef REC As ADODB.Recordset, ByRef grid As Object, Optional ByVal Numeracion As Boolean = True)
    grid.Clear
    If REC.RecordCount > 0 Then
        grid.Cols = REC.Fields.count + 1
        grid.Rows = REC.RecordCount + 1
        grid.FixedCols = 1
        grid.FixedRows = 1
        grid.TextMatrix(0, 0) = "Nº"
        grid.ColWidth(0) = IIf(Numeracion, TextWidth(grid.TextMatrix(0, 0)) + 100, 0)
        For i = 1 To REC.Fields.count
            grid.TextMatrix(0, i) = UCase(REC.Fields(i - 1).Name)
            grid.ColWidth(i) = TextWidth(grid.TextMatrix(0, i)) + 100
        Next i
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            'progreso.Value = i
            grid.TextMatrix(i, 0) = i
            grid.ColWidth(0) = IIf(Numeracion, IIf(TextWidth(grid.TextMatrix(i, 0)) + 100 > grid.ColWidth(0), TextWidth(grid.TextMatrix(i, 0)) + 100, grid.ColWidth(0)), 0)
            For j = 1 To REC.Fields.count
                grid.TextMatrix(i, j) = IIf(IsNull(REC(j - 1)), "Null", REC(j - 1))
                grid.ColWidth(j) = IIf(TextWidth(grid.TextMatrix(i, j)) + 100 > grid.ColWidth(j), TextWidth(grid.TextMatrix(i, j)) + 100, grid.ColWidth(j))
            Next j
            REC.MoveNext
        Next i
    Else
        grid.Cols = 2
        grid.Rows = 2
    End If
End Sub

Private Sub cmd_Salir_Click()
    Unload Me
End Sub

Private Sub Command1_Click()
    Dim var_sql As String
    Dim Sql As String
    Dim maximo_mes As Integer
    Dim Colegio As String
    
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    Frame2.Visible = True
   
    MSFlexGrid1.Cols = 2
    MSFlexGrid1.Rows = 2
    MSFlexGrid1.Clear
    
    Sql = Sql & " SELECT VALOR FROM cfg"
    Sql = Sql & " WHERE param = 'CODBC'"
    objRS.Open Sql, conn
    If Not objRS.EOF Then
        Colegio = objRS!valor
    End If
    objRS.Close
    
    If Colegio <> "HUE001" Then
    var_sql = "SELECT m.ci_alu,alumno,grado,nivel,anno_mat AS 'Año',nombre_usuario,DATE_FORMAT(fecha_matricula,'%Y-%M-%d') AS fecha_matricula," _
               & "IF(m.ind_cup = '1', 'F.P. Cuponera'," _
               & "IF(m.ind_cheq = '1', 'F.P. Cheques'," _
               & "IF(m.ind_cont = '1', 'F.P. Contado'," _
               & "IF(m.ind_cont_cheq = '1', 'F.P. Cont. Cheq'," _
               & "IF(m.ind_cont_tran = '1', 'F.P. Cont. Transf.'," _
               & "IF(m.ind_beca = '1', 'Beca', " _
               & "IF(m.ind_mbeca = '1', 'Media Beca', ''))))))) AS Forma_Pago, " _
               & "IF(MID(ip,1,10) = '192.168.10','Maipu',IF(MID(ip,1,10) = '192.168.12','Macul',IF(MID(ip,1,10) = '192.168.7.','Pie Andino'," _
               & "IF(MID(ip,1,10) = '192.168.2.','Huechuraba',IF(MID(ip,1,10) = '192.168.3.','San Martin',IF(MID(ip,1,10) = '192.168.4.','Florida'," _
               & "IF(MID(ip,1,10) = '192.168.5.','Lincoln',IF(MID(ip,1,10) = '192.168.6.','Farfana',IF(MID(ip,1,10) = '192.168.8.','Pudahuel'," _
               & "IF(MID(ip,1,10) = '192.168.9.','San Bernardo','')))))))))) AS ubicacion" _
               & ",pc,accion_realizada From " _
               & " (SELECT m.ci_alu,CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) AS alumno,m.num_gra AS grado,des_ens_abrev AS nivel,anno_mat,fec_mat_r AS fecha_matricula" _
               & " ,m.ind_cup, m.ind_cheq, m.ind_cont, m.ind_cont_cheq  , m.ind_cont_tran, m.ind_beca, m.ind_mbeca" _
               & " FROM matriculas m,postulantes p,codigos_ensenanza ce" _
               & " WHERE m.ci_alu = p.ci_alu AND m.cod_ens = ce.cod_ens AND m.fec_mat_r >= '" & Format(dtp_desde.Value, "yyyy-mm-dd") _
               & "' AND m.fec_mat_r <= '" & Format(DTP_hasta.Value, "yyyy-mm-dd") & "' AND m.confirmado = 'SI' AND m.activo_alu = 'SI') AS m" _
               & " LEFT JOIN hist_vitacora_alumno h" _
               & " ON m.ci_alu = h.ci_alu AND DATE_FORMAT(m.fecha_matricula,'%Y-%m') = DATE_FORMAT(h.fecha,'%Y-%m') AND accion_realizada LIKE '%matriculado%'" _
               & " GROUP BY m.ci_alu" _
               & " ORDER BY fecha_matricula"
    Else
    
        var_sql = "SELECT m.ci_alu,alumno,grado,nivel,anno_mat AS 'Año',nombre_usuario,DATE_FORMAT(fecha_matricula,'%Y-%M-%d') AS fecha_matricula," _
               & "IFNULL(m.fp_incorporacion, '') AS Cuota_Incorporación, IFNULL(m.fp_matricula, '') AS Cuota_Matricula, IFNULL(m.fp_mensualidad, '') AS Cuota_Mensualidad, " _
               & "IF(MID(ip,1,10) = '192.168.10','Maipu',IF(MID(ip,1,10) = '192.168.12','Macul',IF(MID(ip,1,10) = '192.168.7.','Pie Andino'," _
               & "IF(MID(ip,1,10) = '192.168.2.','Huechuraba',IF(MID(ip,1,10) = '192.168.3.','San Martin',IF(MID(ip,1,10) = '192.168.4.','Florida'," _
               & "IF(MID(ip,1,10) = '192.168.5.','Lincoln',IF(MID(ip,1,10) = '192.168.6.','Farfana',IF(MID(ip,1,10) = '192.168.8.','Pudahuel'," _
               & "IF(MID(ip,1,10) = '192.168.9.','San Bernardo','')))))))))) AS ubicacion" _
               & ",pc,accion_realizada From " _
               & " (SELECT m.ci_alu,CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) AS alumno,m.num_gra AS grado,des_ens_abrev AS nivel,anno_mat,fec_mat_r AS fecha_matricula" _
               & " , m.fp_incorporacion , m.fp_matricula , m.fp_mensualidad" _
               & " FROM matriculas m,postulantes p,codigos_ensenanza ce" _
               & " WHERE m.ci_alu = p.ci_alu AND m.cod_ens = ce.cod_ens AND m.fec_mat_r >= '" & Format(dtp_desde.Value, "yyyy-mm-dd") _
               & "' AND m.fec_mat_r <= '" & Format(DTP_hasta.Value, "yyyy-mm-dd") & "' AND m.confirmado = 'SI' AND m.activo_alu = 'SI') AS m" _
               & " LEFT JOIN hist_vitacora_alumno h" _
               & " ON m.ci_alu = h.ci_alu AND DATE_FORMAT(m.fecha_matricula,'%Y-%m') = DATE_FORMAT(h.fecha,'%Y-%m') AND accion_realizada LIKE '%matriculado%'" _
               & " GROUP BY m.ci_alu" _
               & " ORDER BY fecha_matricula"
    
    End If
    
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        Call Rec2Grid(objRS, MSFlexGrid1, True)
       ' msflex_alumnos.ColSel = 5
    Else
        'MsgBox "Esta mensualidad aún no ha vencido", vbInformation
    End If
    objRS.Close
    MSFlexGrid1.Refresh
    
    Frame2.Visible = False
    
End Sub

Private Sub Command2_Click()
    Dim ApExcel As Variant
    Set ApExcel = CreateObject("Excel.application")
    ApExcel.Workbooks.Add
          
    For i = 1 To Me.MSFlexGrid1.Cols - 1
        ApExcel.Cells(1, i).Font.Size = 12
        ApExcel.Cells(1, i).Font.Bold = True
        ApExcel.Cells(1, i).Formula = Me.MSFlexGrid1.TextMatrix(0, i)
    Next i
    pgBar.Min = 1
    pgBar.Max = MSFlexGrid1.Rows
    pgBar.Value = pgBar.Min
    For i = 1 To MSFlexGrid1.Rows - 1

         For j = 1 To MSFlexGrid1.Cols - 1
            ApExcel.Cells((i + 1), j).Formula = IIf(MSFlexGrid1.TextMatrix(i, j) = "Null", "", MSFlexGrid1.TextMatrix(i, j))
        
        pgBar.Value = i
        Next j
    Next i
            
    ApExcel.Visible = True
'    ApExcel.Range("a1:x1").Borders.color = RGB(255, 0, 0)
    Set ApExcel = Nothing
End Sub


Private Sub Form_Load()
'    Dim i As Integer
'    For i = 2011 To Anno - 1
'        cb_agno.AddItem i
'    Next i
'    cb_agno.Text = Anno - 1
    dtp_desde.Value = Date
    DTP_hasta.Value = Date
End Sub


