VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_Asignacion_Ticket 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Asignación Ticket de Soporte"
   ClientHeight    =   6600
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   11295
   Icon            =   "Form_Asignacion_Ticket.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6600
   ScaleWidth      =   11295
   Begin VB.Frame frame_historico 
      Caption         =   "Consultar Historico"
      ForeColor       =   &H00FF0000&
      Height          =   2295
      Left            =   1560
      TabIndex        =   14
      Top             =   4080
      Visible         =   0   'False
      Width           =   3375
      Begin VB.CommandButton cmd_salir_historico 
         Caption         =   "Salir"
         Height          =   375
         Left            =   1920
         TabIndex        =   20
         Top             =   1680
         Width           =   1215
      End
      Begin VB.CommandButton cmd_Aceptar 
         Caption         =   "Aceptar"
         Height          =   375
         Left            =   240
         TabIndex        =   19
         Top             =   1680
         Width           =   1215
      End
      Begin MSComCtl2.DTPicker dtp_fecha_termino 
         Height          =   375
         Left            =   1800
         TabIndex        =   16
         Top             =   960
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   661
         _Version        =   393216
         Format          =   50528257
         CurrentDate     =   38853
      End
      Begin MSComCtl2.DTPicker dtp_fecha_inicio 
         Height          =   375
         Left            =   1800
         TabIndex        =   15
         Top             =   360
         Width           =   1335
         _ExtentX        =   2355
         _ExtentY        =   661
         _Version        =   393216
         Format          =   50528257
         CurrentDate     =   38853
      End
      Begin VB.Label Label3 
         Caption         =   "Fecha de Termino:"
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   1080
         Width           =   1335
      End
      Begin VB.Label Label2 
         Caption         =   "Fecha de Inicio:"
         Height          =   255
         Left            =   240
         TabIndex        =   17
         Top             =   480
         Width           =   1215
      End
   End
   Begin VB.Timer Timer1 
      Interval        =   60000
      Left            =   7680
      Top             =   240
   End
   Begin VB.Frame Frame4 
      Caption         =   "Asignar Personal de Soporte"
      ForeColor       =   &H00FF0000&
      Height          =   975
      Left            =   6480
      TabIndex        =   8
      Top             =   3480
      Width           =   4695
      Begin VB.CommandButton cmd_Salir 
         Caption         =   "Salir"
         Height          =   375
         Left            =   2640
         TabIndex        =   10
         Top             =   360
         Width           =   1455
      End
      Begin VB.CommandButton cmd_Asignar 
         Caption         =   "Asignar"
         Height          =   375
         Left            =   480
         TabIndex        =   9
         Top             =   360
         Width           =   1455
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Ticket Asignados Hoy"
      ForeColor       =   &H00FF0000&
      Height          =   1935
      Left            =   120
      TabIndex        =   4
      Top             =   4560
      Width           =   8295
      Begin VB.CommandButton cmd_Actualizar 
         Caption         =   "Actualizar"
         Height          =   375
         Left            =   6480
         TabIndex        =   21
         Top             =   240
         Width           =   1455
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Consultar"
         Height          =   375
         Left            =   6480
         TabIndex        =   13
         Top             =   840
         Width           =   1455
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Historico"
         Height          =   375
         Left            =   6480
         TabIndex        =   12
         Top             =   1440
         Width           =   1455
      End
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid grid_ticket_asignados 
         Height          =   1575
         Left            =   120
         TabIndex        =   7
         Top             =   240
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   2778
         _Version        =   393216
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Personal de Soporte"
      ForeColor       =   &H00FF0000&
      Height          =   2535
      Left            =   6480
      TabIndex        =   3
      Top             =   840
      Width           =   4695
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid grid_personal_soporte 
         Height          =   2175
         Left            =   120
         TabIndex        =   6
         Top             =   240
         Width           =   4455
         _ExtentX        =   7858
         _ExtentY        =   3836
         _Version        =   393216
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Ticket Nuevos"
      ForeColor       =   &H00FF0000&
      Height          =   3615
      Left            =   120
      TabIndex        =   2
      Top             =   840
      Width           =   6255
      Begin VB.CommandButton cmd_forzar_recepcion 
         Caption         =   "Recepcionar"
         Height          =   375
         Left            =   120
         TabIndex        =   11
         Top             =   3120
         Width           =   1575
      End
      Begin MSHierarchicalFlexGridLib.MSHFlexGrid grid_ticket_nuevos 
         Height          =   2775
         Left            =   120
         TabIndex        =   5
         Top             =   240
         Width           =   6015
         _ExtentX        =   10610
         _ExtentY        =   4895
         _Version        =   393216
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         _NumberOfBands  =   1
         _Band(0).Cols   =   2
      End
   End
   Begin VB.Label lbl_ticketnuevos 
      Alignment       =   2  'Center
      Caption         =   "Hay Ticket Nuevos"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000FF&
      Height          =   375
      Left            =   8520
      TabIndex        =   22
      Top             =   5280
      Visible         =   0   'False
      Width           =   2655
   End
   Begin VB.Label lbl_usuario_asignador 
      Caption         =   "Label2"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2760
      TabIndex        =   1
      Top             =   240
      Width           =   8295
   End
   Begin VB.Label Label1 
      Caption         =   "Usuario Asignador:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   2535
   End
End
Attribute VB_Name = "Form_Asignacion_Ticket"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim sw As Boolean

Private Sub cmd_Aceptar_Click()
    llenar_ticket_asignados_historico
    frame_historico.Visible = False
    Frame1.Enabled = True
    Frame2.Enabled = True
    Frame3.Enabled = True
    Frame4.Enabled = True
End Sub

Private Sub cmd_Actualizar_Click()
    Frame3.Caption = "Ticket Asignados Hoy"
    llenar_ticket_asignados
End Sub

Private Sub cmd_Asignar_Click()
    If grid_ticket_nuevos.TextMatrix(1, 1) <> "" Then
    Dim var_sql As String
    Dim i, j As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    'Obtengo fecha y hora de asignacion
    var_sql = "SELECT fecha_recepcion as f,date_format(hora_recepcion,'%H:%i:%s') as h FROM spte_ticket where" _
            & " numero_ticket = " & grid_ticket_nuevos.TextMatrix(grid_ticket_nuevos.Row, 1)
    objRS.Open var_sql, conn
    
    'Asigno a un requerimiento a un personal de soporte
    var_sql = "insert into spte_asignacion(folio_solicitud,rut_personal_soporte," _
            & "fecha_recepcion,hora_recepcion,ticket,usuario_asignador," _
            & "fecha_asignacion,hora_asignacion," _
            & "fecha_final,hora_final)" _
            & " values(" & grid_ticket_nuevos.TextMatrix(grid_ticket_nuevos.Row, 5) _
            & ",'" & grid_personal_soporte.TextMatrix(grid_personal_soporte.Row, 3) _
            & "','" & Format(objRS("f"), "yyyy-mm-dd") & "','" & Format(CDate(objRS("h")), "hh:mm:ss") & "'," _
            & grid_ticket_nuevos.TextMatrix(grid_ticket_nuevos.Row, 1) & ",'" _
            & Nom_usu_ses & "',current_date,current_time," _
            & "'1111-11-11','11:11:11')"
    conn.Execute var_sql
        
    'Cambio los estados al ticket
    var_sql = "update spte_ticket set asignado = 'SI',estado_actual = 'Pendiente' where numero_ticket = " _
    & grid_ticket_nuevos.TextMatrix(grid_ticket_nuevos.Row, 1)
    conn.Execute var_sql
    objRS.Close
    
    'Elimino de los ticket nuevos el elemento asignado
    i = grid_ticket_nuevos.Row
    If i <> 1 Then
    grid_ticket_nuevos.RemoveItem (grid_ticket_nuevos.Row)
    Else
    For j = 1 To grid_ticket_nuevos.Cols - 1
        grid_ticket_nuevos.TextMatrix(i, j) = ""
    Next j
    End If
    For j = i To grid_ticket_nuevos.Rows - 1
        grid_ticket_nuevos.TextMatrix(j, 0) = j
    Next j
    llenar_ticket_asignados
    llena_ticket_nuevos
    Else
        MsgBox "No existen ticket nuevos para asignar", vbInformation
    End If
End Sub

Private Sub cmd_forzar_recepcion_Click()
    llena_ticket_nuevos
End Sub

Private Sub cmd_Salir_Click()
    Unload Me
End Sub

Private Sub cmd_salir_historico_Click()
    frame_historico.Visible = False
    Frame1.Enabled = True
    Frame2.Enabled = True
    Frame3.Enabled = True
    Frame4.Enabled = True
End Sub

Private Sub Command1_Click()
    If grid_ticket_asignados.Rows = 2 And grid_ticket_asignados.TextMatrix(1, 1) = "" Then
        Exit Sub
    End If
    form_consultar.generar_consulta (grid_ticket_asignados.TextMatrix(grid_ticket_asignados.Row, 4))
    Load form_consultar
End Sub

Private Sub Command2_Click()
    frame_historico.Visible = True
    Frame1.Enabled = False
    Frame2.Enabled = False
    Frame3.Enabled = False
    Frame4.Enabled = False
End Sub

Private Sub Form_Load()
    llena_ticket_nuevos
    llena_personal_soporte
    llenar_ticket_asignados
    lbl_usuario_asignador.Caption = Nom_com_usu_ses
    dtp_fecha_inicio.Value = Date
    dtp_fecha_termino.Value = Date
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
            'progreso.Value = i
            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

Public Sub llena_ticket_nuevos()
    'MsgBox sw
    Dim var_sql As String
    Dim i As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    var_sql = "select numero_ticket numero,date_format(fecha,'%d-%m-%Y') fecha," _
            & "date_format(fecha,'%H:%i:%s') hora,nombre_completo_usu usuario,folio_solicitud" _
            & " from spte_solicitud ss,spte_ticket st,usuarios u" _
            & " where ss.folio = st.folio_solicitud and asignado = 'NO' and" _
            & " ss.login_usuario = u.aut_nombre_usuario" _
            & " order by fecha,hora asc"
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        Call Rec2Grid(objRS, grid_ticket_nuevos, True)
        'Asigno a spte_ticket la fecha y hora de la recepcion
        For i = 1 To grid_ticket_nuevos.Rows - 1
            var_sql = "update spte_ticket set fecha_recepcion = current_date," _
                    & "hora_recepcion = current_time " _
                    & "where numero_ticket = " & grid_ticket_nuevos.TextMatrix(i, 1) _
                    & " and fecha_recepcion = '0000-00-00' "
            conn.Execute var_sql
        Next i
        grid_ticket_nuevos.ColSel = 4
        grid_ticket_nuevos.ColWidth(5) = 0
    End If
    lbl_ticketnuevos.Visible = False
    objRS.Close
End Sub

Public Sub llena_personal_soporte()
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    var_sql = "SELECT nombre_personal as nombre,cargo_personal as cargo,rut_personal" _
            & " FROM spte_personal"
    objRS.Open var_sql, conn
    Call Rec2Grid(objRS, grid_personal_soporte, True)
    objRS.Close
    grid_personal_soporte.ColSel = 2
    grid_personal_soporte.ColWidth(3) = 0
End Sub

Public Sub llenar_ticket_asignados()
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    var_sql = "SELECT ticket as numero,nombre_personal as 'personal de soporte'," _
            & "estado_actual as 'estado actual',sa.folio_solicitud" _
            & " FROM spte_asignacion sa,spte_personal sp,spte_ticket st" _
            & " Where sa.rut_personal_soporte = sp.rut_personal And" _
            & " sa.ticket = st.numero_ticket and fecha_asignacion = current_date" _
            & " order by sa.fecha_recepcion,sa.hora_recepcion,sa.folio_solicitud"
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        Call Rec2Grid(objRS, grid_ticket_asignados, True)
        grid_ticket_asignados.ColSel = 3
        grid_ticket_asignados.ColWidth(4) = 0
    Else
        'MsgBox "No se han asignado ticket", vbInformation
        grid_ticket_asignados.Rows = 2
        grid_ticket_asignados.ClearStructure
    End If
    objRS.Close
    'grid_personal_soporte.ColWidth(3) = 0
End Sub



Private Sub Timer1_Timer()
    If sw = True Then
        sw = False
    Else
        sw = True
    End If
    If sw = False Then
        Dim var_sql As String
        Dim objRS As ADODB.Recordset
        Set objRS = New ADODB.Recordset
        var_sql = "SELECT ticket as numero,nombre_personal as 'personal de soporte'," _
                & "estado_actual as 'estado actual',sa.folio_solicitud" _
                & " FROM spte_asignacion sa,spte_personal sp,spte_ticket st" _
                & " Where sa.rut_personal_soporte = sp.rut_personal And" _
                & " sa.ticket = st.numero_ticket and fecha_asignacion = current_date" _
                & " and asignado = 'NO'" _
                & " order by sa.fecha_recepcion,sa.hora_recepcion,sa.folio_solicitud"
        objRS.Open var_sql, conn
        If objRS.RecordCount > 1 Then
            If (grid_ticket_nuevos.Rows - 1) < objRS.RecordCount Then
                lbl_ticketnuevos.Visible = True
            End If
            If (grid_ticket_nuevos.Rows - 1) >= objRS.RecordCount Then
                lbl_ticketnuevos.Visible = False
            End If
        End If
        If objRS.RecordCount = 1 Then
            If grid_ticket_nuevos.Rows = 2 And grid_ticket_nuevos.TextMatrix(1, 1) <> "" Then
                lbl_ticketnuevos.Visible = True
            End If
        End If
        objRS.Close
        'llena_ticket_nuevos
    End If
End Sub

Public Sub llenar_ticket_asignados_historico()
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    var_sql = "SELECT ticket as numero,nombre_personal as 'personal de soporte'," _
            & "estado_actual as 'estado actual',sa.folio_solicitud,fecha_asignacion as 'fecha'" _
            & " FROM spte_asignacion sa,spte_personal sp,spte_ticket st" _
            & " Where sa.rut_personal_soporte = sp.rut_personal And" _
            & " sa.ticket = st.numero_ticket and fecha_asignacion >= '" _
            & Format(dtp_fecha_inicio.Value, "yyyy-mm-dd") & "' and fecha_asignacion <= '" _
            & Format(dtp_fecha_termino.Value, "yyyy-mm-dd") & "'" _
            & " order by sa.fecha_recepcion,sa.hora_recepcion,sa.folio_solicitud"
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        Call Rec2Grid(objRS, grid_ticket_asignados, True)
        grid_ticket_asignados.ColSel = 5
        grid_ticket_asignados.ColWidth(4) = 0
    End If
    Frame3.Caption = "Ticket Asignados entre el " & dtp_fecha_inicio.Value & " al " & dtp_fecha_termino.Value
    objRS.Close
    'grid_personal_soporte.ColWidth(3) = 0
End Sub
