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 FCO1040 
   Caption         =   "Mto SUC"
   ClientHeight    =   4995
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   11265
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Sucursales.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   4995
   ScaleWidth      =   11265
   Begin FPSpread.vaSpread sprDatos 
      Height          =   4290
      Left            =   150
      TabIndex        =   0
      Top             =   120
      Width           =   10800
      _Version        =   131077
      _ExtentX        =   19050
      _ExtentY        =   7567
      _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  =   "Sucursales.frx":030A
   End
   Begin VB.Image imgLista 
      Height          =   480
      Left            =   10980
      Picture         =   "Sucursales.frx":0463
      Top             =   360
      Width           =   480
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   375
      Top             =   4500
      _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           =   "Sucursales.frx":076D
   End
End
Attribute VB_Name = "FCO1040"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private MoBitacora 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 MSOrder As String

Private MbOrdenAsc As Boolean
Private MsAntOrden As String

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

Private Sub abToolbar_PreCustomizeMenu(ByVal Cancel As ActiveBarLibraryCtl.ReturnBool)
    Cancel = True
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: GuardaCambios
        Case vbKeyF12: abToolbar.Bands(1).TrackPopup -1, -1
    End Select
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then imgLista_Click
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
        MiX = 11385
        MiY = 5400
        Me.Width = MiX
        Me.Height = MiY
    End If
    
    Caption = GsDsn & " / " & GsAbreviaturaCia & " - Sucursales de la compañia"
    AsignaIconos abToolbar, 3, LALTA, LBAJA, LORDENA, LRENUEVA, LGUARDA, LSALIDA
    ToolInicioGrupo abToolbar, 3, True, 2, 5
    
    MSOrder = " ORDER BY sucursal"
    CreaBitacora
    MsSql = "SELECT sucursal, codigo_iss, descripcion, direccion, cod_dpto, cod_ciudad, telefono, fax, " & _
    " nombre_retenedor, cedula_retenedor, agencias, autoliquida" & _
    " FROM vw_fco_sucursales WHERE compania='" & GsCveCia & "'"
    RenuevaDatos
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 iDeseaGuardar = vbCancel Then Cancel = True
    Set MAdo = Nothing
    Set MoBitacora = Nothing
    Set clsSpread = Nothing
    Gtc(Micx).ihijas = Gtc(Micx).ihijas - 1
    Set FCO1040 = Nothing
End Sub

Private Sub Form_Resize()
    sprDatos.Width = Width - 585
    sprDatos.Height = Height - 1215
    imgLista.Left = sprDatos.Left + sprDatos.Width + 40
End Sub

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

Private Sub imgLista_Click()
    If sprDatos.ActiveCol <> 5 And sprDatos.ActiveCol <> 6 Then Exit Sub
    Dim Aux As Variant
    
    GsParamIN(1) = "codigo"
    GsParamIN(2) = "nombre"
    GsParamIN(3) = "Codigo"
    GsParamIN(4) = "Nombre"
    GsParamIN(6) = ""
    Select Case sprDatos.ActiveCol
        Case 5
            GsParamIN(0) = "SELECT codigo, nombre" & _
            " FROM fco_departamentos WHERE 1=1"
            GsParamIN(5) = "Departamentos"
        Case 6
            sprDatos.GetText 5, sprDatos.ActiveRow, Aux
            GsParamIN(0) = "SELECT codigo, nombre" & _
            " FROM fco_ciudades" & _
            IIf(Trim(Aux) = "", " WHERE 1=1", " WHERE cod_dpto='" & Trim(Aux) & "'")
            GsParamIN(5) = "Municipios"
    End Select
    frmLista.Show 1
    If Trim(GsParamOUT(0)) <> "" Then
        With sprDatos
            .Col = .ActiveCol
            .Row = .ActiveRow
            .Text = GsParamOUT(0)
        End With
        MoBitacora.mCambia
    End If
End Sub

Private Sub sprDatos_Change(ByVal Col As Long, ByVal Row As Long)
    MoBitacora.mCambia
End Sub

Private Sub sprDatos_Click(ByVal Col As Long, ByVal Row As Long)
    If Col = 12 Then MoBitacora.mCambia
End Sub

Private Sub Altas()
    'MoBitacora.mAgrega /* para evitar confusiones, jcl, julio 9/06 */
    Dim sAgr As String
    Dim sDes As String
    Dim bValida As Boolean
    
    bValida = True
    sAgr = sParametroFDT(MAdo, "autoliq", "COL", 23)
    If sAgr = "" Then
        bValida = False
    Else
        MAdo.Sql = "SELECT 1 FROM rel_agr_companias WHERE compania = '" & GsCveCia & "' AND agrupacion = '" & sAgr & "'"
        MAdo.SendSQL
        If MAdo.EOF Then bValida = False
    End If
    
    If Not bValida Then
        clsMsgbox.Mensaje "La compañía no maneja sucursales, si desea activar el uso de sucursales, específique un dato válido en la secuencia 23 de los parámetros de autoliquidación", mAceptar, minforma, GsTitMsg
    Else
        MAdo.Sql = "SELECT descripcion FROM agrupaciones_trab WHERE agrupacion = '" & sAgr & "'"
        MAdo.SendSQL
        If Not MAdo.EOF Then
            sDes = Trim("" & MAdo.GetField(1))
        End If
        clsMsgbox.Mensaje "Para crear una nueva sucursal, primero debe agregarla como un dato de la agrupación " & vbCrLf & sAgr & " - """ & sDes & """" & vbCrLf & "y aparecerá automáticamente aquí para complementar su información", mAceptar, minforma, GsTitMsg
    End If
End Sub

Private Sub Bajas()
'    If sprDatos.VirtualMaxRows <= 0 Then Exit Sub
'    MoBitacora.mBorra
    Dim sAgr As String
    Dim sDes As String
    Dim bValida As Boolean
    
    bValida = True
    sAgr = sParametroFDT(MAdo, "autoliq", "COL", 23)
    If sAgr = "" Then
        bValida = False
    Else
        MAdo.Sql = "SELECT 1 FROM rel_agr_companias WHERE compania = '" & GsCveCia & "' AND agrupacion = '" & sAgr & "'"
        MAdo.SendSQL
        If MAdo.EOF Then bValida = False
    End If
    
    If Not bValida Then
        clsMsgbox.Mensaje "La compañía no maneja sucursales, si desea activar el uso de sucursales, específique un dato válido en la secuencia 23 de los parámetros de autoliquidación", mAceptar, minforma, GsTitMsg
    Else
        MAdo.Sql = "SELECT descripcion FROM agrupaciones_trab WHERE agrupacion = '" & sAgr & "'"
        MAdo.SendSQL
        If Not MAdo.EOF Then
            sDes = Trim("" & MAdo.GetField(1))
        End If
        clsMsgbox.Mensaje "Para eliminar una sucursal, primero debe eliminarla de los datos de la agrupación " & vbCrLf & sAgr & " - """ & sDes & """" & vbCrLf & vbCrLf & "También puede quitarle el check de autoliquida para no incluirla en procesos de autoliquidación ni planilla integrada", mAceptar, minforma, GsTitMsg
    End If
End Sub

Private Sub ConfiguraSpread()
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
        .ColWidth(1) = 4
        .ColWidth(2) = 4
        .ColWidth(3) = 15
        .ColWidth(4) = 10
        .ColWidth(5) = 4
        .ColWidth(6) = 5
        .ColWidth(7) = 9
        .ColWidth(8) = 9
        .ColWidth(9) = 25
        .ColWidth(10) = 15
        .ColWidth(11) = 25
        .ColWidth(12) = 8
        .SetText 1, 0, "Cod."
        .SetText 2, 0, "ISS"
        .SetText 3, 0, "Descripcion"
        .SetText 4, 0, "Direccion"
        .SetText 5, 0, "Dpto"
        .SetText 6, 0, "Ciudad"
        .SetText 7, 0, "Telefono"
        .SetText 8, 0, "Fax"
        .SetText 9, 0, "Nombre Retenedor"
        .SetText 10, 0, "Cedula Retenedor"
        .SetText 11, 0, "Agencias o Sucursales"
        .SetText 12, 0, "Autoliquida"
        ConfiguraSpreadJCL sprDatos
    End With
End Sub

Private Sub CreaBitacora()
   MoBitacora.mCreaBitacora sprDatos, MAdo.lhEnv, MAdo.lhDbc, MAdo.lhstmt, MAdo
   MoBitacora.p_ConfirmaBaja = True
   MoBitacora.mDefineLlave 1
   'MoBitacora.mTablaSPInfo 0, "sp_fco_alta_sucursales", "'" & GsCveCia & "'", 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 2
   'MoBitacora.mTablaSPInfo 1, "sp_fco_baja_sucursales", "'" & GsCveCia & "'", 1
   MoBitacora.mTablaSPInfo 2, "sp_fco_cambio_sucursales", "'" & GsCveCia & "'", 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 2, 12
   MoBitacora.mColNoNulls 1, 2
End Sub

Private Sub GuardaCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    GbRen = MoBitacora.mActualizaBD
    MoBitacora.mVaciaBuffer
    Screen.MousePointer = vbDefault
End Sub

Private Function iDeseaGuardar() 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 MoBitacora.pTransActual > 0 Then
       iDeseaGuardar = clsMsgbox.Mensaje("¿Desea guardar los cambios?", mSiNoCancelar, mConfirma, GsTitMsg)
       Select Case iDeseaGuardar
          Case vbYes
             GuardaCambios
             If GbRen = 0 Then iDeseaGuardar = 2
          Case vbNo
             MoBitacora.mVaciaBuffer 'Vacía el Buffer de la Bitácora
       End Select
    Else
        iDeseaGuardar = 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()
    If iDeseaGuardar = vbCancel Then Exit Sub
    ConfiguraSpread
    MAdo.Sql = MsSql & MSOrder
    If Not MAdo.SendSQL Then Exit Sub
    clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
    With sprDatos
        .Row = -1
        .Col = 1: .TypeEditLen = 10: .Lock = True
        .Col = 2: .TypeEditLen = 3
        .Col = 5: .TypeEditLen = 2
        .Col = 6: .TypeEditLen = 3
        .Col = 12: .CellType = 10
        .ScrollBars = ScrollBarsBoth
    End With
End Sub
