VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_cta_cte 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Cartola de Cuenta Corriente por Apoderado - Año "
   ClientHeight    =   7365
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11280
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7365
   ScaleWidth      =   11280
   Begin VB.ComboBox Cmb_Agno 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   7680
      Style           =   2  'Dropdown List
      TabIndex        =   36
      Top             =   240
      Width           =   1095
   End
   Begin VB.TextBox Text8 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0C0FF&
      Height          =   195
      Left            =   240
      TabIndex        =   31
      Top             =   5280
      Width           =   615
   End
   Begin VB.TextBox Text6 
      Appearance      =   0  'Flat
      BackColor       =   &H00FFC0FF&
      Height          =   195
      Left            =   240
      TabIndex        =   30
      Top             =   5520
      Width           =   615
   End
   Begin VB.TextBox Text2 
      Appearance      =   0  'Flat
      BackColor       =   &H00C0FFC0&
      Height          =   195
      Left            =   240
      TabIndex        =   29
      Top             =   5760
      Width           =   615
   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          =   1530
      Left            =   5400
      TabIndex        =   24
      Top             =   480
      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          =   1530
      Left            =   1080
      TabIndex        =   23
      Top             =   480
      Visible         =   0   'False
      Width           =   3735
   End
   Begin MSHierarchicalFlexGridLib.MSHFlexGrid FlexGrid1 
      Height          =   975
      Left            =   120
      TabIndex        =   25
      Top             =   960
      Width           =   8655
      _ExtentX        =   15266
      _ExtentY        =   1720
      _Version        =   393216
      FixedCols       =   0
      WordWrap        =   -1  'True
      AllowBigSelection=   0   'False
      FocusRect       =   0
      HighLight       =   2
      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
      BeginProperty FontFixed {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
   End
   Begin VB.TextBox Text15 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   1080
      TabIndex        =   22
      Top             =   240
      Width           =   3735
   End
   Begin VB.CommandButton Command5 
      Caption         =   "Salir"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   7080
      Picture         =   "Form_cta_cte.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   21
      Top             =   6480
      Width           =   1335
   End
   Begin VB.CommandButton Command4 
      Caption         =   "Cancelar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   5640
      Picture         =   "Form_cta_cte.frx":0626
      Style           =   1  'Graphical
      TabIndex        =   20
      Top             =   6480
      Width           =   1335
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Imprimir"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   3960
      Picture         =   "Form_cta_cte.frx":098E
      Style           =   1  'Graphical
      TabIndex        =   19
      Top             =   6480
      Width           =   1335
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Deuda"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   2400
      Picture         =   "Form_cta_cte.frx":0EEB
      Style           =   1  'Graphical
      TabIndex        =   18
      Top             =   6480
      Width           =   1335
   End
   Begin MSComCtl2.DTPicker DTPicker2 
      Height          =   375
      Left            =   9960
      TabIndex        =   13
      Top             =   240
      Width           =   1215
      _ExtentX        =   2143
      _ExtentY        =   661
      _Version        =   393216
      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
      Format          =   40960001
      CurrentDate     =   38351
   End
   Begin VB.TextBox Text7 
      Appearance      =   0  'Flat
      BackColor       =   &H8000000A&
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF0000&
      Height          =   285
      Left            =   9960
      TabIndex        =   12
      Top             =   1680
      Width           =   1095
   End
   Begin VB.Frame Frame1 
      Caption         =   "Detalle de Movimientos a la Fecha Consultada"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   3735
      Left            =   120
      TabIndex        =   9
      Top             =   2520
      Width           =   11055
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid FlexGrid2 
         Height          =   2295
         Left            =   120
         TabIndex        =   26
         Top             =   360
         Width           =   10575
         _ExtentX        =   18653
         _ExtentY        =   4048
         _Version        =   393216
         Cols            =   10
         BackColorSel    =   16761024
         FocusRect       =   0
         HighLight       =   2
         FillStyle       =   1
         SelectionMode   =   1
         AllowUserResizing=   1
         FormatString    =   "|^Cuota|<Mes|^Vencimiento|>Valor Cuota|<Estado Pago|>Monto Pago|^Fecha Pago|^Forma de Pago|>Saldo Cuota"
         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   =   10
      End
      Begin VB.TextBox Text14 
         Alignment       =   1  'Right Justify
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   9720
         Locked          =   -1  'True
         TabIndex        =   17
         Text            =   "0"
         Top             =   2880
         Width           =   975
      End
      Begin VB.TextBox Text13 
         Alignment       =   1  'Right Justify
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   5520
         Locked          =   -1  'True
         TabIndex        =   16
         Text            =   "0"
         Top             =   2880
         Width           =   975
      End
      Begin VB.TextBox Text12 
         Alignment       =   1  'Right Justify
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   3360
         Locked          =   -1  'True
         TabIndex        =   15
         Text            =   "0"
         Top             =   2880
         Width           =   975
      End
      Begin VB.Label Label12 
         Caption         =   "Último pago mes"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   -1  'True
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   840
         TabIndex        =   34
         Top             =   3360
         Width           =   1455
      End
      Begin VB.Label Label11 
         Caption         =   "Nulo"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   -1  'True
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   840
         TabIndex        =   33
         Top             =   3120
         Width           =   975
      End
      Begin VB.Label Label10 
         Caption         =   "Crédito a favor"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   -1  'True
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   840
         TabIndex        =   32
         Top             =   2880
         Width           =   1335
      End
      Begin VB.Label Label9 
         Caption         =   "Total de Saldos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   8520
         TabIndex        =   28
         Top             =   2880
         Width           =   1215
      End
      Begin VB.Label Label8 
         Caption         =   "Total Pagos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   4560
         TabIndex        =   27
         Top             =   2880
         Width           =   975
      End
      Begin VB.Label Label13 
         Caption         =   "Total Cuotas"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   2400
         TabIndex        =   14
         Top             =   2880
         Width           =   975
      End
   End
   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            =   7560
      Locked          =   -1  'True
      TabIndex        =   8
      Text            =   "0"
      Top             =   2040
      Width           =   1215
   End
   Begin VB.TextBox Text4 
      Appearance      =   0  'Flat
      BackColor       =   &H8000000A&
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF0000&
      Height          =   285
      Left            =   10320
      TabIndex        =   6
      Text            =   "0"
      Top             =   1320
      Width           =   735
   End
   Begin VB.TextBox Text3 
      Appearance      =   0  'Flat
      BackColor       =   &H8000000A&
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FF0000&
      Height          =   285
      Left            =   10560
      TabIndex        =   4
      Text            =   "0"
      Top             =   960
      Width           =   495
   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            =   5400
      TabIndex        =   2
      Top             =   240
      Width           =   1335
   End
   Begin VB.Label Label14 
      Caption         =   "Periodo"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6960
      TabIndex        =   35
      Top             =   240
      Width           =   615
   End
   Begin VB.Label Label5 
      Caption         =   "Total Deuda:"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   6480
      TabIndex        =   7
      Top             =   2040
      Width           =   975
   End
   Begin VB.Label Label7 
      Caption         =   "Forma Pago :"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   8880
      TabIndex        =   11
      Top             =   1680
      Width           =   975
   End
   Begin VB.Line Line2 
      X1              =   0
      X2              =   11400
      Y1              =   2400
      Y2              =   2400
   End
   Begin VB.Label Label4 
      Caption         =   "Cuotas :"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   8880
      TabIndex        =   5
      Top             =   1320
      Width           =   615
   End
   Begin VB.Label Label3 
      Caption         =   "Cantidad de Alumnos : "
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   8880
      TabIndex        =   3
      Top             =   960
      Width           =   1815
   End
   Begin VB.Line Line1 
      X1              =   0
      X2              =   11400
      Y1              =   720
      Y2              =   720
   End
   Begin VB.Label Label2 
      Caption         =   "Rut"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   4920
      TabIndex        =   1
      Top             =   240
      Width           =   495
   End
   Begin VB.Label Label1 
      Caption         =   "Apoderado"
      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        =   0
      Top             =   240
      Width           =   975
   End
   Begin VB.Label Label6 
      Caption         =   "Fecha Cartola"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   8880
      TabIndex        =   10
      Top             =   240
      Width           =   1095
   End
End
Attribute VB_Name = "Form_cta_cte"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Flag_sub As Boolean
Public Impresion_Aceptar As Boolean
Public Impresion_Pantalla As Boolean
Public Impresion_Detalle As Boolean

Private Sub Cmb_Agno_Click()
    If Flag_sub Then Exit Sub
    FlexGrid1.ClearStructure
    FlexGrid2.ClearStructure
    FlexGrid1.Cols = 5
    FlexGrid1.Rows = 2
    FlexGrid1.FormatString = "^RUN|<Alumno|<Curso|<Colegio|>Monto Adeudado"
    FlexGrid1.ColWidth(0) = 1010
    FlexGrid1.ColWidth(1) = 3400
    FlexGrid1.ColWidth(2) = 1050
    FlexGrid1.ColWidth(3) = 2100
    FlexGrid1.ColWidth(4) = 760
    
    FlexGrid2.Cols = 11
    FlexGrid2.Rows = 2
    FlexGrid2.FormatString = "|^Cuota|<Mes|^Vencimiento|>Valor Cuota|<Estado Pago|>Monto Pago|^Fecha Pago|^Forma de Pago|>Folio Boleta|>Saldo Cuota"
    FlexGrid2.ColWidth(0) = 400
    FlexGrid2.ColWidth(1) = 800
    FlexGrid2.ColWidth(2) = 800
    FlexGrid2.ColWidth(3) = 1000
    'FlexGrid2.ColWidth(4) = 800
    FlexGrid2.ColWidth(5) = 1000
    'FlexGrid2.ColWidth(6) = 800
    FlexGrid2.ColWidth(7) = 1000
    FlexGrid2.ColWidth(8) = 1420
    'FlexGrid2.ColWidth(9) = 700
    
    Text3.Text = 0
    Text4.Text = 0
    Text5.Text = 0
    'Text6.Text = ""
    Text7.Text = ""
    
    'Text11.Text = "No"
    Text12.Text = 0
    Text13.Text = 0
    Text14.Text = 0
    
    Call Completa_Cartola
    
End Sub

Private Sub Command2_Click()
    Load Form_Deuda
    Form_Deuda.Show vbModal
End Sub

Private Sub Command3_Click()
    Load Form_cta_cte_dialog
    Form_cta_cte_dialog.Show vbModal
    If Form_cta_cte.Impresion_Aceptar Then
        'Selecciono Destino
        If Form_cta_cte.Impresion_Pantalla Then
            Form_main.CrystalReport.Destination = crptToWindow
        Else
            Form_main.CrystalReport.Destination = crptToPrinter
        End If
        
        'Selecciono tipo de reporte
        Select Case Form_cta_cte.Impresion_Detalle
            Case True ' Detallado
                Form_main.CrystalReport.Formulas(1) = "Hora = '" & Time & "'"
                Form_main.CrystalReport.ReportFileName = App.Path & "\rpt\cartola_movimientos.rpt"
                Form_main.CrystalReport.WindowTitle = "Cartola de Movimientos"
                Form_main.CrystalReport.WindowState = crptMaximized
                Form_main.CrystalReport.ReplaceSelectionFormula ("")
                Form_main.CrystalReport.ReplaceSelectionFormula ("{fnza_boletas.TIPO_DOC}='blta' AND {fnza_mensualidad.RUN_APO}='" & Form_cta_cte.Text1.Text & "' and {fnza_mensualidad.AGNO}=" & Cmb_Agno.Text)
            
            Case False ' Resumido
                Call CreaBD(DirAplicacion & "\rpt\gestemp.mdb")
                Call CreaTabla(DirAplicacion & "\rpt\gestemp.mdb", "Detalles", "11,10")
                Call RptGrillaTextH(FlexGrid2, FlexGrid2.Rows - 1, "\rpt\gestemp.mdb", "Detalles")
                Titulo = "CARTOLA RESUMIDA DE MOVIMIENTOS AÑO " & Cmb_Agno.Text
                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.Text15 & "'"
                Form_main.CrystalReport.Formulas(6) = "rutapo = '" & Me.Text1 & "'"
                Dim IndFormula As Integer
                IndFormula = 7
                For te = 1 To Me.FlexGrid1.Rows - 2
                    Form_main.CrystalReport.Formulas(IndFormula) = "alumno" & te & " = '" & te & ".-" & Me.FlexGrid1.TextMatrix(te, 1) & "'": IndFormula = IndFormula + 1
                    Form_main.CrystalReport.Formulas(IndFormula) = "run" & te & " = '" & Me.FlexGrid1.TextMatrix(te, 0) & "'": IndFormula = IndFormula + 1
                    Form_main.CrystalReport.Formulas(IndFormula) = "curso" & te & " = '" & Me.FlexGrid1.TextMatrix(te, 2) & "'": IndFormula = IndFormula + 1
                    Form_main.CrystalReport.Formulas(IndFormula) = "colegio" & te & " = '" & Me.FlexGrid1.TextMatrix(te, 3) & "'": IndFormula = IndFormula + 1
                    Form_main.CrystalReport.Formulas(IndFormula) = "arancel" & te & " = '" & RetornaCampo("fnza_detalle_mensualidad", "sum(monto_tot_cuota - monto_abono) as suma", "run_alu='" & Me.FlexGrid1.TextMatrix(te, 0) & "' AND agno='" & Trim(Cmb_Agno.Text) & "' GROUP BY run_alu", conn) & "'": IndFormula = IndFormula + 1
                    Form_main.CrystalReport.Formulas(IndFormula) = "anualidad" & te & " = '" & RetornaCampo("fnza_detalle_mensualidad", "sum(monto_tot_cuota) as suma", "run_alu='" & Me.FlexGrid1.TextMatrix(te, 0) & "' AND agno='" & Trim(Cmb_Agno.Text) & "' GROUP BY run_alu", conn) & "'": IndFormula = IndFormula + 1
                    Form_main.CrystalReport.Formulas(IndFormula) = "pagado" & te & " = '" & RetornaCampo("fnza_detalle_mensualidad", "sum(monto_abono) as suma", "run_alu='" & Me.FlexGrid1.TextMatrix(te, 0) & "' AND agno='" & Trim(Cmb_Agno.Text) & "' GROUP BY run_alu", conn) & "'": IndFormula = IndFormula + 1
                Next te

                Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\cartola_movimientos_res.rpt"
                Form_main.CrystalReport.DataFiles(0) = DirAplicacion & "\rpt\gestemp.mdb"
                Form_main.CrystalReport.WindowState = crptMaximized
                Form_main.CrystalReport.ReplaceSelectionFormula ("")
        End Select
        
        'Imprimo el reporte
        Form_main.CrystalReport.Action = 1
        Call LimpiaFormulas(Form_main.CrystalReport, 99)
    End If
End Sub

Private Sub Command4_Click()
    Text1.Locked = False
    Text15.Locked = False
    DTPicker2.Enabled = True
    Flag_sub = True
    Text1.Text = ""
    Text15.Text = ""
    DTPicker2.Value = Date
    DTPicker2.Enabled = False
    Flag_sub = False
    FlexGrid1.ClearStructure
    FlexGrid2.ClearStructure
    FlexGrid1.Cols = 5
    FlexGrid1.Rows = 2
    FlexGrid1.FormatString = "^RUN|<Alumno|<Curso|<Colegio|>Monto Adeudado"
    FlexGrid1.ColWidth(0) = 1010
    FlexGrid1.ColWidth(1) = 3400
    FlexGrid1.ColWidth(2) = 1050
    FlexGrid1.ColWidth(3) = 2100
    FlexGrid1.ColWidth(4) = 760
    
    FlexGrid2.Cols = 11
    FlexGrid2.Rows = 2
    FlexGrid2.FormatString = "|^Cuota|<Mes|^Vencimiento|>Valor Cuota|<Estado Pago|>Monto Pago|^Fecha Pago|^Forma de Pago|>Folio Boleta|>Saldo Cuota"
    FlexGrid2.ColWidth(0) = 400
    FlexGrid2.ColWidth(1) = 800
    FlexGrid2.ColWidth(2) = 800
    FlexGrid2.ColWidth(3) = 1000
    'FlexGrid2.ColWidth(4) = 800
    FlexGrid2.ColWidth(5) = 1000
    'FlexGrid2.ColWidth(6) = 800
    FlexGrid2.ColWidth(7) = 1000
    FlexGrid2.ColWidth(8) = 1420
    'FlexGrid2.ColWidth(9) = 700
    
    Text3.Text = 0
    Text4.Text = 0
    Text5.Text = 0
    'Text6.Text = ""
    Text7.Text = ""
    
    'Text11.Text = "No"
    Text12.Text = 0
    Text13.Text = 0
    Text14.Text = 0
    
    Text1.SetFocus
End Sub

Private Sub Command5_Click()
    Me.Hide
    Unload Me
End Sub

Private Sub FlexGrid1_DblClick()
    Dim rut As String
    rut = FlexGrid1.TextMatrix(FlexGrid1.Row, 0)
    Call alumno_Cartola(rut)
End Sub

Private Sub FlexGrid1_SelChange()
    Dim My_Row As Integer
    Dim rs As ADODB.Recordset
    
    Set rs = New ADODB.Recordset
    
    If FlexGrid1.Row = (FlexGrid1.Rows - 1) Then
        Exit Sub
    End If
    My_Row = FlexGrid1.Row
    
    'RS.CursorLocation = adUseClient
    rs.Open "SELECT DISTINCT m.run_apo, dm.run_alu,mt.anno_mat, if(mt.ind_cup=1,'cuponera',if(mt.ind_cheq=1,'cheque',if(mt.ind_pac=1,'p.a.c.',if(mt.ind_cont=1,'contado',if(mt.ind_beca=1,'beca','sin información'))))) as forma_de_pago FROM fnza_mensualidad m, fnza_detalle_mensualidad dm, matriculas mt WHERE dm.folio_mens=m.folio_mens AND dm.run_alu=mt.ci_alu AND mt.fec_retiro='1111-11-11' AND mt.activo_alu='SI' AND m.run_apo='" & Text1.Text & "' AND run_alu='" & FlexGrid1.TextMatrix(My_Row, 0) & "' ORDER BY m.run_apo, mt.ci_alu, mt.anno_mat DESC LIMIT 1;", conn
    If rs.RecordCount < 1 Then
        MsgBox "Alumno Sin Matrícula", vbOKOnly, "Falta de Información"
        Text7.Text = "S/Inf"
        rs.Close
        Set rs = Nothing
        Exit Sub
    End If
    rs.MoveFirst
    Text7.Text = rs("forma_de_pago")
    rs.Close
    Set rs = Nothing
End Sub

Private Sub FlexGrid2_SelChange()
    'Dim My_Row As Integer
    'If FlexGrid2.Row = (FlexGrid2.Rows - 1) Then
    '    Exit Sub
    'End If
    'My_Row = FlexGrid2.Row
    
    'Text6.Text = FlexGrid2.TextMatrix(My_Row, 8)
            
End Sub

Private Sub Form_Load()
    'Set rs = New ADODB.Recordset
    
    DTPicker2.Value = Date
    DTPicker2.Enabled = False
    
    Form_cta_cte.Caption = "Cartola de Cuenta Corriente por Apoderado - Año " & Year(Date)
    List1.Visible = False
    List2.Visible = False
    Flag_sub = False
    FlexGrid1.Cols = 5
    FlexGrid1.FormatString = "^RUN|<Alumno|<Curso|<Colegio|>Monto Adeudado"
    FlexGrid1.ColWidth(0) = 1010
    FlexGrid1.ColWidth(1) = 3400
    FlexGrid1.ColWidth(2) = 1050
    FlexGrid1.ColWidth(3) = 2100
    FlexGrid1.ColWidth(4) = 760
    
    FlexGrid2.Cols = 11
    FlexGrid2.FormatString = "|^Cuota|<Mes|^Vencimiento|>Valor Cuota|<Estado Pago|>Monto Pago|^Fecha Pago|^Forma de Pago|>Folio Boleta|>Saldo Cuota"
    FlexGrid2.ColWidth(0) = 400
    FlexGrid2.ColWidth(1) = 800
    FlexGrid2.ColWidth(2) = 800
    FlexGrid2.ColWidth(3) = 1000
    'FlexGrid2.ColWidth(4) = 800
    FlexGrid2.ColWidth(5) = 1000
    'FlexGrid2.ColWidth(6) = 800
    FlexGrid2.ColWidth(7) = 1000
    FlexGrid2.ColWidth(8) = 1420
    'FlexGrid2.ColWidth(9) = 700

    LlenaComboAgno
    
End Sub

Private Sub List1_DblClick()
    Dim rs As ADODB.Recordset
    
    Set rs = New ADODB.Recordset
    Text15.Text = List1.Text
    List1.Visible = False
    List2.Visible = False
    rs.CursorLocation = adUseClient
    rs.Open "SELECT rut_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(Text15.Text) & ")='" & Text15.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    rs.MoveFirst
    Flag_sub = True
    Text1.Text = rs("rut_apo")
    Flag_sub = False
    rs.Close
    Set rs = Nothing
    
    Call Completa_Cartola
End Sub

Private Sub List2_DblClick()
    Dim rs As ADODB.Recordset
    
    Set rs = New ADODB.Recordset
    Text1.Text = List2.Text
    List2.Visible = False
    List1.Visible = False
    rs.CursorLocation = adUseClient
    rs.Open "SELECT CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo FROM apoderados where rut_apo='" & Text1.Text & "' ORDER BY rut_apo;", conn
    rs.MoveFirst
    Flag_sub = True
    Text15.Text = rs("nombre_apo")
    Flag_sub = False
    rs.Close
    Set rs = Nothing
    
    Call Completa_Cartola
End Sub

Private Sub Text1_Change()
    Dim rs As ADODB.Recordset
    
    ' Si el cambio l0o hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If Text1.Text = "" Then Exit Sub
    
    Set rs = New ADODB.Recordset
    Dim Str_Query As String
    rs.CursorLocation = adUseClient
    Str_Query = "SELECT DISTINCT fm.run_apo FROM apoderados a, fnza_mensualidad fm WHERE left(a.rut_apo," & Len(Text1.Text) & ")='" & Text1.Text & "' AND a.rut_apo=fm.run_apo ORDER BY a.rut_apo;"
    rs.Open Str_Query, conn
    List2.Clear
    While Not (rs.EOF)
        List2.AddItem rs("run_apo")
        rs.MoveNext
    Wend
    rs.Close
    Set rs = Nothing
    
    List2.Visible = True
End Sub


Private Sub Text15_Change()
    Dim rs As ADODB.Recordset

    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If Text15.Text = "" Then Exit Sub
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.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(Text15.Text) & ")='" & Text15.Text & "' and a.rut_apo=fm.run_apo ORDER BY a.ape1_apo, a.ape2_apo, a.noms_apo;", conn
    List1.Clear
    While Not (rs.EOF)
        List1.AddItem rs("ape1_apo") & " " & rs("ape2_apo") & " " & rs("noms_apo")
        rs.MoveNext
    Wend
    rs.Close
    Set rs = Nothing
    
    List1.Visible = True
End Sub

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

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

Private Sub Completa_Cartola()
    Dim rs As ADODB.Recordset
    
    Set rs = New ADODB.Recordset
    Dim QR As String
    Dim Int_num_alu As Integer
    Dim Int_num_mov As Integer
    Dim Dbl_tot_deuda As Double
    Dim Dbl_tot_cuota As Double
    Dim Dbl_tot_mvto As Double
    Dim NumMes As Integer, sw_mes, sw_cole As Boolean
    Dim Bol_Nula As Boolean
    Dim A_Pagar As Double, Monto_Pago As Double, Saldo_Mens As Double
    Dim Monto_Nulo As Double, Saldo_Nulo  As Double, A_Pagar_Nulo As Double
    Dim Saldo_Aux As Double
    Dim colegio As String
    
    Int_num_alu = 0
    Int_num_mov = 0
    Dbl_tot_deuda = 0
    Dbl_tot_cuota = 0
    Dbl_tot_mvto = 0
    
    Text1.Locked = True
    Text15.Locked = True
    DTPicker2.Enabled = False
    
    rs.CursorLocation = adUseClient
    QR = "SELECT DISTINCT dm.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombre, cc.nombre as colegio, (sum(dm.monto_tot_cuota) - sum(dm.monto_abono)) AS deuda_total, concat(axc.num_gra, 'º ',axc.let_cur, ' ', if(axc.cod_ens=310,'Medio',if(axc.cod_ens=110,'Básico',if(axc.cod_ens=010,'Kinder','PreKinder')))) as cursoalu FROM fnza_detalle_mensualidad dm, fnza_mensualidad m, postulantes p, hist_cod_colegio cc, alu_x_cur axc WHERE m.run_apo='" & Text1.Text & "' AND m.agno=" & Trim(Cmb_Agno.Text) & " AND dm.folio_mens=m.folio_mens AND dm.run_alu=p.ci_alu AND dm.colegio=cc.colegio AND axc.ci_alu=dm.run_alu AND axc.agno=dm.agno AND axc.fec_cam='1111-11-11' AND ((length(dm.colegio)>6 AND axc.cod_ens='996') OR (length(dm.colegio)=6 AND axc.cod_ens<>'996')) AND ( dm.estado_dtll='impg' OR dm.estado_dtll='clda' OR dm.estado_dtll='cred' OR dm.estado_dtll='abon') GROUP BY dm.run_alu, dm.colegio ORDER BY p.fec_nacalu;"
    rs.Open QR, conn
    If rs.RecordCount < 1 Then
        rs.Close
        Set rs = Nothing
        Exit Sub
    End If
    rs.MoveFirst
    While Not (rs.EOF)
        Int_num_alu = Int_num_alu + 1
        Dbl_tot_deuda = Dbl_tot_deuda + rs("deuda_total")
        FlexGrid1.AddItem rs("run_alu") & Chr(9) & rs("nombre") & Chr(9) & rs("cursoalu") & Chr(9) & rs("colegio") & Chr(9) & rs("deuda_total"), Int_num_alu
        rs.MoveNext
    Wend
    rs.Close

    Text3.Text = Int_num_alu
    Text5.Text = Dbl_tot_deuda
    rs.CursorLocation = adUseClient
    rs.Open "SELECT count(run_apo) as num_mens FROM fnza_mensualidad WHERE run_apo='" & Text1.Text & "' AND agno=" & Trim(Cmb_Agno.Text) & " AND (estado_mens='impg' OR estado_mens='clda' OR estado_mens='abon' OR estado_mens='cred');", conn
    If rs.RecordCount < 1 Then
        rs.Close
        Set rs = Nothing
        Exit Sub
    End If
    Text4.Text = rs("num_mens")
    rs.Close
    NumMes = 0
    colegio = ""
    sw_mes = False
    sw_cole = False
    rs.CursorLocation = adUseClient
    rs.Open "SELECT m.folio_mens, m.fech_venc, m.monto_mens, m.estado_mens, mm.monto_pago, mm.fech_pago, mm.proc_pago, mm.tipo_pago, mm.estado_pago,dm.monto_tot_cuota, mm.folio_mvto, fb.folio_blta_fisico, m.colegio  FROM fnza_movimientos_mensualidad mm, fnza_dtll_mvto dtmv, fnza_detalle_mensualidad dm, fnza_mensualidad m, fnza_boletas fb WHERE fb.tipo_doc='blta' AND dtmv.folio_mvto=mm.folio_mvto and dtmv.folio_dtll=dm.folio_dtll and dtmv.folio_blta=fb.folio_blta and dm.folio_mens=m.folio_mens and m.agno=" & Trim(Cmb_Agno.Text) & " and m.run_apo='" & Text1.Text & "' ORDER BY m.run_apo, m.mes, mm.fech_pago, mm.estado_pago, m.colegio, dm.run_alu;", conn
    If rs.RecordCount > 0 Then
        While Not (rs.EOF)
            Int_num_mov = Int_num_mov + 1
            
            If NumMes <> Month(rs("fech_venc")) Then
                NumMes = Month(rs("fech_venc"))
                sw_mes = True
            Else
                sw_mes = False
            End If
            
            If colegio <> rs!colegio Then
                colegio = rs!colegio
                sw_cole = True
            Else
                sw_cole = False
            End If
            
            'Si cambia el mes, almaceno campo de valor mensual en A_Pagar
            If sw_mes Or sw_cole Then
                Dbl_tot_cuota = Dbl_tot_cuota + rs("monto_mens")
                A_Pagar = rs("monto_mens")
            Else
                If Bol_Nula Then
                    A_Pagar = Saldo_Nulo
                Else
                    A_Pagar = Saldo_Mens
                End If
            End If
            
            Monto_Pago = rs("monto_pago")
            Saldo_Mens = A_Pagar - Monto_Pago
            
            'Si el estado del pago es nulo
            If UCase(rs("estado_pago")) = "NULA" Then
                Bol_Nula = True
                'Paso el monto_pagado a negativo para descontar el movimiento aprobado
                Monto_Nulo = Monto_Pago * -1
                Saldo_Nulo = Saldo_Mens - Monto_Nulo
                A_Pagar_Nulo = Saldo_Mens
            Else
                Bol_Nula = False
                Dbl_tot_mvto = Dbl_tot_mvto + Monto_Pago 'Acumulo Pagos
            End If
            
            If Bol_Nula Then
                'Generamos item adicional para generar movimiento que será anulado
                FlexGrid2.AddItem Int_num_mov & Chr(9) & (Val(Format(rs("fech_venc"), "mm")) - 2) & Chr(9) & Format(rs("fech_venc"), "mmmm") & Chr(9) & rs("fech_venc") & Chr(9) & A_Pagar & Chr(9) & "Aprobado" & Chr(9) & rs("monto_pago") & Chr(9) & rs("fech_pago") & Chr(9) & TraduceProcPago(rs("proc_pago"), conn) & " " & TraduceTipoPago(rs("tipo_pago"), conn) & Chr(9) & rs("folio_blta_fisico") & Chr(9) & Saldo_Mens, Int_num_mov
                'Aplicamos reglas de colores para item nulos y créditos
                SeleccionaFlex2 Int_num_mov
                If Saldo_Mens > 0 Then
                    'FlexGrid2.CellBackColor = &HC0FFFF
                ElseIf Saldo_Mens = 0 Then
                    FlexGrid2.CellBackColor = &HC0FFC0
                Else
                    FlexGrid2.CellBackColor = &HC0C0FF
                End If
                Int_num_mov = Int_num_mov + 1
                FlexGrid2.AddItem Int_num_mov & Chr(9) & (Val(Format(rs("fech_venc"), "mm")) - 2) & Chr(9) & Format(rs("fech_venc"), "mmmm") & Chr(9) & rs("fech_venc") & Chr(9) & A_Pagar_Nulo & Chr(9) & TraduceEstadoPago(rs("estado_pago"), conn) & Chr(9) & Monto_Nulo & Chr(9) & rs("fech_pago") & Chr(9) & TraduceProcPago(rs("proc_pago"), conn) & " " & TraduceTipoPago(rs("tipo_pago"), conn) & Chr(9) & rs("folio_blta_fisico") & Chr(9) & Saldo_Nulo, Int_num_mov
            Else
                FlexGrid2.AddItem Int_num_mov & Chr(9) & (Val(Format(rs("fech_venc"), "mm")) - 2) & Chr(9) & Format(rs("fech_venc"), "mmmm") & Chr(9) & rs("fech_venc") & Chr(9) & A_Pagar & Chr(9) & TraduceEstadoPago(rs("estado_pago"), conn) & Chr(9) & rs("monto_pago") & Chr(9) & rs("fech_pago") & Chr(9) & TraduceProcPago(rs("proc_pago"), conn) & " " & TraduceTipoPago(rs("tipo_pago"), conn) & Chr(9) & rs("folio_blta_fisico") & Chr(9) & Saldo_Mens, Int_num_mov
            End If
            
            SeleccionaFlex2 Int_num_mov
            If Saldo_Mens > 0 Then
                'FlexGrid2.CellBackColor = &HC0FFFF
            ElseIf Saldo_Mens = 0 Then
                FlexGrid2.CellBackColor = &HC0FFC0
            Else
                FlexGrid2.CellBackColor = &HC0C0FF
            End If
            If Val(Me.FlexGrid2.TextMatrix(Int_num_mov, 6)) < 0 Then
                FlexGrid2.CellBackColor = &HFFC0FF
            End If
            rs.MoveNext
        Wend
    End If
    rs.Close
    Set rs = Nothing
    Text12.Text = Dbl_tot_cuota
    Text13.Text = Dbl_tot_mvto
    Text14.Text = Dbl_tot_cuota - Dbl_tot_mvto
    FlexGrid1.SetFocus
    FlexGrid2.SetFocus
    Call SeleccionaFlex2(1)
End Sub

Sub SeleccionaFlex2(ByVal MyRow As Long)
    FlexGrid2.Row = MyRow
    FlexGrid2.Col = 1
    FlexGrid2.RowSel = MyRow
    FlexGrid2.ColSel = 10
End Sub

Sub LlenaComboAgno()
    Dim REC As ADODB.Recordset
    Set REC = New ADODB.Recordset
    REC.Open "SELECT DISTINCT agno FROM fnza_mensualidad ORDER BY AGNO;", conn
    If REC.RecordCount > 0 Then
        For i = 1 To REC.RecordCount
            Cmb_Agno.AddItem REC!agno
            REC.MoveNext
        Next i
        Flag_sub = True
        Cmb_Agno.Text = Year(Date)
        Flag_sub = False
    End If
End Sub

Private Sub alumno_Cartola(rut As String)
    Dim rs As ADODB.Recordset
    
    Set rs = New ADODB.Recordset
    Dim QR As String
    Dim Int_num_alu As Integer
    Dim Int_num_mov As Integer
    Dim Dbl_tot_deuda As Double
    Dim Dbl_tot_cuota As Double
    Dim Dbl_tot_mvto As Double
    Dim NumMes As Integer, sw_mes, sw_cole As Boolean
    Dim Bol_Nula As Boolean
    Dim A_Pagar As Double, Monto_Pago As Double, Saldo_Mens As Double
    Dim Monto_Nulo As Double, Saldo_Nulo  As Double, A_Pagar_Nulo As Double
    Dim Saldo_Aux As Double
    Dim colegio As String
    
    Int_num_alu = 0
    Int_num_mov = 0
    Dbl_tot_deuda = 0
    Dbl_tot_cuota = 0
    Dbl_tot_mvto = 0
    
    Text1.Locked = True
    Text15.Locked = True
    DTPicker2.Enabled = False
    
'    rs.CursorLocation = adUseClient
'    QR = "SELECT DISTINCT dm.run_alu, concat(p.nom_alu,' ',p.ape_pat_alu,' ',p.ape_mat_alu) as nombre, cc.nombre as colegio, (sum(dm.monto_tot_cuota) - sum(dm.monto_abono)) AS deuda_total, concat(axc.num_gra, 'º ',axc.let_cur, ' ', if(axc.cod_ens=310,'Medio',if(axc.cod_ens=110,'Básico',if(axc.cod_ens=010,'Kinder','PreKinder')))) as cursoalu FROM fnza_detalle_mensualidad dm, fnza_mensualidad m, postulantes p, hist_cod_colegio cc, alu_x_cur axc WHERE m.run_apo='" & Text1.Text & "' AND m.agno=" & Trim(Cmb_Agno.Text) & " AND dm.folio_mens=m.folio_mens AND dm.run_alu=p.ci_alu AND dm.colegio=cc.colegio AND axc.ci_alu=dm.run_alu AND axc.agno=dm.agno AND axc.fec_cam='1111-11-11' AND ((length(dm.colegio)>6 AND axc.cod_ens='996') OR (length(dm.colegio)=6 AND axc.cod_ens<>'996')) AND ( dm.estado_dtll='impg' OR dm.estado_dtll='clda' OR dm.estado_dtll='cred' OR dm.estado_dtll='abon') and dm.run_alu = '" & rut & "' GROUP BY dm.run_alu, dm.colegio ORDER BY p.fec_nacalu;"
'    rs.Open QR, conn
'    If rs.RecordCount < 1 Then
'        rs.Close
'        Set rs = Nothing
'        Exit Sub
'    End If
'    rs.MoveFirst
'    While Not (rs.EOF)
'        Int_num_alu = Int_num_alu + 1
'        Dbl_tot_deuda = Dbl_tot_deuda + rs("deuda_total")
'        FlexGrid1.AddItem rs("run_alu") & Chr(9) & rs("nombre") & Chr(9) & rs("cursoalu") & Chr(9) & rs("colegio") & Chr(9) & rs("deuda_total"), Int_num_alu
'        rs.MoveNext
'    Wend
'    rs.Close

'    Text3.Text = Int_num_alu
    Text5.Text = Dbl_tot_deuda
    rs.CursorLocation = adUseClient
    rs.Open "SELECT count(run_apo) as num_mens FROM fnza_mensualidad WHERE run_apo='" & Text1.Text & "' AND agno=" & Trim(Cmb_Agno.Text) & " AND (estado_mens='impg' OR estado_mens='clda' OR estado_mens='abon' OR estado_mens='cred');", conn
    If rs.RecordCount < 1 Then
        rs.Close
        Set rs = Nothing
        Exit Sub
    End If
    Text4.Text = rs("num_mens")
    rs.Close
    NumMes = 0
    colegio = ""
    sw_mes = False
    sw_cole = False
    rs.CursorLocation = adUseClient
    rs.Open "SELECT m.folio_mens, m.fech_venc, m.monto_mens, m.estado_mens, mm.monto_pago, mm.fech_pago, mm.proc_pago, mm.tipo_pago, mm.estado_pago,dm.monto_tot_cuota, mm.folio_mvto, fb.folio_blta_fisico, m.colegio  FROM fnza_movimientos_mensualidad mm, fnza_dtll_mvto dtmv, fnza_detalle_mensualidad dm, fnza_mensualidad m, fnza_boletas fb WHERE fb.tipo_doc='blta' AND dtmv.folio_mvto=mm.folio_mvto and dtmv.folio_dtll=dm.folio_dtll and dtmv.folio_blta=fb.folio_blta and dm.folio_mens=m.folio_mens and m.agno=" & Trim(Cmb_Agno.Text) & " and m.run_apo='" & Text1.Text & "' and dm.run_alu = '" & rut & "' ORDER BY m.run_apo, m.mes, mm.fech_pago, mm.estado_pago, m.colegio, dm.run_alu;", conn
    FlexGrid2.Clear
    FlexGrid2.Row = 2
    If rs.RecordCount > 0 Then
        While Not (rs.EOF)
            Int_num_mov = Int_num_mov + 1
            
            If NumMes <> Month(rs("fech_venc")) Then
                NumMes = Month(rs("fech_venc"))
                sw_mes = True
            Else
                sw_mes = False
            End If
            
            If colegio <> rs!colegio Then
                colegio = rs!colegio
                sw_cole = True
            Else
                sw_cole = False
            End If
            
            'Si cambia el mes, almaceno campo de valor mensual en A_Pagar
            If sw_mes Or sw_cole Then
                Dbl_tot_cuota = Dbl_tot_cuota + rs("monto_mens")
                A_Pagar = rs("monto_mens")
            Else
                If Bol_Nula Then
                    A_Pagar = Saldo_Nulo
                Else
                    A_Pagar = Saldo_Mens
                End If
            End If
            
            Monto_Pago = rs("monto_pago")
            Saldo_Mens = A_Pagar - Monto_Pago
            
            'Si el estado del pago es nulo
            If UCase(rs("estado_pago")) = "NULA" Then
                Bol_Nula = True
                'Paso el monto_pagado a negativo para descontar el movimiento aprobado
                Monto_Nulo = Monto_Pago * -1
                Saldo_Nulo = Saldo_Mens - Monto_Nulo
                A_Pagar_Nulo = Saldo_Mens
            Else
                Bol_Nula = False
                Dbl_tot_mvto = Dbl_tot_mvto + Monto_Pago 'Acumulo Pagos
            End If
            
            If Bol_Nula Then
                'Generamos item adicional para generar movimiento que será anulado
                FlexGrid2.AddItem Int_num_mov & Chr(9) & (Val(Format(rs("fech_venc"), "mm")) - 2) & Chr(9) & Format(rs("fech_venc"), "mmmm") & Chr(9) & rs("fech_venc") & Chr(9) & A_Pagar & Chr(9) & "Aprobado" & Chr(9) & rs("monto_pago") & Chr(9) & rs("fech_pago") & Chr(9) & TraduceProcPago(rs("proc_pago"), conn) & " " & TraduceTipoPago(rs("tipo_pago"), conn) & Chr(9) & rs("folio_blta_fisico") & Chr(9) & Saldo_Mens, Int_num_mov
                'Aplicamos reglas de colores para item nulos y créditos
                SeleccionaFlex2 Int_num_mov
                If Saldo_Mens > 0 Then
                    'FlexGrid2.CellBackColor = &HC0FFFF
                ElseIf Saldo_Mens = 0 Then
                    FlexGrid2.CellBackColor = &HC0FFC0
                Else
                    FlexGrid2.CellBackColor = &HC0C0FF
                End If
                Int_num_mov = Int_num_mov + 1
                FlexGrid2.AddItem Int_num_mov & Chr(9) & (Val(Format(rs("fech_venc"), "mm")) - 2) & Chr(9) & Format(rs("fech_venc"), "mmmm") & Chr(9) & rs("fech_venc") & Chr(9) & A_Pagar_Nulo & Chr(9) & TraduceEstadoPago(rs("estado_pago"), conn) & Chr(9) & Monto_Nulo & Chr(9) & rs("fech_pago") & Chr(9) & TraduceProcPago(rs("proc_pago"), conn) & " " & TraduceTipoPago(rs("tipo_pago"), conn) & Chr(9) & rs("folio_blta_fisico") & Chr(9) & Saldo_Nulo, Int_num_mov
            Else
                FlexGrid2.AddItem Int_num_mov & Chr(9) & (Val(Format(rs("fech_venc"), "mm")) - 2) & Chr(9) & Format(rs("fech_venc"), "mmmm") & Chr(9) & rs("fech_venc") & Chr(9) & A_Pagar & Chr(9) & TraduceEstadoPago(rs("estado_pago"), conn) & Chr(9) & rs("monto_pago") & Chr(9) & rs("fech_pago") & Chr(9) & TraduceProcPago(rs("proc_pago"), conn) & " " & TraduceTipoPago(rs("tipo_pago"), conn) & Chr(9) & rs("folio_blta_fisico") & Chr(9) & Saldo_Mens, Int_num_mov
            End If
            
            SeleccionaFlex2 Int_num_mov
            If Saldo_Mens > 0 Then
                'FlexGrid2.CellBackColor = &HC0FFFF
            ElseIf Saldo_Mens = 0 Then
                FlexGrid2.CellBackColor = &HC0FFC0
            Else
                FlexGrid2.CellBackColor = &HC0C0FF
            End If
            If Val(Me.FlexGrid2.TextMatrix(Int_num_mov, 6)) < 0 Then
                FlexGrid2.CellBackColor = &HFFC0FF
            End If
            rs.MoveNext
        Wend
    End If
    rs.Close
    Set rs = Nothing
    Text12.Text = Dbl_tot_cuota
    Text13.Text = Dbl_tot_mvto
    Text14.Text = Dbl_tot_cuota - Dbl_tot_mvto
    FlexGrid1.SetFocus
    FlexGrid2.SetFocus
    Call SeleccionaFlex2(1)
End Sub

