VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_Pagar_Mensualidad_hue 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Pago de Mensualidades"
   ClientHeight    =   10515
   ClientLeft      =   1800
   ClientTop       =   1590
   ClientWidth     =   12960
   FillStyle       =   0  'Solid
   Icon            =   "Form_Pagar_Mensualidad_hue.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   10515
   ScaleWidth      =   12960
   Begin VB.TextBox txt_gastos_cobranza 
      Height          =   285
      Left            =   11160
      TabIndex        =   88
      Top             =   10080
      Visible         =   0   'False
      Width           =   975
   End
   Begin VB.Frame frame_gastos_cobranza 
      Caption         =   "Gastos 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          =   2895
      Left            =   120
      TabIndex        =   83
      Top             =   6240
      Width           =   6855
      Begin VB.CommandButton cmd_salir_cobranza 
         Caption         =   "Cerrar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3960
         TabIndex        =   87
         Top             =   2040
         Width           =   1455
      End
      Begin VB.CommandButton cmd_agregar_cobranza 
         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            =   1320
         TabIndex        =   86
         Top             =   2040
         Width           =   1455
      End
      Begin VB.TextBox txt_monto_cobranza 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2160
         TabIndex        =   85
         Top             =   960
         Width           =   1455
      End
      Begin VB.Label Label20 
         Caption         =   "Monto de cobranza"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         TabIndex        =   84
         Top             =   960
         Width           =   1695
      End
   End
   Begin VB.CommandButton cmd_gastos_cobranza 
      Caption         =   "Multas"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   8640
      TabIndex        =   82
      Top             =   9600
      Width           =   1335
   End
   Begin VB.TextBox taller 
      Height          =   285
      Left            =   9960
      TabIndex        =   81
      Top             =   10080
      Visible         =   0   'False
      Width           =   855
   End
   Begin VB.TextBox nombre_taller 
      Height          =   285
      Left            =   8640
      TabIndex        =   80
      Top             =   10080
      Visible         =   0   'False
      Width           =   1215
   End
   Begin VB.CommandButton cmd_taller 
      Caption         =   "Agregar Taller"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   10200
      TabIndex        =   79
      Top             =   9600
      Width           =   1335
   End
   Begin VB.Frame Frame_taller 
      Caption         =   "Academia Deportiva"
      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            =   120
      TabIndex        =   68
      Top             =   6240
      Width           =   6855
      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            =   1200
         TabIndex        =   74
         Top             =   2640
         Width           =   1455
      End
      Begin VB.CommandButton txt_salir 
         Caption         =   "Cerrar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   4320
         TabIndex        =   73
         Top             =   2640
         Width           =   1335
      End
      Begin VB.TextBox txt_taller 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1320
         TabIndex        =   72
         Top             =   570
         Width           =   5055
      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            =   1320
         TabIndex        =   71
         Top             =   1050
         Width           =   1815
      End
      Begin VB.ComboBox cb_tipo_taller 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1320
         TabIndex        =   70
         Top             =   1560
         Width           =   1815
      End
      Begin VB.ComboBox cb_tipo_cliente 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1320
         TabIndex        =   69
         Top             =   2040
         Width           =   1815
      End
      Begin VB.Label Label16 
         Caption         =   "Taller"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   78
         Top             =   600
         Width           =   975
      End
      Begin VB.Label Label17 
         Caption         =   "Monto"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         TabIndex        =   77
         Top             =   1080
         Width           =   855
      End
      Begin VB.Label Label18 
         Caption         =   "Tipo Taller"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   76
         Top             =   1560
         Width           =   855
      End
      Begin VB.Label Label19 
         Caption         =   "Tipo Cliente"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   75
         Top             =   2040
         Width           =   975
      End
   End
   Begin VB.Frame Frame15 
      Caption         =   "Valor UF"
      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            =   6840
      TabIndex        =   60
      Top             =   1920
      Width           =   1575
      Begin VB.TextBox txt_uf 
         Height          =   375
         Left            =   120
         TabIndex        =   62
         Top             =   720
         Width           =   1335
      End
      Begin MSComCtl2.DTPicker dtp_fecha_uf 
         Height          =   375
         Left            =   120
         TabIndex        =   61
         Top             =   240
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   661
         _Version        =   393216
         Format          =   58589185
         CurrentDate     =   44390
      End
   End
   Begin VB.TextBox t_cu 
      Height          =   285
      Left            =   11640
      TabIndex        =   59
      Text            =   "Text10"
      Top             =   9720
      Visible         =   0   'False
      Width           =   255
   End
   Begin VB.TextBox c_co 
      Height          =   285
      Left            =   11040
      TabIndex        =   58
      Text            =   "Text10"
      Top             =   9600
      Visible         =   0   'False
      Width           =   375
   End
   Begin VB.TextBox escol 
      Height          =   285
      Left            =   10200
      TabIndex        =   57
      Text            =   "Text12"
      Top             =   9600
      Visible         =   0   'False
      Width           =   735
   End
   Begin VB.TextBox matric 
      Height          =   405
      Left            =   9360
      TabIndex        =   56
      Text            =   "Text11"
      Top             =   9480
      Visible         =   0   'False
      Width           =   735
   End
   Begin VB.TextBox incor 
      Height          =   285
      Left            =   8640
      TabIndex        =   55
      Text            =   "Text10"
      Top             =   9480
      Visible         =   0   'False
      Width           =   495
   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            =   8520
      TabIndex        =   11
      Top             =   120
      Width           =   4215
      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.CommandButton Command9 
      Caption         =   "Documentar con 10 cheques"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   6840
      TabIndex        =   54
      Top             =   3960
      Visible         =   0   'False
      Width           =   1575
   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          =   1740
      Left            =   6840
      TabIndex        =   39
      TabStop         =   0   'False
      Top             =   720
      Width           =   1335
   End
   Begin VB.Frame Frame14 
      Caption         =   "Información Adicional Mes de "
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   2655
      Left            =   120
      TabIndex        =   42
      Top             =   6960
      Width           =   8295
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid GrillaBlta 
         Height          =   2175
         Left            =   120
         TabIndex        =   43
         TabStop         =   0   'False
         Top             =   360
         Width           =   8055
         _ExtentX        =   14208
         _ExtentY        =   3836
         _Version        =   393216
         Cols            =   10
         FixedCols       =   0
         BackColorBkg    =   -2147483643
         Enabled         =   0   'False
         HighLight       =   0
         FillStyle       =   1
         GridLines       =   0
         GridLinesFixed  =   0
         ScrollBars      =   2
         SelectionMode   =   1
         FormatString    =   "^Tipo Doc.|^Folio|^Fecha|^Monto|^Forma Pago|^Estado|^Rut Apod.|^E. Chq."
         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   =   10
      End
      Begin VB.Label Label10 
         Alignment       =   2  'Center
         BorderStyle     =   1  'Fixed Single
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   255
         Left            =   120
         TabIndex        =   44
         Top             =   2040
         Width           =   7935
      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          =   1740
      Left            =   840
      TabIndex        =   40
      TabStop         =   0   'False
      Top             =   720
      Width           =   5295
   End
   Begin VB.Frame Frame13 
      Caption         =   "Año de Consulta"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   735
      Left            =   6840
      TabIndex        =   37
      Top             =   1080
      Width           =   1575
      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        =   38
         Top             =   240
         Width           =   1215
      End
   End
   Begin VB.Frame Frame12 
      Height          =   855
      Left            =   8520
      TabIndex        =   34
      Top             =   8640
      Width           =   3135
      Begin VB.CommandButton Command1 
         Caption         =   "Salir"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   120
         MaskColor       =   &H00FFFFFF&
         TabIndex        =   36
         Top             =   240
         Width           =   1335
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Emitir Boleta"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   1680
         TabIndex        =   35
         Top             =   240
         Width           =   1335
      End
   End
   Begin VB.Frame Frame7 
      Caption         =   "Último Folio de Boleta Emitido"
      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            =   8520
      TabIndex        =   22
      Top             =   7800
      Width           =   3135
      Begin VB.Label Label8 
         Alignment       =   2  'Center
         BackColor       =   &H00FFFFFF&
         Caption         =   "Colegio"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   120
         TabIndex        =   24
         Top             =   240
         Width           =   2895
      End
      Begin VB.Label Label7 
         Alignment       =   2  'Center
         BackColor       =   &H00FFFFFF&
         Caption         =   "00000000"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   12
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   255
         Left            =   120
         TabIndex        =   23
         Top             =   480
         Width           =   2895
      End
   End
   Begin VB.Frame Frame5 
      Caption         =   "Montos"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1815
      Left            =   8520
      TabIndex        =   13
      Top             =   5880
      Width           =   3135
      Begin VB.TextBox Text6 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1320
         Locked          =   -1  'True
         TabIndex        =   20
         Text            =   "Text6"
         Top             =   960
         Width           =   1575
      End
      Begin VB.TextBox Text5 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1320
         Locked          =   -1  'True
         TabIndex        =   17
         TabStop         =   0   'False
         Text            =   "Text5"
         Top             =   240
         Width           =   1575
      End
      Begin VB.TextBox Text4 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1320
         Locked          =   -1  'True
         TabIndex        =   16
         Text            =   "Text4"
         Top             =   600
         Width           =   1575
      End
      Begin VB.TextBox Text3 
         Alignment       =   1  'Right Justify
         Appearance      =   0  'Flat
         BackColor       =   &H00C0E0FF&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1320
         Locked          =   -1  'True
         TabIndex        =   14
         Text            =   "Text3"
         Top             =   1320
         Width           =   1575
      End
      Begin VB.Label Label6 
         Caption         =   "Total Abonos"
         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        =   21
         ToolTipText     =   "Suma de los Abonos realizados por el apoderado"
         Top             =   960
         Width           =   1095
      End
      Begin VB.Label Label5 
         Caption         =   "Total Cuotas"
         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        =   19
         ToolTipText     =   "Valor total de las cuotas a pagar"
         Top             =   240
         Width           =   1095
      End
      Begin VB.Label Label4 
         Caption         =   "Total Exención"
         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        =   18
         ToolTipText     =   "Suma total de las exenciones del alumno"
         Top             =   600
         Width           =   1095
      End
      Begin VB.Label Label3 
         Caption         =   "Total a Pagar"
         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        =   15
         ToolTipText     =   "Valor total a pagar en la boleta."
         Top             =   1320
         Width           =   1095
      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          =   3615
      Left            =   120
      TabIndex        =   8
      Top             =   3240
      Width           =   8295
      Begin VB.Frame Frame_Actualizacion_Masivo 
         Caption         =   "Actualizar Masivo"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1815
         Left            =   240
         TabIndex        =   45
         Top             =   1200
         Visible         =   0   'False
         Width           =   7695
         Begin ComctlLib.ProgressBar progreso 
            Height          =   255
            Left            =   480
            TabIndex        =   46
            Top             =   1320
            Width           =   6735
            _ExtentX        =   11880
            _ExtentY        =   450
            _Version        =   327682
            Appearance      =   1
         End
         Begin VB.Label Label13 
            Caption         =   "Label13"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   2400
            TabIndex        =   49
            Top             =   840
            Width           =   615
         End
         Begin VB.Label Label12 
            Caption         =   "Label12"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   480
            TabIndex        =   48
            Top             =   840
            Width           =   615
         End
         Begin VB.Label Label11 
            Caption         =   "Espere Mientras el Sistema Actualiza los Datos"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   14.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   480
            TabIndex        =   47
            Top             =   360
            Width           =   6735
         End
      End
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid GrillaDtll 
         Height          =   3255
         Left            =   120
         TabIndex        =   12
         Top             =   240
         Width           =   8055
         _ExtentX        =   14208
         _ExtentY        =   5741
         _Version        =   393216
         BackColor       =   16777215
         Cols            =   11
         FixedCols       =   0
         BackColorSel    =   14737632
         ForeColorSel    =   16711680
         BackColorBkg    =   16777215
         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          =   2055
      Left            =   120
      TabIndex        =   5
      Top             =   1080
      Width           =   6615
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid Grilla 
         Height          =   1695
         Left            =   120
         TabIndex        =   7
         Top             =   240
         Width           =   6375
         _ExtentX        =   11245
         _ExtentY        =   2990
         _Version        =   393216
         FixedCols       =   0
         BackColorSel    =   14737632
         ForeColorSel    =   16711680
         BackColorBkg    =   -2147483643
         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           =   8295
      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            =   6720
         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            =   6240
         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
   Begin VB.CommandButton Btn_Recalcula 
      Caption         =   "Recalcular Mensualidad"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   6840
      TabIndex        =   41
      Top             =   4560
      Visible         =   0   'False
      Width           =   1575
   End
   Begin VB.Frame Frame8 
      Caption         =   "Emisión de Boleta"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   4695
      Left            =   8520
      TabIndex        =   25
      Top             =   1080
      Visible         =   0   'False
      Width           =   4215
      Begin VB.Frame Frame9 
         Caption         =   "Forma de Pago"
         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        =   63
         Top             =   1200
         Width           =   3855
         Begin VB.ComboBox CboFormaPago1 
            Height          =   315
            ItemData        =   "Form_Pagar_Mensualidad_hue.frx":2A8B2
            Left            =   240
            List            =   "Form_Pagar_Mensualidad_hue.frx":2A8C8
            Style           =   2  'Dropdown List
            TabIndex        =   67
            Top             =   360
            Width           =   1815
         End
         Begin VB.ComboBox CboFormaPago2 
            Height          =   315
            ItemData        =   "Form_Pagar_Mensualidad_hue.frx":2A904
            Left            =   240
            List            =   "Form_Pagar_Mensualidad_hue.frx":2A91A
            Style           =   2  'Dropdown List
            TabIndex        =   66
            Top             =   840
            Width           =   1815
         End
         Begin VB.TextBox TxtMonto1 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2160
            TabIndex        =   65
            TabStop         =   0   'False
            Top             =   360
            Width           =   1575
         End
         Begin VB.TextBox TxtMonto2 
            Alignment       =   1  'Right Justify
            Appearance      =   0  'Flat
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   2160
            TabIndex        =   64
            TabStop         =   0   'False
            Top             =   840
            Width           =   1575
         End
      End
      Begin VB.Frame Frame11 
         Caption         =   "Fecha Pago"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   735
         Left            =   120
         TabIndex        =   31
         Top             =   360
         Width           =   2895
         Begin MSComCtl2.DTPicker Dtp_Fec_emision 
            Height          =   375
            Left            =   1440
            TabIndex        =   33
            Top             =   240
            Width           =   1335
            _ExtentX        =   2355
            _ExtentY        =   661
            _Version        =   393216
            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
            Format          =   58589185
            CurrentDate     =   40544
         End
         Begin VB.Label Label9 
            Caption         =   "Fecha Boleta"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00000000&
            Height          =   255
            Left            =   120
            TabIndex        =   32
            Top             =   360
            Width           =   1215
         End
      End
      Begin VB.CommandButton Command5 
         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            =   2640
         TabIndex        =   30
         Top             =   4080
         Width           =   1335
      End
      Begin VB.Frame Frame10 
         Caption         =   "Folio Impreso"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   735
         Left            =   120
         TabIndex        =   28
         Top             =   3840
         Width           =   1455
         Begin VB.TextBox Text7 
            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
            TabIndex        =   29
            Text            =   "Text7"
            Top             =   360
            Width           =   1215
         End
      End
      Begin VB.CommandButton Command4 
         Caption         =   "Agregar al Libro"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   855
         Left            =   2760
         Picture         =   "Form_Pagar_Mensualidad_hue.frx":2A956
         Style           =   1  'Graphical
         TabIndex        =   27
         Top             =   2880
         Width           =   1335
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Imprimir Boleta"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   855
         Left            =   1320
         Picture         =   "Form_Pagar_Mensualidad_hue.frx":2AF3C
         Style           =   1  'Graphical
         TabIndex        =   26
         Top             =   2880
         Width           =   1335
      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          =   3855
      Left            =   8520
      TabIndex        =   9
      Top             =   1080
      Width           =   3135
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid GrillaMens 
         Height          =   3495
         Left            =   120
         TabIndex        =   10
         TabStop         =   0   'False
         Top             =   240
         Width           =   2895
         _ExtentX        =   5106
         _ExtentY        =   6165
         _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.TextBox Text8 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   10320
      TabIndex        =   51
      Text            =   "Text8"
      Top             =   8880
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.TextBox Text9 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   10320
      TabIndex        =   53
      Text            =   "Text9"
      Top             =   9240
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.Label Label15 
      Caption         =   "Total Otras Exenciones"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   8520
      TabIndex        =   52
      Top             =   9240
      Visible         =   0   'False
      Width           =   1695
   End
   Begin VB.Label Label14 
      Caption         =   "Total Exencion Becas"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   8520
      TabIndex        =   50
      Top             =   8880
      Visible         =   0   'False
      Width           =   1575
   End
End
Attribute VB_Name = "Form_Pagar_Mensualidad_hue"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


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 colegio2 As String

'Dim rut_alu_cons As String

Dim ResetPago As Boolean
Private Sub Btn_Recalcula_Click()
    Dim objRS As New ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    If MsgBox("¿Esta seguro que desea recalcular la mensualidad del apoderado?", vbOKCancel + vbCritical, "ADVERTENCIA") = vbOK Then
        Me.Frame1.Enabled = False
        Me.Frame2.Enabled = False
        Me.Frame3.Enabled = False
        Me.Frame4.Enabled = False
        Me.Frame5.Enabled = False
        Me.Frame6.Enabled = False
        Me.Frame7.Enabled = False
        Me.Frame12.Enabled = False
        Me.Frame13.Enabled = False
                
        var_sql = "select alu.run_alu,alu.monto_tot_cuota from" _
            & " (select * from" _
            & " (select * from fnza_detalle_mensualidad f,matriculas m" _
            & " where agno = 2009 and mes = 3 and monto_tot_cuota > 0 and" _
            & " f.run_alu = m.ci_alu and f.agno = m.anno_mat and ind_mbeca = 0 and ind_beca = 0) n," _
            & " (select run_alu  from fnza_detalle_mensualidad f,matriculas m" _
            & " where agno = 2008 and mes = 12 and f.run_alu = m.ci_alu and f.agno = m.anno_mat and confirmado = 'SI') a" _
            & " where n.run_alu = a.run_alu) alu,apo_x_alu apo" _
            & " where alu.run_alu = apo.ci_alu and alu.agno = apo.agno and rut_apo = '" & Me.text2.Text & "'"
        objRS.Open var_sql, conn
            While Not objRS.EOF
                var_sql = "update fnza_detalle_mensualidad set monto_exen_desc = 0" _
                        & " where agno = 2009 and run_alu = '" & objRS("run_alu") _
                        & "' and concepto <> 'ct00' and monto_exen_desc <> 0"
                conn.Execute var_sql
                objRS.MoveNext
            Wend
            
        'rut_alu_cons = objRS("run_alu")
        
        objRS.Close
        
        RecalculaCuota_Apo Me.text2.Text, val(Combo1.Text), conn
        Flag_sub = True
        Call LimpiaComboCol
        Call LlenaComboCol
        Flag_sub = False
        ImageCombo2.Refresh
        Call SeteaGrillaMens
        Call LlenaGrillaMens
        Call SeteaGrilla
        Call LlenaGrilla
        Call SeteaGrillaDtll
        Call LlenaGrillaDtll
        
        Me.Frame1.Enabled = True
        Me.Frame2.Enabled = True
        Me.Frame3.Enabled = True
        Me.Frame4.Enabled = True
        Me.Frame5.Enabled = True
        Me.Frame6.Enabled = True
        Me.Frame7.Enabled = True
        Me.Frame12.Enabled = True
        Me.Frame13.Enabled = True
    End If
End Sub



Private Sub cmd_agregar_Click()
    Dim var_sql As String
    Dim ci_alu As String
    Dim fecha_venc As String
    Dim total_academias As Integer
    Dim monto_mensualidad As Long
    Dim folio_mensualidad As Long
    Dim estado_mensualidad As String
    Dim Concepto As String
 
    Dim objRS As New ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    'Validacion
    If cb_tipo_cliente.Text = "" Or cb_tipo_taller.Text = "" Or txt_monto.Text = "" Or txt_taller.Text = "" Then
        MsgBox "Debe ingresar todos los datos", vbInformation
        Exit Sub
    End If
        
    If val(txt_monto.Text) = 0 Then
        MsgBox "Debe ingresar un monto numerico", vbInformation
        Exit Sub
    End If
        
    ' Rut alumno y fecha vencimiento
    ci_alu = Me.grilla.TextMatrix(grilla.Row, 0)
    fecha_venc = Combo1.Text & "-01-10"
        
    ' Verifico si ya esta creada mensualidad de enero
    var_sql = "SELECT monto_mens,estado_mens FROM fnza_mensualidad WHERE agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND mes = 1"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        monto_mensualidad = objRS("monto_mens")
        estado_mensualidad = objRS("ESTADO_MENS")
    End If
    objRS.Close
    
    ' Busco cuantas academias hay creadas
    var_sql = "SELECT count(*) as total_academias FROM fnza_detalle_mensualidad WHERE agno = " & Combo1.Text & " AND run_alu = '" & ci_alu & "' AND mes = 1 and concepto like 'aca%'"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        total_academias = objRS("total_academias")
    End If
    objRS.Close
    
    ' Si no esta creda mensualidad de enero la creo, si esta creada modifico solo el monto
    If total_academias = 0 Then
        If monto_mensualidad = 0 Then
            var_sql = "insert into `fnza_mensualidad` (`COLEGIO`, `RUN_APO`, `FECH_VENC`, `MONTO_MENS`," _
                & "`ABONO_MENS`, `FECH_PAGO`, `ESTADO_MENS`, `MES`, `AGNO`, `monto_mens_d`)" _
                & "values('HUE001','" & text2.Text & "',cast('" & fecha_venc & "' as date),'" & txt_monto.Text & "'," _
                & "'0','0000-00-00','impg','1','" & Combo1.Text & "','" & txt_monto.Text & "');"
            conn.Execute var_sql
        Else
            estado_mensualidad = IIf(estado_mensualidad = "impg", "impg", "abon")
            var_sql = "UPDATE fnza_mensualidad SET monto_mens = monto_mens + " & txt_monto.Text & ",estado_mens = '" & estado_mensualidad & "'" _
                    & " WHERE agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND mes = 1"
            conn.Execute var_sql
        End If
    End If
        
    'Rescato folio de mensualidad
    var_sql = "SELECT FOLIO_MENS FROM fnza_mensualidad WHERE agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND mes = 1"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        folio_mensualidad = objRS("FOLIO_MENS")
    End If
    objRS.Close
        
    ' Concepto
    Concepto = "aca" & total_academias
    
    var_sql = "insert into `fnza_detalle_mensualidad` (`FOLIO_MENS`, `RUN_ALU`, `COLEGIO`, `CONCEPTO`," _
              & "`FECH_VENC`, `MONTO_TOTAL`, `MONTO_EXEN_HNO`, `MONTO_EXEN_BCA`, `MONTO_EXEN_DESC`," _
              & "`MONTO_EXEN_CONV`, `MONTO_EXEN_TIPO_PAGO`, `MONTO_TOT_CUOTA`, `MONTO_ABONO`, `FECH_PAGO`," _
              & "`ESTADO_DTLL`, `COD_CONVENIO`, `MES`, `AGNO`, `TERCIO`," _
              & "`motivo_ajuste`, `monto_tot_cuota_d`, `monto_total_UF`, `monto_exen_UF`, `monto_tot_cuota_UF`," _
              & "`taller`, `tipo_taller`, `monto_taller`,tipo_cliente)" _
              & " values('" & folio_mensualidad & "','" & ci_alu & "','HUE001','" & Concepto & "'," _
              & "cast('" & fecha_venc & "' as date),'" & txt_monto.Text & "','0','0','0'," _
              & "'0','0','" & txt_monto.Text & "','0','0000-00-00'," _
              & "'impg','none','1','" & Combo1.Text & "','NO'," _
              & "'','" & txt_monto.Text & "','0','0','0'," _
              & "'" & txt_taller.Text & "','" & cb_tipo_taller.Text & "','" & txt_monto.Text & "','" & cb_tipo_cliente.Text & "');"
    conn.Execute var_sql
    
    MsgBox "Academia ha sido creada satisfactoriamente", vbInformation
    Frame_taller.Visible = False
    
        If Flag_sub Then Exit Sub
        Call ReseteaSeleccionBoleta
        Flag_sub = True
        Call LimpiaComboCol
        Call LlenaComboCol
        Flag_sub = False
        Call SeteaGrillaMens
        Call LlenaGrillaMens
        Call SeteaGrilla
        If Combo1.Text > 2021 Then Call recalcula_UF(text2.Text, Format(dtp_fecha_uf.Value, "yyyy-mm-dd"), Combo1.Text)
        Call LlenaGrilla
        Call SeteaGrillaDtll
        Call SeteaGrillaBlta
End Sub

Private Sub cmd_agregar_cobranza_Click()
    Dim var_sql As String
    Dim ci_alu As String
    Dim fecha_venc As String
    Dim total_academias As Integer
    Dim monto_mensualidad As Long
    Dim folio_mensualidad As Long
    Dim estado_mensualidad As String
    Dim Concepto As String
 
    Dim objRS As New ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    'Validacion
'    If cb_tipo_cliente.Text = "" Or cb_tipo_taller.Text = "" Or txt_monto.Text = "" Or txt_taller.Text = "" Then
'        MsgBox "Debe ingresar todos los datos", vbInformation
'        Exit Sub
'    End If
        
    If val(txt_monto_cobranza.Text) = 0 Then
        MsgBox "Debe ingresar un monto numerico", vbInformation
        Exit Sub
    End If
        
    ' Rut alumno y fecha vencimiento
    ci_alu = Me.grilla.TextMatrix(grilla.Row, 0)
    fecha_venc = Combo1.Text & "-01-10"
        
    ' Verifico si ya esta creada mensualidad de enero
    var_sql = "SELECT monto_mens,estado_mens FROM fnza_mensualidad WHERE agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND mes = 1"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        monto_mensualidad = objRS("monto_mens")
        estado_mensualidad = objRS("ESTADO_MENS")
    End If
    objRS.Close
    
    ' Busco si ya se crearon gastos de cobranza
    var_sql = "SELECT count(*) as total_academias FROM fnza_detalle_mensualidad WHERE agno = " & Combo1.Text & " AND run_alu = '" & ci_alu & "' AND mes = 1 and concepto like 'gco%'"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        total_academias = objRS("total_academias")
    End If
    objRS.Close
    
    ' Si no esta creda mensualidad de enero la creo, si esta creada modifico solo el monto
    If total_academias = 0 Then
        If monto_mensualidad = 0 Then
            var_sql = "insert into `fnza_mensualidad` (`COLEGIO`, `RUN_APO`, `FECH_VENC`, `MONTO_MENS`," _
                & "`ABONO_MENS`, `FECH_PAGO`, `ESTADO_MENS`, `MES`, `AGNO`, `monto_mens_d`)" _
                & "values('HUE001','" & text2.Text & "',cast('" & fecha_venc & "' as date),'" & txt_monto_cobranza.Text & "'," _
                & "'0','0000-00-00','impg','1','" & Combo1.Text & "','" & txt_monto_cobranza.Text & "');"
            conn.Execute var_sql
        Else
            estado_mensualidad = IIf(estado_mensualidad = "impg", "impg", "abon")
            var_sql = "UPDATE fnza_mensualidad SET monto_mens = monto_mens + " & txt_monto_cobranza.Text & ",estado_mens = '" & estado_mensualidad & "'" _
                    & " WHERE agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND mes = 1"
            conn.Execute var_sql
        End If
    End If
        
    'Rescato folio de mensualidad
    var_sql = "SELECT FOLIO_MENS FROM fnza_mensualidad WHERE agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND mes = 1"
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        folio_mensualidad = objRS("FOLIO_MENS")
    End If
    objRS.Close
        
    ' Concepto
    Concepto = "gco" & total_academias
    '  Concepto = "gcob"
    
    var_sql = "insert into `fnza_detalle_mensualidad` (`FOLIO_MENS`, `RUN_ALU`, `COLEGIO`, `CONCEPTO`," _
              & "`FECH_VENC`, `MONTO_TOTAL`, `MONTO_EXEN_HNO`, `MONTO_EXEN_BCA`, `MONTO_EXEN_DESC`," _
              & "`MONTO_EXEN_CONV`, `MONTO_EXEN_TIPO_PAGO`, `MONTO_TOT_CUOTA`, `MONTO_ABONO`, `FECH_PAGO`," _
              & "`ESTADO_DTLL`, `COD_CONVENIO`, `MES`, `AGNO`, `TERCIO`," _
              & "`motivo_ajuste`, `monto_tot_cuota_d`, `monto_total_UF`, `monto_exen_UF`, `monto_tot_cuota_UF`," _
              & "`taller`, `tipo_taller`, `monto_taller`,tipo_cliente)" _
              & " values('" & folio_mensualidad & "','" & ci_alu & "','HUE001','" & Concepto & "'," _
              & "cast('" & fecha_venc & "' as date),'" & txt_monto_cobranza.Text & "','0','0','0'," _
              & "'0','0','" & txt_monto_cobranza.Text & "','0','0000-00-00'," _
              & "'impg','none','1','" & Combo1.Text & "','NO'," _
              & "'','" & txt_monto_cobranza.Text & "','0','0','0'," _
              & "'','','" & txt_monto_cobranza.Text & "','');"
    conn.Execute var_sql
    
    MsgBox "Gastos de cobranza han sido creado satisfactoriamente", vbInformation
    frame_gastos_cobranza.Visible = False
    
        If Flag_sub Then Exit Sub
        Call ReseteaSeleccionBoleta
        Flag_sub = True
        Call LimpiaComboCol
        Call LlenaComboCol
        Flag_sub = False
        Call SeteaGrillaMens
        Call LlenaGrillaMens
        Call SeteaGrilla
        If Combo1.Text > 2021 Then Call recalcula_UF(text2.Text, Format(dtp_fecha_uf.Value, "yyyy-mm-dd"), Combo1.Text)
        Call LlenaGrilla
        Call SeteaGrillaDtll
        Call SeteaGrillaBlta
End Sub

Private Sub cmd_gastos_cobranza_Click()
    If Me.grilla.TextMatrix(grilla.Row, 0) = "" Then
        MsgBox "Debe seleccionar un alumno antes de ingresar gastos de cobranza", vbInformation
        Exit Sub
    End If
    frame_gastos_cobranza.Visible = Visible
    'cb_tipo_cliente.Text = ""
    'cb_tipo_taller.Text = ""
    txt_monto_cobranza.Text = 0
    'txt_taller.Text = ""
End Sub

Private Sub cmd_salir_cobranza_Click()
    frame_gastos_cobranza.Visible = False
End Sub

Private Sub cmd_taller_Click()
    If Me.grilla.TextMatrix(grilla.Row, 0) = "" Then
        MsgBox "Debe seleccionar un alumno antes de ingresar el taller", vbInformation
        Exit Sub
    End If
    Frame_taller.Visible = Visible
    cb_tipo_cliente.Text = ""
    cb_tipo_taller.Text = ""
    txt_monto.Text = ""
    txt_taller.Text = ""
End Sub

Private Sub Combo1_Click()
    If (Text1.Text = "" Or text2.Text = "") Then
        Exit Sub
    Else
        If Flag_sub Then Exit Sub
        Call ReseteaSeleccionBoleta
        Flag_sub = True
        Call LimpiaComboCol
        Call LlenaComboCol
        Flag_sub = False
        Call SeteaGrillaMens
        Call LlenaGrillaMens
        Call SeteaGrilla
        If Combo1.Text > 2021 Then Call recalcula_UF(text2.Text, Format(dtp_fecha_uf.Value, "yyyy-mm-dd"), Combo1.Text)
'''''''        If Combo1.Text >= 2023 Then
'''''''            var_sql = "UPDATE fnza_mensualidad f,fnza_detalle_mensualidad ff,fnza_valor_matricula fv SET ff.monto_tot_cuota = fv.valor" _
'''''''                    & " WHERE f.folio_mens = ff.folio_mens AND" _
'''''''                    & " f.agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND concepto = 'ct00'" _
'''''''                    & " AND ff.run_alu = fv.ci_alu AND ff.agno = fv.agno"
'''''''            conn.Execute var_sql
'''''''        End If
        Call LlenaGrilla
        Call SeteaGrillaDtll
        Call SeteaGrillaBlta
    End If
End Sub

Private Sub Command1_Click()
    Unload Me
End Sub

Private Sub Command2_Click()
    ' si no hay nada que pagar no hacer nada
    If val(Text3.Text) <= 0 Then Exit Sub
    Dtp_Fec_emision.Value = Date
    Text7.Text = val(Label7.Caption) + 1
    
    'Aqui digito ultimo folio softland
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    aaa = ConectarSQL(connSQL, "192.168.7.13", colegio, "sa", "passCORPsa.2024", True)
    var_sql = "select max(folio) as folio from " & DevuelveCampo("fnza_temp_boleta_electronica", "", "sector", "1=1", conn) & ".softland.iw_gsaen where tipo = 'B'"
    objRS.Open var_sql, connSQL
    If objRS.RecordCount > 0 Then
        If objRS("folio") < 17975 Then
            Text7.Text = 17975
        Else
            Text7.Text = objRS("folio") + 1
        End If
    End If
    objRS.Close
    connSQL.Close
    
    Frame1.Enabled = False
    Frame2.Enabled = False
    Frame3.Enabled = False
    Frame6.Enabled = False
    Frame13.Enabled = False
    Command1.Enabled = False
    Command2.Enabled = False
    'Command9.Enabled = False
    Frame8.Enabled = True
    Frame8.Visible = True
    'Option1.SetFocus
    'Option1.Value = False
    
    'ae grega para limpiar los combos de forma de pago
    CboFormaPago1.ListIndex = -1
    CboFormaPago2.ListIndex = -1
End Sub

Private Sub Command3_Click()
On Error GoTo Controlerror:

    Dim OkImprimir As Boolean
    Dim Verificar As Integer
    
    'consulta
    Dim objRS As New ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    
    Dim inco As String
    Dim ct00 As String
    Dim esco As String
    
    Dim cc As Long
    Dim tcc As Long
    Dim d As Long
    Dim td As Long
    
    Dim ruta As String
    Dim ruta2 As String
    Dim registro0 As String
    Dim registro1 As String
    Dim registro2 As String
    Dim registro3 As String
    Dim registro4 As String
    Dim registro5 As String
    Dim Registro As String
    Dim registro6 As String
    Dim registro7 As String
    Dim numero_coordinador As Integer
    
'''''''    If Option1.Value = False And Option2.Value = False And Option3.Value = False And Option4.Value = False And Option5.Value = False And Option6.Value = False And Option7.Value = False Then
'''''''        MsgBox "Primero debe seleccionar una forma de pago", vbInformation
'''''''        Exit Sub
'''''''    End If
    
    If CboFormaPago1.Text = "" Then
        MsgBox "Primero debe seleccionar una forma de pago", vbInformation
        Exit Sub
    End If
    
    'consulta
    
    ' Imprimir Boleta
    ' ########
'''''quito mensajes pa ra jazmin
'''''    Verificar = MsgBox("La FECHA de Emisión " & Dtp_Fec_emision.Value & vbCrLf & vbCrLf & "¿Es Correcta?", vbOKCancel + vbQuestion, "Verificar Fecha")
'''''    If (Verificar = 2) Then Exit Sub
    
    Load Form_Boleta_Imprimir
    Llena_Vista_Boleta
    Form_Boleta_Imprimir.Show vbModal
    OkImprimir = Form_Boleta_Imprimir.OkImprimir
    Unload Form_Boleta_Imprimir
    
    If Not (OkImprimir) Then Exit Sub
            
            Dim MArancel As String, MExencion As Long, MPagado As Long, MTotal As Long, MCuota  As Long
            Dim MCPadres As String, MAportes As String, MOtros As String, MParcial As Long
            Dim FEmision As String, NomApo As String, RutApoBol As String, NomAlu As String, curso As String
            Dim suma As String, Mensual As String, MesBoleta As String, EnPalabras As clsNum2Let
            Dim iniPrinter As String
            Dim ResetPrinter As String
            Dim FormFeed As String
            
            Dim diab As String
            Dim mesb As String
            Dim aniob As String
            
            Set EnPalabras = New clsNum2Let
            iniPrinter = Chr(27) + Chr(67) + Chr(51) + Chr(13) + Chr(27) + Chr(74) + Chr(120)
            ResetPrinter = Chr(27) + "@"
            FormFeed = Chr(12)
            
            'Open "LPT1:" For Output As 1
            'Open "C:\hola.txt" For Output As 1
            
            var_sql = "SELECT valor FROM cfg WHERE param = 'codbc'"
            objRS.Open var_sql, conn
            colegio2 = objRS("valor")
            objRS.Close

                NomApo = Left(Me.Text1.Text, 31)                ' Nombre del apoderado
                RutApoBol = Me.text2.Text
                Pagado = Me.Text3.Text                          ' Monto a pagar
                EnPalabras.Numero = val(Pagado)                 ' Monto a pagar
                NomAlu = Me.grilla.TextMatrix(grilla.Row, 1)    ' Nombre del alumno
                curso = CursoAlumno(Me.grilla.TextMatrix(grilla.Row, 0), val(Combo1.Text), conn)  ' curso
                MesBoleta = CalculaMeses(Me.grilla.TextMatrix(grilla.Row, 0), val(Combo1.Text)) ' mes de la boleta
                FEmision = Dtp_Fec_emision.Value                'fecha de emision de la boleta
                MCuota = val(Me.Text3.Text)                     ' monto cuota
                MArancel = IIf(val(Text6.Text) > 0, Me.Text5.Text & "-(" & Text6.Text & ")Abono", Me.Text5.Text)
                'MExencion = Val(Me.Text4.Text)                 ' exenciones
                MExencion = val(Me.Text8.Text)                  ' exenciones
                If val(Me.Text8.Text) > 0 Then
                    MParcial = val(Me.Text3.Text)
                Else
                    MParcial = val(Me.Text5.Text)               ' Monto Parcial
                End If
                MOtrasExencion = val(Me.Text9.Text)             ' Otras exencion
                If val(Me.Text9.Text) > 0 Then
                    MParcial1 = val(Me.Text3.Text)
                Else
                    MParcial1 = val(Me.Text3.Text)              'Monto Parcial
                End If
                MCPadres = 0                                    ' monto centro de padres
                MAportes = 0                                    ' monto de aportes voluntarios
                MOtros = 0                                      ' monto otros
                MTotal = val(Me.Text3.Text)                     ' monto total
                mexencionBeca = val(Me.Text8.Text)              ' monto exencion Becas
                mexencionotro = val(Me.Text9.Text)              ' monto otras exenciones
               'Letra = 1: TOTAL_LETRAS = 10: agno_v = 5
               
               'vbCrLf + vbCrLf + Space(38) + CStr(MExencion) + Space(26 - Len(CStr(MExencion)) + 1) + CStr(MParcial)
                'vbCrLf + vbCrLf + Space(38) + CStr(MOtrasExencion) + Space(26 - Len(CStr(MOtrasExencion)) + 1) + CStr(MParcial1)
                
                tcc = c_co.Text
                If t_cu.Text = 0 Then
                    cc = 0
                Else
                    cc = (tcc / t_cu.Text)
                End If
                
                
                td = MOtrasExencion
                If t_cu.Text = 0 Then
                    d = 0
                Else
                    d = (MOtrasExencion / t_cu.Text)
                End If
                
                
                diab = Mid(FEmision, 1, 2)
                mesb = Mid(FEmision, 4, 2)
                aniob = Mid(FEmision, 9, 2)
                
             If colegio2 = "HUE001" Or colegio2 = "ALT001" Then
                
'                Print #1, Chr(15) & _
                vbCrLf + vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf & _
                vbCrLf + Space(20) + NomApo + Space(25) + RutApoBol & _
                vbCrLf + vbCrLf + Space(20) + NomAlu & _
                vbCrLf + vbCrLf + Space(20) + MesBoleta + Space(40) + curso & _
                vbCrLf + vbCrLf + Space(21) + Pagado + Space(6) + EnPalabras.ALetra & _
                vbCrLf & _
                vbCrLf + vbCrLf + Space(55) + incor.Text & _
                vbCrLf + vbCrLf + Space(55) + matric.Text & _
                vbCrLf + vbCrLf + Space(36) + CStr(cc) + Space(19 - Len(CStr(cc)) + 1) + CStr(tcc) & _
                vbCrLf + vbCrLf + Space(36) + CStr((d)) + Space(19 - Len(CStr((d))) + 1) + CStr(td) & _
                vbCrLf + vbCrLf + Space(55) + CStr(MAportes) & _
                vbCrLf + vbCrLf + Space(55) + CStr(MCPadres) & _
                vbCrLf + vbCrLf + Space(55) + CStr(MOtros) & _
                vbCrLf + vbCrLf + Space(53) + CStr(MTotal) & _
                vbCrLf + vbCrLf + vbCrLf + vbCrLf + Space(8) + diab + Space(4) + mesb + Space(8) + aniob & _
                vbCrLf; vbCrLf + vbCrLf + vbCrLf
             '   Print #1, ResetPrinter
                Close 1
                
            Else
            
                Print #1, Chr(15) & _
                vbCrLf + vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf & _
                vbCrLf + Space(20) + NomApo + Space(25) + RutApoBol & _
                vbCrLf + vbCrLf + Space(20) + NomAlu & _
                vbCrLf + vbCrLf + Space(20) + MesBoleta + Space(40) + curso & _
                vbCrLf + vbCrLf + Space(25) + Pagado + Space(10) + EnPalabras.ALetra & _
                vbCrLf + vbCrLf & _
                vbCrLf + vbCrLf + Space(65) + incor.Text & _
                vbCrLf + vbCrLf + Space(65) + matric.Text & _
                vbCrLf + vbCrLf + Space(38) + CStr(cc) + Space(26 - Len(CStr(cc)) + 1) + CStr(tcc) & _
                vbCrLf + vbCrLf + Space(38) + CStr((d)) + Space(26 - Len(CStr((d))) + 1) + CStr(td) & _
                vbCrLf + vbCrLf + Space(65) + CStr(MAportes) & _
                vbCrLf + vbCrLf + Space(65) + CStr(MCPadres) & _
                vbCrLf + vbCrLf + Space(65) + CStr(MOtros) & _
                vbCrLf + vbCrLf + Space(63) + CStr(MTotal) & _
                vbCrLf + vbCrLf + vbCrLf + vbCrLf + Space(8) + diab + Space(4) + mesb + Space(8) + aniob & _
                vbCrLf; vbCrLf + vbCrLf + vbCrLf
             '   Print #1, ResetPrinter
             '   Close 1
                
            End If
            mestrabajo = DevuelveCampo("cfg", "", "valor", "param = 'mes_trabajo'", conn)
            If Format(FEmision, "YYYYMM") <> mestrabajo Then
                MsgBox "Fecha invalida, debe ingresar una fecha perteneciente al mes de trabajo actual", vbInformation
                Exit Sub
            End If
            
            'vbCrLf + vbCrLf + vbCrLf + vbCrLf + Space(48) + Combo1.Text + Space(15) + vbCrLf & _

            'Boleta Electronica
            'Datos de apoderado
            var_sql = "SELECT replace(dir_apo,',','') as dir_apo,IF(LENGTH(email) > 9 AND email IS NOT NULL AND email LIKE '%@%' AND email LIKE '%.%',email,'apoderados.sin.correo@bostoncollege.cl') email,comuna FROM apoderados a,codigos__geograficos cg WHERE rut_apo = '" & RutApoBol & "' AND a.comuna_apo = cg.cod_geo "
            objRS.Open var_sql, conn
            mail = objRS("email")
            direccion = objRS("dir_apo")
            Comuna = objRS("comuna")
            Ciudad = "SANTIAGO"
            objRS.Close
    
            'Forma de pago
'            If Option1.Value = True Then forma_pago = "101" 'contado
'            If Option2.Value = True Then forma_pago = "102" 'cheque
'            If Option3.Value = True Then forma_pago = "107" 'pat
'            If Option4.Value = True Then forma_pago = "106" 'tarjeta credito
'            If Option5.Value = True Then forma_pago = "108" 'Transferencia
'            If Option6.Value = True Then forma_pago = "105" 'tarjeta debito
'            If Option7.Value = True Then forma_pago = "109" 'Upago
            If CboFormaPago1.Text = "Contado" Then forma_pago = "101" 'contado
            If CboFormaPago1.Text = "Cheque" Then forma_pago = "102" 'cheque
            '''''' If CboFormaPago1.Text = "" Then forma_pago = "107" 'pat
            If CboFormaPago1.Text = "T. Credito" Then forma_pago = "106" 'tarjeta credito
            If CboFormaPago1.Text = "Transf." Then forma_pago = "108" 'Transferencia
            If CboFormaPago1.Text = "T. Debito" Then forma_pago = "105" 'tarjeta debito
            If CboFormaPago1.Text = "Upago" Then forma_pago = "109" 'Upago
            
    
            'run_alu = Me.Grilla.TextMatrix(Grilla.Row, 0)    ' Rut del alumno
            alumno_curso = NomAlu & "          Curso: " & curso
    
                'Ruta Boleta
            ruta = "\\vsoftland\Users\lriveros\Desktop\BOLETA ELECTRONICA\boleta_electronica_base64.txt"
            ruta2 = DevuelveCampo("usuarios", "", "ruta_softland", "AUT_NOMBRE_USUARIO ='" & Nom_usu_ses & "'", conn)
    
'            'MkDir "C:\Boleta_Electronica"
'            ruta = "C:\Boleta_Electronica\boleta_electronica_base64.txt"
   '''''''''''''''''''''''''       ruta2 = "C:\Boleta Electronica\boleta_electronica.txt"
            'ruta = "\\192.168.7.12\departamentos\INFORMATICA\electronica.txt"
            'ruta = "\\sdsw02\wwwroot\sanbernardo_base64.txt"
            'ruta2 = "\\sdsw02\wwwroot\sanbernardo.txt"
            'Call Crear_Archivo_Cobranza(ruta)
            Call Crear_Archivo_Cobranza(ruta2)
            
     registro0 = "Tipo_de_Documento_de_Venta;Subtipo_del_Documento;Estado_del_Documento;Bodega_Origen_de_los_Productos;Numero_de_Documento;Fecha_de_Generacion_del_Documento;Concepto_del_Documento;Fecha_de_Vencimiento_del_Documento;Observacion;Moneda_del_Documento;Equivalencia_de_la_Moneda_de_Venta_del_Documento;" _
                & "NCredito_por_Devolucion_o_Refacturacion;Guia_de_Entrada_que_Referencia;Motivo_Anulacion;Nro_Documento_que_Referencia;Tipo_de_documento_que_referencia;" _
                & "Codigo_de_Cliente;Nombre_del_Cliente;Rut_del_Cliente;Giro_del_Cliente;Mail_DTE_del_Cliente;Direccion_del_Cliente;N_Direccion_del_Cliente;Comuna_del_Cliente;Ciudad_del_Cliente;Lugar_del_Documento;Direccion_del_Documento;Codigo_Comuna_del_Documento;Codigo_Ciudad_del_Documento;Codigo_Region_del_Documento;" _
                & "Codigo_Pais_del_Documento;Codigo_Lista_de_Precios;Codigo_de_Vendedor;Codigo_Centro_de_Costo;Codigo_Condicion_de_Pago;Codigo_de_Distribuidor;Nombre_de_Distribuidor;Codigo_Lugar_de_Despacho;Retirado_Por;Patente_del_Camion_de_Despacho;Solicitado_Por;Rut_Solicitante;Despachado_Por;Rut_Transportista;" _
                & "Cuenta_Contable_para_Notas_de_Debito;Porcentaje_de_Descuento_1;Valor_de_Descuento_1;Porcentaje_de_Descuento_2;Valor_de_Descuento_2;Porcentaje_de_Descuento_3;Valor_de_Descuento_3;Porcentaje_de_Descuento_4;Valor_de_Descuento_4;Porcentaje_de_Descuento_5;Valor_de_Descuento_5;Flete;Embalaje;" _
                & "Codigo_de_Canal_de_Ventas;Total_Final;Codigo_de_Producto;Codigo_Unidad_de_Medida;Detalle_del_Producto;Descripcion_del_Producto;Cantidad_Facturada;Cantidad_Despachada;Precio_Unitario_Moneda_Base;Precio_Unitario_Moneda_de_Venta;Equivalencia_de_la_moneda_del_producto_vs_base;Porcentaje_de_Descuento_de_Linea_1;" _
                & "Valor_de_Descuento_de_Linea_1;Porcentaje_de_Descuento_de_Linea_2;Valor_de_Descuento_de_Linea_2;Porcentaje_de_Descuento_de_Linea_3;Valor_de_Descuento_de_Linea_3;" _
                & "Porcentaje_de_Descuento_de_Linea_4;Valor_de_Descuento_de_Linea_4;Porcentaje_de_Descuento_de_Linea_5;Valor_de_Descuento_de_Linea_5;Valor_Total_Descuentos_de_Linea;Porcentaje_de_credito_Empresas_Constructoras;Valor_Total_de_Credito_Empresas_Constructoras;Partida_o_Talla;Pieza_o_Color;" _
                & "Fecha_de_Vencimiento_de_la_Partida_o_Pieza;Serie;Numero_Nota_de_Venta;Identificador_Impresora_Fiscal;Conserva_Folio_Asignado_al_DTE;Referencia_1_Tipo_Documento_SII;Referencia_1_Descripcion;Referencia_1_Numero_Documento;Referencia_1_Fecha_Documento;" _
                & "Referencia_1_Codigo_Referencia_Boleta;Referencia_2_Tipo_Documento_SII;Referencia_2_Descripcion;Referencia_2_Numero_Documento;Referencia_2_Fecha_Documento;Referencia_2_Codigo_Referencia_Boleta;Referencia_3_Tipo_Documento_SII;Referencia_3_Descripcion;Referencia_3_Numero_Documento;Referencia_3_Fecha_Documento;" _
                & "Referencia_3_Codigo_Referencia_Boleta;Referencia_4_Tipo_Documento_SII;Referencia_4_Descripcion;Referencia_4_Numero_Documento;Referencia_4_Fecha_Documento;Referencia_4_Codigo_Referencia_Boleta;Referencia_5_Tipo_Documento_SII;Referencia_5_Descripcion;Referencia_5_Numero_Documento;Referencia_5_Fecha_Documento;" _
                & "Referencia_5_Codigo_Referencia_Boleta;Tipo_de_Transaccion;Forma_Pago_SII;ExportacionIndicador_de_Servicio;ExportacionForma_de_Pago_Exportacion;ExportacionIdAdicional_Receptor_Extranjero;ExportacionRut_Chofer;ExportacionNombre_Chofer;ExportacionModalidad_de_Venta;ExportacionClausula_de_Exportacion;ExportacionTotal_Clausula_de_Ventas_Exportacion;ExportacionRecargo_sTotal_Clausula_de_Venta;ExportacionVia_de_Transporte;" _
                & "ExportacionIddel_Medio_de_Transporte;ExportacionRut_Compania_Transportista;ExportacionNombre_Compania_Transportadora;ExportacionIdAdicional_Cia_Transportadora;ExportacionBooking;ExportacionMotoNave;ExportacionCodigo_de_Operador;ExportacionPuerto_de_Embarque;ExportacionIdAdicional_Puerto_de_Embarque;" _
                & "ExportacionPuerto_de_Desembarque;ExportacionIdAdicional_Puerto_de_Desembarque;ExportacionTara;ExportacionUnidad_de_Medida_Tara;ExportacionTotal_Peso_Bruto;ExportacionUnidad_Peso_Bruto;ExportacionTotal_Peso_Neto;ExportacionUnidad_Peso_Neto;ExportacionTotal_Items;ExportacionTotal_Bultos;ExportacionTipo_de_Bulto;" _
                & "ExportacionMarca;ExportacionId_Container;ExportacionSello;ExportacionEmisor_Sello;ExportacionFlete;ExportacionSeguro;ExportacionCodigo_Pais_Receptor;ExportacionTipo_Moneda_Transaccion"
     registro7 = registro0
     Call AgregarRegistroCobranza(registro0, ruta2)
            
     '' Talleres
    If nombre_taller.Text <> "" Then MesBoleta = nombre_taller.Text
    If val(txt_gastos_cobranza.Text) > 0 And InStr(MesBoleta, " a ") > 0 Then
       MesBoleta = Replace(MesBoleta, "Marzo", "Mar")
       MesBoleta = Replace(MesBoleta, "Abril", "Abr")
       MesBoleta = Replace(MesBoleta, "Mayo", "May")
       MesBoleta = Replace(MesBoleta, "Junio", "Jun")
       MesBoleta = Replace(MesBoleta, "Julio", "Jul")
       MesBoleta = Replace(MesBoleta, "Agosto", "Ago")
       MesBoleta = Replace(MesBoleta, "Septiembre", "Sep")
       MesBoleta = Replace(MesBoleta, "Octubre", "Oct")
       MesBoleta = Replace(MesBoleta, "Noviembre", "Nov")
       MesBoleta = Replace(MesBoleta, "Diciembre", "Dic")
    End If
    If val(txt_gastos_cobranza.Text) > 0 Then MesBoleta = MesBoleta & " más multa"
    If val(txt_gastos_cobranza.Text) > 0 Then MesBoleta = Replace(MesBoleta, "Cuota Incorporación a ", "")
                    
    'Cuota Incorporacion
    enumeracion_concepto = "B1"
    detalle_producto = "CUOTA INCORPORACION"
    desc_matri0 = IIf(valor_concepto = 0, 0, DevuelveCampo("fnza_detalle_mensualidad", "", "(monto_total - monto_tot_cuota) + monto_abono AS descuento", "agno = " & Combo1.Text & " and run_alu = '" & Me.grilla.TextMatrix(grilla.Row, 0) & "' AND concepto = 'ct00' and estado_dtll <> 'clda'", conn))
    desc_otros0 = IIf(desc_matri0 > 0, desc_matri0, 0)
    If tcc = 0 Then
        desc_otros1 = 0
    Else
        descue = DevuelveCampo("fnza_detalle_mensualidad", "", "monto_exen_desc AS descuento", "agno = " & Combo1.Text & " and run_alu = '" & Me.grilla.TextMatrix(grilla.Row, 0) & "' AND concepto = 'inco'", conn)
        descuento = IIf(descue = "", 0, descue)
        desc_otros1 = (td - (descuento)) - IIf(desc_matri <> "", desc_matri, 0)
    End If
      
    total_boleta = (incor.Text + matric.Text + tcc) - (desc_otros0 + desc_otros1)
    desc_beca = 0
    desc_otros = 0
    valor_concepto = incor.Text
    
                    '1  2 3 4               5                                6                7              8CAM                  9        1011
    registro1 = "B;S;V;1;" & Form_Pagar_Mensualidad_hue.Text7.Text & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";0" & "1" & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";" & alumno_curso & ";;;"
                   '12 - 16      17 ok            18              19                20             21ok            22ok
    registro2 = ";;;;;" & RutApoBol & ";" & NomApo & ";" & Replace(RutApoBol, "-", "") & ";" & MesBoleta & ";" & mail & ";" & direccion & ";"
                  '         23                24ok           25ok   262728       35         30 - 40
    registro3 = "" & Combo1.Text & ";" & Comuna & ";" & Ciudad & ";;;;;;;;;;" & forma_pago & ";;;;;;" & MesBoleta
                      '42-58               59cam                   60               61           62           636465         66          676869     70         71      72
    registro4 = ";;;;;;;;;;;;;;;;;;" & total_boleta & ";" & enumeracion_concepto & ";;" & detalle_producto & ";;1;1;" & valor_concepto & ";;;;" & desc_beca & ";;" & desc_otros & ";;;;;;;;"
                     '81 - 153
    registro5 = ";;;;;;;;S;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
    Registro = registro1 & registro2 & registro3 & registro4 & registro5
    registro6 = Registro
    registro7 = registro7 & vbCrLf & registro6
    
    'Call AgregarRegistroCobranza(Base64EncodeString(Registro), ruta)
    Call AgregarRegistroCobranza(Registro, ruta2)
            
    'Derecho Matricula
    enumeracion_concepto = "B2"
    detalle_producto = "DERECHO MATRICULA AÑO ESCOLAR 2017"
    valor_concepto = matric.Text
    desc_matri = IIf(valor_concepto = 0, 0, DevuelveCampo("fnza_detalle_mensualidad", "", "(monto_total - monto_tot_cuota) + monto_abono AS descuento", "agno = " & Combo1.Text & " and run_alu = '" & Me.grilla.TextMatrix(grilla.Row, 0) & "' AND concepto = 'ct00' and estado_dtll <> 'clda'", conn))
    desc_beca = 0
    desc_otros = IIf(desc_matri > 0, desc_matri, 0)
                    '1  2 3 4               5                                6                7              8CAM                  9        1011
    registro1 = "B;S;V;1;" & Form_Pagar_Mensualidad_hue.Text7.Text & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";0" & "1" & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";" & alumno_curso & ";;;"
                   '12 - 16      17 ok            18              19                20             21ok            22ok
    registro2 = ";;;;;" & RutApoBol & ";" & NomApo & ";" & Replace(RutApoBol, "-", "") & ";" & MesBoleta & ";" & mail & ";" & direccion & ";"
                  '         23                24ok           25ok   262728      29ok         30 - 40
    registro3 = "" & Combo1.Text & ";" & Comuna & ";" & Ciudad & ";;;;;;;;;;" & forma_pago & ";;;;;;" & MesBoleta
                      '42-58               59                      60               61          62           636465         66           676869     70         71      72
    registro4 = ";;;;;;;;;;;;;;;;;;" & total_boleta & ";" & enumeracion_concepto & ";;" & detalle_producto & ";;1;1;" & valor_concepto & ";;;;" & desc_beca & ";;" & desc_otros & ";;;;;;;;"
                     '81 - 153
    registro5 = ";;;;;;;;S;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
    Registro = registro1 & registro2 & registro3 & registro4 & registro5
    registro6 = Registro
    registro7 = registro7 & vbCrLf & registro6

    'Call AgregarRegistroCobranza(Base64EncodeString(Registro), ruta)
    Call AgregarRegistroCobranza(Registro, ruta2)

    'Mensualidades
    enumeracion_concepto = "B3"
    detalle_producto = "MONTO MENSUAL"
    valor_concepto = tcc
    desc_beca = 0
    
    'desc_otros = td
    If valor_concepto = 0 Then
        desc_otros = 0
    Else
        descue = DevuelveCampo("fnza_detalle_mensualidad", "", "monto_exen_desc AS descuento", "agno = " & Combo1.Text & " and run_alu = '" & Me.grilla.TextMatrix(grilla.Row, 0) & "' AND concepto = 'inco'", conn)
        descuento = IIf(descue = "", 0, descue)
        desc_otros = (td - (descuento)) - IIf(desc_matri <> "", desc_matri, 0)
    End If
               '1  2 3 4               5                                6                7              8CAM                  9        1011
    registro1 = "B;S;V;1;" & Form_Pagar_Mensualidad_hue.Text7.Text & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";0" & "1" & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";" & alumno_curso & ";;;"
               '12 - 16      17 ok            18              19                20             21ok            22ok
    registro2 = ";;;;;" & RutApoBol & ";" & NomApo & ";" & Replace(RutApoBol, "-", "") & ";" & MesBoleta & ";" & mail & ";" & direccion & ";"
              '         23                24ok           25ok   262728      29ok         30 - 40
    registro3 = "" & Combo1.Text & ";" & Comuna & ";" & Ciudad & ";;;;;;;;;;" & forma_pago & ";;;;;;" & MesBoleta
                 '42-58                    59                   60                61        62             636465         66           676869     70         71       72
    registro4 = ";;;;;;;;;;;;;;;;;;" & total_boleta & ";" & enumeracion_concepto & ";;" & detalle_producto & ";;1;1;" & valor_concepto & ";;;;" & desc_beca & ";;" & desc_otros & ";;;;;;;;"
                '81 - 153
    registro5 = ";;;;;;;;S;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
    Registro = registro1 & registro2 & registro3 & registro4 & registro5
    registro7 = registro7 & vbCrLf & Registro
    'Call AgregarRegistroCobranza(Base64EncodeString(Registro), ruta)
    Call AgregarRegistroCobranza(Registro, ruta2)
    'End If
        
    
        
    ' Talleres
    enumeracion_concepto = "B4"
    detalle_producto = "TALLERES"
    valor_concepto = taller.Text
    desc_beca = 0
    desc_otros = 0
               '1  2 3 4               5                                6                7              8CAM                  9        1011
    registro1 = "B;S;V;1;" & Form_Pagar_Mensualidad_hue.Text7.Text & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";0" & "1" & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";" & alumno_curso & ";;;"
               '12 - 16      17 ok            18              19                20             21ok            22ok
    registro2 = ";;;;;" & RutApoBol & ";" & NomApo & ";" & Replace(RutApoBol, "-", "") & ";" & MesBoleta & ";" & mail & ";" & direccion & ";"
              '         23                24ok           25ok   262728      29ok         30 - 40
    registro3 = "" & Combo1.Text & ";" & Comuna & ";" & Ciudad & ";;;;;;;;;;" & forma_pago & ";;;;;;" & MesBoleta
                 '42-58                    59                     60                61         62             636465          66         676869     70         71       72
    registro4 = ";;;;;;;;;;;;;;;;;;" & total_boleta & ";" & enumeracion_concepto & ";;" & detalle_producto & ";;1;1;" & valor_concepto & ";;;;" & desc_beca & ";;" & desc_otros & ";;;;;;;;"
                '81 - 153
    registro5 = ";;;;;;;;S;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
    Registro = registro1 & registro2 & registro3 & registro4 & registro5
    'registro6 = Registro
    registro7 = registro7 & vbCrLf & Registro
    Call AgregarRegistroCobranza(Registro, ruta2)
    
    
    
       ' Otros cobros
    enumeracion_concepto = "B5"
    detalle_producto = "OTROS COBROS"
    valor_concepto = txt_gastos_cobranza.Text
    desc_beca = 0
    desc_otros = 0
               '1  2 3 4               5                                6                7              8CAM                  9        1011
    registro1 = "B;S;V;1;" & Form_Pagar_Mensualidad_hue.Text7.Text & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";0" & "1" & ";" & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ";" & alumno_curso & ";;;"
               '12 - 16      17 ok            18              19                20             21ok            22ok
    registro2 = ";;;;;" & RutApoBol & ";" & NomApo & ";" & Replace(RutApoBol, "-", "") & ";" & MesBoleta & ";" & mail & ";" & direccion & ";"
              '         23                24ok           25ok   262728      29ok         30 - 40
    registro3 = "" & Combo1.Text & ";" & Comuna & ";" & Ciudad & ";;;;;;;;;;" & forma_pago & ";;;;;;" & MesBoleta
                 '42-58                    59                     60                61         62             636465          66         676869     70         71       72
    registro4 = ";;;;;;;;;;;;;;;;;;" & total_boleta & ";" & enumeracion_concepto & ";;" & detalle_producto & ";;1;1;" & valor_concepto & ";;;;" & desc_beca & ";;" & desc_otros & ";;;;;;;;"
                '81 - 153
    registro5 = ";;;;;;;;S;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
    Registro = registro1 & registro2 & registro3 & registro4 & registro5
    'registro6 = Registro
    registro7 = registro7 & vbCrLf & Registro
    Call AgregarRegistroCobranza(Registro, ruta2)
    
'''''    'Otros cobros obligatorios
'''''    enumeracion_concepto = "B5"
'''''    valor_concepto = 0
'''''    desc_beca = 0
'''''    desc_otros = 0
'''''               '1  2 3 4               5                                6                7              8CAM                  9        1011
'''''    registro1 = "B,S,V,1," & Form_Pagar_Mensualidad_hue.Text7.Text & "," & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & ",0" & "1" & "," & Format(FEmision, "dd") & "/" & Format(FEmision, "mm") & "/" & Format(FEmision, "yyyy") & "," & alumno_curso & ",,,"
'''''               '12 - 16      17 ok            18              19                20             21ok            22ok
'''''    registro2 = ",,,,," & RutApoBol & "," & NomApo & "," & Replace(RutApoBol, "-", "") & "," & MesBoleta & "," & mail & "," & direccion & ","
'''''              '         23                24ok           25ok   262728      29ok         30 - 40
'''''    registro3 = "" & Combo1.Text & "," & Comuna & "," & Ciudad & ",,,," & forma_pago & ",,,,,,,,,,,,"
'''''                 '41-53                    54cam            55      56      5758      59cam          60 - 71            72
'''''    registro4 = ",,,,,,,,,,,,," & enumeracion_concepto & ",," & taller & ",1,1," & valor_concepto & ",,,," & desc_beca & ",," & desc_otros & ",,,,,,,,"
'''''                '73 - 101
'''''    registro5 = ",,,,,,,,S,,,,,,,,,,,,,,,,,,,,,"
'''''    Registro = registro1 & registro2 & registro3 & registro4 & registro5
'''''    'registro6 = Registro
'''''    registro7 = registro7 & vbCrLf & Registro
'''''    'Call AgregarRegistroCobranza(Base64EncodeString(registro7), ruta)
'''''    Call AgregarRegistroCobranza(Registro, ruta2)
        
    'Exencion Becas
    'If MParcial > 0 Then
    
    'Lleno tabla con base 64
'    var_sql = "update fnza_temp_boleta_electronica set boleta = '" & registro7 & "',boleta_64='" & Base64EncodeString(registro7) & "';"
'    conn.Execute var_sql
    
    numero_coordinador = DevuelveCampo("usuarios", "", "numero_coordinador", "aut_nombre_usuario = '" & Nom_usu_ses & "'", conn)
    certificado_digital = DevuelveCampo("usuarios", "", "certificado_digital", "aut_nombre_usuario = '" & Nom_usu_ses & "'", conn)
    
    If numero_coordinador = 1 Then var_sql = "update fnza_temp_boleta_electronica set boleta = '" & registro7 & "',boleta_64='" & Base64EncodeString(registro7) & "',certificado_digital = '" & certificado_digital & "';"
    If numero_coordinador = 2 Then var_sql = "update fnza_temp_boleta_electronica_2 set boleta = '" & registro7 & "',boleta_64='" & Base64EncodeString(registro7) & "',certificado_digital = '" & certificado_digital & "';"
    If numero_coordinador = 3 Then var_sql = "update fnza_temp_boleta_electronica_3 set boleta = '" & registro7 & "',boleta_64='" & Base64EncodeString(registro7) & "',certificado_digital = '" & certificado_digital & "';"
    If numero_coordinador = 4 Then var_sql = "update fnza_temp_boleta_electronica_4 set boleta = '" & registro7 & "',boleta_64='" & Base64EncodeString(registro7) & "',certificado_digital = '" & certificado_digital & "';"
    If numero_coordinador = 5 Then var_sql = "update fnza_temp_boleta_electronica_5 set boleta = '" & registro7 & "',boleta_64='" & Base64EncodeString(registro7) & "',certificado_digital = '" & certificado_digital & "';"
    
    conn.Execute var_sql
    
    
    'Llamo aplicacion que se conecta con Web Service
    Shell App.Path & "\conector\WindowsApplication2.exe", vbNormalFocus
    
  
    'Insertar log
        sw = True
        GrillaDtll.Col = 1
        For I = 1 To Form_Pagar_Mensualidad_hue.GrillaDtll.Rows - 1
            GrillaDtll.Row = I
            If Form_Pagar_Mensualidad_hue.GrillaDtll.CellBackColor = CDbl(&HC0E0FF) And sw = True Then
                sw = False
                primer_mes = Form_Pagar_Mensualidad_hue.GrillaDtll.TextMatrix(I, 1)
            End If
        Next I
        sw = True
        I = Form_Pagar_Mensualidad_hue.GrillaDtll.Rows - 1
        GrillaDtll.Col = 1
        While I > 0
            GrillaDtll.Row = I
            Form_Pagar_Mensualidad_hue.grilla.Col = 1
            If Form_Pagar_Mensualidad_hue.GrillaDtll.CellBackColor = CDbl(&HC0E0FF) And sw = True Then
                sw = False
                ultimo_mes = Form_Pagar_Mensualidad_hue.GrillaDtll.TextMatrix(I, 1)
            End If
            I = I - 1
        Wend
        
        accion = "Crear Boleta"
        accion_detalle = "Se a impreso la boleta con folio " _
                       & Form_Pagar_Mensualidad_hue.Text7.Text _
                       & ", con monto " & val(Me.Text3.Text) & " para los meses de " _
                       & primer_mes & " hasta " & ultimo_mes
        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_hue.grilla.TextMatrix(Form_Pagar_Mensualidad_hue.grilla.Row, 0), _
        Form_Pagar_Mensualidad_hue.text2.Text, CStr(accion), CStr(accion_detalle), Form_Pagar_Mensualidad_hue.Text7.Text, Form_Pagar_Mensualidad_hue.Text7.Text)
        
        If Combo1.Text > 2021 And tcc > 0 Then
        accion = "Crear Boleta"
        accion_detalle = "Se a impreso la boleta con folio " _
                       & Form_Pagar_Mensualidad_hue.Text7.Text _
                       & ", con fecha de UF " & dtp_fecha_uf.Value & ", con valor de UF de " & txt_uf.Text
        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_hue.grilla.TextMatrix(Form_Pagar_Mensualidad_hue.grilla.Row, 0), _
        Form_Pagar_Mensualidad_hue.text2.Text, CStr(accion), CStr(accion_detalle), Form_Pagar_Mensualidad_hue.Text7.Text, Form_Pagar_Mensualidad_hue.Text7.Text)
        End If
        
        
        
    'Fin de log
        
'        accion = "Crear Boleta"
'        accion_detalle = "Se a impreso la boleta con folio " _
'                       & Form_Pagar_Mensualidad_hue.Text7.Text _
'                       & ", con monto " & val(Me.Text3.Text) & " para los meses de " _
'                       & primer_mes & " hasta " & ultimo_mes
'        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_hue.Grilla.TextMatrix(Form_Pagar_Mensualidad_hue.Grilla.Row, 0), _
'        Form_Pagar_Mensualidad_hue.text2.Text, CStr(accion), CStr(accion_detalle), 0, 0)
'    'Fin de log
        
        Verificar = MsgBox("¿Desea Agregar la Boleta de folio nº" & Text7.Text & " al Libro?", vbOKCancel + vbQuestion, "Agregar al Libro")
        If Verificar = 2 Then
    'Log
        accion = "Crear Boleta"
        accion_detalle = "El usuario NOOOO AGREGO al libro la boleta con folio " _
                       & Form_Pagar_Mensualidad_hue.Text7.Text _
                       & ", con monto " & val(Me.Text3.Text) & " para los meses de " _
                       & primer_mes & " hasta " & ultimo_mes
        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_hue.grilla.TextMatrix(Form_Pagar_Mensualidad_hue.grilla.Row, 0), _
        Form_Pagar_Mensualidad_hue.text2.Text, CStr(accion), CStr(accion_detalle), 0, 0)
    'Fin de log
           ' Unload Form_Pagar_Mensualidad_hue
            Exit Sub
        Else
            'Unload Form_Pagar_Mensualidad_hue
            Call Command4_Click
        End If
        Exit Sub
Controlerror:
    If Err.Number = 53 Then
        MsgBox "Usted no puede imprimir boletas ya que su impresora matriz de puntos no está configurada. Comuníquese con soporte.", vbCritical
        Call Command5_Click
    Else
        If Err.Number = 6 Then
            MsgBox "Seleccione solo una cuota para realizar el abono de 50%", vbCritical
        Call Command5_Click
        Else
            MsgBox "Alerta: " & Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbExclamation, "ALERTA DE ANOMALÍA"
        End If
    End If
    Resume
    
End Sub

Private Sub Command4_Click()
On Error GoTo Controlerror:
    Dim NumFolioOK As Integer
    Dim ProcPago As String
    Dim TipoPago As String
    Dim FormaPago As String
    Dim Detalle() As Long
    Dim DetallePago() As Long
    Dim TamDtll As Integer
    Dim TipoPagoCHQ As Integer
    Dim TipoPagoCON As Integer
    Dim monto As Long
    Dim accion, accion_detalle, primer_mes, ultimo_mes As String
    Dim sw As Boolean
    Dim I As Integer
    
    Dim ProcPago2 As String 'se agrega 24-05-2022
    Dim Tipopago2 As String 'se agrega 24-05-2022
    Dim FormaPago2 As String 'se agrega 24-05-2022

    'If Option1.Value = False And Option2.Value = False And Option3.Value = False And Option4.Value = False And Option5.Value = False And Option6.Value = False And Option7.Value = False Then
    If CboFormaPago1.ListIndex = -1 Then
        MsgBox "Primero debe seleccionar una forma de pago", vbInformation
        Exit Sub
    End If
    
    
    MontoTotal = 0
    If CboFormaPago1.ListIndex <> -1 Then
        If TxtMonto1.Text = "" Then
            MsgBox "Favor ingresar monto de forma de pago 1", vbInformation
            Exit Sub
        Else
            MontoTotal = MontoTotal + TxtMonto1.Text
        End If
    End If
    
    If CboFormaPago2.ListIndex <> -1 Then
        If TxtMonto2.Text = "" Then
            MsgBox "Favor ingresar monto de forma de pago 2", vbInformation
            Exit Sub
        Else
            MontoTotal = MontoTotal + val(TxtMonto2.Text)
        End If
    End If
    If MontoTotal <> val(Text3.Text) Then
        MsgBox "Montos de forma de pago no coincide con valor total, favor revisar", vbInformation
                Exit Sub
    End If
    
    TipoPagoCHQ = val(RetornaCampo("matriculas", "ind_cheq", "ci_alu='" & Me.grilla.TextMatrix(grilla.Row, 0) & "' AND anno_mat='" & Combo1.Text & "' AND ACTIVO_ALU='SI'", conn))
    TipoPagoCON = val(RetornaCampo("matriculas", "ind_cont", "ci_alu='" & Me.grilla.TextMatrix(grilla.Row, 0) & "' AND anno_mat='" & Combo1.Text & "' AND ACTIVO_ALU='SI'", conn))
    TipoPagoPAT = val(RetornaCampo("matriculas", "ind_pac", "ci_alu='" & Me.grilla.TextMatrix(grilla.Row, 0) & "' AND anno_mat='" & Combo1.Text & "' AND ACTIVO_ALU='SI'", conn))
    
''''''    Quito mensaje para jazmin
''''''    NumFolioOK = MsgBox("El Folio de Boleta Nº" & Text7.Text & vbCrLf & vbCrLf & " ¿Es Correcto?", vbOKCancel + vbQuestion, "Verificación de Folio")
''''''    If NumFolioOK = 2 Then Exit Sub
    
    'Contado
    'If Option1.Value Then
    If CboFormaPago1.ListIndex <> -1 Then
        If CboFormaPago1.ListIndex = 0 Then
            ProcPago = "caja"
            TipoPago = "ctdo"
            FormaPago = "al Contado"
            If TipoPagoCHQ = 1 Then
                If MsgBox("El alumno tiene tipo de pago CHEQUES para el año." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
                    Exit Sub
                End If
            End If
        End If
        'Cheque
        'If Option2.Value Then
        If CboFormaPago1.ListIndex = 1 Then
            ProcPago = "caja"
            TipoPago = "chqe"
            FormaPago = "con Cheque(s)"
            If TipoPagoCON = 1 Then
                If MsgBox("El alumno tiene tipo de pago CONTADO para el año." & vbCrLf & "Nota: El pago con un solo cheque al día es considerado al contado." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
                    Exit Sub
                End If
            End If
        End If
       'Tarjeta credito
        'If Option4.Value Then
        If CboFormaPago1.ListIndex = 2 Then
            ProcPago = "caja"
            TipoPago = "tcre"
            FormaPago = "con Tarjeta de Credito"
            If TipoPagoCON = 1 Or TipoPagoPAT = 1 Or TipoPagoCHQ = 1 Then
                If MsgBox("El alumno tiene tipo de pago CONTADO para el año." & vbCrLf & "Nota: El pago con un solo cheque al día es considerado al contado." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
                    Exit Sub
                End If
            End If
        End If
        'Tarjeta debito
        'If Option5.Value Then
        If CboFormaPago1.ListIndex = 3 Then
            ProcPago = "caja"
            TipoPago = "tdeb"
            FormaPago = "con Tarjeta de Debito"
            If TipoPagoCON = 1 Or TipoPagoPAT = 1 Or TipoPagoCHQ = 1 Then
                If MsgBox("El alumno tiene tipo de pago CONTADO para el año." & vbCrLf & "Nota: El pago con un solo cheque al día es considerado al contado." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
                    Exit Sub
                End If
            End If
        End If
        
        'UPAGO
        'If Option8.Value Then
        If CboFormaPago1.ListIndex = 4 Then
            ProcPago = "icup"
            TipoPago = "upag"
            FormaPago = "con Upago"
            If TipoPagoCON = 1 Or TipoPagoPAT = 1 Or TipoPagoCHQ = 1 Then
                If MsgBox("El alumno tiene tipo de pago CONTADO para el año." & vbCrLf & "Nota: El pago con un solo cheque al día es considerado al contado." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
                    Exit Sub
                End If
            End If
        End If
            'Transferencia
        'If Option9.Value Then
        If CboFormaPago1.ListIndex = 5 Then
            ProcPago = "caja"
            TipoPago = "tran"
            FormaPago = "con Transferencia"
            If TipoPagoCHQ = 1 Then
                If MsgBox("El alumno tiene tipo de pago CHEQUES para el año." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
                    Exit Sub
                End If
            End If
        End If
    End If
    'se agrega 24-05-2022 para seleccionar la segunda forma de pago
    'Contado
    'If Option1.Value Then
    If CboFormaPago2.ListIndex <> -1 Then
        If CboFormaPago2.ListIndex = 0 Then
            ProcPago2 = "caja"
            Tipopago2 = "ctdo"
            FormaPago2 = "al Contado"
    '        If TipoPagoCHQ = 1 Then
    '            If MsgBox("El alumno tiene tipo de pago CHEQUES para el año." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
    '                Exit Sub
    '            End If
    '        End If
        End If
        'Cheque
        'If Option2.Value Then
        If CboFormaPago2.ListIndex = 1 Then
            ProcPago2 = "caja"
            Tipopago2 = "chqe"
            FormaPago2 = "con Cheque(s)"
    '        If TipoPagoCON = 1 Then
    '            If MsgBox("El alumno tiene tipo de pago CONTADO para el año." & vbCrLf & "Nota: El pago con un solo cheque al día es considerado al contado." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
    '                Exit Sub
    '            End If
    '        End If
        End If
        'Tarjeta credito
        'If Option4.Value Then
        If CboFormaPago2.ListIndex = 2 Then
            ProcPago2 = "caja"
            Tipopago2 = "tcre"
            FormaPago2 = "con Tarjeta de Credito"
    '        If TipoPagoCON = 1 Or TipoPagoPAT = 1 Or TipoPagoCHQ = 1 Then
    '            If MsgBox("El alumno tiene tipo de pago CONTADO para el año." & vbCrLf & "Nota: El pago con un solo cheque al día es considerado al contado." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
    '                Exit Sub
    '            End If
    '        End If
        End If
        'Tarjeta debito
        'If Option5.Value Then
        If CboFormaPago2.ListIndex = 3 Then
            ProcPago2 = "caja"
            Tipopago2 = "tdeb"
            FormaPago2 = "con Tarjeta de Debito"
            'If TipoPagoCON = 1 Or TipoPagoPAT = 1 Or TipoPagoCHQ = 1 Then
            '    If MsgBox("El alumno tiene tipo de pago CONTADO para el año." & vbCrLf & "Nota: El pago con un solo cheque al día es considerado al contado." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
            '        Exit Sub
            '    End If
            'End If
        End If
        'UPAGO
        'If Option8.Value Then
        If CboFormaPago2.ListIndex = 4 Then
            ProcPago2 = "icup"
            Tipopago2 = "upag"
            FormaPago2 = "con Upago"
            'If TipoPagoCON = 1 Or TipoPagoPAT = 1 Or TipoPagoCHQ = 1 Then
            '    If MsgBox("El alumno tiene tipo de pago CONTADO para el año." & vbCrLf & "Nota: El pago con un solo cheque al día es considerado al contado." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
            '        Exit Sub
            '    End If
            'End If
        End If
            'Transferencia
        'If Option9.Value Then
        If CboFormaPago2.ListIndex = 5 Then
            ProcPago2 = "caja"
            Tipopago2 = "tran"
            FormaPago2 = "con Transferencia"
            'If TipoPagoCHQ = 1 Then
            '    If MsgBox("El alumno tiene tipo de pago CHEQUES para el año." & vbCrLf & vbCrLf & "¿Desea Continuar?", vbExclamation + vbYesNo, "ADVERTENCIA") = vbNo Then
            '        Exit Sub
            '    End If
            'End If
        End If
    End If
    
    mestrabajo = DevuelveCampo("cfg", "", "valor", "param = 'mes_trabajo'", conn)
    If Format(Dtp_Fec_emision.Value, "YYYYMM") <> mestrabajo Then
         MsgBox "Fecha invalida, debe ingresar una fecha perteneciente al mes de trabajo actual", vbInformation
         Exit Sub
    End If
    
        
    NumFolioOK = MsgBox("La forma de pago de la boleta es " & FormaPago & "." & vbCrLf & vbCrLf & " ¿Es Correcto?", vbOKCancel + vbQuestion, "Verificación de Forma de Pago")
    If NumFolioOK = 2 Then Exit Sub
        
    TamDtll = 0
    For I = 1 To UBound(CuotasPag)
        If CuotasPag(I) Then
            TamDtll = TamDtll + 1
            ReDim Preserve Detalle(1 To 2, 1 To TamDtll)
            Detalle(1, TamDtll) = GrillaDtll.TextMatrix(I, 0)
            Detalle(2, TamDtll) = GrillaDtll.TextMatrix(I, 11)
        End If
    Next I
    
    'vamos a revisar la forma de pago
     If CboFormaPago1.ListIndex <> -1 And CboFormaPago2.ListIndex <> -1 Then
        MontoAux = TxtMonto1.Text
        MontoAux2 = TxtMonto2.Text
        For I = 0 To UBound(Detalle) + 1
            j = j + 1
            
            
            If MontoAux > 0 Then
              
              Do While MontoAux > 0
                ReDim Preserve DetallePago(1 To 4, 1 To j)
                If MontoAux > Detalle(2, j) Then
                    DetallePago(1, j) = Detalle(1, j)  'folio
                    DetallePago(2, j) = Detalle(2, j)  'monto
                    DetallePago(3, j) = 1
                    MontoAux = MontoAux - Detalle(2, j)
                    j = j + 1
                Else
                    DetallePago(1, j) = Detalle(1, j)  'folio
                    DetallePago(2, j) = MontoAux  'monto
                    DetallePago(3, j) = 1
                    MontoAux = MontoAux - MontoAux
                     MontoFalta = Detalle(2, j) - DetallePago(2, j)
                    j = j + 1
                End If
              Loop
            End If
            If MontoAux2 > 0 Then
            

                If MontoFalta > 0 Then
                    ReDim Preserve DetallePago(1 To 4, 1 To j)
                    DetallePago(1, j) = Detalle(1, j - 1) 'folio
                    DetallePago(2, j) = MontoFalta 'monto
                    DetallePago(3, j) = 2
                    MontoAux2 = MontoAux2 - MontoFalta
                    MontoFalta = MontoFalta - MontoFalta
                End If
            
                Do While MontoAux2 > 0
                j = j + 1
                ReDim Preserve DetallePago(1 To 4, 1 To j)
                If MontoAux2 > Detalle(2, j - 1) Then
                    DetallePago(1, j) = Detalle(1, j)  'folio
                    DetallePago(2, j) = Detalle(2, j)  'monto
                    DetallePago(3, j) = 2
                    MontoAux2 = MontoAux2 - Detalle(2, j)
                    j = j + 1
                Else
                    DetallePago(1, j) = Detalle(1, j - 1) 'folio
                    DetallePago(2, j) = MontoAux2  'monto
                    DetallePago(3, j) = 2
                    MontoAux2 = MontoAux - MontoAux2
                    MontoFalta = Detalle(2, j - 1) - DetallePago(2, j)
                    j = j + 1
                End If
              Loop
            End If
        Next I
    End If

    
    
    'PROCESO QUE DISCRIMINA PAGOS EN BANCO ENVIADOS A COBRANZA.
    Dim EstadoCupon As String
    Dim Fvcto As Date
    Dim CabBol As String
    Dim MontoCupon As String
    

    
    For I = 1 To UBound(Detalle, 2)
        If Len(ImageCombo2.SelectedItem.Key) > 6 Then
            CabBol = RetornaCampo("CFG", "valor", "param='CodConvBCIBC'", conn)
        Else
            CabBol = ""
        End If
        Fvcto = RetornaCampo("fnza_detalle_mensualidad", "fech_venc", "folio_dtll='" & Detalle(1, I) & "'", conn)
        CabBol = CabBol & Year(Fvcto) & Format((Month(Fvcto) - 2), "00")
        EstadoCupon = RetornaCampo("fnza_cuponeras as c, fnza_deta_cupones as d", "d.estado", "c.folio_cuponera=d.folio_cuponera and c.esta_fin='PE' and c.rut_apo='" & Me.text2.Text & "' and d.vcto='" & Format(Fvcto, "yyyy-mm-dd") & "' and d.numero='" & CabBol & "'", conn)
        MontoCupon = RetornaCampo("fnza_cuponeras as c, fnza_deta_cupones as d", "d.valor", "c.folio_cuponera=d.folio_cuponera and c.esta_fin='PE' and c.rut_apo='" & Me.text2.Text & "' and d.vcto='" & Format(Fvcto, "yyyy-mm-dd") & "' and d.numero='" & CabBol & "'", conn)
        If EstadoCupon = "GC" Then
            conn.Execute "INSERT INTO fnza_elimina_cobranza(rut_apo,cab_bol,num_cup,fech_ven,monto,estado) VALUES ('" & Me.text2.Text & "','" & CabBol & "','" & (Month(Fvcto) - 2) & "','" & Format(Fvcto, "yyyy-mm-dd") & "','" & MontoCupon & "','eliminar') ON DUPLICATE KEY UPDATE rut_apo=rut_apo;"
        End If
    Next I
    
    'crear_boleta val(Text7.Text), Mid(ImageCombo2.SelectedItem.Key, 1, 6), Me.Text2.Text, Me.Grilla.TextMatrix(Grilla.Row, 0), Dtp_Fec_emision.Value, Dtp_Fec_emision.Value, val(Me.Text3.Text), ProcPago, TipoPago, Detalle, conn
    If CboFormaPago1.ListIndex <> -1 And CboFormaPago2.ListIndex <> -1 Then
        crear_boleta val(Text7.Text), Mid(ImageCombo2.SelectedItem.Key, 1, 6), Me.text2.Text, Me.grilla.TextMatrix(grilla.Row, 0), Dtp_Fec_emision.Value, _
                  Dtp_Fec_emision.Value, val(Me.Text3.Text), ProcPago, TipoPago, DetallePago, TipoPago, Tipopago2, val(Me.TxtMonto1.Text), val(Me.TxtMonto2.Text), conn
    Else
        crear_boleta val(Text7.Text), Mid(ImageCombo2.SelectedItem.Key, 1, 6), Me.text2.Text, Me.grilla.TextMatrix(grilla.Row, 0), Dtp_Fec_emision.Value, _
                     Dtp_Fec_emision.Value, val(Me.Text3.Text), ProcPago, TipoPago, Detalle, TipoPago, Tipopago2, val(Me.TxtMonto1.Text), val(Me.TxtMonto2.Text), conn
                     
                     
    End If
    
    
    'Insertar log
        sw = True
        GrillaDtll.Col = 1
        For I = 1 To Form_Pagar_Mensualidad_hue.GrillaDtll.Rows - 1
            GrillaDtll.Row = I
            If Form_Pagar_Mensualidad_hue.GrillaDtll.CellBackColor = CDbl(&HC0E0FF) And sw = True Then
                sw = False
                primer_mes = Form_Pagar_Mensualidad_hue.GrillaDtll.TextMatrix(I, 1)
            End If
        Next I
        sw = True
        I = Form_Pagar_Mensualidad_hue.GrillaDtll.Rows - 1
        GrillaDtll.Col = 1
        While I > 0
            GrillaDtll.Row = I
            Form_Pagar_Mensualidad_hue.grilla.Col = 1
            If Form_Pagar_Mensualidad_hue.GrillaDtll.CellBackColor = CDbl(&HC0E0FF) And sw = True Then
                sw = False
                ultimo_mes = Form_Pagar_Mensualidad_hue.GrillaDtll.TextMatrix(I, 1)
            End If
            I = I - 1
        Wend
        
        accion = "Crear Boleta"
        accion_detalle = "Se a AGREGADO AL LIBRO la boleta con folio " _
                       & Form_Pagar_Mensualidad_hue.Text7.Text _
                       & ", con monto " & val(Me.Text3.Text) & " para los meses de " _
                       & primer_mes & " hasta " & ultimo_mes
        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_hue.grilla.TextMatrix(Form_Pagar_Mensualidad_hue.grilla.Row, 0), _
        Form_Pagar_Mensualidad_hue.text2.Text, CStr(accion), CStr(accion_detalle), Form_Pagar_Mensualidad_hue.Text7.Text, Form_Pagar_Mensualidad_hue.Text7.Text)
        
        
        If Combo1.Text > 2021 And (primer_mes = "Marzo" Or primer_mes = "Abril" Or primer_mes = "Mayo" Or primer_mes = "Junio" Or primer_mes = "Julio" Or primer_mes = "Agosto" Or primer_mes = "Septiembre" Or primer_mes = "Octubre" Or primer_mes = "Noviembre" Or primer_mes = "Diciembre") Then
        accion_detalle = "Se a AGREGADO AL LIBRO la boleta con folio " _
                       & Form_Pagar_Mensualidad_hue.Text7.Text _
                       & ", con fecha de UF " & dtp_fecha_uf.Value & ", con valor de UF " & txt_uf.Text
        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_hue.grilla.TextMatrix(Form_Pagar_Mensualidad_hue.grilla.Row, 0), _
        Form_Pagar_Mensualidad_hue.text2.Text, CStr(accion), CStr(accion_detalle), Form_Pagar_Mensualidad_hue.Text7.Text, Form_Pagar_Mensualidad_hue.Text7.Text)
        End If
        
    'Fin de log
        
        
'        accion = "Crear Boleta"
'        accion_detalle = "Se a AGREGADO AL LIBRO la boleta con folio " _
'                       & Form_Pagar_Mensualidad_hue.Text7.Text _
'                       & ", con monto " & val(Me.Text3.Text) & " para los meses de " _
'                       & primer_mes & " hasta " & ultimo_mes
'        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_hue.Grilla.TextMatrix(Form_Pagar_Mensualidad_hue.Grilla.Row, 0), _
'        Form_Pagar_Mensualidad_hue.text2.Text, CStr(accion), CStr(accion_detalle), 0, 0)
'    'Fin de log
    
    
    ResetPago = True
    
    Command5_Click
    
    'If Option2.Value Then
    If CboFormaPago1.ListIndex = 1 Then
        Load Form_Ingreso_Cheques
        Form_Ingreso_Cheques.Flag_Sub_True
        Form_Ingreso_Cheques.Text1.Text = Me.grilla.TextMatrix(grilla.Row, 1)
        Form_Ingreso_Cheques.text2.Text = Me.grilla.TextMatrix(grilla.Row, 0)
        Form_Ingreso_Cheques.Flag_Sub_False
        Form_Ingreso_Cheques.Text1.Locked = True
        Form_Ingreso_Cheques.text2.Locked = True
        Form_Ingreso_Cheques.cmb_agno.Text = Combo1.Text
        Form_Ingreso_Cheques.Show
    End If
    
    Exit Sub
Controlerror:
    MsgBox "Alerta: " & Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbExclamation, "ALERTA DE ANOMALÍA"
    'Resume
End Sub

Private Sub Command5_Click()
    Frame1.Enabled = True
    Frame2.Enabled = True
    Frame3.Enabled = True
    Frame6.Enabled = True
    Frame12.Enabled = True
    Frame13.Enabled = True
    Command1.Enabled = True
    Command2.Enabled = True
    Frame8.Enabled = False
    Frame8.Visible = False
    
    If ResetPago Then
        Call ReseteaSeleccionBoleta
        Flag_sub = True
        Call SeteaGrillaMens
        Call LlenaGrillaMens
        Call SeteaGrillaDtll
        Call LlenaGrillaDtll
        Flag_sub = False
        ResetPago = False
    End If
    
End Sub
Private Sub Command6_Click()
    Dim objRS As New ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    If MsgBox("¿Esta seguro que desea aplicar el 5% a la mensualidad del apoderado?", vbOKCancel + vbCritical, "ADVERTENCIA") = vbOK Then
        Me.Frame1.Enabled = False
        Me.Frame2.Enabled = False
        Me.Frame3.Enabled = False
        Me.Frame4.Enabled = False
        Me.Frame5.Enabled = False
        Me.Frame6.Enabled = False
        Me.Frame7.Enabled = False
        Me.Frame12.Enabled = False
        Me.Frame13.Enabled = False
     
        RecalculaCuota_Apo Me.text2.Text, val(Combo1.Text), conn
        Call Cinco_por_cierto(text2.Text)
        Flag_sub = True
        Call LimpiaComboCol
        Call LlenaComboCol
        Flag_sub = False
        ImageCombo2.Refresh
        Call SeteaGrillaMens
        Call LlenaGrillaMens
        Call SeteaGrilla
        Call LlenaGrilla
        Call SeteaGrillaDtll
        Call LlenaGrillaDtll
        
        Me.Frame1.Enabled = True
        Me.Frame2.Enabled = True
        Me.Frame3.Enabled = True
        Me.Frame4.Enabled = True
        Me.Frame5.Enabled = True
        Me.Frame6.Enabled = True
        Me.Frame7.Enabled = True
        Me.Frame12.Enabled = True
        Me.Frame13.Enabled = True
    End If
    
End Sub

Private Sub Command7_Click()
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim rec As ADODB.Recordset
    Set rec = New ADODB.Recordset
'    var_sql = "select rut_apo from" _
'            & " (select * from" _
'            & " (select * from fnza_detalle_mensualidad f,matriculas m" _
'            & " where agno = 2009 and mes = 3 and monto_tot_cuota > 0 and" _
'            & " f.run_alu = m.ci_alu and f.agno = m.anno_mat and ind_mbeca = 0" _
'            & " and ind_beca = 0 and fec_mat >= '2008-12-01' and fec_mat <= '2008-12-31' and monto_exen_desc = 0 AND (monto_total - (monto_exen_hno + monto_exen_bca + monto_exen_desc + monto_exen_conv + monto_exen_tipo_pago)) = monto_tot_cuota and confirmado = 'SI') n," _
'            & " (select run_alu  from fnza_detalle_mensualidad f,matriculas m" _
'            & " where agno = 2008 and mes = 12 and f.run_alu = m.ci_alu and f.agno = m.anno_mat and confirmado = 'SI') a" _
'            & " where n.run_alu = a.run_alu) alu,apo_x_alu apo" _
'            & " where alu.run_alu = apo.ci_alu and alu.agno = apo.agno group by rut_apo"
            
    var_sql = "select distinct apo.rut_apo from fnza_boletas b,fnza_dtll_mvto n,fnza_movimientos_mensualidad m,fnza_detalle_mensualidad f," _
            & "(select distinct ind_cup,ci_alu,ind_beca,ind_mbeca from matriculas where anno_mat = 2009 and confirmado = 'SI' and ind_cup = 1) mm," _
            & "(select distinct ci_alu from matriculas where anno_mat = 2008 and confirmado = 'SI' and activo_alu = 'SI') mat,apo_x_alu apo" _
            & " Where b.folio_blta = n.folio_blta And n.folio_mvto = m.folio_mvto And n.folio_dtll = f.folio_dtll" _
            & " and f.agno = 2009 and f.concepto = 'ct00' and b.fecha_blta >= '2008-12-01' and b.fecha_blta <= '2008-12-31' and f.run_alu = mat.ci_alu" _
            & " and estado_pago = 'aprb' and f.run_alu = mm.ci_alu" _
            & " and apo.ci_alu = f.run_alu and apo.agno = 2009"


            
    objRS.Open var_sql, conn
    progreso.Value = 0
    progreso.Min = 0
    progreso.Max = objRS.RecordCount
    Label12.Caption = objRS.RecordCount
    Label4.Caption = "Descuento 5%"
    Frame_Actualizacion_Masivo.Visible = True
    Frame_Actualizacion_Masivo.Caption = "Generación de Masivo de 5%"
    
    While Not objRS.EOF
        var_sql = "select alu.run_alu,alu.monto_tot_cuota from" _
            & " (select * from" _
            & " (select * from fnza_detalle_mensualidad f,matriculas m" _
            & " where agno = 2009 and mes = 3 and monto_tot_cuota > 0 and" _
            & " f.run_alu = m.ci_alu and f.agno = m.anno_mat and ind_mbeca = 0 and ind_beca = 0) n," _
            & " (select run_alu  from fnza_detalle_mensualidad f,matriculas m" _
            & " where agno = 2008 and mes = 12 and f.run_alu = m.ci_alu and f.agno = m.anno_mat and confirmado = 'SI') a" _
            & " where n.run_alu = a.run_alu) alu,apo_x_alu apo" _
            & " where alu.run_alu = apo.ci_alu and alu.agno = apo.agno and rut_apo = '" & objRS("rut_apo") & "'"
        rec.Open var_sql, conn
            While Not rec.EOF
                var_sql = "update fnza_detalle_mensualidad set monto_exen_desc = 0" _
                        & " where agno = 2009 and run_alu = '" & rec("run_alu") _
                        & "' and concepto <> 'ct00' and monto_exen_desc <> 0"
                conn.Execute var_sql
                rec.MoveNext
            Wend
        rec.Close
        RecalculaCuota_Apo objRS("rut_apo"), val(2009), conn
        Call Cinco_por_cierto(objRS("rut_apo"))
        objRS.MoveNext
        Frame_Actualizacion_Masivo.Refresh
        progreso.Value = progreso.Value + 1
        Label13.Caption = progreso.Value
    Wend
    objRS.Close
    MsgBox "Proceso a finalizado exitosamente", vbInformation
End Sub

Private Sub Command8_Click()
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    var_sql = "update fnza_detalle_mensualidad set monto_exen_desc = 0" _
            & " Where agno = 2009 And monto_tot_cuota > 0 And monto_exen_desc <> 0"
    conn.Execute var_sql
    
    var_sql = "select rut_apo from" _
            & " (select * from" _
            & " (select * from fnza_detalle_mensualidad f,matriculas m" _
            & " where agno = 2009 and mes = 3 and monto_tot_cuota > 0 and" _
            & " f.run_alu = m.ci_alu and f.agno = m.anno_mat and ind_mbeca = 0 and ind_beca = 0 and fec_mat = '2008-12-31' and monto_exen_desc = 0 and (monto_total - (monto_exen_hno + monto_exen_bca + monto_exen_desc + monto_exen_conv + monto_exen_tipo_pago)) <> monto_tot_cuota) n," _
            & " (select run_alu  from fnza_detalle_mensualidad f,matriculas m" _
            & " where agno = 2008 and mes = 12 and f.run_alu = m.ci_alu and f.agno = m.anno_mat and confirmado = 'SI') a" _
            & " where n.run_alu = a.run_alu) alu,apo_x_alu apo" _
            & " where alu.run_alu = apo.ci_alu and alu.agno = apo.agno group by rut_apo"
    objRS.Open var_sql, conn
    progreso.Value = 0
    progreso.Min = 0
    progreso.Max = objRS.RecordCount
    Label12.Caption = objRS.RecordCount
    Label4.Caption = "Descuento 5%"
    Frame_Actualizacion_Masivo.Visible = True
    Frame_Actualizacion_Masivo.Caption = "Revertir 5%"
    
    While Not objRS.EOF
        RecalculaCuota_Apo objRS("rut_apo"), 2009, conn
        objRS.MoveNext
        Frame_Actualizacion_Masivo.Refresh
        progreso.Value = progreso.Value + 1
        Label13.Caption = progreso.Value
    Wend
    objRS.Close
    MsgBox "Proceso a finalizado exitosamente", vbInformation
End Sub

Private Sub Command9_Click()
    Dim objRS As New ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim rec As New ADODB.Recordset
    Set rec = New ADODB.Recordset
    Dim sw As Integer
    Dim exencion_cheques As Integer
    Dim pagos As Integer
    Dim Monto_Total As Long
    If MsgBox("¿Esta seguro que desea documentar con 10 cheques?", vbOKCancel + vbCritical, "ADVERTENCIA") = vbOK Then
   ' a = 10 Mod 3
   ' MsgBox a
    Dim var_sql As String
    
    ' Obtengo alumnos del apoderado
    var_sql = "SELECT ci_alu FROM apo_x_alu" _
            & " where rut_apo = '" & Me.text2.Text & "' and agno = " & val(Combo1.Text)
    objRS.Open var_sql, conn
    
    'Por cada alumno se hace este proceso
    While Not objRS.EOF
    
        ' Verifico que tenga tipo de pago cheques
        var_sql = "SELECT ind_cheq,monto_exen_tipo_pago" _
                & " FROM matriculas m,fnza_detalle_mensualidad f" _
                & " where m.anno_mat = f.agno and m.ci_alu = f.run_alu and mes = 5" _
                & " and m.ci_alu = '" & objRS("ci_alu") & "' and agno = " & val(Combo1.Text)
        rec.Open var_sql, conn
        sw = rec("ind_cheq")
        exencion_cheques = rec("monto_exen_tipo_pago")
        rec.Close
        
        ' Verifico que no tenga pagos efectuados
        var_sql = "select * from fnza_detalle_mensualidad where run_alu = '" & objRS("ci_alu") _
        & "' and agno = " & val(Combo1.Text) & " and monto_abono > 0"
        rec.Open var_sql, conn
        pagos = rec.RecordCount
        rec.Close
        
        ' Verifico que el alumno tenga tipo de pago cheques y que no tenga nada pagado
        If sw = 1 And exencion_cheques > 0 And pagos = 0 Then
            var_sql = "select sum(monto_total) as monto_total,sum(monto_tot_cuota) cuota,sum(monto_exen_conv) as convenio," _
                    & " sum(monto_exen_tipo_pago) tipo_pago,sum(monto_exen_hno) as hermano" _
                    & " from fnza_detalle_mensualidad" _
                    & " where run_alu = '" & objRS("ci_alu") & "' and agno = " & val(Combo1.Text)
            rec.Open var_sql, conn
            
            'Dejo en cero los cargos de febrero
            var_sql = "Update fnza_detalle_mensualidad set" _
                    & " monto_total = 0," _
                    & " monto_tot_cuota = 0," _
                    & " monto_exen_conv= 0," _
                    & " monto_exen_tipo_pago = 0," _
                    & " monto_exen_hno = 0" _
                    & " where run_alu = '" & objRS("ci_alu") & "' and agno = " & val(Combo1.Text) _
                    & " and mes = 2"
            conn.Execute var_sql
            
            If rec("monto_total") > 0 Then
                Monto_Total = (rec("monto_total") / 10)  '- CLng((REC("monto_total") Mod 10)))
            Else
                Monto_Total = 0
            End If
            
'            If REC("cuota") > 0 Then
'                cuota = CLng((REC("cuota") / 10)) '- CLng((REC("cuota") Mod 10)))
'            Else
'                cuota = 0
'            End If
            
            If rec("convenio") > 0 Then
                Convenio = CLng((rec("convenio") / 10)) ' - CLng((REC("convenio") Mod 10)))
            Else
                Convenio = 0
            End If
            If rec("tipo_pago") > 0 Then
                tipo_pago = CLng((rec("tipo_pago") / 10)) ' - CLng((REC("tipo_pago") Mod 10)))
            Else
                tipo_pago = 0
            End If
            If rec("hermano") > 0 Then
                hermano = CLng((rec("hermano") / 10)) ' - CLng((REC("hermano") Mod 10)))
            Else
                hermano = 0
            End If
            
            If rec("cuota") > 0 Then
                cuota = Monto_Total - (Convenio + hermano + tipo_pago)
                'cuota = CLng((REC("cuota") / 10)) '- CLng((REC("cuota") Mod 10)))
            Else
                cuota = 0
            End If
            
            
            'Ajusto los cargos de 11 cuotas a 10 cuotas
            var_sql = "Update fnza_detalle_mensualidad set" _
                    & " monto_total = " & Monto_Total & "," _
                    & " monto_tot_cuota = " & cuota & "," _
                    & " monto_exen_conv= " & Convenio & "," _
                    & " monto_exen_tipo_pago = " & tipo_pago & "," _
                    & " monto_exen_hno = " & hermano _
                    & " where run_alu = '" & objRS("ci_alu") & "' and agno = " & val(Combo1.Text) _
                    & " and mes > 2 and mes < 12"
            conn.Execute var_sql
            Monto_Total = 0
            cuota = 0
            Convenio = 0
            tipo_pago = 0
            hermano = 0
            If rec("monto_total") > 0 Then
                Monto_Total = CLng(rec("monto_total") / 10) + CLng((rec("monto_total") Mod 10))
            End If
'            If REC("cuota") > 0 Then
'                cuota = CLng(REC("cuota") / 10) + CLng((REC("cuota") Mod 10))
'            End If
            
            If rec("convenio") > 0 Then
                Convenio = CLng(rec("convenio") / 10) + CLng((rec("convenio") Mod 10))
            End If
            If rec("tipo_pago") > 0 Then
                tipo_pago = CLng((rec("tipo_pago") / 10)) + CLng((rec("tipo_pago") Mod 10))
            End If
            If rec("hermano") > 0 Then
                hermano = CLng((rec("hermano") / 10)) + CLng((rec("hermano") Mod 10))
            End If
                If rec("cuota") > 0 Then
                cuota = Monto_Total - (Convenio + hermano + tipo_pago)
                'cuota = CLng((REC("cuota") / 10)) '- CLng((REC("cuota") Mod 10)))
'            Else
'                cuota = 0
            End If
            
            ' La diferencia de los pesos se hace en diciembre
            var_sql = "Update fnza_detalle_mensualidad set" _
                    & " monto_total = " & Monto_Total & "," _
                    & " monto_tot_cuota = " & cuota & "," _
                    & " monto_exen_conv= " & Convenio & "," _
                    & " monto_exen_tipo_pago = " & tipo_pago & "," _
                    & " monto_exen_hno = " & hermano _
                    & " where run_alu = '" & objRS("ci_alu") & "' and agno = " & val(Combo1.Text) _
                    & " and mes = 12"
            conn.Execute var_sql
                    
            rec.Close
            
            'Log Recalcular
        accion = "Recalcular 10 cuotas"
        accion_detalle = "Se ha cambiado la mensualidad de 11 cuotas " _
                       & "a 10 cuotas"
        Call Inserta_Vitacora_Finanza(objRS("ci_alu"), _
        Form_Pagar_Mensualidad_hue.text2.Text, CStr(accion), CStr(accion_detalle), 0, 0)
    'Fin de log
            
        Else
            var_sql = "select concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as alumno" _
                    & " from postulantes where ci_alu = '" & objRS("ci_alu") & "'"
            rec.Open var_sql, conn
            MsgBox "El alumno " & rec("alumno") & " no cuenta con tipo de pago cheques o tiene cancelado febrero o algun mes del arancel", vbInformation
            rec.Close
        End If
        
        objRS.MoveNext
    Wend
    objRS.Close
    ' Busco totales por titular
    var_sql = "select mes,sum(monto_tot_cuota) as cuota from apo_x_alu a,fnza_detalle_mensualidad f" _
            & " where a.ci_alu = f.run_alu and a.agno = f.agno" _
            & " and f.agno = " & val(Combo1.Text) _
            & " and rut_apo = '" & Me.text2.Text & "'" _
            & " group by rut_apo,mes"
    objRS.Open var_sql, conn
    While Not objRS.EOF
        ' Modifico los totales del titular
        var_sql = "update fnza_mensualidad" _
               & " Set monto_mens = " & objRS("cuota") _
               & " where agno = " & val(Combo1.Text) & " and run_apo = '" & Me.text2.Text & "' and mes = " _
               & objRS("mes")
        conn.Execute var_sql
        objRS.MoveNext
    Wend
    objRS.Close
    
       Flag_sub = True
        Call LimpiaComboCol
        Call LlenaComboCol
        Flag_sub = False
        ImageCombo2.Refresh
        Call SeteaGrillaMens
        Call LlenaGrillaMens
        Call SeteaGrilla
        Call LlenaGrilla
        Call SeteaGrillaDtll
        Call LlenaGrillaDtll
        
        Me.Frame1.Enabled = True
        Me.Frame2.Enabled = True
        Me.Frame3.Enabled = True
        Me.Frame4.Enabled = True
        Me.Frame5.Enabled = True
        Me.Frame6.Enabled = True
        Me.Frame7.Enabled = True
        Me.Frame12.Enabled = True
        Me.Frame13.Enabled = True
        
 
    End If
End Sub

'Private Sub dtp_fecha_uf_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date)
''    txt_uf.Text = DevuelveCampo("fnza_valor_UF", "", "valor", "fecha = '" & Format(dtp_fecha_uf.Value, "yyyy-mm-dd") & "'", conn)
'End Sub

Private Sub dtp_fecha_uf_Change()
    txt_uf.Text = DevuelveCampo("fnza_valor_UF", "", "valor", "fecha = '" & Format(dtp_fecha_uf.Value, "yyyy-mm-dd") & "'", conn)
    If Combo1.Text > 2021 Then
        Call recalcula_UF(text2.Text, Format(dtp_fecha_uf.Value, "yyyy-mm-dd"), Combo1.Text)
        Combo1_Click
'        If (Text1.Text = "" Or Text2.Text = "") Then
'            Exit Sub
'        Else
'            If Flag_sub Then Exit Sub
'            Call ReseteaSeleccionBoleta
'            Flag_sub = True
'            Call LimpiaComboCol
'            Call LlenaComboCol
'            Flag_sub = False
'            Call SeteaGrillaMens
'            Call LlenaGrillaMens
'            Call SeteaGrilla
'            'If Combo1.Text > 2021 Then Call recalcula_UF(Text2.Text, Date, Combo1.Text)
'            Call LlenaGrilla
'            Call SeteaGrillaDtll
'            Call SeteaGrillaBlta
'        End If
    End If
End Sub
'
'Private Sub dtp_fecha_uf_Click()
'txt_uf.Text = DevuelveCampo("fnza_valor_UF", "", "valor", "fecha = '" & Format(dtp_fecha_uf.Value, "yyyy-mm-dd") & "'", conn)
'End Sub
'
'Private Sub dtp_fecha_uf_CloseUp()
'txt_uf.Text = DevuelveCampo("fnza_valor_UF", "", "valor", "fecha = '" & Format(dtp_fecha_uf.Value, "yyyy-mm-dd") & "'", conn)
'End Sub
'
'Private Sub dtp_fecha_uf_DblClick()
'txt_uf.Text = DevuelveCampo("fnza_valor_UF", "", "valor", "fecha = '" & Format(dtp_fecha_uf.Value, "yyyy-mm-dd") & "'", conn)
'End Sub
'
'Private Sub dtp_fecha_uf_LostFocus()
'txt_uf.Text = DevuelveCampo("fnza_valor_UF", "", "valor", "fecha = '" & Format(dtp_fecha_uf.Value, "yyyy-mm-dd") & "'", conn)
'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
    Text3.Text = 0
    Text4.Text = 0
    Text5.Text = 0
    Text6.Text = 0
    
    Call SeteaGrilla
    Call SeteaGrillaDtll
    Call SeteaGrillaMens
    
    Set RC = New ADODB.Recordset
    Frame3.Enabled = False
    Frame2.Enabled = False
    Frame8.Visible = False
    Frame8.Enabled = False
    Frame_taller.Visible = False
    frame_gastos_cobranza.Visible = False
    Call LlenaComboAgno
    dtp_fecha_uf.Value = Date
    txt_uf.Text = DevuelveCampo("fnza_valor_UF", "", "valor", "fecha = '" & Format(Date, "yyyy-mm-dd") & "'", conn)
    
    cb_tipo_taller.AddItem "ACADEMIA"
    cb_tipo_taller.AddItem "SELECCION"
    cb_tipo_cliente.AddItem "ALUMNO"
    cb_tipo_cliente.AddItem "APODERADO"
    
    
    'Tabla para guardar envios a cobranza desfazados.
    conn.Execute "CREATE TABLE IF NOT EXISTS fnza_elimina_cobranza (rut_apo varchar(10) NOT NULL default '', cab_bol varchar(100) NOT NULL default '', num_cup varchar(100) NOT NULL default '', fech_ven date NOT NULL default '0000-00-00', monto bigint(20) NOT NULL default '0', estado varchar(100) NOT NULL default '', PRIMARY KEY  (rut_apo,cab_bol,num_cup,fech_ven)) ENGINE=MyISAM;"
    
    '2022
    
    var_sql = "UPDATE fnza_detalle_mensualidad" _
            & " SET monto_total = monto_abono,monto_exen_hno = 0,monto_exen_bca = 0,monto_exen_desc = 0,monto_exen_conv = 0,monto_exen_tipo_pago = 0," _
            & " monto_tot_cuota = monto_abono,estado_dtll = 'clda'" _
            & " WHERE agno >= 2022 AND estado_dtll <> 'clda' AND estado_dtll <> 'impg' AND monto_tot_cuota > 0 AND concepto = 'esco';"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_mensualidad SET monto_mens = abono_mens,estado_mens = 'clda' WHERE agno >= 2022 AND estado_mens <> 'clda' AND estado_mens <> 'impg' AND mes > 2;"
    conn.Execute var_sql
    
    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'clda' WHERE agno >= 2022 AND monto_tot_cuota = monto_abono;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'abon' WHERE agno >= 2022 AND monto_tot_cuota > monto_abono AND monto_abono > 0;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'impg' WHERE agno >= 2022 AND monto_tot_cuota > monto_abono AND monto_abono = 0;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'cred' WHERE agno >= 2022 AND monto_tot_cuota < monto_abono and monto_tot_cuota > 0;"
    conn.Execute var_sql

    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'clda' WHERE agno >= 2022 AND monto_mens = abono_mens;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'abon' WHERE agno >= 2022 AND monto_mens > abono_mens AND abono_mens > 0;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'impg' WHERE agno >= 2022 AND monto_mens > abono_mens AND abono_mens = 0;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'cred' WHERE agno >= 2022 AND monto_mens < abono_mens;"
    conn.Execute var_sql
              
              
'''''''    '2020
'''''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;" '-- drop index clave on temp_bloquead
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.ci_alu,f.agno,f.mes) AS clave" _
'''''''            & " FROM fnza_lista_negra_apoderados f,apo_x_alu a WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2020 AND bloqueado = 1;"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'prot' WHERE CONCAT(run_alu,agno,mes) IN (SELECT clave FROM temp_bloquead);"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.rut_apo,f.agno,f.mes) AS clave FROM fnza_lista_negra_apoderados f,apo_x_alu a" _
'''''''            & " WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2020 AND bloqueado = 1;"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'prot' WHERE CONCAT(run_apo,agno,mes) IN (SELECT clave FROM temp_bloquead);"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
'''''''    conn.Execute var_sql
              
              
''''''    '2019
''''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;" '-- drop index clave on temp_bloquead
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.ci_alu,f.agno,f.mes) AS clave" _
''''''            & " FROM fnza_lista_negra_apoderados f,apo_x_alu a WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2019 AND bloqueado = 1;"
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'prot' WHERE CONCAT(run_alu,agno,mes) IN (SELECT clave FROM temp_bloquead);"
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;"
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.rut_apo,f.agno,f.mes) AS clave FROM fnza_lista_negra_apoderados f,apo_x_alu a" _
''''''            & " WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2019 AND bloqueado = 1;"
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'prot' WHERE CONCAT(run_apo,agno,mes) IN (SELECT clave FROM temp_bloquead);"
''''''    conn.Execute var_sql
''''''
''''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
''''''    conn.Execute var_sql
              
              
''''''''    '2017
''''''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;" '-- drop index clave on temp_bloquead
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.ci_alu,f.agno,f.mes) AS clave" _
''''''''            & " FROM fnza_lista_negra_apoderados f,apo_x_alu a WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2017  AND bloqueado = 1;"
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'prot' WHERE CONCAT(run_alu,agno,mes) IN (SELECT clave FROM temp_bloquead);"
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;"
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.rut_apo,f.agno,f.mes) AS clave FROM fnza_lista_negra_apoderados f,apo_x_alu a" _
''''''''            & " WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2017  AND bloqueado = 1;"
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'prot' WHERE CONCAT(run_apo,agno,mes) IN (SELECT clave FROM temp_bloquead);"
''''''''    conn.Execute var_sql
''''''''
''''''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
''''''''    conn.Execute var_sql
    
    
'''''''        '2018
'''''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;" '-- drop index clave on temp_bloquead
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.ci_alu,f.agno,f.mes) AS clave" _
'''''''            & " FROM fnza_lista_negra_apoderados f,apo_x_alu a WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2018 AND bloqueado = 1;"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'prot' WHERE CONCAT(run_alu,agno,mes) IN (SELECT clave FROM temp_bloquead);"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.rut_apo,f.agno,f.mes) AS clave FROM fnza_lista_negra_apoderados f,apo_x_alu a" _
'''''''            & " WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2018 AND bloqueado = 1;"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'prot' WHERE CONCAT(run_apo,agno,mes) IN (SELECT clave FROM temp_bloquead);"
'''''''    conn.Execute var_sql
'''''''
'''''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
'''''''    conn.Execute var_sql
    
    
''''    '2016
''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;"  '-- drop index clave on temp_bloquead
''''    conn.Execute var_sql
''''
''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.ci_alu,f.agno,f.mes) AS clave" _
''''            & " FROM fnza_lista_negra_apoderados f,apo_x_alu a WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2016 AND bloqueado = 1;"
''''    conn.Execute var_sql
''''
''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
''''    conn.Execute var_sql
''''
''''    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'prot' WHERE CONCAT(run_alu,agno,mes) IN (SELECT clave FROM temp_bloquead);"
''''    conn.Execute var_sql
''''
''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
''''    conn.Execute var_sql
''''    var_sql = "DROP TABLE IF EXISTS temp_bloquead;"
''''    conn.Execute var_sql
''''
''''    var_sql = "CREATE TABLE temp_bloquead SELECT CONCAT(a.rut_apo,f.agno,f.mes) AS clave FROM fnza_lista_negra_apoderados f,apo_x_alu a" _
''''            & " WHERE f.ci_apo = a.rut_apo AND f.agno = a.agno AND f.agno = 2016  AND bloqueado = 1;"
''''    conn.Execute var_sql
''''
''''    var_sql = "ALTER TABLE temp_bloquead ADD INDEX (clave);"
''''    conn.Execute var_sql
''''
''''    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'prot' WHERE CONCAT(run_apo,agno,mes) IN (SELECT clave FROM temp_bloquead);"
''''    conn.Execute var_sql
''''
''''    var_sql = "DROP INDEX clave ON temp_bloquead;"
''''    conn.Execute var_sql

var_sql = "UPDATE fnza_upago_recaudado r,fnza_mensualidad_pagare p SET monto_pagare = 0,pagare_pagado = 'SI'" _
        & " WHERE r.rut = p.run_apo AND r.vencimiento = DATE_FORMAT(DATE(DATE_ADD(p.fech_venc, INTERVAL 1 YEAR)),'%Y-%m-%d') AND r.concepto = 'Repactacion'"
conn.Execute var_sql

var_sql = "UPDATE fnza_upago_recaudado r,fnza_mensualidad_pagare_2023 p SET monto_pagare = 0,pagare_pagado = 'SI'" _
        & " WHERE r.rut = p.run_apo AND r.vencimiento = p.vencimiento AND r.concepto = 'Repactacion'"
conn.Execute var_sql
    
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 SeteaGrillaBlta
    Call GrillaDtll_SelChange
End Sub

Private Sub recalcula_UF(rut As String, Fecha As Date, agno As Integer)
    Dim objRS As New ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim rec As New ADODB.Recordset
    Set rec = New ADODB.Recordset
    Dim var_sql As String
    Dim valor As Double
    Dim total_UF As Double
    'Dim i As interger
    var_sql = "SELECT * FROM fnza_valor_uf WHERE fecha = '" & Format(Fecha, "yyyy-mm-dd") & "'"
    objRS.Open var_sql, conn
    If objRS.RecordCount = 0 Then
        objRS.Close
        MsgBox "No se ha ingresado valor de la UF del dia seleccionado"
        Exit Sub
    Else
        valor_uf = objRS("valor")
    End If
    objRS.Close
    var_sql = "SELECT * FROM apo_x_alu WHERE agno = " & agno & " AND rut_apo = '" & rut & "'"
    objRS.Open var_sql, conn
    total_UF = 0
    While Not objRS.EOF
        Rut_ALu = objRS("ci_alu")
        var_sql = "UPDATE fnza_detalle_mensualidad " _
                & " SET monto_total = monto_total_UF * " & Replace(valor_uf, ",", ".") & "," _
                & "monto_exen_desc = (monto_total_UF * " & Replace(valor_uf, ",", ".") & ") - (monto_tot_cuota_uf * " & Replace(valor_uf, ",", ".") & ")," _
                & "monto_tot_cuota = monto_tot_cuota_uf * " & Replace(valor_uf, ",", ".") _
                & " WHERE agno = " & agno & " AND run_alu = '" & objRS("ci_alu") & "' AND concepto = 'esco'" _
                & " and (estado_dtll = 'impg' or estado_dtll = 'abon')"
        conn.Execute var_sql
        
        var_sql = "UPDATE fnza_detalle_mensualidad" _
                & " SET monto_exen_desc = monto_total - monto_tot_cuota" _
                & " WHERE agno = " & agno & " AND run_alu = '" & objRS("ci_alu") & "' AND concepto = 'esco'" _
                & " and (estado_dtll = 'impg' or estado_dtll = 'abon')"
        conn.Execute var_sql

        var_sql = "SELECT monto_tot_cuota_UF FROM fnza_detalle_mensualidad WHERE agno = " & agno & " AND run_alu = '" & objRS("ci_alu") & "' AND concepto = 'esco' and (estado_dtll = 'impg' or estado_dtll = 'abon') LIMIT 1"
        rec.Open var_sql, conn
        If rec.RecordCount > 0 Then
            total_UF = total_UF + rec("monto_tot_cuota_UF")
        End If
        rec.Close
        
        objRS.MoveNext
    Wend
    objRS.Close
    
    var_sql = "UPDATE " _
            & "(SELECT rut_apo,SUM(monto_tot_cuota) mensu,f.agno,f.mes" _
            & " FROM fnza_detalle_mensualidad f,apo_x_alu a" _
            & " WHERE f.agno = a.agno AND f.run_alu = a.ci_alu AND f.agno = " & agno & " AND rut_apo = '" & rut & "'" _
            & " GROUP BY rut_apo,f.mes) AS m,fnza_mensualidad f" _
            & " Set f.monto_mens = m.Mensu" _
            & " WHERE m.rut_apo = f.run_apo AND m.agno = f.agno AND m.mes = f.mes AND f.agno = " & agno & " AND mensu <> monto_mens"
    conn.Execute var_sql
    
    If total_UF < 10 Then Exit Sub
    
    ''' vamos a probar
    var_sql = "select (monto_mens - abono_mens) as monto_mens from fnza_mensualidad where agno = " & agno & " and run_apo = '" & rut & "' and mes > 2 and estado_mens <> 'clda' and estado_mens <> 'cred' limit 1"
    rec.Open var_sql, conn
    If rec.RecordCount > 0 Then
        Monto_Mens = rec("monto_mens")
    End If
    rec.Close
      
    
    '''''' Igualo aproximación
    If Monto_Mens < Round(total_UF * valor_uf) Then
        Diferencia = Round(total_UF * valor_uf) - Monto_Mens
        var_sql = "UPDATE fnza_mensualidad SET monto_mens = (monto_mens + " & Diferencia _
                & ") WHERE agno = " & agno & " AND run_apo = '" & rut & "' AND mes > 2 AND (estado_mens = 'impg' OR estado_mens = 'abon')"
        conn.Execute var_sql
        
        var_sql = "UPDATE fnza_detalle_mensualidad" _
                & " SET monto_total = (monto_total + " & Diferencia & "),monto_tot_cuota = (monto_tot_cuota + " & Diferencia _
                & ") WHERE agno = " & agno & " AND run_alu = '" & Rut_ALu & "' AND concepto = 'esco' AND (estado_dtll = 'impg' OR estado_dtll = 'abon')"
        conn.Execute var_sql
                
        var_sql = "UPDATE fnza_detalle_mensualidad" _
                & " SET monto_exen_desc = monto_total - monto_tot_cuota" _
                & " WHERE agno = " & agno & " AND run_alu = '" & Rut_ALu & "' AND concepto = 'esco'" _
                & " and (estado_dtll = 'impg' or estado_dtll = 'abon')"
        conn.Execute var_sql
              
    End If
    
    '''''' Igualo aproximación
    If Monto_Mens > val(total_UF * valor_uf) Then
        Diferencia = Monto_Mens - Round(total_UF * valor_uf)
        var_sql = "UPDATE fnza_mensualidad SET monto_mens = (monto_mens - " & Diferencia _
                & ") WHERE agno = " & agno & " AND run_apo = '" & rut & "' AND mes > 2 AND (estado_mens = 'impg' OR estado_mens = 'abon')"
        conn.Execute var_sql
        
        var_sql = "UPDATE fnza_detalle_mensualidad" _
                & " SET monto_total = (monto_total - " & Diferencia & "),monto_tot_cuota = (monto_tot_cuota - " & Diferencia _
                & ") WHERE agno = " & agno & " AND run_alu = '" & Rut_ALu & "' AND concepto = 'esco' AND (estado_dtll = 'impg' OR estado_dtll = 'abon')"
        conn.Execute var_sql
    
        var_sql = "UPDATE fnza_detalle_mensualidad" _
                & " SET monto_exen_desc = monto_total - monto_tot_cuota" _
                & " WHERE agno = " & agno & " AND run_alu = '" & Rut_ALu & "' AND concepto = 'esco'" _
                & " and (estado_dtll = 'impg' or estado_dtll = 'abon')"
        conn.Execute var_sql
         
    End If
     
    
        
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)
    Call MostrarTotalBoleta
End Sub

Private Sub GrillaDtll_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Call GrillaDtll_DblClick
    End If
    If KeyAscii = 98 Or KeyAscii = 66 Then
        Call elimina_mensualidades
      
         
    End If
End Sub

Private Sub GrillaDtll_SelChange()
    'Llenado de la Grilla boletas
    Call SeteaGrillaBlta
    LlenaGrillaBlta val(GrillaDtll.TextMatrix(GrillaDtll.Row, 0))

End Sub

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

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


Private Sub List1_DblClick()
    Dim RC As ADODB.Recordset
    
    Text1.Text = List1.Text
    List1.Visible = False
    List2.Visible = False
    Set RC = New ADODB.Recordset
    RC.Open "SELECT rut_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(Text1.Text) & ")='" & Text1.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    RC.MoveFirst
    Flag_sub = True
    text2.Text = RC("rut_apo")
    RC.Close
    Call LimpiaComboCol
    Call LlenaComboCol
    Flag_sub = False
    ImageCombo2.Refresh
    Call SeteaGrillaMens
    Call LlenaGrillaMens
    Call SeteaGrilla
    If Combo1.Text > 2021 Then Call recalcula_UF(text2.Text, Format(dtp_fecha_uf.Value, "yyyy-mm-dd"), Combo1.Text)
'''''       If Combo1.Text >= 2023 Then
'''''            var_sql = "UPDATE fnza_mensualidad f,fnza_detalle_mensualidad ff,fnza_valor_matricula fv SET ff.monto_tot_cuota = fv.valor" _
'''''                    & " WHERE f.folio_mens = ff.folio_mens AND" _
'''''                    & " f.agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND concepto = 'ct00'" _
'''''                    & " AND ff.run_alu = fv.ci_alu AND ff.agno = fv.agno AND estado_dtll = 'impg'"
'''''            conn.Execute var_sql
'''''        End If
    Call LlenaGrilla
    Call SeteaGrillaDtll
    Call SeteaGrillaBlta
End Sub

Private Sub List2_DblClick()
    Dim RC As ADODB.Recordset
    text2.Text = List2.Text
    List2.Visible = False
    List1.Visible = False
    Set RC = New ADODB.Recordset
    RC.Open "SELECT CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo FROM apoderados where rut_apo='" & text2.Text & "' ORDER BY rut_apo;", conn
    RC.MoveFirst
    Flag_sub = True
    Text1.Text = RC("nombre_apo")
    RC.Close
    Call LimpiaComboCol
    Call LlenaComboCol
    Flag_sub = False
    ImageCombo2.Refresh
    Call SeteaGrillaMens
    Call LlenaGrillaMens
    Call SeteaGrilla
    If Combo1.Text > 2021 Then Call recalcula_UF(text2.Text, Format(dtp_fecha_uf.Value, "yyyy-mm-dd"), Combo1.Text)
''''       If Combo1.Text >= 2023 Then
''''            var_sql = "UPDATE fnza_mensualidad f,fnza_detalle_mensualidad ff,fnza_valor_matricula fv SET ff.monto_tot_cuota = fv.valor" _
''''                    & " WHERE f.folio_mens = ff.folio_mens AND" _
''''                    & " f.agno = " & Combo1.Text & " AND run_apo = '" & text2.Text & "' AND concepto = 'ct00'" _
''''                    & " AND ff.run_alu = fv.ci_alu AND ff.agno = fv.agno AND estado_dtll = 'impg'"
''''            conn.Execute var_sql
''''       End If
    Call LlenaGrilla
    Call SeteaGrillaDtll
    Call SeteaGrillaBlta
End Sub


Private Sub Text1_Change()
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If Text1.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
    
    Frame3.Enabled = False
    Frame2.Enabled = False
    Frame6.Enabled = False
    
    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"), val(Combo1.Text), conn), I
        RC.MoveNext
    Next I
    RC.Close
    Frame2.Enabled = True
    grilla.SetFocus
End Sub

Private Sub LlenaGrillaBlta(ByVal FolioDtll As Long)
    Dim QRY As String
    Dim rec As ADODB.Recordset
    Dim FolioChq As String
    Dim EstadoChq As String
    Dim RunApo As String
    Dim RunAlu As String
    
    RunAlu = grilla.TextMatrix(grilla.Row, 0)
    RunApo = text2.Text
    Label10.Caption = ""
    Frame14.Caption = "Información Adicional Mes de " & GrillaDtll.TextMatrix(GrillaDtll.Row, 1)
    
    QRY = "SELECT 'Boleta' as tipo_doc, fb.folio_blta_fisico as 'folio', fb.fecha_pago as 'fecha', fmm.monto_pago, fmm.tipo_pago, fmm.estado_pago as 'estado', fb.run_apo, fb.folio_blta, fmm.folio_mvto " & _
          "FROM fnza_boletas as fb, fnza_dtll_mvto as fdm, fnza_movimientos_mensualidad as fmm " & _
          "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' AND fdm.folio_mvto=fmm.folio_mvto " & _
          "Union " & _
          "SELECT 'N. Crédito' as tipo_doc, fn.folio_fisico_ntcr as 'folio', fn.fecha_ntcr as 'fecha', fdn.monto_pago, fn.tipo_pago, fn.estado_ntcr as 'estado', fn.run_apo, fdn.blta_rel as 'folio_blta', fdn.folio_dtll_ntcr as 'folio_mvto' " & _
          "FROM fnza_ntcr as fn, fnza_detalle_ntcr as fdn " & _
          "WHERE fn.folio_ntcr=fdn.folio_ntcr AND fdn.folio_dtll_rel=" & FolioDtll & " AND fdn.nulo='NO' " & _
          "ORDER BY folio_blta, tipo_doc, fecha;"
    
    Set rec = New ADODB.Recordset
    rec.Open QRY, conn
    
    If rec.RecordCount > 0 Then
        For I = 1 To rec.RecordCount
            GrillaBlta.AddItem rec!tipo_doc & Chr(9) & Format(rec("folio"), "0000000") & Chr(9) & rec("fecha") & Chr(9) & rec("monto_pago") & Chr(9) & TraduceTipoPago(rec("tipo_pago"), conn) & Chr(9) & TraduceEstadoPago(rec("estado"), conn) & Chr(9) & rec("run_apo"), I
            If Trim(rec("run_apo")) <> Trim(text2.Text) Then
                Label10.Caption = "El alumno tiene otro apoderado en la(s) boleta(s) de este mes."
            End If
            
            If rec("tipo_pago") = "chqe" And rec!tipo_doc = "Boleta" Then
                FolioChq = RetornaCampo("fnza_chq_mvto", "folio_chq", "folio_mvto='" & rec("folio_mvto") & "'", conn)
                If FolioChq <> "" Then
                    EstadoChq = RetornaCampo("fnza_cheques_recibidos", "estado_chq", "folio_chq=" & FolioChq & " ", conn)
                    GrillaBlta.TextMatrix(I, 7) = TraduceEstadoChq(EstadoChq, conn)
                    If EstadoChq = "acla" Or EstadoChq = "resc" Then
                        GrillaBlta.CellBackColor = &HC0FFFF
                        GrillaBlta.CellForeColor = &H0&
                    ElseIf EstadoChq = "prto" Or EstadoChq = "inco" Or EstadoChq = "cjud" Then
                        GrillaBlta.CellBackColor = &H80000005
                        GrillaBlta.CellForeColor = &HFF&
                    ElseIf EstadoChq = "gtia" Or EstadoChq = "dsto" Or EstadoChq = "endo" Or EstadoChq = "fact" Then
                        GrillaBlta.CellBackColor = &H80000005
                        GrillaBlta.CellForeColor = &HFF0000
                    Else
                        GrillaBlta.CellBackColor = &H80000005
                        GrillaBlta.CellForeColor = &H0
                    End If
                Else
                    GrillaBlta.TextMatrix(I, 7) = "Sin Reg."
                    GrillaBlta.CellBackColor = &H80000005
                    GrillaBlta.CellForeColor = &HFF00FF
                End If
            End If
            rec.MoveNext
        Next I
    End If
    rec.Close
    
End Sub

Private Sub LlenaGrillaDtll()
    Dim QR As String
    Dim RunAlu As String
    Dim MyRow As Integer
    
    ReDim CuotasFix(1 To 1)
    
    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_tipo_pago) as 'monto_exen_desc',monto_exen_conv,(monto_exen_hno + monto_exen_bca + monto_exen_desc + monto_exen_conv + monto_exen_tipo_pago) as exencion,monto_abono,cod_convenio,monto_tot_cuota, estado_dtll, mes, agno FROM fnza_detalle_mensualidad WHERE run_alu='" & RunAlu & "' AND colegio='" & ImageCombo2.SelectedItem.Key & "' AND agno='" & Combo1.Text & "' ORDER BY fech_venc,concepto;"
    
    QR = "DROP TABLE IF EXISTS temp_orden_mensualidades"
    conn.Execute QR
    
    QR = "CREATE TABLE temp_orden_mensualidades TYPE = MYISAM SELECT @ROW_NUMBER:=@ROW_NUMBER+1 AS ROW_NUMBER,temp_mensualidades.* from (SELECT folio_dtll,fech_venc,concepto,monto_total,monto_exen_hno,monto_exen_bca,(monto_exen_desc + monto_exen_tipo_pago) as 'monto_exen_desc',monto_exen_conv,(monto_exen_hno + monto_exen_bca + monto_exen_desc + monto_exen_conv + monto_exen_tipo_pago) as exencion,monto_abono,cod_convenio,monto_tot_cuota, estado_dtll, mes, agno,concat(tipo_taller,' - ',taller) as taller FROM fnza_detalle_mensualidad WHERE run_alu='" & RunAlu & "' AND colegio='" & ImageCombo2.SelectedItem.Key & "' AND agno='" & Combo1.Text & "' ORDER BY fech_venc,concepto) as temp_mensualidades,(SELECT @ROW_NUMBER:=0) r"
    conn.Execute QR
    
    QR = "UPDATE temp_orden_mensualidades SET row_number = row_number + 4"
    conn.Execute QR
    
    QR = "UPDATE temp_orden_mensualidades SET row_number = row_number - 3 WHERE concepto = 'ct00'"
    conn.Execute QR
    
    QR = "SELECT * FROM temp_orden_mensualidades ORDER BY row_number"
    
    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("taller"), I
        ReDim Preserve CuotasFix(1 To I)
        If (RC("estado_dtll") = "clda") 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)
    GrillaDtllSel 1
    GrillaDtll.Refresh
    RC.Close
    Frame3.Enabled = True
    GrillaDtll.SetFocus
End Sub

Private Sub LlenaGrillaMens()
    Dim QR As String
    Dim RunApo As String
    Call CajaUltimoFolio
    
    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
        ElseIf (RC("estado_mens") = "prot") Then
            GrillaMens.CellBackColor = &HFFFF00      '&HFFFF00
        End If
        RC.MoveNext
    Next I
    RC.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 fm.agno=" & Trim(Me.Combo1.Text) & " AND hc.colegio=fm.colegio Order By colegio"
    RC.Open QR, conn
    If RC.RecordCount = 0 Then
        ImageCombo2.ComboItems.Add 1, "none", "Sin Alumnos para el año " & Trim(Me.Combo1.Text)
        Set ImageCombo2.SelectedItem = ImageCombo2.ComboItems.Item(1)
        ImageCombo2.Refresh
        ImageCombo2.Enabled = False
        Btn_Recalcula.Enabled = False
        RC.Close
        Exit Sub
    Else
        Btn_Recalcula.Enabled = True
    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)
    ImageCombo2.Refresh
    If ImageCombo2.ComboItems.count <= 1 Then
        ImageCombo2.Enabled = False
    Else
        ImageCombo2.Enabled = True
    End If
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|>A Pagar|^Cod Estado|^Estado|<Fecha Venc.|^Cod Concepto|<Concepto"
    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  ' Descrip Concepto
    
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 SeteaGrillaBlta()
    Label10.Caption = ""
    GrillaBlta.ClearStructure
    GrillaBlta.Rows = 2
    GrillaBlta.FormatString = "^Tipo Doc.|^Folio|^Fecha|>Monto|^Forma Pago|^Estado|^Rut Apod.|^E. Chq."
    GrillaBlta.ColWidth(0) = 950 ' Tipo Doc.
    GrillaBlta.ColWidth(1) = 950 ' Folio
    GrillaBlta.ColWidth(2) = 950 ' Fecha
    GrillaBlta.ColWidth(3) = 950 ' Monto
    GrillaBlta.ColWidth(4) = 950 ' Forma_Pago
    GrillaBlta.ColWidth(5) = 950 ' Estado
    GrillaBlta.ColWidth(6) = 950 ' Rut Apoderado
    GrillaBlta.ColWidth(7) = 950 ' Estado Cheque
    
    'GrillaBlta.ColWidth(8) = 950 'Estado del Pago
    'GrillaBlta.ColWidth(9) = 900 'Tipo Documento
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 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
    
    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)) Then
                For e = MyRowFin To 1 Step -1
                    If Not CuotasFix(e) Then
                        GrillaDtllSel e
                        GrillaDtll.CellBackColor = &HC0E0FF
                        CuotasPag(e) = True
                    End If
                Next e
            Else
                For e = MyRowFin To UBound(CuotasPag)
                    If Not CuotasFix(e) Then
                        GrillaDtllSel e
                        Call ColorGrillaDtll(e)
                        CuotasPag(e) = False
                    End If
                Next e
            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
    ElseIf (GrillaDtll.TextMatrix(MyRow, 12) = "prot") Then
        GrillaDtll.CellBackColor = &HFFFF00
    Else
        GrillaDtll.CellBackColor = &HFFFFFF
    End If
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 MostrarTotalBoleta()
    Dim TotalPagar As Long
    Dim TotalExenc As Long
    Dim TotalAbono As Long
    Dim TotalCuota As Long
    Dim TotalExencBeca As Long
    Dim inco As Long
    Dim matri As Long
    Dim esco As Long
    Dim t_c As Integer
    Dim c_c As Long
    Dim gc As Long
    TotalExencBeca = 0
    TotalPagar = 0
    TotalExenc = 0
    TotalCuota = 0
    TotalAbono = 0
        
    '' Limpiamos variables de taller
    c_c_t = 0
    taller.Text = 0
    nombre_taller.Text = ""
    
    t_c = 0
    For I = 1 To UBound(CuotasPag)
        If CuotasPag(I) Then
            If GrillaDtll.TextMatrix(I, 15) = "inco" Then
                inco = val(GrillaDtll.TextMatrix(I, 11))
            End If
            If GrillaDtll.TextMatrix(I, 15) = "ct00" Then
                matri = val(GrillaDtll.TextMatrix(I, 3))
            End If
            If GrillaDtll.TextMatrix(I, 15) = "esco" Then
                t_c = t_c + 1
                esco = esco + val(GrillaDtll.TextMatrix(I, 11))
                c_c = c_c + val(GrillaDtll.TextMatrix(I, 3))
            End If
            If Mid(GrillaDtll.TextMatrix(I, 15), 1, 3) = "aca" Then
               t_c_t = t_c_t + 1
                c_c_t = c_c_t + val(GrillaDtll.TextMatrix(I, 3))
                nombre_taller.Text = GrillaDtll.TextMatrix(I, 17)
            End If
            If Mid(GrillaDtll.TextMatrix(I, 15), 1, 3) = "gco" Then
               't_c_t = t_c_t + 1
               'c_c_t = c_c_t + val(GrillaDtll.TextMatrix(I, 3))
               ' nombre_taller.Text = GrillaDtll.TextMatrix(I, 17)
               gc = val(GrillaDtll.TextMatrix(I, 11))
            End If
            TotalCuota = TotalCuota + val(GrillaDtll.TextMatrix(I, 3))
            TotalExencBeca = TotalExencBeca + val(GrillaDtll.TextMatrix(I, 5))
            TotalExenc = TotalExenc + val(GrillaDtll.TextMatrix(I, 8))
            TotalAbono = TotalAbono + val(GrillaDtll.TextMatrix(I, 9))
            TotalPagar = TotalPagar + val(GrillaDtll.TextMatrix(I, 11))
        End If
    Next I
    TxtMonto1.Text = str(TotalPagar)
    Text3.Text = str(TotalPagar)
    Text4.Text = str(TotalExenc)
    Text6.Text = str(TotalAbono)
    Text5.Text = str(TotalCuota)
    Text8.Text = str(TotalExencBeca)
    Text9.Text = str(TotalExenc - TotalExencBeca)
    incor.Text = inco
    matric.Text = matri
    escol.Text = esco
    taller.Text = c_c_t
    t_cu.Text = t_c
    c_co.Text = c_c
    txt_gastos_cobranza.Text = gc
End Sub

Private Sub CajaUltimoFolio()
    Label8.Caption = ImageCombo2.SelectedItem.Text
    Label7.Caption = Ult_Folio_Fisico(ImageCombo2.SelectedItem.Key, conn)
End Sub

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

Private Sub Llena_Vista_Boleta()
    Dim mes_cancelado As String
    Dim NumLet As clsNum2Let
    
    Set NumLet = New clsNum2Let
    ' Folio Sugerido de la Boleta
    Form_Boleta_Imprimir.Label2.Caption = Me.Text7.Text
    ' Nombre del Colegio
    Form_Boleta_Imprimir.Label1.Caption = Me.Label8.Caption
    ' Nombre Apoderado
    Form_Boleta_Imprimir.Text1.Text = Me.Text1.Text
    ' Run Apoderado
    Form_Boleta_Imprimir.text2.Text = Me.text2.Text
    ' Nombre Alumno
    Form_Boleta_Imprimir.Text3.Text = Me.grilla.TextMatrix(grilla.Row, 1)
    ' Mes(es) cancelados
    If nombre_taller.Text = "" Then
        mes_cancelado = CalculaMeses(Me.grilla.TextMatrix(grilla.Row, 0), val(Combo1.Text))
    Else
        mes_cancelado = nombre_taller.Text
    End If
    Form_Boleta_Imprimir.Text4.Text = mes_cancelado
    ' Curso del alumno
    Form_Boleta_Imprimir.Text5.Text = CursoAlumno(Me.grilla.TextMatrix(grilla.Row, 0), val(Combo1.Text), conn)
    ' Total (La Suma de)
    Form_Boleta_Imprimir.Text6.Text = Me.Text3.Text
    ' total en palabras
    NumLet.Numero = val(Me.Text3.Text)
    Form_Boleta_Imprimir.Text7.Text = NumLet.ALetra
    ' Hacer funcion que calcula año(s) de detalle(s)
    Form_Boleta_Imprimir.Text8.Text = Combo1.Text
    ' Total de las cuotas
    Form_Boleta_Imprimir.Text9.Text = "0" 'Me.Text5.Text
    ' Monto Mensual
    Form_Boleta_Imprimir.Text10.Text = IIf(val(Text6.Text) > 0, Me.Text5.Text & "-(" & Text6.Text & ")Abono", Me.Text5.Text)
    ' Exencion sistema becas
    Form_Boleta_Imprimir.Text11.Text = Me.Text4.Text
    ' total a pagar escolaridad
    Form_Boleta_Imprimir.Text12.Text = Me.Text3.Text
    ' aportes donaciones
    Form_Boleta_Imprimir.Text13.Text = "0"
    ' centro de padres
    Form_Boleta_Imprimir.Text14.Text = "0"
    ' otros cobros obligatorios
    Form_Boleta_Imprimir.Text15.Text = "0"
    ' TOTAL
    Form_Boleta_Imprimir.Text16.Text = Me.Text3.Text
    ' Fecha
    Form_Boleta_Imprimir.Text17.Text = Dtp_Fec_emision.Value
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;"
        QR = "SELECT let_cur" _
           & " FROM alu_x_cur WHERE ci_alu='" & RunAlu & "' AND agno = " & Combo1.Text & " and activo_alu = 'SI';"
        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

Function CalculaMeses(ByVal RunAlu As String, ByVal agno As Integer) As String
    Dim Cadena As String
    Dim CadenaFin As String
    Dim SwFirst As Boolean
    Dim CuotaCero As Integer

    SwFirst = False
    CadenaFin = ""
    Cadena = ""
    For I = 1 To UBound(CuotasPag)
        If CuotasPag(I) Then
            If Not (SwFirst) Then
                CuotaCero = MesCuotaCero(RunAlu, agno, conn)
                If (Month(GrillaDtll.TextMatrix(I, 14)) = CuotaCero) Then
                    If RetornaCampo("CFG", "valor", "param='CODBC'", conn) = "FLO001" Then
                        Cadena = GrillaDtll.TextMatrix(I + 1, 1) '& " 1/" & (GrillaDtll.Rows - 2) Yo
                    Else
                        'Cadena = " Cuota " & " 1/11"
                        'Cadena = " Cuota " & " 1/" & (GrillaDtll.Rows - 2)
                        Cadena = "Matricula "
                    End If
                ElseIf (Month(GrillaDtll.TextMatrix(I, 14)) = (CuotaCero + 1)) Then
                    If RetornaCampo("CFG", "valor", "param='CODBC'", conn) = "FLO001" Then
                        Cadena = GrillaDtll.TextMatrix(I, 1) ' & " 2/" & (GrillaDtll.Rows - 2) Yo
                    Else
                        Cadena = GrillaDtll.TextMatrix(I, 1) & "  " 'Yo
                    End If
                Else
                    If GrillaDtll.TextMatrix(I, 1) = "Enero" Then
                        Cadena = "Cuota Incorporación"
                    Else
                        Cadena = GrillaDtll.TextMatrix(I, 1)
                    End If
                End If
                If Mid(GrillaDtll.TextMatrix(I, 15), 1, 3) <> "gco" Then SwFirst = True
            Else
                CadenaFin = " a " & IIf(GrillaDtll.TextMatrix(I, 1) = "Febrero", "Matricula ", GrillaDtll.TextMatrix(I, 1)) '& " " & GrillaDtll.TextMatrix(i, 2)
            End If
        End If
    Next I
    CalculaMeses = Cadena & CadenaFin & "_" & agno
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 = 1
    Flag_sub = False
End Sub

Public Function Cinco_por_cierto(rut_apo As String) As Boolean
    Dim sw As Boolean
    Dim cant_cuotas As Integer
    Dim monto_apo As Long
    Dim total As Long
    Dim ct00 As Long
    Dim descuento As Long
    Dim valor As Double
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim rec As ADODB.Recordset
    Set rec = New ADODB.Recordset
    var_sql = "select valor from cfg where param = 'CODBC'"
    objRS.Open var_sql, conn
    If objRS("valor") = "LIN001" Then
        cant_cuotas = 10
    Else
        cant_cuotas = 11
    End If
    objRS.Close
    
    var_sql = "select alu.run_alu,alu.monto_tot_cuota from" _
            & " (select * from" _
            & " (select * from fnza_detalle_mensualidad f,matriculas m" _
            & " where agno = 2009 and mes = 3 and monto_tot_cuota > 0 and" _
            & " f.run_alu = m.ci_alu and f.agno = m.anno_mat and ind_mbeca = 0 and ind_beca = 0 and confirmado = 'SI') n," _
            & " (select run_alu  from fnza_detalle_mensualidad f,matriculas m" _
            & " where agno = 2008 and mes = 12 and f.run_alu = m.ci_alu and f.agno = m.anno_mat and confirmado = 'SI') a" _
            & " where n.run_alu = a.run_alu) alu,apo_x_alu apo" _
            & " where alu.run_alu = apo.ci_alu and alu.agno = apo.agno and rut_apo = '" & rut_apo & "'"
    objRS.Open var_sql, conn
    monto_apo = 0
    While Not objRS.EOF
        sw = False
        var_sql = "select m.fech_pago from fnza_detalle_mensualidad f,fnza_movimientos_mensualidad m" _
                & " where concepto = 'ct00' and run_alu = '" & objRS("run_alu") _
                & "' and agno = 2009 and f.folio_dtll = m.folio_dtll" _
                & " and m.fech_pago >= '2008-12-01' and m.fech_pago <= '2008-12-31'"
        rec.Open var_sql, conn
        If rec.RecordCount > 0 Then
            sw = True
        Else
            sw = False
        End If
        rec.Close
        
        If sw = True Then
            var_sql = "SELECT monto_exen_desc FROM fnza_detalle_mensualidad where run_alu = '" & objRS("run_alu") & "' and agno = 2009"
            rec.Open var_sql, conn
            If rec("monto_exen_desc") = 0 Then
                sw = True
            Else
                sw = False
            End If
            rec.Close
        End If
                
        If sw = True Then
            var_sql = "SELECT monto_tot_cuota as m" _
                    & " FROM fnza_detalle_mensualidad where run_alu = '" & objRS("run_alu") & "' and" _
                    & " agno = 2009 and concepto = 'ct00' limit 1"
            rec.Open var_sql, conn
            If Not rec.EOF Then
                ct00 = rec("m")
            Else
                ct00 = 0
            End If
        
            rec.Close
        
            valor = ((objRS("monto_tot_cuota") * cant_cuotas) - (objRS("monto_tot_cuota") * cant_cuotas) * 0.05)
            valor = (valor - ct00) / 10
            valor = objRS("monto_tot_cuota") - valor
            total = Round(valor)
            var_sql = "Update fnza_detalle_mensualidad" _
                    & " set monto_tot_cuota = monto_tot_cuota - " & total & ",monto_exen_desc = " & total _
                    & " where run_alu = '" & objRS("run_alu") & "' and agno = 2009 and mes <> 2"
            conn.Execute var_sql
            monto_apo = monto_apo + total
        End If
        objRS.MoveNext
    Wend
    objRS.Close
    For I = 3 To 12
        var_sql = "select sum(monto_tot_cuota) as deuda" _
                & " from fnza_detalle_mensualidad f,matriculas m,apo_x_alu a" _
                & " where f.agno = 2009 and mes = " & I & " and f.run_alu = m.ci_alu and f.agno = m.anno_mat and f.agno = a.agno and f.run_alu = a.ci_alu and rut_apo = '" & rut_apo & "'" _
                & " and length(colegio) = 6"
        objRS.Open var_sql, conn
        If Not objRS.EOF Then
        var_sql = "update fnza_mensualidad set monto_mens = " & objRS("deuda") _
                & " where run_apo = '" & rut_apo & "' and agno=2009 and mes = " & I
        conn.Execute var_sql
        End If
        objRS.Close
    Next I
End Function

Private Function elimina_mensualidades()
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    Dim folio_dtll As Long
    Dim th As Integer
    Dim ci_alu As String
    Dim ci_apo As String
    Dim agnno As Integer
    Dim mes As Integer
    Dim monto_abono As Long
    Dim monto_tot_cuota As Long
    Dim colegio As String
    Dim borrar As Integer
    
    var_sql = "SELECT borrar_mensualidades as b FROM usuarios where aut_nombre_usuario = '" & Nom_usu_ses & "'"
    objRS.Open var_sql, conn
    borrar = objRS("b")
    objRS.Close
    
    If borrar = 0 Then
        MsgBox "Ud. no tiene privilegios para borrar las mensualidades", vbInformation
        Exit Function
    End If
    
'    MsgBox GrillaDtll.TextMatrix(GrillaDtll.Row, 9)
    folio_dtll = GrillaDtll.TextMatrix(GrillaDtll.Row, 0)
    
    'Busco ruts
    var_sql = "select run_alu,agno,mes,monto_abono,colegio,monto_tot_cuota from fnza_detalle_mensualidad" _
            & " Where folio_dtll = " & folio_dtll
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        ci_alu = objRS("run_alu")
        'ci_apo = objRS("run_apo")
        agnno = objRS("agno")
        mes = objRS("mes")
        monto_abono = objRS("monto_abono")
        colegio = objRS("colegio")
        monto_tot_cuota = objRS("monto_tot_cuota")
    End If
    objRS.Close
        
    'Busco cantidad de hermanos
    var_sql = "select count(c.ci_alu) as t from (select distinct ci_alu,anno_mat as agno from matriculas where anno_mat = " & agnno & ") c,apo_x_alu a,fnza_detalle_mensualidad f" _
            & " where c.agno = a.agno and c.agno = " & agnno & " and c.ci_alu = a.ci_alu and" _
            & " c.agno = f.agno and c.ci_alu = f.run_alu and mes = " & mes & " and  rut_apo = '" & Me.text2.Text & "' and f.colegio = '" & colegio & "'"
    objRS.Open var_sql, conn
    th = objRS("t")
    objRS.Close
            
    If monto_abono > 0 Then
        MsgBox "Mensualidad no se puede eliminar,porque ya esta cancelada", vbInformation
        Exit Function
    Else
        var_sql = "update fnza_mensualidad set monto_mens = (monto_mens - " & monto_tot_cuota & ")" _
                & " where run_apo = '" & Me.text2.Text & "' and mes = " & mes _
                & " and agno = " & agnno & " and colegio = '" & colegio & "'"
        conn.Execute var_sql
        
        If th < 2 Then
            var_sql = "delete from fnza_mensualidad" _
                    & " where run_apo = '" & Me.text2.Text & "' and mes = " & mes & " and" _
                    & " agno = " & agnno & " and colegio = '" & colegio & "' and abono_mens = 0"
            conn.Execute var_sql
        End If
        var_sql = "delete from fnza_detalle_mensualidad where folio_dtll = " & folio_dtll
        conn.Execute var_sql
        MsgBox "Mensualidad fue eliminada satisfactoriamente", vbInformation
    End If
    
        Flag_sub = True
        Call LimpiaComboCol
        Call LlenaComboCol
        Flag_sub = False
        ImageCombo2.Refresh
        Call SeteaGrillaMens
        Call LlenaGrillaMens
        Call SeteaGrilla
        Call LlenaGrilla
        Call SeteaGrillaDtll
        Call LlenaGrillaDtll
        
        Me.Frame1.Enabled = True
        Me.Frame2.Enabled = True
        Me.Frame3.Enabled = True
        Me.Frame4.Enabled = True
        Me.Frame5.Enabled = True
        Me.Frame6.Enabled = True
        Me.Frame7.Enabled = True
        Me.Frame12.Enabled = True
        Me.Frame13.Enabled = True
End Function

Function Crear_Archivo_Cobranza(ruta As String) As Boolean
On Error GoTo Controlerror:
    'ArchBCI = "\\" & Form_main.Winsock1.LocalIP & "\Reg_Cobranza\" & "deuda.txt"
    ArchBCI = ruta
    Crear_Archivo_Cobranza = False
    Canc = FreeFile
    Open ArchBCI For Output As #Canc
    Close #Canc

    Crear_Archivo_Cobranza = True
    Exit Function
Controlerror:
    Err.Raise Err.Number, "CrearArchBCI->" & Err.Source, Err.Description
    Resume
End Function

Function AgregarRegistroCobranza(Registro As String, ruta As String) As Boolean
On Error GoTo Controlerror:
    Dim num_arch As Integer
    
    AgregarRegistroCobranza = False
    
    num_arch = FreeFile
    Arch = ruta
    Open Arch For Append As #num_arch
        Print #num_arch, Registro
    Close #num_arch
    AgregarRegistroCobranza = True
    Exit Function
Controlerror:
    Err.Raise Err.Number, "AgregarRegistroArchivoGeneracion->" & Err.Source, Err.Description
End Function

Private Sub txt_salir_Click()
    Frame_taller.Visible = False
End Sub

Private Sub txt_taller_Change()
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

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