VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form Form_PAT 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Registro de P.A.T."
   ClientHeight    =   3210
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   5580
   Icon            =   "Form_PAT.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   3210
   ScaleWidth      =   5580
   Begin VB.Frame form_PAT 
      Caption         =   "Registro de P.A.T."
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   2895
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5295
      Begin VB.CommandButton cmd_limpiar 
         Caption         =   "Limpiar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3480
         TabIndex        =   20
         Top             =   1800
         Width           =   1575
      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          =   900
         Left            =   1560
         TabIndex        =   19
         Top             =   600
         Visible         =   0   'False
         Width           =   1695
      End
      Begin VB.ComboBox cb_agno 
         BeginProperty Font 
            Name            =   "Arial Narrow"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   1560
         TabIndex        =   18
         Top             =   2520
         Width           =   1695
      End
      Begin VB.CommandButton cmd_salir 
         Caption         =   "Salir"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3480
         TabIndex        =   16
         Top             =   2280
         Width           =   1575
      End
      Begin VB.CommandButton cmd_eliminar 
         Caption         =   "Eliminar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3480
         TabIndex        =   15
         Top             =   1320
         Width           =   1575
      End
      Begin VB.CommandButton cmd_modificar 
         Caption         =   "Modificar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3480
         TabIndex        =   14
         Top             =   840
         Width           =   1575
      End
      Begin VB.CommandButton cmd_agregar 
         Caption         =   "Agregar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3480
         TabIndex        =   13
         Top             =   360
         Width           =   1575
      End
      Begin VB.TextBox txt_monto 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1560
         TabIndex        =   12
         Top             =   2160
         Width           =   1695
      End
      Begin VB.TextBox txt_nro_tarjeta 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1560
         TabIndex        =   10
         Top             =   1800
         Width           =   1695
      End
      Begin MSComCtl2.DTPicker dtp_fec_termino 
         Height          =   285
         Left            =   1560
         TabIndex        =   9
         Top             =   1440
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   503
         _Version        =   393216
         Format          =   39583745
         CurrentDate     =   43804
      End
      Begin MSComCtl2.DTPicker dtp_fec_inicio 
         Height          =   285
         Left            =   1560
         TabIndex        =   8
         Top             =   1080
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   503
         _Version        =   393216
         Format          =   39583745
         CurrentDate     =   43501
      End
      Begin VB.TextBox txt_rut_pat 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1560
         TabIndex        =   7
         Top             =   720
         Width           =   1695
      End
      Begin VB.TextBox txt_rut_apo 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1560
         TabIndex        =   6
         Top             =   360
         Width           =   1695
      End
      Begin VB.Label Label7 
         Caption         =   "Año:"
         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        =   17
         Top             =   2520
         Width           =   735
      End
      Begin VB.Label Label6 
         Caption         =   "Monto:"
         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        =   11
         Top             =   2160
         Width           =   1095
      End
      Begin VB.Label Label5 
         Caption         =   "Nro. Tarjeta:"
         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        =   5
         Top             =   1800
         Width           =   975
      End
      Begin VB.Label Label4 
         Caption         =   "Fecha Termino:"
         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             =   1440
         Width           =   1215
      End
      Begin VB.Label Label3 
         Caption         =   "Fecha Inicio:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   120
         TabIndex        =   3
         Top             =   1080
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "Rut. Titular  P.A.T.:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   120
         TabIndex        =   2
         Top             =   720
         Width           =   1455
      End
      Begin VB.Label Label1 
         Caption         =   "Rut. 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        =   1
         Top             =   360
         Width           =   1335
      End
   End
End
Attribute VB_Name = "Form_PAT"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_agregar_Click()
    Dim accion As String
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    'Reviso que registro no este ingresado
    varsql = "SELECT * FROM fnza_pat WHERE rut_apo = '" & txt_rut_apo.Text & "' AND agno = " & cb_agno.Text
    objRS.Open varsql, conn
    If objRS.RecordCount > 0 Then
        MsgBox "Registro P.A.T para el año " & cb_agno.Text & " para este apoderado ya fue registrado", vbInformation
        objRS.Close
        Exit Sub
    End If
    objRS.Close
    
    If txt_rut_apo.Text = "" Or txt_rut_pat.Text = "" Or (Format(dtp_fec_inicio.Value, "yyyymmdd") > Format(dtp_fec_termino.Value, "yyyymmdd")) Or txt_nro_tarjeta.Text = "" Or txt_monto.Text = "" Then
        MsgBox "Debe ingresar todos los datos", vbInformation
        Exit Sub
    End If
    
    ' Valida Rut
    If Not ValidaRut(txt_rut_pat.Text) Then
        MsgBox "El Rut del P.A.T no es valido", vbInformation
        Exit Sub
    End If
        
    var_sql = "INSERT INTO fnza_pat(rut_apo,rut_pat,monto,fec_inicio,fec_termino,nro_tarjeta,agno,fecha_ingreso,usuario_ingreso)" _
            & " VALUES('" & txt_rut_apo.Text & "','" & txt_rut_pat.Text & "'," & txt_monto.Text _
            & ",'" & Format(dtp_fec_inicio.Value, "yyyy/mm/dd") & "','" & Format(dtp_fec_termino.Value, "yyyy/mm/dd") & "','" & txt_nro_tarjeta.Text & "'," & cb_agno.Text & ",CURDATE(),'" & Nom_com_usu_ses & "');"
    conn.Execute var_sql
    MsgBox "Registro de P.A.T. fue grabado exitosamente", vbInformation
    
    ' Logs P.A.T.
    accion_detalle = "Se ha ingresado P.A.T. al apoderado con Rut " & txt_rut_apo.Text & ", Rut titular Pat " & txt_rut_pat.Text & " para el año " & cb_agno.Text
    accion = "Ingreso de P.A.T."
    Call Inserta_Vitacora_Finanza("11111111-1", txt_rut_apo.Text, accion, CStr(accion_detalle), 0, 0)
        
    cmd_limpiar_Click
    
    'Format(fecha, "dd/mm/yyyy")
End Sub

Private Sub cmd_eliminar_Click()
   Dim var_sql As String
   Dim accion As String
   Dim objRS As ADODB.Recordset
   Set objRS = New ADODB.Recordset
   
   var_sql = "select * from fnza_pat WHERE agno = " & cb_agno.Text & " AND rut_apo = '" & txt_rut_apo.Text & "'"
   objRS.Open var_sql, conn
   If objRS.RecordCount = 0 Then
        objRS.Close
        Exit Sub
   End If
   
   If MsgBox("¿Esta seguro de que desea eliminar los datos?", vbQuestion + vbYesNo) = vbYes Then
        var_sql = "delete from fnza_pat" _
                & " WHERE agno = " & cb_agno.Text & " AND rut_apo = '" & txt_rut_apo.Text & "'"
        conn.Execute var_sql
        MsgBox "Registro de P.A.T. fue eliminado exitosamente", vbInformation
                
        ' Logs P.A.T.
        accion_detalle = "Se ha eliminado el P.A.T. al apoderado con Rut " & txt_rut_apo.Text & ", Rut titular Pat " & txt_rut_pat.Text & " para el año " & cb_agno.Text
        accion = "Eliminación de P.A.T."
        Call Inserta_Vitacora_Finanza("11111111-1", txt_rut_apo.Text, accion, CStr(accion_detalle), 0, 0)
        cmd_limpiar_Click
        
   End If
End Sub

Private Sub cmd_limpiar_Click()
    txt_rut_apo.Text = ""
    txt_rut_pat.Text = ""
    dtp_fec_inicio = "05-02-2019"
    dtp_fec_termino = "05-12-2019"
    txt_nro_tarjeta = ""
    txt_monto = ""
    cb_agno = "2019"
    List1.Clear
    List1.Visible = False
End Sub

Private Sub cmd_modificar_Click()
   Dim var_sql As String
   Dim accion As String
   
   ' Valida Rut
   If txt_rut_pat.Text = "" Then Exit Sub
   
   If Not ValidaRut(txt_rut_pat.Text) Then
       MsgBox "El Rut del P.A.T no es valido", vbInformation
       Exit Sub
   End If
   
   If MsgBox("¿Esta seguro de que desea modificar los datos?", vbQuestion + vbYesNo) = vbYes Then
        var_sql = "UPDATE fnza_pat SET rut_apo = '" & txt_rut_apo.Text & "',rut_pat = '" & txt_rut_pat.Text & "',monto = " & txt_monto.Text & "," _
                & "fec_inicio = '" & Format(dtp_fec_inicio.Value, "yyyy/mm/dd") & "',fec_termino = '" & Format(dtp_fec_termino.Value, "yyyy/mm/dd") & "',nro_tarjeta = '" & txt_nro_tarjeta.Text & "',agno = " & cb_agno.Text _
                & " WHERE agno = " & cb_agno.Text & " AND rut_apo = '" & txt_rut_apo.Text & "'"
        conn.Execute var_sql
        MsgBox "Registro de P.A.T fue modificado exitosamente", vbInformation
               
            ' Logs P.A.T.
        accion_detalle = "Se ha modificado el P.A.T. al apoderado con Rut " & txt_rut_apo.Text & ", Rut titular Pat " & txt_rut_pat.Text & " para el año " & cb_agno.Text
        accion = "Modificación de P.A.T."
        Call Inserta_Vitacora_Finanza("11111111-1", txt_rut_apo.Text, accion, CStr(accion_detalle), 0, 0)
        
        cmd_limpiar_Click
   End If
End Sub

Private Sub cmd_salir_Click()
    Unload Me
End Sub


Private Sub Form_Load()
    For i = 2019 To Anno + 1
        cb_agno.AddItem i
    Next i
    cb_agno.Text = 2019
End Sub

Private Sub List1_DblClick()
    txt_rut_apo.Text = List1.Text
    'lst_Rut.Visible = False
    Dim objRS As ADODB.Recordset
    Dim varsql As String
    varsql = "SELECT ape1_apo,ape2_apo,noms_apo" _
           & " FROM apoderados where rut_apo = '" & txt_rut_apo.Text & "'"

    Set objRS = New ADODB.Recordset
        objRS.Open varsql, conn
    If Not objRS.EOF Then
'        txt_NombreCompleto.Text = objRS("ape1_apo") & " " & objRS("ape2_apo") & " " & objRS("noms_apo")
    End If
    objRS.Close
    
    varsql = "SELECT rut_apo,rut_pat,fec_inicio,fec_termino,nro_tarjeta,monto,agno FROM fnza_pat WHERE rut_apo = '" & txt_rut_apo.Text & "'"
    objRS.Open varsql, conn
    If Not objRS.EOF Then
        txt_rut_pat.Text = objRS("rut_pat")
        dtp_fec_inicio.Value = objRS("fec_inicio")
        dtp_fec_termino.Value = objRS("fec_termino")
        txt_nro_tarjeta.Text = objRS("nro_tarjeta")
        txt_monto.Text = objRS("monto")
        cb_agno.Text = objRS("agno")
    End If
    objRS.Close
    
'    lst_nombre.Visible = False
    List1.Visible = False
    If List1.Text <> "" Then
        txt_rut_apo.Locked = True
       ' txt_NombreCompleto.Locked = True
    End If
    
    'Monto Pat
    varsql = "SELECT SUM(monto_tot_cuota) AS monto_pat FROM fnza_detalle_mensualidad f, apo_x_alu axa,matriculas m" _
           & " Where f.run_alu = axa.ci_alu And f.agno = axa.agno And axa.ci_alu = m.ci_alu And axa.agno = m.anno_mat" _
           & " AND m.confirmado = 'SI' AND m.fec_mat_r IS NOT NULL AND f.agno = 2019 AND axa.rut_apo = '" & txt_rut_apo.Text & "'"
    objRS.Open varsql, conn
    If objRS.RecordCount > 0 Then
        txt_monto.Text = objRS("monto_pat")
    End If
    objRS.Close
    
End Sub

Private Sub txt_rut_apo_Change()
    Dim varsql As String
    Dim objRC As ADODB.Recordset
    Dim rut As Long
    Set objRS = New ADODB.Recordset
    varsql = "SELECT distinct a.rut_apo" _
           & " FROM apoderados a,apo_x_alu axa,matriculas m" _
           & " where a.rut_apo LIKE '" & txt_rut_apo.Text & "%'" _
           & " and a.rut_apo = axa.rut_apo and axa.ci_alu = m.ci_alu and confirmado = 'SI' and fec_mat_r is not null" _
           & " and axa.agno = m.anno_mat and axa.agno = " & cb_agno.Text
    objRS.Open varsql, conn
    List1.Clear
    If Not objRS.EOF And txt_rut_apo.Text <> "" Then
        List1.Visible = True
    End If
    While Not objRS.EOF
        List1.AddItem objRS("rut_apo")
        objRS.MoveNext
    Wend
    objRS.Close
End Sub
