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 = "{AB3877A8-B7B2-11CF-9097-444553540000}#1.0#0"; "gtdate32.ocx"
Begin VB.Form FCO2010A 
   Caption         =   "Registro de Autorizaciones"
   ClientHeight    =   4875
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5460
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Autorizaciones_Alta.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   4875
   ScaleWidth      =   5460
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame fraFrame 
      Caption         =   "Descontar de la autoliquidacion de"
      Enabled         =   0   'False
      Height          =   1215
      Left            =   240
      TabIndex        =   16
      Top             =   1200
      Width           =   5055
      Begin VB.TextBox txtSuc 
         Height          =   285
         Left            =   3720
         MaxLength       =   10
         TabIndex        =   5
         Top             =   360
         Width           =   735
      End
      Begin VB.TextBox txtEntidad 
         Height          =   285
         Left            =   1440
         MaxLength       =   10
         TabIndex        =   4
         Top             =   360
         Width           =   975
      End
      Begin VB.TextBox txtAño 
         Height          =   285
         Left            =   3720
         MaxLength       =   4
         TabIndex        =   6
         Top             =   720
         Width           =   550
      End
      Begin VB.TextBox txtMes 
         Height          =   285
         Left            =   4320
         MaxLength       =   2
         TabIndex        =   7
         Top             =   720
         Width           =   375
      End
      Begin VB.Image imgListaSuc 
         Height          =   480
         Left            =   4560
         Picture         =   "Autorizaciones_Alta.frx":030A
         Top             =   360
         Width           =   480
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Sucursal"
         Height          =   210
         Index           =   10
         Left            =   3000
         TabIndex        =   19
         Top             =   360
         Width           =   645
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Administradora"
         Height          =   210
         Index           =   2
         Left            =   240
         TabIndex        =   18
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Periodo"
         Height          =   210
         Index           =   4
         Left            =   3000
         TabIndex        =   17
         Top             =   720
         Width           =   540
      End
      Begin VB.Image imgListaEnt 
         Height          =   480
         Left            =   2520
         Picture         =   "Autorizaciones_Alta.frx":0614
         Top             =   360
         Width           =   480
      End
   End
   Begin FPSpread.vaSpread sprDatos 
      Bindings        =   "Autorizaciones_Alta.frx":091E
      Height          =   1080
      Left            =   600
      TabIndex        =   8
      Top             =   2760
      Width           =   4095
      _Version        =   131077
      _ExtentX        =   7223
      _ExtentY        =   1905
      _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  =   "Autorizaciones_Alta.frx":0934
   End
   Begin VB.TextBox txtValorTotal 
      Height          =   285
      Left            =   4080
      MaxLength       =   10
      TabIndex        =   3
      Top             =   720
      Width           =   1215
   End
   Begin VB.TextBox txtAusentismo 
      Height          =   285
      Left            =   4200
      MaxLength       =   10
      TabIndex        =   9
      Top             =   2400
      Visible         =   0   'False
      Width           =   855
   End
   Begin VB.ComboBox cboTipo 
      Height          =   330
      Left            =   3000
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   240
      Width           =   2295
   End
   Begin VB.TextBox txtNumero 
      Height          =   285
      Left            =   960
      MaxLength       =   10
      TabIndex        =   0
      Top             =   240
      Width           =   1215
   End
   Begin GTMaskDate.GTMaskDate fpFecha 
      Height          =   300
      HelpContextID   =   722
      Left            =   1560
      TabIndex        =   2
      Top             =   705
      Width           =   1320
      _Version        =   65537
      _ExtentX        =   2328
      _ExtentY        =   529
      _StockProps     =   77
      BackColor       =   -2147483643
      BeginProperty NullFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty CalFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty CalCaptionFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty CalDayCaptionFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty ToolTipFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   4800
      Top             =   0
      _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           =   "Autorizaciones_Alta.frx":0A8D
   End
   Begin VB.Image imgListaTra 
      Height          =   480
      Left            =   4800
      Picture         =   "Autorizaciones_Alta.frx":1B5B
      Top             =   2880
      Width           =   480
   End
   Begin VB.Label lblLabels 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Detalle de trabajadores"
      Height          =   210
      Index           =   7
      Left            =   600
      TabIndex        =   15
      Top             =   2520
      Width           =   1665
   End
   Begin VB.Image imgListaAus 
      Height          =   480
      Left            =   5040
      Picture         =   "Autorizaciones_Alta.frx":1E65
      Top             =   2400
      Visible         =   0   'False
      Width           =   480
   End
   Begin VB.Label lblLabels 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Valor Total"
      Height          =   210
      Index           =   6
      Left            =   3240
      TabIndex        =   14
      Top             =   720
      Width           =   780
   End
   Begin VB.Label lblLabels 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Ausentismo"
      Height          =   210
      Index           =   5
      Left            =   3240
      TabIndex        =   13
      Top             =   2400
      Visible         =   0   'False
      Width           =   855
   End
   Begin VB.Label lblLabels 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Fecha de Emisión"
      Height          =   210
      Index           =   3
      Left            =   240
      TabIndex        =   12
      Top             =   720
      Width           =   1260
   End
   Begin VB.Label lblLabels 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Tipo"
      Height          =   210
      Index           =   1
      Left            =   2520
      TabIndex        =   11
      Top             =   240
      Width           =   300
   End
   Begin VB.Label lblLabels 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Numero"
      Height          =   210
      Index           =   0
      Left            =   240
      TabIndex        =   10
      Top             =   240
      Width           =   555
   End
End
Attribute VB_Name = "FCO2010A"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents clsSpread As NSpread
Attribute clsSpread.VB_VarHelpID = -1
Private MAdo As ODBC.ODBCDirecto
Private MiCx As Integer 'Conexión
Private MiX As Integer 'Ancho de la forma
Private MiY As Integer 'Alta de la forma

Private MbHuboCambios As Boolean
Private MbEntiVal As Boolean
Private MsSql As String
Private MsCodAgrEPS As String
Private MnEntidad() As String
Private MsCodAgrSUC As String
Private MbManSUC As Boolean
Private MbSucValida As Boolean
Private msvista_incapacidad As String

Private MiNumDecimales As Integer        ' Número de decimales

Private Sub abToolbar_Click(ByVal Tool As ActiveBarLibraryCtl.Tool)
    Select Case LCase(Tool.Name)
        Case "tlguarda": GuardarCambios
        Case "tlsalida"
            If MbHuboCambios Then
                If clsMsgbox.Mensaje("¿Desea guardar los cambios?", mSiNoCancelar, mConfirma, GsTitMsg) = vbYes Then GuardarCambios
            End If
            Unload Me
    End Select
End Sub

Private Sub cboTipo_Click()
    If cboTipo.ListIndex = -1 Then
        fraFrame.Enabled = False
    Else
        fraFrame.Enabled = True
        If MnEntidad(cboTipo.ListIndex) = 1 Then
            txtEntidad = "ARP"
            MbEntiVal = True
            txtEntidad.Enabled = False
            imgListaEnt.Enabled = False
        Else
            txtEntidad = ""
            txtEntidad.Enabled = True
            imgListaEnt.Enabled = True
        End If
        MbHuboCambios = True
    End If
End Sub

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

Private Sub Form_Activate()
    WindowState = 0
    Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
    On Error Resume Next
    If Tag = "" Then Tag = "0": txtNumero.SetFocus
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF3: Unload Me
        Case vbKeyF11: GuardarCambios
    End Select
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then
        Select Case LCase(ActiveControl.Name)
            Case "txtentidad": imgListaEnt_Click
            Case "txtsuc": imgListaSuc_Click
            Case "sprdatos": imgListaTra_Click
        End Select
    End If
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
    Me.Icon = LoadPicture(sIconoForma)
        
    Set clsSpread = New NSpread
    GAdam.ObtieneColores
    
    If Not MDIChild Then
        WindowState = 0
        Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
        Screen.MousePointer = vbDefault
    End If
    
    'Tamaño de la forma
    If Me.WindowState = 0 Then
        MiX = 5580
        MiY = 5280
        Me.Width = MiX
        Me.Height = MiY
    End If
        
    'Decimales según panel de control
    MiNumDecimales = iNumeroDecimalesImporte
    
    Tag = ""
    Caption = GsDsn & " / " & GsCveCia & " - Registro de Autorizaciones"
    AsignaIconos abToolbar, 3, LGUARDA, LSALIDA
    
    RecuperarTiposLicencia
    MbHuboCambios = False
    MbEntiVal = False
    
    GAdam.ConfiguraFecha fpFecha, True
    fpFecha.Text = Date
    
    txtAño.Text = Year(Date)
    txtMes.Text = Month(Date)
    'txtMes = IIf(Month(Date) < 10, "0" & Month(Date), Month(Date))
    
    fpFecha.Text = Format(Date, "dd/mm/yyyy")
    
    
    MsSql = "SELECT trabajador, valor FROM fco_autorizaciones_det" & _
    " WHERE compania='" & GsCveCia & "' AND autorizacion=0"
    RenuevaDatos
    RecuperarCodsAgr
    
    sprDatos.ShadowColor = GLSPREADINACTIVO
    
    MbSucValida = False
    MbManSUC = False
    
    If GbEdicion Then
     If LTrim(RTrim(msvista_incapacidad)) = "vw_fco_ausentismos_mayores" Then
        'Recuperar datos porque es cambio
        MAdo.Sql = "SELECT numero, tipo_incapacidad, fecha, valor_total, sucursal, cod_entidad, periodo, ausentismo" & _
        " FROM vw_fco_ausentismos_mayores " & _
        " WHERE compania='" & GsCveCia & "' AND autorizacion=" & GsCodDato
     Else
           'Recuperar datos porque es cambio
        MAdo.Sql = "SELECT numero, tipo_incapacidad, fecha, valor_total, sucursal, cod_entidad, periodo, ausentismo" & _
        " FROM vw_fco_ausentismos_menores " & _
        " WHERE compania='" & GsCveCia & "' AND autorizacion=" & GsCodDato
     End If
        MAdo.SendSQL
        If Not MAdo.EOF Then
            txtNumero = MAdo.GetField(1) 'numero
            cboTipo.ListIndex = RecuperarItem("" & MAdo.GetField(2), cboTipo) 'tipo_incapacidad
            'fpFecha = MAdo.GetField(3)  'fecha
            txtValorTotal = MAdo.GetField(4) 'valor_total
            txtSUC = MAdo.GetField(5) 'sucursal
            txtEntidad = MAdo.GetField(6) 'cod_entidad
            'txtAño = Left(MAdo.GetField(7), 4) 'periodo
            'txtMes = Right(Trim(MAdo.GetField(7)), 2) 'periodo
            txtAusentismo = MAdo.GetField(8) 'ausentismo
        End If

        MsSql = "SELECT trabajador, valor FROM fco_autorizaciones_det" & _
        " WHERE compania = '" & GsCveCia & "' AND autorizacion=" & GsCodDato
        RenuevaDatos
        MbHuboCambios = False
    End If
    Screen.MousePointer = vbDefault
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Set MAdo = Nothing
    Set clsSpread = Nothing
    Gtc(MiCx).ihijas = Gtc(MiCx).ihijas - 1
    
    Set FCO2010A = Nothing

End Sub

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

Private Sub imgListaEnt_Click()
    Screen.MousePointer = vbHourglass
    GsParamOUT(0) = ""
    GsParamOUT(1) = ""
    GsParamIN(0) = "Select codigo, descripcion" & _
    " From vw_fco_administradoras" & _
    " Where compania = '" & GsCveCia & "' AND tipo='EPS'"
    GsParamIN(1) = "codigo"
    GsParamIN(2) = "descripcion"
    GsParamIN(3) = "Codigo"
    GsParamIN(4) = "Descripcion"
    GsParamIN(5) = "Entidades Promotoras de Salud"
    GsParamIN(6) = ""
    frmLista.Show 1
    txtEntidad = GsParamOUT(0)
    If Trim(txtEntidad) <> "" Then
        MbEntiVal = True
        SendEnter
    End If
    Screen.MousePointer = vbDefault
End Sub

Private Sub imgListaSuc_Click()
    Screen.MousePointer = vbHourglass
    GsParamIN(0) = "SELECT sucursal, descripcion" & _
    " FROM vw_fco_sucursales_cia" & _
    " WHERE compania='" & GsCveCia & "'"
    GsParamIN(1) = "sucursal"
    GsParamIN(2) = "descripcion"
    GsParamIN(3) = "Codigo"
    GsParamIN(4) = "Nombre"
    GsParamIN(5) = "Sucursal"
    GsParamIN(6) = ""
    frmLista.Show 1
    txtSUC = GsParamOUT(0)
    If Trim(txtSUC) <> "" Then
        MbHuboCambios = True
        MbSucValida = True
        SendEnter
    End If
End Sub

Private Sub imgListaTra_Click()
    Dim nFila As Long
    Screen.MousePointer = vbHourglass
    nFila = sprDatos.ActiveRow
    GsParamOUT(0) = ""
    GsParamOUT(1) = ""
    GsParamIN(0) = "Select A.trabajador, REPLACE(A.nombre,'/',' ')" & _
    " From trabajadores A, trabajadores_grales B" & _
    " Where A.trabajador = B.trabajador And" & _
    " B.compania = '" & GsCveCia & "'" ' And" & _
    '" B.sit_trabajador=1"
    GsParamIN(1) = "A.trabajador"
    GsParamIN(2) = "A.nombre"
    GsParamIN(3) = "Codigo"
    GsParamIN(4) = "Nombre"
    GsParamIN(5) = "Trabajadores"
    GsParamIN(6) = ""
    frmLista.Show 1
    If Trim(GsParamOUT(0)) <> "" Then
        With sprDatos
            .Row = nFila
            .Col = 1
            .Text = GsParamOUT(0)
        End With
        CrearFilaNueva
        DoEvents
        sprDatos.SetFocus
        With sprDatos
            .Row = nFila
            .Col = 2
            .Action = 0
        End With
    End If
    Screen.MousePointer = vbDefault
End Sub

Private Sub sprDatos_GotFocus()
    sprDatos.ShadowColor = GLSPREADACTIVO
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)
    If Col = 2 Then txtValorTotal = CalcularTotal
End Sub

Private Sub sprDatos_LostFocus()
    sprDatos.ShadowColor = GLSPREADINACTIVO
End Sub

Private Sub txtAño_GotFocus()
    txtAño.SelStart = 0
    txtAño.SelLength = Len(txtAño)
End Sub

Private Sub txtAño_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        SendEnter
    Else
        KeyAscii = iValidarDato(KeyAscii, "0123456789", True, True)
    End If
End Sub

Private Sub txtAño_LostFocus()
    If Val(txtAño) < 2000 Then txtAño = Year(Date)
End Sub

Private Sub txtEntidad_Change()
    MbEntiVal = False
End Sub

Private Sub txtEntidad_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        SendEnter
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii)))
    End If
End Sub

Private Sub txtMes_GotFocus()
    txtMes.SelStart = 0
    txtMes.SelLength = Len(txtMes)
End Sub

Private Sub txtMes_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        SendEnter
    Else
        KeyAscii = iValidarDato(KeyAscii, "0123456789", True, True)
    End If
End Sub

Private Sub txtMes_LostFocus()
    If Val(txtMes) < 10 Then txtMes = "0" & Val(txtMes)
End Sub

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

Private Sub txtSuc_Change()
    MbSucValida = False
End Sub

Private Sub txtSUC_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        If Not (MbSucValida) Then ValidarSucursal
        If MbSucValida Or Trim(txtSUC) = "" Then SendEnter
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii)))
    End If
End Sub

Private Sub txtValorTotal_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        SendEnter
    Else
        KeyAscii = iValidarDato(KeyAscii, "0123456789", True, True)
    End If
End Sub

Private Sub AvisarError(Origen As Control, Msg As String)
    clsMsgbox.Mensaje Msg, mAceptar, mAdvierte, GsTitMsg
    Origen.SetFocus
End Sub

Private Function CalcularTotal() As Double
    Dim Aux As Variant
    Dim nSuma As Double
    Dim i As Integer
    
    nSuma = 0
    For i = 1 To sprDatos.VirtualMaxRows
        sprDatos.GetText 2, i, Aux
        nSuma = nSuma + Val(Aux)
    Next i
    CalcularTotal = nSuma
End Function

Private Sub ConfiguraSpread()
    sprDatos.VisibleCols = 2
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
    
        .Row = 0:
        .Col = 1: .Text = "Trabajador"
        .Col = 2: .Text = "Valor"
                
        .Visible = True
        
        ConfiguraSpreadJCL sprDatos
        
    End With
End Sub

Private Sub CrearFilaNueva()
    With sprDatos
        .VirtualMaxRows = .VirtualMaxRows + 1
        .Row = .VirtualMaxRows
        .Action = 7  'SS_ACTION_INSERT_ROW
    End With
End Sub

Private Sub GuardarCambios()
    On Error GoTo TratarError
    Dim sSql As String
    
    'Validacion de datos
    If Val(txtNumero) = 0 Then AvisarError txtNumero, "Digite el Numero de Autorizacion": Exit Sub
    If cboTipo.ListIndex = -1 Then AvisarError cboTipo, "Elija el Tipo": Exit Sub
    MbManSUC = (txtSUC <> "")
    If MbManSUC Then
        If Trim(txtSUC) = "" Then MbSucValida = True
        If Not MbSucValida Then ValidarSucursal
        If Not MbSucValida Then txtSUC.SetFocus: Exit Sub
    Else
        txtSUC = ""
    End If
    If Trim(txtEntidad) = "" Then AvisarError txtEntidad, "EPS no valida": Exit Sub
    If Trim(txtEntidad) = "ARP" Then MbEntiVal = True
    If Not MbEntiVal Then ValidarEntidad
    If Not MbEntiVal Then AvisarError txtEntidad, "Entidad digitada no existe": Exit Sub
    If Len(txtAño) <> 4 Then AvisarError txtAño, "Año no valido": Exit Sub
    txtMes = Right("00" & Trim(txtMes), 2)
    If Len(txtMes) <> 2 Or Val(txtMes) < 1 Or Val(txtMes) > 12 Then AvisarError txtMes, "Mes no valido": Exit Sub
    'If sprDatos.VirtualMaxRows = 1 Then AvisarError sprDatos, "Seleccione el trabajador": Exit Sub
    txtValorTotal.Tag = txtValorTotal
    txtValorTotal = CalcularTotal
    If Val(txtValorTotal) = 0 Then txtValorTotal = Val(txtValorTotal.Tag)
    
    If GbEdicion Then
        MAdo.Sql = "sp_fco_baja_autorizaciones_det '" & GsCveCia & "'," & GsCodDato & ",'0'"
        MAdo.ExecSQL
        
        MAdo.Sql = "sp_fco_baja_autorizaciones '" & GsCveCia & "'," & GsCodDato
        MAdo.ExecSQL
        
    End If
    Screen.MousePointer = vbHourglass
    ' Parte 1: Encabezado de la autorizacion
    MAdo.Sql = "sp_fco_alta_autorizaciones '" & GsCveCia & "'," & _
    "'" & txtSUC & "','" & txtNumero & "'," & _
    "'" & cboTipo.ItemData(cboTipo.ListIndex) & "','" & MnEntidad(cboTipo.ListIndex) & "'," & _
    "'" & txtEntidad.Text & "','" & Format(fpFecha.Text, "yyyymmdd") & "'," & _
    "'" & txtAño & txtMes & "'," & Val(txtAusentismo) & ",'1'," & Val(txtValorTotal)
    
    MAdo.ExecSQL
    
    If sprDatos.VirtualMaxRows = 1 Then GoTo Salir
    'Parte 2: Detalle de la autorizacion
    Dim i As Integer
    Dim AuxTra As Variant
    Dim AuxVal As Variant
    Dim nAutor As Long
    
    MAdo.Sql = "SELECT Max(autorizacion) FROM fco_autorizaciones" & _
    " WHERE compania='" & GsCveCia & "' And numero='" & txtNumero & "'"
    MAdo.SendSQL
    If Not MAdo.EOF Then
        nAutor = Val(MAdo.GetField(1))
        
        For i = 1 To sprDatos.VirtualMaxRows - 1
            sprDatos.GetText 1, i, AuxTra
            sprDatos.GetText 2, i, AuxVal
            
            If Trim(AuxTra) <> "" Then
                MAdo.Sql = "sp_fco_alta_autorizaciones_det '" & GsCveCia & "'," & _
                nAutor & ",'" & AuxTra & "'," & AuxVal
            
                MAdo.ExecSQL
            End If
        Next i
    End If
Salir:
    Screen.MousePointer = vbDefault
    MbHuboCambios = False
    Unload Me
    Exit Sub
TratarError:
    Screen.MousePointer = vbDefault
    If Err > 0 Then
        clsMsgbox.Mensaje Err & " " & Err.Description, mAceptar, mAdvierte, GsTitMsg
    End If
End Sub

Private Sub RecuperarCodsAgr()
    Dim sSql As String
        
    MAdo.Sql = " Select dato" & _
    " From vw_fdt_parametros" & _
    " Where  compania =" & "'" & GsCveCia & "'" & _
    " And secuencia=21"
    MAdo.SendSQL
    
    If MAdo.EOF Then
        clsMsgbox.Mensaje "No existe la agrupacion para EPS en esta compañia", mAceptar, mAdvierte, GsTitMsg
    Else
        MsCodAgrEPS = MAdo.GetField(1)
    End If

    MAdo.Sql = " Select dato" & _
    " From vw_fdt_parametros" & _
    " Where  compania =" & "'" & GsCveCia & "'" & _
    " And secuencia=23"
    MAdo.SendSQL

    If MAdo.EOF Then
        clsMsgbox.Mensaje "No existe la agrupacion para Sucursal en esta compañia", mAceptar, mAdvierte, GsTitMsg
    Else
        MsCodAgrSUC = MAdo.GetField(1)
    End If

End Sub

Private Sub RecuperarTiposLicencia()
    cboTipo.Clear
    MAdo.Sql = " SELECT item, descripcion, valor" & _
    " FROM criterios_valores_col" & _
    " WHERE campo='tipo_licencia'" & _
    " ORDER BY item"
    MAdo.SendSQL
    Do Until MAdo.EOF
        cboTipo.AddItem MAdo.GetField(2) 'descripcion
        cboTipo.ItemData(cboTipo.NewIndex) = MAdo.GetField(1) 'item
        ReDim Preserve MnEntidad(cboTipo.NewIndex)
        MnEntidad(cboTipo.NewIndex) = MAdo.GetField(3) 'valor
        MAdo.Mnext
    Loop

End Sub

Private Sub RenuevaDatos()
    ConfiguraSpread
    
    MAdo.Sql = MsSql
    If Not MAdo.SendSQL Then Exit Sub
    clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
    
    With sprDatos
        .ColWidth(1) = 10
        .ColWidth(2) = 15
        .Col = 1: .Row = -1: .Lock = True
        
        .Col = 2: .Row = -1:  .CellType = 2: .TypeFloatSeparator = True:
                  .TypeFloatDecimalPlaces = MiNumDecimales: .TypeFloatMax = "99999999999999999": .TypeFloatMin = "0.00"
        
    End With
    CrearFilaNueva
End Sub

Private Sub ValidarEntidad()
    If Trim(txtEntidad) = "" Then Exit Sub
    Screen.MousePointer = vbHourglass
    MAdo.Sql = _
    " SELECT dato FROM datos_agr_trab" & _
    " WHERE agrupacion = '" & MsCodAgrEPS & "'" & _
    " AND ltrim(rtrim(dato)) = '" & Trim(txtEntidad) & "'"
    MAdo.SendSQL
    If Not MAdo.EOF Then
        txtEntidad = MAdo.GetField(1)
        MbEntiVal = True
    End If

    Screen.MousePointer = vbDefault
End Sub

Private Sub ValidarSucursal()
    If Trim(txtSUC) = "" Then Exit Sub
    MAdo.Sql = _
    "select dato, descripcion from datos_agr_trab where agrupacion ='" & MsCodAgrSUC & "'" & _
    " And ltrim(dato)='" & LTrim(txtSUC) & "'"
    MAdo.SendSQL
    If MAdo.EOF Then
        Screen.MousePointer = vbDefault
        clsMsgbox.Mensaje "No existe la sucursal", mAceptar, mAdvierte, GsTitMsg
        Exit Sub
    Else
        txtSUC = MAdo.GetField(1)
        MbSucValida = True
    End If

    MbHuboCambios = True
End Sub

Private Function RecuperarItem(Valor As Integer, BuscarEn As ComboBox) As Integer
    Dim i As Integer
    Dim bEncontrado As Boolean
    i = -1: bEncontrado = False
    Do Until i > BuscarEn.ListCount - 1 Or bEncontrado
        i = i + 1
        If BuscarEn.ItemData(i) = Valor Then bEncontrado = True
    Loop
    If bEncontrado Then
        RecuperarItem = i
    Else
        RecuperarItem = -1
    End If
End Function

Public Sub cargar(msvista)

msvista_incapacidad = msvista
 
End Sub

