VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Object = "{00025600-0000-0000-C000-000000000046}#4.6#0"; "crystl32.ocx"
Begin VB.Form Form_Imprimir_Contrato_Apoderado 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Imprimir Contrato Educacional y Compromiso de Pago"
   ClientHeight    =   2895
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   8430
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Form_Imprimir_Contrato_Apoderado.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   2895
   ScaleWidth      =   8430
   Begin Crystal.CrystalReport cr_pagare 
      Left            =   1920
      Top             =   2280
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   262150
   End
   Begin VB.CommandButton cmd_pagare 
      Caption         =   "Imprimir Pagaré"
      Height          =   855
      Left            =   6840
      Picture         =   "Form_Imprimir_Contrato_Apoderado.frx":2A8B2
      Style           =   1  'Graphical
      TabIndex        =   14
      Top             =   1920
      Width           =   1455
   End
   Begin VB.ListBox List2 
      Height          =   900
      Left            =   6720
      TabIndex        =   11
      TabStop         =   0   'False
      Top             =   720
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.ListBox List1 
      Height          =   900
      Left            =   960
      TabIndex        =   10
      TabStop         =   0   'False
      Top             =   720
      Visible         =   0   'False
      Width           =   5295
   End
   Begin VB.Frame Frame2 
      Caption         =   "Forma Pago Pactado"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   735
      Left            =   5640
      TabIndex        =   12
      Top             =   1080
      Width           =   2655
      Begin MSComctlLib.ImageCombo ImageCombo1 
         Height          =   345
         Left            =   120
         TabIndex        =   13
         Top             =   240
         Width           =   2415
         _ExtentX        =   4260
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Locked          =   -1  'True
      End
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Imprimir &Contrato"
      Height          =   855
      Left            =   5160
      Picture         =   "Form_Imprimir_Contrato_Apoderado.frx":2AEB4
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   1920
      Width           =   1455
   End
   Begin VB.Frame Frame13 
      Caption         =   "Año de Consulta"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   735
      Left            =   3840
      TabIndex        =   7
      Top             =   1080
      Width           =   1695
      Begin VB.ComboBox Combo1 
         Height          =   330
         Left            =   120
         Style           =   2  'Dropdown List
         TabIndex        =   8
         Top             =   240
         Width           =   1455
      End
   End
   Begin VB.Frame Frame6 
      Caption         =   "Colegio"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   735
      Left            =   120
      TabIndex        =   5
      Top             =   1080
      Width           =   3615
      Begin MSComctlLib.ImageCombo ImageCombo2 
         Height          =   345
         Left            =   120
         TabIndex        =   6
         Top             =   240
         Width           =   3375
         _ExtentX        =   5953
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Locked          =   -1  'True
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Apoderado"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   8175
      Begin VB.TextBox Text1 
         Height          =   285
         Left            =   840
         TabIndex        =   2
         Top             =   360
         Width           =   5295
      End
      Begin VB.TextBox Text2 
         Height          =   285
         Left            =   6600
         TabIndex        =   1
         Top             =   360
         Width           =   1335
      End
      Begin VB.Label Label1 
         Caption         =   "Nombre"
         Height          =   255
         Left            =   120
         TabIndex        =   4
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label2 
         Caption         =   "Run"
         Height          =   255
         Left            =   6240
         TabIndex        =   3
         Top             =   360
         Width           =   375
      End
   End
End
Attribute VB_Name = "Form_Imprimir_Contrato_Apoderado"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Variables Gen del Form
Dim Flag_sub As Boolean
'se agrega 09-06-2022
Private Type cuotas
    NumeroCuota As String
    MesCuota As String
    MesTexto As String
    ValorCuota As String
    Año As String
End Type

Dim cuotas() As cuotas

Private Sub Command1_Click()
  
    If Me.Combo1.Text <> "" And Me.text2.Text <> "" Then
        creacartaaviso Trim(Me.text2.Text), Trim(Me.Combo1.Text), " "
        Call LimpiaFormulas(Form_main.CrystalReport, 30)
        Form_main.CrystalReport.ReportFileName = App.Path & "\rpt\cartaaviso.rpt"
        Form_main.CrystalReport.WindowState = crptMaximized
        Form_main.CrystalReport.WindowTitle = "Carta Aviso"
        Form_main.CrystalReport.ReplaceSelectionFormula ("")
        Form_main.CrystalReport.ReplaceSelectionFormula ("{tmp_aviso.ci_apo}='" & Trim(Me.text2.Text) & "'")
        Form_main.CrystalReport.Destination = crptToWindow
        Form_main.CrystalReport.Action = 1
        Call LimpiaFormulas(Form_main.CrystalReport, 30)
    End If
    
End Sub

Private Sub cmd_pagare_Click()
 '''' Pagare
    Dim apoderado As String
    Dim rut As String
    Dim nacionalidad As String
    Dim direccion As String
    Dim Comuna As String
    Dim Telefono As String
    Dim alumnos As String
    Dim colegio As String
    Dim sociedad As String
    Dim rut_sociedad As String
    Dim monto As String
    Dim cantidad_cuotas As Integer
    Dim cuota1 As String
    Dim cuota2 As String
    Dim cuota3 As String
    Dim cuota4 As String
    Dim cuota5 As String
    Dim cuota6 As String
    Dim cuota7 As String
    Dim cuota8 As String
    Dim cuota9 As String
    Dim cuota10 As String
    Dim forma_pago As String
    Dim dia As Integer
    Dim mes As String
    Dim fecha_pagare As Date
    'Dim agno As String
    Dim Folio As Integer
    Dim accion_detalle As String
    Dim ValorUF As String
    Dim TextoCuota As String
    Dim PuntoyRaya As String
    Dim Texto1 As String
    Dim Texto2 As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    '' rut_apo agno
    
    var_sql = "SELECT m.ci_alu,CONCAT(nom_alu,' ',ape_pat_alu,' ',ape_mat_alu) AS alumno" _
            & " FROM apo_x_alu axa,matriculas m,postulantes p" _
            & " Where axa.ci_alu = m.ci_alu And axa.agno = m.anno_mat And axa.ci_alu = p.ci_alu" _
            & " AND axa.agno = " & Combo1.Text & " AND axa.rut_apo = '" & text2.Text & "'"
    objRS.Open var_sql, conn
    alumnos = ""
    cont = 0
    If objRS.RecordCount > 0 Then
        While Not objRS.EOF
            cont = cont + 1
            If cont = 1 Then
                alumnos = alumnos & objRS("alumno")
            Else
                alumnos = alumnos & ", " & objRS("alumno")
            End If
            objRS.MoveNext
            forma_pago = "Cuponera" 'objRS("forma_pago")
        Wend
    End If
    objRS.Close
    
    
    If forma_pago = "cheque" Or forma_pago = "contado" Or forma_pago = "Credito" Or forma_pago = "Transferencia" Or forma_pago = "Debito" Then
        Exit Sub
    End If
    
    
    var_sql = "SELECT concat(noms_apo,' ',ape1_apo,' ',ape2_apo) as apoderado,rut_apo,'Chileno' AS nacionalidad,dir_apo,comuna,cel_apo" _
            & " FROM apoderados a,codigos__geograficos cg" _
            & " WHERE a.comuna_apo = cg.cod_geo AND rut_apo = '" & text2.Text & "'"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        apoderado = objRS("apoderado")
        rut = objRS("rut_apo")
        nacionalidad = objRS("nacionalidad")
        direccion = objRS("dir_apo")
        Comuna = objRS("comuna")
        Telefono = objRS("cel_apo")
    End If
    objRS.Close
    
    'se agrega parametro de monto de uf para no tener valores en duro 09-06-2022
    ValorUF = 0
    var_sql = ""
    var_sql = " SELECT VALOR FROM CFG"
    var_sql = var_sql & " where param = 'MONTO_UF'"
    var_sql = var_sql & " and agno = " & Combo1.Text & ""
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        ValorUF = objRS("valor")
    End If
    objRS.Close
    
    
    var_sql = "SELECT SUM(monto_mens) AS monto,COUNT(mes) AS cantidad_cuotas FROM fnza_mensualidad WHERE run_apo = '" & text2.Text & "' AND agno = " & Combo1.Text & " AND mes >= 3"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        'monto =                     objRS("monto") / 36865.37
        If ValorUF > 0 Then
            monto = IIf(IsNull(objRS("monto")), 0, objRS("monto") / val(ValorUF))
            cantidad_cuotas = objRS("cantidad_cuotas")
        End If
    End If
    objRS.Close
        
'    var_sql = "SELECT SUM(monto_mens) AS monto,COUNT(mes) AS cantidad_cuotas FROM fnza_mensualidad WHERE run_apo = '" & Text2.Text & "' AND agno = " & Combo1.Text & " AND mes >= 3"
'    objRS.Open var_sql, conn
'    If objRS.RecordCount > 0 Then
'        monto = objRS("monto")
'        cantidad_cuotas = objRS("cantidad_cuotas")
'    End If
'    objRS.Close
    
    var_sql = "SELECT monto_mens,mes FROM fnza_mensualidad WHERE run_apo = '" & text2.Text & "' AND agno = " & Combo1.Text & " AND mes >= 3 ORDER BY mes"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        ReDim Preserve cuotas(objRS.RecordCount)
        I = 1
        While Not objRS.EOF
        
            cuotas(I).MesCuota = objRS("mes")
              Select Case objRS("mes")
                Case 1
                    cuotas(I).MesTexto = "Enero"
                Case Is = 2
                    cuotas(I).MesTexto = "Febrero"
                Case Is = 3
                    cuotas(I).MesTexto = "Marzo"
                Case Is = 4
                    cuotas(I).MesTexto = "Abril"
                Case Is = 5
                    cuotas(I).MesTexto = "Mayo"
                Case Is = 6
                    cuotas(I).MesTexto = "Junio"
                Case Is = 7
                    cuotas(I).MesTexto = "Julio"
                Case Is = 8
                    cuotas(I).MesTexto = "Agosto"
                Case Is = 9
                    cuotas(I).MesTexto = "Septiembre"
                Case Is = 10
                    cuotas(I).MesTexto = "Octubre"
                Case Is = 11
                    cuotas(I).MesTexto = "Noviembre"
                Case Is = 12
                    cuotas(I).MesTexto = "Diciembre"
            End Select
            cuotas(I).NumeroCuota = I
                                  'objRS("monto_mens") / 36865.37
            cuotas(I).ValorCuota = objRS("monto_mens") / val(ValorUF)
            cuotas(I).Año = Combo1.Text
            I = I + 1
            
'            If objRS("mes") = 3 Then cuota1 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 4 Then cuota2 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 5 Then cuota3 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 6 Then cuota4 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 7 Then cuota5 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 8 Then cuota6 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 9 Then cuota7 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 10 Then cuota8 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 11 Then cuota9 = objRS("monto_mens") / 36865.37
'            If objRS("mes") = 12 Then cuota10 = objRS("monto_mens") / 36865.37
            objRS.MoveNext
        Wend
    End If
    objRS.Close
        
    
    var_sql = "SELECT localidad_est,CONCAT('COLEGIO ',nom_est) AS colegio,nom_sostenedor AS sociedad,rut_sostenedor AS rut_sociedad FROM establecimientos"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        colegio = objRS("colegio")
        sociedad = objRS("sociedad")
        rut_sociedad = objRS("rut_sociedad")
        comuna_colegio = objRS("localidad_est")
    End If
    objRS.Close
    
        
    var_sql = "SELECT DAY(NOW()) AS dia,MONTH(NOW()) as mes,YEAR(NOW()) AS agno"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        dia = objRS("dia")
        mes = objRS("mes")
        agno = objRS("agno")
    End If
    objRS.Close
    
    
    var_sql = "SELECT (MAX(folio) + 1) AS folio FROM fnza_pagare_historial"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        Folio = IIf(IsNull(objRS("folio")), 1, objRS("folio"))
    End If
    objRS.Close
    'Set objRS = Nothing
        
        
''''''    'Reviso que el pagare no se duplique
''''''    var_sql = "SELECT * " _
''''''            & " From fnza_pagare_historial" _
''''''            & " WHERE ci_apo = '" & text2.Text & "' AND agno = " & Combo1.Text
''''''    objRS.Open var_sql, conn
''''''    If objRS.RecordCount > 0 Then
''''''        MsgBox "El pagaré ya fue impreso", vbInformation
''''''        Exit Sub
''''''    End If
''''''    objRS.Close
            
        
    var_sql = "replace INTO fnza_pagare_historial(ci_apo,txt,txt_detalle,cardinal,sostenedor,pie_detalle,agno,folio)" _
            & " SELECT '" & text2.Text & "',txt,txt_detalle,cardinal,sostenedor,pie_detalle," & Combo1.Text & "," & Folio & " AS folio FROM fnza_pagare"
    conn.Execute var_sql
    
    ' Log Pagaré
    accion_detalle = "El usuario genero Pagaré para el apoderado " & apoderado
    Call Inserta_Vitacora_Finanza(text2.Text, text2.Text, "Generación de Pagaré", accion_detalle, 0, 0)
    ' Fin Log
           
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[apoderado]','" & apoderado & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    ' Format(cuota1, "###,###,###")
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[rut]','" & Format(rut, "&&.&&&.&&&") & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[nacionalidad]','" & nacionalidad & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[direccion]','" & direccion & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[comuna]','" & Comuna & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[colegio]','" & colegio & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[alumnos]','" & alumnos & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[telefono]','" & Telefono & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[sociedad]','" & sociedad & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    'Format(cuota1, "###,###,###")
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[rut_sociedad]','" & Format(rut_sociedad, "&&.&&&.&&&") & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt = REPLACE(txt,'[monto]','" & Mid(monto, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    'Format(suma, "###,###,###")
        
    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cantidad_cuotas]'," & cantidad_cuotas & ") WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
    conn.Execute var_sql
    
    PuntoyRaya = ".-"
        
    TextoCuota = ""
    For I = 1 To UBound(cuotas)
        Texto1 = "Cuota N° " & I & ",  por la suma de "
        Texto2 = "UF,  con vencimiento al 10 de " & cuotas(I).MesTexto & " de " & cuotas(I).Año & "  "
        If TextoCuota = "" Then
            TextoCuota = "" & I & "" & PuntoyRaya & " " & Texto1 & "  " & Mid(cuotas(I).ValorCuota, 1, 8) & "  " & Texto2 & " " & Chr(13) & ""
        Else
            TextoCuota = TextoCuota & "" & I & "" & PuntoyRaya & "  " & Texto1 & "  " & Mid(cuotas(I).ValorCuota, 1, 8) & "  " & Texto2 & "  " & Chr(13) & ""
        End If
        
    Next I
    var_sql = ""
    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[DETALLE_CUOTA]', '" & TextoCuota & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
    conn.Execute var_sql
        
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota1 ]','" & Mid(cuota1, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota2 ]','" & Mid(cuota2, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota3 ]','" & Mid(cuota3, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota4 ]','" & Mid(cuota4, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota5 ]','" & Mid(cuota5, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota6 ]','" & Mid(cuota6, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota7 ]','" & Mid(cuota7, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota8 ]','" & Mid(cuota8, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota9 ]','" & Mid(cuota9, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
'
'    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[cuota10 ]','" & Mid(cuota10, 1, 8) & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '1.- Vencimiento:'"
'    conn.Execute var_sql
    
        
    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[forma_pago]','Cheque') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '2.- Lugar de pago:'"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[comuna_colegio]','" & comuna_colegio & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '2.- Lugar de pago:'"
    conn.Execute var_sql
    
    
    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[alumnos]','" & alumnos & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '4.- Declaración:'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[colegio]','" & colegio & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '4.- Declaración:'"
    conn.Execute var_sql
    
    
    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[colegio]','" & colegio & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '6.- Cambio de domicilio:'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET txt_detalle = REPLACE(txt_detalle,'[colegio]','" & colegio & "') WHERE ci_apo = '" & text2.Text & "' AND cardinal = '9.- Domicilio y Jurisdicción:'"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET pie_detalle = REPLACE(pie_detalle,'[colegio]','" & colegio & "')"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET pie_detalle = REPLACE(pie_detalle,'[sociedad]','" & sociedad & "')"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET pie_detalle = REPLACE(pie_detalle,'[rut_sociedad]','" & rut_sociedad & "')"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET pie_detalle = REPLACE(pie_detalle,'[apoderado]','" & apoderado & "')"
    conn.Execute var_sql
        
    var_sql = "UPDATE fnza_pagare_historial SET pie_detalle = REPLACE(pie_detalle,'[dia_fecha]','" & dia & "')"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_pagare_historial SET pie_detalle = REPLACE(pie_detalle,'[mes_fecha]','" & IIf(mes = 1, "Enero", IIf(mes = 2, "Febrero", IIf(mes = 3, "Marzo", IIf(mes = 4, "Abril", IIf(mes = 5, "Mayo", IIf(mes = 6, "Junio", IIf(mes = 7, "Julio", IIf(mes = 8, "Agosto", IIf(mes = 9, "Septiembre", IIf(mes = 10, "Octubre", IIf(mes = 11, "Noviembre", "Diciembre"))))))))))) & "')"
    conn.Execute var_sql
    
    var_sql = "DELETE FROM fnza_pagare_temp;"
    conn.Execute var_sql
    
    var_sql = "INSERT INTO fnza_pagare_temp(ci_apo,txt,txt_detalle,cardinal,sostenedor,pie_detalle,agno,folio)" _
            & " SELECT ci_apo,txt,txt_detalle,cardinal,sostenedor,pie_detalle,agno,folio FROM fnza_pagare_historial WHERE ci_apo = '" & text2.Text & "' AND agno = " & Combo1.Text & " and folio = " & Folio & ";"
    conn.Execute var_sql
    
    '' cr_pagare
    '' Form_main.CrystalReport
    Call LimpiaFormulas(cr_pagare, 30)
    cr_pagare.ReportFileName = App.Path & "\Rpt\pagare_corporacion_bc.rpt"
    
    'Format("2009-03-05", "yyyy-mm-dd")
    'cr_pagare.Formulas(3) = "hora = '" & est & "'"
    fecha_pagare = DevuelveCampo("cfg", "", "now()", "1=1", conn)
    
    cr_pagare.Formulas(1) = "fecha = '" & Format(fecha_pagare, "dd-mm-yyyy") & "'"
    cr_pagare.Destination = crptToWindow
    cr_pagare.Action = 1
    Call LimpiaFormulas(cr_pagare, 30)
       
    ' Log finanza
         accion_detalle = "El usuario genero pagare para apoderado " & apoderado
         Call Inserta_Vitacora_Finanza(text2.Text, text2.Text, "Generación de pagare", accion_detalle, 0, 0)
    ' Fin Log
End Sub

Private Sub Command3_Click()
        Dim objRS As ADODB.Recordset
        Set objRS = New ADODB.Recordset
        Dim var_sql As String
        Dim conf, noconf As Integer
        var_sql = "update cfg set valor = 'NO' where param = 'LETRAS'"
        conn.Execute var_sql
      
    var_sql = "delete FROM tmp_contrato WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
    var_sql = "delete FROM tmp_contratocab WHERE ci_apo = '" & text2.Text & "'"
    conn.Execute var_sql
      
'    var_sql = "SELECT * FROM fnza_mensualidad WHERE agno = " & Combo1.Text & " AND run_apo = '" & Text2.Text & "'"
'    objRS.Open var_sql, conn
'    If objRS.RecordCount = 0 Then
'        MsgBox "El apoderado NO registra mensualidades para el año " & Combo1.Text & ", o no esta matriculado para este año.", vbInformation
'        Exit Sub
'    End If
'    objRS.Close
        
      
    var_sql = "select m.ci_alu,confirmado,concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as nombre,IF(fec_mat_r IS NULL,'NO','SI') matricula" _
            & " from apo_x_alu axa,matriculas m,fnza_detalle_mensualidad fdm,postulantes p" _
            & " where axa.agno = m.anno_mat and axa.ci_alu = m.ci_alu and m.ci_alu = p.ci_alu and axa.agno = " & Combo1.Text _
            & " and rut_apo = '" & text2.Text & "' and m.ci_alu = fdm.run_alu and m.anno_mat = fdm.agno" _
            & " group by fdm.run_alu"
    objRS.Open var_sql, conn
      
    
    conf = 0
    noconf = 0
    While Not objRS.EOF
        If objRS("confirmado") = "NO" Or objRS("matricula") = "NO" Then
            noconf = noconf + 1
            MsgBox "El Alumno " & objRS("nombre") & " con Rut. " & objRS("ci_alu") & " no esta confirmado para matricula", vbInformation
        Else
            conf = conf + 1
        End If
        objRS.MoveNext
    Wend
    objRS.Close
    If conf = 0 Then Exit Sub
    
    If conf > 0 And noconf > 0 Then
        MsgBox "En el contrato seran considerados solo los alumnos que esten matriculados", vbInformation
    End If

    Dim QRY As String
    Dim rec As ADODB.Recordset
    
    QRY = "SELECT run_apo FROM fnza_mensualidad WHERE run_apo='" & Trim(text2.Text) & "' AND agno=" & Combo1.Text '& " AND colegio='" & Trim(ImageCombo2.SelectedItem.Key) & "';"
    Set rec = New ADODB.Recordset
    rec.Open QRY, conn
    If rec.RecordCount > 0 Then
        creacontrato Trim(text2.Text), Trim(Combo1.Text), Trim(ImageCombo1.SelectedItem.Key), False, ""
        
    Else
        MsgBox "El apoderado " & Text1.Text & ", no tiene alumnos matriculados para el " & Combo1.Text & " en " & ImageCombo2.SelectedItem.Text, vbInformation, "Sin Alumnos"
    End If
    rec.Close
 
End Sub

'Fin Vars Form
Private Sub Form_Load()
    Flag_sub = True
    LlenaComboAgno
    Flag_sub = False
    LlenaComboFormaPago
    'se agrega 03-08-2022
    ReDim Preserve cuotas(0)
End Sub

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

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

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

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

Private Sub Text2_Change()
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If text2.Text = "" Then Exit Sub

    Dim Str_Query As String
    RC.CursorLocation = adUseClient
    Str_Query = "SELECT DISTINCT fm.run_apo FROM apoderados a, fnza_mensualidad fm WHERE left(a.rut_apo," & Len(text2.Text) & ")='" & text2.Text & "' AND a.rut_apo=fm.run_apo ORDER BY a.rut_apo;"
    RC.Open Str_Query, conn
    List2.Clear
    While Not (RC.EOF)
        List2.AddItem RC("run_apo")
        RC.MoveNext
    Wend
    RC.Close
    List2.Visible = True
    List1.Visible = False
End Sub

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

Private Sub LlenaComboCol()
    Dim QR As String
    Dim RunApo As String
    Dim RC As ADODB.Recordset
    
    Set RC = New ADODB.Recordset
    ImageCombo2.ComboItems.Clear
    RunApo = text2.Text
    QR = "SELECT DISTINCT hc.colegio,hc.nombre FROM hist_cod_colegio hc, fnza_mensualidad fm WHERE fm.run_apo='" & RunApo & "' AND hc.colegio=fm.colegio Order By colegio"
    RC.Open QR, conn
    If RC.RecordCount = 0 Then
        RC.Close
        Exit Sub
    End If
    RC.MoveFirst
    For I = 1 To RC.RecordCount
        ImageCombo2.ComboItems.Add I, RC("colegio"), RC("nombre")
        RC.MoveNext
    Next I
    RC.Close
    Set ImageCombo2.SelectedItem = ImageCombo2.ComboItems.Item(1)
    ImageCombo2.Refresh
End Sub

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

Private Sub LlenaComboFormaPago()
    ImageCombo1.ComboItems.Add 1, "A", "Cuponera"
    ImageCombo1.ComboItems.Add 1, "B", "Contado"
    ImageCombo1.ComboItems.Add 1, "C", "Cheque"
    'ImageCombo1.ComboItems.Add 1, "D", "No determinada"
    Set ImageCombo1.SelectedItem = ImageCombo1.ComboItems.Item("A")
End Sub
