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 FCO2020 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Administración de Embargos"
   ClientHeight    =   5070
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10950
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Administracion de Embargos.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5070
   ScaleWidth      =   10950
   Begin VB.ComboBox cboConcepto 
      Height          =   330
      Left            =   3960
      TabIndex        =   2
      Top             =   90
      Width           =   840
   End
   Begin VB.ComboBox cboSituacion 
      Height          =   330
      ItemData        =   "Administracion de Embargos.frx":030A
      Left            =   8760
      List            =   "Administracion de Embargos.frx":0314
      Style           =   2  'Dropdown List
      TabIndex        =   3
      Top             =   105
      Width           =   1995
   End
   Begin VB.TextBox txtBusqueda 
      Height          =   330
      Index           =   1
      Left            =   1110
      TabIndex        =   1
      Top             =   90
      Width           =   2835
   End
   Begin VB.TextBox txtBusqueda 
      Height          =   330
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   90
      Width           =   975
   End
   Begin FPSpread.vaSpread sprDatos 
      Bindings        =   "Administracion de Embargos.frx":032C
      Height          =   3825
      Left            =   120
      TabIndex        =   4
      Top             =   480
      Width           =   10695
      _Version        =   131077
      _ExtentX        =   18865
      _ExtentY        =   6747
      _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  =   "Administracion de Embargos.frx":0342
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   0
      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           =   "Administracion de Embargos.frx":049B
   End
End
Attribute VB_Name = "FCO2020"
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 MBitacora As New ADAMBitacora.Bitacora

Private MbFirst As Boolean

Private MbRenovar As Boolean
Private MsSql As String
Private MsSql0 As String
Private MsOrder As String
Private MsSituacion As String
Private MbCargando As Boolean
Private MbOrdenAsc As Boolean
Private MsAntOrden As String
Private MsWhereAdi As String
Private MsConceptos() As String

Private MiKey As Integer

Private Sub abToolbar_Click(ByVal Tool As ActiveBarLibraryCtl.Tool)
    Select Case LCase(Tool.Name)
        Case "tlalta": Altas
        Case "tlbaja": Bajas
        Case "tltrabaja": TrabajarCon
        Case "tlaulas": OficinasEmbargos
        Case "tlordena": OrdenarDatos
        Case "tlrenueva": AplicaFiltros
        Case "tlguarda": GuardaCambios
        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 cboSituacion_Click()
    If MbCargando Then Exit Sub
    Select Case cboSituacion.ListIndex
        Case 0: MsSituacion = " AND situacion = 1"
        Case 1: MsSituacion = " AND situacion <> 1"
    End Select
    RenuevaDatos
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
            Screen.MousePointer = vbHourglass
            MBitacora.mBorra
            Screen.MousePointer = vbDefault
        Case vbKeyF11: GuardaCambios
        Case vbKeyF12: abToolbar.Bands(1).TrackPopup -1, -1
    End Select
End Sub

Private Sub Form_Load()
    Dim sConcat As String
    
    MbFirst = True
    GbAError = False
    Me.Tag = GiVenMax%
    Gven(Val(Me.Tag)).icx = Gicx%
    MiCx = Gven(Val(Me.Tag)).icx
    Set MAdo = Gtc(MiCx).Ado
    If GbSinRegistrar Then RegistraVersion MAdo
    Caption = GsDsn & " / " & GsAbreviaturaCia & " - Resoluciones Judiciales"

    '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
        
    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 = 11040
        MiY = 5550
        Me.Width = MiX
        Me.Height = MiY
    End If
    
    Set clsSpread = New NSpread
    GAdam.ObtieneColores
    
    GbAlterarToolBar = True
    AsignaIconos abToolbar, 3, LALTA, LBAJA, LTRABAJA, LAULAS, LORDENA, LRENUEVA, LGUARDA, LSALIDA
    ToolInicioGrupo abToolbar, 3, True, 2, 5
    GbAlterarToolBar = False
        
    CreaBitacora
            
    MbCargando = True
    MsOrder = " Order By 1 DESC"
    cboSituacion.ListIndex = 0
    If Left(UCase(GsDsn), 3) = "ORA" Then
        sConcat = "||"
    Else
        sConcat = "+"
    End If
    MsSituacion = " And situacion = 1"
    MsSql0 = _
    " SELECT trabajador, apellidos " & sConcat & " ' ' " + sConcat + " nombres nombre," & _
    " concepto, secuencia, base, quinta_parte," & _
    " monto_total, saldo_actual, porcentaje, cuota_fija" & _
    " FROM vw_fdt_embargos" & _
    " WHERE compania = '" & GsCveCia & "'"
    MsSql = MsSql0
    MsWhereAdi = " AND 1=2"
    RenuevaDatos
    LlenarCombos
    MbCargando = False
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 2 Then abToolbar.Bands(1).TrackPopup -1, -1
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If iDeseaGuardarCambios = 2 Then Cancel = True
    Set MAdo = Nothing
    Gtc(MiCx).ihijas = Gtc(MiCx).ihijas - 1
    Set clsSpread = Nothing
    Set MBitacora = Nothing
    Set FCO2020 = Nothing
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 2
            sprDatos.GetDataFillData Aux, 1
            sprDatos.SetText Col, Row, Replace(Aux, "/", " ")
            Cancel = True
    End Select
End Sub

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

Private Sub Bajas()
    If sprDatos.VirtualMaxRows <= 0 Then Exit Sub
    MBitacora.mBorra
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_fdt_baja_embargos", "'" & GsCveCia & "'", 1, 3, 4
End Sub

Private Sub GuardaCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    MbRenovar = MBitacora.mActualizaBD
    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 MBitacora.pTransActual > 0 Then
       iDeseaGuardarCambios = clsMsgbox.Mensaje("¿Desea guardar los cambios?", mSiNoCancelar, mConfirma, GsTitMsg)
       Select Case iDeseaGuardarCambios
          Case 6
             GuardaCambios
             If MbRenovar = 0 Then iDeseaGuardarCambios = 2
          Case 7
             MBitacora.mVaciaBuffer 'Vacía el Buffer de la Bitácora
       End Select
    Else
        iDeseaGuardarCambios = 1
    End If
End Function

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

Private Sub RenuevaDatos()
    ConfiguraSpread
    
    MAdo.Sql = MsSql & MsWhereAdi & MsSituacion & MsOrder
    If Not MAdo.SendSQL Then Exit Sub
        
    clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
    
    With sprDatos
        .ColWidth(1) = 8
        .ColWidth(2) = 24
        .ColWidth(3) = 7
        .ColWidth(4) = 4
        .ColWidth(5) = 4
        .ColWidth(6) = 4
        .ColWidth(7) = 10
        .ColWidth(8) = 10
        .ColWidth(9) = 5
        .ColWidth(10) = 10
    End With
    GAdam.AjustaSpread sprDatos, 10
End Sub

Private Sub ConfiguraSpread()
    sprDatos.VisibleCols = 8
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
    
        .Row = 0:
        .Col = 1: .Text = "Trabajador"
        .Col = 2: .Text = "Nombre"
        .Col = 3: .Text = "Concepto"
        .Col = 4: .Text = "Sec."
        .Col = 5: .Text = "Base"
        .Col = 6: .Text = "1/5"
        .Col = 7: .Text = "Monto Total"
        .Col = 8: .Text = "Saldo Actual"
        .Col = 9: .Text = "%"
        .Col = 10: .Text = "Cuota Fija"
        .Col = 2
        .DataFillEvent = True
        .Col = -1: .Row = -1: .Lock = True
    End With
    ConfiguraSpreadJCL sprDatos
End Sub

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

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

Private Sub AplicaFiltros()
    MsSql = MsSql0
    MsWhereAdi = ""
    If Trim(txtBusqueda(0)) <> "" Then
        Select Case MiKey
            Case vbKeyReturn
                MsWhereAdi = " AND trabajador Like '%" & txtBusqueda(0) & "%'"
            Case 10
                MsWhereAdi = " AND trabajador Like '" & txtBusqueda(0) & "%'"
        End Select
    End If
    If Trim(txtBusqueda(1)) <> "" Then
        Select Case MiKey
            Case vbKeyReturn
                MsWhereAdi = MsWhereAdi & " AND apellidos Like '%" & Replace(txtBusqueda(1), "/", " ") & "%'"
            Case 10
                MsWhereAdi = MsWhereAdi & " AND apellidos Like '" & Replace(txtBusqueda(1), "/", " ") & "%'"
End Select
    End If
        
    If Trim(cboConcepto.Text) <> "" Then
        MsWhereAdi = MsWhereAdi & " AND concepto = " & cboConcepto.Text
    End If
    
    RenuevaDatos
End Sub
Private Sub TrabajarCon()
    Dim Aux As Variant
    Dim sClave As String  'trabajadorconceptosecuencia
    
    If sprDatos.ActiveRow < 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    sprDatos.GetText 1, sprDatos.ActiveRow, Aux
    sClave = sRellenar(Trim(Aux), " ", 0, 10)
    sprDatos.GetText 3, sprDatos.ActiveRow, Aux
    sClave = sClave & sRellenar(Trim(Aux), "0", 0, 5)
    sprDatos.GetText 4, sprDatos.ActiveRow, Aux
    sClave = sClave & sRellenar(Trim(Aux), "0", 0, 3)
    'Tag = sClave
    GsLlave = sClave
    FCO2020A.Caption = GsDsn & " / " & GsCveCia & " - Cambio de Embargo"
    FCO2020A.Show 1
    RenuevaDatos
End Sub

Private Sub OficinasEmbargos()
    Screen.MousePointer = vbHourglass
    FCO2020B.Caption = GsDsn & " / " & GsCveCia & " - Oficinas Embargos"
    FCO2020B.Show 1
    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 vw_fdt_embargos 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


