VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form_ManejoCajas 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Manejo de Cajas"
   ClientHeight    =   5970
   ClientLeft      =   2580
   ClientTop       =   3120
   ClientWidth     =   8115
   ForeColor       =   &H00000000&
   Icon            =   "Form_ManejoCajas.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   5970
   ScaleWidth      =   8115
   Begin VB.CommandButton Command7 
      Caption         =   "Editar Caja"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   1560
      TabIndex        =   17
      Top             =   5280
      Width           =   1215
   End
   Begin VB.CommandButton Command4 
      Caption         =   "Asignar Folios"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   120
      TabIndex        =   11
      Top             =   5280
      Width           =   1215
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Otra Caja"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   5280
      TabIndex        =   7
      Top             =   5280
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Cerrar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   6720
      TabIndex        =   3
      Top             =   5280
      Width           =   1215
   End
   Begin VB.Frame Frame2 
      ForeColor       =   &H00FF0000&
      Height          =   1455
      Left            =   3120
      TabIndex        =   1
      Top             =   120
      Width           =   4815
      Begin VB.TextBox Text3 
         BackColor       =   &H8000000F&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   960
         Locked          =   -1  'True
         TabIndex        =   13
         Text            =   "Text3"
         Top             =   960
         Width           =   3735
      End
      Begin VB.TextBox Text2 
         BackColor       =   &H8000000F&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   960
         Locked          =   -1  'True
         TabIndex        =   12
         Text            =   "Text2"
         Top             =   600
         Width           =   3735
      End
      Begin VB.TextBox Text1 
         BackColor       =   &H8000000F&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   960
         Locked          =   -1  'True
         TabIndex        =   8
         Text            =   "Text1"
         Top             =   240
         Width           =   3735
      End
      Begin VB.Label Label3 
         Caption         =   "Colegio"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   14
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label2 
         Caption         =   "Ubicación"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   10
         Top             =   960
         Width           =   855
      End
      Begin VB.Label Label1 
         Caption         =   "Cajero"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   9
         Top             =   240
         Width           =   855
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Caja Seleccionada"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1455
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   2895
      Begin VB.OptionButton Option2 
         Caption         =   "PreKinder"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   1080
         TabIndex        =   16
         Top             =   360
         Width           =   1095
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Colegio"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   195
         Left            =   120
         TabIndex        =   15
         Top             =   360
         Value           =   -1  'True
         Width           =   855
      End
      Begin VB.ComboBox Combo1 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   120
         Style           =   2  'Dropdown List
         TabIndex        =   5
         Top             =   840
         Width           =   1695
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Ver"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   615
         Left            =   1920
         Picture         =   "Form_ManejoCajas.frx":2A8B2
         Style           =   1  'Graphical
         TabIndex        =   4
         Top             =   720
         Width           =   855
      End
   End
   Begin VB.Frame Frame5 
      Caption         =   "Asignar Folios"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   3495
      Left            =   120
      TabIndex        =   18
      Top             =   1680
      Visible         =   0   'False
      Width           =   7815
      Begin VB.TextBox Text8 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1200
         TabIndex        =   22
         Text            =   "Text8"
         Top             =   1080
         Width           =   1815
      End
      Begin VB.TextBox Text9 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   4440
         TabIndex        =   21
         Text            =   "Text9"
         Top             =   1080
         Width           =   1815
      End
      Begin VB.CommandButton Command8 
         Caption         =   "Guardar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   240
         TabIndex        =   20
         Top             =   2760
         Width           =   1215
      End
      Begin VB.CommandButton Command9 
         Caption         =   "Cancelar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   6360
         TabIndex        =   19
         Top             =   2760
         Width           =   1215
      End
      Begin VB.Label Label10 
         Caption         =   "NO"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3240
         TabIndex        =   36
         Top             =   2880
         Visible         =   0   'False
         Width           =   375
      End
      Begin VB.Label Label8 
         Alignment       =   2  'Center
         Caption         =   "Folio Inicial"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   1200
         TabIndex        =   24
         Top             =   720
         Width           =   1815
      End
      Begin VB.Label Label9 
         Alignment       =   2  'Center
         Caption         =   "Folio Inicial"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   4440
         TabIndex        =   23
         Top             =   720
         Width           =   1815
      End
   End
   Begin VB.Frame Frame4 
      Caption         =   "Datos Caja"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   3495
      Left            =   120
      TabIndex        =   25
      Top             =   1680
      Visible         =   0   'False
      Width           =   7815
      Begin VB.TextBox Text4 
         Appearance      =   0  'Flat
         BackColor       =   &H8000000F&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2280
         Locked          =   -1  'True
         TabIndex        =   31
         Text            =   "Text4"
         Top             =   480
         Width           =   5055
      End
      Begin VB.TextBox Text5 
         Appearance      =   0  'Flat
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2280
         MaxLength       =   10
         TabIndex        =   30
         Text            =   "Text5"
         Top             =   1080
         Width           =   5055
      End
      Begin VB.TextBox Text6 
         Appearance      =   0  'Flat
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2280
         MaxLength       =   100
         TabIndex        =   29
         Text            =   "Text6"
         Top             =   1560
         Width           =   5055
      End
      Begin VB.TextBox Text7 
         Appearance      =   0  'Flat
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2280
         MaxLength       =   100
         TabIndex        =   28
         Text            =   "Text7"
         Top             =   2160
         Width           =   5055
      End
      Begin VB.CommandButton Command5 
         Caption         =   "Guardar Caja"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   240
         TabIndex        =   27
         Top             =   2760
         Width           =   1215
      End
      Begin VB.CommandButton Command6 
         Caption         =   "Cancelar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   6360
         TabIndex        =   26
         Top             =   2760
         Width           =   1215
      End
      Begin VB.Label Label4 
         Caption         =   "Colegio"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   35
         Top             =   480
         Width           =   1815
      End
      Begin VB.Label Label5 
         Caption         =   "Nombre de la Caja"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   34
         Top             =   1080
         Width           =   1815
      End
      Begin VB.Label Label6 
         Caption         =   "Nombre del Cajero"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   33
         Top             =   1680
         Width           =   1815
      End
      Begin VB.Label Label7 
         Caption         =   "Ubicación"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   32
         Top             =   2280
         Width           =   1815
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Boletas Asignadas"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   3495
      Left            =   120
      TabIndex        =   2
      Top             =   1680
      Width           =   7815
      Begin MSFlexGridLib.MSFlexGrid Grilla 
         Height          =   3135
         Left            =   120
         TabIndex        =   6
         Top             =   240
         Width           =   7575
         _ExtentX        =   13361
         _ExtentY        =   5530
         _Version        =   393216
         FixedCols       =   0
         AllowBigSelection=   0   'False
         ScrollTrack     =   -1  'True
         FocusRect       =   0
         ScrollBars      =   2
         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
      End
   End
End
Attribute VB_Name = "Form_ManejoCajas"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
    Unload Me
End Sub

Private Sub Command2_Click()
    Dim colegio As String
        
    If Combo1.Text = "" Then Exit Sub
    If Combo1.Text = "Agregar Caja" Then
        If Option1.Value = True Then
            colegio = RetornaCampo("CFG", "valor", "param='CODBC'", conn)
        Else
            colegio = RetornaCampo("CFG", "valor", "param='CODPK'", conn)
        End If
        Frame1.Enabled = False
        Frame3.Visible = False
        Frame4.Visible = True
        Frame5.Visible = False
        Command4.Enabled = False
        Command7.Enabled = False
        Text4.Text = RetornaCampo("hist_cod_colegio", "nombre", "colegio='" & colegio & "'", conn)
    Else
        Frame1.Enabled = False
        Frame3.Visible = True
        Frame4.Visible = False
        Frame5.Visible = False
        Command4.Enabled = True
        Command7.Enabled = True
        Llena_Datos_Caja
        Setea_Grilla
        llena_grilla
    End If
End Sub

Private Sub Command3_Click()
    Frame1.Enabled = True
    Frame3.Visible = True
    Frame4.Visible = False
    Frame5.Visible = False
    Call Form_Load
End Sub

Private Sub Command4_Click()
    Frame1.Enabled = False
    Frame3.Visible = False
    Frame4.Visible = False
    Frame5.Visible = True
    Text8.Text = ""
    Text9.Text = ""
    Text8.SetFocus
    Command4.Enabled = False
    Command7.Enabled = False
    Label10.Caption = "NO"
End Sub

Private Sub Command5_Click()
    Dim colegio As String
    Dim NUEVO As Boolean
    Dim FolioCaja As Long
    Dim QRY As String
    
    If Trim(Text5.Text) = "" Or Trim(Text6.Text) = "" Or Trim(Text7.Text) = "" Then Exit Sub
    
    If Option1.Value = True Then
        colegio = RetornaCampo("CFG", "valor", "param='CODBC'", conn)
    Else
        colegio = RetornaCampo("CFG", "valor", "param='CODPK'", conn)
    End If
    NUEVO = IIf((Combo1.Text = "Agregar Caja"), True, False)
    
    If Not NUEVO Then
        FolioCaja = Val(RetornaCampo("fnza_caja", "folio_caja", "nombre='" & Combo1.Text & "' AND colegio='" & colegio & "'", conn))
        QRY = "UPDATE fnza_caja SET nombre='" & Trim(Text5.Text) & "', cajero='" & Trim(Text6.Text) & "', ubicacion='" & Trim(Text7.Text) & "' WHERE folio_caja=" & FolioCaja & " LIMIT 1;"
    Else
        QRY = "INSERT fnza_caja(colegio,nombre,cajero,ubicacion) VALUES('" & colegio & "','" & Trim(Text5.Text) & "','" & Trim(Text6.Text) & "','" & Trim(Text7.Text) & "') ON DUPLICATE KEY UPDATE cajero='" & Trim(Text6.Text) & "',ubicacion='" & Trim(Text7.Text) & "'"
    End If
    conn.Execute QRY
    
    Call Command6_Click
End Sub

Private Sub Command6_Click()
    Dim NUEVO As Boolean
    NUEVO = IIf((Combo1.Text = "Agregar Caja"), True, False)
    If NUEVO Then
        Call Command3_Click
    Else
        Call Command2_Click
    End If
End Sub

Private Sub Command7_Click()
    Frame1.Enabled = False
    Frame3.Visible = False
    Frame4.Visible = True
    Frame5.Visible = False
    Command4.Enabled = False
    Command7.Enabled = False
    Text5.Text = Combo1.Text
    Text6.Text = Text1.Text
    Text7.Text = Text3.Text
End Sub

Private Sub Command8_Click()
    ' INSERTAR FOLIOS
    Dim Editando As Boolean
    Dim colegio As String
    Dim FolioCaja As Long
    Dim QRY As String
    Dim VERIF As Long
    
    
    
    If Not (Val(Text8.Text) > 0 And Val(Text9.Text) > 0 And Val(Text9.Text) >= Val(Text8.Text)) Then
        MsgBox "Error en el valor de los folios." & vbCrLf & "Reviselos por favor.", vbCritical, "Error de Validación"
        Exit Sub
    End If
    
    Editando = IIf((Label10.Caption = "SI"), True, False)
    
    If Not (Editando = True And Val(grilla.TextMatrix(grilla.Row, 1)) = Val(Text8.Text)) Then
        If Editando Then
            VERIF = Val(RetornaCampo("fnza_caja_folios", "count(folio_asig) as err", "folio_ini<=" & Text9.Text & " AND folio_fin>=" & Text8.Text & " and folio_asig<>" & grilla.TextMatrix(grilla.Row, 5), conn))
        Else
            VERIF = Val(RetornaCampo("fnza_caja_folios", "count(folio_asig) as err", "folio_ini<=" & Text9.Text & " AND folio_fin>=" & Text8.Text, conn))
        End If
        If VERIF > 0 Then
            MsgBox "Folios Iniciales están siendo ocupados", vbCritical, "Error"
            Exit Sub
        End If
    End If
    If Not (Editando = True And Val(grilla.TextMatrix(grilla.Row, 2)) = Val(Text9.Text)) Then
        If Editando Then
            VERIF = Val(RetornaCampo("fnza_caja_folios", "count(folio_asig) as err", "folio_ini<=" & Text9.Text & " AND folio_fin>=" & Text9.Text & " and folio_asig<>" & grilla.TextMatrix(grilla.Row, 5), conn))
        Else
            VERIF = Val(RetornaCampo("fnza_caja_folios", "count(folio_asig) as err", "folio_ini<=" & Text9.Text & " AND folio_fin>=" & Text9.Text, conn))
        End If
        If VERIF > 0 Then
            MsgBox "Folios finales están siendo ocupados", vbCritical, "Error"
            Exit Sub
        End If
    End If
    
    If Option1.Value = True Then
        colegio = RetornaCampo("CFG", "valor", "param='CODBC'", conn)
    Else
        colegio = RetornaCampo("CFG", "valor", "param='CODPK'", conn)
    End If
    FolioCaja = Val(RetornaCampo("fnza_caja", "folio_caja", "nombre='" & Combo1.Text & "' AND colegio='" & colegio & "'", conn))
    
    If Editando Then
        QRY = "UPDATE fnza_caja_folios SET folio_ini=" & Trim(Text8.Text) & ", folio_fin=" & Trim(Text9.Text) & ", fecha_mod=date_format(now(),'%Y-%m-%d %H:%i:%s') WHERE folio_asig=" & grilla.TextMatrix(grilla.Row, 5)
    Else
        QRY = "INSERT INTO fnza_caja_folios(folio_caja,folio_ini,folio_fin,fecha_mod,fecha_asig) VALUES('" & FolioCaja & "','" & Trim(Text8.Text) & "','" & Trim(Text9.Text) & "',date_format(now(),'%Y-%m-%d %H:%i:%s'),date_format(now(),'%Y-%m-%d %H:%i:%s'));"
    End If
    conn.Execute QRY
    Call Command9_Click
    
End Sub

Private Sub Command9_Click()
    Call Command2_Click
End Sub

Private Sub Form_Load()
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    Text7.Text = ""
    Text8.Text = ""
    Text9.Text = ""
    Command4.Enabled = False
    Command7.Enabled = False
    Combo_Cajas
    Setea_Grilla
End Sub

Private Sub Combo_Cajas()
    Dim REC As ADODB.Recordset
    Dim colegio As String
    Set REC = New ADODB.Recordset
    
    If Option1.Value = True Then
        colegio = RetornaCampo("CFG", "valor", "param='CODBC'", conn)
    Else
        colegio = RetornaCampo("CFG", "valor", "param='CODPK'", conn)
    End If
    Combo1.Clear
    REC.Open "SELECT folio_caja,nombre,colegio FROM fnza_caja WHERE colegio='" & colegio & "'", conn
    While Not REC.EOF
        Combo1.AddItem REC!nombre
        REC.MoveNext
    Wend
    Combo1.AddItem "Agregar Caja"
End Sub

Private Sub Setea_Grilla()
    grilla.Clear
    grilla.Rows = 2
    grilla.Cols = 2
    grilla.FormatString = "^Fec. Asignación|>Folio Inic.|>Folio Final|^Fec. Ult. Modif.|>Disponibles|>Folio"
    grilla.ColWidth(0) = 1700
    grilla.ColWidth(1) = 900
    grilla.ColWidth(2) = 900
    grilla.ColWidth(3) = 1700
    grilla.ColWidth(4) = 1000
    grilla.ColWidth(5) = 0
End Sub

Private Sub llena_grilla()
    Dim REC As ADODB.Recordset
    Dim FolioCaja As Long
    Dim OCUPADOS As Long
    Dim colegio As String
    
    Set REC = New ADODB.Recordset
    If Combo1.Text <> "Agregar Caja" Then
        If Option1.Value = True Then
            colegio = RetornaCampo("CFG", "valor", "param='CODBC'", conn)
        Else
            colegio = RetornaCampo("CFG", "valor", "param='CODPK'", conn)
        End If
        FolioCaja = Val(RetornaCampo("fnza_caja", "folio_caja", "nombre='" & Combo1.Text & "' AND colegio='" & colegio & "'", conn))
        REC.Open "SELECT * FROM fnza_caja_folios WHERE folio_caja=" & FolioCaja & " ORDER BY folio_ini DESC;", conn
        If REC.RecordCount > 0 Then
            For i = 1 To REC.RecordCount
                DESOCUPADOS = Val(RetornaCampo("fnza_boletas", "count(folio_blta_fisico) as ocupadas", "colegio='" & colegio & "' AND folio_blta_fisico>=" & REC!folio_ini & " AND folio_blta_fisico<=" & REC!folio_fin & " GROUP BY colegio", conn))
                DESOCUPADOS = Val(REC!folio_fin) - Val(REC!folio_ini) + 1 - OCUPADOS
                grilla.AddItem REC!fecha_Asig & Chr(9) & REC!folio_ini & Chr(9) & REC!folio_fin & Chr(9) & REC!fecha_mod & Chr(9) & str(DESOCUPADOS) & Chr(9) & REC!folio_asig, i
                If OCUPADOS > 0 Then
                    conn.Execute "UPDATE fnza_caja_folios SET cerrado='NO' WHERE folio_asig=" & REC!folio_asig & ";"
                Else
                    conn.Execute "UPDATE fnza_caja_folios SET cerrado='SI' WHERE folio_asig=" & REC!folio_asig & ";"
                End If
                REC.MoveNext
            Next i
        End If
        REC.Close
    End If
End Sub

Private Sub Llena_Datos_Caja()
    Dim colegio As String
    Dim FolioCaja As Long
    
    If Option1.Value = True Then
        colegio = RetornaCampo("CFG", "valor", "param='CODBC'", conn)
    Else
        colegio = RetornaCampo("CFG", "valor", "param='CODPK'", conn)
    End If
    FolioCaja = Val(RetornaCampo("fnza_caja", "folio_caja", "nombre='" & Combo1.Text & "' AND colegio='" & colegio & "'", conn))
    
    Text1.Text = RetornaCampo("fnza_caja", "cajero", "folio_caja=" & FolioCaja, conn)
    Text2.Text = RetornaCampo("hist_cod_colegio", "nombre", "colegio='" & colegio & "'", conn)
    Text3.Text = RetornaCampo("fnza_caja", "ubicacion", "folio_caja=" & FolioCaja, conn)
End Sub

Private Sub Grilla_DblClick()
    If Val(grilla.TextMatrix(grilla.Row, 5)) = 0 Then Exit Sub
    Frame1.Enabled = False
    Frame3.Visible = False
    Frame4.Visible = False
    Frame5.Visible = True
    Command4.Enabled = False
    Command7.Enabled = False
    Label10.Caption = "SI"
    Text8.Text = grilla.TextMatrix(grilla.Row, 1)
    Text9.Text = grilla.TextMatrix(grilla.Row, 2)
End Sub

Private Sub Option1_Click()
    Call Combo_Cajas
End Sub

Private Sub Option2_Click()
    Call Combo_Cajas
End Sub

Private Sub Text8_Change()
    Text9.Text = Text8.Text
End Sub
