VERSION 5.00
Object = "{B02F3647-766B-11CE-AF28-C3A2FBE76A13}#2.5#0"; "ss32x25.ocx"
Object = "{AB3877A8-B7B2-11CF-9097-444553540000}#1.0#0"; "gtdate32.ocx"
Object = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "crystl32.ocx"
Object = "{9FE8BEE1-8569-4532-8518-BB32F08FC1EB}#2.0#0"; "dtF4.ocx"
Object = "{97335038-A7BC-4769-A9D0-0ABA53604B7B}#4.0#0"; "dtCancelar.ocx"
Object = "{9AC9B5FB-32D0-45ED-8D8D-2230E080F807}#9.0#0"; "dtCalendario.ocx"
Object = "{4BF4915B-F10F-4F39-9B5C-42E3F9C787AF}#4.0#0"; "dtAceptar.ocx"
Begin VB.Form FCO3052 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Archivos para Bancos con Selección de Trabajadores"
   ClientHeight    =   7350
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7845
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "FCO3052 Medios Bancos NS.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7350
   ScaleWidth      =   7845
   Begin VB.Timer tmrHelp 
      Enabled         =   0   'False
      Interval        =   3000
      Left            =   120
      Top             =   6840
   End
   Begin VB.Frame fraDatos 
      Height          =   5775
      Left            =   120
      TabIndex        =   14
      Top             =   840
      Visible         =   0   'False
      Width           =   7575
      Begin FPSpread.vaSpread sprDatos 
         Height          =   1800
         Left            =   3480
         OleObjectBlob   =   "FCO3052 Medios Bancos NS.frx":030A
         TabIndex        =   10
         Top             =   240
         Width           =   3855
      End
      Begin VB.CommandButton cmdFiltrar 
         Height          =   495
         Left            =   5400
         Picture         =   "FCO3052 Medios Bancos NS.frx":04E3
         Style           =   1  'Graphical
         TabIndex        =   29
         ToolTipText     =   "Click para Seleccionar los Trabajadores a incluir en el Archivo"
         Top             =   2280
         Width           =   495
      End
      Begin DataTec_Calendario.dtCalendario dtCalendario 
         Height          =   1695
         Left            =   120
         TabIndex        =   8
         Top             =   960
         Width           =   2655
         _ExtentX        =   4683
         _ExtentY        =   2990
      End
      Begin VB.ComboBox cboClaNom 
         Height          =   330
         Left            =   1440
         Style           =   1  'Simple Combo
         TabIndex        =   6
         Top             =   600
         Width           =   735
      End
      Begin VB.ComboBox cboCia 
         Height          =   330
         Left            =   1440
         Style           =   1  'Simple Combo
         TabIndex        =   3
         Top             =   240
         Width           =   735
      End
      Begin VB.Frame fraFrame 
         Caption         =   "Resultados del proceso"
         Height          =   1080
         Index           =   2
         Left            =   4680
         TabIndex        =   19
         Top             =   4560
         Width           =   2715
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "Trabajadores"
            Height          =   210
            Index           =   1
            Left            =   60
            TabIndex        =   23
            Top             =   315
            Width           =   960
         End
         Begin VB.Label lblLabels 
            AutoSize        =   -1  'True
            BackStyle       =   0  'Transparent
            Caption         =   "Valor Total"
            Height          =   210
            Index           =   2
            Left            =   90
            TabIndex        =   22
            Top             =   660
            Width           =   780
         End
         Begin VB.Label lblNroTrab 
            Alignment       =   2  'Center
            BackStyle       =   0  'Transparent
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   270
            Left            =   1050
            TabIndex        =   21
            Top             =   330
            Width           =   495
         End
         Begin VB.Label lblValorTotal 
            Alignment       =   1  'Right Justify
            BackStyle       =   0  'Transparent
            BorderStyle     =   1  'Fixed Single
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   270
            Left            =   1050
            TabIndex        =   20
            Top             =   660
            Width           =   1455
         End
      End
      Begin VB.CommandButton cmdQuitar 
         Height          =   375
         Left            =   2880
         Picture         =   "FCO3052 Medios Bancos NS.frx":0B65
         Style           =   1  'Graphical
         TabIndex        =   11
         ToolTipText     =   "Eliminar"
         Top             =   1335
         Width           =   495
      End
      Begin VB.CommandButton cmdAgregar 
         Height          =   375
         Left            =   2880
         Picture         =   "FCO3052 Medios Bancos NS.frx":0E6F
         Style           =   1  'Graphical
         TabIndex        =   9
         ToolTipText     =   "Agregar"
         Top             =   900
         Width           =   495
      End
      Begin VB.TextBox txtResponsable 
         Height          =   285
         Left            =   1440
         MaxLength       =   20
         TabIndex        =   18
         Top             =   5040
         Width           =   2145
      End
      Begin VB.CheckBox chkFiltrar 
         Caption         =   "Filtrar trabajadores con cuenta del banco"
         Height          =   285
         Left            =   240
         TabIndex        =   17
         Top             =   5400
         Value           =   1  'Checked
         Width           =   3450
      End
      Begin VB.Frame fraRutas 
         Caption         =   "Rutas (Lectura/Escritura)"
         Height          =   1725
         Left            =   120
         TabIndex        =   15
         Top             =   2760
         Width           =   7320
         Begin FPSpread.vaSpread sprRUT 
            Height          =   1305
            Left            =   150
            OleObjectBlob   =   "FCO3052 Medios Bancos NS.frx":1179
            TabIndex        =   16
            Top             =   285
            Width           =   6765
         End
         Begin DataTec_F4.dtF4 dtF4Rut 
            Height          =   375
            Left            =   6960
            TabIndex        =   28
            Top             =   480
            Width           =   255
            _ExtentX        =   450
            _ExtentY        =   661
         End
      End
      Begin Crystal.CrystalReport crpReporte 
         Left            =   2880
         Top             =   1920
         _ExtentX        =   741
         _ExtentY        =   741
         _Version        =   348160
         PrintFileLinesPerPage=   60
      End
      Begin GTMaskDate.GTMaskDate txtFecha 
         Height          =   315
         HelpContextID   =   722
         Left            =   1440
         TabIndex        =   24
         ToolTipText     =   "Fecha de Envio"
         Top             =   4560
         Width           =   1215
         _Version        =   65537
         _ExtentX        =   2143
         _ExtentY        =   556
         _StockProps     =   77
         BackColor       =   -2147483643
         KeepFocusOnError=   -1  'True
         CaretPicture    =   "FCO3052 Medios Bancos NS.frx":1352
         BeginProperty NullFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   -1  'True
            Strikethrough   =   0   'False
         EndProperty
         ValidateType    =   1
         ValidateRangeHigh=   "12/31/2500"
         ValidateRangeLow=   "01/01/2003"
         BeginProperty CalFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty CalCaptionFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         CalDayCaption1  =   "D"
         CalDayCaption2  =   "L"
         CalDayCaption3  =   "M"
         CalDayCaption4  =   "M"
         CalDayCaption5  =   "J"
         CalDayCaption6  =   "V"
         BeginProperty CalDayCaptionFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   9.75
            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 DataTec_F4.dtF4 dtF4Cia 
         Height          =   375
         Left            =   2280
         TabIndex        =   4
         Top             =   240
         Width           =   255
         _ExtentX        =   450
         _ExtentY        =   661
      End
      Begin DataTec_F4.dtF4 dtF4ClaNom 
         Height          =   375
         Left            =   2280
         TabIndex        =   7
         Top             =   600
         Width           =   255
         _ExtentX        =   450
         _ExtentY        =   661
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Todos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00FF0000&
         Height          =   210
         Index           =   6
         Left            =   6000
         TabIndex        =   31
         Top             =   2280
         Width           =   525
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Filtro de trabajadores:"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   210
         Index           =   5
         Left            =   3480
         TabIndex        =   30
         Top             =   2280
         Width           =   1815
      End
      Begin VB.Label lblLabels 
         BackStyle       =   0  'Transparent
         Caption         =   "C&lase Nómina"
         Height          =   315
         Index           =   0
         Left            =   360
         TabIndex        =   5
         Top             =   645
         Width           =   975
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Fecha"
         Height          =   210
         Index           =   3
         Left            =   240
         TabIndex        =   26
         Top             =   4560
         Width           =   450
      End
      Begin VB.Label lblLabels 
         BackStyle       =   0  'Transparent
         Caption         =   "&Compañia"
         Height          =   315
         Index           =   4
         Left            =   360
         TabIndex        =   2
         Top             =   300
         Width           =   930
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Responsable"
         Height          =   210
         Index           =   12
         Left            =   240
         TabIndex        =   25
         Top             =   5040
         Width           =   945
      End
   End
   Begin DataTec_Aceptar.dtAceptar dtAceptar1 
      Height          =   495
      Left            =   7080
      TabIndex        =   13
      Top             =   6720
      Width           =   495
      _ExtentX        =   873
      _ExtentY        =   873
   End
   Begin DataTec_Cancelar.dtCancelar dtCancelar1 
      Height          =   495
      Left            =   6480
      TabIndex        =   12
      Top             =   6720
      Width           =   495
      _ExtentX        =   873
      _ExtentY        =   873
   End
   Begin VB.Frame fraMedios 
      Caption         =   "&Medio a Generar"
      Height          =   720
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   7575
      Begin VB.ComboBox cboMedios 
         Height          =   330
         Left            =   105
         TabIndex        =   1
         Top             =   240
         Width           =   7335
      End
   End
   Begin VB.Label lblAyuda 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H80000018&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Presione ENTER para continuar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   405
      Left            =   4680
      TabIndex        =   27
      Top             =   960
      Visible         =   0   'False
      Width           =   2640
   End
End
Attribute VB_Name = "FCO3052"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private MAdo As ODBC.ODBCDirecto
Private WithEvents clsSpread As NSpread
Attribute clsSpread.VB_VarHelpID = -1
Private MiCx As Integer
Private MsMedios() As String
Private MbTpoNom_OK As Boolean
Private MiIdProc As Integer
Private MsBanco As String
Private MbError As Boolean
Private MbRaton As Boolean
Private MbEnF4 As Boolean 'Bandera para no hacer caso al F3 si el usuario lo dio en el form de Lista

Private Sub cboCia_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then dtF4Cia_Click
End Sub

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

Private Sub cboClaNom_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then dtF4ClaNom_Click
End Sub

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

Private Sub cboMedios_Click()
    fraDatos.Visible = False
    If MbRaton Then AceptarMedio
    MbRaton = True
    tmrHelp.Enabled = True
End Sub

Private Sub cboMedios_KeyDown(KeyCode As Integer, Shift As Integer)
    MbRaton = False
End Sub

Private Sub cboMedios_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
        AceptarMedio
    Else
        MbRaton = False
        Autocompletar cboMedios, KeyAscii
        MbRaton = True
    End If
End Sub

Private Sub cmdAgregar_Click()
    Dim sCN As String
    
    If cboCia.ListIndex = -1 Then Exit Sub
    If dtCalendario.TipoNomina = "" Then Exit Sub
    If dtCalendario.Año = 0 Then Exit Sub
    If dtCalendario.Periodo = 0 Then Exit Sub
    
    If Not MbTpoNom_OK Then
        ValidarTipoNomina
        If Not MbTpoNom_OK Then Exit Sub
    End If
    
    MbError = False
    ObtenerFecha
    If MbError Then Exit Sub
    
    If cboClaNom.ListIndex = -1 Then
        'se quiere insertar varias clases de nomina
        MAdo.Sql = "SELECT a.clase_nomina" & _
        " FROM clases_nomina a, rel_usu_clase_nom b" & _
        " WHERE a.clase_nomina = b.clase_nomina" & _
        " AND b.usuario = '" & GsUid & "'"
        MAdo.SendSQL
    
        While Not MAdo.EOF
            sCN = MAdo.GetField(1)
            If bRegistroNuevo(sCN) Then AgregarNuevoRegistro sCN
            MAdo.Mnext
        Wend
    Else
        If bRegistroNuevo(cboClaNom.Text) Then
            AgregarNuevoRegistro cboClaNom.Text
        Else
            clsMsgbox.Mensaje "El registro a procesar ya existe", mAceptar, mAdvierte, GsTitMsg
        End If
    End If
    
    cboClaNom.ListIndex = -1
    dtCalendario.TipoNomina = ""
    dtCalendario.Año = 0
    dtCalendario.Periodo = 0
    MbTpoNom_OK = False
    
    On Error Resume Next
    If cboClaNom.Enabled Then
        cboClaNom.SetFocus
    Else
        dtCalendario.SetFocus
    End If
End Sub

Private Sub cmdFiltrar_Click()
    Dim sCias As String
    Dim sClaNoms As String
    Dim i As Integer
    Dim vaux As Variant
    
    If sprDatos.MaxRows > 0 Then
        Screen.MousePointer = vbHourglass
        MbEnF4 = True
        sCias = ""
        sClaNoms = ""
        For i = 1 To sprDatos.MaxRows
            sprDatos.GetText 1, i, vaux
            sCias = sCias & IIf(sCias = "", "", ",") & "'" & CStr(vaux) & "'"
            sprDatos.GetText 2, i, vaux
            sClaNoms = sClaNoms & IIf(sClaNoms = "", "", ",") & "'" & CStr(vaux) & "'"
        Next i
        sCias = "(" & Replace(sCias, "'", "''") & ")"
        sClaNoms = "(" & Replace(sClaNoms, "'", "''") & ")"
        MAdo.Sql = "sp_fdt_ins_bancos_trab '" & GsUid & "'," & Val(MsBanco) & ",'" & sCias & "','" & sClaNoms & "'"
        If MAdo.ExecSQL <> -1 Then
            FCO3052F.PasarDatos Val(MsBanco)
            FCO3052F.Show 1
            If GiEntero = 0 Then
                lblLabels(6) = "Todos"
            Else
                lblLabels(6) = GiEntero & " Trabajadores"
            End If
        End If
    End If
End Sub

Private Sub cmdQuitar_Click()
    If sprDatos.VirtualMaxRows <> 0 Then
        With sprDatos
            .Row = .ActiveRow
            .Action = 5
            .VirtualMaxRows = .VirtualMaxRows - 1
            .Row = .VirtualMaxRows
            If .Row <= 6 Then .ColWidth(5) = 7.4
        End With
    End If
End Sub

Private Sub dtAceptar1_Click()
    Procesa
End Sub

Private Sub dtCalendario_Change(Origen As DataTec_Calendario.OrigenF4)
    If Origen = oTipoNomina Then MbTpoNom_OK = False
End Sub

Private Sub dtCalendario_F4(Origen As DataTec_Calendario.OrigenF4)
    Screen.MousePointer = vbHourglass
    
    MbEnF4 = True
    Dim Lista As New cdtLista
    
    If Origen = oTipoNomina Then
        With Lista
            .Sql = "SELECT tipo_nomina, descripcion FROM tipos_nomina WHERE manejo = 1"
            .Campo1 = "tipo_nomina"
            .Campo2 = "descripcion"
            .Titulo1 = "Tipo de Nómina"
            .Titulo2 = "Descripcion"
            .TituloVentana = "Tipos de Nómina"
            .MostrarLista
            If .Valor1 <> "" Then
                dtCalendario.TipoNomina = .Valor1
                SendEnter
                SendEnter
            End If
        End With
    Else
        If Trim(dtCalendario.TipoNomina) = "" Then
            dtCalendario_F4 oTipoNomina
        Else
            With Lista
                .Sql = " SELECT anio, periodo" & _
                       " FROM calendario_procesos a, cal_proc_cias b" & _
                       " WHERE a.id_calendario = b.id_calendario" & _
                         " AND b.compania = '" & cboCia.Text & "'" & _
                         " AND tipo_nomina = '" & dtCalendario.TipoNomina & "'"
                .Campo1 = "anio"
                .Campo2 = "periodo"
                .Titulo1 = "Año"
                .Titulo2 = "Período"
                .Orden = "anio * 100000 + periodo DESC"
                .TituloVentana = "Períodos de Nómina"
                .MostrarLista
                If .Valor1 <> "" Then
                    dtCalendario.Año = .Valor1
                    dtCalendario.Periodo = .Valor2
                    On Error Resume Next
                    cmdAgregar.SetFocus
                End If
            End With
        End If
    End If
    
    Set Lista = Nothing
    Screen.MousePointer = vbDefault
End Sub

Private Sub dtCalendario_KeyReturn(Origen As DataTec_Calendario.OrigenF4, Cancelar As Boolean)
    If Origen = oTipoNomina Then
        ValidarTipoNomina
        If Not MbTpoNom_OK Then Cancelar = True
    End If
End Sub

Private Sub dtCancelar1_Click()
    Unload Me
End Sub

Private Sub dtF4Cia_Click()
    Dim Lista As New cdtLista
    
    MbEnF4 = True
    With Lista
        .Campo1 = "compania"
        .Campo2 = "nombre_cia"
        .Sql = "SELECT compania, nombre_cia FROM companias" & _
        " WHERE compania IN (SELECT compania FROM aut_companias WHERE usuario = '" & GsUid & "')"
        .Titulo1 = "Compañía"
        .Titulo2 = "Nombre"
        .TituloVentana = "Compañías"
        .MostrarLista
        If .Valor1 <> "" Then
            cboCia.ListIndex = iBuscarDatoEnCombo(cboCia, .Valor1)
        End If
        If cboCia.ListIndex >= 0 Then SendEnter: SendEnter
    End With
    
    Set Lista = Nothing
End Sub

Private Sub dtF4ClaNom_Click()
    Dim Lista As New cdtLista
    
    MbEnF4 = True
    With Lista
        .Campo1 = "clase_nomina"
        .Campo2 = "descripcion"
        .Sql = "SELECT clase_nomina, descripcion FROM clases_nomina" & _
        " WHERE clase_nomina IN (SELECT clase_nomina FROM rel_usu_clase_nom WHERE usuario = '" & GsUid & "')"
        .Titulo1 = "Clase Nómina"
        .Titulo2 = "Descripción"
        .TituloVentana = "Clases de Nómina"
        .MostrarLista
        If .Valor1 <> "" Then
            cboClaNom.ListIndex = iBuscarDatoEnCombo(cboClaNom, .Valor1)
            On Error Resume Next
            SendEnter
            SendEnter
        End If
    End With
    
    Set Lista = Nothing
End Sub

Private Sub dtF4RUT_Click()
    Dim vaux As Variant
    Dim sRuta As String
    Dim Carpeta As New cdtCarpeta
    
    MbEnF4 = True
    With sprRUT
        If .ActiveCol = 4 Then
            .GetText .ActiveCol, .ActiveRow, vaux
            sRuta = vaux
            sRuta = sCambiarSlash(sRuta, 2)
            sRuta = Carpeta.PedirCarpeta(sRuta)
            If sRuta <> "" Then
                .Col = 4: .Row = .ActiveRow: .Text = sCambiarSlash(sRuta, 1)
            End If
        End If
    End With
    
    Set Carpeta = Nothing
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF3
            If MbEnF4 Then
                MbEnF4 = False
            Else
                GbRen = False
                Unload Me
            End If
        Case vbKeyF11: Procesa
    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
        
    Caption = GsDsn & "/" & GsCveCia & " - Archivos para Bancos"
    
    GAdam.ConfiguraFecha txtFecha, True
    txtFecha.Text = Date
        
    'Tamaño de la forma
    Width = 7935
    Height = 7830
        
    GAdam.ObtieneColores
    Set clsSpread = New NSpread
    ConfiguraSpread
    
    MbTpoNom_OK = False
    MbRaton = True
    MbEnF4 = False
    MsBanco = "0"
    
    LlenarListas
    RenuevaDatosRut
End Sub

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

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

Private Sub sprRUT_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then dtF4RUT_Click
End Sub

Private Sub tmrHelp_Timer()
    lblAyuda.Visible = True
    tmrHelp.Enabled = False
End Sub

Private Sub AceptarMedio()
    If cboMedios.ListIndex = -1 Then Exit Sub
    lblAyuda.Visible = False
    MsBanco = MsMedios(0, cboMedios.ListIndex)
    txtResponsable = MsMedios(1, cboMedios.ListIndex)
    RenuevaDatosRut
    fraDatos.Visible = True
    If cboMedios.Enabled = False Then
        'Transpasar el tabindex inicial
        If cboCia.Enabled Then
            cboCia.TabIndex = 1
        Else
            If cboClaNom.Enabled Then
                cboClaNom.TabIndex = 1
            Else
                dtCalendario.TabIndex = 1
            End If
        End If
    Else
        On Error Resume Next
        cboCia.SetFocus
    End If
    MAdo.Sql = "sp_fdt_del_bancos_trab '" & GsUid & "', " & Val(MsBanco) & ", ''"
    MAdo.ExecSQL
End Sub

Private Sub AgregarNuevoRegistro(ClaseNomina As String)
    With sprDatos
        'Agregando una fila al spread
        .Row = .VirtualMaxRows + 1: .Action = 7
        .VirtualMaxRows = .VirtualMaxRows + 1
        .Row = .VirtualMaxRows
        .SetText 1, .Row, cboCia.Text
        .SetText 2, .Row, ClaseNomina
        .SetText 3, .Row, dtCalendario.TipoNomina
        .SetText 4, .Row, dtCalendario.Año
        .SetText 5, .Row, dtCalendario.Periodo
        If .Row > 6 Then .ColWidth(5) = 5.3
    End With
End Sub

Private Sub BorrarIdRep()
    'preguntar antes si MiIdProc es diferente a cero para borrarlo lo anterior
    If MiIdProc <> 0 Then
        'Llamada al procedimiento, de borrado de archivos
        MAdo.Sql = "sp_fdt_del_bancos_proc " & _
            MiIdProc & "," & _
            "'" & GsUid & "'," & MsMedios(0, cboMedios.ListIndex) & ""
        MAdo.ExecSQL
    End If
End Sub

Private Function bRegistroNuevo(ClaseNomina As String) As Boolean
    Dim sCia As String
    Dim sClaseNom As String
    Dim sTipoNom As String
    Dim sAnio As String
    Dim sPeriodo As String
    Dim i As Byte

    bRegistroNuevo = True
    'Revisando que no se este insertando algo ya registrado
    With sprDatos
        For i = 1 To .MaxRows
            .Row = i
            .Col = 1: sCia = Trim(.Text)
            .Col = 2: sClaseNom = Trim(.Text)
            .Col = 3: sTipoNom = Trim(.Text)
            .Col = 4: sAnio = Trim(.Text)
            .Col = 5: sPeriodo = Trim(.Text)
            
            If sCia = cboCia.Text And sClaseNom = ClaseNomina And sTipoNom = dtCalendario.TipoNomina And _
            Val(sAnio) = dtCalendario.Año And Val(sPeriodo) = dtCalendario.Periodo Then
                bRegistroNuevo = False
                i = .MaxRows + 1
            End If
        Next i
    End With
End Function

Private Sub ConfiguraSpread()
    'Se configura el Spread
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
        .ColWidth(1) = 6
        .ColWidth(2) = 6
        .ColWidth(3) = 6
        .ColWidth(4) = 6
        .ColWidth(5) = 7.4
        
        .SetText 1, 0, "Cia"
        .SetText 2, 0, "C.Nom."
        .SetText 3, 0, "T.Nom."
        .SetText 4, 0, "Anio"
        .SetText 5, 0, "Periodo"
        
        .Col = 1: .TypeEditLen = 4: .TypeEditCharCase = 2
        .Col = 2: .TypeEditLen = 2: .TypeEditCharCase = 2
        .Col = 3: .TypeEditLen = 2: .TypeEditCharCase = 2
        .Col = 4: .TypeEditLen = 4: .TypeEditCharCase = 2
        .Col = 5: .TypeEditLen = 3: .TypeEditCharCase = 2
        
        .Col = -1: .Row = -1: .Lock = True
        .ScrollBars = ScrollBarsBoth
        ConfiguraSpreadJCL sprDatos
    End With
    MAdo.Sql = "SELECT '','','','','' FROM companias WHERE compania='Z'"
    MAdo.SendSQL
    
    clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
End Sub

Private Sub LlenarListas()
    'Llenado del combo de archivos disponibles
    MAdo.Sql = "SELECT banco, descripcion, responsable FROM vw_fdt_bancos WHERE compania = '" & GsCveCia & "'"
    If Not MAdo.SendSQL Then Exit Sub
    Do Until MAdo.EOF
        cboMedios.AddItem MAdo.GetField(2)  'Descripcion
        ReDim Preserve MsMedios(2, cboMedios.NewIndex)
        MsMedios(0, cboMedios.NewIndex) = MAdo.GetField(1)
        MsMedios(1, cboMedios.NewIndex) = "" & MAdo.GetField(3)
        MAdo.Mnext
    Loop

    'Llenado el combo para Compañías
    MAdo.Sql = "SELECT RTrim(compania) FROM aut_companias WHERE usuario = '" & GsUid & "' ORDER BY 1"
    If MAdo.SendSQL Then
        Do Until MAdo.EOF
            cboCia.AddItem MAdo.GetField(1)
            MAdo.Mnext
        Loop
    End If
    If cboCia.ListCount = 1 Then
        cboCia.ListIndex = 0
        cboCia.Enabled = False
        dtF4Cia.Habilitado = False
    Else
        cboCia.ListIndex = iBuscarDatoEnCombo(cboCia, GsCveCia)
    End If
    
    'Llenando el combo para Clases de Nómina
    MAdo.Sql = "SELECT RTrim(clase_nomina) FROM rel_usu_clase_nom WHERE usuario = '" & GsUid & "' ORDER BY 1"
    If MAdo.SendSQL Then
        Do Until MAdo.EOF
            cboClaNom.AddItem MAdo.GetField(1)
            MAdo.Mnext
        Loop
    End If
    If cboClaNom.ListCount = 1 Then
        cboClaNom.ListIndex = 0
        cboClaNom.Enabled = False
        dtF4ClaNom.Habilitado = False
    End If
    
    'Si solo hay un medio activar los controles
    If cboMedios.ListCount = 1 Then
        cboMedios.ListIndex = 0
        cboMedios.Enabled = False
        AceptarMedio
    End If
End Sub

Private Sub MostrarMM()
    Dim sTabla As String
    Dim sRuta As String
    Dim sArchivo As String
    Dim i As Integer
    Dim Aux As Variant
    Dim iTipo As Byte
    Dim iSec As Integer
    Dim iRetVal As Long
    Dim sFuncSub As String
    Dim iIntentos As Integer 'JCL Junio 20/07 Para Pronaca

    On Error GoTo RutaNoExiste
    MbError = False
    
    iIntentos = 0 'JCL Junio 20/07 Para Pronaca

    If Mid$(UCase(GsDsn), 1, 3) = "ORA" Then
        sFuncSub = "SubStr"
    Else
        sFuncSub = "SubString"
    End If
    
    With sprRUT
        For i = 1 To .VirtualMaxRows
            .GetText 2, i, Aux
            iTipo = CInt(Aux)
            .Col = 1: .Row = i
            If Val(.Value) = 1 And iTipo = 2 Then  'si esta seleccionado y ademas es archivo
                .GetText 3, i, Aux
                sArchivo = CStr(Aux)
                .GetText 4, i, Aux
                sRuta = CStr(Aux)
                sRuta = sCambiarSlash(sRuta, 2)
                .GetText 5, i, Aux
                sTabla = CStr(Aux)
                .GetText 6, i, Aux
                iSec = CInt(Aux)
                
                MAdo.Sql = "SELECT " & sFuncSub & "(registros,1,255)," & sFuncSub & "(registros, 256, 255), " & _
                "" & sFuncSub & "(registros,511,255)," & sFuncSub & "(registros, 766, 255), " & sFuncSub & "(registros, 1021, 255) " & _
                "FROM " & sTabla & " " & _
                " WHERE id_rep = " & MiIdProc & " AND usuariow = '" & GsUid & "'" & _
                " AND banco = " & MsBanco & " AND sec_archivo = " & iSec & "" & _
                " ORDER BY secuencia "
                If Not MAdo.SendSQL Then GoTo Finaliza
                
                sRuta = sRuta & "\" & sArchivo
                
                'JCL Junio 20/07 Para Pronaca
                If Dir(sRuta, vbArchive) <> "" Then 'Si existe se borra
                    Shell "Attrib " & sRuta & " -r" 'Para poder borrarlo hay que quitarle la propiedad solo lectura
                    Kill sRuta 'Eliminar el archivo
                End If
                    
                Open sRuta For Output As #1
                Do Until MAdo.EOF
                    Print #1, MAdo.GetField(1) & MAdo.GetField(2) & MAdo.GetField(3) & MAdo.GetField(4) & MAdo.GetField(5)
                    MAdo.Mnext
                Loop
                Close #1
                                
                Shell "Attrib " & sRuta & " +r" 'JCL Junio 20/07 Para Pronaca Se establece atributo de solo lectura
                
                iRetVal = Shell("NOTEPAD.EXE " & sRuta, vbNormalFocus)
            End If
        Next i
    End With
    Exit Sub
RutaNoExiste:
    MbError = True
    If Err = 76 Then
        sRuta = "C:"
        Resume Next
    Else 'JCL Junio 20/07 Para Pronaca
        If Err = 70 Or Err = 75 Then
            iIntentos = iIntentos + 1
            If iIntentos < 5000 Then
                Resume
            Else
                Screen.MousePointer = vbDefault
                clsMsgbox.Mensaje Err.Description, mAceptar, mAdvierte, GsTitMsg
            End If
        Else
            Screen.MousePointer = vbDefault
            clsMsgbox.Mensaje Err.Description, mAceptar, mAdvierte, GsTitMsg
        End If
    End If
Finaliza:
    MbError = True
    Screen.MousePointer = vbDefault
End Sub

Private Sub MostrarReporte()
    Dim sTabla As String
    Dim sRuta As String
    Dim sArchivo As String
    Dim i As Integer
    Dim j As Integer
    Dim Aux As Variant
    Dim iTipo As Byte

    On Error GoTo RutaNoExiste
    MbError = False

    With sprRUT
        For i = 1 To .VirtualMaxRows
            .GetText 2, i, Aux
            iTipo = CInt(Aux)
            .Col = 1: .Row = i
            If Val(.Value) = 1 And iTipo = 1 Then  'si esta seleccionado y ademas es reporte
                .GetText 3, i, Aux
                sArchivo = CStr(Aux)
                .GetText 4, i, Aux
                sRuta = CStr(Aux)
                sRuta = sCambiarSlash(sRuta, 2)
                .GetText 5, i, Aux
                sTabla = CStr(Aux)
          
                'Abriendo el reporte
                With crpReporte
                    .WindowShowPrintSetupBtn = True
                    .WindowShowSearchBtn = True
                    .MarginLeft = 0
                    .WindowState = crptNormal
                    .WindowTitle = "Reportes Interfases"
                    .WindowLeft = 100
                    .WindowTop = 100
                      
                    .ReportFileName = sRuta & "\" & sArchivo
                    .Connect = "DSN = " & UCase(GsDsn) & "; UID = " & GsUid & "; PWD = " & GsPwd
                
                    .SQLQuery = " SELECT * FROM " & sTabla & _
                    " WHERE id_rep = " & MiIdProc & " AND usuariow = '" & GsUid & "'" & _
                    " AND banco = " & MsBanco
                    
                    .ReplaceSelectionFormula ""
                
                    For j = 0 To .GetNSubreports - 1
                        .SubreportToChange = .GetNthSubreportName(j)
                        .Connect = "DSN = " & UCase(GsDsn) & "; UID = " & GsUid & "; PWD = " & GsPwd
                    Next j
                
                    .WindowState = crptNormal
                    .Action = 1
                
                    For j = 0 To .GetNSubreports - 1
                        .DataFiles(0) = ""
                    Next j
                End With
            End If
        Next i
    End With
    Exit Sub
RutaNoExiste:
    If Err > 0 Then
        MbError = True
        Screen.MousePointer = vbDefault
        clsMsgbox.Mensaje Err.Description, mAceptar, mAdvierte, GsTitMsg
    End If
End Sub

Private Sub ObtenerFecha()
    Screen.MousePointer = vbHourglass
    MAdo.Sql = _
    " SELECT a.fecha_pago" & _
    " FROM calendario_procesos a, cal_proc_cias b" & _
    " WHERE a.id_calendario = b.id_calendario" & _
    " AND b.compania = '" & cboCia.Text & "'" & _
    " AND a.tipo_nomina = '" & dtCalendario.TipoNomina & "'" & _
    " AND a.anio = " & dtCalendario.Año & _
    " AND a.periodo = " & dtCalendario.Periodo
    MAdo.SendSQL
    If MAdo.EOF Then
        clsMsgbox.Mensaje "No existe ese período o ese calendario no está relacionado con esta compañia", mAceptar, mAdvierte, GsTitMsg
        dtCalendario.SetFocus
        MbError = True
    Else
        txtFecha.Text = MAdo.GetFieldDate(1)
    End If
    Screen.MousePointer = vbDefault
End Sub

Private Sub Procesa()
    On Error GoTo NoPude
    Dim sFuncSub As String
    Dim iRetVal As Integer
    Dim sCia As String
    Dim sClaseNom As String
    Dim sTipoNom As String
    Dim sAnio As String
    Dim sPeriodo As String
    Dim i As Integer
            
    'Zona de validaciones
    If cboMedios.ListIndex = -1 Then
        clsMsgbox.Mensaje "Seleccione el archivo a generar", mAceptar, mAdvierte, GsTitMsg
        On Error Resume Next
        cboMedios.SetFocus
        Exit Sub
    End If

    If sprDatos.VirtualMaxRows = 0 Then
        clsMsgbox.Mensaje "No hay registros para procesar, agregue los registros a la grilla de la derecha", mAceptar, mAdvierte, GsTitMsg
        Exit Sub
    End If

    BorrarIdRep
    'Hallar un id para este proceso
    Randomize
    MiIdProc = Int((32000 * Rnd) + 1)
      
    'Proceso Principal
    Screen.MousePointer = vbHourglass
    
    MAdo.Sql = "DELETE FROM ri_procesar WHERE id_rep = " & MiIdProc & " AND usuariow = '" & GsUid & "'"
    If MAdo.ExecSQL = -1 Then GoTo NoPude
    With sprDatos
        For i = 1 To .MaxRows
            .Row = i
            .Col = 1: sCia = Trim(.Text)
            .Col = 2: sClaseNom = Trim(.Text)
            .Col = 3: sTipoNom = Trim(.Text)
            .Col = 4: sAnio = Trim(.Text)
            .Col = 5: sPeriodo = Trim(.Text)
                
            MAdo.Sql = "INSERT INTO ri_procesar (id_rep, usuariow, grupo_nom, compania, clase_nomina, tipo_nomina, anio, periodo)" & _
            " VALUES (" & MiIdProc & ",'" & GsUid & "','','" & sCia & "','" & sClaseNom & "','" & sTipoNom & "'," & sAnio & "," & sPeriodo & ")"
            If MAdo.ExecSQL = -1 Then GoTo NoPude
        Next i
    End With
                
    'Llamada al procedimiento
    MAdo.Sql = "sp_fdt_gen_medios_bancos " & _
    "" & MiIdProc & ",'" & GsUid & "'," & _
    "" & MsMedios(0, cboMedios.ListIndex) & "," & _
    "'" & Format(txtFecha.Text, "yyyymmdd") & "'," & _
    "'" & txtResponsable.Text & "', 1, " & _
    IIf(Me.chkFiltrar.Value = vbChecked, 1, 0)
    
    If MAdo.ExecSQL = -1 Then GoTo NoPude
                
    MostrarReporte
    If MbError Then GoTo Finaliza
    MostrarMM
    If MbError Then GoTo Finaliza
        
    'Hallar los resultados del proceso
    MAdo.Sql = _
    " SELECT trabajadores, valor_total" & _
    " FROM fdt_bancos_resultados" & _
    " WHERE id_rep = " & MiIdProc & "" & _
    " AND usuariow = '" & GsUid & "'" & _
    " AND banco = " & MsMedios(0, cboMedios.ListIndex)
    If Not MAdo.SendSQL Then GoTo Finaliza
    
    If Not MAdo.EOF Then
        lblNroTrab = "" & MAdo.GetField(1)
        lblValorTotal = Format("" & MAdo.GetField(2), "###,##0.00")
    End If
            
    Screen.MousePointer = vbDefault
            
    Exit Sub
NoPude:
    BorrarIdRep
    Screen.MousePointer = vbDefault
    clsMsgbox.Mensaje Err & " " & Err.Description, mAceptar, mAdvierte, GsTitMsg

Finaliza:
    Screen.MousePointer = vbDefault
End Sub

Private Sub RenuevaDatosRut()
    Dim i As Integer
    Dim iValor As Byte

    With sprRUT
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprRUT
        
        .ColWidth(1) = 2
        .ColWidth(2) = 0
        .ColWidth(3) = 14
        .ColWidth(4) = 40
        .ColWidth(5) = 0
        .ColWidth(6) = 0
        
        .SetText 1, 0, " "
        .SetText 2, 0, "Tipo Oculto": .Col = 2: .ColHidden = True
        .SetText 3, 0, "Archivo"
        .SetText 4, 0, "Ruta (Lectura/Escritura)"
        .SetText 5, 0, "Tabla Oculta": .Col = 5: .ColHidden = True
        .SetText 6, 0, "Secuencia Oculta": .Col = 6: .ColHidden = True
                
        .Col = 3: .TypeEditLen = 50
        .Col = 4: .TypeEditLen = 500
                                
        .ScrollBars = ScrollBarsBoth
        ConfiguraSpreadJCL sprRUT
    End With
    
    MAdo.Sql = "SELECT 1, tipo, archivo, ruta, tabla, secuencia FROM fdt_rutas " & _
               "WHERE operacion = 'FCO1070' AND codigo = " & MsBanco & " ORDER BY tipo"
    If Not MAdo.SendSQL Then Exit Sub
    clsSpread.LlenaSpread 0, sprRUT, MAdo, MAdo.lhDbc, MAdo.lhstmt

    With sprRUT
        For i = 1 To .VirtualMaxRows
            .Col = 2: .Row = i
            If .Text <> "" Then
                iValor = Val(.Value)
            Else
                iValor = 255
            End If
        
            If iValor = 1 Then 'es un reporte, no se puede cambiar
                .Col = 3: .Row = i: .Lock = True
            End If
            .Col = 1: .Row = -1: .CellType = 10
        Next i
    End With

End Sub

Private Sub ValidarTipoNomina()
    Screen.MousePointer = vbHourglass
    MbTpoNom_OK = True
    MAdo.Sql = "SELECT 1 FROM tipos_nomina WHERE tipo_nomina = '" & dtCalendario.TipoNomina & "'"
    MAdo.SendSQL
    If MAdo.EOF Then
        MbTpoNom_OK = False
        clsMsgbox.Mensaje "No existe el tipo de nómina", mAceptar, mAdvierte, GsTitMsg
        dtCalendario.SetFocus
    End If
    Screen.MousePointer = vbDefault
End Sub

