VERSION 5.00
Object = "{0F987290-56EE-11D0-9C43-00A0C90F29FC}#1.0#0"; "ActBar.ocx"
Object = "{B02F3647-766B-11CE-AF28-C3A2FBE76A13}#2.5#0"; "ss32x25.ocx"
Object = "{9FE8BEE1-8569-4532-8518-BB32F08FC1EB}#2.0#0"; "dtF4.ocx"
Begin VB.Form FCO2096 
   Caption         =   "Control PI Pensionados"
   ClientHeight    =   8100
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   11700
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "FCO2096 Control Planilla Pensionados.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   8100
   ScaleWidth      =   11700
   Begin VB.Frame fraInfo 
      Height          =   735
      Left            =   120
      TabIndex        =   32
      Top             =   0
      Visible         =   0   'False
      Width           =   7215
      Begin VB.Label lblTitulo 
         BackStyle       =   0  'Transparent
         ForeColor       =   &H00FF0000&
         Height          =   375
         Left            =   240
         TabIndex        =   33
         Top             =   240
         Width           =   6735
      End
   End
   Begin VB.CommandButton cmdContinuar 
      Caption         =   "C&ontinuar (F9) >"
      Height          =   375
      Left            =   5880
      TabIndex        =   25
      Top             =   4800
      Width           =   1335
   End
   Begin VB.Frame fraPasos 
      Height          =   4695
      Index           =   0
      Left            =   2040
      TabIndex        =   26
      Top             =   1920
      Width           =   7215
      Begin VB.Frame fraFrame 
         Caption         =   "Filtros Opcionales"
         Height          =   2055
         Index           =   1
         Left            =   240
         TabIndex        =   29
         Top             =   2520
         Width           =   6735
         Begin VB.TextBox txtDatosDes 
            BackColor       =   &H8000000F&
            Height          =   315
            Index           =   3
            Left            =   4320
            Locked          =   -1  'True
            TabIndex        =   57
            TabStop         =   0   'False
            Top             =   1680
            Width           =   2295
         End
         Begin VB.TextBox txtDatosDes 
            BackColor       =   &H8000000F&
            Height          =   315
            Index           =   2
            Left            =   4320
            Locked          =   -1  'True
            TabIndex        =   56
            TabStop         =   0   'False
            Top             =   1320
            Width           =   2295
         End
         Begin VB.TextBox txtDatosDes 
            BackColor       =   &H8000000F&
            Height          =   315
            Index           =   1
            Left            =   4320
            Locked          =   -1  'True
            TabIndex        =   55
            TabStop         =   0   'False
            Top             =   960
            Width           =   2295
         End
         Begin VB.TextBox txtDatos 
            Height          =   315
            Index           =   3
            Left            =   2520
            MaxLength       =   10
            TabIndex        =   23
            Top             =   1680
            Width           =   1335
         End
         Begin VB.TextBox txtDatos 
            Height          =   315
            Index           =   2
            Left            =   2520
            MaxLength       =   10
            TabIndex        =   20
            Top             =   1320
            Width           =   1335
         End
         Begin VB.TextBox txtDatos 
            Height          =   315
            Index           =   1
            Left            =   2520
            MaxLength       =   10
            TabIndex        =   17
            Top             =   960
            Width           =   1335
         End
         Begin VB.TextBox txtTrabajador 
            Height          =   315
            Left            =   2520
            MaxLength       =   10
            TabIndex        =   8
            Top             =   240
            Width           =   1335
         End
         Begin DataTec_F4.dtF4 dtF4Agr 
            Height          =   255
            Left            =   3960
            TabIndex        =   12
            Top             =   600
            Width           =   375
            _ExtentX        =   661
            _ExtentY        =   450
         End
         Begin VB.TextBox txtDato 
            Height          =   315
            Left            =   4850
            MaxLength       =   10
            TabIndex        =   14
            Top             =   600
            Width           =   1335
         End
         Begin VB.TextBox txtAgr 
            Height          =   315
            Left            =   2520
            MaxLength       =   10
            TabIndex        =   11
            Top             =   600
            Width           =   1335
         End
         Begin DataTec_F4.dtF4 dtF4Dato 
            Height          =   255
            Left            =   6240
            TabIndex        =   15
            Top             =   600
            Width           =   375
            _ExtentX        =   661
            _ExtentY        =   450
         End
         Begin DataTec_F4.dtF4 dtF4Tra 
            Height          =   255
            Left            =   3960
            TabIndex        =   9
            Top             =   240
            Width           =   375
            _ExtentX        =   661
            _ExtentY        =   450
         End
         Begin DataTec_F4.dtF4 dtF4Datos 
            Height          =   255
            Index           =   1
            Left            =   3915
            TabIndex        =   18
            Top             =   960
            Width           =   375
            _ExtentX        =   661
            _ExtentY        =   450
         End
         Begin DataTec_F4.dtF4 dtF4Datos 
            Height          =   255
            Index           =   2
            Left            =   3915
            TabIndex        =   21
            Top             =   1320
            Width           =   375
            _ExtentX        =   661
            _ExtentY        =   450
         End
         Begin DataTec_F4.dtF4 dtF4Datos 
            Height          =   255
            Index           =   3
            Left            =   3915
            TabIndex        =   24
            Top             =   1680
            Width           =   375
            _ExtentX        =   661
            _ExtentY        =   450
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "Pensiona&do"
            Height          =   210
            Index           =   8
            Left            =   360
            TabIndex        =   7
            Top             =   240
            Width           =   840
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "&Caja de Compensación"
            Enabled         =   0   'False
            Height          =   210
            Index           =   7
            Left            =   360
            TabIndex        =   22
            Top             =   1680
            Width           =   1650
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "&Fondo de Pensiones"
            Enabled         =   0   'False
            Height          =   210
            Index           =   6
            Left            =   360
            TabIndex        =   19
            Top             =   1320
            Width           =   1470
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "E&ntidad Promotora de Salud"
            Height          =   210
            Index           =   5
            Left            =   360
            TabIndex        =   16
            Top             =   960
            Width           =   1980
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "&Dato"
            Height          =   210
            Index           =   4
            Left            =   4440
            TabIndex        =   13
            Top             =   600
            Width           =   330
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "A&grupación"
            Height          =   210
            Index           =   3
            Left            =   360
            TabIndex        =   10
            Top             =   600
            Width           =   840
         End
      End
      Begin VB.Frame fraFrame 
         Caption         =   "Datos Obligatorios"
         Height          =   1815
         Index           =   0
         Left            =   240
         TabIndex        =   27
         Top             =   600
         Width           =   6735
         Begin VB.ComboBox cboSuc 
            Height          =   330
            Left            =   3480
            TabIndex        =   6
            Top             =   960
            Width           =   3015
         End
         Begin VB.ComboBox cboPeriodo 
            Height          =   330
            Left            =   4560
            TabIndex        =   4
            Top             =   480
            Width           =   1215
         End
         Begin VB.OptionButton optSistema 
            Caption         =   "P&arafiscales"
            Height          =   255
            Index           =   3
            Left            =   120
            TabIndex        =   2
            Top             =   1080
            Width           =   1935
         End
         Begin VB.OptionButton optSistema 
            Caption         =   "&Pensión"
            Height          =   255
            Index           =   1
            Left            =   120
            TabIndex        =   1
            Top             =   720
            Width           =   2055
         End
         Begin VB.OptionButton optSistema 
            Caption         =   "&Salud"
            Height          =   255
            Index           =   0
            Left            =   120
            TabIndex        =   0
            Top             =   360
            Value           =   -1  'True
            Width           =   2175
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "S&ucursal"
            Height          =   210
            Index           =   2
            Left            =   2640
            TabIndex        =   5
            Top             =   960
            Width           =   645
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "P&eríodo Autoliquidación"
            Height          =   210
            Index           =   0
            Left            =   2640
            TabIndex        =   3
            Top             =   480
            Width           =   1680
         End
      End
      Begin VB.Label lblLabels 
         Caption         =   "Esta  opción permite verificar la información del archivo de planilla integrada de autoliquidación"
         Height          =   255
         Index           =   9
         Left            =   120
         TabIndex        =   28
         Top             =   240
         Width           =   6975
         WordWrap        =   -1  'True
      End
   End
   Begin VB.Frame fraPasos 
      Height          =   6615
      Index           =   1
      Left            =   120
      TabIndex        =   30
      Top             =   720
      Visible         =   0   'False
      Width           =   11415
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   10
         Left            =   6720
         TabIndex        =   46
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   9
         Left            =   6120
         TabIndex        =   45
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   8
         Left            =   5400
         TabIndex        =   44
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   7
         Left            =   4800
         TabIndex        =   43
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   6
         Left            =   4200
         TabIndex        =   42
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   5
         Left            =   3480
         TabIndex        =   41
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   4
         Left            =   2880
         TabIndex        =   40
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   3
         Left            =   2280
         TabIndex        =   39
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   2
         Left            =   1680
         TabIndex        =   38
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   1
         Left            =   960
         TabIndex        =   37
         Top             =   240
         Width           =   495
      End
      Begin VB.TextBox txtFiltro 
         Height          =   315
         Index           =   0
         Left            =   120
         TabIndex        =   36
         Top             =   240
         Width           =   495
      End
      Begin DataTec_F4.dtF4 dtF41 
         Height          =   375
         Left            =   11100
         TabIndex        =   34
         Top             =   1200
         Width           =   255
         _ExtentX        =   450
         _ExtentY        =   661
      End
      Begin FPSpread.vaSpread sprDatos 
         Bindings        =   "FCO2096 Control Planilla Pensionados.frx":030A
         Height          =   5655
         Left            =   120
         TabIndex        =   31
         Top             =   600
         Width           =   10935
         _Version        =   131077
         _ExtentX        =   19288
         _ExtentY        =   9975
         _StockProps     =   64
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         MaxCols         =   1
         MaxRows         =   1
         SpreadDesigner  =   "FCO2096 Control Planilla Pensionados.frx":0320
      End
   End
   Begin VB.Frame fraResumen 
      Height          =   2535
      Left            =   120
      TabIndex        =   47
      Top             =   1800
      Visible         =   0   'False
      Width           =   11175
      Begin VB.OptionButton optResumen 
         Caption         =   "Por EPS"
         Height          =   255
         Index           =   3
         Left            =   7080
         TabIndex        =   54
         Top             =   600
         Width           =   1335
      End
      Begin VB.OptionButton optResumen 
         Caption         =   "Por EPS y Sucursal"
         Height          =   255
         Index           =   2
         Left            =   4920
         TabIndex        =   53
         Top             =   600
         Width           =   1815
      End
      Begin VB.OptionButton optResumen 
         Caption         =   "Totales Generales"
         Height          =   255
         Index           =   4
         Left            =   8760
         TabIndex        =   52
         Top             =   600
         Width           =   1815
      End
      Begin VB.OptionButton optResumen 
         Caption         =   "Por Sucursal"
         Height          =   255
         Index           =   1
         Left            =   2760
         TabIndex        =   51
         Top             =   600
         Width           =   1815
      End
      Begin VB.OptionButton optResumen 
         Caption         =   "Por Sucursal y EPS"
         Height          =   255
         Index           =   0
         Left            =   600
         TabIndex        =   50
         Top             =   600
         Value           =   -1  'True
         Width           =   1815
      End
      Begin FPSpread.vaSpread sprResumen 
         Bindings        =   "FCO2096 Control Planilla Pensionados.frx":0479
         Height          =   5175
         Left            =   240
         TabIndex        =   48
         Top             =   960
         Width           =   10575
         _Version        =   131077
         _ExtentX        =   18653
         _ExtentY        =   9128
         _StockProps     =   64
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         MaxCols         =   1
         MaxRows         =   1
         SpreadDesigner  =   "FCO2096 Control Planilla Pensionados.frx":048F
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Resumen y Totales"
         ForeColor       =   &H00FF0000&
         Height          =   210
         Index           =   1
         Left            =   240
         TabIndex        =   49
         Top             =   240
         Width           =   1380
      End
   End
   Begin VB.Label lblInfo 
      Alignment       =   1  'Right Justify
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H00C0FFFF&
      BorderStyle     =   1  'Fixed Single
      BeginProperty Font 
         Name            =   "Trebuchet MS"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   270
      Left            =   11280
      TabIndex        =   35
      Top             =   420
      UseMnemonic     =   0   'False
      Visible         =   0   'False
      Width           =   75
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   360
      Top             =   7320
      _ExtentX        =   847
      _ExtentY        =   847
      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
      Bands           =   "FCO2096 Control Planilla Pensionados.frx":05E8
   End
End
Attribute VB_Name = "FCO2096"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private MoBitacora As New ADAMBitacora.Bitacora
Private WithEvents clsSpread As NSpread
Attribute clsSpread.VB_VarHelpID = -1
Private MAdo As ODBC.ODBCDirecto
Private Micx As Integer 'Conexión
Private MsAnio As String
Private MsMes As String
Private MsSucursal As String
Private MsFiltrosOpc As String
Private MsSqlIni As String
Private MsSql As String
Private MsSqlResumen As String
Private MSOrder As String
Private MbOrdenAsc As Boolean
Private MsAntOrden As String
Private Enum Sistemas
    Salud = 1
    Pension = 2
    Parafiscales = 8
End Enum
Private Enum TipoCampo
    Numerico = 1
    AlfaNumerico = 2
    Fecha = 3
End Enum
Private MeSistema As Sistemas
Private MiCampos As Byte
Private MbToolbarCreada As Boolean
Private MbDatos_OK(1 To 3) As Boolean
Private MsSUC() As String
Private MsAgr(1 To 3) As String

Private Sub abToolbar_Click(ByVal Tool As ActiveBarLibraryCtl.Tool)
    Select Case Tool.Name
        Case "tlordena": OrdenarDatos
        Case "tlrenueva": Refrescar
        Case "tlguarda": GuardaCambios
        Case "tlsalida": Unload Me
        Case "tlrcolum": Atras
        Case "tlmanvig": MostrarResumen
    End Select
End Sub

Private Sub abToolbar_PreCustomizeMenu(ByVal Cancel As ActiveBarLibraryCtl.ReturnBool)
    Cancel = True
End Sub

Private Sub cboPeriodo_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        KeyAscii = 0
        SendEnter
    Else
        Autocompletar cboPeriodo, KeyAscii
    End If
End Sub

Private Sub cboSuc_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        SendEnter
    Else
        Autocompletar cboSuc, KeyAscii
    End If
End Sub

Private Sub cmdContinuar_Click()
    Dim bMaxim As Boolean
    On Error Resume Next 'Necesario porque hay SetFocus
    
    'Validación de datos obligatorios
    If cboPeriodo.ListIndex = -1 Then
        clsMsgbox.Mensaje "Debe seleccionar el período de autoliquidación", mAceptar, mAdvierte, GsTitMsg
        cboPeriodo.SetFocus
        Exit Sub
    End If
    If cboSuc.Enabled Then
        If cboSuc.ListIndex = -1 Then
            clsMsgbox.Mensaje "Debe seleccionar la sucursal", mAceptar, mAdvierte, GsTitMsg
            cboSuc.SetFocus
            Exit Sub
        End If
    End If
    
    Screen.MousePointer = vbHourglass
    
    'Deducir el Sistema a manejar
    If optSistema(0).Value Then
        MeSistema = Salud
        lblTitulo = "SALUD."
    ElseIf optSistema(1).Value Then
        MeSistema = Pension
        lblTitulo = "PENSIONES."
    ElseIf optSistema(2).Value Then
        MeSistema = Riesgos
        lblTitulo = "RIESGOS PROFESIONALES."
    Else
        MeSistema = Parafiscales
        lblTitulo = "PARAFISCALES."
    End If
    
    'Deducir el año, el mes y la sucursal
    MsAnio = Left(cboPeriodo.Text, 4)
    MsMes = Right(cboPeriodo.Text, 2)

    MsSucursal = MsSUC(cboSuc.ListIndex)
    
    lblTitulo = lblTitulo & "     Período: " & cboPeriodo.Text & "    " & _
    "Sucursal: " & cboSuc.Text & "    "
    
    'Deducir la condición de los filtros opcionales
    MsFiltrosOpc = ""
    If Trim(txtTrabajador) <> "" Then
        MAdo.Sql = "SELECT trabajador FROM vw_fco_pensionados" & _
        " WHERE compania = '" & GsCveCia & "' AND LTRIM(RTRIM(trabajador)) = '" & Trim(txtTrabajador) & "'"
        MAdo.SendSQL
        If MAdo.EOF Then
            clsMsgbox.Mensaje "Trabajador no existe (o el usuario no tiene suficientes privilegios)", mAceptar, mAdvierte, GsTitMsg
            Exit Sub
        Else
            txtTrabajador = MAdo.GetField(1)
            lblTitulo = lblTitulo & " Trabajador: " & Trim(txtTrabajador) & "   "
            MsFiltrosOpc = MsFiltrosOpc & " AND a.trabajador = '" & txtTrabajador & "'"
        End If
    End If
    If Trim(txtAgr) & Trim(txtDato) <> "" Then
        MAdo.Sql = "SELECT 1 FROM datos_agr_trab WHERE agrupacion = '" & txtAgr & "' AND dato = '" & txtDato & "'"
        MAdo.SendSQL
        If MAdo.EOF Then
            clsMsgbox.Mensaje "La combinación agrupación/dato escrita no existe", mAceptar, mAdvierte, GsTitMsg
            Exit Sub
        Else
            lblTitulo = lblTitulo & " " & Trim(txtAgr) & ": " & Trim(txtDato) & "   "
            MsFiltrosOpc = MsFiltrosOpc & " AND EXISTS (SELECT 1 FROM rel_trab_agr x " & _
                                     " WHERE a.compania = x.compania AND a.trabajador = x.trabajador" & _
                                     " AND x.agrupacion = '" & txtAgr & "' AND dato = '" & txtDato & "')"
        End If
    End If
    If txtDatos(1).Enabled Then
        If Trim(txtDatos(1)) <> "" Then
            If Not MbDatos_OK(1) Then ValidarDato 1
            If MbDatos_OK(1) Then
                MsFiltrosOpc = MsFiltrosOpc & " AND cod_EPS = '" & txtDatos(1) & "'"
                lblTitulo = lblTitulo & " EPS: " & txtDatosDes(1)
            Else
                clsMsgbox.Mensaje "No existe el dato digitado para EPS", mAceptar, mAdvierte, GsTitMsg
                txtDatos(1).SetFocus
                Exit Sub
            End If
        End If
    End If
    If txtDatos(2).Enabled Then
        If Trim(txtDatos(2)) <> "" Then
            If Not MbDatos_OK(2) Then ValidarDato 2
            If MbDatos_OK(2) Then
                MsFiltrosOpc = MsFiltrosOpc & " AND cod_AFP = '" & txtDatos(2) & "'"
                lblTitulo = lblTitulo & " AFP: " & txtDatosDes(2)
            Else
                clsMsgbox.Mensaje "No existe el dato digitado para AFP", mAceptar, mAdvierte, GsTitMsg
                txtDatos(2).SetFocus
                Exit Sub
            End If
        End If
    End If
    If txtDatos(3).Enabled Then
        If Trim(txtDatos(3)) <> "" Then
            If Not MbDatos_OK(3) Then ValidarDato 3
            If MbDatos_OK(3) Then
                MsFiltrosOpc = MsFiltrosOpc & " AND cod_CCF = '" & txtDatos(3) & "'"
                lblTitulo = lblTitulo & " CCF: " & txtDatosDes(3)
            Else
                clsMsgbox.Mensaje "No existe el dato digitado para CCF", mAceptar, mAdvierte, GsTitMsg
                txtDatos(3).SetFocus
                Exit Sub
            End If
        End If
    End If
    
    bMaxim = False
    If WindowState = vbMaximized Then
        bMaxim = True
        Visible = False
        WindowState = vbNormal
    End If
    If Not MbToolbarCreada Then
        GbAlterarToolBar = True
        AsignaIconos abToolbar, 3, LRCOLUM, LORDENA, LRENUEVA, LMANVIG, LGUARDA, LSALIDA
        GbAlterarToolBar = False
        ToolInicioGrupo abToolbar, 3, True, 1, 3, 4
        MbToolbarCreada = True
    Else
        abToolbar.Bands(0).Visible = True
    End If
    If bMaxim Then
        Visible = True
        WindowState = vbMaximized
    End If
    
    MSOrder = " ORDER BY 4, 6"
    
    CreaBitacora
    ArmaQuery
    AplicaFiltros
    cmdContinuar.Visible = False
    fraPasos(0).Visible = False
    Width = 11820
    Height = 8505
    fraPasos(1).Visible = True
    fraInfo.Visible = True
    DoEvents
    RedimensionaTextos
    
    Screen.MousePointer = vbDefault
End Sub

Private Sub dtF41_Click()
    If sprDatos.ActiveCol > 0 And sprDatos.ActiveRow > 0 Then
        Dim Lista As New cdtLista
    
        Select Case sprDatos.ActiveCol
            Case 11, 20
                With Lista
                    Select Case MAdo.DBMS
                        Case "SQLSERVER"
                            .Sql = " SELECT LEFT(descripcion, 2), RTRIM(RIGHT(descripcion, 38))" & _
                                   " FROM criterios_valores_col" & _
                                   " WHERE campo = 'tipo_documento'"
                            
                            .Campo1 = "Left(descripcion, 2)"
                            .Campo2 = "RTrim(Right(descripcion, 38))"
                        Case Else
                            .Sql = " SELECT SUBSTR(descripcion, 1, 2), RTRIM(SUBSTR(descripcion, 3, 38))" & _
                                   " FROM criterios_valores_col" & _
                                   " WHERE campo = 'tipo_documento'"
                            .Campo1 = "SUBSTR(descripcion, 1, 2)"
                            .Campo2 = "RTRIM(SUBSTR(descripcion, 3, 38))"
                    End Select
                    
                    .Titulo1 = "Código"
                    .Titulo2 = "Descripción"
                    .TituloVentana = "Tipo de Documento de Identidad"
                    .MostrarLista
                    If .Valor1 <> "" Then
                        sprDatos.SetText sprDatos.ActiveCol, sprDatos.ActiveRow, .Valor1
                        MoBitacora.mCambia sprDatos.ActiveRow
                    End If
                End With
            Case 13
                With Lista
                    .Sql = " SELECT item, RTRIM(descripcion)" & _
                           " FROM criterios_valores_col" & _
                           " WHERE campo = 'tipo_pension'"
                    .Campo1 = "item"
                    .Campo2 = "RTRIM(descripcion)"
                    .Titulo1 = "Código"
                    .Titulo2 = "Descripción"
                    .Orden = "1"
                    .TituloVentana = "Tipo de Pensión"
                    .MostrarLista
                    If .Valor1 <> "" Then
                        sprDatos.SetText sprDatos.ActiveCol, sprDatos.ActiveRow, .Valor1
                        MoBitacora.mCambia sprDatos.ActiveRow
                    End If
                End With
            Case 42
                If MeSistema = Salud Or MeSistema = Pension Then
                    With Lista
                        .Sql = " SELECT codigo, descripcion" & _
                               " FROM vw_fco_administradoras" & _
                               " WHERE compania = '" & GsCveCia & "'" & _
                               " AND tipo = '" & IIf(MeSistema = Salud, "EPS", "AFP") & "'"
                        .Campo1 = "codigo"
                        .Campo2 = "descripcion"
                        .Titulo1 = IIf(MeSistema = Salud, "EPS", "AFP")
                        .Titulo2 = "Nombre"
                        If MeSistema = Salud Then
                            .TituloVentana = "Entidades Promotoras de Salud"
                        Else
                            .TituloVentana = "Administradoras de Fondos de Pensiones"
                        End If
                        .MostrarLista
                        If .Valor1 <> "" Then
                            sprDatos.SetText sprDatos.ActiveCol, sprDatos.ActiveRow, .Valor1
                            MoBitacora.mCambia sprDatos.ActiveRow
                        End If
                    End With
                End If
        End Select
        
        Set Lista = Nothing
    End If
End Sub

Private Sub dtF4Agr_Click()
    Dim Lista As New cdtLista
    
    With Lista
        .Sql = _
            " SELECT a.agrupacion, a.descripcion" & _
            " FROM agrupaciones_trab a, rel_agr_companias b" & _
            " WHERE a.agrupacion = b.agrupacion" & _
            " AND b.compania = '" & GsCveCia & "'"
        .Campo1 = "a.agrupacion"
        .Campo2 = "a.descripcion"
        .Titulo1 = "Agrupación"
        .Titulo2 = "Descripción"
        .Orden = "2"
        .TituloVentana = "Agrupaciones"
        .MostrarLista
        If .Valor1 <> "" Then
            txtAgr = .Valor1
            SendEnter
            SendEnter
        End If
    End With
    
    Set Lista = Nothing
End Sub

Private Sub dtF4Dato_Click()
    On Error Resume Next 'Necesario por el SetFocus
    If Trim(txtAgr) = "" Then
        clsMsgbox.Mensaje "Elija primero la agrupación de trabajadores por la cual desea filtrar", mAceptar, mAdvierte, GsTitMsg
        txtAgr.SetFocus
        Exit Sub
    End If
    
    Dim Lista As New cdtLista
    
    With Lista
        .Sql = _
            " SELECT a.dato, a.descripcion" & _
            " FROM datos_agr_trab a" & _
            " WHERE agrupacion = '" & txtAgr & "'" & _
            " AND NOT EXISTS" & _
            " (SELECT 1 FROM rel_usu_agr_trab x" & _
            " WHERE a.agrupacion = x.agrupacion AND a.dato = x.dato" & _
            "   AND x.usuario = '" & GsUid & "')"
        .Campo1 = "a.dato"
        .Campo2 = "a.descripcion"
        .Titulo1 = "Dato"
        .Titulo2 = "Descripción"
        .Orden = "2"
        .TituloVentana = "Datos de la agrupación " & txtAgr
        .MostrarLista
        If .Valor1 <> "" Then
            txtDato = .Valor1
            SendEnter
            SendEnter
        End If
    End With
    
    Set Lista = Nothing
    
End Sub

Private Sub dtF4Datos_Click(Index As Integer)
    Dim Lista As New cdtLista
    Dim sAgr As String
    
    Select Case Index
        Case 1: sAgr = MsAgr(1)
        Case 2: sAgr = MsAgr(2)
        Case 3: sAgr = MsAgr(3)
    End Select
    
    With Lista
        .Sql = "SELECT a.dato, RTRIM(a.descripcion)" & _
                " FROM datos_agr_trab a" & _
                " WHERE agrupacion = '" & sAgr & "'" & _
                " AND NOT EXISTS" & _
                " (SELECT 1 FROM rel_usu_agr_trab x" & _
                " WHERE a.agrupacion = x.agrupacion AND a.dato = x.dato" & _
                "   AND x.usuario = '" & GsUid & "')"
        .Campo1 = "a.dato"
        .Campo2 = "a.descripcion"
        .Titulo1 = "Dato"
        .Titulo2 = "Nombre"
        .Orden = "1"
        .MostrarLista
        If .Valor1 <> "" Then
            txtDatos(Index) = .Valor1
            txtDatosDes(Index) = .Valor2
            MbDatos_OK(Index) = True
        End If
    End With

End Sub

Private Sub dtF4Tra_Click()
    Dim Lista As New cdtLista
    
    With Lista
        .Sql = _
            " SELECT t.trabajador, REPLACE(t.nombre, '/', ' ')" & _
            " FROM trabajadores t, vw_fco_pensionados tg" & _
            " WHERE t.trabajador = tg.trabajador" & _
            " AND tg.compania = '" & GsCveCia & "'"
        .Campo1 = "t.agrupacion"
        .Campo2 = "t.nombre"
        .Titulo1 = "Trabajador"
        .Titulo2 = "Nombre"
        .Orden = "1"
        .TituloVentana = "Trabajadores"
        .MostrarLista
        If .Valor1 <> "" Then
            txtTrabajador = .Valor1
            SendEnter
        End If
    End With
    
    Set Lista = Nothing
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF3: Unload Me
        Case vbKeyF5: Refrescar
        Case vbKeyF9: If cmdContinuar.Visible Then cmdContinuar_Click
        Case vbKeyF11: GuardaCambios
    End Select
End Sub

Private Sub Form_Load()
    GbAError = False
    Me.Tag = GiVenMax%
    Gven(Val(Me.Tag)).icx = Gicx%
    Micx = Gven(Val(Me.Tag)).icx
    Set MAdo = Gtc(Micx).Ado
    
    'Checa nivel de seguridad
    Gven(Val(Me.Tag)).iNivSeguridad = iObtenNivSeguridad(GsOper, GsUid, Micx)
    If Gven(Val(Me.Tag)).iNivSeguridad = 0 Then
        Screen.MousePointer = vbDefault
        Me.Top = -10000
        GbAError = True
        Exit Sub
    End If
        
    'Tamaño de la forma
    If WindowState = 0 Then
        Width = 7590
        Height = 5820
    End If
    
    With fraPasos(0)
        .Top = 120
        .Left = 120
        .Height = 4575
        .Width = 7215
    End With
    With fraPasos(1)
        .Top = 720
        .Left = 120
        .Height = 6615
        .Width = 11415
    End With
    With fraResumen
        .Top = 720
        .Left = 120
        .Height = 6615
        .Width = 11415
    End With
    
    Caption = GsDsn & " / " & GsCveCia & " - Control Planilla Integrada Pensionados"
        
    LlenarCombos
    
    Set clsSpread = New NSpread
    GAdam.ObtieneColores
    MbToolbarCreada = False

    optSistema_Click 0
    
    Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Resize()
    fraPasos(1).Width = Width - 405
    fraPasos(1).Height = Height - 1890
    sprDatos.Width = fraPasos(1).Width - 480
    sprDatos.Height = fraPasos(1).Height - 630
    dtF41.Left = fraPasos(1).Width - 315

    fraResumen.Width = fraPasos(1).Width
    fraResumen.Height = fraPasos(1).Height
    sprResumen.Width = fraResumen.Width - 480
    sprResumen.Height = fraResumen.Height - 1200
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set MAdo = Nothing
    Gtc(Micx).ihijas = Gtc(Micx).ihijas - 1
    Set MoBitacora = Nothing
    Set clsSpread = Nothing
    Set FCO2096 = Nothing
End Sub

Private Sub fraPasos_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
    MostrarInfo ""
End Sub

Private Sub optResumen_Click(Index As Integer)
    Screen.MousePointer = vbHourglass
    ArmaQueryResumen
    MuestraResultadosResumen
    Screen.MousePointer = vbDefault
End Sub

Private Sub optSistema_Click(Index As Integer)
    Dim i As Byte
    For i = 1 To 3
        lblLabels(i + 4).Enabled = False
        txtDatos(i).Text = ""
        txtDatos(i).Enabled = False
        txtDatosDes(i).Text = ""
        dtF4Datos(i).Habilitado = False
    Next i
    
    Select Case Index
        Case 0
            lblLabels(5).Enabled = True
            txtDatos(1).Enabled = True
            dtF4Datos(1).Habilitado = True
        Case 1
            lblLabels(6).Enabled = True
            txtDatos(2).Enabled = True
            dtF4Datos(2).Habilitado = True
        Case 3
            lblLabels(7).Enabled = True
            txtDatos(3).Enabled = True
            dtF4Datos(3).Habilitado = True
    End Select
End Sub

Private Sub optSistema_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        KeyAscii = 0
        SendEnter
    End If
End Sub

Private Sub sprDatos_Change(ByVal Col As Long, ByVal Row As Long)
    Dim vAux As Variant

    MoBitacora.mCambia
    If Col = 11 Or Col = 20 Then
        sprDatos.GetText Col, Row, vAux
        Select Case MAdo.DBMS
            Case "SQLSERVER"
                MAdo.Sql = "SELECT 1 FROM criterios_valores_col WHERE campo = 'tipo_documento' AND LEFT(descripcion, 2) = '" & CStr(vAux) & "'"
            Case Else
                MAdo.Sql = "SELECT 1 FROM criterios_valores_col WHERE campo = 'tipo_documento' AND SUBSTR(descripcion, 1, 2) = '" & CStr(vAux) & "'"
        End Select
        If MAdo.SendSQL Then
            If MAdo.EOF Then
                clsMsgbox.Mensaje "El valor digitado no es valido (o falta llenar la tabla criterios_valores_col)", mAceptar, mAdvierte, GsTitMsg
                sprDatos.SetText Col, Row, ""
            End If
        End If
    End If
    If Col = 13 Then
        sprDatos.GetText Col, Row, vAux
        MAdo.Sql = "SELECT 1 FROM criterios_valores_col WHERE campo = 'tipo_pension' AND item = " & CStr(vAux)
        If MAdo.SendSQL Then
            If MAdo.EOF Then
                clsMsgbox.Mensaje "El valor digitado no es valido (o falta llenar la tabla criterios_valores_col)", mAceptar, mAdvierte, GsTitMsg
                sprDatos.SetText Col, Row, ""
            End If
        End If
    End If
    If Col = 42 Then
        If MeSistema = Salud Or MeSistema = Pension Then
            sprDatos.GetText Col, Row, vAux
            If Trim(CStr(vAux)) <> "" Then
                MAdo.Sql = "SELECT cod_super, descripcion FROM vw_fco_administradoras" & _
                " WHERE compania = '" & GsCveCia & "' AND codigo = '" & CStr(vAux) & "'" & _
                " AND tipo = '" & IIf(MeSistema = Salud, "EPS", "AFP") & "'"
                If MAdo.SendSQL Then
                    If MAdo.EOF Then
                        clsMsgbox.Mensaje "La " & IIf(MeSistema = Salud, "EPS", "AFP") & " digitada no existe", mAceptar, mAdvierte, GsTitMsg
                        sprDatos.SetText Col, Row, ""
                    Else
                        sprDatos.SetText 43, Row, MAdo.GetField(1)
                        sprDatos.SetText 44, Row, MAdo.GetField(2)
                    End If
                End If
            End If
        End If
    End If
End Sub

Private Sub sprDatos_ColWidthChange(ByVal Col1 As Long, ByVal Col2 As Long)
    RedimensionaTextos
End Sub

Private Sub sprDatos_EditMode(ByVal Col As Long, ByVal Row As Long, ByVal Mode As Integer, ByVal ChangeMade As Boolean)
    MoBitacora.mCambia
End Sub

Private Sub sprDatos_KeyPress(KeyAscii As Integer)
    If sprDatos.ActiveCol > 29 And sprDatos.ActiveCol < 38 Then
        KeyAscii = iValidarDato(KeyAscii, "X ", True, True)
    End If
End Sub

Private Sub sprDatos_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then dtF41_Click
End Sub

Private Sub sprDatos_LeaveCell(ByVal Col As Long, ByVal Row As Long, ByVal NewCol As Long, ByVal NewRow As Long, Cancel As Boolean)
    MostrarInfo ""
End Sub

Private Sub sprDatos_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim xtc As Long
    Dim ytc As Long
    Dim wtc As Long
    Dim htc As Long
    Dim vAux As Variant
    Dim i As Long
    Dim bRecorrer As Boolean
    Dim sTemp As String
    
    MostrarInfo ""
    
    'Tipo de Pensión
    sprDatos.GetCellPos 13, 0, xtc, ytc, wtc, htc
    
    If x >= xtc And x <= xtc + wtc And y >= ytc Then
        i = sprDatos.TopRow
        bRecorrer = True
        While bRecorrer
            sprDatos.GetCellPos 13, i, xtc, ytc, wtc, htc
            If y >= ytc And y <= ytc + htc Then
                bRecorrer = False
            Else
                i = i + 1
            End If
            If i > sprDatos.MaxRows Then bRecorrer = False
        Wend
        sprDatos.GetText 13, i, vAux
        sTemp = "Tipo de Pensión: " & CStr(vAux) & ". "
        sprDatos.GetText 14, i, vAux
        sTemp = sTemp & CStr(vAux)
        MostrarInfo sTemp
    End If
    
    'Novedades
    sprDatos.GetCellPos 30, 0, xtc, ytc, wtc, htc
    If x >= xtc And x <= xtc + wtc Then MostrarInfo "Novedad ING: Ingreso"
    sprDatos.GetCellPos 31, 0, xtc, ytc, wtc, htc
    If x >= xtc And x <= xtc + wtc Then MostrarInfo "Novedad RET: Retiro"
    sprDatos.GetCellPos 32, 0, xtc, ytc, wtc, htc
    If x >= xtc And x <= xtc + wtc Then MostrarInfo "Novedad TDE: Ingreso a esta EPS"
    sprDatos.GetCellPos 33, 0, xtc, ytc, wtc, htc
    If x >= xtc And x <= xtc + wtc Then MostrarInfo "Novedad TAE: Retiro de esta EPS"
    sprDatos.GetCellPos 34, 0, xtc, ytc, wtc, htc
    If x >= xtc And x <= xtc + wtc Then MostrarInfo "Novedad TDP: Ingreso a esta AFP"
    sprDatos.GetCellPos 35, 0, xtc, ytc, wtc, htc
    If x >= xtc And x <= xtc + wtc Then MostrarInfo "Novedad TAP: Retiro de esta AFP"
    sprDatos.GetCellPos 36, 0, xtc, ytc, wtc, htc
    If x >= xtc And x <= xtc + wtc Then MostrarInfo "Novedad VSP: Variación Salario Permanente"
    sprDatos.GetCellPos 37, 0, xtc, ytc, wtc, htc
    If x >= xtc And x <= xtc + wtc Then MostrarInfo "Novedad SUS: Suspensión"
    
    If MeSistema = Salud Then
        'Información de la EPS
        sprDatos.GetCellPos 39, 0, xtc, ytc, wtc, htc
        
        If x >= xtc And x <= xtc + wtc Then
            i = sprDatos.TopRow
            bRecorrer = True
            While bRecorrer
                sprDatos.GetCellPos 39, i, xtc, ytc, wtc, htc
                If y >= ytc And y <= ytc + htc Then
                    bRecorrer = False
                Else
                    i = i + 1
                End If
                If i > sprDatos.MaxRows Then bRecorrer = False
            Wend
            sprDatos.GetText 39, i, vAux
            sTemp = "EPS: " & Trim(CStr(vAux)) & " "
            sprDatos.GetText 40, i, vAux
            sTemp = sTemp & " Código " & Trim(CStr(vAux))
            sprDatos.GetText 41, i, vAux
            sTemp = sTemp & " " & Trim(CStr(vAux))
            MostrarInfo sTemp
        End If
        
        'Información de la Nueva EPS
        sprDatos.GetCellPos 42, 0, xtc, ytc, wtc, htc
        
        If x >= xtc And x <= xtc + wtc Then
            i = sprDatos.TopRow
            bRecorrer = True
            While bRecorrer
                sprDatos.GetCellPos 42, i, xtc, ytc, wtc, htc
                If y >= ytc And y <= ytc + htc Then
                    bRecorrer = False
                Else
                    i = i + 1
                End If
                If i > sprDatos.MaxRows Then bRecorrer = False
            Wend
            sprDatos.GetText 42, i, vAux
            If Trim(CStr(vAux)) <> "" Then
                sTemp = "EPS: " & Trim(CStr(vAux)) & " "
                sprDatos.GetText 43, i, vAux
                sTemp = sTemp & " Código " & Trim(CStr(vAux))
                sprDatos.GetText 44, i, vAux
                sTemp = sTemp & " " & Trim(CStr(vAux))
                MostrarInfo sTemp
            End If
        End If
    End If
    
    If MeSistema = Pension Then
        'Información de la AFP
        sprDatos.GetCellPos 39, 0, xtc, ytc, wtc, htc
        
        If x >= xtc And x <= xtc + wtc Then
            i = sprDatos.TopRow
            bRecorrer = True
            While bRecorrer
                sprDatos.GetCellPos 39, i, xtc, ytc, wtc, htc
                If y >= ytc And y <= ytc + htc Then
                    bRecorrer = False
                Else
                    i = i + 1
                End If
                If i > sprDatos.MaxRows Then bRecorrer = False
            Wend
            sprDatos.GetText 39, i, vAux
            sTemp = "AFP: " & Trim(CStr(vAux)) & " "
            sprDatos.GetText 40, i, vAux
            sTemp = sTemp & " Código " & Trim(CStr(vAux))
            sprDatos.GetText 41, i, vAux
            sTemp = sTemp & " " & Trim(CStr(vAux))
            MostrarInfo sTemp
        End If
        
        'Información de la Nueva AFP
        sprDatos.GetCellPos 42, 0, xtc, ytc, wtc, htc
        
        If x >= xtc And x <= xtc + wtc Then
            i = sprDatos.TopRow
            bRecorrer = True
            While bRecorrer
                sprDatos.GetCellPos 42, i, xtc, ytc, wtc, htc
                If y >= ytc And y <= ytc + htc Then
                    bRecorrer = False
                Else
                    i = i + 1
                End If
                If i > sprDatos.MaxRows Then bRecorrer = False
            Wend
            sprDatos.GetText 42, i, vAux
            If Trim(CStr(vAux)) <> "" Then
                sTemp = "AFP: " & Trim(CStr(vAux)) & " "
                sprDatos.GetText 43, i, vAux
                sTemp = sTemp & " Código " & Trim(CStr(vAux))
                sprDatos.GetText 44, i, vAux
                sTemp = sTemp & " " & Trim(CStr(vAux))
                MostrarInfo sTemp
            End If
        End If
    End If

    If MeSistema = Parafiscales Then
        'Información de la CCF
        sprDatos.GetCellPos 39, 0, xtc, ytc, wtc, htc
        
        If x >= xtc And x <= xtc + wtc Then
            i = sprDatos.TopRow
            bRecorrer = True
            While bRecorrer
                sprDatos.GetCellPos 39, i, xtc, ytc, wtc, htc
                If y >= ytc And y <= ytc + htc Then
                    bRecorrer = False
                Else
                    i = i + 1
                End If
                If i > sprDatos.MaxRows Then bRecorrer = False
            Wend
            sprDatos.GetText 39, i, vAux
            sTemp = "CCF: " & Trim(CStr(vAux)) & " "
            sprDatos.GetText 40, i, vAux
            sTemp = sTemp & " Código " & Trim(CStr(vAux))
            sprDatos.GetText 41, i, vAux
            sTemp = sTemp & " " & Trim(CStr(vAux))
            MostrarInfo sTemp
        End If
    End If
End Sub

Private Sub sprDatos_TopLeftChange(ByVal OldLeft As Long, ByVal OldTop As Long, ByVal NewLeft As Long, ByVal NewTop As Long)
    RedimensionaTextos
End Sub

Private Sub txtAgr_KeyPress(KeyAscii As Integer)
    On Error Resume Next
    
    If KeyAscii = vbKeyReturn Then
        KeyAscii = 0
        If Trim(txtAgr) = "" Then
            txtDatos(1).SetFocus
        Else
            txtDato.SetFocus
        End If
    End If
End Sub

Private Sub txtAgr_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then dtF4Agr_Click
End Sub

Private Sub txtDato_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        KeyAscii = 0
        SendEnter
        SendEnter
    End If
End Sub

Private Sub txtDato_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then dtF4Dato_Click
End Sub

Private Sub txtDatos_Change(Index As Integer)
    MbDatos_OK(Index) = False
    txtDatosDes(Index) = ""
End Sub

Private Sub txtDatos_GotFocus(Index As Integer)
    txtDatos(Index).SelStart = 0
    txtDatos(Index).SelLength = Len(txtDatos(Index))
End Sub

Private Sub txtDatos_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then
        dtF4Datos_Click Index
    End If
End Sub

Private Sub txtDatos_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        ValidarDato Index
        On Error Resume Next
        cmdContinuar.SetFocus
    End If
End Sub

Private Sub txtFiltro_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Or KeyAscii = 10 Then
        Screen.MousePointer = vbHourglass
        AplicaFiltros
        Screen.MousePointer = vbDefault
    End If
End Sub

Private Sub txtTrabajador_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        KeyAscii = 0
        SendEnter
        SendEnter
    End If
End Sub

Private Sub txtTrabajador_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then dtF4Tra_Click
End Sub

Private Sub AplicaFiltros()
    Dim i As Integer
    Dim k As Byte
    Dim iTc(0 To 9) As TipoCampo
    Dim sCampos(0 To 9) As String
    
    iTc(0) = AlfaNumerico: iTc(1) = AlfaNumerico: iTc(2) = Numerico: iTc(3) = AlfaNumerico: iTc(4) = AlfaNumerico
    iTc(5) = AlfaNumerico: iTc(6) = AlfaNumerico: iTc(7) = AlfaNumerico: iTc(8) = Numerico: iTc(9) = Numerico
    
    sCampos(0) = "sucursal"
    sCampos(1) = "trabajador"
    sCampos(2) = "secuencia"
    sCampos(3) = "pens_ape1"
    sCampos(4) = "pens_ape2"
    sCampos(5) = "pens_nom1"
    sCampos(6) = "pens_nom2"
    sCampos(7) = "pens_tdoc"
    sCampos(8) = "pens_id"
    sCampos(9) = "tipo_pension"
    
    MsSql = MsSqlIni
    For i = 0 To MiCampos - 1
        If Trim(txtFiltro(i)) <> "" Then
            If iTc(i) = Numerico Then
                MsSql = MsSql & " AND " & sCampos(i) & " = " & Val(txtFiltro(i))
            Else
                If iTc(i) = Fecha Then
                    MsSql = MsSql & " AND " & sCampos(i) & " = '" & Format(txtFiltro(i), "yyyymmdd") & "'"
                Else
                    MsSql = MsSql & " AND " & sCampos(i) & " LIKE '%" & txtFiltro(i) & "%'"
                End If
            End If
        End If
    Next i
    RenuevaDatos
End Sub

Private Sub ArmaQuery()
    Dim sSELECT As String
    Dim sFROM As String
    Dim sWHERE As String
    
    'Armando el SELECT común
    sSELECT = _
    " SELECT compania, anio, mes, sucursal, trabajador, secuencia, pens_ape1, pens_ape2, pens_nom1, pens_nom2, pens_tdoc, pens_id," & _
    " tipo_pension, tipo_pension_des, pension_compartida, caus_ape1, caus_ape2, caus_nom1, caus_nom2, caus_tdoc, caus_id, " & _
    " tipo_pensionado, tipo_pensionado_des, residente_en_exterior, departamento, departamento_des, municipio, municipio_des," & _
    " situa_en_exterior, nov_ING, nov_RET, nov_TDE, nov_TAE, nov_TDP, nov_TAP, nov_VSP, nov_SUS, mesada"
    
    'Campos adicionales según el sistema que quiere editarse
    Select Case MeSistema
        Case Salud
            sSELECT = sSELECT & ", cod_EPS, eps_cod_super, eps_nombre, cod_EPS_Tras, neps_cod_super, neps_nombre, dias_EPS, tarifa_EPS, aporte_EPS, UPC_adicional"
        Case Pension
            sSELECT = sSELECT & ", cod_AFP, afp_cod_super, afp_nombre, cod_AFP_Tras, nafp_cod_super, nafp_nombre, dias_AFP, tarifa_AFP, aporte_AFP, voluntario_AFP, aporte_total_AFP, valor_no_retenido, dias_FSP, aporte_FSP_sol, aporte_FSP_sub, tarifa_FSP"
        Case Parafiscales
            sSELECT = sSELECT & ", cod_CCF, ccf_cod_super, ccf_nombre, dias_CCF, tarifa_CCF, aporte_CCF"
    End Select
    
    sFROM = " FROM vw_fco_pi_pens_det a"
    
    sWHERE = _
    " WHERE compania = " & "'" & GsCveCia & "'" & _
    " AND anio = " & MsAnio & _
    " AND mes = " & MsMes & _
    IIf(MsSucursal = "", "", " AND sucursal = '" & MsSucursal & "'") & _
    MsFiltrosOpc
    
    MsSqlIni = sSELECT & sFROM & sWHERE
    MsSql = MsSqlIni
End Sub

Private Sub ArmaQueryResumen()
    Dim sSELECT As String
    Dim sFROM As String
    Dim sWHERE As String
    Dim sWHEREADI As String
    Dim sGROUPBY As String
    Dim sORDERBY As String
    
    Select Case MeSistema
        Case Salud
            If optResumen(0).Value Then
                sSELECT = "SELECT sucursal, cod_EPS, eps_nombre, SUM(mesada), SUM(aporte_EPS), SUM(UPC_adicional), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY sucursal, cod_EPS, eps_nombre"
            End If
            If optResumen(1).Value Then
                sSELECT = "SELECT sucursal, '', suc_nombre, SUM(mesada), SUM(aporte_EPS), SUM(UPC_adicional), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY sucursal, suc_nombre"
            End If
            If optResumen(2).Value Then
                sSELECT = "SELECT cod_EPS, eps_nombre, sucursal, SUM(mesada), SUM(aporte_EPS), SUM(UPC_adicional), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY cod_EPS, eps_nombre, sucursal"
            End If
            If optResumen(3).Value Then
                sSELECT = "SELECT cod_EPS, '', eps_nombre, SUM(mesada), SUM(aporte_EPS), SUM(UPC_adicional), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY cod_EPS, eps_nombre"
            End If
            If optResumen(4).Value Then
                sSELECT = "SELECT 'Totales:', '', '', SUM(mesada), SUM(aporte_EPS), SUM(UPC_adicional), COUNT(Distinct trabajador)"
            End If
        Case Pension
            If optResumen(0).Value Then
                sSELECT = "SELECT sucursal, cod_AFP, afp_nombre, SUM(mesada), SUM(aporte_AFP), SUM(voluntario_AFP), SUM(aporte_total_AFP), SUM(aporte_FSP_sol), SUM(aporte_FSP_sub), SUM(valor_no_retenido), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY sucursal, cod_AFP, afp_nombre"
            End If
            If optResumen(1).Value Then
                sSELECT = "SELECT sucursal, '', suc_nombre, SUM(mesada), SUM(aporte_AFP), SUM(voluntario_AFP), SUM(aporte_total_AFP), SUM(aporte_FSP_sol), SUM(aporte_FSP_sub), SUM(valor_no_retenido), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY sucursal, suc_nombre"
            End If
            If optResumen(2).Value Then
                sSELECT = "SELECT cod_AFP, afp_nombre, sucursal, SUM(mesada), SUM(aporte_AFP), SUM(voluntario_AFP), SUM(aporte_total_AFP), SUM(aporte_FSP_sol), SUM(aporte_FSP_sub), SUM(valor_no_retenido), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY cod_AFP, afp_nombre, sucursal"
            End If
            If optResumen(3).Value Then
                sSELECT = "SELECT cod_AFP, '', afp_nombre, SUM(mesada), SUM(aporte_AFP), SUM(voluntario_AFP), SUM(aporte_total_AFP), SUM(aporte_FSP_sol), SUM(aporte_FSP_sub), SUM(valor_no_retenido), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY cod_AFP, afp_nombre"
            End If
            If optResumen(4).Value Then
                sSELECT = "SELECT 'Totales:', '', '', SUM(mesada), SUM(aporte_AFP), SUM(voluntario_AFP), SUM(aporte_total_AFP), SUM(aporte_FSP_sol), SUM(aporte_FSP_sub), SUM(valor_no_retenido), COUNT(Distinct trabajador)"
            End If
        Case Parafiscales
            If optResumen(0).Value Then
                sSELECT = "SELECT sucursal, cod_CCF, ccf_nombre, SUM(mesada), SUM(aporte_CCF), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY sucursal, cod_CCF, ccf_nombre"
            End If
            If optResumen(1).Value Then
                sSELECT = "SELECT sucursal, '', suc_nombre, SUM(mesada), SUM(aporte_CCF), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY sucursal, suc_nombre"
            End If
            If optResumen(2).Value Then
                sSELECT = "SELECT cod_CCF, ccf_nombre, sucursal, SUM(mesada), SUM(aporte_CCF), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY cod_CCF, ccf_nombre, sucursal"
            End If
            If optResumen(3).Value Then
                sSELECT = "SELECT cod_CCF, '', ccf_nombre, SUM(mesada), SUM(aporte_CCF), COUNT(Distinct trabajador)"
                sGROUPBY = " GROUP BY cod_CCF, ccf_nombre"
            End If
            If optResumen(4).Value Then
                sSELECT = "SELECT 'Totales:', '', '', SUM(mesada), SUM(aporte_CCF), COUNT(Distinct trabajador)"
            End If
    End Select
    
    sFROM = " FROM vw_fco_pi_pens_det a"
    
    sWHERE = _
    " WHERE compania = " & "'" & GsCveCia & "'" & _
    " AND anio = " & MsAnio & _
    " AND mes = " & MsMes & _
    IIf(MsSucursal = "", "", " AND sucursal = '" & MsSucursal & "'") & _
    MsFiltrosOpc
    
    'Excluir registros en ceros
    Select Case MeSistema
        Case Salud: sWHEREADI = " AND mesada + aporte_EPS + UPC_adicional <> 0 "
        Case Pension: sWHEREADI = " AND mesada + aporte_AFP + voluntario_AFP + aporte_total_AFP + aporte_FSP_sol + aporte_FSP_sub + valor_no_retenido <> 0 "
        Case Parafiscales: sWHEREADI = " AND mesada + aporte_CCF <> 0 "
    End Select
    
    'Deducción del Orden
    If optResumen(0).Value Then sORDERBY = " ORDER BY 1, 2"
    If optResumen(1).Value Then sORDERBY = " ORDER BY 1"
    If optResumen(2).Value Then sORDERBY = " ORDER BY 1, 3"
    If optResumen(3).Value Then sORDERBY = " ORDER BY 1"
    If optResumen(4).Value Then sORDERBY = ""
    
    MsSqlResumen = sSELECT & sFROM & sWHERE & sWHEREADI & sGROUPBY & sORDERBY
End Sub

Private Sub Atras()
    Dim bMaxim As Boolean
    On Error Resume Next 'Necesario porque hay SetFocus
        
    Screen.MousePointer = vbHourglass
        
    Set MoBitacora = Nothing
    If WindowState = vbMaximized Then
        bMaxim = True
        Visible = False
        WindowState = vbNormal
    End If
    abToolbar.Bands(0).Visible = False
    If bMaxim Then
        WindowState = vbMaximized
        Visible = True
    End If
    
    cmdContinuar.Visible = True
    fraPasos(0).Visible = True
    Width = 7590
    Height = 5820
    fraPasos(1).Visible = False
    fraInfo.Visible = False
    fraResumen.Visible = False
    
    Screen.MousePointer = vbDefault
End Sub

Private Sub CreaBitacora()
    MoBitacora.mCreaBitacora sprDatos, MAdo.lhEnv, MAdo.lhDbc, MAdo.lhstmt, MAdo
    MoBitacora.p_ConfirmaBaja = True
    MoBitacora.mDefineLlave 1
    MoBitacora.mColNoNulls 1
    Select Case MeSistema
        Case Salud
            MoBitacora.mTablaSPInfo 2, "sp_fco_upd_pi_pens_det_eps", 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 42, 45, 38, 46, 47, 48
        Case Pension
            MoBitacora.mTablaSPInfo 2, "sp_fco_upd_pi_pens_det_afp", 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 42, 45, 51, 38, 46, 47, 48, 50, 52, 53, 54
        Case Parafiscales
            MoBitacora.mTablaSPInfo 2, "sp_fco_upd_pi_pens_det_ccf", 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 42, 38, 43, 44
    End Select
End Sub

Private Sub GuardaCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    GbRen = MoBitacora.mActualizaBD
    MoBitacora.mVaciaBuffer
    SpreadPropiedades
    RedimensionaTextos
    Screen.MousePointer = vbDefault
End Sub

Private Function iDeseaGuardarCambios() As Integer
    ' Descripción : Devuelve el valor de la opción seleccionada en la clsMsgBox
    ' Uso : iDeseaGuardarCambios
    ' Regresa : Un Entero , dependiendo de la respuesta en clsMsgBox
    If MoBitacora.pTransActual > 0 Then
       iDeseaGuardarCambios = clsMsgbox.Mensaje("¿Desea guardar los cambios?", mSiNoCancelar, mConfirma, GsTitMsg)
       Select Case iDeseaGuardarCambios
          Case vbYes
             GuardaCambios
             If GbRen = 0 Then iDeseaGuardarCambios = 2
          Case vbNo
             MoBitacora.mVaciaBuffer 'Vacía el Buffer de la Bitácora
       End Select
    Else
        iDeseaGuardarCambios = 1
    End If
End Function

Private Sub LlenarCombos()
    Dim i As Byte
    Dim iSec As Integer
    Dim sPar As String

    'Combo de Períodos con Autoliquidación
    Select Case MAdo.DBMS
        Case "SQLSERVER"
            MAdo.Sql = "SELECT DISTINCT RTRIM(anio) + '-' + RIGHT('00' + RTRIM(mes), 2), sit_periodo FROM fco_pi_pens_rt1"
        Case Else
            MAdo.Sql = "SELECT DISTINCT RTRIM(anio) || '-' || LPAD(RTRIM(mes), 2, '0'), sit_periodo FROM fco_pi_pens_rt1"
    End Select
    If MAdo.SendSQL Then
        Do Until MAdo.EOF
            cboPeriodo.AddItem MAdo.GetField(1)
            cboPeriodo.ItemData(cboPeriodo.NewIndex) = MAdo.GetField(2)
            MAdo.Mnext
        Loop
    End If
    
    'Combo de Sucursales
    cboSuc.Clear
    MAdo.Sql = "SELECT forma_presentacion FROM vw_fco_cias_datos_adi WHERE compania = '" & GsCveCia & "'"
    MAdo.SendSQL
    If Not MAdo.EOF Then
        If UCase(MAdo.GetField(1)) = "S" Then
            cboSuc.AddItem "(Todas)"
            MAdo.Sql = "SELECT sucursal, RTRIM(descripcion)" & _
            " FROM vw_fco_sucursales" & _
            " WHERE compania = '" & GsCveCia & "'" & _
            " AND autoliquida = 1" & _
            " ORDER BY 1"
            If MAdo.SendSQL Then
                Do Until MAdo.EOF
                    cboSuc.AddItem Trim(MAdo.GetField(1)) & "-" & Trim(MAdo.GetField(2))
                    ReDim Preserve MsSUC(cboSuc.NewIndex)
                    MsSUC(cboSuc.NewIndex) = MAdo.GetField(1)
                    MAdo.Mnext
                Loop
            End If
        Else
            cboSuc.AddItem "(Consolidado)"
        End If
    End If
    If cboSuc.ListCount = 1 Then
        cboSuc.ListIndex = 0
        lblLabels(2).Enabled = False
        cboSuc.Enabled = False
    End If
    
    'Se aprovecha para recuperar parámetros (EPS, AFP y CCF)
    MsAgr(1) = sParametroFDT(MAdo, "autoliq", "COL", 21)
    MsAgr(2) = sParametroFDT(MAdo, "autoliq", "COL", 22)
    MsAgr(3) = sParametroFDT(MAdo, "parafiscal", "COL", 1)
End Sub

Private Sub MostrarInfo(Mensaje As String)
    lblInfo.Caption = "  " & Mensaje & "  "
    If Trim(lblInfo.Caption) = "" Then
        lblInfo.Visible = False
    Else
        lblInfo.Visible = True
    End If
End Sub

Private Sub MostrarResumen()
    Screen.MousePointer = vbHourglass
    If fraResumen.Visible Then
        'Hay que mostrar los DETALLES
        fraPasos(1).Visible = True
        fraResumen.Visible = False
        abToolbar.Bands(0).Tools(3).ToolTipText = "Resumen y Totales"
        abToolbar.Bands(0).Tools(1).Enabled = True
        abToolbar.Bands(0).Tools(2).Enabled = True
        abToolbar.Bands(0).Tools(4).Enabled = True
    Else
        'Hay que mostrar el RESUMEN
        fraPasos(1).Visible = False
        fraResumen.Visible = True
        abToolbar.Bands(0).Tools(3).ToolTipText = "Detalles"
        abToolbar.Bands(0).Tools(1).Enabled = False
        abToolbar.Bands(0).Tools(2).Enabled = False
        abToolbar.Bands(0).Tools(4).Enabled = False
        ArmaQueryResumen
        MuestraResultadosResumen
        Select Case MeSistema
            Case Salud
                optResumen(0).Caption = "Por Sucursal y EPS"
                optResumen(2).Caption = "Por EPS y Sucursal"
                optResumen(3).Caption = "Por EPS"
            Case Pension
                optResumen(0).Caption = "Por Sucursal y AFP"
                optResumen(2).Caption = "Por AFP y Sucursal"
                optResumen(3).Caption = "Por AFP"
            Case Parafiscales
                optResumen(0).Caption = "Por Sucursal y CCF"
                optResumen(2).Caption = "Por CCF y Sucursal"
                optResumen(3).Caption = "Por CCF"
        End Select
    End If
    Screen.MousePointer = vbDefault
End Sub

Private Sub MuestraResultadosResumen()
    Dim i As Long
    Dim sCol1 As String
    Dim sCol2 As String
    Dim sCol3 As String
    Dim iCol1 As Integer
    Dim iCol2 As Integer
    Dim iCol3 As Integer

    'Resolviendo los títulos y los anchos de las primeras 3 columnas
    If optResumen(0).Value Or optResumen(1).Value Then
        sCol1 = "Sucursal"
        iCol1 = 7
        Select Case MeSistema
            Case Salud: sCol2 = "EPS"
            Case Pension: sCol2 = "AFP"
            Case Parafiscales: sCol2 = "CCF"
        End Select
        iCol2 = 5
        sCol3 = "Nombre"
        iCol3 = 20
    End If
    If optResumen(2).Value Or optResumen(3).Value Then
        sCol3 = "Sucursal"
        iCol3 = 7
        Select Case MeSistema
            Case Salud: sCol1 = "EPS"
            Case Pension: sCol1 = "AFP"
            Case Parafiscales: sCol1 = "CCF"
        End Select
        iCol1 = 5
        sCol2 = "Nombre"
        iCol2 = 20
    End If
    If optResumen(4).Value Then
        sCol1 = " "
        iCol1 = 7
        sCol2 = " "
        iCol2 = 0
        sCol3 = " "
        iCol3 = 0
    End If


    With sprResumen
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprResumen
        .Row = 0
        Select Case MeSistema
            Case Salud
                '.VisibleCols = 6
                .Col = 1: .Text = sCol1
                .Col = 2: .Text = sCol2
                .Col = 3: .Text = sCol3
                .Col = 4: .Text = "Mesada"
                .Col = 5: .Text = "Aportes"
                .Col = 6: .Text = "UPC Adicional"
                .Col = 7: .Text = "Afiliados"
            Case Pension
                '.VisibleCols = 10
                .Col = 1: .Text = sCol1
                .Col = 2: .Text = sCol2
                .Col = 3: .Text = sCol3
                .Col = 4: .Text = "Mesada"
                .Col = 5: .Text = "Aportes"
                .Col = 6: .Text = "Voluntarios"
                .Col = 7: .Text = "Total Aportes"
                .Col = 8: .Text = "FSP Solid."
                .Col = 9: .Text = "FSP Subs."
                .Col = 10: .Text = "Vlr.No Ret."
                .Col = 11: .Text = "Afiliados"
            Case Parafiscales
                '.VisibleCols = 5
                .Col = 1: .Text = sCol1
                .Col = 2: .Text = sCol2
                .Col = 3: .Text = sCol3
                .Col = 4: .Text = "Mesada"
                .Col = 5: .Text = "Aporte CCF"
                .Col = 6: .Text = "Afiliados"
        End Select
        .Row = -1
        .Col = 1: .Lock = True
        
        ConfiguraSpreadJCL sprResumen
        .Visible = False
    End With

    MAdo.Sql = MsSqlResumen

    If MAdo.SendSQL Then
        clsSpread.LlenaSpread 0, sprResumen, MAdo, MAdo.lhDbc, MAdo.lhstmt
            
        With sprResumen
            .Row = -1
            Select Case MeSistema
                Case Salud
                    .ColWidth(1) = iCol1    'Sucursal
                    .ColWidth(2) = iCol2    'EPS
                    .ColWidth(3) = iCol3    'Nombre
                    .ColWidth(4) = 10       'Mesada
                    .ColWidth(5) = 10       'Aportes
                    .ColWidth(6) = 10       'UPC Adicional
                    
                    .Col = 4: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    .Col = 5: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    .Col = 6: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    
                Case Pension
                    .ColWidth(1) = iCol1    'Sucursal
                    .ColWidth(2) = iCol2    'AFP
                    .ColWidth(3) = iCol3    'Nombre
                    .ColWidth(4) = 10       'Mesada
                    .ColWidth(5) = 10       'Aportes
                    .ColWidth(6) = 10       'Voluntarios
                    .ColWidth(7) = 10       'Total
                    .ColWidth(8) = 10       'FSP
                    .ColWidth(9) = 10       'FSP
                    .ColWidth(10) = 10       'Valor No Retenido
                                
                    .Col = 4: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    .Col = 5: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    .Col = 6: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    .Col = 7: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    .Col = 8: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    .Col = 9: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                    .Col = 10: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
                                
                Case Parafiscales
                    .ColWidth(1) = iCol1    'Sucursal
                    .ColWidth(2) = iCol2    'Caja de Compensación Familiar
                    .ColWidth(3) = iCol3    'Nombre
                    .ColWidth(4) = 10       'Aportes Caja de Compensación
            
                    .Col = 4: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
            End Select
            
            'Columnas Ocultas
            If optResumen(1).Value Or optResumen(3).Value Then
                .Col = 2
                .ColHidden = True
            End If
            If optResumen(4).Value Then
                .Col = 2
                .ColHidden = True
                .Col = 3
                .ColHidden = True
                GAdam.AjustaSpread sprResumen, 1
            End If
            
            'Ajustar Spread
            If optResumen(0).Value Then GAdam.AjustaSpread sprResumen, 3
            If optResumen(1).Value Then GAdam.AjustaSpread sprResumen, 3
            If optResumen(2).Value Then GAdam.AjustaSpread sprResumen, 2
            If optResumen(3).Value Then GAdam.AjustaSpread sprResumen, 3
            If optResumen(4).Value Then GAdam.AjustaSpread sprResumen, 1
            
            'Poner las filas pares de otro color para facilitar revisión del usuario
            For i = 2 To .MaxRows Step 2
                .Row = i: .Col = -1: .BackColor = RGB(0, 236, 236)
            Next i

            .Row = -1: .Col = -1: .Lock = True
            
            .Visible = True
        End With
    End If
End Sub

Private Sub OrdenarDatos()
    Screen.MousePointer = vbHourglass
    If MsAntOrden = CStr(sprDatos.ActiveCol) Then
        MbOrdenAsc = Not (MbOrdenAsc)
    Else
        MbOrdenAsc = True
    End If
    MSOrder = " Order By 1, 3, " & CStr(sprDatos.ActiveCol) & IIf(MbOrdenAsc, "", "DESC")
    MsAntOrden = CStr(sprDatos.ActiveCol)
    AplicaFiltros
    Screen.MousePointer = vbDefault
End Sub

Private Sub RedimensionaTextos()
    Dim nAncho As Long
    Dim nPosAcum As Long
    Dim i As Integer
    Dim k As Integer
    Dim x As Integer
    
    x = 3 'Número de Columnas Ocultas al inicio del Spread
    MiCampos = 11
    For i = 0 To MiCampos - 1
        If i <= sprDatos.LeftCol - x - 2 Then
            txtFiltro(i).Visible = False
        Else
            txtFiltro(i).Visible = True
        End If
    Next i
    nPosAcum = 120
    
    For i = 0 To MiCampos - 1
        If txtFiltro(i).Visible Then
            sprDatos.ColWidthToTwips sprDatos.ColWidth(i + x + 1), nAncho
            If nAncho = 0 Then
                txtFiltro(i).Visible = False
            Else
                txtFiltro(i).Width = nAncho
                If i > 0 Then
                    If txtFiltro(i - 1).Visible Then
                        txtFiltro(i).Left = txtFiltro(i - 1).Left + txtFiltro(i - 1).Width
                    Else
                        txtFiltro(i).Left = nPosAcum
                    End If
                End If
                nPosAcum = txtFiltro(i).Left + txtFiltro(i).Width
            End If
        End If
    Next i
    
    'CODIGO QUE CONTROLA QUE LOS TEXTOS NO SE PASEN DEL ANCHO DEL SPREAD:
    For i = MiCampos - 1 To 0 Step -1
        If i = MiCampos Then k = 120 Else k = 0
        If txtFiltro(i).Left + txtFiltro(i).Width > sprDatos.Width + k Then
            If sprDatos.Width - txtFiltro(i).Left + 120 > 0 Then
                txtFiltro(i).Width = sprDatos.Width - txtFiltro(i).Left + 120
            Else
                txtFiltro(i).Visible = False
            End If
        End If
    Next i
End Sub

Private Sub Refrescar()
    Screen.MousePointer = vbHourglass
    AplicaFiltros
    RedimensionaTextos
    Screen.MousePointer = vbDefault
End Sub

Private Sub RenuevaDatos()
    SpreadConfigura
                                
    MAdo.Sql = MsSql & MSOrder
      
    If MAdo.SendSQL Then
        clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
        SpreadAnchos
        SpreadPropiedades
        sprDatos.Visible = True
    End If

    On Error Resume Next
    sprDatos.SetFocus
End Sub

Private Sub SpreadAnchos()
    With sprDatos
        'Campos Comunes
        .ColWidth(1) = 0        'Compañía
        .ColWidth(2) = 0        'Año
        .ColWidth(3) = 0        'Mes
        .ColWidth(4) = 7        'Sucursal
        .ColWidth(5) = 8        'Trabajador
        .ColWidth(6) = 7        'Secuencia
        .ColWidth(7) = 10       'Ape1 Pensionado
        .ColWidth(8) = 10       'Ape2 Pensionado
        .ColWidth(9) = 10       'Nom1 Pensionado
        .ColWidth(10) = 10      'Nom2 Pensionado
        .ColWidth(11) = 4       'Tipo Doc. Pens.
        .ColWidth(12) = 8       'Id. Pens.
        .ColWidth(13) = 8       'Tipo Pensión
        .ColWidth(14) = 0       'Descripción Tipo Pensión
        .ColWidth(15) = 6       'Compartida
        .ColWidth(16) = 10       'Ape1 Causante
        .ColWidth(17) = 10       'Ape2 Causante
        .ColWidth(18) = 10       'Nom1 Causante
        .ColWidth(19) = 10       'Nom2 Causante
        .ColWidth(20) = 4       'Tipo Doc. Caus.
        .ColWidth(21) = 8       'Id. Caus.
        .ColWidth(22) = 8       'Tipo de Pensionado
        .ColWidth(23) = 0       'Descripción del tipo de pensionado
        .ColWidth(24) = 8       'Residente en el Exterior
        .ColWidth(25) = 5       'Departamento
        .ColWidth(26) = 0       'Nombre Departamento
        .ColWidth(27) = 6       'Municipio
        .ColWidth(28) = 0       'Nombre Municipio
        .ColWidth(29) = 6       'Pension situada exterior
        .ColWidth(30) = 2       'ING
        .ColWidth(31) = 2       'RET
        .ColWidth(32) = 2       'TDE
        .ColWidth(33) = 2       'TAE
        .ColWidth(34) = 2       'TDP
        .ColWidth(35) = 2       'TAP
        .ColWidth(36) = 2       'VSP
        .ColWidth(37) = 2       'SUS
        .ColWidth(38) = 9       'Mesada
        'Campos exclusivos para SALUD
        If MeSistema = Salud Then
            .ColWidth(39) = 5       'cod_EPS
            .ColWidth(40) = 0       'cod super EPS
            .ColWidth(41) = 0       'nombre EPS
            .ColWidth(42) = 5       'nueva EPS
            .ColWidth(43) = 0       'cod super nueva EPS
            .ColWidth(44) = 0       'nombre nueva EPS
            .ColWidth(45) = 5       'Días EPS
            .ColWidth(46) = 6       'Tarifa EPS
            .ColWidth(47) = 9       'Aporte EPS
            .ColWidth(48) = 9       'UPC Adicional
        End If
        'Campos exclusivos para PENSION
        If MeSistema = Pension Then
            .ColWidth(39) = 8       'AFP
            .ColWidth(40) = 0       'Super AFP
            .ColWidth(41) = 0       'Nombre AFP
            .ColWidth(42) = 8       'nueva AFP
            .ColWidth(43) = 0       'Super nueva AFP
            .ColWidth(44) = 0       'Nombre nueva AFP
            .ColWidth(45) = 5       'Días AFP
            .ColWidth(46) = 6       'Tarifa AFP
            .ColWidth(47) = 8       'Aporte AFP
            .ColWidth(48) = 8       'Voluntario AFP
            .ColWidth(49) = 8       'Total AFP
            .ColWidth(50) = 8       'Valor No Retenido
            .ColWidth(51) = 5       'Días FSP
            .ColWidth(52) = 8       'Aporte FSP Solidaridad
            .ColWidth(53) = 8       'Aporte FSP Subsistencia
            .ColWidth(54) = 6       'Tarifa FSP
        End If
        'Campos exclusivos para PARAFISCALES
        If MeSistema = Parafiscales Then
            .ColWidth(39) = 6       'CCF
            .ColWidth(40) = 0       'Super CCF
            .ColWidth(41) = 0       'Nombre CCF
            .ColWidth(42) = 5       'Días CCF
            .ColWidth(43) = 6       'Tarifa CCF
            .ColWidth(44) = 8       'Aporte CCF
        End If
        .RowHeight(0) = 30
    End With
End Sub

Private Sub SpreadConfigura()
    With sprDatos
        Select Case MeSistema
            Case Salud: .VisibleCols = 48
            Case Pension: .VisibleCols = 54
            Case Parafiscales: .VisibleCols = 44
        End Select
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
        .Row = 0:
        .Col = 4: .Text = "Sucursal"
        .Col = 5: .Text = "Trabajador"
        .Col = 6: .Text = "Sec."
        .Col = 7: .Text = "Pens.Ape.1"
        .Col = 8: .Text = "Pens.Ape.2"
        .Col = 9: .Text = "Pens.Nom.1"
        .Col = 10: .Text = "Pens.Nom.2"
        .Col = 11: .Text = "Pens.Tipo Doc."
        .Col = 12: .Text = "Pens.Nro.Id."
        .Col = 13: .Text = "Tipo Pensión"
        .Col = 14: .Text = "TPDes"
        .Col = 15: .Text = "Compartida"
        .Col = 16: .Text = "Caus.Ape.1"
        .Col = 17: .Text = "Caus.Ape.2"
        .Col = 18: .Text = "Caus.Nom.1"
        .Col = 19: .Text = "Caus.Nom.2"
        .Col = 20: .Text = "Caus.Tipo Doc."
        .Col = 21: .Text = "Caus.Nro.Id."
        .Col = 22: .Text = "Tipo Pensionado"
        .Col = 23: .Text = "TPdoDes"
        .Col = 24: .Text = "Reside Ext."
        .Col = 25: .Text = "Dpto"
        .Col = 26: .Text = "NomDep"
        .Col = 27: .Text = "Municipio"
        .Col = 28: .Text = "NomMuni"
        .Col = 29: .Text = "Situar Ext."
        .Col = 30: .Text = "I N G  "
        .Col = 31: .Text = "R E T  "
        .Col = 32: .Text = "T D E  "
        .Col = 33: .Text = "T A E  "
        .Col = 34: .Text = "T D P  "
        .Col = 35: .Text = "T A P  "
        .Col = 36: .Text = "V S P  "
        .Col = 37: .Text = "S U S  "
        .Col = 38: .Text = "Mesada"
        'Campos exclusivos para SALUD
        If MeSistema = Salud Then
            .Col = 39: .Text = "EPS"
            .Col = 40: .Text = "Super EPS"
            .Col = 41: .Text = "Nombr EPS"
            .Col = 42: .Text = "Nueva EPS"
            .Col = 43: .Text = "Super Nueva EPS"
            .Col = 44: .Text = "Nombr Nueva EPS"
            .Col = 45: .Text = "Días EPS"
            .Col = 46: .Text = "Tarifa EPS"
            .Col = 47: .Text = "Aporte EPS"
            .Col = 48: .Text = "UPC Adicional"
        End If
        'Campos exclusivos para PENSION
        If MeSistema = Pension Then
            .Col = 39: .Text = "AFP"
            .Col = 40: .Text = "AFP Super"
            .Col = 41: .Text = "AFP Nombre"
            .Col = 42: .Text = "Nueva AFP"
            .Col = 43: .Text = "Nueva AFP Super"
            .Col = 44: .Text = "Nueva AFP Nombre"
            .Col = 45: .Text = "Días AFP"
            .Col = 46: .Text = "Tarifa AFP"
            .Col = 47: .Text = "Aporte AFP"
            .Col = 48: .Text = "Voluntario"
            .Col = 49: .Text = "Aporte Total"
            .Col = 50: .Text = "Valor No Retenido"
            .Col = 51: .Text = "Días FSP"
            .Col = 52: .Text = "FSP Solid."
            .Col = 53: .Text = "FSP Subs."
            .Col = 54: .Text = "Tarifa FSP"
        End If
        'Campos exclusivos para PARAFISCALES
        If MeSistema = Parafiscales Then
            .Col = 39: .Text = "CCF"
            .Col = 40: .Text = "CCF Super"
            .Col = 41: .Text = "CCF Nombre"
            .Col = 42: .Text = "Días CCF"
            .Col = 43: .Text = "Tarifa CCF"
            .Col = 44: .Text = "Aporte CCF"
        End If

        .Row = -1
        .Col = 1: .Lock = True
        
        ConfiguraSpreadJCL sprDatos
        .Visible = False
    End With
End Sub

Private Sub SpreadPropiedades()
    Dim i As Long
    
    With sprDatos
        'Columnas no editables
        .Row = -1
        .Col = 1: .Lock = True  'Compañía
        .Col = 2: .Lock = True  'Año
        .Col = 3: .Lock = True  'Mes
        .Col = 4: .Lock = True  'Sucursal
        .Col = 5: .Lock = True  'Trabajador
        .Col = 6: .Lock = True  'Secuencia
        .Col = 39: .Lock = True  'EPS, AFP o CCF
        If MeSistema = Pension Then
            .Col = 49: .Lock = True
        End If
        
        'Pero si el período está cerrado, nada es editable:
        If cboPeriodo.ItemData(cboPeriodo.ListIndex) = 2 Then
            .Row = -1: .Col = -1: .Lock = True
            clsMsgbox.Mensaje "Este período ya fue cerrado para autoliquidación, la información mostrada es de solo lectura", mAceptar, minforma, GsTitMsg
            abToolbar.Bands(0).Tools(4).Enabled = False
        Else
            abToolbar.Bands(0).Tools(4).Enabled = True
        End If
        
        'Nivel de Seguridad de Solo Consulta
        If Gven(Val(Me.Tag)).iNivSeguridad = 1 Then
            .Row = -1: .Col = -1: .Lock = True
            abToolbar.Bands(0).Tools(4).Enabled = False
        End If
        
        'Inmovilizar paneles
        .ColsFrozen = 2
        
        'Poner las filas pares de otro color para facilitar revisión del usuario
        For i = 2 To .MaxRows Step 2
            .Row = i: .Col = -1: .BackColor = RGB(0, 236, 236)
        Next i
        
        'Columnas Ocultas
        .Col = 1: .ColHidden = True
        .Col = 2: .ColHidden = True
        .Col = 3: .ColHidden = True
        .Col = 14: .ColHidden = True
        .Col = 23: .ColHidden = True
        .Col = 26: .ColHidden = True
        .Col = 28: .ColHidden = True
        If MeSistema = Salud Or MeSistema = Pension Then
            .Col = 40: .ColHidden = True
            .Col = 41: .ColHidden = True
            .Col = 43: .ColHidden = True
            .Col = 44: .ColHidden = True
        End If
        If MeSistema = Parafiscales Then
            .Col = 40: .ColHidden = True
            .Col = 41: .ColHidden = True
        End If
        
        'Configuración de tipos de celdas y sus características
        .Row = -1
        'Tipo de Documento
        .Col = 11: .TypeEditCharCase = 2: .TypeEditLen = 2: .TypeEditCharSet = 1
        .Col = 20: .TypeEditCharCase = 2: .TypeEditLen = 2: .TypeEditCharSet = 1
        'Número de Documento
        .Col = 12: .TypeEditCharSet = 3: .TypeEditLen = 16
        .Col = 21: .TypeEditCharSet = 3: .TypeEditLen = 16
        'Tipo de Pensión
        .Col = 13: .TypeIntegerMax = 15: .TypeIntegerMin = 1
        .Col = 22: .TypeIntegerMax = 4: .TypeIntegerMin = 1
        'Apellidos y Nombres
        .Col = 7: .TypeEditCharSet = 1: .TypeEditLen = 20
        .Col = 8: .TypeEditCharSet = 1: .TypeEditLen = 30
        .Col = 9: .TypeEditCharSet = 1: .TypeEditLen = 20
        .Col = 10: .TypeEditCharSet = 1: .TypeEditLen = 30
        .Col = 16: .TypeEditCharSet = 1: .TypeEditLen = 20
        .Col = 17: .TypeEditCharSet = 1: .TypeEditLen = 30
        .Col = 18: .TypeEditCharSet = 1: .TypeEditLen = 20
        .Col = 19: .TypeEditCharSet = 1: .TypeEditLen = 30
        'Campos char(1) Compartida, Residente en el exterior y Situa pensión en el exterior
        .Col = 15: .TypeEditLen = 1: .TypeEditCharCase = 2: .TypeEditCharSet = 1
        .Col = 24: .TypeEditLen = 1: .TypeEditCharCase = 2: .TypeEditCharSet = 1
        .Col = 29: .TypeEditLen = 1: .TypeEditCharCase = 2: .TypeEditCharSet = 1
        'Departamento
        .Col = 25: .TypeEditLen = 2: .TypeEditCharSet = 3
        'Municipio
        .Col = 27: .TypeEditLen = 3: .TypeEditCharSet = 3
        'Columnas de Novedades
        For i = 30 To 37
            .Col = i: .TypeEditLen = 1: .TypeEditCharCase = 2: .TypeEditCharSet = 1
        Next i
        'Mesada Pensional
        .Col = 38: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True
        If MeSistema = Salud Then
            'Nueva EPS
            .Col = 42: .TypeEditLen = 6: .TypeEditCharCase = 2
            'Días Cotizados
            .Col = 45: .CellType = 3: .TypeIntegerMin = 1: .TypeIntegerMax = 30
            'Tarifa
            .Col = 46: .CellType = 2: .TypeFloatDecimalPlaces = 3: .TypeFloatMax = 1: .TypeFloatMin = 0
            'Aportes
            .Col = 47: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
            .Col = 48: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
        End If
        If MeSistema = Pension Then
            'Nueva AFP
            .Col = 42: .TypeEditLen = 6: .TypeEditCharCase = 2
            'Días Cotizados
            .Col = 45: .CellType = 3: .TypeIntegerMin = 1: .TypeIntegerMax = 30
            .Col = 51: .CellType = 3: .TypeIntegerMin = 1: .TypeIntegerMax = 30
            'Tarifas
            .Col = 46: .CellType = 2: .TypeFloatDecimalPlaces = 3: .TypeFloatMax = 1: .TypeFloatMin = 0
            .Col = 54: .CellType = 2: .TypeFloatDecimalPlaces = 3: .TypeFloatMax = 1: .TypeFloatMin = 0
            'Aportes
            .Col = 47: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
            .Col = 48: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
            .Col = 49: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
            .Col = 50: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
            .Col = 52: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
            .Col = 53: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
        End If
        If MeSistema = Parafiscales Then
            'Días Cotizados
            .Col = 42: .CellType = 3: .TypeIntegerMin = 1: .TypeIntegerMax = 30
            'Tarifa
            .Col = 43: .CellType = 2: .TypeFloatDecimalPlaces = 2: .TypeFloatMax = 1: .TypeFloatMin = 0
            'Aportes
            .Col = 44: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatSeparator = True: .TypeFloatMax = 999999999: .TypeFloatMin = 0
        End If
                
        .ScrollBars = ScrollBarsBoth
    End With
End Sub

Private Sub ValidarDato(Index As Integer)
    Dim sAgr As String
    MbDatos_OK(Index) = True
    
    If Trim(txtDatos(Index)) = "" Then Exit Sub
    
    Select Case Index
        Case 1: sAgr = MsAgr(1)
        Case 2: sAgr = MsAgr(2)
        Case 3: sAgr = MsAgr(3)
    End Select
    
    MAdo.Sql = "SELECT RTRIM(a.descripcion)" & _
    " FROM datos_agr_trab a" & _
    " WHERE agrupacion = '" & sAgr & "'" & _
    " AND dato = '" & txtDatos(Index) & "'" & _
    " AND NOT EXISTS" & _
    " (SELECT 1 FROM rel_usu_agr_trab x" & _
    " WHERE a.agrupacion = x.agrupacion AND a.dato = x.dato" & _
    "   AND x.usuario = '" & GsUid & "')"
    If MAdo.SendSQL Then
        If MAdo.EOF Then
            MbDatos_OK(Index) = False
            txtDatosDes(Index) = ""
        Else
            txtDatosDes(Index) = MAdo.GetField(1)
        End If
    End If
    
End Sub
