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"
Begin VB.Form FCO2000 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Ausentismos"
   ClientHeight    =   6300
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11925
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Administracion de Ausentismos.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   6300
   ScaleWidth      =   11925
   Begin FPSpread.vaSpread sprDatos 
      Bindings        =   "Administracion de Ausentismos.frx":030A
      Height          =   5235
      Left            =   120
      TabIndex        =   5
      Top             =   480
      Width           =   11655
      _Version        =   131077
      _ExtentX        =   20558
      _ExtentY        =   9234
      _StockProps     =   64
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      MaxCols         =   1
      MaxRows         =   1
      SpreadDesigner  =   "Administracion de Ausentismos.frx":0320
   End
   Begin VB.ComboBox cboConcepto 
      Height          =   330
      Left            =   4025
      TabIndex        =   3
      Top             =   120
      Width           =   840
   End
   Begin VB.TextBox txtBuscarIdAu 
      Height          =   315
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   495
   End
   Begin VB.TextBox txtBuscarDesc 
      Height          =   315
      Left            =   4890
      TabIndex        =   4
      Top             =   120
      Width           =   2400
   End
   Begin VB.TextBox txtBuscarNomb 
      Height          =   315
      Left            =   1600
      TabIndex        =   2
      Top             =   120
      Width           =   2400
   End
   Begin VB.TextBox txtBuscarTrab 
      Height          =   315
      Left            =   630
      TabIndex        =   1
      Top             =   120
      Width           =   960
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   240
      Top             =   5760
      _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           =   "Administracion de Ausentismos.frx":0457
   End
End
Attribute VB_Name = "FCO2000"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private MBitacora 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 MsSql As String
Private MsSqlIni As String
Private MsOrden As String
Private MbOrdenAsc As Boolean
Private MsAntOrden As String
Private MbRenovar  As Boolean
Private MsWhereAdi As String
Private MiKey As Integer
Private MsConceptos() As String

Private Sub abToolbar_Click(ByVal Tool As ActiveBarLibraryCtl.Tool)
    Select Case LCase(Tool.Name)
        Case "tlalta": Altas
        Case "tlbaja": Bajas
        Case "tltrabaja": TrabajarCon
        Case "tlordena": OrdenarDatos
        Case "tlrenueva": AplicaFiltros
        Case "tlguarda": GuardarCambios
        Case "tlsalida": Unload Me
    End Select
End Sub

Private Sub cboConcepto_Click()
  If cboConcepto.ListIndex > -1 Or Len(Trim(cboConcepto)) > 0 Then
    AplicaFiltros
  End If
End Sub

Private Sub cboConcepto_KeyPress(KeyAscii As Integer)
  If KeyAscii <> vbKeyReturn And KeyAscii <> 10 Then Exit Sub
  If cboConcepto.ListIndex > -1 Or Len(Trim(cboConcepto)) > 0 Then
    MiKey = KeyAscii
    AplicaFiltros
  End If
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF3: Unload Me
        Case vbKeyF5: RenuevaDatos
        Case vbKeyF6: Altas
        Case vbKeyF7: Bajas
        Case vbKeyF11: GuardarCambios
        Case vbKeyF12: abToolbar.Bands(1).TrackPopup -1, -1
    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
    Me.Icon = LoadPicture(sIconoForma)
    
    '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
    
    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
        Me.Width = 12015
        Me.Height = 6780
    End If
        
    Caption = GsDsn & " / " & GsCveCia & " - Ausentismos"
    
    AsignaIconos abToolbar, 3, LALTA, LBAJA, LTRABAJA, LORDENA, LRENUEVA, LGUARDA, LSALIDA
    ToolInicioGrupo abToolbar, 3, True, 2, 5
            
    CreaBitacora
    MsSqlIni = _
    " SELECT au.id_ausentismo, au.trabajador, REPLACE(t.nombre,'/',' ')," & _
    " au.concepto, c.descripcion, au.fecha_inicio, au.fecha_fin, " & _
    " au.fecha_ini_real, au.fecha_fin_real, au.nro_incapacidad, au.dias, au.horas" & _
    " FROM fco_ausentismos au, trabajadores t, conceptos c, trabajadores_grales tg, rel_usu_clase_nom u" & _
    " WHERE au.trabajador = t.trabajador " & _
    "   AND au.concepto = c.concepto " & _
    "   AND t.trabajador = tg.trabajador " & _
    "   AND au.compania = tg.compania " & _
    "   AND au.trabajador = tg.trabajador " & _
    "   AND tg.clase_nomina = u.clase_nomina " & _
    "   AND u.usuario = '" & GsUid & "' " & _
    "   AND au.compania = '" & Trim(GsCveCia) & "'"
    MsSql = MsSqlIni
    MsWhereAdi = " AND 1=2"
    MsOrden = " ORDER BY au.id_ausentismo DESC"
    RenuevaDatos
    LlenarCombos
End Sub

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

Private Sub Form_Resize()
    On Error Resume Next
    With sprDatos
        .Height = Height - 1545
        .Width = Width - 360
    End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If GbExterno Then End
End Sub

Private Sub sprDatos_DataFill(ByVal Col As Long, ByVal Row As Long, ByVal DataType As Integer, ByVal fGetData As Integer, Cancel As Integer)
    Dim Aux As Variant
    Select Case Col
        Case 3
            sprDatos.GetDataFillData Aux, 1
            sprDatos.SetText Col, Row, Replace(Aux, "/", " ")
            Cancel = True
    End Select
End Sub

Private Sub sprDatos_DblClick(ByVal Col As Long, ByVal Row As Long)
    TrabajarCon
End Sub

Private Sub sprDatos_KeyDown(KeyCode As Integer, Shift As Integer)
    Form_KeyDown KeyCode, Shift
End Sub

Private Sub txtBuscarDesc_KeyPress(KeyAscii As Integer)
    If KeyAscii <> vbKeyReturn And KeyAscii <> 10 Then Exit Sub
    'If Len(Trim(Me.txtBuscarDesc)) > 0 Then
      MiKey = KeyAscii
      AplicaFiltros
    'End If
End Sub

Private Sub txtBuscarIdAu_KeyPress(KeyAscii As Integer)
    If KeyAscii <> vbKeyReturn And KeyAscii <> 10 Then Exit Sub
    'If Len(Trim(Me.txtBuscarIdAu)) > 0 Then
      MiKey = KeyAscii
      AplicaFiltros
    'End If
End Sub

Private Sub txtBuscarNomb_KeyPress(KeyAscii As Integer)
    If KeyAscii <> vbKeyReturn And KeyAscii <> 10 Then Exit Sub
    'If Len(Trim(Me.txtBuscarNomb)) > 0 Then
      MiKey = KeyAscii
      AplicaFiltros
    'End If
End Sub

Private Sub txtBuscarTrab_KeyPress(KeyAscii As Integer)
    If KeyAscii <> vbKeyReturn And KeyAscii <> 10 Then Exit Sub
    'If Len(Trim(Me.txtBuscarTrab)) > 0 Then
      MiKey = KeyAscii
      AplicaFiltros
    'End If
End Sub

Private Sub Altas()
    Screen.MousePointer = vbHourglass
    'Tag = "A"
    GsConcepto = ""
    GsTrabajador = ""
    GsLlave = "A"
    FCO2000A.Caption = GsDsn & " / " & GsCveCia & " - Alta de Ausentismo"
    FCO2000A.Show 1
    
    If Len(Trim(GsConcepto)) > 0 Then
      MiKey = vbKeyReturn
      LlenarCombos
      Me.cboConcepto.Text = GsConcepto
      Me.txtBuscarTrab.Text = GsTrabajador
      AplicaFiltros
    End If
End Sub

Private Sub Bajas()
    If sprDatos.VirtualMaxRows <= 0 Then Exit Sub
    MBitacora.mBorra
End Sub

Private Sub ConfiguraSpread()
    sprDatos.VisibleCols = 7
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
        .Row = 0:
        .Col = 1: .Text = "Id."
        .Col = 2: .Text = "Trabajador"
        .Col = 3: .Text = "Nombre"
        .Col = 4: .Text = "Concepto"
        .Col = 5: .Text = "Descripcion"
        .Col = 6: .Text = "Inicia"
        .Col = 7: .Text = "Termina"
        .Col = 8: .Text = "Ini.Real"
        .Col = 9: .Text = "Fin.Real"
        .Col = 10: .Text = "Nro.Incap."
        .Col = 11: .Text = "Días"
        .Col = 12: .Text = "Horas"
        .Col = 3
        .DataFillEvent = True
        ConfiguraSpreadJCL sprDatos
        .Visible = False
    End With
End Sub

Private Sub CreaBitacora()
   MBitacora.mCreaBitacora sprDatos, MAdo.lhEnv, MAdo.lhDbc, MAdo.lhstmt, MAdo
   MBitacora.p_ConfirmaBaja = True
   MBitacora.mDefineLlave 1
   MBitacora.mTablaSPInfo 1, "sp_fco_baja_ausentismos", "'" & GsCveCia & "'", 1
   MBitacora.mColNoNulls 1
End Sub

Private Sub GuardarCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    MbRenovar = MBitacora.mActualizaBD
    Screen.MousePointer = vbDefault
            
End Sub

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

Private Sub RenuevaDatos()
    On Error GoTo MostrarError
    Screen.MousePointer = vbHourglass
    ConfiguraSpread
    
    MAdo.Sql = MsSql & MsWhereAdi & MsOrden
    If Not MAdo.SendSQL Then Exit Sub
    clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
    
    With sprDatos
        .ColWidth(1) = 4
        .ColWidth(2) = 8
        .ColWidth(3) = 20
        .ColWidth(4) = 7
        .ColWidth(5) = 20
        .ColWidth(6) = 8
        .ColWidth(7) = 8
        .ColWidth(8) = 8
        .ColWidth(9) = 8
        .ColWidth(10) = 8
        .ColWidth(11) = 4
        .ColWidth(12) = 5
        .Col = -1: .Row = -1: .Lock = True
        .Visible = True
    End With
    
    Screen.MousePointer = vbDefault
    Exit Sub
MostrarError:
    Screen.MousePointer = vbDefault
    Clipboard.Clear
    Clipboard.SetText MsSql & MsOrden
    clsMsgbox.Mensaje Err.Description, mAceptar, mAdvierte, GsTitMsg
End Sub

Private Sub TrabajarCon()
    Dim Aux As Variant
    
    If sprDatos.ActiveRow < 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    sprDatos.GetText 1, sprDatos.ActiveRow, Aux
    'Tag = CStr(Aux)
    GsLlave = CStr(Aux)
    FCO2000A.Caption = GsDsn & " / " & GsCveCia & " - Cambio de Ausentismos"
    FCO2000A.Show 1
    If GbRen Then RenuevaDatos
End Sub

Private Sub AplicaFiltros()
    MsSql = MsSqlIni
    MsWhereAdi = ""
                    
    If Trim(txtBuscarIdAu) <> "" Then
        Select Case MiKey
            Case vbKeyReturn
                MsWhereAdi = " AND au.id_ausentismo Like '%" & txtBuscarIdAu & "%'"
            Case 10
                MsWhereAdi = " AND au.id_ausentismo Like '" & txtBuscarIdAu & "%'"
        End Select
    End If
    
    If Trim(txtBuscarTrab) <> "" Then
        Select Case MiKey
            Case vbKeyReturn
                MsWhereAdi = MsWhereAdi & " AND au.trabajador Like '%" & txtBuscarTrab & "%'"
            Case 10
                MsWhereAdi = MsWhereAdi & " AND au.trabajador Like '" & txtBuscarTrab & "%'"
        End Select
    End If
                           
    If Trim(txtBuscarNomb) <> "" Then
        Select Case MiKey
            Case vbKeyReturn
                MsWhereAdi = MsWhereAdi & " AND t.nombre Like '%" & Replace(txtBuscarNomb, "/", " ") & "%'"
            Case 10
                MsWhereAdi = MsWhereAdi & " AND t.nombre Like '" & Replace(txtBuscarNomb, "/", " ") & "%'"
        End Select
    End If
                               
    If Trim(cboConcepto.Text) <> "" Then
        MsWhereAdi = MsWhereAdi & " AND au.concepto = " & cboConcepto.Text
    End If
                                                                                 
    If Trim(txtBuscarDesc) <> "" Then
        Select Case MiKey
            Case vbKeyReturn
                MsWhereAdi = MsWhereAdi & " AND c.descripcion Like '%" & txtBuscarDesc & "%'"
            Case 10
                MsWhereAdi = MsWhereAdi & " AND c.descripcion Like '" & txtBuscarDesc & "%'"
        End Select
    End If
                                                                                                                                                                  
    RenuevaDatos
End Sub

Private Sub LlenarCombos()
    cboConcepto.Clear
    
    MAdo.Sql = _
    "SELECT DISTINCT a.concepto, " & _
    "(SELECT descripcion FROM conceptos_ns x WHERE x.compania = a.compania AND x.concepto = a.concepto)" & _
    "FROM fco_ausentismos a WHERE compania = '" & GsCveCia & "' ORDER BY 1"
    If Not MAdo.SendSQL Then Exit Sub
    Do Until MAdo.EOF
        cboConcepto.AddItem MAdo.GetField(1)
        ReDim Preserve MsConceptos(cboConcepto.NewIndex)
        MsConceptos(cboConcepto.NewIndex) = MAdo.GetField(2)
        MAdo.Mnext
    Loop
End Sub


