VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MsComCtl.ocx"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSComCt2.ocx"
Begin VB.Form frmIngresoPremioTicketFecha 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Ingreso de Premios (Ticket) por Fecha"
   ClientHeight    =   8280
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10785
   Icon            =   "frmIngresoPremioTicketFecha.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   8280
   ScaleWidth      =   10785
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdMensaje 
      Caption         =   "Espere un momento. Generando Reporte ..."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   1440
      TabIndex        =   10
      Top             =   7560
      Visible         =   0   'False
      Width           =   4695
   End
   Begin VB.CommandButton cmdExcel 
      Caption         =   "&Editar en Excel"
      Height          =   375
      Left            =   9240
      TabIndex        =   4
      Top             =   7200
      Width           =   1335
   End
   Begin VB.CommandButton cmdExtornar 
      Caption         =   "E&xtornar"
      Height          =   375
      Left            =   9240
      TabIndex        =   3
      Top             =   6720
      Width           =   1335
   End
   Begin VB.CommandButton cmdSalir 
      Caption         =   "&Salir"
      Height          =   375
      Left            =   9240
      TabIndex        =   5
      Top             =   7680
      Width           =   1335
   End
   Begin VB.CommandButton cmdBuscar 
      Caption         =   "B&uscar"
      Default         =   -1  'True
      Height          =   375
      Left            =   9240
      TabIndex        =   2
      Top             =   1440
      Width           =   1335
   End
   Begin MSComctlLib.ListView lvwIngresoPremioTicket 
      Height          =   7815
      Left            =   120
      TabIndex        =   6
      Top             =   360
      Width           =   8895
      _ExtentX        =   15690
      _ExtentY        =   13785
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      _Version        =   393217
      Icons           =   "imlPremioTicket"
      SmallIcons      =   "imlPremioTicket"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin MSComCtl2.DTPicker dtpFInicio 
      Height          =   315
      Left            =   9240
      TabIndex        =   0
      Top             =   360
      Width           =   1215
      _ExtentX        =   2143
      _ExtentY        =   556
      _Version        =   393216
      CalendarForeColor=   -2147483640
      CalendarTitleBackColor=   -2147483645
      CalendarTitleForeColor=   -2147483629
      CalendarTrailingForeColor=   -2147483645
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   58261507
      CurrentDate     =   37042
   End
   Begin MSComCtl2.DTPicker dtpFFin 
      Height          =   315
      Left            =   9240
      TabIndex        =   1
      Top             =   960
      Width           =   1215
      _ExtentX        =   2143
      _ExtentY        =   556
      _Version        =   393216
      CalendarForeColor=   -2147483640
      CalendarTitleBackColor=   -2147483645
      CalendarTitleForeColor=   -2147483629
      CalendarTrailingForeColor=   -2147483645
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   58261507
      CurrentDate     =   37042
   End
   Begin MSComctlLib.ImageList imlPremioTicket 
      Left            =   0
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   3
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmIngresoPremioTicketFecha.frx":0442
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmIngresoPremioTicketFecha.frx":0894
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmIngresoPremioTicketFecha.frx":0CE6
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.Label lblLabels 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Ingresos"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   9
      Top             =   120
      Width           =   8895
   End
   Begin VB.Label lblLabels 
      Caption         =   "Del"
      Height          =   375
      Index           =   1
      Left            =   9240
      TabIndex        =   8
      Top             =   120
      Width           =   495
   End
   Begin VB.Label lblLabels 
      Caption         =   "Al"
      Height          =   375
      Index           =   2
      Left            =   9240
      TabIndex        =   7
      Top             =   720
      Width           =   495
   End
End
Attribute VB_Name = "frmIngresoPremioTicketFecha"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public dFInicio As Date
Public dFFin As Date

Private Sub Form_Load()

  'Carga el formulario
  
  On Error GoTo LineaError

  Screen.MousePointer = vbHourglass
  
  Call ConfigurarColumnas
  Call InicializarForm
  
  Screen.MousePointer = vbDefault
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault
  
End Sub

Private Sub ConfigurarColumnas()

  'Configura las columnas de la lista lvwIngresoPremioTicket
  
  On Error GoTo LineaError

  Dim aColumnTitle() As String
  Dim aColumnWidth() As Single
  Dim aColumnAlign() As Integer
  
  ReDim aColumnTitle(6) As String
  ReDim aColumnWidth(6) As Single
  ReDim aColumnAlign(6) As Integer

  aColumnTitle(0) = "Fecha Ingreso"
  aColumnTitle(1) = "Premio"
  aColumnTitle(2) = "Cantidad"
  aColumnTitle(3) = "Usuario"
  aColumnTitle(4) = "Fecha Extorno"
  aColumnTitle(5) = "Usuario Extorno"
  
  aColumnWidth(0) = 0.15
  aColumnWidth(1) = 0.25
  aColumnWidth(2) = 0.12
  aColumnWidth(3) = 0.15
  aColumnWidth(4) = 0.15
  aColumnWidth(5) = 0.15
  
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnLeft
  aColumnAlign(2) = lvwColumnRight
  aColumnAlign(3) = lvwColumnLeft
  aColumnAlign(4) = lvwColumnLeft
  aColumnAlign(5) = lvwColumnLeft
    
  Call oListAdmin.InicializarLista(lvwIngresoPremioTicket, aColumnTitle, _
                                   aColumnWidth, aColumnAlign, lvwReport)
                                   
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub InicializarForm()

  'Inicializa el Form
  
  On Error GoTo LineaError
  
  Call CentrarControl(Me, cmdMensaje)
  
  dtpFInicio.Value = Date - 15
  dtpFFin.Value = Date
  
  Call cmdBuscar_Click
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Public Sub LlenarListaIngresoPremioTicket()

  'Llena la lista IngresoPremioTicket
  
  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  Dim itemX As ListItem
  
  sSQL = "SELECT a.*, sPremDesc " + _
         "FROM Ingreso_Premio_Ticket a, Premio_Ticket b " + _
         "WHERE a.cPremCode = b.cPremCode AND " + _
         "FORMAT(dIngrDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dIngrDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by dIngrDate DESC, sPremDesc"
  sSQL = VBsprintf(sSQL, Format(dtpFInicio.Value, "yyyy/mm/dd"), _
         Format(dtpFFin.Value, "yyyy/mm/dd"))
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir

  Do While Not ADORS.EOF
  
    Set itemX = lvwIngresoPremioTicket.ListItems.Add(, "k" + RPad(LeerCampo(ADORS!cPremCode), 10, " ") + LeerCampo(ADORS!cIngrCode), Format(LeerCampo(ADORS!dIngrDate), "dd/mm/yyyy hh:mm"))
    itemX.SubItems(1) = LeerCampo(ADORS!sPremDesc)
    itemX.SubItems(2) = Format(LeerCampo(ADORS!nIngrCant), "##,##0")
    itemX.SubItems(3) = LeerCampo(ADORS!sUserDesc)
    
    If LeerCampo(ADORS!dExtoDate) = "" Then
      
      If LeerCampo(ADORS!cAjusFlag) <> CStr(kSI) Then
        
        itemX.Icon = 1
        itemX.SmallIcon = 1
        
      Else
      
        itemX.Icon = 3
        itemX.SmallIcon = 3
      
      End If
      
    Else
      itemX.SubItems(4) = Format(LeerCampo(ADORS!dExtoDate), "dd/mm/yyyy hh:mm")
      itemX.SubItems(5) = LeerCampo(ADORS!sUseEDesc)
      itemX.Icon = 2
      itemX.SmallIcon = 2
    End If
  
    ADORS.MoveNext
    
  Loop
  
  lblLabels(0).Caption = "Ingresos   -   Del " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " Al " + Format(dtpFFin.Value, "dd/mm/yyyy")
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
         
End Sub

Public Sub ManejarControles()

  'Maneja el uso de los controles
  
  On Error GoTo LineaError

  Call DeshabilitarControl(cmdExtornar, False)
  Call DeshabilitarControl(cmdExcel, False)

  If lvwIngresoPremioTicket.ListItems.Count > 0 And _
  (piPerfil_Codigo = kPERFIL_ADMINISTRADOR Or piPerfil_Codigo = kPERFIL_SUPERVISOR) Then
      
    lvwIngresoPremioTicket.SelectedItem.EnsureVisible
    Call HabilitarControl(cmdExtornar, False)
    Call HabilitarControl(cmdExcel, False)
    
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub lvwIngresoPremioTicket_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

  'Ordenar Según la columna seleccionada
  
  On Error GoTo LineaError
  
  If ColumnHeader.Index = 1 Or ColumnHeader.Index = 5 Then
  
    Call APISort(lvwIngresoPremioTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_DATE)

  ElseIf ColumnHeader.Index = 3 Then
  
    Call APISort(lvwIngresoPremioTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_VALUE)
                 
  Else
  
    Call APISort(lvwIngresoPremioTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_DEFAULT)
                 
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Public Sub cmdBuscar_Click()

  'Buscar Ingresos según rango de fecha
  
  On Error GoTo LineaError

  lblLabels(0).Caption = "Ingresos"
  lvwIngresoPremioTicket.ListItems.Clear

  LlenarListaIngresoPremioTicket
  
  dFInicio = dtpFInicio.Value
  dFFin = dtpFFin.Value
  
  ManejarControles
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub cmdExtornar_Click()

  'Extornar Ingreso
  
  On Error GoTo LineaError
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim sPremio As String
  
  Dim itemX As ListItem
  Dim bConnFlag As Boolean
  
  Dim lStock As Long
  Dim lCantidad As Long
  
  Screen.MousePointer = vbHourglass
    
  If lvwIngresoPremioTicket.SelectedItem.SmallIcon = 2 Then
    MsgBox "Ingreso ya ha sido extornado", vbOKOnly + vbInformation
    GoTo Salir
  ElseIf lvwIngresoPremioTicket.SelectedItem.SmallIcon = 3 Then
    MsgBox "Los ajustes no pueden ser extornados", vbOKOnly + vbInformation
    GoTo Salir
  End If
  
  sPremio = Trim(Mid(lvwIngresoPremioTicket.SelectedItem.Key, 2, 10))
  
  sSQL = "SELECT nPremStoc FROM Premio_Ticket WHERE cPremCode = $"
  sSQL = VBsprintf(sSQL, sPremio)
  
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
  lStock = CLng(LeerCampo(ADORS!nPremStoc))
  lCantidad = CLng(lvwIngresoPremioTicket.SelectedItem.SubItems(2))
  
  Set ADORS = Nothing
  
  If lStock < lCantidad Then
    MsgBox "No se puede ejecutar el proceso. Stock actual menor a la cantidad a extornar.", vbOKOnly + vbInformation
    GoTo Salir
  End If
  
  If MsgBox("Se extornará ingreso seleccionado (Fecha: " + lvwIngresoPremioTicket.SelectedItem.Text + " - Premio: " + lvwIngresoPremioTicket.SelectedItem.SubItems(1) + " - Cantidad: " + lvwIngresoPremioTicket.SelectedItem.SubItems(2) + "). Confirma Acción?", _
  vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then GoTo Salir
  
  ADOCnn.BeginTrans
  bConnFlag = True
  
  sSQL = "UPDATE Ingreso_Premio_Ticket SET dExtoDate = '$', sUseEDesc = '$' " + _
         "WHERE cPremCode = $ AND cIngrCode = $"
  sSQL = VBsprintf(sSQL, Format(Now, "yyyy/mm/dd hh:mm"), ReemplazarComilla(psUsuario_Descripcion), sPremio, _
         Mid(lvwIngresoPremioTicket.SelectedItem.Key, 12))
         
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1
  
  sSQL = "UPDATE Premio_Ticket SET nPremStoc = nPremStoc - $ " + _
         "WHERE cPremCode = $"
  sSQL = VBsprintf(sSQL, Format(lvwIngresoPremioTicket.SelectedItem.SubItems(2), "####0"), _
         sPremio)

  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1
  
  ADOCnn.CommitTrans
  bConnFlag = False
  
  Set itemX = lvwIngresoPremioTicket.SelectedItem
  
  itemX.SubItems(4) = Format(Now, "dd/mm/yyyy hh:mm")
  itemX.SubItems(5) = psUsuario_Descripcion
  itemX.Icon = 2
  itemX.SmallIcon = 2
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
LineaError1:
  If bConnFlag Then ADOCnn.RollbackTrans
  
Salir:
  Set ADORS = Nothing
  Screen.MousePointer = vbDefault
  
End Sub

Private Sub CmdExcel_Click()

  'Editar en Hoja Excel

  On Error GoTo LineaError

  Dim xlApp As Excel.Application
  Dim xlBook As Excel.Workbook
  Dim xlSheet As Excel.Worksheet
  Dim xlSheetTemp As Excel.Worksheet
  
  Dim lFila As Long
  Dim i As Long
  Dim lRegistros As Long
  
  Screen.MousePointer = vbHourglass
  
  cmdMensaje.Visible = True
  
  Set xlApp = CreateObject("excel.application")
  Set xlBook = xlApp.Workbooks.Add
  Set xlSheet = xlBook.Worksheets.Add
  
  xlSheet.Name = "Ingreso de Premios"
  
  xlBook.Application.DisplayAlerts = False
  
  For Each xlSheetTemp In xlBook.Worksheets
    If xlSheetTemp.Name <> xlSheet.Name Then
      xlSheetTemp.Delete
    End If
  Next xlSheetTemp
  
  xlBook.Application.DisplayAlerts = True
  
  'Formato Página
  xlSheet.PageSetup.Orientation = xlPortrait
  xlSheet.PageSetup.LeftMargin = Application.InchesToPoints(0.3)
  xlSheet.PageSetup.RightMargin = Application.InchesToPoints(0.3)
  xlSheet.PageSetup.TopMargin = Application.InchesToPoints(0.5)
  xlSheet.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
  xlSheet.PageSetup.HeaderMargin = Application.InchesToPoints(0.1)
  xlSheet.PageSetup.FooterMargin = Application.InchesToPoints(0.1)
  xlSheet.PageSetup.PrintTitleRows = xlSheet.Rows("1:5").Address
    
  'Cabecera / Pie de Página
  xlSheet.PageSetup.LeftHeader = "&6Moy Park"
  xlSheet.PageSetup.RightHeader = "&6" + "Sistema de Afiliación de Clientes"
  xlSheet.PageSetup.RightFooter = "&6página &P"
  
  'Columna
  xlSheet.Columns(1).ColumnWidth = 13
  xlSheet.Columns(2).ColumnWidth = 25
  xlSheet.Columns(3).ColumnWidth = 7.5
  xlSheet.Columns(4).ColumnWidth = 10
  xlSheet.Columns(5).ColumnWidth = 13
  xlSheet.Columns(6).ColumnWidth = 10
  xlSheet.Columns(7).ColumnWidth = 15
  
  lFila = 1
  
  'Título
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + 1, 1)).NumberFormat = "@"
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + 1, 1)).Font.Bold = True
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + 1, 1)).Font.Size = 11
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + 1, 1)).HorizontalAlignment = xlCenter
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Merge
  xlSheet.Range(xlSheet.Cells(lFila + 1, 1), xlSheet.Cells(lFila + 1, 7)).Merge
  
  xlSheet.Cells(lFila, 1).Value = "INGRESO DE PREMIOS (TICKETS)"
  xlSheet.Cells(lFila + 1, 1).Value = "DEL " + Format(dFInicio, "dd/mm/yyyy") + " AL " + Format(dFFin, "dd/mm/yyyy")
  
  lFila = lFila + 4
   
  'SubTítulo
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).NumberFormat = "@"
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Font.Bold = True
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Font.Size = 8
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).HorizontalAlignment = xlCenter
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Borders.LineStyle = xlContinuous
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Borders.Weight = 2
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Borders(xlEdgeTop).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Borders(xlEdgeBottom).Weight = 3
  xlSheet.Cells(lFila, 1).Borders(xlEdgeLeft).Weight = 3
  xlSheet.Cells(lFila, 7).Borders(xlEdgeRight).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Interior.ColorIndex = 15
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Interior.Pattern = xlSolid
  
  xlSheet.Cells(lFila, 1).Value = "Fecha Ingreso"
  xlSheet.Cells(lFila, 2).Value = "Premio"
  xlSheet.Cells(lFila, 3).Value = "Cantidad"
  xlSheet.Cells(lFila, 4).Value = "Usuario"
  xlSheet.Cells(lFila, 5).Value = "Fecha Extorno"
  xlSheet.Cells(lFila, 6).Value = "Usuar.Extor."
  xlSheet.Cells(lFila, 7).Value = "Tipo"
  
  lFila = lFila + 1
  lRegistros = lvwIngresoPremioTicket.ListItems.Count
  
  'Datos
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 7)).NumberFormat = "@"
  xlSheet.Range(xlSheet.Cells(lFila, 3), xlSheet.Cells(lFila + lRegistros - 1, 3)).NumberFormat = "##,##0"
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 7)).Font.Size = 8
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 7)).HorizontalAlignment = xlLeft
  xlSheet.Range(xlSheet.Cells(lFila, 3), xlSheet.Cells(lFila + lRegistros - 1, 3)).HorizontalAlignment = xlRight
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 7)).Borders.LineStyle = xlContinuous
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 7)).Borders.Weight = 2
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Borders(xlEdgeTop).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 7)).Borders(xlEdgeBottom).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 1)).Borders(xlEdgeLeft).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 7), xlSheet.Cells(lFila + lRegistros - 1, 7)).Borders(xlEdgeRight).Weight = 3
  
  For i = 1 To lRegistros
  
    xlSheet.Cells(lFila, 1) = lvwIngresoPremioTicket.ListItems(i).Text
    xlSheet.Cells(lFila, 2) = lvwIngresoPremioTicket.ListItems(i).SubItems(1)
    xlSheet.Cells(lFila, 3) = lvwIngresoPremioTicket.ListItems(i).SubItems(2)
    xlSheet.Cells(lFila, 4) = lvwIngresoPremioTicket.ListItems(i).SubItems(3)
    xlSheet.Cells(lFila, 5) = lvwIngresoPremioTicket.ListItems(i).SubItems(4)
    xlSheet.Cells(lFila, 6) = lvwIngresoPremioTicket.ListItems(i).SubItems(5)
    
    If lvwIngresoPremioTicket.ListItems(i).Icon = 1 Then
      xlSheet.Cells(lFila, 7) = "INGRESO"
    ElseIf lvwIngresoPremioTicket.ListItems(i).Icon = 2 Then
      xlSheet.Cells(lFila, 7) = "INGR.EXTORNADO"
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Font.ColorIndex = 53
    Else
      xlSheet.Cells(lFila, 7) = "AJUSTE"
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Font.ColorIndex = 11
    End If
    
    lFila = lFila + 1
    
  Next
  
  'Mostrar
  xlApp.WindowState = xlMaximized
  xlApp.Visible = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
    
  On Error Resume Next

  xlBook.Close False
  xlApp.Quit
  
Salir:

  On Error Resume Next
  
  Set xlSheetTemp = Nothing
  Set xlSheet = Nothing
  Set xlBook = Nothing
  Set xlApp = Nothing
  
  cmdMensaje.Visible = False
  
  Screen.MousePointer = vbDefault

End Sub


Private Sub CmdSalir_Click()

  'Descargar Form

  On Error GoTo LineaError

  Unload Me
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub





