VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{F39CBE5C-2D1B-11D6-8D4A-0050043A2E60}#2.0#0"; "ProgBarProzent.ocx"
Begin VB.Form Form_Informes2Fnza 
   ClientHeight    =   7380
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9585
   Icon            =   "Form_Informes2Fnza.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   7380
   ScaleWidth      =   9585
   Begin VB.Frame Frame_cobranza 
      Caption         =   "Impresión de Cartas de Cobranza"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   7095
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   9255
      Begin VB.CommandButton Btn_impri_list 
         Caption         =   "Imprimir Listado"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   6120
         TabIndex        =   42
         Top             =   6600
         Width           =   1455
      End
      Begin VB.Frame Frame_Cartas 
         Height          =   3855
         Left            =   0
         TabIndex        =   31
         Top             =   0
         Visible         =   0   'False
         Width           =   4335
         Begin VB.ComboBox Cmb_Tipo_Cartas 
            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        =   39
            Top             =   480
            Width           =   2415
         End
         Begin VB.CommandButton Btn_Aplica_Tipo 
            Caption         =   "Aplicar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   2760
            TabIndex        =   38
            Top             =   240
            Width           =   1455
         End
         Begin VB.CommandButton Btn_Cancela_Tipo 
            Caption         =   "Cancelar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   2760
            TabIndex        =   37
            Top             =   720
            Width           =   1455
         End
         Begin VB.CheckBox Chk_TodosCartas 
            Caption         =   "Todos los apoderados"
            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        =   36
            Top             =   840
            Width           =   2055
         End
         Begin VB.TextBox Txt_TextoCarta 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   1455
            Left            =   120
            Locked          =   -1  'True
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   35
            Top             =   1560
            Width           =   4095
         End
         Begin VB.TextBox txt_tit_carta 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   120
            Locked          =   -1  'True
            TabIndex        =   34
            Top             =   1200
            Width           =   4095
         End
         Begin VB.TextBox Txt_Pie_Carta 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   120
            Locked          =   -1  'True
            TabIndex        =   33
            Top             =   3120
            Width           =   4095
         End
         Begin VB.TextBox txt_cuotas_mora 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   1680
            Locked          =   -1  'True
            TabIndex        =   32
            Top             =   3480
            Width           =   495
         End
         Begin VB.Label Label9 
            Caption         =   "Tipo de Carta "
            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        =   41
            Top             =   240
            Width           =   2295
         End
         Begin VB.Label Label5 
            Caption         =   "Nº Cuotas en Mora"
            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        =   40
            Top             =   3480
            Width           =   1455
         End
      End
      Begin VB.TextBox Txt_NCartas 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1920
         Locked          =   -1  'True
         TabIndex        =   30
         Top             =   6600
         Width           =   855
      End
      Begin VB.CommandButton btn_can_cob 
         Caption         =   "Cancelar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7200
         TabIndex        =   19
         Top             =   2280
         Width           =   1455
      End
      Begin VB.CommandButton btn_impri_cartas 
         Caption         =   "Imprimir Cartas"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7680
         TabIndex        =   18
         Top             =   6600
         Width           =   1455
      End
      Begin VB.Frame Frame3 
         Height          =   615
         Left            =   120
         TabIndex        =   3
         Top             =   240
         Width           =   3015
         Begin VB.OptionButton opt_indiv_gral 
            Caption         =   "Individual"
            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          =   255
            Index           =   0
            Left            =   1680
            TabIndex        =   5
            Top             =   240
            Width           =   1215
         End
         Begin VB.OptionButton opt_indiv_gral 
            Caption         =   "Por Curso"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   1
            Left            =   120
            TabIndex        =   4
            Top             =   240
            Width           =   1215
         End
      End
      Begin VB.Frame Frame_TipoPAgo 
         Caption         =   "Selección tipos de carta"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   3135
         Left            =   120
         TabIndex        =   1
         Top             =   3360
         Width           =   9015
         Begin MSFlexGridLib.MSFlexGrid Grd_Apod_Cob 
            Height          =   2775
            Left            =   120
            TabIndex        =   2
            Top             =   240
            Width           =   8775
            _ExtentX        =   15478
            _ExtentY        =   4895
            _Version        =   393216
         End
      End
      Begin ProgBarProzent.ProgBar Prgbar_Cob 
         Height          =   375
         Left            =   120
         TabIndex        =   7
         Top             =   2880
         Width           =   9015
         _ExtentX        =   15901
         _ExtentY        =   661
      End
      Begin VB.Frame Frame2 
         Caption         =   "Mes de Referencia"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1095
         Left            =   120
         TabIndex        =   6
         Top             =   960
         Width           =   3015
         Begin VB.CheckBox Chk_IncluyeMes 
            Caption         =   "Incluir este Mes"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   195
            Left            =   120
            TabIndex        =   23
            Top             =   800
            Width           =   2415
         End
         Begin VB.ComboBox Cmb_mes_ref 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            ItemData        =   "Form_Informes2Fnza.frx":2A8B2
            Left            =   120
            List            =   "Form_Informes2Fnza.frx":2A8DA
            Style           =   2  'Dropdown List
            TabIndex        =   20
            Top             =   360
            Width           =   2655
         End
      End
      Begin VB.Frame Frame_general 
         Height          =   1815
         Left            =   3240
         TabIndex        =   8
         Top             =   240
         Width           =   5895
         Begin VB.CheckBox chk_todos_cob 
            Caption         =   "Todos los cursos"
            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             =   1320
            Width           =   1575
         End
         Begin VB.ListBox lst_cursosinf 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   1020
            Left            =   3600
            Style           =   1  'Checkbox
            TabIndex        =   10
            Top             =   480
            Width           =   2175
         End
         Begin VB.ComboBox cmb_mod_cob 
            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
            TabIndex        =   9
            Top             =   480
            Width           =   3255
         End
         Begin VB.Label Label6 
            Caption         =   "Cursos"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   3600
            TabIndex        =   13
            Top             =   240
            Width           =   615
         End
         Begin VB.Label Label7 
            Caption         =   "Tipo de Enseñanza"
            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        =   12
            Top             =   240
            Width           =   1695
         End
      End
      Begin VB.Frame Frame_individual 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   1815
         Left            =   3240
         TabIndex        =   14
         Top             =   240
         Width           =   5055
         Begin VB.TextBox txt_apo_alu 
            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          =   285
            Left            =   960
            TabIndex        =   17
            Top             =   1080
            Width           =   3855
         End
         Begin VB.CommandButton btn_otro_alu 
            Caption         =   "Otro Apoderado"
            Height          =   375
            Left            =   3480
            TabIndex        =   16
            Top             =   1800
            Width           =   1455
         End
         Begin VB.TextBox txt_rut_apo 
            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          =   285
            Left            =   960
            TabIndex        =   15
            Top             =   720
            Width           =   1455
         End
      End
      Begin VB.Frame Frame_Generacion 
         Caption         =   "Generación de Cartas"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   615
         Left            =   120
         TabIndex        =   21
         Top             =   2160
         Width           =   6615
         Begin VB.CommandButton Btn_Generar_Cartas 
            Caption         =   "Generar Cartas"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   4920
            TabIndex        =   25
            Top             =   170
            Width           =   1575
         End
         Begin VB.OptionButton Opt_Forma_Asignacion 
            Caption         =   "Tipo Carta Forma Manual"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   1
            Left            =   2640
            TabIndex        =   24
            Top             =   240
            Width           =   2175
         End
         Begin VB.OptionButton Opt_Forma_Asignacion 
            Caption         =   "Tipo Carta Forma Automática"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   0
            Left            =   120
            TabIndex        =   22
            Top             =   240
            Width           =   2775
         End
      End
      Begin VB.Frame Frame_destino 
         Height          =   495
         Left            =   2880
         TabIndex        =   26
         Top             =   6480
         Width           =   2940
         Begin VB.OptionButton Opt_destino 
            Caption         =   "Pantalla"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   1
            Left            =   1560
            TabIndex        =   28
            Top             =   180
            Width           =   975
         End
         Begin VB.OptionButton Opt_destino 
            Caption         =   "Impresora"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Index           =   0
            Left            =   120
            TabIndex        =   27
            Top             =   180
            Width           =   1215
         End
      End
      Begin VB.Label Label8 
         Caption         =   "Cartas Disponibles"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   29
         Top             =   6600
         Width           =   1695
      End
   End
End
Attribute VB_Name = "Form_Informes2Fnza"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Variables de edición de mensualidades
Dim Grupo() As String
Dim Inigdeuda As Long, Fingdeuda As Long
Dim MesIniDeuda As Integer, MesFindeuda As Integer
Dim CodConvBci As String, CuotasPagadas As Long
Dim Tipobus As Integer ' Tipo de búsqueda 0 => Apoderado o 1 => Alumno
Dim NaluMat As Integer, NaluPos As Integer, FilaAlu As Long, FilaCuota As Long
Dim GeneraAnualidad As Boolean
'Dim PrimeraCarga As Boolean
Dim RutApoCaja As String, Rutalu As String
Dim Ncuotas As Integer
'*****************************************
Dim Acartas() As String, NPosiblesCartas As Integer
Dim SelCursos As String
Dim Anuevocurso()
Dim MarcaAlumno As Boolean
Dim ARutBus() As String, FilaDeuda As Long, FilaUlt As Long, FilaUltapo As Long
Dim fila As Long, FilaCob As Long
Dim Busqueda As Integer, ValorAntiguo As Long
Dim RutApo As String, MesReferencia As String
Sub CartaAutom(t As Long) ' T es la Fila
Set RsFuncion = New ADODB.Recordset
RsFuncion.CursorLocation = adUseClient
RsFuncion.Open "select * from comunicados where cuotas_mora =" & CInt(Me.Grd_Apod_Cob.TextMatrix(fila, 7)), conn
If RsFuncion.RecordCount > 0 Then
    RsFuncion.MoveFirst
    Me.Grd_Apod_Cob.TextMatrix(t, 8) = RsFuncion!descripcion
    Me.Grd_Apod_Cob.TextMatrix(t, 9) = RsFuncion!Titulo
    'Me.Grd_Apod_Cob.TextMatrix(T, 10) = FillconStr(RsFuncion!cuerpo, 800, "L", "DER") & "."
    Me.Grd_Apod_Cob.TextMatrix(t, 10) = RsFuncion!cuerpo
    Me.Grd_Apod_Cob.TextMatrix(t, 11) = RsFuncion!pie
End If
RsFuncion.Close
Set RsFuncion = Nothing
End Sub
Function CuotasenMora(RutApo As String, NMes As Integer, IncluirMes As Boolean) As Integer
Dim Operador As String, CuotaImp As Integer
Set RsAux = New ADODB.Recordset: Set rsER = New ADODB.Recordset
RsAux.CursorLocation = adUseClient: rsER.CursorLocation = adUseClient
CuotaImp = 0
Operador = IIf(IncluirMes, "<=", "<")
RsAux.Open "select * from anualidad_x_apo where rut_apo='" & RutApo & "' and month(fecha_venc) " & Operador & " " & NMes, conn
If RsAux.RecordCount > 0 Then
    For t = 0 To RsAux.RecordCount - 1
        rsER.Open "select sum(monto) from pagos where rut_apo='" & RutApo & "' and id_cuota = " & RsAux!id_cuota, conn
        If rsER.RecordCount > 0 Then
            Pagado = IIf(IsNull(rsER(0)), 0, rsER(0))
            If Pagado < RsAux!Monto Then
                CuotaImp = CuotaImp + 1
            End If
        End If
        rsER.Close
        RsAux.MoveNext
    Next t
End If
CuotasenMora = CuotaImp
RsAux.Close
Set RsAux = Nothing: Set rsER = Nothing
End Function
Sub ArmaCursos()
Dim Ngrado As String, Letra As String, modalidad As String, Con As Integer
Con = 0
SelCursos = ""
If Me.lst_cursosinf.SelCount > 0 And Me.cmb_mod_cob.Text <> "" Then
    modalidad = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.cmb_mod_cob.Text & "'", conn)
    For t = 0 To Me.lst_cursosinf.ListCount - 1
        If Me.lst_cursosinf.Selected(t) Then
            Con = t
        End If
    Next t
    For t = 0 To Me.lst_cursosinf.ListCount - 1
        If Me.lst_cursosinf.Selected(t) Then
            Ngrado = Anuevocurso(t, 1)
            Letra = Anuevocurso(t, 2)
            If t = Con Then
                SelCursos = SelCursos & "(ac.num_gra  = '" & Ngrado & "' and ac.let_cur = '" & Letra & "' and ac.cod_ens ='" & modalidad & "')"
            Else
                SelCursos = SelCursos & "(ac.num_gra  = '" & Ngrado & "' and ac.let_cur = '" & Letra & "' and ac.cod_ens ='" & modalidad & "')" & " or "
            End If
        End If
    Next
    SelCursos = "and (" & SelCursos & ")"
End If
End Sub
Sub IniGrillaLista()
Me.Grd_Apod_Cob.Clear
Me.Grd_Apod_Cob.Rows = 10
Me.Grd_Apod_Cob.Cols = 12
Me.Grd_Apod_Cob.FixedCols = 0
Me.Grd_Apod_Cob.FixedRows = 1
                              '   0      1          2             3               4       5        6        7        8        9   10      11
Me.Grd_Apod_Cob.FormatString = "Item |Curso  |Rut Apoderado|Nombre apoderado |A Pagar | Pagado | Deuda |Impagas|Tipo Carta|Titulo|Cuerpo|Pie"
Me.Grd_Apod_Cob.ColWidth(0) = 400
Me.Grd_Apod_Cob.ColWidth(1) = 700
Me.Grd_Apod_Cob.ColWidth(2) = 500 '  0 Rut, no debe verse
Me.Grd_Apod_Cob.ColWidth(3) = 3200
Me.Grd_Apod_Cob.ColWidth(4) = 700
Me.Grd_Apod_Cob.ColWidth(5) = 700
Me.Grd_Apod_Cob.ColWidth(6) = 700
Me.Grd_Apod_Cob.ColWidth(7) = 700
Me.Grd_Apod_Cob.ColWidth(8) = 1200 ' Tipo Carta
Me.Grd_Apod_Cob.ColWidth(9) = 500 ' 0Parte de la Carta
Me.Grd_Apod_Cob.ColWidth(10) = 500 ' 0Parte de la Carta
Me.Grd_Apod_Cob.ColWidth(11) = 500 ' 0Parte de la Carta
'Me.Grd_Apod_Cob.ColWidth(12) = 0 ' Indica si es el hermano mayor o no
End Sub
Sub OcultaFrames()
Me.Frame_cobranza.Visible = False
End Sub
Private Sub Btn_Aplica_Tipo_Click()
If Me.Cmb_Tipo_Cartas.ListIndex >= 0 Then
    Dim Fini As Long, Ffin As Long, TipoC As String
    'TipoC = Me.Cmb_Tipo_Cartas.Text
    Me.Frame_Cartas.Visible = False: Me.Frame_cobranza.Enabled = True
    If Me.Chk_TodosCartas.Value = 1 Then
        Fini = 1: Ffin = fila
    Else
        Fini = FilaCob: Ffin = FilaCob
    End If
        For t = Fini To Ffin
            Me.Grd_Apod_Cob.TextMatrix(t, 8) = Me.Cmb_Tipo_Cartas
            Me.Grd_Apod_Cob.TextMatrix(t, 9) = Me.txt_tit_carta
            Me.Grd_Apod_Cob.TextMatrix(t, 10) = Me.Txt_TextoCarta
            Me.Grd_Apod_Cob.TextMatrix(t, 11) = Me.Txt_Pie_Carta
            Me.Grd_Apod_Cob.Refresh
        Next t
Else
    MsgBox ("Seleccione Tipo de Carta")
End If
End Sub

Private Sub Btn_Can_Cob_Click()
Unload Me
End Sub

Private Sub Btn_Cancela_Tipo_Click()
Me.Frame_Cartas.Visible = False
Me.Frame_cobranza.Enabled = True
End Sub

Private Sub Btn_Generar_Cartas_Click()
Dim LoqueDebe As Long, Pagado As Long, Mayor As Boolean
If Me.Cmb_mes_ref.ListIndex >= 0 And Me.lst_cursosinf.SelCount > 0 And Len(Trim(Me.cmb_mod_cob)) > 0 Then
    Mes = Me.Cmb_mes_ref.ItemData(Me.Cmb_mes_ref.ListIndex)
    'Me.Frame_cobranza.Height = "6975"
    'Me.Height = "7470"
    'Me.Refresh
    Call IniGrillaLista
    Abarra = 0
    Me.Prgbar_Cob.ShowProgress 0
    Me.Prgbar_Cob.Zusatztext = "% Terminado"
    Call ArmaCursos
    If Me.Chk_IncluyeMes.Value Then
        Operador = "<="
        MesReferencia = Me.Cmb_mes_ref.Text
    Else
        Operador = "<"
        MesReferencia = IIf(Me.Cmb_mes_ref.ListIndex > 0, Me.Cmb_mes_ref.ListIndex - 1, Me.Cmb_mes_ref.Text)
    End If
    'Operador = IIf(Me.Chk_IncluyeMes.Value, "<=", "<")
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
        'rs.Open "select ap.ci_alu, ac.num_gra, ac.let_cur, co.cod_des, a.rut_apo, a.noms_apo, a.ape1_apo, a.ape2_apo, sum(d.monto) from anualidad_x_apo d, apoderados a, apo_x_alu ap, alu_x_cur ac , matriculas m, codigos_ensenanza co where d.rut_apo=a.rut_apo and a.rut_apo = ap.rut_apo and ap.ci_alu= m.ci_alu and m.ci_alu = ac.ci_alu and (ac.activo_alu = m.activo_alu or (ac.activo_alu <> m.activo_alu and ac.fec_cam <>'1111-11-11')) AND m.fec_mat=ac.fec_mat and ac.cod_ens=co.cod_ens and m.ind_beca='0' " & SelCursos & " and month(d.fecha_venc) " & Operador & " '" & Mes & "' group by a.rut_apo order by ac.cod_ens, ac.num_gra, ac.let_cur, a.ape1_apo, a.ape2_apo, a.noms_apo", conn
        rs.Open "select ap.ci_alu, ac.num_gra, ac.let_cur, co.cod_des, a.rut_apo, a.noms_apo, a.ape1_apo, a.ape2_apo from apoderados a, apo_x_alu ap, alu_x_cur ac , matriculas m, codigos_ensenanza co where a.rut_apo = ap.rut_apo and ap.ci_alu= m.ci_alu and m.ci_alu = ac.ci_alu and (ac.activo_alu = m.activo_alu or (ac.activo_alu <> m.activo_alu and ac.fec_cam <>'1111-11-11')) AND m.fec_mat=ac.fec_mat and ac.cod_ens=co.cod_ens and m.ind_beca='0' " & SelCursos & " group by a.rut_apo order by ac.cod_ens, ac.num_gra, ac.let_cur, a.ape1_apo, a.ape2_apo, a.noms_apo", conn
    ' Esta consulta trae lo mismo anteriormente mas los alumnos
    ' select po.ci_alu, po.ape_pat_alu, po.ape_mat_alu, a.rut_apo, a.noms_apo, a.ape1_apo, a.ape2_apo, sum(d.monto) from anualidad_x_apo d, apoderados a, apo_x_alu ap, alu_x_cur ac , matriculas m, postulantes po where d.rut_apo=a.rut_apo and a.rut_apo = ap.rut_apo and ap.ci_alu= m.ci_alu and m.ci_alu = ac.ci_alu and (ac.activo_alu = m.activo_alu or (ac.activo_alu <> m.activo_alu and ac.fec_cam <>'1111-11-11')) AND m.fec_mat=ac.fec_mat and m.ind_beca='0' and ((ac.num_gra  = '6' and ac.let_cur = 'A' and ac.cod_ens ='110')) and ac.ci_alu=po.ci_alu group by a.rut_apo order by ac.cod_ens, ac.num_gra, ac.let_cur, po.ape_pat_alu, po.ape_mat_alu, ac.fec_ing_curso
    Me.Prgbar_Cob.MaxValue = rs.RecordCount
    fila = 0: c = 0: Me.Txt_NCartas = 0
    If rs.RecordCount > 0 Then
        While Not rs.EOF
                'If rs!rut_apo = "10837298-2" Then MsgBox ("aqui")
                c = c + 1
                ' VER SI APODERADO DEBE
                Mayor = EselMayor(rs!ci_alu, Anno)
                If ((LoqueDebe - Pagado) > 0) And Mayor Then
                    'If Val(Pagado) < Val(rs(4)) Then
                    Me.Grd_Apod_Cob.AddItem ""
                    fila = fila + 1
                    Me.Grd_Apod_Cob.TextMatrix(fila, 0) = fila
                    If UCase(rs!cod_des) = "K" Or UCase(rs!cod_des) = "PK" Then
                        curso = UCase(rs!cod_des) & "º" & UCase(rs!Let_Cur)
                    ElseIf UCase(rs!cod_des) = "EB" Or UCase(rs!cod_des) = "EM" Then
                        curso = UCase(rs!Num_Gra) & "º" & UCase(rs!Let_Cur) & " " & UCase(rs!cod_des)
                    End If
                    Me.Grd_Apod_Cob.TextMatrix(fila, 1) = curso
                    Me.Grd_Apod_Cob.TextMatrix(fila, 2) = rs!Rut_apo
                    Me.Grd_Apod_Cob.TextMatrix(fila, 3) = rs!ape1_apo & " " & rs!ape2_apo & " " & rs!Noms_Apo
                    Me.Grd_Apod_Cob.TextMatrix(fila, 4) = LoqueDebe ' rs(8) ' lo que debe
                    Me.Grd_Apod_Cob.TextMatrix(fila, 5) = Pagado 'IIf(Len(Trim(Pagado)) > 0, Pagado, 0) ' lo que ha pagado
                    Me.Grd_Apod_Cob.TextMatrix(fila, 6) = Val(Me.Grd_Apod_Cob.TextMatrix(fila, 4)) - Val(Me.Grd_Apod_Cob.TextMatrix(fila, 5)) ' deuda
                    Me.Grd_Apod_Cob.TextMatrix(fila, 7) = CStr(CuotasenMora(rs!Rut_apo, CStr(Mes), IIf(Me.Chk_IncluyeMes.Value, True, False)))
                    'Me.Grd_Apod_Cob.TextMatrix(Fila, 12) = IIf(Mayor, "SI", "NO")
                    If Me.Opt_Forma_Asignacion(0).Value Then
                        Call CartaAutom(fila)
                    End If
                    'If Len(Trim(Me.Grd_Apod_Cob.TextMatrix(Fila, 8))) > 0 Then
                        Me.Txt_NCartas = Val(Me.Txt_NCartas) + 1
                        Me.Txt_NCartas.Refresh
                    'End If
                    Me.Grd_Apod_Cob.Refresh
                    Me.btn_impri_cartas.Enabled = True
            End If
            rs.MoveNext
            Me.Prgbar_Cob.ShowProgress c
            DoEvents
        Wend
    End If
    NPosiblesCartas = fila
    rs.Close
Else
    MsgBox ("Faltan opciones por seleccionar")
    Me.Cmb_mes_ref.SetFocus
End If
Set rs = Nothing
End Sub

Private Sub btn_impri_cartas_Click()
Call CreaBD(DirAplicacion & "\rpt\gestemp.mdb")
'Call CreaTabla(DirAplicacion & "\rpt\gestemp.mdb", "Detalles", "10,10-1,12-2,10")
Call CreaTabla(DirAplicacion & "\rpt\gestemp.mdb", "Detalles", "13,10")
Call RptGrillaText(Grd_Apod_Cob, fila, "\rpt\gestemp.mdb", "Detalles")
Titulo = "Cartas de Cobranza"
Nombrecol = devuelvecampo("establecimientos", "", "nom_est", "nom_est <> ''", conn)
Direccol = devuelvecampo("establecimientos", "", "dir_est", "dir_est <> ''", conn)
ComunaCol = devuelvecampo("establecimientos", "", "localidad_est", "localidad_est <> ''", conn)
Form_main.CrystalReport.WindowTitle = Titulo
Form_main.CrystalReport.Formulas(0) = "nomcol = '" & Nombrecol & "'"
Form_main.CrystalReport.Formulas(1) = "dircol = '" & Direccol & "'"
Form_main.CrystalReport.Formulas(2) = "comunacol = '" & ComunaCol & "'"
Form_main.CrystalReport.Formulas(3) = "hora = '" & Time & "'"
Form_main.CrystalReport.Formulas(4) = "MesRef = '" & MesReferencia & "'"
Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\cartacob.rpt"
Form_main.CrystalReport.DataFiles(0) = DirAplicacion & "\rpt\GesTemp.mdb"
Form_main.CrystalReport.WindowState = crptMaximized
'Form_Main.CrystalReport.ReplaceSelectionFormula ("")
Form_main.CrystalReport.Action = 1
Call LimpiaFormulas(Form_main.CrystalReport, 20)
'Form_Main.CrystalReport.ReplaceSelectionFormula ("")
'Kill (DirAplicacion & "\rpt\GesTemp.mdb")

End Sub
Private Sub Btn_impri_list_Click()
Call CreaBD(DirAplicacion & "\rpt\gestemp.mdb")
Call CreaTabla(DirAplicacion & "\rpt\gestemp.mdb", "Detalles", "12,10")
Call RptGrillaText(Grd_Apod_Cob, fila, "\rpt\gestemp.mdb", "Detalles")
Titulo = "Listado de Apoderados Morosos"
Nombrecol = devuelvecampo("establecimientos", "", "nom_est", "nom_est <> ''", conn)
Direccol = devuelvecampo("establecimientos", "", "dir_est", "dir_est <> ''", conn)
ComunaCol = devuelvecampo("establecimientos", "", "localidad_est", "localidad_est <> ''", conn)
Form_main.CrystalReport.WindowTitle = Titulo
Form_main.CrystalReport.Formulas(0) = "nomcol = '" & Nombrecol & "'"
Form_main.CrystalReport.Formulas(1) = "dircol = '" & Direccol & "'"
Form_main.CrystalReport.Formulas(2) = "comunacol = '" & ComunaCol & "'"
Form_main.CrystalReport.Formulas(3) = "hora = '" & Time & "'"
Form_main.CrystalReport.Formulas(4) = "titulo = '" & UCase(Titulo) & "'"
Form_main.CrystalReport.Formulas(5) = "modalidad = '" & Me.cmb_mod_cob & "'"
Form_main.CrystalReport.Formulas(6) = "mesref = '" & Me.Cmb_mes_ref & "'"
Form_main.CrystalReport.ReportFileName = DirAplicacion & "\rpt\ListaCob.rpt"
Form_main.CrystalReport.DataFiles(0) = DirAplicacion & "\rpt\GesTemp.mdb"
Form_main.CrystalReport.WindowState = crptMaximized
'Form_Main.CrystalReport.ReplaceSelectionFormula ("")
Form_main.CrystalReport.Action = 1
Call LimpiaFormulas(Form_main.CrystalReport, 20)
'Form_Main.CrystalReport.ReplaceSelectionFormula ("")
'Kill (DirAplicacion & "\rpt\GesTemp.mdb")
End Sub

Private Sub Btn_Salir_Click()
Unload Me
End Sub

Private Sub chk_todos_cob_Click()
If Me.chk_todos_cob.Value Then
    For t = 0 To Me.lst_cursosinf.ListCount - 1
        Me.lst_cursosinf.Selected(t) = True
    Next t
Else
    For t = 0 To Me.lst_cursosinf.ListCount - 1
        Me.lst_cursosinf.Selected(t) = False
        Me.lst_cursosinf.ListIndex = 0
    Next t
End If
End Sub


Private Sub cmb_mod_cob_Click()
Me.chk_todos_cob.Enabled = True
Me.chk_todos_cob.Value = 0
modalidad = devuelvecampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.cmb_mod_cob.Text & "'", conn)
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "SELECT num_gra, let_cur FROM CURSOS where cod_ens ='" & modalidad & "' ORDER BY NUM_GRA,let_cur", conn
If rs.RecordCount > 0 Then
    ReDim Anuevocurso(rs.RecordCount, 2)
    Me.lst_cursosinf.Clear
    c = 0
    While Not rs.EOF
        lst_cursosinf.AddItem rs("num_gra") + " " + rs("LET_CUR")
        Anuevocurso(c, 1) = rs("num_gra")
        Anuevocurso(c, 2) = rs("let_cur")
        rs.MoveNext
        c = c + 1
    Wend
    End If
rs.Close
Set rs = Nothing
End Sub

Private Sub Cmb_Tipo_Cartas_Click()
If Me.Cmb_Tipo_Cartas.ListIndex >= 0 Then
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open "select * from comunicados where codigo ='" & Acartas(Me.Cmb_Tipo_Cartas.ListIndex) & "'", conn
    If rs.RecordCount > 0 Then
        Me.txt_tit_carta = rs!Titulo
        'Me.Txt_TextoCarta = FillconStr(RsFuncion!cuerpo, 800, "L", "DER") & "."
        Me.Txt_TextoCarta = rs!cuerpo
        Me.Txt_Pie_Carta = rs!pie
        Me.txt_cuotas_mora = rs!cuotas_mora
    Else
        Me.txt_tit_carta = ""
        Me.Txt_TextoCarta = ""
        Me.Txt_Pie_Carta = ""
        Me.txt_cuotas_mora = ""
    End If
    rs.Close
    Set rs = Nothing
End If
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub Form_Load()
If MenuInformes2Fnza = "ccobranza" Then
    Me.Height = "7575"
    Me.Width = "9390"
    Call OcultaFrames
    Busqueda = 1
    Me.opt_indiv_gral(1).Value = True
    Me.Opt_destino(1).Value = True
    Me.Frame_cobranza.Left = 0
    Me.Frame_cobranza.Top = 0
    Me.Frame_cobranza.Visible = True
    Me.chk_todos_cob.Value = False
    Me.chk_todos_cob.Enabled = False
    Me.Chk_IncluyeMes.Value = 1
    Me.btn_impri_cartas.Enabled = False
    Me.Opt_Forma_Asignacion(0).Value = True
    Me.Txt_NCartas = 0
    Me.Caption = "Emisión Cartas de Cobranza"
    Call IniGrillaLista
    Call llenacombo(cmb_mod_cob, "codigos_ensenanza", "des_ens", "order by ord_ens", conn)
    Call llenacomboconarreglo(Cmb_Tipo_Cartas, "comunicados", "descripcion", "codigo", Acartas, conn)
    Me.Cmb_Tipo_Cartas.AddItem ""
    Me.Show
End If
End Sub

Private Sub Grd_Alum_Cok_DblClick()
End Sub

Private Sub Grd_Apod_Cob_DblClick()
If NPosiblesCartas > 0 Then
    If Me.Grd_Apod_Cob.Row > 0 Then
        If Me.Grd_Apod_Cob.TextMatrix(Me.Grd_Apod_Cob.Row, 6) > 0 Then
            Me.Cmb_Tipo_Cartas.ListIndex = -1
            Me.Txt_Pie_Carta = "": Me.Txt_TextoCarta = "": Me.txt_tit_carta = ""
            FilaCob = Me.Grd_Apod_Cob.Row
            Me.Frame_Cartas.Visible = True
            Me.Chk_TodosCartas.Value = 0
            Me.Frame_cobranza.Enabled = False
        Else
            MsgBox ("Apoderado Sin deuda a la fecha, imposible emitir carta")
        End If
    End If
End If
End Sub


Private Sub Opt_destino_Click(Index As Integer)
If Index = 0 Then
    Form_main.CrystalReport.Destination = crptToPrinter
ElseIf Index = 1 Then
    Form_main.CrystalReport.Destination = crptToWindow
End If
End Sub

Private Sub opt_indiv_gral_Click(Index As Integer)
If Index = 0 Then ' Seleccionó individual
    Me.Frame_general.Visible = False
    Me.Frame_individual.Visible = True
    'Call btn_otro_alu_Click
ElseIf Index = 1 Then ' Seleccionó general
    Me.Frame_individual.Visible = False
    Me.Frame_general.Visible = True
    Me.cmb_mod_cob.Text = ""
    Me.lst_cursosinf.Clear
    Me.chk_todos_cob.Value = False
    Me.chk_todos_cob.Enabled = False
    'Me.cmb_mod_cob.SetFocus
End If
End Sub
