VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_Mover_Pago 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Mover Pagos de Mensualidades"
   ClientHeight    =   7230
   ClientLeft      =   1800
   ClientTop       =   1590
   ClientWidth     =   11700
   FillStyle       =   0  'Solid
   Icon            =   "Form_Mover_Pagos.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7230
   ScaleWidth      =   11700
   Begin VB.CommandButton Btn_Cancelar 
      Caption         =   "Cancelar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   9240
      TabIndex        =   20
      Top             =   6600
      Width           =   1575
   End
   Begin VB.CommandButton Btn_MoverBoleta 
      Caption         =   "Mover Boleta"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   9240
      TabIndex        =   19
      Top             =   6000
      Width           =   1575
   End
   Begin VB.Frame Frame5 
      Caption         =   "Boleta(s) a Mover"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1215
      Left            =   8400
      TabIndex        =   17
      Top             =   4560
      Width           =   3135
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid GrillaBlta 
         Height          =   855
         Left            =   120
         TabIndex        =   18
         TabStop         =   0   'False
         Top             =   240
         Width           =   2895
         _ExtentX        =   5106
         _ExtentY        =   1508
         _Version        =   393216
         Cols            =   4
         FixedCols       =   0
         Enabled         =   0   'False
         HighLight       =   0
         FillStyle       =   1
         GridLines       =   0
         GridLinesFixed  =   0
         ScrollBars      =   0
         SelectionMode   =   1
         FormatString    =   "^Folio Bol.|^Fecha Blta.|>Monto|"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _NumberOfBands  =   1
         _Band(0).Cols   =   4
      End
   End
   Begin VB.Frame Frame4 
      Caption         =   "Detalle Mensualidad"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   3375
      Left            =   8400
      TabIndex        =   15
      Top             =   1080
      Width           =   3135
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid GrillaMens 
         Height          =   3015
         Left            =   120
         TabIndex        =   16
         TabStop         =   0   'False
         Top             =   240
         Width           =   2895
         _ExtentX        =   5106
         _ExtentY        =   5318
         _Version        =   393216
         Cols            =   3
         FixedCols       =   0
         Enabled         =   0   'False
         HighLight       =   0
         FillStyle       =   1
         GridLines       =   0
         GridLinesFixed  =   0
         ScrollBars      =   0
         SelectionMode   =   1
         FormatString    =   "^Fecha Venc.|>Monto|^Estado"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _NumberOfBands  =   1
         _Band(0).Cols   =   3
      End
   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          =   1320
      Left            =   840
      TabIndex        =   14
      TabStop         =   0   'False
      Top             =   720
      Width           =   5295
   End
   Begin VB.ListBox List2 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      Left            =   6720
      TabIndex        =   13
      TabStop         =   0   'False
      Top             =   720
      Width           =   1335
   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          =   855
      Left            =   6600
      TabIndex        =   11
      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        =   12
         Top             =   360
         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          =   855
      Left            =   8400
      TabIndex        =   9
      Top             =   120
      Width           =   3135
      Begin MSComctlLib.ImageCombo ImageCombo2 
         Height          =   345
         Left            =   240
         TabIndex        =   6
         Top             =   360
         Width           =   2655
         _ExtentX        =   4683
         _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 Frame3 
      Caption         =   "Detalle de la Mensualidad del Alumno"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   4335
      Left            =   120
      TabIndex        =   8
      Top             =   2760
      Width           =   8175
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid GrillaDtll 
         Height          =   3975
         Left            =   120
         TabIndex        =   10
         Top             =   240
         Width           =   7935
         _ExtentX        =   13996
         _ExtentY        =   7011
         _Version        =   393216
         BackColor       =   16777215
         Cols            =   11
         FixedCols       =   0
         BackColorSel    =   14737632
         ForeColorSel    =   16711680
         AllowBigSelection=   0   'False
         HighLight       =   2
         FillStyle       =   1
         GridLinesUnpopulated=   2
         SelectionMode   =   1
         FormatString    =   "<Folio|<Fecha Venc.|<Concepto|>Cuota|>Exen. Hno.|> Exen. Beca|>Exen. Dscto.|>Exen. Conv.|^Convenio|>Total a Pagar|<Estado"
         RowSizingMode   =   1
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _NumberOfBands  =   1
         _Band(0).Cols   =   11
         _Band(0).TextStyleBand=   0
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Alumno(s)"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1575
      Left            =   120
      TabIndex        =   5
      Top             =   1080
      Width           =   6375
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid Grilla 
         Height          =   1215
         Left            =   120
         TabIndex        =   7
         Top             =   240
         Width           =   6135
         _ExtentX        =   10821
         _ExtentY        =   2143
         _Version        =   393216
         FixedCols       =   0
         BackColorSel    =   14737632
         ForeColorSel    =   16711680
         FocusRect       =   0
         FillStyle       =   1
         GridLines       =   0
         GridLinesFixed  =   1
         GridLinesUnpopulated=   1
         ScrollBars      =   2
         SelectionMode   =   1
         RowSizingMode   =   1
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
         _Band(0).GridLineWidthBand=   1
         _Band(0).TextStyleBand=   0
      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 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        =   4
         Text            =   "Text2"
         Top             =   360
         Width           =   1335
      End
      Begin VB.TextBox Text1 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   720
         TabIndex        =   2
         Text            =   "Text1"
         Top             =   360
         Width           =   5295
      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
      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        =   1
         Top             =   360
         Width           =   855
      End
   End
End
Attribute VB_Name = "Form_Mover_Pago"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Flag_sub As Boolean
Dim colegio As String
Dim RC As ADODB.Recordset
Dim CMD As ADODB.Command
Dim CuotasFix() As Boolean
Dim CuotasPag() As Boolean
Dim CuotasCld() As Boolean
Dim ResetPago As Boolean

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

Private Sub Btn_MoverBoleta_Click()
    Dim AluRow As Integer
    Dim OrigRow As Integer
    Dim DestRow As Integer
    Dim FolioBlta As Long
    Dim CMD As ADODB.Command
    Dim QRY As String
    Dim rec As ADODB.Recordset
    Dim accion_detalle As String
    Dim BolRow As Long
    ' Rutina para mover la boleta
    AluRow = grilla.Row
    
    For I = 1 To UBound(CuotasCld)
        If CuotasCld(I) Then
            BolRow = I
        End If
    Next I
    
    Set rec = New ADODB.Recordset
    
    ' Verifico folio de origen no nulo y no devuelto
    QRY = "SELECT fb.folio_blta FROM fnza_boletas as fb, fnza_dtll_mvto as fdm WHERE fb.tipo_doc='blta' AND fb.folio_blta=fdm.folio_blta AND fdm.folio_dtll=" & val(GrillaDtll.TextMatrix(BolRow, 0)) & " AND fb.estado_blta<>'nula' AND fb.estado_blta<>'devo';"
    rec.Open QRY, conn
    If rec.RecordCount = 0 Then
        MsgBox "No se encontró una boleta de origen válida", vbExclamation, "ANOMALÍA"
        Exit Sub
    Else
        FolioBlta = rec!folio_blta
    End If
    rec.Close
    
    For I = 1 To UBound(CuotasFix)
        If CuotasCld(I) Then OrigRow = I
        If CuotasPag(I) Then DestRow = I
    Next I
    ' Mover los montos abonados
    abonar_detalle val(GrillaDtll.TextMatrix(DestRow, 0)), val(GrillaDtll.TextMatrix(OrigRow, 9)), CDate(GrillaDtll.TextMatrix(OrigRow, 17)), conn
    abonar_detalle val(GrillaDtll.TextMatrix(OrigRow, 0)), (val(GrillaDtll.TextMatrix(OrigRow, 9)) * -1), CDate(Date), conn
    ' Cambiar el detalle de la boleta y el movimiento
    Set CMD = New ADODB.Command
    CMD.ActiveConnection = conn
    CMD.CommandType = adCmdText
    ' En fnza_dtll_mvto
    QRY = "UPDATE fnza_dtll_mvto SET folio_dtll=" & GrillaDtll.TextMatrix(DestRow, 0) & " WHERE folio_dtll=" & GrillaDtll.TextMatrix(OrigRow, 0) & " and folio_blta=" & FolioBlta & ";"
    CMD.CommandText = QRY
    CMD.Execute
    ' En fnza_movimientos_mensualidad
    QRY = "UPDATE fnza_movimientos_mensualidad as fmm, fnza_dtll_mvto as mvto SET fmm.folio_dtll=" & GrillaDtll.TextMatrix(DestRow, 0) & ", fmm.fech_venc_cptos='" & Format(GrillaDtll.TextMatrix(DestRow, 14), "yyyy-mm-dd") & "', fmm.cod_concepto='" & GrillaDtll.TextMatrix(DestRow, 15) & "' WHERE fmm.folio_dtll=" & GrillaDtll.TextMatrix(OrigRow, 0) & " AND fmm.folio_mvto=mvto.folio_mvto and mvto.folio_blta=" & FolioBlta & ";"
    CMD.CommandText = QRY
    CMD.Execute
    
    ' Insertar log
    accion_detalle = "El pago para el mes de " & GrillaDtll.TextMatrix(OrigRow, 1) _
                   & " a sido cambiado para el mes de " & GrillaDtll.TextMatrix(DestRow, 1) _
                   & " del año " & Combo1.Text
    Call Inserta_Vitacora_Finanza(grilla.TextMatrix(grilla.Row, 0), text2.Text, _
                                  "Mover pagos", accion_detalle, 0, 0)
    ' Fin de log
    
    ' Mostrar la nueva información
    Call SeteaGrillaMens
    Call LlenaGrillaMens
    Grilla_Click
End Sub

Private Sub Combo1_Click()
    If Flag_sub Then Exit Sub
    Call ReseteaSeleccionBoleta
    Flag_sub = True
    Call LimpiaComboCol
    Call LlenaComboCol
    Flag_sub = False
    Call SeteaGrillaMens
    Call LlenaGrillaMens
    Call SeteaGrilla
    Call LlenaGrilla
    Call SeteaGrillaDtll
    Call HabilitarBotonMover
End Sub

Private Sub Form_Load()
    ResetPago = False
    Me.Top = 0
    Me.Left = 0
    Flag_sub = True
    Text1.Text = ""
    text2.Text = ""
    Flag_sub = False
    List1.Visible = False
    List2.Visible = False
        
    Call SeteaGrilla
    Call SeteaGrillaDtll
    Call SeteaGrillaMens
    Call SeteaGrillaBlta
    
    Set RC = New ADODB.Recordset
    Frame3.Enabled = False
    Frame2.Enabled = False
    
    Call LlenaComboAgno
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set rs = Nothing
End Sub

Private Sub Grilla_Click()
    Call ReseteaSeleccionBoleta
    Call SeteaGrillaDtll
    Call LlenaGrillaDtll
    Call HabilitarBotonMover
End Sub

Private Sub Grilla_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Call Grilla_Click
    End If
End Sub

Private Sub GrillaDtll_DblClick()
    Dim MyRow As Long
    MyRow = IIf(GrillaDtll.RowSel >= GrillaDtll.Row, GrillaDtll.RowSel, GrillaDtll.Row)
    Call SeleccionaDtll
    Call GrillaDtllSel(MyRow + 1)
    Call HabilitarBotonMover
End Sub

Private Sub GrillaDtll_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Call GrillaDtll_DblClick
    End If
End Sub

Private Sub ImageCombo2_Change()
    If Flag_sub = True Then Exit Sub
    Call SeteaGrillaMens
    Call LlenaGrillaMens
    Call SeteaGrilla
    Call LlenaGrilla
End Sub

Private Sub ImageCombo2_Click()
    If Flag_sub = True Then Exit Sub
    Call SeteaGrillaMens
    Call LlenaGrillaMens
    Call SeteaGrilla
    Call LlenaGrilla
End Sub

Private Sub List1_DblClick()
    
    Text1.Text = List1.Text
    List1.Visible = False
    List2.Visible = False
    RC.CursorLocation = adUseClient
    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 LimpiaComboCol
    Call LlenaComboCol
    Flag_sub = False
    ImageCombo2.Refresh
    Call SeteaGrillaMens
    Call LlenaGrillaMens
    Call SeteaGrilla
    Call LlenaGrilla
    Call SeteaGrillaDtll
    Call LlenaGrillaDtll
    Call HabilitarBotonMover
End Sub

Private Sub List2_DblClick()
    text2.Text = List2.Text
    List2.Visible = False
    List1.Visible = False
    RC.CursorLocation = adUseClient
    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 LimpiaComboCol
    Call LlenaComboCol
    Flag_sub = False
    ImageCombo2.Refresh
    Call SeteaGrillaMens
    Call LlenaGrillaMens
    Call SeteaGrilla
    Call LlenaGrilla
    Call SeteaGrillaDtll
    Call LlenaGrillaDtll
    Call HabilitarBotonMover
End Sub

Private Sub Text1_Change()
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If Text1.Text = "" Then Exit Sub
    
    Frame3.Enabled = False
    Frame2.Enabled = False
    Frame6.Enabled = False
    RC.CursorLocation = adUseClient
    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()
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If text2.Text = "" Then Exit Sub
    
    Frame3.Enabled = False
    Frame2.Enabled = False
    Frame6.Enabled = False
    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 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 LlenaGrilla()
    Dim QR As String
    QR = "SELECT DISTINCT fdm.run_alu, CONCAT(p.ape_pat_alu,' ',p.ape_mat_alu,' ',p.nom_alu) as nombre FROM fnza_mensualidad fm, fnza_detalle_mensualidad fdm, postulantes p WHERE fm.folio_mens=fdm.folio_mens AND fm.run_apo='" & text2.Text & "' AND p.ci_alu=fdm.run_alu AND fdm.colegio='" & ImageCombo2.SelectedItem.Key & "' AND fm.agno=fdm.agno And fdm.agno=" & Combo1.Text & " order by fdm.run_alu"
    RC.Open QR, conn
    If RC.RecordCount = 0 Then
        RC.Close
        Exit Sub
    End If
    For I = 1 To RC.RecordCount
        grilla.AddItem RC("run_alu") & Chr(9) & RC("nombre") & Chr(9) & CursoAlumno(RC("run_alu"), 2005, conn), I
        RC.MoveNext
    Next I
    RC.Close
    Frame2.Enabled = True
    grilla.SetFocus
End Sub

Private Sub LlenaGrillaDtll()
    Dim QR As String
    Dim RunAlu As String
    Dim MyRow As Integer
    
    ReDim CuotasFix(1 To 1)
    'CuotasFix(1) = false
    
    Frame3.Caption = "Detalle de la Mensualidad del Alumno"
    MyRow = grilla.Row
    
    RunAlu = grilla.TextMatrix(MyRow, 0)
    Frame3.Caption = "Detalle de la Mensualidad del Alumno " & grilla.TextMatrix(MyRow, 1)
    
    QR = "SELECT folio_dtll,fech_venc,concepto,monto_total,monto_exen_hno,monto_exen_bca,monto_exen_desc,monto_exen_conv,(monto_exen_hno+monto_exen_bca+monto_exen_desc+monto_exen_conv) as exencion,monto_abono,cod_convenio,monto_tot_cuota, estado_dtll, mes, agno, if(fech_pago='0000-00-00','',fech_pago) as fecha_pago FROM fnza_detalle_mensualidad WHERE run_alu='" & RunAlu & "' AND colegio='" & ImageCombo2.SelectedItem.Key & "' AND agno='" & Combo1.Text & "' ORDER BY concepto,fech_venc"
    RC.Open QR, conn
    If RC.RecordCount = 0 Then
        RC.Close
        Exit Sub
    End If
    RC.MoveFirst
    GrillaDtll.FillStyle = flexFillRepeat
    For I = 1 To RC.RecordCount
        GrillaDtll.AddItem RC("folio_dtll") & Chr(9) & MesATexto(val(RC("mes"))) & Chr(9) & RC("agno") & Chr(9) & RC("monto_total") & Chr(9) & RC("monto_exen_hno") & Chr(9) & RC("monto_exen_bca") & Chr(9) & RC("monto_exen_desc") & Chr(9) & RC("monto_exen_conv") & Chr(9) & RC("exencion") & Chr(9) & RC("monto_abono") & Chr(9) & RC("cod_convenio") & Chr(9) & (val(RC("monto_tot_cuota")) - val(RC("monto_abono"))) & Chr(9) & RC("estado_dtll") & Chr(9) & TraduceEstadoDtll(RC("estado_dtll"), conn) & Chr(9) & RC("fech_venc") & Chr(9) & RC("concepto") & Chr(9) & TraduceConceptoDtll(RC("concepto"), conn) & Chr(9) & RC("fecha_pago"), I
        ReDim Preserve CuotasFix(1 To I)
        If (RC("estado_dtll") = "clda" Or RC("estado_dtll") = "erro") Then
            CuotasFix(I) = True
            'GrillaDtll.CellBackColor = &HC0FFC0
        ElseIf (RC("estado_dtll") = "abon") Then
            CuotasFix(I) = False
            'GrillaDtll.CellBackColor = &HC0FFFF
        ElseIf (RC("estado_dtll") = "cred") Then
            CuotasFix(I) = True
            'GrillaDtll.CellBackColor = &HC0C0FF
        Else
            CuotasFix(I) = False
            'GrillaDtll.CellBackColor = &HFFFFFF
        End If
        GrillaDtllSel I
        ColorGrillaDtll (I)
        RC.MoveNext
    Next I
    ReDim CuotasPag(1 To RC.RecordCount)
    ReDim CuotasCld(1 To RC.RecordCount)
    GrillaDtllSel 1
    GrillaDtll.Refresh
    RC.Close
    Frame3.Enabled = True
    GrillaDtll.SetFocus
End Sub

Private Sub LlenaGrillaMens()
    Dim QR As String
    Dim RunApo As String
    Dim RC As ADODB.Recordset
    
    Set RC = New ADODB.Recordset
    
    RunApo = text2.Text
    
    QR = "SELECT fech_venc, monto_mens, estado_mens FROM fnza_mensualidad WHERE run_apo='" & RunApo & "' AND agno=" & Combo1.Text & " and colegio='" & ImageCombo2.SelectedItem.Key & "' AND estado_mens<>'nula' AND estado_mens<>'reti' AND estado_mens<>'rpto' ORDER BY fech_venc;"
    RC.Open QR, conn
    If RC.RecordCount = 0 Then
        RC.Close
        Exit Sub
    End If
    RC.MoveFirst
    For I = 1 To RC.RecordCount
        GrillaMens.AddItem RC("fech_venc") & Chr(9) & RC("monto_mens") & Chr(9) & RC("estado_mens") & Chr(9) & TraduceEstadoMens(RC("estado_mens"), conn), I
        GrillaMens.Col = 0
        GrillaMens.Row = I
        GrillaMens.RowSel = I
        GrillaMens.ColSel = 3
        If (RC("estado_mens") = "clda") Then
            GrillaMens.CellBackColor = &HC0FFC0
        ElseIf (RC("estado_mens") = "abon") Then
            GrillaMens.CellBackColor = &HC0FFFF
        ElseIf (RC("estado_mens") = "cred") Then
            GrillaMens.CellBackColor = &HC0C0FF
        End If
        RC.MoveNext
    Next I
    RC.Close
End Sub

Private Sub LlenaGrillaBlta(ByVal FolioDtll As Long)
    Dim QRY As String
    Dim rec As ADODB.Recordset
    Dim RunApo As String
    Dim RunAlu As String
    
    RunAlu = grilla.TextMatrix(grilla.Row, 0)
    RunApo = text2.Text
    
    QRY = "SELECT fb.* FROM fnza_boletas as fb, fnza_dtll_mvto as fdm WHERE fb.tipo_doc='blta' AND fb.folio_blta=fdm.folio_blta AND fdm.folio_dtll=" & FolioDtll & " AND fb.estado_blta<>'nula' AND fb.estado_blta<>'devo';"
    Set rec = New ADODB.Recordset
    rec.Open QRY, conn
    
    If rec.RecordCount > 0 Then
        For I = 1 To rec.RecordCount
            GrillaBlta.AddItem rec("folio_blta_fisico") & Chr(9) & rec("fecha_pago") & Chr(9) & rec("monto_blta") & Chr(9) & rec("folio_blta"), I
        Next I
    End If
    rec.Close
End Sub

Private Sub LimpiaComboCol()
    ImageCombo2.ComboItems.Clear
End Sub

Private Sub LlenaComboCol()
    Dim QR As String
    Dim RunApo As String
    
    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
    Frame6.Enabled = True
    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)
End Sub

Private Sub SeteaGrillaDtll()
    Frame3.Caption = "Detalle de la Mensualidad del Alumno"
    GrillaDtll.ClearStructure
    GrillaDtll.Rows = 2
    GrillaDtll.FormatString = "<Folio|<Mes|^Año|>Cuota|>Exen. Hno|> Exen. Beca|>Exen. Dscto.|>Exen. Conv.|>Total Exen.|>Abonado|^Convenio|>Total a Pagar|^Cod Estado|^Estado|<Fecha Venc.|^Cod Concepto|<Concepto|<Fecha Abono"
    GrillaDtll.ColWidth(0) = 0      ' folio
    GrillaDtll.ColWidth(1) = 1000   '  Mes en palabras
    GrillaDtll.ColWidth(2) = 500   ' Año
    GrillaDtll.ColWidth(3) = 1000   ' Cuota
    GrillaDtll.ColWidth(4) = 0    ' Exen Hno
    GrillaDtll.ColWidth(5) = 0    ' Exen Bca
    GrillaDtll.ColWidth(6) = 0    ' Exen Dscto.
    GrillaDtll.ColWidth(7) = 0    ' Exen Conv.
    GrillaDtll.ColWidth(8) = 1000 ' Exento total
    GrillaDtll.ColWidth(9) = 1000   ' monto abonado
    GrillaDtll.ColWidth(10) = 0      ' convenio
    GrillaDtll.ColWidth(11) = 1000   ' Total
    GrillaDtll.ColWidth(12) = 0   ' Cod Estado
    GrillaDtll.ColWidth(13) = 1000 ' Descrip Estado
    GrillaDtll.ColWidth(14) = 0  ' FechVenc
    GrillaDtll.ColWidth(15) = 0 ' cod Concepto
    GrillaDtll.ColWidth(16) = 1100  ' Descrip Concepto
    GrillaDtll.ColWidth(17) = 0 'fecha abono
    
End Sub

Private Sub SeteaGrilla()
    grilla.ClearStructure
    grilla.Rows = 2
    grilla.FormatString = "<RUN|<Nombre|<Curso"
    grilla.ColWidth(0) = 1200
    grilla.ColWidth(1) = 4100
    grilla.ColWidth(2) = 1000
End Sub

Private Sub SeteaGrillaMens()
    GrillaMens.ClearStructure
    GrillaMens.Rows = 2
    GrillaMens.FormatString = "^Fecha Venc.|^Monto|^Cod Estado|^Estado"
    GrillaMens.ColWidth(0) = 1000 ' Fecha Venc
    GrillaMens.ColWidth(1) = 850  ' Monto
    GrillaMens.ColWidth(2) = 0   ' Cod Estado
    GrillaMens.ColWidth(3) = 1000 ' Descrip Estado
End Sub

Private Sub SeteaGrillaBlta()
    GrillaBlta.ClearStructure
    GrillaBlta.Rows = 2
    GrillaBlta.FormatString = "^Folio|^Fecha Blta.|^Monto|^Folio Interno"
    GrillaBlta.ColWidth(0) = 750 ' Folio Fisico
    GrillaBlta.ColWidth(1) = 950 ' Fecha Blta
    GrillaBlta.ColWidth(2) = 850  ' Monto
    GrillaBlta.ColWidth(3) = 0   ' Folio Interno Estado
End Sub

Private Sub EditarGrillaDtll()
    Dim MySelAlu As Integer
    Dim MySelMen As Integer
    Dim nombre As String
    Dim Concepto As String
    Dim Fecha As Date
    Dim QR As String
        
    MySelAlu = grilla.Row
    MySelMen = GrillaDtll.Row
    
    Label4.Caption = "Alumno: " & grilla.TextMatrix(MySelAlu, 1)
    Label5.Caption = "Concepto: " & GrillaDtll.TextMatrix(MySelMen, 2)
    Label3.Caption = "Fecha Vencimiento " & GrillaDtll.TextMatrix(MySelMen, 1)
    Text3.Text = GrillaDtll.TextMatrix(MySelMen, 3)
    Text4.Text = GrillaDtll.TextMatrix(MySelMen, 4)
    Text5.Text = GrillaDtll.TextMatrix(MySelMen, 5)
    Text6.Text = GrillaDtll.TextMatrix(MySelMen, 6)
    Text7.Text = GrillaDtll.TextMatrix(MySelMen, 7)
    
    QR = "SELECT Distinct fc.cod_convenio, fc.descripcion FROM fnza_convenios fc, fnza_detalle_mensualidad fdm WHERE fc.colegio=fdm.colegio AND fc.colegio='" & ImageCombo2.SelectedItem.Key & "' AND fdm.estado_dtll<>'nula' AND fdm.estado_dtll<>'reti' AND fdm.estado_dtll<>'rpto' GROUP BY cod_convenio;"
    RC.Open QR, conn
    
    ImageCombo1.ComboItems.Clear
    If RC.RecordCount = 0 Then
        ImageCombo1.ComboItems.Add 1, "none", "Ninguno"
        ImageCombo1.ComboItems.Add 2, "pend", "Pendiente"
    Else
        ImageCombo1.ComboItems.Add 1, "pend", "Pendiente"
        RC.MoveFirst
        For I = 1 To RC.RecordCount
            ImageCombo1.ComboItems.Add I + 1, RC("cod_convenio"), RC("descripcion")
            RC.MoveNext
        Next I
        RC.Close
    End If
    Set ImageCombo1.SelectedItem = ImageCombo1.ComboItems.Item(GrillaDtll.TextMatrix(MySelMen, 8))
    
    Frame1.Enabled = False
    Frame2.Enabled = False
    Frame3.Enabled = False
    Frame4.Enabled = False
    Frame6.Enabled = False
    Frame5.Visible = True
End Sub

Private Sub SeleccionaDtll()
    Dim MyRowIni As Integer
    Dim MyRowFin As Integer
    Dim QRY As String
    Dim rec As ADODB.Recordset
    
    MyRowIni = IIf(GrillaDtll.Row <= GrillaDtll.RowSel, GrillaDtll.Row, GrillaDtll.RowSel)
    MyRowFin = IIf(GrillaDtll.Row <= GrillaDtll.RowSel, GrillaDtll.RowSel, GrillaDtll.Row)
    
    If UBound(CuotasFix) < MyRowFin Then Exit Sub
    
    If Not (CuotasPag(MyRowFin)) And Not (CuotasCld(MyRowFin)) Then
            If Not CuotasFix(MyRowFin) Then
                'Revisar si ya esta seleccionada otra para el movimiento.
                For I = 1 To UBound(CuotasPag)
                    If CuotasPag(I) Then Exit Sub
                Next I
                GrillaDtllSel MyRowFin
                GrillaDtll.CellBackColor = &HC0E0FF
                CuotasPag(MyRowFin) = True
            Else
                For I = 1 To UBound(CuotasPag)
                    If CuotasCld(I) Then Exit Sub
                Next I
                ' Llenar info de Boletas de la mensualidad
                Call SeteaGrillaBlta
                LlenaGrillaBlta GrillaDtll.TextMatrix(MyRowFin, 0)
                GrillaDtllSel MyRowFin
                GrillaDtll.CellBackColor = &H0
                GrillaDtll.CellForeColor = &HC0E0FF
                CuotasCld(MyRowFin) = True
            End If
    Else
            If Not CuotasFix(MyRowFin) Then
                GrillaDtllSel MyRowFin
                Call ColorGrillaDtll(MyRowFin)
                CuotasPag(MyRowFin) = False
            ElseIf CuotasCld(MyRowFin) Then
                GrillaDtllSel MyRowFin
                Call ColorGrillaDtll(MyRowFin)
                CuotasCld(MyRowFin) = False
            End If
    End If
End Sub

Function ColorGrillaDtll(ByVal MyRow) As Boolean
    If (GrillaDtll.TextMatrix(MyRow, 12) = "clda") Then
        GrillaDtll.CellBackColor = &HC0FFC0
    ElseIf (GrillaDtll.TextMatrix(MyRow, 12) = "abon") Then
        GrillaDtll.CellBackColor = &HC0FFFF
    ElseIf (GrillaDtll.TextMatrix(MyRow, 12) = "cred") Then
        GrillaDtll.CellBackColor = &HC0C0FF
    Else
        GrillaDtll.CellBackColor = &HFFFFFF
    End If
    GrillaDtll.CellForeColor = &H0
End Function

Function GrillaDtllSel(ByVal MyRow As Long) As Boolean
    GrillaDtllSel = False
    If (UBound(CuotasFix) + 1) < MyRow Then Exit Function
    GrillaDtll.Col = 0
    GrillaDtll.Row = MyRow
    GrillaDtll.RowSel = MyRow
    GrillaDtll.ColSel = 16
    GrillaDtllSel = True
End Function

Private Sub ReseteaSeleccionBoleta()
    ReDim CuotasFix(1 To 1)
    ReDim CuotasPag(1 To 1)
    ReDim CuotasCld(1 To 1)
    CuotasFix(1) = False
    CuotasPag(1) = False
    CuotasCld(1) = False
End Sub

Private Sub HabilitarBotonMover()
    For I = 1 To UBound(CuotasCld)
        If CuotasCld(I) Then
            For j = 1 To UBound(CuotasPag)
                If CuotasPag(j) Then
                    Btn_MoverBoleta.Enabled = True
                    Exit Sub
                End If
            Next j
            Exit For
        End If
    Next I
    Btn_MoverBoleta.Enabled = False
End Sub

Function CursoAlumno(ByVal RunAlu As String, ByVal agno As Integer, CNX As ADODB.Connection) As String
On Error GoTo Controlerror:
    Dim RC As ADODB.Recordset
    Dim QR As String
    Dim Ens As String
    Dim gra As String
    Dim Codens As Integer
    
    CursoAlumno = ""
    QR = "SELECT ce.cod_des,m.cod_ens,m.num_gra FROM matriculas m, codigos_ensenanza ce WHERE m.cod_ens=ce.cod_ens AND m.ci_alu='" & RunAlu & "' AND m.anno_mat='" & agno & "' ORDER BY m.fec_mat DESC LIMIT 1;"
    Set RC = New ADODB.Recordset
    RC.Open QR, CNX
    If RC.RecordCount = 0 Then
        CursoAlumno = "" '"No encontrado"
    Else
        RC.MoveFirst
        Codens = val(RC!Cod_Ens)
        Ens = RC!cod_des
        gra = RC!Num_Gra
        If Not (Codens = 996) Then
            CursoAlumno = gra & " " & Ens
        Else
            CursoAlumno = Ens
        End If
        RC.Close
        QR = "SELECT let_cur FROM alu_x_cur WHERE ci_alu='" & RunAlu & "' AND DATE_FORMAT(fec_mat,'%Y')='" & agno & "' AND fec_cam='1111-11-11' LIMIT 1;"
        RC.Open QR, CNX
        If RC.RecordCount = 0 Then
            RC.Close
            Set RC = Nothing
            Exit Function
        End If
        If (Codens = 996) Or (Codens = 10) Then
            CursoAlumno = Ens & " " & RC!Let_Cur
        Else
            CursoAlumno = gra & "º " & RC!Let_Cur & " " & Ens
        End If
    End If
    RC.Close
    Set RC = Nothing
    
    Exit Function
Controlerror:
    Set RC = Nothing
    Err.Raise Err.Number, Err.Source, Err.Description
End Function

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