VERSION 5.00
Object = "{B68EC213-82B3-11D5-85C7-000083628378}#3.3#0"; "CoolFlex.ocx"
Object = "{F39CBE5C-2D1B-11D6-8D4A-0050043A2E60}#2.0#0"; "ProgBarProzent.ocx"
Begin VB.Form Form_Tpagos_Act 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Tipos de Pago Alumnos Año Actual"
   ClientHeight    =   7140
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11520
   Icon            =   "Form_TPagos_Act.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7140
   ScaleWidth      =   11520
   ShowInTaskbar   =   0   'False
   Begin VB.Frame Frame_Botones 
      BorderStyle     =   0  'None
      Height          =   495
      Left            =   7080
      TabIndex        =   17
      Top             =   6120
      Width           =   2775
      Begin VB.CommandButton Btn_Gra_cap 
         Caption         =   "Grabar"
         Enabled         =   0   'False
         Height          =   375
         Left            =   0
         TabIndex        =   19
         Top             =   120
         Width           =   1215
      End
      Begin VB.CommandButton Btn_limpiar 
         Caption         =   "Limpiar"
         Height          =   375
         Left            =   1440
         TabIndex        =   18
         Top             =   120
         Width           =   1215
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Seleccione un curso"
      ForeColor       =   &H00FF0000&
      Height          =   1215
      Left            =   0
      TabIndex        =   5
      Top             =   0
      Width           =   11535
      Begin VB.PictureBox Picture1 
         Height          =   375
         Left            =   1560
         ScaleHeight     =   315
         ScaleWidth      =   2475
         TabIndex        =   15
         Top             =   720
         Width           =   2535
         Begin VB.Label lbl_fecha 
            Alignment       =   2  'Center
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   9.75
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   0
            TabIndex        =   16
            Top             =   0
            Width           =   2535
         End
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Conf. Impresora"
         Height          =   375
         Left            =   9600
         TabIndex        =   12
         Top             =   240
         Width           =   1455
      End
      Begin VB.CommandButton BtnGenRep 
         Caption         =   "Generar Reporte"
         Enabled         =   0   'False
         Height          =   375
         Left            =   9600
         TabIndex        =   11
         Top             =   720
         Width           =   1455
      End
      Begin VB.Frame Frame3 
         ForeColor       =   &H00FF0000&
         Height          =   975
         Left            =   7800
         TabIndex        =   9
         Top             =   120
         Width           =   1335
         Begin VB.OptionButton OptDesMAt 
            Caption         =   "Impresora"
            Height          =   255
            Index           =   1
            Left            =   120
            TabIndex        =   13
            Top             =   600
            Width           =   1095
         End
         Begin VB.OptionButton OptDesMAt 
            Caption         =   "Pantalla"
            Height          =   255
            Index           =   0
            Left            =   120
            TabIndex        =   10
            Top             =   240
            Value           =   -1  'True
            Width           =   975
         End
      End
      Begin VB.ComboBox Cmb_Let_Cur 
         Enabled         =   0   'False
         Height          =   315
         Left            =   6840
         TabIndex        =   2
         Top             =   360
         Width           =   615
      End
      Begin VB.ComboBox Cmb_Grado 
         Enabled         =   0   'False
         Height          =   315
         Left            =   4920
         TabIndex        =   1
         Top             =   360
         Width           =   615
      End
      Begin VB.ComboBox Cmb_Cod_ens 
         Height          =   315
         Left            =   1560
         TabIndex        =   0
         Top             =   360
         Width           =   2595
      End
      Begin VB.Label Label3 
         Caption         =   "Fecha del sistema"
         Height          =   195
         Left            =   120
         TabIndex        =   14
         Top             =   720
         Width           =   1335
      End
      Begin VB.Label Tipo 
         Caption         =   "Tipo de enseñanza"
         Height          =   195
         Left            =   120
         TabIndex        =   8
         Top             =   360
         Width           =   1455
      End
      Begin VB.Label Label1 
         Caption         =   "Nivel"
         Height          =   195
         Left            =   4440
         TabIndex        =   7
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label2 
         Caption         =   "Letra - curso"
         Height          =   195
         Left            =   5880
         TabIndex        =   6
         Top             =   360
         Width           =   1095
      End
      Begin VB.Line Line3 
         BorderColor     =   &H80000003&
         X1              =   7665
         X2              =   7665
         Y1              =   120
         Y2              =   1200
      End
      Begin VB.Line Line4 
         BorderColor     =   &H00FFFFFF&
         X1              =   7680
         X2              =   7680
         Y1              =   120
         Y2              =   1200
      End
   End
   Begin VB.CommandButton Btn_Sal_Cap 
      Caption         =   "Salir"
      Enabled         =   0   'False
      Height          =   375
      Left            =   9960
      TabIndex        =   3
      Top             =   6240
      Width           =   1215
   End
   Begin VB.PictureBox CmDialog1 
      Height          =   480
      Left            =   120
      ScaleHeight     =   420
      ScaleWidth      =   1140
      TabIndex        =   20
      Top             =   0
      Width           =   1200
   End
   Begin ProgBarProzent.ProgBar ProgBar1 
      Height          =   375
      Left            =   120
      TabIndex        =   21
      Top             =   6240
      Width           =   6855
      _ExtentX        =   12091
      _ExtentY        =   661
   End
   Begin CoolFlexGrid.CoolFlex CoolFlex1 
      Height          =   4695
      Index           =   0
      Left            =   0
      TabIndex        =   22
      Top             =   1320
      Visible         =   0   'False
      Width           =   11535
      _ExtentX        =   20346
      _ExtentY        =   8281
   End
   Begin VB.Label lbl_Num_Alu 
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   6720
      Width           =   2055
   End
End
Attribute VB_Name = "Form_Tpagos_Act"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim resmatri() As String
Dim Modificado As Boolean
Dim LosNoMat As Boolean
Dim Fila As Long
Dim ValCoDEns As Integer

Sub IniciaGrilla()
'me.CoolFlex1(1).FixedCols
CoolFlex1(1).EditEnable = True
'******** Encabezado **********
Me.CoolFlex1(1).Rows = 3
Me.CoolFlex1(1).FixedRows = 1
Me.CoolFlex1(1).Clear
With CoolFlex1(1)
    .Row = 0
    .Col = 0: .Text = "RUN"
    .Col = 1: .Text = "Nombre Alumno"
    .Col = 2: .Text = "Teléfono"
    .Col = 3: .Text = "Beca Comp."
    .Col = 4: .Text = "Media Beca"
    .Col = 5: .Text = "Cuponera"
    .Col = 6: .Text = "Cheques"
    .Col = 7: .Text = "P.A.C."
    .Col = 8: .Text = "Contado"
    .Col = 9: .Text = "Nombre Apoderado"
    .Col = 10: .Text = "Firma Apoderado"
    .Col = 11: .Text = "RUT Apoderado"
    .ColType 3, eCheckbox
    .ColType 4, eCheckbox
    .ColType 5, eCheckbox
    .ColType 6, eCheckbox
    .ColType 7, eCheckbox
    .ColType 8, eCheckbox
    '.Row = 1
    '.Col = 4: .Text = "":
    '.Col = 5: .Text = ""
    '.Col = 6: .Text = ""
    '.Col = 7: .Text = ""
    '.Col = 8: .Text = ""
    '.Col = 9: .Text = ""
End With

End Sub

Public Sub GenRep()
On Error GoTo controler
'**************************************
Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseClient
a = "select nom_est, dir_est, localidad_est from establecimientos"
Rs.Open a, conn
If Rs.RecordCount <> 0 Then
Form_main.CrystalReport.Formulas(0) = "NomCol = '" & Rs(0) & "'"
Form_main.CrystalReport.Formulas(1) = "DirCol = '" & Rs(1) & "'"
Form_main.CrystalReport.Formulas(2) = "ComunaCol = '" & Rs(2) & "'"
End If
Rs.Close
CodModalidad = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.Cmb_Cod_ens.Text & "'", conn)
Cod_Des = devuelvecampo("codigos_ensenanza", "", "cod_des", "cod_ens ='" & CodModalidad & "'", conn)
Form_main.CrystalReport.WindowTitle = "Estadística de Reservas"
Form_main.CrystalReport.Formulas(3) = "TipEns = '" & Me.Cmb_Cod_ens & "'"

If Cod_Des = "K" Or Cod_Des = "PK" Then
    Form_main.CrystalReport.Formulas(4) = "Curso = '" & Cod_Des & " " & Me.Cmb_Let_Cur & "'"
Else
    Form_main.CrystalReport.Formulas(4) = "Curso = '" & Me.Cmb_Grado & " " & Me.Cmb_Let_Cur & "'"
End If
Form_main.CrystalReport.Formulas(5) = "Hora = '" & Time() & "'"
Form_main.CrystalReport.DataFiles(0) = DirAplicacion & "\GesTemp.mdb"
Form_main.CrystalReport.Action = 1
Call LimpiaFormulas(Form_main.CrystalReport, 30)
'******************************************
Exit Sub
controler:
Resume Next

End Sub

Private Sub Btn_Gra_cap_Click()
'On Error GoTo controler
Dim CodigoEns As String, MontoEx As Long
'conn.BeginTrans
'***********************************************************************
'* inicializa la barra de progreso                                     *
'***********************************************************************
nmax = Me.CoolFlex1(1).Rows - 1
'Dim resmatri()
  With ProgBar1
    .ShowProgress 0
    .MaxValue = nmax
    .Richtung = mDir
    .ProgressStyle = mStyle
    .ShowProzent = 1
    .Zusatztext = "%"
    .ShowProgress 0
  End With
'***********************************************************************
For i = 1 To CoolFlex1(1).Rows - 1
    With CoolFlex1(1)
    'Debug.Print
                'Aquí pregunto por las opciones chequeadas
                C5 = IIf(.TextMatrix(i, 3) = "C", 1, 0) ' beca
                C6 = IIf(.TextMatrix(i, 4) = "C", 1, 0) ' media beca
                C7 = IIf(.TextMatrix(i, 5) = "C", 1, 0) ' cuponeras
                C8 = IIf(.TextMatrix(i, 6) = "C", 1, 0) ' cheques
                C9 = IIf(.TextMatrix(i, 7) = "C", 1, 0) ' pac
                C10 = IIf(.TextMatrix(i, 8) = "C", 1, 0) 'contado
                a = "UPDATE MATRICULAS Set ind_beca = '" & C5 & "' , ind_mbeca = '" & C6 & "' , ind_cup = '" & C7 & "' , ind_cheq = '" & C8 & "' ,ind_pac = '" & C9 & "', ind_cont = '" & C10 & "' WHERE CI_ALU ='" & .TextMatrix(i, 0) & "' and fec_mat = '" & InvierteFecha(CDate(resmatri(i, 2)), "R") & "' and activo_alu='SI'"
                conn.Execute a
                
                MontoEx = IIf(C5 = 1, 100, IIf(C6 = 1, 50, 0))
                If MontoEx > 0 Then
                    conn.Execute "replace into becas(run_alu, agno, tipo_beca, monto_excencion) values ('" & .TextMatrix(i, 0) & "'," & Anno & ", '2', " & MontoEx & ")"
                Else
                    'if existreg("becas","run_alu ='"& .TextMatrix(i, 0) & "' and agno =
                    conn.Execute "delete from becas where run_alu='" & .TextMatrix(i, 0) & "' and agno = " & Val(Anno)
                End If
                ' #######################
                ' Aqui se realiza la llamada al procedimiento
                ' para recalcular y regenerar la cuotas en fnza_detalle_mensualidad y fnza_mensualidad.
                  RecalculaCuota_Alu .TextMatrix(i, 0), Year(CDate(resmatri(i, 2))), conn
                  'RecalculaCuota .TextMatrix(i, 0), CDate(resmatri(i, 2)), Year(CDate(resmatri(i, 2))), ValCoDEns, conn
                ' #######################
                ProgBar1.ShowProgress i
                DoEvents
    End With
Next i
'***********************
'Call Command1_Click
 'conn.CommitTrans
 MsgBox "Los datos han sido grabados satisfactoriamente", vbInformation + vbOKOnly, "Mensaje de Gescol"
 'Me.CoolFlex1.Clear
 Me.BtnGenRep.Enabled = True
 Me.Btn_Gra_cap.Enabled = False
 Me.Btn_Sal_Cap.Enabled = True
Exit Sub
controler:
MsgBox Err.Description, vbCritical + vbOKOnly, "Error número :" & Err.Number
'conn.RollbackTrans
MsgBox "Los datos no fueron grabados.", vbCritical + vbOKOnly, "Mensaje de Gescol"
End Sub

Private Sub Btn_Limpiar_Click()
Me.Cmb_Cod_ens = ""
Me.Cmb_Grado = ""
Me.Cmb_Let_Cur = ""
Me.BtnGenRep.Enabled = False
Me.Btn_Gra_cap.Enabled = False
Me.CoolFlex1(1).Rows = 2
Me.CoolFlex1(1).Clear
End Sub

Private Sub Btn_Sal_Cap_Click()
Unload Me
End Sub

Private Sub BtnGenRep_Click()
'If Me.OptOptUno.Value = True Then
'    'If MsgBox("Esta acción guardará en la base de datos los cambios realizados . ¿Desea continuar?", vbYesNo + vbQuestion) = vbYes Then
        Call Btn_Gra_cap_Click
'        'Form_main.CrystalReport.ReportFileName = DirAplicacion + "rpt\reservas.rpt"
        
columnasnum = Me.CoolFlex1(1).Cols
Call CreaBD(DirAplicacion & "\GesTemp.mdb")
Set Rendim = DBEngine.Workspaces(0).OpenDatabase(DirAplicacion & "\GesTemp.mdb")
'If LosNoMat Then
    Call CreaTabla(DirAplicacion & "\GesTemp.mdb", "Detalles", "12,10")
'Else
'    Call CreaTabla(DirAplicacion & "\GesTemp.mdb", "Detalles", "11,10")
'End If
For R = 1 To Me.CoolFlex1(1).Rows - 1
    detal = "": ins = "": horiz = ""
    For t = 0 To Me.CoolFlex1(1).Cols - 1
        If Me.CoolFlex1(1).TextMatrix(R, t) = "" Then
            detal = detal & "Null , "
            'horiz = horiz & "'____________________________________' ,"
        ElseIf Me.CoolFlex1(1).TextMatrix(R, t) = "C" Then
            detal = detal & "'*' , "
        ElseIf Me.CoolFlex1(1).TextMatrix(R, t) = "U" Then
            detal = detal & "Null , "
        Else
        '******* CONTROLAR APOSTROFES ********
                Nombre = Me.CoolFlex1(1).TextMatrix(R, t)
                If Nombre <> "" Then
                    Pos = InStr(1, Nombre, "'")
                    If Pos <> 0 Then
                        nombre1 = Mid(Nombre, 1, Pos) & "'" & Mid(Nombre, Pos + 1, Len(Nombre))
                        Nombre = nombre1
                    End If
                End If
'******* fin CONTROLAR APOSTROFES ********
            detal = detal & "'" & Nombre & "' , "
            'horiz = horiz & "'____________________________________' ,"
        End If
        ins = ins & "C" & CStr(t + 1) & ", "
    Next t
    ins = Left(ins, Len(ins) - 2): ins = "(" & ins & ")"
    detal = Left(detal, Len(detal) - 2): detal = "(" & detal & ")"
    a = "insert into Detalles " & ins & " values " & detal
    Rendim.Execute a
Next R
Rendim.Close
    Titulo = "TIPOS DE PAGO ALUMNOS ACTUALES"
    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) = "Tipens = '" & Me.Cmb_Cod_ens.Text & "'"
    Form_main.CrystalReport.Formulas(6) = "Curso = '" & Me.Cmb_Grado & " " & Me.Cmb_Let_Cur & "'"
    Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\TPAGOS.rpt"
    Form_main.CrystalReport.DataFiles(0) = DirAplicacion & "\GesTemp.mdb"
    Form_main.CrystalReport.WindowState = crptMaximized
    Form_main.CrystalReport.ReplaceSelectionFormula ("")
    Form_main.CrystalReport.Action = 1
    Call LimpiaFormulas(Form_main.CrystalReport, 30)
    Form_main.CrystalReport.ReplaceSelectionFormula ("")
'    Kill (DirAplicacion + "GesTemp.mdb")

End Sub

Private Sub Cmb_Cod_ens_Click()

If Len(Me.Cmb_Cod_ens) <> 0 Then
CoolFlex1(1).Clear
 Nivel = devuelvecampo("codigos_ensenanza", "des_ens", "num_gra_max", "des_ens = " & "'" & Me.Cmb_Cod_ens.Text & "'", conn)
 ValCoDEns = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens = " & "'" & Me.Cmb_Cod_ens.Text & "'", conn)
 Cmb_Grado.Enabled = True
 Cmb_Grado.Clear
 Me.ProgBar1.ShowProgress 0
 Me.Btn_Gra_cap.Enabled = False
 Me.BtnGenRep.Enabled = False
 For t = 1 To Val(Nivel)
    Cmb_Grado.AddItem t
 Next t
End If

End Sub

Private Sub Cmb_Cod_ens_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

Private Sub Cmb_Grado_Click()
Cmb_Let_Cur.Clear
'CoolFlex1(1).Clear
CodModalidad = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.Cmb_Cod_ens.Text & "'", conn)
Ngrado = Me.Cmb_Grado.Text
Me.ProgBar1.ShowProgress 0
Me.Btn_Gra_cap.Enabled = False
Me.BtnGenRep.Enabled = False
Call llenacombo(Cmb_Let_Cur, "cursos", "let_cur", "where cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "'", conn)
'btn_carga_asignaturas_Click
Me.Cmb_Let_Cur.Enabled = True

End Sub

Private Sub Cmb_Grado_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

Private Sub Cmb_let_cur_Click()
Call Command1_Click
End Sub

Private Sub Command1_Click()
Dim Indice As Integer
Call IniciaGrilla
'******** FIN Encabezado **********

CodModalidad = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.Cmb_Cod_ens.Text & "'", conn)

'SELECT P.CI_ALU, P.NOM_ALU, P.APE_PAT_ALU, P.APE_MAT_ALU, AC.FEC_MAT, M.RESERVA FROM POSTULANTES P, ALU_X_CUR AC, MATRICULAS M WHERE P.CI_ALU = M.CI_ALU AND M.CI_ALU = AC.CI_ALU AND M.ACTIVO_ALU = 'SI' AND   P.CI_ALU = AC.CI_ALU AND AC.COD_ENS ='110' AND AC.NUM_GRA ='1' AND AC.ACTIVO_ALU ='SI' AND AC.fec_cam ='1111-11-11' AND AC.LET_CUR ='A' ORDER BY APE_PAT_ALU ASC, APE_MAT_ALU ASC, NOM_ALU ASC

Set Rs = New ADODB.Recordset
Set rsaux = New ADODB.Recordset
Rs.CursorLocation = adUseClient
rsaux.CursorLocation = adUseClient                                                    ' los indicadores que estan abajo no cuentan ind_cheq, ind_pac, ind_cup etc.....

'               0           1           2           3           4           5           6           7           8           9           10          11          12          13      14
a = "SELECT P.CI_ALU, P.NOM_ALU, P.APE_PAT_ALU, P.APE_MAT_ALU, M.FEC_MAT, M.RESERVA, M.IND_CUP, M.IND_CHEQ, M.IND_PAC, M.IND_BECA, M.IND_MBECA,M.IND_CONT, P.FON_ALU, M.COD_JOR, M.ANNO_MAT " & _
    "FROM POSTULANTES P, ALU_X_CUR AC, MATRICULAS M " & _
    "WHERE P.CI_ALU = M.CI_ALU AND M.CI_ALU = AC.CI_ALU AND M.ACTIVO_ALU = 'SI' AND P.CI_ALU = AC.CI_ALU AND AC.COD_ENS ='" & CodModalidad & "' AND " & _
    "AC.NUM_GRA ='" & Me.Cmb_Grado & "' AND " & _
    "AC.ACTIVO_ALU ='SI' AND " & _
    "AC.fec_cam ='1111-11-11' AND " & _
    "AC.LET_CUR ='" & Me.Cmb_Let_Cur & "' AND (M.ANNO_MAT ='" & Anno & "' or isnull(M.ANNO_MAT)) " & _
    "ORDER BY APE_PAT_ALU ASC, APE_MAT_ALU ASC, NOM_ALU ASC"

Rs.Open a, conn
'Indice = 1
If Rs.RecordCount > 0 Then

'***********************************************************************
'* inicializa la barra de progreso                                     *
'***********************************************************************
nmax = Rs.RecordCount
ReDim resmatri(nmax, 5) ' Dimensiono matriz para llenar indicadores invisibles
  With ProgBar1
    .ShowProgress 0
    .MaxValue = nmax
    .Richtung = mDir
    .ProgressStyle = mStyle
    .ShowProzent = 1
    .Zusatztext = "%"
    .ShowProgress 0
  End With
'***********************************************************************
     
     
     Rs.MoveLast
     Rs.MoveFirst
     
     i = 1
     While Not Rs.EOF
       ''Aquí almaceno en el array  el rut, la fecha matrícula y el cod. de jornada.
       resmatri(i, 1) = Rs("ci_alu"): resmatri(i, 2) = Rs("fec_mat"): resmatri(i, 3) = Rs("Cod_jor")
       CoolFlex1(1).Rows = i + 1
       CoolFlex1(1).Row = i
       CoolFlex1(1).Col = 0: CoolFlex1(1).Text = Rs("CI_ALU")
       Nombre = Rs("APE_PAT_ALU") & "  " & Rs("APE_MAT_ALU") & "  " & Rs("NOM_ALU")
       If Len(Nombre) > 33 Then Nombre = Left(Nombre, 33)
            CoolFlex1(1).Col = 1: CoolFlex1(1).Text = Nombre
            CoolFlex1(1).Col = 2: CoolFlex1(1).Text = Rs("fon_alu")
            CoolFlex1(1).Col = 3
            CoolFlex1(1).Text = IIf(IsNull(Rs("ind_beca")) Or Rs("ind_beca") <> 1, "U", "C")
         
            CoolFlex1(1).Col = 4
            CoolFlex1(1).Text = IIf(IsNull(Rs("ind_mbeca")) Or Rs("ind_mbeca") <> 1, "U", "C")
            
            CoolFlex1(1).Col = 5
            CoolFlex1(1).Text = IIf(IsNull(Rs("ind_cup")) Or Rs("ind_cup") <> 1, "U", "C")
            
            CoolFlex1(1).Col = 6
            CoolFlex1(1).Text = IIf(IsNull(Rs("ind_cheq")) Or Rs("ind_cheq") <> 1, "U", "C")
            
            CoolFlex1(1).Col = 7
            CoolFlex1(1).Text = IIf(IsNull(Rs("ind_pac")) Or Rs("ind_pac") <> 1, "U", "C")
            
            CoolFlex1(1).Col = 8
            CoolFlex1(1).Text = IIf(IsNull(Rs("ind_cont")) Or Rs("ind_cont") <> 1, "U", "C")
            'Aquí mostrar el tipo de pago actual
            'en la columna Nº 11
            
            rsinforme.CursorLocation = adUseClient
            rsinforme.Open "select a.noms_apo, a.ape1_apo, a.ape2_apo, a.rut_apo from apoderados a, apo_x_alu ap, postulantes p where p.ci_alu=ap.ci_alu and ap.rut_apo=a.rut_apo and p.ci_alu = '" & Rs("CI_ALU") & "'", conn
            If rsinforme.RecordCount > 0 Then
                CoolFlex1(1).Col = 9
                CoolFlex1(1).Text = Trim(rsinforme(0)) & " " & Trim(rsinforme(1)) & " " & Trim(rsinforme(2))
                CoolFlex1(1).Col = 11
                CoolFlex1(1).Text = rsinforme(3)
            End If
            rsinforme.Close
            i = i + 1
       Rs.MoveNext
       
       ProgBar1.ShowProgress i
       DoEvents
    Wend
    ProgBar1.ShowProgress 100
    
Me.BtnGenRep.Enabled = True
Me.Btn_Gra_cap.Enabled = True
Me.Btn_Sal_Cap.Enabled = True

End If
Me.lbl_Num_Alu.Caption = "Alumnos en el curso :" & i
Rs.Close
End Sub

Private Sub Cmb_Let_Cur_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub

Private Sub Cmb_Tipos_pago_Click()
'Me.CoolFlex1(1).TextMatrix(Fila, 11) = Me.Cmb_Tipos_pago.Text
Me.Frame1.Enabled = True
Me.Frame_Botones.Enabled = True
Me.CoolFlex1(1).GridEnabled = True
End Sub

Private Sub CoolFlex1_CellCheckBoxClick(Index As Integer, ColIndex As Long, Value As Integer)
If Value = 1 Then
    'If (ColIndex >= 5 And ColIndex <= 10) And (UCase(Me.CoolFlex1(1).TextMatrix(Me.CoolFlex1(1).Row, 4)) = "U") Then
    '        'If UCase(Me.CoolFlex1(1).TextMatrix(Me.CoolFlex1(1).Row, 3)) = "NO" Then
    '            MsgBox ("Imposible realizar esta operación" & Chr(13) & "Alumno No matriculado")
    '            Me.CoolFlex1(1).Col = ColIndex
    '            Me.CoolFlex1(1).Text = "U"
    '            'TextMatrix(Me.CoolFlex1(1).Row, ColIndex) = "U"
    ''ElseIf ColIndex = 4 And UCase(Me.CoolFlex1(1).TextMatrix(Me.CoolFlex1(1).Row, 3)) = "NO" Then
    ''    MsgBox ("Imposible realizar esta operación" & Chr(13) & "No tiene matrícula reservada")
    ''    Me.CoolFlex1(1).Col = ColIndex
    ''    Me.CoolFlex1(1).Text = "U"
    'End If
    
    If ColIndex = 3 Then ' beca
        Me.CoolFlex1(1).Col = 4: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 5: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 6: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 7: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 8: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = ColIndex
    ElseIf ColIndex = 4 Then ' media beca
        Me.CoolFlex1(1).Col = 3: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = ColIndex
    ElseIf ColIndex = 5 Then 'cuponera
        Me.CoolFlex1(1).Col = 3: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 6: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 7: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 8: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = ColIndex
    ElseIf ColIndex = 6 Then
        Me.CoolFlex1(1).Col = 3: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 5: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 7: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 8: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = ColIndex
    ElseIf ColIndex = 7 Then
        Me.CoolFlex1(1).Col = 3: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 5: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 6: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 8: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = ColIndex
    ElseIf ColIndex = 8 Then
        Me.CoolFlex1(1).Col = 3: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 5: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 6: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = 7: Me.CoolFlex1(1).Text = "U"
        Me.CoolFlex1(1).Col = ColIndex
    End If
Else
    If ColIndex = 5 Then 'verificar que no tenga cuponera para permitirle quitar la opción
        Fila = Me.CoolFlex1(1).Row
        RutApo = Me.CoolFlex1(1).TextMatrix(Fila, 11)
        Agno = Year(CDate(resmatri(Fila, 2)))
        If ExistReg("fnza_cuponeras", "rut_apo ='" & RutApo & "' and agno=" & Agno & " and (ucase(esta_fin)='PE' or ucase(esta_fin)='PA')", conn) Then
            MsgBox "Apoderado tiene Cuponera Vigente, imposible quitar la opción."
            Me.CoolFlex1(1).Col = 5: Me.CoolFlex1(1).Text = "U"
            Me.CoolFlex1(1).Col = ColIndex
        End If
    End If
End If
'ElseIf ColIndex = 4 Then
'        Me.CoolFlex1(1).Col = 5: Me.CoolFlex1(1).Text = "U"
'        Me.CoolFlex1(1).Col = 6: Me.CoolFlex1(1).Text = "U"
'        Me.CoolFlex1(1).Col = 7: Me.CoolFlex1(1).Text = "U"
'        Me.CoolFlex1(1).Col = 8: Me.CoolFlex1(1).Text = "U"
 '       Me.CoolFlex1(1).Col = 9: Me.CoolFlex1(1).Text = "U"
 '       Me.CoolFlex1(1).Col = 10: Me.CoolFlex1(1).Text = "U"
 ''       Me.CoolFlex1(1).Col = 4: Me.CoolFlex1(1).Col = ColIndex'End If
                                                                                                                                      End Sub
Private Sub CoolFlex1_CellComboBoxChange(Index As Integer, ColIndex As Long)
Modificado = True
Me.BtnGenRep.Enabled = False
Me.Btn_Gra_cap.Enabled = True
End Sub

Private Sub CoolFlex1_Click(Index As Integer)
'If index = 1 And Me.CoolFlex1(1).Col = 11 Then 'And Muestra Then
'    'Me.Cmb_Tipos_pago.ListIndex = -1
'    Fila = Me.CoolFlex1(1).Row
'    Me.Frame1.Enabled = False
'    Me.Frame_Botones.Enabled = False
'    Me.CoolFlex1(1).GridEnabled = False
'    Me.Frame_Tipos_Pago.Visible = True
'End If
End Sub

Private Sub CoolFlex1_GotFocus(Index As Integer)
Modificado = True
Me.BtnGenRep.Enabled = False
Me.Btn_Gra_cap.Enabled = True
End Sub

Private Sub Form_Load()
Modificado = False
Load Me.CoolFlex1(1)
CoolFlex1(1).Clear
'CoolFlex1(1).EditTextLenght = 0
CoolFlex1(1).EditEnable = False
CoolFlex1(1).Cols = 12
CoolFlex1(1).Rows = 3
Me.CoolFlex1(1).Visible = True
With CoolFlex1(1)
.FixedCols = 3
.FixedRows = 1
.ColWidth(0) = 950 'RUT
.ColWidth(1) = 3300 'NOMBRE
.ColWidth(2) = 800 'FONO
.ColWidth(3) = 780  'Beca Completa
.ColWidth(4) = 780  'Media Beca
.ColWidth(5) = 780  'Cuponera
.ColWidth(6) = 780  'Cheques
.ColWidth(7) = 780  'P.A.C.
.ColWidth(8) = 780  'CONTADO
.ColWidth(9) = 3300 ' Nombre apoderado
.ColWidth(10) = 3300 ' Nombre apoderado
.ColWidth(11) = 950 'RUT apoderado
.HideCol(10) = True
.HideCol(11) = True
End With
Me.lbl_fecha.Caption = Date
Me.Btn_Gra_cap.Enabled = False
'Call Iniciagrilla
CentrarForma Me
Set Rs = New ADODB.Recordset
Rs.CursorLocation = adUseClient
Set rsinforme = New ADODB.Recordset
rsinforme.CursorLocation = adUseClient
'********* Llena combos ****************
Call llenacombo(Cmb_Cod_ens, "codigos_ensenanza", "des_ens", "order by ord_ens", conn)
End Sub


Private Sub Form_Unload(Cancel As Integer)
Call menuhabilitado(True)
End Sub

'************ SQL ESTADISTICA ***************
'* SELECT AC.COD_ENS, AC.NUM_GRA, AC.LET_CUR,MO.COD_DES, COUNT(M.RESERVA) AS MATRICULA, COUNT(M.RESERVA)-sum(M.RESERVA) AS SIN_RES, sum(M.RESERVA) AS CON_RES FROM POSTULANTES P, ALU_X_CUR AC, MATRICULAS M, CODIGOS_ENSENANZA MO WHERE P.CI_ALU = M.CI_ALU AND M.CI_ALU = AC.CI_ALU AND M.ACTIVO_ALU = 'SI' AND P.CI_ALU = AC.CI_ALU     AND AC.ACTIVO_ALU ='SI' AND AC.fec_cam ='1111-11-11' AND AC.COD_ENS=MO.COD_ENS   GROUP BY AC.COD_ENS, AC.NUM_GRA, AC.LET_CUR  ORDER BY AC.COD_ENS ASC, AC.NUM_GRA ASC, AC.LET_CUR ASC
'********************************************
Private Sub OptDesMAt_Click(Index As Integer)
If Index = 1 Then
    Form_main.CrystalReport.Destination = crptToPrinter
ElseIf Index = 0 Then
    Form_main.CrystalReport.Destination = crptToWindow
End If
End Sub

Function RecalculaCuota(ByVal RunAlu As String, ByVal FECMAT As Date, ByVal Agno As Integer, ByVal Codens As Integer, ByRef CNX As ADODB.Connection) As Boolean
On Error GoTo Controlerror:
    Dim RC As ADODB.Recordset
    Dim RC_Ver As ADODB.Recordset
    Dim CMD As ADODB.Command
    Dim QR As String
    Dim RunApo As String
    Dim Colegio As String
    Dim FolioDtll As Long
    Dim FolioMens As Long
    Dim RegAfectted As Long
    Dim MesINI As Integer
    Dim MatrizPagos As Variant
    Dim QueryCodEns As String
    Dim CodConv As String
    Dim TotalAgnoApo As Long
    
    RecalculaCuota = False
    Set RC = New ADODB.Recordset
    Set RC_Ver = New ADODB.Recordset
    ' extraigo el Colegio
    QR = "SELECT hcc.colegio FROM establecimientos e, hist_cod_colegio hcc WHERE hcc.cod_rbd=e.rdb LIMIT 1;"
    RC.Open QR, CNX
    If Not (RC.RecordCount = 0) Then
        RC.MoveFirst
        Colegio = RC("colegio")
        RC.Close
    Else
        RC.Close
        Err.Raise vbObjectError + 700, "Form_Tpagos_Act.RecalculaCuota", "No se encontro establecimiento."
    End If
    
    ' extraigo el apoderado
    QR = "SELECT rut_apo FROM apo_x_alu WHERE ci_alu='" & RunAlu & "' LIMIT 1;"
    RC.Open QR, CNX
    If Not (RC.RecordCount = 0) Then
        RC.MoveFirst
        RunApo = RC("rut_apo")
        RC.Close
    Else
        RC.Close
        Err.Raise vbObjectError + 700, "Form_Tpagos_Act.RecalculaCuota", "No se encontro apoderado en la relación."
    End If
    
    If Codens = 996 Then
        Colegio = Colegio & "MMC"
        QueryCodEns = " and c.cod_des = 'PK'"
    Else
        QueryCodEns = " and c.cod_des <> 'PK'"
    End If
    
    
    QR = "select ac.ci_alu, a.rut_apo, ac.fec_mat from apoderados a, apo_x_alu ap, matriculas ac, codigos_ensenanza c where a.rut_apo = ap.rut_apo and a.rut_apo='" & RunApo & "' and ap.ci_alu=ac.ci_alu and ac.cod_ens=c.cod_ens and ac.activo_alu = 'SI' " & QueryCodEns
    RC.Open QR, CNX
    If RC.RecordCount = 0 Then
        RC.Close
        Err.Raise vbObjectError + 705, "Form_Tpagos_Act.RecalculaCuota", "No se encuentran alumno(s) asociado(s) al apoderado. " & vbCrLf & RunApo & " -> " & RunAlu & " no existe."
        Exit Function
    End If
    RC.MoveFirst
    Set CMD = New ADODB.Command
    CMD.CommandType = adCmdText
    CMD.ActiveConnection = CNX
    For j = 1 To RC.RecordCount

    If Year(RC!fec_mat) < Agno Then
        MesINI = 2
        ElseIf Month(RC!fec_mat) < 2 Then
            MesINI = 2
    Else
            If Day(RC!fec_mat) > 15 Then
                MesINI = Month(RC!fec_mat)
            Else
                MesINI = Month(RC!fec_mat) - 1
            End If
    End If
        

        ' Calula la cuota del alumno
        MatrizPagos = CalculaCuotaalu(RC("ci_alu"), Colegio, Agno, False)
        If MatrizPagos(0, 3) = 0 Then
            CodConv = "none"
        Else
            CodConv = "pend"
        End If
                
        For i = MesINI To 12
            ' calcula el folio del detalle si exite
            FolioDtll = num_folio_dtll(RC("ci_alu"), "esco", Colegio, i, Agno, CNX)

            ' si existe entonces
            If Not (FolioDtll = 0) Then
                FolioMens = num_mens_from_dtll(FolioDtll, CNX)
                If FolioMens = 0 Then
                    Err.Raise vbObjectError + 709, "Form_Tpagos_Act.RecalculaCuota", "No fue posible encontrar mensualidad para el detalle de folio nº" & FolioDtll
                End If
            
                ' Cuanto figura a pagar hasta ahora
                QR = "SELECT monto_mens as anualidad FROM fnza_mensualidad WHERE folio_mens=" & FolioMens & ";"
                RC_Ver.Open QR, CNX
                If Not (RC_Ver.RecordCount = 0) Then
                    RC_Ver.MoveFirst
                    If Not (IsNull(RC_Ver("anualidad"))) Then
                        TotalAgnoApo = RC_Ver("anualidad")
                    Else
                        TotalAgnoApo = 0
                    End If
                    RC_Ver.Close
                Else
                    RC_Ver.Close
                    TotalAgnoApo = 0
                End If
            
        ' Registrar montos
                If Not (fijar_montos_detalle(CNX, FolioDtll, MatrizPagos(0, 0), MatrizPagos(0, 2), MatrizPagos(0, 1), MatrizPagos(0, 4), MatrizPagos(0, 3), CodConv)) Then
                        Err.Raise vbObjectError + 707, "", "No fue posible Fijar los montos en el detalle de folio nº" & FolioDtll
                End If
                
        ' ver si fue alterada la mens
                QR = "SELECT monto_mens as anualidad FROM fnza_mensualidad WHERE folio_mens=" & FolioMens & ";"
                RC_Ver.Open QR, CNX
                If Not (RC_Ver.RecordCount = 0) Then
                    RC_Ver.MoveFirst
                    If Not (TotalAgnoApo = RC_Ver("anualidad")) Then
                        QR = "REPLACE fnza_apoderado_revisar(run_apo,folio_mens,forma_pago,fech_modificacion) VALUES ('" & RunApo & "','0','beca_mensualidad_editada','" & Format(FECMAT, "yyyy-mm-dd") & "') "
                        CMD.CommandText = QR
                        CMD.Execute RegAfectted
                        If RegAfectted = 0 Then
                            Err.Raise vbObjectError + 711, "", "No fue posible registrar posible modificacion de mensualidad folio nº" & FolioMens & " ligada al detalle folio nº" & FolioDtll
                        End If
                    End If
                Else
                    Err.Raise vbObjectError + 713, "Form_Tpagos_Act.RecalculaCuota", "No se encontro el apoderado durante la verificación de modificación."
                End If
                RC_Ver.Close
        

            Else
        ' No hacer nada si no existe, solo registrar una alerta
        QR = "REPLACE fnza_apoderado_revisar(run_apo,folio_mens,forma_pago,fech_modificacion) VALUES ('" & RunApo & "','0','beca_dtll_inexistente_" & RC!Ci_alu & "','" & Format(RC!fec_mat, "yyyy-mm-dd") & "') "
                CMD.CommandText = QR
                CMD.Execute RegAfectted
                If RegAfectted = 0 Then
                    Err.Raise vbObjectError + 711, "", "No fue posible registrar posible modificacion de mensualidad folio nº" & FolioMens & " ligada al detalle folio nº" & FolioDtll
                End If
        End If

        Next i
        RC.MoveNext
    Next j
    RC.Close
    
    Set RC = Nothing
    Set RC_Ver = Nothing
    RecalculaCuota = True
    
    Exit Function
Controlerror:
    If Err.Number = -2147220797 Then
        Resume
    End If
    Resume
    Set RC = Nothing
    Set RC_Ver = Nothing
    Err.Raise Err.Number, Err.Source & vbCrLf & "Form_Tpagos_Act.RecalculaCuota", Err.Description
End Function

