VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
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_elec 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Pago de Mensualidades"
   ClientHeight    =   11040
   ClientLeft      =   1800
   ClientTop       =   1590
   ClientWidth     =   13005
   FillStyle       =   0  'Solid
   Icon            =   "Form_Pagar_Mensualidad_elec.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   11040
   ScaleWidth      =   13005
   Begin VB.Frame Frame15 
      Caption         =   "Descuentos"
      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            =   120
      TabIndex        =   60
      Top             =   9120
      Width           =   8295
      Begin MSFlexGridLib.MSFlexGrid GrillaDescuentos 
         Height          =   1455
         Left            =   120
         TabIndex        =   61
         Top             =   240
         Width           =   8055
         _ExtentX        =   14208
         _ExtentY        =   2566
         _Version        =   393216
         Cols            =   3
         FixedCols       =   0
         GridLines       =   0
         GridLinesFixed  =   0
         FormatString    =   "^Descuento|^Porcentaje|^Observación"
         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
      End
   End
   Begin VB.Frame Frame6 
      Caption         =   "Colegio"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   855
      Left            =   8520
      TabIndex        =   11
      Top             =   120
      Width           =   3135
      Begin MSComctlLib.ImageCombo ImageCombo2 
         Height          =   345
         Left            =   240
         TabIndex        =   6
         Top             =   360
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Locked          =   -1  'True
      End
   End
   Begin VB.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        =   58
      Top             =   2640
      Width           =   1575
   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        =   57
      Text            =   "Text9"
      Top             =   10560
      Visible         =   0   'False
      Width           =   1335
   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        =   55
      Text            =   "Text8"
      Top             =   10320
      Visible         =   0   'False
      Width           =   1335
   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        =   43
      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          =   2055
      Left            =   120
      TabIndex        =   46
      Top             =   6960
      Width           =   8295
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid GrillaBlta 
         Height          =   1575
         Left            =   120
         TabIndex        =   47
         TabStop         =   0   'False
         Top             =   360
         Width           =   8055
         _ExtentX        =   14208
         _ExtentY        =   2778
         _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        =   48
         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        =   44
      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        =   41
      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        =   42
         Top             =   240
         Width           =   1215
      End
   End
   Begin VB.Frame Frame12 
      Height          =   855
      Left            =   8520
      TabIndex        =   39
      Top             =   9120
      Width           =   3135
      Begin VB.CommandButton Command1 
         Caption         =   "Abono 50%"
         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
         TabIndex        =   59
         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        =   40
         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             =   8040
      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        =   25
         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             =   6000
      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        =   49
         Top             =   1080
         Visible         =   0   'False
         Width           =   7695
         Begin ComctlLib.ProgressBar progreso 
            Height          =   255
            Left            =   480
            TabIndex        =   50
            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        =   53
            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        =   52
            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        =   51
            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        =   45
      Top             =   1920
      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          =   4815
      Left            =   8520
      TabIndex        =   26
      Top             =   1080
      Visible         =   0   'False
      Width           =   4335
      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            =   2880
         Picture         =   "Form_Pagar_Mensualidad_elec.frx":2A8B2
         Style           =   1  'Graphical
         TabIndex        =   38
         Top             =   2880
         Width           =   1215
      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        =   32
         Top             =   360
         Width           =   2895
         Begin MSComCtl2.DTPicker Dtp_Fec_emision 
            Height          =   375
            Left            =   1440
            TabIndex        =   34
            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          =   51904513
            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        =   33
            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        =   31
         Top             =   4320
         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            =   240
         TabIndex        =   29
         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        =   30
            Text            =   "Text7"
            Top             =   360
            Width           =   1215
         End
      End
      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        =   28
         Top             =   1200
         Width           =   3855
         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        =   37
            TabStop         =   0   'False
            Top             =   840
            Width           =   1575
         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        =   35
            TabStop         =   0   'False
            Top             =   360
            Width           =   1575
         End
         Begin VB.ComboBox CboFormaPago2 
            Height          =   315
            ItemData        =   "Form_Pagar_Mensualidad_elec.frx":2AE98
            Left            =   240
            List            =   "Form_Pagar_Mensualidad_elec.frx":2AEAB
            Style           =   2  'Dropdown List
            TabIndex        =   36
            Top             =   840
            Width           =   1815
         End
         Begin VB.ComboBox CboFormaPago1 
            Height          =   315
            ItemData        =   "Form_Pagar_Mensualidad_elec.frx":2AED5
            Left            =   240
            List            =   "Form_Pagar_Mensualidad_elec.frx":2AEE8
            Style           =   2  'Dropdown List
            TabIndex        =   24
            Top             =   360
            Width           =   1815
         End
      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            =   1560
         Picture         =   "Form_Pagar_Mensualidad_elec.frx":2AF12
         Style           =   1  'Graphical
         TabIndex        =   27
         Top             =   2880
         Width           =   1215
      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.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        =   56
      Top             =   10560
      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        =   54
      Top             =   10320
      Visible         =   0   'False
      Width           =   1575
   End
End
Attribute VB_Name = "Form_Pagar_Mensualidad_elec"
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 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
        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 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
        Call LlenaGrilla
        Call SeteaGrillaDtll
        Call SeteaGrillaBlta
    End If
End Sub

Private Sub Command1_Click()
    abono
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
        Text7.Text = objRS("folio") + 1
    
    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
    'se 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 objRS As ADODB.Recordset
    Dim varsql As String
    Set objRS = New ADODB.Recordset
    Dim OkImprimir As Boolean
    Dim Verificar As Integer
    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 caja As Integer
    
    ' Imprimir Boleta
    ' ########
    
'''''''    If Option9.Value = False And Option1.Value = False And Option2.Value = False And Option4.Value = False And Option5.Value = False And Option6.Value = False And Option7.Value = False And Option8.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
        
    'Selecccion de caja 1
    If CboFormaPago1.Text = "Transf." Or CboFormaPago1.Text = "Cheque" Or CboFormaPago1.Text = "Contado" Then
        caja = DevuelveCampo("cfg", "", "valor", "param = 'Bodega_CAJA'", conn)
        'caja = 1
    End If
    
'    'Selecccion de caja 2 BCI
'    If Option6.Value = True Then
'        caja = DevuelveCampo("cfg", "", "valor", "param = 'Bodega_BCI'", conn)
'        'caja = 2
'    End If
    
    'Selecccion de caja 3 IBR
    If CboFormaPago1.Text = "IBR" Then
        caja = DevuelveCampo("cfg", "", "valor", "param = 'Bodega_IBR'", conn)
        'caja = 3
    End If
    
    'Selecccion de caja 4 Upago
    If CboFormaPago1.Text = "Upago" Then
        caja = DevuelveCampo("cfg", "", "valor", "param = 'Bodega_UPAGO'", conn)
        'caja = 3
    End If
    
    '''''' Validacion fecha
'''''    If Format(FEmision, "yyyy-mm-dd") < Format("2018-12-19", "yyyy-mm-dd") Then
'''''        MsgBox "La Fecha ingresada debe ser mayor a 2 de Enero", vbInformation, "ERROR"
'''''        Exit Sub
'''''    End If
            
      '''''' Validacion fecha mayor a Enero 2019
''''    If Format(Dtp_Fec_emision.Value, "yyyy-mm-dd") <> Format("2019-01-02", "yyyy-mm-dd") Then
''''        MsgBox "La Boleta debe ser ingresada con fecha 2 de Enero de 2019", vbInformation, "ERROR"
''''        Exit Sub
''''    End If
            
    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 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
                        
            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:\prueba.txt" For Output As 1
                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)
                MArancel = IIf(val(Text6.Text) > 0, Me.Text5.Text - (Text6.Text), 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
'                Print #1, Chr(15) & _
'                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
'                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
'                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
'                vbCrLf + vbCrLf + vbCrLf + vbCrLf & _
'                vbCrLf + vbCrLf & _
'                vbCrLf + Space(25) + NomApo + Space(20) + RutApoBol & _
'                vbCrLf + vbCrLf + Space(25) + NomAlu & _
'                vbCrLf + vbCrLf + Space(25) + MesBoleta + Space(37) + curso & _
'                vbCrLf + vbCrLf + Space(25) + Pagado + Space(10) + EnPalabras.ALetra & _
'                vbCrLf + vbCrLf + vbCrLf + vbCrLf + Space(48) + Combo1.Text + Space(15) + vbCrLf & _
'                vbCrLf + vbCrLf + Space(50) + CStr(MArancel) & _
'                vbCrLf + vbCrLf + Space(50) + CStr(MExencion) + Space(26 - Len(CStr(MExencion)) + 1) + CStr(MParcial) & _
'                vbCrLf + vbCrLf + Space(50) + CStr(MOtrasExencion) + Space(26 - Len(CStr(MOtrasExencion)) + 1) + CStr(MParcial1) & _
'                vbCrLf + vbCrLf + Space(81) + CStr(MAportes) & _
'                vbCrLf + vbCrLf + Space(81) + CStr(MCPadres) & _
'                vbCrLf + vbCrLf + Space(81) + CStr(MOtros) & _
'                vbCrLf + vbCrLf + Space(77) + CStr(MTotal) & _
'                vbCrLf + vbCrLf + vbCrLf + vbCrLf + Space(20) + FEmision & _
'                vbCrLf; vbCrLf + vbCrLf + vbCrLf
            '''''Print #1, ResetPrinter
            '''''Close 1
                     
    'Boleta Electronica
    'Datos de apoderado
    
    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
    
    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 = "105" 'tarjeta debito
'''''    If Option6.Value = True Then forma_pago = "104" 'BCI
'''''    If Option7.Value = True Then forma_pago = "103" 'IBR
'''''    If Option8.Value = True Then forma_pago = "109" 'Upago
'''''    If Option9.Value = True Then forma_pago = "108" 'Transferencia
    
         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
         If CboFormaPago1.Text = "IBR" Then forma_pago = "103" 'IBR
  
   
    'run_alu = Me.Grilla.TextMatrix(Grilla.Row, 0)    ' Rut del alumno
    alumno_curso = NomAlu & "          Curso: " & curso
    
    'MkDir "C:\Boleta_Electronica"
    
'''    'Ruta Boleta
'''    ruta = "\\192.168.7.192\Users\lriveros\Desktop\BOLETA ELECTRONICA\boleta_electronica_base64.txt"
''     ruta = "\\vsoftland\Users\lriveros\Desktop\BOLETA ELECTRONICA\boleta_electronica.txt"
     ruta2 = DevuelveCampo("usuarios", "", "ruta_softland", "AUT_NOMBRE_USUARIO ='" & Nom_usu_ses & "'", conn)
        
        
'    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)
    
    If RutApoBol = "44444447-9" Then
        NomApo = "PAGO TRANSFERENCIA"
        MesBoleta = "PAGO SIN IDENTIFICAR"
        alumno_curso = "PAGO TRANSFERENCIA"
    End If
    
    
    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)
        
    'Exencion Becas
    'If MParcial > 0 Then
    
    'Derecho Matricula
    enumeracion_concepto = "B2"
    detalle_producto = "DERECHO MATRICULA AÑO ESCOLAR 2017"
    valor_concepto = 0
    desc_beca = 0
    desc_otros = 0
    
    total_boleta = Me.Text5.Text - (val(IIf(val(Text6.Text) > 0 And MExencion > 0, MExencion + Me.Text6.Text, MExencion)) + val(IIf(val(Text6.Text) > 0 And MOtrasExencion > 0, MOtrasExencion + Me.Text6.Text, MOtrasExencion + Me.Text6.Text)))
    
               '1  2 3 4               5                                6                7              8CAM                  9        1011
    registro1 = "B;S;V;" & caja & ";" & Form_Pagar_Mensualidad_elec.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                    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 = val(IIf(val(Text6.Text) > 0, Me.Text5.Text, Me.Text5.Text))
    valor_concepto = Me.Text5.Text
'    desc_beca = MExencion
'    desc_otros = MOtrasExencion
    desc_beca = val(IIf(val(Text6.Text) > 0 And MExencion > 0, MExencion + Me.Text6.Text, MExencion))
    desc_otros = val(IIf(val(Text6.Text) > 0 And MOtrasExencion > 0, MOtrasExencion + Me.Text6.Text, MOtrasExencion + Me.Text6.Text))
               '1  2 3 4               5                                6                7              8CAM                  9        1011
    registro1 = "B;S;V;" & caja & ";" & Form_Pagar_Mensualidad_elec.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                    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
    
'    'Aportes o donaciones
'    enumeracion_concepto = "B6"
'    Registro = Replace(registro6, "B2", "B6")
'    registro7 = registro7 & vbCrLf & Registro
'    Call AgregarRegistroCobranza(Registro, ruta2)
    
'    'Cuotas extraordinarias centro de padres
'    enumeracion_concepto = "B7"
'    Registro = Replace(registro6, "B2", "B7")
'    registro7 = registro7 & vbCrLf & Registro
'    'Call AgregarRegistroCobranza(Base64EncodeString(Registro), ruta)
'    Call AgregarRegistroCobranza(Registro, ruta2)
'
        'Otros cobros obligatorios
'    enumeracion_concepto = "B8"
'    Registro = Replace(registro6, "B2", "B8")
'    registro7 = registro7 & vbCrLf & Registro
'    'Call AgregarRegistroCobranza(Base64EncodeString(registro7), ruta)
'    Call AgregarRegistroCobranza(Registro, ruta2)
    
    'Agrego a base de datos boleta electronica
'    var_sql = "DELETE FROM fnza_temp_boleta_electronica;"
'    conn.Execute var_sql
    'var_sql = "replace INTO fnza_temp_boleta_electronica(boleta,boleta_64) VALUES('" & registro7 & "','" & Base64EncodeString(registro7) & "');"
    
    ''estaba corporacion codigo
'''''''    certificado_digital = DevuelveCampo("usuarios", "", "certificado_digital", "aut_nombre_usuario = '" & Nom_usu_ses & "'", conn)
'''''''    var_sql = "update fnza_temp_boleta_electronica set boleta = '" & registro7 & "',boleta_64='" & Base64EncodeString(registro7) & "',certificado_digital = '" & certificado_digital & "';"
'''''''    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
        
    'Format(Fvcto, "yyyy-mm-dd")
    
'''''    'Otras Exenciones
'''''    If MParcial1 > 0 Then
'''''    enumeracion_concepto = "B4"
'''''    valor_concepto = MParcial1
'''''    descuentos = MOtrasExencion
'''''                   '1  2 3 4               5                                6                7          8CAM              9        1011
'''''    registro1 = "B;S;V;1;" & Form_Pagar_Mensualidad_elec.Text7.Text & ";" & FEmision & ";" & CStr(1) & ";" & FEmision & ";" & alumno_curso & ";;;"
'''''               '12 - 16      17 ok            18              19                20             21ok            22ok
'''''    registro2 = ";;;;;" & RutApoBol & ";" & NomApo & ";" & 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 & ";;;" & valor_concepto & ";;;;;;;;;;;;;" & descuentos & ";"
'''''                '73 - 101
'''''    registro5 = ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
'''''    Registro = registro1 & registro2 & registro3 & registro4 & registro5
'''''    Call AgregarRegistroCobranza(Registro, ruta)
'''''    End If
        
    ' Inserta base de datos
    Shell App.Path & "\conector\WindowsApplication2.exe", vbNormalFocus
    
    'Call AgregarRegistroCobranza(Registro, ruta)
            
    'Insertar log
        sw = True
        GrillaDtll.Col = 1
        For I = 1 To Form_Pagar_Mensualidad_elec.GrillaDtll.Rows - 1
            GrillaDtll.Row = I
            If Form_Pagar_Mensualidad_elec.GrillaDtll.CellBackColor = CDbl(&HC0E0FF) And sw = True Then
                sw = False
                primer_mes = Form_Pagar_Mensualidad_elec.GrillaDtll.TextMatrix(I, 1)
            End If
        Next I
        sw = True
        I = Form_Pagar_Mensualidad_elec.GrillaDtll.Rows - 1
        GrillaDtll.Col = 1
        While I > 0
            GrillaDtll.Row = I
            Form_Pagar_Mensualidad_elec.Grilla.Col = 1
            If Form_Pagar_Mensualidad_elec.GrillaDtll.CellBackColor = CDbl(&HC0E0FF) And sw = True Then
                sw = False
                ultimo_mes = Form_Pagar_Mensualidad_elec.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_elec.Text7.Text _
                       & ", con monto " & val(Me.Text3.Text) & " para los meses de " _
                       & primer_mes & " hasta " & ultimo_mes
        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_elec.Grilla.TextMatrix(Form_Pagar_Mensualidad_elec.Grilla.Row, 0), _
        Form_Pagar_Mensualidad_elec.Text2.Text, CStr(accion), CStr(accion_detalle), Form_Pagar_Mensualidad_elec.Text7.Text, Form_Pagar_Mensualidad_elec.Text7.Text)
    '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_elec.Text7.Text _
                       & ", con monto " & val(Me.Text3.Text) & " para los meses de " _
                       & primer_mes & " hasta " & ultimo_mes
        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_elec.Grilla.TextMatrix(Form_Pagar_Mensualidad_elec.Grilla.Row, 0), _
        Form_Pagar_Mensualidad_elec.Text2.Text, CStr(accion), CStr(accion_detalle), Form_Pagar_Mensualidad_elec.Text7.Text, Form_Pagar_Mensualidad_elec.Text7.Text)
    'Fin de log
        
            Exit Sub
        Else
            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
        Resume
    Else
        If Err.Number = 6 Then
            MsgBox "Seleccione solo una cuota para realizar el abono de 50%", vbCritical
        Call Command5_Click
        Else
            If Err.Number = 0 Then
            Else
                MsgBox "Alerta: " & Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbExclamation, "ALERTA DE ANOMALÍA"
            End If
            Resume
        End If
    End If
    
End Sub

Private Sub Command4_Click()
On Error GoTo Controlerror:
    Dim NumFolioOK As Integer
    Dim ProcPago As String
    Dim ProcPago2 As String 'se agrega 24-05-2022
    Dim TipoPago As String
    Dim Tipopago2 As String 'se agrega 24-05-2022
    Dim FormaPago As String
    Dim FormaPago2 As String 'se agrega 24-05-2022
    Dim MontoAux As Long
    Dim MontoAux2 As Long
    Dim Detalle() As Long
    Dim DetallePago() As Long
    Dim MontoFalta 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 objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
        
    Dim MontoTotal As Long    'se agrega 25-05-2022
    
    'If Option9.Value = False And Option1.Value = False And Option2.Value = False And Option4.Value = False And Option5.Value = False And Option6.Value = False And Option7.Value = False And Option8.Value = False Then
    If CboFormaPago1.ListIndex = -1 Then
        MsgBox "Primero debe seleccionar una forma de pago", vbInformation
        Exit Sub
    End If
    
    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 + TxtMonto2.Text
        End If
    End If
    If MontoTotal <> 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))
    
    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
        
        'IBR
        'If Option7.Value Then
        If CboFormaPago1.ListIndex = 2 Then
            ProcPago = "icup"
            TipoPago = "cobr"
            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 = 3 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 = 4 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
        'IBR
        'If Option7.Value Then
        If CboFormaPago2.ListIndex = 2 Then
            ProcPago2 = "icup"
            Tipopago2 = "cobr"
            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 = 3 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 = 4 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
           
'''''    '''''' Validacion fecha mayor a Enero 2019
'''''    If Format(Dtp_Fec_emision.Value, "yyyy-mm-dd") <> Format("2019-01-02", "yyyy-mm-dd") Then
'''''        MsgBox "La Boleta debe ser ingresada con fecha 2 de Enero de 2019", vbInformation, "ERROR"
'''''        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)   'folio
            Detalle(2, TamDtll) = GrillaDtll.TextMatrix(I, 11)  'monto
        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
                    'TxtMonto2.Text = TxtMonto2.Text - MontoFalta
                    MontoAux2 = MontoAux2 - MontoFalta
                    MontoFalta = MontoFalta - MontoFalta
                    'j = j + 1
                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
            'If montoaux > 0 Then 'quedo con sobrante
            '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 bvMontoCupon 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
    
    ''''''' Valido que la boleta este en sofland
    aaa = ConectarSQL(connSQL, "192.168.7.13", colegio, "sa", "passCORPsa.2024", True)
    var_sql = "select folio,codbode from " & DevuelveCampo("fnza_temp_boleta_electronica", "", "sector", "1=1", conn) & ".softland.iw_gsaen where tipo = 'B' and folio = " & Text7.Text
    objRS.Open var_sql, connSQL
    If objRS.RecordCount = 0 Then
         MsgBox "La boleta NO se encuentra ingresada en Softland, la boleta no ha sido agregada al libro", vbInformation, "Advertencia"
         objRS.Close
         connSQL.Close
         Exit Sub
    End If
    objRS.Close
    
    connSQL.Close
    
    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_elec.GrillaDtll.Rows - 1
            GrillaDtll.Row = I
            If Form_Pagar_Mensualidad_elec.GrillaDtll.CellBackColor = CDbl(&HC0E0FF) And sw = True Then
                sw = False
                primer_mes = Form_Pagar_Mensualidad_elec.GrillaDtll.TextMatrix(I, 1)
            End If
        Next I
        sw = True
        I = Form_Pagar_Mensualidad_elec.GrillaDtll.Rows - 1
        GrillaDtll.Col = 1
        While I > 0
            GrillaDtll.Row = I
            Form_Pagar_Mensualidad_elec.Grilla.Col = 1
            If Form_Pagar_Mensualidad_elec.GrillaDtll.CellBackColor = CDbl(&HC0E0FF) And sw = True Then
                sw = False
                ultimo_mes = Form_Pagar_Mensualidad_elec.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_elec.Text7.Text _
                       & ", con monto " & val(Me.Text3.Text) & " para los meses de " _
                       & primer_mes & " hasta " & ultimo_mes
        Call Inserta_Vitacora_Finanza(Form_Pagar_Mensualidad_elec.Grilla.TextMatrix(Form_Pagar_Mensualidad_elec.Grilla.Row, 0), _
        Form_Pagar_Mensualidad_elec.Text2.Text, CStr(accion), CStr(accion_detalle), Form_Pagar_Mensualidad_elec.Text7.Text, Form_Pagar_Mensualidad_elec.Text7.Text)
    '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
    
    If CboFormaPago2.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:
    If Err.Number = 0 Then
    Else
        MsgBox "Alerta: " & Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbExclamation, "ALERTA DE ANOMALÍA"
    End If
    '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
    'se grega para limpiar los combos de forma de pago
    'CboFormaPago1.ListIndex = -1
    'CboFormaPago2.ListIndex = -1
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
    ' Falta validacion de matricula
    var_sql = "SELECT a.ci_alu FROM apo_x_alu a,matriculas m" _
            & " where a.ci_alu = m.ci_alu and a.agno = m.anno_mat and a.rut_apo = '" & Me.Text2.Text & "' and a.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 = 3" _
                & " 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 Then
        If sw = 1 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,SUM(monto_exen_bca) AS beca" _
                    & " 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," _
                    & " monto_exen_bca = 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) - ((rec("monto_total") Mod 10) / 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 = (rec("convenio") / 10) - ((rec("convenio") Mod 10) / 10)
            Else
                Convenio = 0
            End If
            If rec("tipo_pago") > 0 Then
                tipo_pago = ((rec("tipo_pago") / 10)) - ((rec("tipo_pago") Mod 10) / 10)
            Else
                tipo_pago = 0
            End If
            If rec("hermano") > 0 Then
                hermano = ((rec("hermano") / 10)) - ((rec("hermano") Mod 10) / 10)
            Else
                hermano = 0
            End If
            
            If rec("beca") > 0 Then
                Beca = ((rec("beca") / 10)) - ((rec("beca") Mod 10) / 10)
                'cuota = CLng((REC("cuota") / 10)) '- CLng((REC("cuota") Mod 10)))
            Else
                Beca = 0
            End If
            
            If rec("cuota") > 0 Then
                cuota = Monto_Total - (Convenio + hermano + tipo_pago + Beca)
                '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 & "," _
                    & " monto_exen_bca = " & Beca _
                    & " 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 = ((rec("monto_total") / 10) - ((rec("monto_total") Mod 10) / 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 = ((rec("convenio") / 10) - ((rec("convenio") Mod 10) / 10)) + CLng((rec("convenio") Mod 10))
            End If
            If rec("tipo_pago") > 0 Then
                tipo_pago = (((rec("tipo_pago") / 10)) - ((rec("tipo_pago") Mod 10) / 10)) + CLng((rec("tipo_pago") Mod 10))
            End If
            If rec("hermano") > 0 Then
                hermano = (((rec("hermano") / 10)) - ((rec("hermano") Mod 10) / 10)) + CLng((rec("hermano") Mod 10))
            End If
            If rec("beca") > 0 Then
                Beca = (((rec("beca") / 10)) - ((rec("beca") Mod 10) / 10)) + CLng((rec("beca") Mod 10))
            End If
                If rec("cuota") > 0 Then
                cuota = Monto_Total - (Convenio + hermano + tipo_pago + Beca)
                '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 & "," _
                    & " monto_exen_bca = " & Beca _
                    & " 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_elec.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", vbInformation
            rec.Close
        End If
        
        'Modifico estados mensualidad alumno
        var_sql = "update fnza_detalle_mensualidad" _
                & " set estado_dtll = if(monto_tot_cuota = monto_abono,'clda',if(monto_tot_cuota > monto_abono and monto_abono > 0,'abon',if(monto_tot_cuota < monto_abono and monto_abono > 0,'cred','impg')))" _
                & " where agno = " & val(Combo1.Text) & " and run_alu = '" & objRS("ci_alu") & "'"
        conn.Execute var_sql
        
        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
    
    'Modifico estados mensualidad apoderado
    var_sql = "update fnza_mensualidad" _
            & " set estado_mens = if(monto_mens = abono_mens,'clda',if(monto_mens >abono_mens and abono_mens > 0,'abon',if(monto_mens < abono_mens and abono_mens > 0,'cred','impg')))" _
            & " where agno = " & val(Combo1.Text) & " and run_apo = '" & Me.Text2.Text & "'"
    conn.Execute var_sql
    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 Form_Load()
    ResetPago = False
    Me.Top = 0
    Me.Left = 0
    Flag_sub = True
    Text1.Text = ""
    Text2.Text = ""
    TxtMonto1.Text = ""
    TxtMonto2.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
    Call LlenaComboAgno
    
    '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;"
    
    '2020
    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'clda' WHERE agno >= 2020 AND monto_tot_cuota = monto_abono;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_detalle_mensualidad SET estado_dtll = 'abon' WHERE agno >= 2020 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 >= 2020 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 >= 2020 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 >= 2020 AND monto_mens = abono_mens;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'abon' WHERE agno >= 2020 AND monto_mens > abono_mens AND abono_mens > 0;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'impg' WHERE agno >= 2020 AND monto_mens > abono_mens AND abono_mens = 0;"
    conn.Execute var_sql
    var_sql = "UPDATE fnza_mensualidad SET estado_mens = 'cred' WHERE agno >= 2020 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
              
              
    '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
'
'    '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
    
    
'    '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
'
    'Cambio el descuento de ajuste a tipo de pago particulares
    var_sql = "UPDATE fnza_detalle_mensualidad SET monto_exen_tipo_pago = monto_exen_desc WHERE agno > 2010 AND monto_exen_desc > 0;"
    conn.Execute var_sql
    
     'Cambio el descuento de ajuste a tipo de pago particulares
    var_sql = "UPDATE fnza_detalle_mensualidad SET monto_exen_desc = 0 WHERE agno > 2010 AND monto_exen_desc > 0;;"
    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
    Call LlenaGrillaDescuentos
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
    Call LlenaGrilla
    Call SeteaGrillaDtll
    Call SeteaGrillaBlta
    Call LlenaGrillaDescuentos
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
    Call LlenaGrilla
    Call SeteaGrillaDtll
    Call SeteaGrillaBlta
    Call LlenaGrillaDescuentos
End Sub



Private Sub Option7_Click()

End Sub

Private Sub Option8_Click()

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 LlenaGrillaDescuentos()
    Dim QRY As String
    Dim objRS As New ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim FolioChq As String
    Dim EstadoChq As String
    Dim RunApo As String
    Dim RunAlu As String
    Dim contado As Boolean
    Dim cheque As Boolean
    Dim Beca As Boolean
    Dim mBeca As Boolean
    Dim hermano2 As Integer
    Dim beca2 As Integer
    Dim convenio2 As Integer
    Dim tipo_pago2 As Integer
    Dim Convenio As Boolean
    Dim desc_conv As String
    Dim convenio_jardin As String
    Dim ajuste As Long
    Dim motivo_ajuste As String
    
'    Mes = GrillaDtll.TextMatrix(Grilla.Row, 1)
'    MsgBox Mes
    RunAlu = Grilla.TextMatrix(Grilla.Row, 0)
    RunApo = Text2.Text
'    Label10.Caption = ""
'    Frame14.Caption = "Información Adicional Mes de " & GrillaDtll.TextMatrix(GrillaDtll.Row, 1)
' Combo1.Text as agno

    contado = False
    cheque = False
    Beca = False
    mBeca = False
    QRY = "SELECT ind_cont,ind_cheq,ind_cup,ind_beca,ind_mbeca FROM matriculas WHERE anno_mat = " & Combo1.Text & " AND ci_alu = '" & RunAlu & "'"
    objRS.Open QRY, conn
    If objRS.RecordCount > 0 Then
        contado = IIf(objRS("ind_cont") = 1, True, False)
        cheque = IIf(objRS("ind_cheq") = 1, True, False)
        Beca = IIf(objRS("ind_beca") = 1, True, False)
        mBeca = IIf(objRS("ind_mbeca") = 1, True, False)
    End If
    objRS.Close
    
    hermano2 = 0
    convenio2 = 0
    tipo_pago2 = 0
    QRY = "SELECT run_alu,(monto_exen_hno * 100)/monto_total AS hermano,(monto_exen_bca * 100)/monto_total AS beca,(monto_exen_conv * 100)/monto_total AS convenio," _
        & "(monto_exen_tipo_pago * 100)/monto_total AS tipo_pago,mes,monto_tot_cuota,monto_total,cod_convenio,monto_exen_desc,motivo_ajuste" _
        & " FrOM fnza_detalle_mensualidad WHERE run_alu = '" & RunAlu & "' AND agno = " & Combo1.Text & " and mes = 4"
    objRS.Open QRY, conn
    If objRS.RecordCount > 0 Then
        hermano2 = IIf(IsNull(objRS("hermano")), 0, objRS("hermano"))
        convenio2 = IIf(IsNull(objRS("convenio")), 0, objRS("convenio"))
        convenio2 = IIf(IsNull(objRS("tipo_pago")), 0, objRS("tipo_pago"))
        
'        convenio2 = objRS("convenio")
'        tipo_pago2 = objRS("tipo_pago")

    End If
    objRS.Close
    
    ajuste = 0
    motivo_ajuste = ""
    QRY = "SELECT monto_exen_desc,motivo_ajuste FROM fnza_detalle_mensualidad WHERE agno = " & Combo1.Text & " AND monto_exen_desc <> 0 AND run_alu = '" & RunAlu & "' LIMIT 1"
    objRS.Open QRY, conn
    If objRS.RecordCount > 0 Then
        ajuste = objRS("monto_exen_desc")
        motivo_ajuste = objRS("motivo_ajuste")
    End If
    objRS.Close
    
    beca2 = 0
    QRY = "SELECT (monto_exen_bca * 100)/monto_total AS beca FROM fnza_detalle_mensualidad WHERE agno = " _
        & Combo1.Text & " AND (monto_exen_bca * 100)/monto_total > 45 AND run_alu = '" & RunAlu & "' LIMIT 1"
    objRS.Open QRY, conn
    If objRS.RecordCount > 0 Then
        beca2 = objRS("beca")
    End If
    objRS.Close
    
    Convenio = False
    desc_conv = ""
    cod_conv = ""
    QRY = "SELECT a.cod_conv,des_conv FROM apoderados a,convenios c WHERE rut_apo = '" & RunApo & "'" _
        & " AND CAST(a.cod_conv AS UNSIGNED) = CAST(c.cod_conv AS UNSIGNED) and a.cod_conv <> 'N'"
    objRS.Open QRY, conn
    If objRS.RecordCount > 0 Then
        'convenio = IIf(objRS("ind_mbeca") = 1, True, False)
        desc_conv = objRS("des_conv")
        cod_conv = objRS("cod_conv")
    End If
    objRS.Close
    
    convenio_jardin = ""
    QRY = "SELECT jardin FROM fnza_convenio_jardin WHERE run_alu = '" & RunAlu & "' AND agno = " & Combo1.Text
    objRS.Open QRY, conn
    If objRS.RecordCount > 0 Then
        convenio_jardin = objRS("jardin")
    End If
    objRS.Close
    
    QRY = "SELECT run_alu,(monto_exen_hno * 100)/monto_total AS hermano,(monto_exen_bca * 100)/monto_total AS beca,(monto_exen_conv * 100)/monto_total AS convenio," _
        & "(monto_exen_tipo_pago * 100)/monto_total AS tipo_pago,mes,monto_tot_cuota,monto_total,cod_convenio" _
        & " FrOM fnza_detalle_mensualidad WHERE run_alu = '" & RunAlu & "' AND agno = " & Combo1.Text & " and concepto = 'ct00'"
    objRS.Open QRY, conn
    If objRS.RecordCount > 0 Then
        
        convenio_jardin2 = objRS("convenio")
        
    End If
    objRS.Close
    
    'GrillaDescuentos.Clear
    GrillaDescuentos.Rows = 1
    GrillaDescuentos.Row = 0
    
    GrillaDescuentos.ColWidth(0) = 4250 ' Tipo Doc.
    GrillaDescuentos.ColWidth(1) = 900 ' Folio
    GrillaDescuentos.ColWidth(2) = 2800 ' Fecha
    
    'GrillaDescuentos.AddItem "Hermano" & Chr(9) & "25%" & Chr(9) & ""
    'MsgBox RunAlu
    
    If contado = True And tipo_pago2 > 0 Then
        GrillaDescuentos.AddItem "CONTADO" & Chr(9) & "12%" & Chr(9) & ""
    End If
    
    If cheque = True And tipo_pago2 > 0 Then
        GrillaDescuentos.AddItem "CHEQUE" & Chr(9) & "5%" & Chr(9) & ""
    End If
    
    If Beca = True And beca2 = 100 Then
        GrillaDescuentos.AddItem "BECA" & Chr(9) & "100%" & Chr(9) & ""
    End If
    
    If mBeca = True And beca2 > 48 Then
        GrillaDescuentos.AddItem "BECA" & Chr(9) & "50%" & Chr(9) & ""
    End If
    
    If hermano2 > 23 And hermano2 < 27 Then
        GrillaDescuentos.AddItem "HERMANO" & Chr(9) & "25%" & Chr(9) & ""
    End If
    
    If desc_conv <> "" And convenio2 > 0 And cod_conv = 4 Then
        GrillaDescuentos.AddItem desc_conv & Chr(9) & "20%" & Chr(9) & ""
    End If
    
    If desc_conv <> "" And convenio2 > 0 And cod_conv <> 4 Then
        GrillaDescuentos.AddItem desc_conv & Chr(9) & "30%" & Chr(9) & ""
    End If
    
    If convenio_jardin <> "" And convenio_jardin2 > 0 Then
        GrillaDescuentos.AddItem "CONVENIO JARDIN" & Chr(9) & "100%" & Chr(9) & "En cuota cero"
    End If
    
    If ajuste <> 0 Then
        GrillaDescuentos.AddItem "AJUSTE" & Chr(9) & "" & Chr(9) & motivo_ajuste
    End If
          
    
'    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;"
'    RC.Open QR, conn
'    If RC.RecordCount = 0 Then
'        RC.Close
'        Exit Sub
'    End If
    
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;"
    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) & val(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), 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
        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
    
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 SeteaGrillaDescuentos()
    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
    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
    TotalExencBeca = 0
    TotalPagar = 0
    TotalExenc = 0
    TotalCuota = 0
    TotalAbono = 0
    For I = 1 To UBound(CuotasPag)
        If CuotasPag(I) Then
            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
    Text3.Text = str(TotalPagar)
    'se agrega al monto1 el total a pagar
    TxtMonto1.Text = str(TotalPagar)
    Text4.Text = str(TotalExenc)
    Text6.Text = str(TotalAbono)
    Text5.Text = str(TotalCuota)
    Text8.Text = str(TotalExencBeca)
    Text9.Text = str(TotalExenc - TotalExencBeca)
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 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
    Form_Boleta_Imprimir.Text4.Text = CalculaMeses(Me.Grilla.TextMatrix(Grilla.Row, 0), val(Combo1.Text))
    ' 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
    
    If Err.Number = 0 Then
    Else
        Err.Raise Err.Number, Err.Source, Err.Description
    End If
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/" & (GrillaDtll.Rows - 2) Yo
                    Else
                        'Cadena = " Cuota " & " 1/11"
                        Cadena = " Cuota " & " 1/" & (GrillaDtll.Rows - 2)
                    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
                    Cadena = GrillaDtll.TextMatrix(I, 1)
                End If
                SwFirst = True
            Else
                CadenaFin = " a " & GrillaDtll.TextMatrix(I, 1) '& " " & GrillaDtll.TextMatrix(i, 2)
            End If
        End If
    Next I
    CalculaMeses = Cadena & CadenaFin
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

Private Sub abono()
On Error GoTo Controlerror:
    Dim var3 As Double
    Dim var4 As Double
    Dim var6 As Double
    Dim var5 As Double
    Dim var8 As Double
    Dim var9 As Double
    
    var3 = Text3
    var4 = Text4
    var6 = Text6
    var5 = Text5
    var8 = Text8
    var9 = Text9
    
    Text3.Text = IIf(var3 Mod 2 = 0, Round(var3 / 2), (CInt(Round((var3 / 2) + 0.5)))) 'Total a pagar
    'Text4.Text = Round(Round(var4) + Round(var3 / 2))  'Total Exenciones
    Text4.Text = var5 - Text3.Text   'Total Exenciones
    Text6.Text = Round(Text6) ' Total abonos
    Text5.Text = Round(Text5) ' Base
    Text8.Text = Round(Text8)
    Text9.Text = Round(Text4 - Text8)
    Command2_Click
    
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
            If Err.Number = 0 Then
            Else
                MsgBox "Alerta: " & Err.Number & vbCrLf & Err.Description & vbCrLf & Err.Source, vbExclamation, "ALERTA DE ANOMALÍA"
            End If
        End If
    End If
    
End Sub

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 TxtMonto2_LostFocus()
Dim Valor1 As Long
Dim Valor2 As Long
Dim ValorTotal As Long

If TxtMonto2.Text <> "" Then
    ValorTotal = Text3.Text
    Valor1 = TxtMonto1.Text
    Valor2 = TxtMonto2.Text
    
    If ValorTotal <> (Valor1 + Valor2) Then
        MsgBox "Montos de pago no coinciden con Valor Total, Favor revisar", vbInformation
        Exit Sub
    End If
End If
End Sub
