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 FCO5010T 
   Caption         =   "Datos Adicionales a los Reportes"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6015
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "ProcesoReportes_T.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   3195
   ScaleWidth      =   6015
   StartUpPosition =   3  'Windows Default
   Begin FPSpread.vaSpread sprDatos 
      Bindings        =   "ProcesoReportes_T.frx":030A
      Height          =   2505
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5775
      _Version        =   131077
      _ExtentX        =   10186
      _ExtentY        =   4419
      _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  =   "ProcesoReportes_T.frx":0320
   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           =   "ProcesoReportes_T.frx":0479
   End
End
Attribute VB_Name = "FCO5010T"
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 MiX As Integer 'Ancho de la forma
Private MiY As Integer 'Alta de la forma

Private MsSql As String
Private MbRenovar As Boolean
Private MsEsNulo As String

Private MbOrdenAsc As Boolean
Private MsAntOrden 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": GuardaCambios
        Case "tlsalida": Unload Me
    End Select
End Sub

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

End Sub

Private Sub Form_Load()
    GbAError = False
    Me.Tag = GiVenMax%
    Gven(Val(Me.Tag)).icx = Gicx%
    MiCx = Gven(Val(Me.Tag)).icx
    Set Mado = Gtc(MiCx).Ado
    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 = 6135
        MiY = 3600
        Me.Width = MiX
        Me.Height = MiY
    End If

    Caption = GsDsn & " / " & GsCveCia & " - A.L.A. Datos Adicionales"
    AsignaIconos abToolbar, 3, LGUARDA, LSALIDA
    If Left(UCase(GsDsn), 3) = "ORA" Then
        MsEsNulo = "Nvl"
    Else
        MsEsNulo = "IsNull"
    End If
    
    If Mado.DBMS = "SQLSERVER" Then
        MsSql = " SELECT item,  CASE signo WHEN '-1' THEN ' -' ELSE ' +' END as signo, causa, Max(referencia) referencia," & _
        " Sum(valor_1) valor_1, Sum(valor_2) valor_2, Sum(valor_3) valor_3" & _
        " FROM vw_fco_ala_datos_adi" & _
        " WHERE sgss=" & GnSGSS & " AND RTrim(tabla) IN ('0', '" & Trim(GsTabla) & "')" & _
        " AND RTrim(cod_adm) IN ('0','" & Trim(GsAdmin) & "') " & _
        IIf(Trim(GsCodDato) = "", "", " AND " & MsEsNulo & "(RTrim(cod_suc)" & IIf(Left(UCase(GsDsn), 3) = "ORA", "||", "+") & "'0','0') IN ('00','" & Trim(GsCodDato) & "0')") & _
        " GROUP BY item, signo, causa" & _
        " ORDER BY Max(secuencia)"
    Else 'La consulta anterior no es válida en Oracle 8
        MsSql = " SELECT item,  DECODE(signo, '-1', ' -', ' +') AS signo, causa, Max(referencia) referencia," & _
        " Sum(valor_1) valor_1, Sum(valor_2) valor_2, Sum(valor_3) valor_3" & _
        " FROM vw_fco_ala_datos_adi" & _
        " WHERE sgss=" & GnSGSS & " AND RTrim(tabla) IN ('0', '" & Trim(GsTabla) & "')" & _
        " AND RTrim(cod_adm) IN ('0','" & Trim(GsAdmin) & "') " & _
        IIf(Trim(GsCodDato) = "", "", " AND " & MsEsNulo & "(RTrim(cod_suc)" & IIf(Left(UCase(GsDsn), 3) = "ORA", "||", "+") & "'0','0') IN ('00','" & Trim(GsCodDato) & "0')") & _
        " GROUP BY item, signo, causa" & _
        " ORDER BY Max(secuencia)"
    End If
    
    'Decimales según panel de control
    MiNumDecimales = iNumeroDecimalesImporte
    
    CreaBitacora
    RenuevaDatos
    Screen.MousePointer = vbDefault
End Sub

Private Sub ConfiguraSpread()
    sprDatos.VisibleCols = 6
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
        .Row = 0
        .Col = 1: .Text = "Item oculto"
        .Col = 2: .Text = " ": .DataFillEvent = True
        .Col = 3: .Text = "Descripcion"
        .Col = 4: .Text = "Nro/Doc"
        .Col = 5: .Text = "Valor"
        .Visible = True
    End With
End Sub

Private Sub CreaBitacora()
   MBitacora.mCreaBitacora sprDatos, Mado.lhEnv, Mado.lhDbc, Mado.lhstmt, Mado
   MBitacora.p_ConfirmaBaja = True
   MBitacora.mTablaSPInfo 2, "sp_fco_cambio_ala_datos_adi", "'" & GsTabla & "'", CStr(GnSGSS), "'" & GsAdmin & "'", "'" & GsCodDato & "'", 1, 4, 5, 6, 7
   MBitacora.mColNoNulls 2
End Sub

Private Sub RenuevaDatos()
    On Error Resume Next
    ConfiguraSpread
    
    Mado.Sql = MsSql
    If Not Mado.SendSQL Then Exit Sub
    clsSpread.LlenaSpread 0, sprDatos, Mado, Mado.lhDbc, Mado.lhstmt
    
    With sprDatos
        .Row = 0
        .Col = 1: .ColHidden = True
        .ColWidth(2) = 3
        If GnSGSS = Salud Or GnSGSS = Riesgos Then
            .ColWidth(3) = 24
            .ColWidth(4) = 10
            .ColWidth(5) = 10.5
            .Col = 6: .ColHidden = True
            .Col = 7: .ColHidden = True
            .Col = 5: .Row = -1:  .CellType = 2: .TypeFloatSeparator = True:
                      .TypeFloatDecimalPlaces = MiNumDecimales: .TypeFloatMax = "99999999999999999": .TypeFloatMin = "0.00"
        Else
            If GnSGSS = ISS_Consolidado Then
                .ColWidth(3) = 1
                .ColWidth(3) = 14.9
                .ColWidth(4) = 5.4
                .ColWidth(5) = 8
                .ColWidth(6) = 8
                .ColWidth(7) = 8
                .Col = 5: .Text = "Pension"
                .Col = 6: .Text = "Salud"
                .Col = 7: .Text = "Riesgos"
                .Col = 5: .Row = -1:  .CellType = 2: .TypeFloatSeparator = True:
                          .TypeFloatDecimalPlaces = MiNumDecimales: .TypeFloatMax = "99999999999999999": .TypeFloatMin = "0.00"
                .Col = 6: .Row = -1:  .CellType = 2: .TypeFloatSeparator = True:
                          .TypeFloatDecimalPlaces = MiNumDecimales: .TypeFloatMax = "99999999999999999": .TypeFloatMin = "0.00"
                .Col = 7: .Row = -1:  .CellType = 2: .TypeFloatSeparator = True:
                          .TypeFloatDecimalPlaces = MiNumDecimales: .TypeFloatMax = "99999999999999999": .TypeFloatMin = "0.00"
            Else
                .ColWidth(3) = 17.1
                .ColWidth(4) = 9
                .ColWidth(5) = 9.1
                .ColWidth(6) = 9.1
                .Col = 5: .Text = "Pension"
                .Col = 6: .Text = IIf(GnSGSS = Pensiones, "F.S.P", "Salud")
                .Col = 5: .Row = -1:  .CellType = 2: .TypeFloatSeparator = True:
                          .TypeFloatDecimalPlaces = MiNumDecimales: .TypeFloatMax = "99999999999999999": .TypeFloatMin = "0.00"
                .Col = 6: .Row = -1:  .CellType = 2: .TypeFloatSeparator = True:
                          .TypeFloatDecimalPlaces = MiNumDecimales: .TypeFloatMax = "99999999999999999": .TypeFloatMin = "0.00"
                
                .Col = 7: .ColHidden = True
            End If
        End If
        .Col = 2: .Row = -1: .Lock = True
        .Col = 3: .Row = -1: .Lock = True
        .Col = 4: .Row = -1: .TypeEditLen = 20
        .Row = 1: .Action = 0
        .ScrollBars = ScrollBarsBoth
    End With
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If iDeseaGuardarCambios = 2 Then Cancel = True
    Set Mado = Nothing
    Set MBitacora = Nothing
    Set clsSpread = Nothing
    Gtc(MiCx).ihijas = Gtc(MiCx).ihijas - 1
    Set FCO5010T = Nothing
    
End Sub

Private Sub sprDatos_Change(ByVal Col As Long, ByVal Row As Long)
    MBitacora.mCambia
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, IIf(Val(Aux) = 1, "  +", "  -")
            Cancel = True
    End Select
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 GuardaCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    MbRenovar = MBitacora.mActualizaBD
    MBitacora.mVaciaBuffer
    Screen.MousePointer = vbDefault
    Unload Me
End Sub

