VERSION 5.00
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_mantenedor_factoring 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Factoring"
   ClientHeight    =   4920
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   6345
   Icon            =   "Form_mantenedor_factoring.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4920
   ScaleWidth      =   6345
   Begin VB.Frame Frame1 
      Caption         =   "Listado de factoring"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   4575
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6015
      Begin VB.CommandButton Command5 
         Caption         =   "Salir"
         Height          =   375
         Left            =   4560
         TabIndex        =   11
         Top             =   3960
         Width           =   1215
      End
      Begin VB.CommandButton cmd_eliminar 
         Caption         =   "Eliminar"
         Height          =   375
         Left            =   3120
         TabIndex        =   10
         Top             =   3960
         Width           =   1215
      End
      Begin VB.CommandButton cmd_modificar 
         Caption         =   "Modificar"
         Height          =   375
         Left            =   1680
         TabIndex        =   9
         Top             =   3960
         Width           =   1215
      End
      Begin VB.CommandButton cmd_insertar 
         Caption         =   "Insertar"
         Height          =   375
         Left            =   240
         TabIndex        =   8
         Top             =   3960
         Width           =   1215
      End
      Begin VB.Frame Frame_cajas 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   2055
         Left            =   960
         TabIndex        =   1
         Top             =   1200
         Visible         =   0   'False
         Width           =   4215
         Begin VB.CommandButton cmd_cancelar 
            Caption         =   "Cancelar"
            Height          =   375
            Left            =   2280
            TabIndex        =   5
            Top             =   1440
            Width           =   1095
         End
         Begin VB.CommandButton cmd_aceptar 
            Caption         =   "Aceptar"
            Height          =   375
            Left            =   840
            TabIndex        =   4
            Top             =   1440
            Width           =   1095
         End
         Begin VB.TextBox txt_folio_final 
            Height          =   285
            Left            =   1200
            TabIndex        =   3
            Top             =   960
            Width           =   2775
         End
         Begin VB.TextBox txt_folio_inicial 
            Height          =   285
            Left            =   1200
            Locked          =   -1  'True
            TabIndex        =   2
            Top             =   480
            Width           =   1575
         End
         Begin VB.Label Label4 
            Caption         =   "Factoring"
            Height          =   255
            Left            =   120
            TabIndex        =   7
            Top             =   960
            Width           =   855
         End
         Begin VB.Label Label3 
            Caption         =   "Folio"
            Height          =   255
            Left            =   120
            TabIndex        =   6
            Top             =   480
            Width           =   855
         End
      End
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid grid_cajas 
         Height          =   3375
         Left            =   240
         TabIndex        =   12
         Top             =   360
         Width           =   5505
         _ExtentX        =   9710
         _ExtentY        =   5953
         _Version        =   393216
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         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
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
End
Attribute VB_Name = "Form_mantenedor_factoring"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cmd_Aceptar_Click()
    Dim Mensaje As String
    Dim Folio As Long
    Dim folio_inicial As Long
    Dim folio_final As Long
    
'    folio_inicial = val(grid_cajas.TextMatrix(grid_cajas.Row, 2))
'    folio_final = val(grid_cajas.TextMatrix(grid_cajas.Row, 3))
'    Folio = Mid(cb_cajas, 6)
    
    If Frame_cajas.Caption = "Ingresar Caja" Then
'        var_sql = "insert into fnza_cajas_folios(folio,folio_inicial,folio_final,activo)" _
'                & " values(" & Folio & "," & txt_folio_inicial.Text & "," & txt_folio_final.Text & ",'NO')"
        var_sql = "INSERT INTO fnza_factoring(cod_fac,factoring) VALUES(" & txt_folio_inicial.Text & ",'" & txt_folio_final.Text & "');"
        Mensaje = "El factoring ha sido ingresado satisfactoriamente"
    Else
'        var_sql = "update fnza_cajas_folios set folio_inicial = " & txt_folio_inicial.Text & ",folio_final = " & txt_folio_final.Text & " where" _
'                & " folio = " & Folio & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
        var_sql = "UPDATE fnza_factoring SET factoring = '" & txt_folio_final.Text & "' WHERE cod_fac = " & txt_folio_inicial.Text
        Mensaje = "El factoring ha sido modificado satisfactoriamente"
    End If
        
    conn.Execute var_sql
    
    Frame_cajas.Visible = False
    
    Form_Load
    MsgBox Mensaje, vbInformation
    
    
End Sub

Private Sub cmd_Cancelar_Click()
    Frame_cajas.Visible = False
End Sub

Private Sub cmd_eliminar_Click()
    Dim Folio As Long
    Dim total As Long


    total = DevuelveCampo("fnza_cheques_recibidos", "", "COUNT(*) AS total", "cod_factoring = " & grid_cajas.TextMatrix(grid_cajas.Row, 1) & "", conn)
    
    If total = 0 Then
        var_sql = "DELETE FROM fnza_factoring WHERE cod_fac = " & grid_cajas.TextMatrix(grid_cajas.Row, 1) & ";"
        conn.Execute var_sql
        Form_Load
        MsgBox "El factoring ha sido eliminado satisfactoriamente", vbInformation
    Else
        MsgBox "No es posible eliminar el Factoring porque hay cheques relacionados a este.", vbInformation
    End If

End Sub

Private Sub cmd_insertar_Click()
    txt_folio_inicial.Text = DevuelveCampo("fnza_factoring", "", "(MAX(cod_fac) + 1) AS fac", "1=1", conn)
    'txt_folio_inicial.Locked = True
    txt_folio_final.Text = ""
    Frame_cajas.Caption = "Ingresar Caja"
    Frame_cajas.Visible = True
End Sub

Private Sub cmd_modificar_Click()
    Dim Folio As Long
    Dim folio_inicial As Long
    Dim folio_final As Long
    'Folio = Mid(cb_cajas, 6)
    txt_folio_inicial = grid_cajas.TextMatrix(grid_cajas.Row, 1)
    txt_folio_final = grid_cajas.TextMatrix(grid_cajas.Row, 2)
    
    Frame_cajas.Caption = "Modificar Caja"
    Frame_cajas.Visible = True
End Sub

'''''Private Sub Command1_Click()
'''''    Dim i As Integer
'''''    Dim j As Integer
'''''    Dim objRS As ADODB.Recordset
'''''    Set objRS = New ADODB.Recordset
'''''    Dim var_sql As String
'''''    var_sql = "SELECT concat('Caja ',caja) as caja,folio_inicial,folio_final,activo,cf.folio FROM fnza_cajas as c,fnza_cajas_folios cf where c.folio = cf.folio and caja = " & Mid(cb_cajas, 6)
'''''    objRS.Open var_sql, conn
'''''    grid_cajas.Clear
'''''    grid_cajas.Rows = 2
'''''    If objRS.RecordCount > 0 Then
'''''    Call Rec2Grid(objRS, grid_cajas, True)
'''''    'grid_cajas.ColWidth(5) = 0
'''''
''''''    For j = 1 To grid_cajas.Rows - 1
''''''        For i = 1 To grid_cajas.Cols - 1
''''''            If grid_cajas.TextMatrix(j, 4) = "SI" Then
''''''                grid_cajas.Row = j
''''''                grid_cajas.Col = i
''''''                grid_cajas.CellBackColor = vbGreen
''''''                'grid_cajas.CellAlignment = flexAlignCenterCenter
''''''            End If
''''''        Next i
''''''    Next j
'''''    End If
'''''    objRS.Close
'''''
'''''End Sub

Private Sub Command5_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Dim I As Integer
    Dim j As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    var_sql = "SELECT * FROM fnza_factoring ORDER BY cod_fac"
    objRS.Open var_sql, conn
    grid_cajas.Clear
    grid_cajas.Rows = 2
    If objRS.RecordCount > 0 Then
        Call Rec2Grid(objRS, grid_cajas, True)
    End If
    objRS.Close
End Sub

Private Sub Rec2Grid(ByRef rec As ADODB.Recordset, ByRef grid As Object, Optional ByVal Numeracion As Boolean = True)
    grid.ClearStructure
    If rec.RecordCount > 0 Then
        grid.Cols = rec.Fields.count + 1
        grid.Rows = rec.RecordCount + 1
        grid.FixedCols = 1
        grid.FixedRows = 1
        grid.TextMatrix(0, 0) = "Nš"
        grid.ColWidth(0) = IIf(Numeracion, TextWidth(grid.TextMatrix(0, 0)) + 100, 0)
        For I = 1 To rec.Fields.count
            grid.TextMatrix(0, I) = UCase(rec.Fields(I - 1).Name)
            grid.ColWidth(I) = TextWidth(grid.TextMatrix(0, I)) + 100
        Next I
        rec.MoveFirst
        For I = 1 To rec.RecordCount
            grid.TextMatrix(I, 0) = I
            grid.ColWidth(0) = IIf(Numeracion, IIf(TextWidth(grid.TextMatrix(I, 0)) + 100 > grid.ColWidth(0), TextWidth(grid.TextMatrix(I, 0)) + 100, grid.ColWidth(0)), 0)
            For j = 1 To rec.Fields.count
                grid.TextMatrix(I, j) = IIf(IsNull(rec(j - 1)), "Null", rec(j - 1))
                grid.ColWidth(j) = IIf(TextWidth(grid.TextMatrix(I, j)) + 100 > grid.ColWidth(j), TextWidth(grid.TextMatrix(I, j)) + 100, grid.ColWidth(j))
            Next j
            rec.MoveNext
        Next I
    Else
        grid.Cols = 2
        grid.Rows = 2
    End If
End Sub

'Private Sub grid_cajas_DblClick()
'    Dim Folio As Long
'    Dim folio_inicial As Long
'    Dim folio_final As Long
'    Dim var_sql As String
'    Dim activo As String
'
'    Folio = grid_cajas.TextMatrix(grid_cajas.Row, 5)
'    folio_inicial = grid_cajas.TextMatrix(grid_cajas.Row, 2)
'    folio_final = grid_cajas.TextMatrix(grid_cajas.Row, 3)
'    activo = grid_cajas.TextMatrix(grid_cajas.Row, 4)
'
'    If activo = "SI" Then
'        var_sql = "update fnza_cajas_folios set activo = 'NO' where folio = " & Folio _
'                & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
'    Else
'        var_sql = "update fnza_cajas_folios set activo = 'SI' where folio = " & Folio _
'                & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
'    End If
'
''    var_sql = "update fnza_cajas_folios set activo = 'NO' where folio = " & Folio
''    conn.Execute var_sql
''
''    var_sql = "update fnza_cajas_folios set activo = 'SI' where folio = " & Folio _
''            & " and folio_inicial >= " & folio_inicial & " and folio_final <= " & folio_final
'    conn.Execute var_sql
'
'    Command1_Click
'
'    MsgBox "La caja " & cb_cajas.Text & " con rango de folios de " & folio_inicial & " hasta " & folio_final & " a sido activada"
'End Sub


