VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Begin VB.Form Form_Imprimir_Contrato_Apoderado_hue 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Imprimir Contrato Educacional y Compromiso de Pago"
   ClientHeight    =   2925
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   8475
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   2925
   ScaleWidth      =   8475
   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          =   1110
      Left            =   6720
      TabIndex        =   11
      TabStop         =   0   'False
      Top             =   720
      Visible         =   0   'False
      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          =   1110
      Left            =   840
      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"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   6720
      Picture         =   "Form_Imprimir_Contrato_Apoderado_hue.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   1920
      Width           =   1575
   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 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         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            =   240
         TabIndex        =   6
         Top             =   240
         Width           =   3255
         _ExtentX        =   5741
         _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 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   720
         TabIndex        =   2
         Top             =   360
         Width           =   5295
      End
      Begin VB.TextBox Text2 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   6600
         TabIndex        =   1
         Top             =   360
         Width           =   1335
      End
      Begin VB.Label Label1 
         Caption         =   "Nombre"
         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        =   4
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label2 
         Caption         =   "Run"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   6120
         TabIndex        =   3
         Top             =   360
         Width           =   375
      End
   End
End
Attribute VB_Name = "Form_Imprimir_Contrato_Apoderado_hue"
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

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 Command3_Click()
        Dim objRS As ADODB.Recordset
        Set objRS = New ADODB.Recordset
        Dim rec As ADODB.Recordset
        Set rec = New ADODB.Recordset
        
        Dim forma_pago As String
        Dim Rut_ALu As String
        Dim accion_detalle As String
        
        Dim var_sql As String
        Dim conf, noconf As Integer
        var_sql = "update cfg set valor = 'NO' where param = 'LETRAS'"
        conn.Execute var_sql
        
        If Combo1.Text = 2022 And Trim(ImageCombo1.SelectedItem.Key) = "C" Then
            MsgBox "No esta permitida la forma de pago P.A.T. para el año 2022"
            Exit Sub
        End If
        
        
    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 m.ci_alu,confirmado,concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as nombre" _
            & " 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" Then
            noconf = noconf + 1
            MsgBox "El Alumno " & objRS("nombre") & " con Rut. " & objRS("ci_alu") & " no esta confirmado para matricula", vbInformation
        Else
            conf = conf + 1
            Rut_ALu = objRS("ci_alu")
        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

    
        ''''''Verifico que cheques esten ingresados para poder realizar matricula.
    var_sql = "SELECT SUM(monto_chq) as mc FROM fnza_cheques_recibidos WHERE run_apo = '" & text2.Text & "' AND agno = " & Combo1.Text
    rec.Open var_sql, conn
    If rec.RecordCount > 0 And Not IsNull(rec("mc")) Then
        monto_cheques = rec("mc")
    Else
        monto_cheques = 0
    End If
    rec.Close
    var_sql = "SELECT SUM(monto_mens) as mm FROM fnza_mensualidad WHERE mes > 2 and run_apo = '" & text2.Text & "' AND agno = " & Combo1.Text
    rec.Open var_sql, conn
    If rec.RecordCount > 0 And Not IsNull(rec("mm")) Then
        monto_mensualidad = rec("mm")
    Else
        monto_mensualidad = 0
    End If
    rec.Close
    forma_pago = DevuelveCampo("matriculas", "", "forma_pago", " ci_alu='" & Rut_ALu & "' AND fec_mat_r IS NOT NULL and anno_mat = " & Combo1.Text, conn)
    If monto_cheques < 1400000 And forma_pago = "Cheque" Then
        MsgBox "NO se puede emitir el contrato, todos los cheques deben estar ingresados al sistema", vbInformation
        Exit Sub
        
    End If
        
'    ' Insertar Log de insercion de matricula.
'    Select Case Codens
'        Case "111"
'            grado = "PG"
'        Case "996"
'            grado = "PK"
'        Case "010"
'            grado = "K"
'        Case "110"
'            grado = "EB"
'        Case "310"
'            grado = "EM"
'    End Select
'        curso = CStr(NumGra) & "º " & grado
'        accion_realizada = "El alumno fue matriculado en " & curso _
'                        & ", para el período " & (val(Grid1.TextMatrix(MyRow, 8)) + 1)
'        log = Inserta_Vitacora_Alumno(Grid1.TextMatrix(Grid1.Row, 2), accion_realizada)
'        ' Fin Log.
                
        ' Log finanza
        accion_detalle = "El usuario para sacar el contrato " & Combo1.Text & " selecciono la forma de pago: " & ImageCombo1.Text
        Call Inserta_Vitacora_Finanza(Rut_ALu, text2.Text, "Forma de Pago Contrato", accion_detalle, 0, 0)
        
        ' Fin Log
    
    Dim QRY As String
    
    
    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
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()
    If Combo1.Text < 2022 Then
        ImageCombo1.ComboItems.Add 1, "A", "Cheques"
    Else
        ImageCombo1.ComboItems.Add 1, "A", "Cuponera"
    End If
    ImageCombo1.ComboItems.Add 1, "B", "Contado"
    ImageCombo1.ComboItems.Add 1, "C", "Tarjeta de credito"
    Set ImageCombo1.SelectedItem = ImageCombo1.ComboItems.Item("A")
End Sub
