VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSComCt2.ocx"
Begin VB.Form frmReporteFecha 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Reporte"
   ClientHeight    =   2700
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5775
   Icon            =   "frmReporteFecha.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   2700
   ScaleWidth      =   5775
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdEstandar 
      Cancel          =   -1  'True
      Caption         =   "&Cancelar"
      Height          =   375
      Index           =   1
      Left            =   4320
      TabIndex        =   11
      Top             =   2160
      Width           =   1335
   End
   Begin VB.CommandButton cmdEstandar 
      Caption         =   "&Aceptar"
      Default         =   -1  'True
      Height          =   375
      Index           =   0
      Left            =   4320
      TabIndex        =   10
      Top             =   1680
      Width           =   1335
   End
   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            =   120
      TabIndex        =   9
      Top             =   840
      Visible         =   0   'False
      Width           =   4695
   End
   Begin VB.Frame fraGrupo 
      Caption         =   " Agrupado por "
      Height          =   1695
      Left            =   120
      TabIndex        =   5
      Top             =   840
      Width           =   4095
      Begin VB.OptionButton optGrupo 
         Caption         =   "Grupo3"
         Height          =   255
         Index           =   2
         Left            =   1200
         TabIndex        =   8
         Top             =   1200
         Width           =   1815
      End
      Begin VB.OptionButton optGrupo 
         Caption         =   "Grupo2"
         Height          =   255
         Index           =   1
         Left            =   1200
         TabIndex        =   7
         Top             =   840
         Width           =   1815
      End
      Begin VB.OptionButton optGrupo 
         Caption         =   "Grupo1"
         Height          =   255
         Index           =   0
         Left            =   1200
         TabIndex        =   6
         Top             =   480
         Width           =   1815
      End
   End
   Begin VB.Frame fraCanjeLista 
      Height          =   735
      Index           =   2
      Left            =   120
      TabIndex        =   0
      Top             =   0
      Width           =   4095
      Begin MSComCtl2.DTPicker dtpFInicio 
         Height          =   315
         Left            =   840
         TabIndex        =   1
         Top             =   240
         Width           =   1215
         _ExtentX        =   2143
         _ExtentY        =   556
         _Version        =   393216
         CalendarForeColor=   -2147483640
         CalendarTitleBackColor=   -2147483645
         CalendarTitleForeColor=   -2147483629
         CalendarTrailingForeColor=   -2147483645
         CustomFormat    =   "dd/MM/yyyy"
         Format          =   23658499
         CurrentDate     =   37042
      End
      Begin MSComCtl2.DTPicker dtpFFin 
         Height          =   315
         Left            =   2640
         TabIndex        =   2
         Top             =   240
         Width           =   1215
         _ExtentX        =   2143
         _ExtentY        =   556
         _Version        =   393216
         CalendarForeColor=   -2147483640
         CalendarTitleBackColor=   -2147483645
         CalendarTitleForeColor=   -2147483629
         CalendarTrailingForeColor=   -2147483645
         CustomFormat    =   "dd/MM/yyyy"
         Format          =   23658499
         CurrentDate     =   37042
      End
      Begin VB.Label lblLabels 
         Caption         =   "Al"
         Height          =   375
         Index           =   1
         Left            =   2280
         TabIndex        =   4
         Top             =   240
         Width           =   495
      End
      Begin VB.Label lblLabels 
         Caption         =   "Del"
         Height          =   375
         Index           =   0
         Left            =   240
         TabIndex        =   3
         Top             =   240
         Width           =   495
      End
   End
End
Attribute VB_Name = "frmReporteFecha"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Const kGRUPO1 = 0
Const kGRUPO2 = 1
Const kGRUPO3 = 2

Private Sub Form_Load()

  'Carga el formulario
  
  On Error GoTo LineaError

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

Private Sub InicializarForm()

  'Inicializa el Form
  
  On Error GoTo LineaError
  
  Call CentrarControl(Me, cmdMensaje)
  
  optGrupo(kGRUPO1).Caption = "Fecha"
  
  If frmPrincipal.iMnuReporte = kMNU_REPORTE_ACUMULACION_POR_FECHA Then
  
    Me.Caption = "Acumulación por Fecha"
    optGrupo(kGRUPO2).Visible = False
    optGrupo(kGRUPO3).Caption = "Cliente"
    
  ElseIf frmPrincipal.iMnuReporte = kMNU_REPORTE_CANJE_POR_FECHA Then
  
    Me.Caption = "Canje por Fecha"
    optGrupo(kGRUPO2).Caption = "Cliente"
    optGrupo(kGRUPO3).Caption = "Premio"
    
  ElseIf frmPrincipal.iMnuReporte = kMNU_REPORTE_INGRESO_POR_FECHA Then
  
    Me.Caption = "Ingreso de Premios (Tickets) por Fecha"
    optGrupo(kGRUPO2).Visible = False
    optGrupo(kGRUPO3).Caption = "Premio"
    
  End If
    
  dtpFInicio.Value = Date - 15
  dtpFFin.Value = Date

  optGrupo(kGRUPO1).Value = True
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub cmdEstandar_Click(Index As Integer)

  'Acepta o Cancela Generación del reporte
  
  Screen.MousePointer = vbHourglass
  
  On Error GoTo LineaError
  
  Select Case Index
  
  Case kCMD_ACEPTAR
  
    If frmPrincipal.iMnuReporte = kMNU_REPORTE_ACUMULACION_POR_FECHA Then
      If Not ReporteAcumulacion Then GoTo Salir
    ElseIf frmPrincipal.iMnuReporte = kMNU_REPORTE_CANJE_POR_FECHA Then
      If Not ReporteCanje Then GoTo Salir
    ElseIf frmPrincipal.iMnuReporte = kMNU_REPORTE_INGRESO_POR_FECHA Then
      If Not ReporteIngreso Then GoTo Salir
    End If
  
  Case kCMD_CANCELAR
    
  End Select
  
  Unload Me
  
  GoTo Salir

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Screen.MousePointer = vbDefault

End Sub

Private Function ReporteAcumulacion() As Boolean

  'Genera Reporte Acumulacion de Premios por Fecha
  
  On Error GoTo LineaError
  
  Dim xlApp As Excel.Application
  Dim xlBook As Excel.Workbook
  Dim xlSheet1 As Excel.Worksheet
  Dim xlSheet2 As Excel.Worksheet
  Dim xlSheetTemp As Excel.Worksheet

  Dim lFila As Long
  
  ReporteAcumulacion = False
  
  cmdMensaje.Visible = True
  
  Set xlApp = CreateObject("excel.application")
  Set xlBook = xlApp.Workbooks.Add
  Set xlSheet1 = xlBook.Worksheets.Add
  Set xlSheet2 = xlBook.Worksheets.Add
  
  xlSheet1.Name = "Puntos"
  xlSheet2.Name = "Tickets"
  
  xlBook.Application.DisplayAlerts = False
  
  For Each xlSheetTemp In xlBook.Worksheets
    If xlSheetTemp.Name <> xlSheet1.Name And xlSheetTemp.Name <> xlSheet2.Name Then
      xlSheetTemp.Delete
    End If
  Next xlSheetTemp
  
  xlBook.Application.DisplayAlerts = True
  
   'Formato Página
  xlSheet1.PageSetup.Orientation = xlLandscape
  xlSheet1.PageSetup.LeftMargin = Application.InchesToPoints(0.5)
  xlSheet1.PageSetup.RightMargin = Application.InchesToPoints(0.5)
  xlSheet1.PageSetup.TopMargin = Application.InchesToPoints(0.5)
  xlSheet1.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
  xlSheet1.PageSetup.HeaderMargin = Application.InchesToPoints(0.1)
  xlSheet1.PageSetup.FooterMargin = Application.InchesToPoints(0.1)
  xlSheet1.PageSetup.PrintTitleRows = xlSheet1.Rows("1:5").Address
  
  xlSheet2.PageSetup.Orientation = xlLandscape
  xlSheet2.PageSetup.LeftMargin = Application.InchesToPoints(0.5)
  xlSheet2.PageSetup.RightMargin = Application.InchesToPoints(0.5)
  xlSheet2.PageSetup.TopMargin = Application.InchesToPoints(0.5)
  xlSheet2.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
  xlSheet2.PageSetup.HeaderMargin = Application.InchesToPoints(0.1)
  xlSheet2.PageSetup.FooterMargin = Application.InchesToPoints(0.1)
  xlSheet2.PageSetup.PrintTitleRows = xlSheet1.Rows("1:5").Address
    
  'Cabecera / Pie de Página
  xlSheet1.PageSetup.LeftHeader = "&6Moy Park"
  xlSheet1.PageSetup.RightHeader = "&6" + "Sistema de Afiliación de Clientes"
  xlSheet1.PageSetup.RightFooter = "&6página &P"
  
  xlSheet2.PageSetup.LeftHeader = "&6Moy Park"
  xlSheet2.PageSetup.RightHeader = "&6" + "Sistema de Afiliación de Clientes"
  xlSheet2.PageSetup.RightFooter = "&6página &P"
  
  If Not ReporteAcumulacionPunto(xlSheet1) Then GoTo LineaError1
  If Not ReporteAcumulacionTicket(xlSheet2) Then GoTo LineaError1
  
  'Mostrar
  xlApp.WindowState = xlMaximized
  xlApp.Visible = True
  
  ReporteAcumulacion = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
LineaError1:
  
  On Error Resume Next

  xlBook.Close False
  xlApp.Quit
  
Salir:

  On Error Resume Next
  
  Set xlSheetTemp = Nothing
  Set xlSheet1 = Nothing
  Set xlBook = Nothing
  Set xlApp = Nothing
  
  cmdMensaje.Visible = False
  
End Function

Private Function ReporteAcumulacionPunto(xlSheet As Excel.Worksheet) As Boolean

  'Inserta la parte de Títulos y SubTitulos
  
  On Error GoTo LineaError
  
  Dim lFila As Long
  Dim lColumna As Long
  
  ReporteAcumulacionPunto = False
  
  'Columna
  
  If optGrupo(kGRUPO1).Value Then
  
    xlSheet.Columns(1).ColumnWidth = 7
    xlSheet.Columns(2).ColumnWidth = 8.5
    xlSheet.Columns(3).ColumnWidth = 36
    xlSheet.Columns(4).ColumnWidth = 9.5
    xlSheet.Columns(5).ColumnWidth = 9.5
    xlSheet.Columns(6).ColumnWidth = 12
    xlSheet.Columns(7).ColumnWidth = 13
    xlSheet.Columns(8).ColumnWidth = 12
    xlSheet.Columns(9).ColumnWidth = 15
    
    lColumna = 9
    
  Else
  
    xlSheet.Columns(1).ColumnWidth = 18
    xlSheet.Columns(2).ColumnWidth = 10
    xlSheet.Columns(3).ColumnWidth = 10
    xlSheet.Columns(4).ColumnWidth = 10
    xlSheet.Columns(5).ColumnWidth = 15
    xlSheet.Columns(6).ColumnWidth = 15
    xlSheet.Columns(7).ColumnWidth = 15
    xlSheet.Columns(8).ColumnWidth = 15
    
    lColumna = 8
    
  End If
  
  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, lColumna)).Merge
  xlSheet.Range(xlSheet.Cells(lFila + 1, 1), xlSheet.Cells(lFila + 1, lColumna)).Merge
  
  xlSheet.Cells(lFila, 1).Value = "ACUMULACION DE PUNTOS"
  xlSheet.Cells(lFila + 1, 1).Value = "DEL " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " AL " + Format(dtpFFin.Value, "dd/mm/yyyy")
  
  lFila = lFila + 4
   
  'SubTítulo
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).NumberFormat = "@"
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Bold = True
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Size = 8
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).HorizontalAlignment = xlCenter
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.LineStyle = xlContinuous
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.Weight = 2
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeTop).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeBottom).Weight = 3
  xlSheet.Cells(lFila, 1).Borders(xlEdgeLeft).Weight = 3
  xlSheet.Cells(lFila, lColumna).Borders(xlEdgeRight).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.ColorIndex = 15
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.Pattern = xlSolid
  
  If optGrupo(kGRUPO1).Value Then
    xlSheet.Cells(lFila, 1).Value = "Hora"
    xlSheet.Cells(lFila, 2).Value = "Tarjeta"
    xlSheet.Cells(lFila, 3).Value = "Cliente"
    xlSheet.Cells(lFila, 4).Value = "Importe"
    xlSheet.Cells(lFila, 5).Value = "Puntos"
    xlSheet.Cells(lFila, 6).Value = "Usuario"
    xlSheet.Cells(lFila, 7).Value = "Fecha Extorno"
    xlSheet.Cells(lFila, 8).Value = "Usuar.Extor."
    xlSheet.Cells(lFila, 9).Value = "Tipo"
  Else
    xlSheet.Cells(lFila, 1).Value = "Fecha Acum."
    xlSheet.Cells(lFila, 2).Value = "Tarjeta"
    xlSheet.Cells(lFila, 3).Value = "Importe"
    xlSheet.Cells(lFila, 4).Value = "Puntos"
    xlSheet.Cells(lFila, 5).Value = "Usuario"
    xlSheet.Cells(lFila, 6).Value = "Fecha Extorno"
    xlSheet.Cells(lFila, 7).Value = "Usuar.Extor."
    xlSheet.Cells(lFila, 8).Value = "Tipo"
  End If
  
  lFila = lFila + 2
  
  If optGrupo(kGRUPO1).Value Then
    If Not ReporteAcumulacionPuntoFecha(xlSheet, lFila) Then Exit Function
  Else
    If Not ReporteAcumulacionPuntoCliente(xlSheet, lFila) Then Exit Function
  End If
  
  ReporteAcumulacionPunto = True
    
  Exit Function
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Function

Private Function ReporteAcumulacionPuntoFecha(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalImporte As Long
  Dim lTotalImporte As Long
  Dim lSubTotalPunto As Long
  Dim lTotalPunto As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteAcumulacionPuntoFecha = False
  
  sSQL = "SELECT DISTINCT FORMAT(dAcumDate, 'yyyy/mm/dd') AS dFecha " + _
         "FROM Acumulacion_Punto " + _
         "WHERE FORMAT(dAcumDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dAcumDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 1 DESC"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalImporte = 0
  lTotalPunto = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = Format(LeerCampo(ADORS!dFecha), "dd/mm/yyyy")
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sClieApel, sClieName " + _
             "FROM Acumulacion_Punto a, Cliente b " + _
             "WHERE a.cClieCode = b.cClieCode AND " + _
             "FORMAT(dAcumDate, 'yyyy/mm/dd') = '$' " + _
             "Order by sClieApel + ' ' + sClieName, dAcumDate DESC"
      sSQL = VBsprintf(sSQL, Format(LeerCampo(ADORS!dFecha), "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalImporte = 0
      lSubTotalPunto = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).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, 9), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dAcumDate), "hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sClieApel) + " " + LeerCampo(ADORS1!sClieName)
          xlSheet.Cells(lFila, 4) = Format(LeerCampo(ADORS1!nAcumImpo), "##,##0")
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!nPuntCant), "##,##0")
          xlSheet.Cells(lFila, 6) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 7) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 8) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
        
            If LeerCampo(ADORS1!cAjusFlag) <> CStr(kSI) Then
              xlSheet.Cells(lFila, 9) = "ACUMULACION"
            Else
              xlSheet.Cells(lFila, 9) = "AJUSTE"
              xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Font.ColorIndex = 11
            End If
            
            lSubTotalImporte = lSubTotalImporte + CLng(xlSheet.Cells(lFila, 4))
            lSubTotalPunto = lSubTotalPunto + CLng(xlSheet.Cells(lFila, 5))
        
          Else
            xlSheet.Cells(lFila, 9) = "ACUM.EXTORNADA"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalImporte, "##,##0") + " Soles - " + Format(lSubTotalPunto, "##,##0") + " Puntos"
      
        lTotalImporte = lTotalImporte + lSubTotalImporte
        lTotalPunto = lTotalPunto + lSubTotalPunto
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalImporte, "##,##0") + " Soles - " + Format(lTotalPunto, "##,##0") + " Puntos"
  
  End If
  
  ReporteAcumulacionPuntoFecha = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteAcumulacionPuntoCliente(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalImporte As Long
  Dim lTotalImporte As Long
  Dim lSubTotalPunto As Long
  Dim lTotalPunto As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteAcumulacionPuntoCliente = False
  
  sSQL = "SELECT DISTINCT a.cClieCode, sClieApel + ' ' + sClieName AS sName " + _
         "FROM Acumulacion_Punto a, Cliente b " + _
         "WHERE a.cClieCode = b.cClieCode AND " + _
         "FORMAT(dAcumDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dAcumDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 2"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalImporte = 0
  lTotalPunto = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = LeerCampo(ADORS!sName)
    
      lFila = lFila + 1
    
      sSQL = "SELECT * " + _
             "FROM Acumulacion_Punto " + _
             "WHERE cClieCode = $ AND " + _
             "FORMAT(dAcumDate, 'yyyy/mm/dd') >= '$' AND " + _
             "FORMAT(dAcumDate, 'yyyy/mm/dd') <= '$' " + _
             "Order by dAcumDate DESC"
      sSQL = VBsprintf(sSQL, LeerCampo(ADORS!cClieCode), _
             Format(dtpFInicio.Value, "yyyy/mm/dd"), _
             Format(dtpFFin.Value, "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalImporte = 0
      lSubTotalPunto = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 3), xlSheet.Cells(lFila + lRegistros - 1, 4)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 3), xlSheet.Cells(lFila + lRegistros - 1, 4)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).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, 8), xlSheet.Cells(lFila + lRegistros - 1, 8)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dAcumDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = Format(LeerCampo(ADORS1!nAcumImpo), "##,##0")
          xlSheet.Cells(lFila, 4) = Format(LeerCampo(ADORS1!nPuntCant), "##,##0")
          xlSheet.Cells(lFila, 5) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 6) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 7) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
        
            If LeerCampo(ADORS1!cAjusFlag) <> CStr(kSI) Then
              xlSheet.Cells(lFila, 8) = "ACUMULACION"
            Else
              xlSheet.Cells(lFila, 8) = "AJUSTE"
              xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Font.ColorIndex = 11
            End If
            
            lSubTotalImporte = lSubTotalImporte + CLng(xlSheet.Cells(lFila, 3))
            lSubTotalPunto = lSubTotalPunto + CLng(xlSheet.Cells(lFila, 4))
        
          Else
            xlSheet.Cells(lFila, 8) = "ACUM.EXTORNADA"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalImporte, "##,##0") + " Soles - " + Format(lSubTotalPunto, "##,##0") + " Puntos"
      
        lTotalImporte = lTotalImporte + lSubTotalImporte
        lTotalPunto = lTotalPunto + lSubTotalPunto
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalImporte, "##,##0") + " Soles - " + Format(lTotalPunto, "##,##0") + " Puntos"
  
  End If
  
  ReporteAcumulacionPuntoCliente = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteAcumulacionTicket(xlSheet As Excel.Worksheet) As Boolean

  'Inserta la parte de Títulos y SubTitulos
  
  On Error GoTo LineaError
  
  Dim lFila As Long
  Dim lColumna As Long
  
  ReporteAcumulacionTicket = False
  
  'Columna
  
  If optGrupo(kGRUPO1).Value Then
  
    xlSheet.Columns(1).ColumnWidth = 7
    xlSheet.Columns(2).ColumnWidth = 8.5
    xlSheet.Columns(3).ColumnWidth = 46
    xlSheet.Columns(4).ColumnWidth = 9.5
    xlSheet.Columns(5).ColumnWidth = 12
    xlSheet.Columns(6).ColumnWidth = 13
    xlSheet.Columns(7).ColumnWidth = 12
    xlSheet.Columns(8).ColumnWidth = 15
    
    lColumna = 8
    
  Else
  
    xlSheet.Columns(1).ColumnWidth = 18
    xlSheet.Columns(2).ColumnWidth = 12
    xlSheet.Columns(3).ColumnWidth = 12
    xlSheet.Columns(4).ColumnWidth = 16
    xlSheet.Columns(5).ColumnWidth = 16
    xlSheet.Columns(6).ColumnWidth = 16
    xlSheet.Columns(7).ColumnWidth = 16
    
    lColumna = 7
    
  End If
  
  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, lColumna)).Merge
  xlSheet.Range(xlSheet.Cells(lFila + 1, 1), xlSheet.Cells(lFila + 1, lColumna)).Merge
  
  xlSheet.Cells(lFila, 1).Value = "ACUMULACION DE TICKETS"
  xlSheet.Cells(lFila + 1, 1).Value = "DEL " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " AL " + Format(dtpFFin.Value, "dd/mm/yyyy")
  
  lFila = lFila + 4
   
  'SubTítulo
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).NumberFormat = "@"
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Bold = True
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Size = 8
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).HorizontalAlignment = xlCenter
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.LineStyle = xlContinuous
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.Weight = 2
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeTop).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeBottom).Weight = 3
  xlSheet.Cells(lFila, 1).Borders(xlEdgeLeft).Weight = 3
  xlSheet.Cells(lFila, lColumna).Borders(xlEdgeRight).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.ColorIndex = 15
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.Pattern = xlSolid
  
  If optGrupo(kGRUPO1).Value Then
    xlSheet.Cells(lFila, 1).Value = "Hora"
    xlSheet.Cells(lFila, 2).Value = "Tarjeta"
    xlSheet.Cells(lFila, 3).Value = "Cliente"
    xlSheet.Cells(lFila, 4).Value = "Tickets"
    xlSheet.Cells(lFila, 5).Value = "Usuario"
    xlSheet.Cells(lFila, 6).Value = "Fecha Extorno"
    xlSheet.Cells(lFila, 7).Value = "Usuar.Extor."
    xlSheet.Cells(lFila, 8).Value = "Tipo"
  Else
    xlSheet.Cells(lFila, 1).Value = "Fecha Acum."
    xlSheet.Cells(lFila, 2).Value = "Tarjeta"
    xlSheet.Cells(lFila, 3).Value = "Tickets"
    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"
  End If
  
  lFila = lFila + 2
  
  If optGrupo(kGRUPO1).Value Then
    If Not ReporteAcumulacionTicketFecha(xlSheet, lFila) Then Exit Function
  Else
    If Not ReporteAcumulacionTicketCliente(xlSheet, lFila) Then Exit Function
  End If
  
  ReporteAcumulacionTicket = True
    
  Exit Function
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Function

Private Function ReporteAcumulacionTicketFecha(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalTicket As Long
  Dim lTotalTicket As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteAcumulacionTicketFecha = False
  
  sSQL = "SELECT DISTINCT FORMAT(dAcumDate, 'yyyy/mm/dd') AS dFecha " + _
         "FROM Acumulacion_Ticket " + _
         "WHERE FORMAT(dAcumDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dAcumDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 1 DESC"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalTicket = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = Format(LeerCampo(ADORS!dFecha), "dd/mm/yyyy")
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sClieApel, sClieName " + _
             "FROM Acumulacion_Ticket a, Cliente b " + _
             "WHERE a.cClieCode = b.cClieCode AND " + _
             "FORMAT(dAcumDate, 'yyyy/mm/dd') = '$' " + _
             "Order by sClieApel + ' ' + sClieName, dAcumDate DESC"
      sSQL = VBsprintf(sSQL, Format(LeerCampo(ADORS!dFecha), "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalTicket = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 4)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 4)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 8)).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, 8), xlSheet.Cells(lFila + lRegistros - 1, 8)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dAcumDate), "hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sClieApel) + " " + LeerCampo(ADORS1!sClieName)
          xlSheet.Cells(lFila, 4) = Format(LeerCampo(ADORS1!nTickCant), "##,##0")
          xlSheet.Cells(lFila, 5) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 6) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 7) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
        
            If LeerCampo(ADORS1!cAjusFlag) <> CStr(kSI) Then
              xlSheet.Cells(lFila, 8) = "ACUMULACION"
            Else
              xlSheet.Cells(lFila, 8) = "AJUSTE"
              xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Font.ColorIndex = 11
            End If
            
            lSubTotalTicket = lSubTotalTicket + CLng(xlSheet.Cells(lFila, 4))
        
          Else
            xlSheet.Cells(lFila, 8) = "ACUM.EXTORNADA"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalTicket, "##,##0") + " Tickets"
      
        lTotalTicket = lTotalTicket + lSubTotalTicket
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 8)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalTicket, "##,##0") + " Tickets"
  
  End If
  
  ReporteAcumulacionTicketFecha = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteAcumulacionTicketCliente(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalTicket As Long
  Dim lTotalTicket As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteAcumulacionTicketCliente = False
  
  sSQL = "SELECT DISTINCT a.cClieCode, sClieApel + ' ' + sClieName AS sName " + _
         "FROM Acumulacion_Ticket a, Cliente b " + _
         "WHERE a.cClieCode = b.cClieCode AND " + _
         "FORMAT(dAcumDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dAcumDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 2"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalTicket = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      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 = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Merge
      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 = LeerCampo(ADORS!sName)
    
      lFila = lFila + 1
    
      sSQL = "SELECT * " + _
             "FROM Acumulacion_Ticket " + _
             "WHERE cClieCode = $ AND " + _
             "FORMAT(dAcumDate, 'yyyy/mm/dd') >= '$' AND " + _
             "FORMAT(dAcumDate, 'yyyy/mm/dd') <= '$' " + _
             "Order by dAcumDate DESC"
      sSQL = VBsprintf(sSQL, LeerCampo(ADORS!cClieCode), _
             Format(dtpFInicio.Value, "yyyy/mm/dd"), _
             Format(dtpFFin.Value, "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalTicket = 0
      
      If lRegistros <> 0 Then
        
        '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 m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dAcumDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = Format(LeerCampo(ADORS1!nTickCant), "##,##0")
          xlSheet.Cells(lFila, 4) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 6) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
        
            If LeerCampo(ADORS1!cAjusFlag) <> CStr(kSI) Then
              xlSheet.Cells(lFila, 7) = "ACUMULACION"
            Else
              xlSheet.Cells(lFila, 7) = "AJUSTE"
              xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Font.ColorIndex = 11
            End If
            
            lSubTotalTicket = lSubTotalTicket + CLng(xlSheet.Cells(lFila, 3))
        
          Else
            xlSheet.Cells(lFila, 7) = "ACUM.EXTORNADA"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        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 = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalTicket, "##,##0") + " Tickets"
      
        lTotalTicket = lTotalTicket + lSubTotalTicket
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    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 = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalTicket, "##,##0") + " Tickets"
  
  End If
  
  ReporteAcumulacionTicketCliente = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteCanje() As Boolean

  'Genera Reporte Canje de Premios por Fecha
  
  On Error GoTo LineaError
  
  Dim xlApp As Excel.Application
  Dim xlBook As Excel.Workbook
  Dim xlSheet1 As Excel.Worksheet
  Dim xlSheet2 As Excel.Worksheet
  Dim xlSheetTemp As Excel.Worksheet
  
  Dim lFila As Long
  
  ReporteCanje = False
  
  cmdMensaje.Visible = True
  
  Set xlApp = CreateObject("excel.application")
  Set xlBook = xlApp.Workbooks.Add
  Set xlSheet1 = xlBook.Worksheets.Add
  Set xlSheet2 = xlBook.Worksheets.Add
  
  xlSheet1.Name = "Puntos"
  xlSheet2.Name = "Tickets"
  
  xlBook.Application.DisplayAlerts = False
  
  For Each xlSheetTemp In xlBook.Worksheets
    If xlSheetTemp.Name <> xlSheet1.Name And xlSheetTemp.Name <> xlSheet2.Name Then
      xlSheetTemp.Delete
    End If
  Next xlSheetTemp
  
  xlBook.Application.DisplayAlerts = True
  
   'Formato Página
  xlSheet1.PageSetup.Orientation = xlLandscape
  xlSheet1.PageSetup.LeftMargin = Application.InchesToPoints(0.5)
  xlSheet1.PageSetup.RightMargin = Application.InchesToPoints(0.5)
  xlSheet1.PageSetup.TopMargin = Application.InchesToPoints(0.5)
  xlSheet1.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
  xlSheet1.PageSetup.HeaderMargin = Application.InchesToPoints(0.1)
  xlSheet1.PageSetup.FooterMargin = Application.InchesToPoints(0.1)
  xlSheet1.PageSetup.PrintTitleRows = xlSheet1.Rows("1:5").Address
  
  xlSheet2.PageSetup.Orientation = xlLandscape
  xlSheet2.PageSetup.LeftMargin = Application.InchesToPoints(0.5)
  xlSheet2.PageSetup.RightMargin = Application.InchesToPoints(0.5)
  xlSheet2.PageSetup.TopMargin = Application.InchesToPoints(0.5)
  xlSheet2.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
  xlSheet2.PageSetup.HeaderMargin = Application.InchesToPoints(0.1)
  xlSheet2.PageSetup.FooterMargin = Application.InchesToPoints(0.1)
  xlSheet2.PageSetup.PrintTitleRows = xlSheet1.Rows("1:5").Address
    
  'Cabecera / Pie de Página
  xlSheet1.PageSetup.LeftHeader = "&6Moy Park"
  xlSheet1.PageSetup.RightHeader = "&6" + "Sistema de Afiliación de Clientes"
  xlSheet1.PageSetup.RightFooter = "&6página &P"
  
  xlSheet2.PageSetup.LeftHeader = "&6Moy Park"
  xlSheet2.PageSetup.RightHeader = "&6" + "Sistema de Afiliación de Clientes"
  xlSheet2.PageSetup.RightFooter = "&6página &P"
  
  If Not ReporteCanjePunto(xlSheet1) Then GoTo LineaError1
  If Not ReporteCanjeTicket(xlSheet2) Then GoTo LineaError1
  
  'Mostrar
  xlApp.WindowState = xlMaximized
  xlApp.Visible = True
  
  ReporteCanje = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
LineaError1:
  
  On Error Resume Next

  xlBook.Close False
  xlApp.Quit
  
Salir:

  On Error Resume Next
  
  Set xlSheetTemp = Nothing
  Set xlSheet1 = Nothing
  Set xlBook = Nothing
  Set xlApp = Nothing
  
  cmdMensaje.Visible = False
  
End Function

Private Function ReporteCanjePunto(xlSheet As Excel.Worksheet) As Boolean

  'Inserta la parte de Títulos y SubTitulos
  
  On Error GoTo LineaError
  
  Dim lFila As Long
  Dim lColumna As Long
  
  ReporteCanjePunto = False
  
  'Columna
  
  If optGrupo(kGRUPO1).Value Then
  
    xlSheet.Columns(1).ColumnWidth = 7
    xlSheet.Columns(2).ColumnWidth = 8.5
    xlSheet.Columns(3).ColumnWidth = 26
    xlSheet.Columns(4).ColumnWidth = 20
    xlSheet.Columns(5).ColumnWidth = 8.5
    xlSheet.Columns(6).ColumnWidth = 8.5
    xlSheet.Columns(7).ColumnWidth = 12
    xlSheet.Columns(8).ColumnWidth = 13
    xlSheet.Columns(9).ColumnWidth = 12
    xlSheet.Columns(10).ColumnWidth = 15
    
    lColumna = 10
    
  Else
  
    xlSheet.Columns(1).ColumnWidth = 13
    xlSheet.Columns(2).ColumnWidth = 8.5
    xlSheet.Columns(3).ColumnWidth = 40
    xlSheet.Columns(4).ColumnWidth = 8.5
    xlSheet.Columns(5).ColumnWidth = 8.5
    xlSheet.Columns(6).ColumnWidth = 12
    xlSheet.Columns(7).ColumnWidth = 13
    xlSheet.Columns(8).ColumnWidth = 12
    xlSheet.Columns(9).ColumnWidth = 15
    
    
    lColumna = 9
    
  End If
  
  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, lColumna)).Merge
  xlSheet.Range(xlSheet.Cells(lFila + 1, 1), xlSheet.Cells(lFila + 1, lColumna)).Merge
  
  xlSheet.Cells(lFila, 1).Value = "CANJE DE PUNTOS"
  xlSheet.Cells(lFila + 1, 1).Value = "DEL " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " AL " + Format(dtpFFin.Value, "dd/mm/yyyy")
  
  lFila = lFila + 4
   
  'SubTítulo
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).NumberFormat = "@"
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Bold = True
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Size = 8
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).HorizontalAlignment = xlCenter
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.LineStyle = xlContinuous
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.Weight = 2
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeTop).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeBottom).Weight = 3
  xlSheet.Cells(lFila, 1).Borders(xlEdgeLeft).Weight = 3
  xlSheet.Cells(lFila, lColumna).Borders(xlEdgeRight).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.ColorIndex = 15
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.Pattern = xlSolid
  
  If optGrupo(kGRUPO1).Value Then
    xlSheet.Cells(lFila, 1).Value = "Hora"
    xlSheet.Cells(lFila, 2).Value = "Tarjeta"
    xlSheet.Cells(lFila, 3).Value = "Cliente"
    xlSheet.Cells(lFila, 4).Value = "Premio"
    xlSheet.Cells(lFila, 5).Value = "Cantidad"
    xlSheet.Cells(lFila, 6).Value = "Ptos.Canj."
    xlSheet.Cells(lFila, 7).Value = "Usuario"
    xlSheet.Cells(lFila, 8).Value = "Fecha Extorno"
    xlSheet.Cells(lFila, 9).Value = "Usuar.Extor."
    xlSheet.Cells(lFila, 10).Value = "Tipo"
  Else
    xlSheet.Cells(lFila, 1).Value = "Fecha Acum."
    xlSheet.Cells(lFila, 2).Value = "Tarjeta"
    xlSheet.Cells(lFila, 3).Value = IIf(optGrupo(kGRUPO2).Value, "Premio", "Cliente")
    xlSheet.Cells(lFila, 4).Value = "Cantidad"
    xlSheet.Cells(lFila, 5).Value = "Ptos.Canj."
    xlSheet.Cells(lFila, 6).Value = "Usuario"
    xlSheet.Cells(lFila, 7).Value = "Fecha Extorno"
    xlSheet.Cells(lFila, 8).Value = "Usuar.Extor."
    xlSheet.Cells(lFila, 9).Value = "Tipo"
  End If
  
  lFila = lFila + 2
  
  If optGrupo(kGRUPO1).Value Then
    If Not ReporteCanjePuntoFecha(xlSheet, lFila) Then Exit Function
  ElseIf optGrupo(kGRUPO2).Value Then
    If Not ReporteCanjePuntoCliente(xlSheet, lFila) Then Exit Function
  Else
    If Not ReporteCanjePuntoPremio(xlSheet, lFila) Then Exit Function
  End If
  
  ReporteCanjePunto = True
    
  Exit Function
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Function

Private Function ReporteCanjePuntoFecha(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalPunto As Long
  Dim lTotalPunto As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteCanjePuntoFecha = False
  
  sSQL = "SELECT DISTINCT FORMAT(dCanjDate, 'yyyy/mm/dd') AS dFecha " + _
         "FROM Canje_Punto " + _
         "WHERE FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 1 DESC"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalPunto = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = Format(LeerCampo(ADORS!dFecha), "dd/mm/yyyy")
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sPremDesc, sClieApel, sClieName " + _
             "FROM Canje_Punto a, Premio_Punto b, Cliente c " + _
             "WHERE a.cPremCode = b.cPremCode AND " + _
             "a.cClieCode = c.cClieCode AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') = '$' " + _
             "Order by sClieApel + ' ' + sClieName, sPremDesc, dCanjDate DESC"
      sSQL = VBsprintf(sSQL, Format(LeerCampo(ADORS!dFecha), "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalPunto = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 5), xlSheet.Cells(lFila + lRegistros - 1, 6)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 5), xlSheet.Cells(lFila + lRegistros - 1, 6)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).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, 10), xlSheet.Cells(lFila + lRegistros - 1, 10)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dCanjDate), "hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sClieApel) + " " + LeerCampo(ADORS1!sClieName)
          xlSheet.Cells(lFila, 4) = LeerCampo(ADORS1!sPremDesc)
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!nPremCant), "##,##0")
          xlSheet.Cells(lFila, 6) = Format(LeerCampo(ADORS1!nPuntCant), "##,##0")
          xlSheet.Cells(lFila, 7) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 8) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 9) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
            xlSheet.Cells(lFila, 10) = "CANJE"
            lSubTotalPunto = lSubTotalPunto + CLng(xlSheet.Cells(lFila, 6))
          Else
            xlSheet.Cells(lFila, 10) = "CANJE EXTORNADO"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalPunto, "##,##0") + " Puntos Canjeados"
      
        lTotalPunto = lTotalPunto + lSubTotalPunto
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalPunto, "##,##0") + " Puntos Canjeados"
  
  End If
  
  ReporteCanjePuntoFecha = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteCanjePuntoCliente(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalPunto As Long
  Dim lTotalPunto As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteCanjePuntoCliente = False
  
  sSQL = "SELECT DISTINCT a.cClieCode, sClieApel + ' ' + sClieName AS sName " + _
         "FROM Canje_Punto a, Cliente b " + _
         "WHERE a.cClieCode = b.cClieCode AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 2"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalPunto = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = LeerCampo(ADORS!sName)
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sPremDesc " + _
             "FROM Canje_Punto a, Premio_Punto b " + _
             "WHERE a.cPremCode = b.cPremCode AND " + _
             "a.cClieCode = $ AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
             "Order by sPremDesc, dCanjDate DESC"
      sSQL = VBsprintf(sSQL, LeerCampo(ADORS!cClieCode), _
             Format(dtpFInicio.Value, "yyyy/mm/dd"), _
             Format(dtpFFin.Value, "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalPunto = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).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, 9), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dCanjDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sPremDesc)
          xlSheet.Cells(lFila, 4) = Format(LeerCampo(ADORS1!nPremCant), "##,##0")
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!nPuntCant), "##,##0")
          xlSheet.Cells(lFila, 6) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 7) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 8) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
            xlSheet.Cells(lFila, 9) = "CANJE"
            lSubTotalPunto = lSubTotalPunto + CLng(xlSheet.Cells(lFila, 5))
          Else
            xlSheet.Cells(lFila, 9) = "CANJE EXTORNADO"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalPunto, "##,##0") + " Puntos Canjeados"
      
        lTotalPunto = lTotalPunto + lSubTotalPunto
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalPunto, "##,##0") + " Puntos Canjeados"
  
  End If
  
  ReporteCanjePuntoCliente = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function
Private Function ReporteCanjePuntoPremio(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalPunto As Long
  Dim lTotalPunto As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteCanjePuntoPremio = False
  
  sSQL = "SELECT DISTINCT a.cPremCode, sPremDesc " + _
         "FROM Canje_Punto a, Premio_Punto b " + _
         "WHERE a.cPremCode = b.cPremCode AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 2"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalPunto = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = LeerCampo(ADORS!sPremDesc)
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sClieApel, sClieName " + _
             "FROM Canje_Punto a, Cliente b " + _
             "WHERE a.cClieCode = b.cClieCode AND " + _
             "a.cPremCode = $ AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
             "Order by sClieApel + ' ' + sClieName, dCanjDate DESC"
      sSQL = VBsprintf(sSQL, LeerCampo(ADORS!cPremCode), _
             Format(dtpFInicio.Value, "yyyy/mm/dd"), _
             Format(dtpFFin.Value, "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalPunto = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).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, 9), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dCanjDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sClieApel) + " " + LeerCampo(ADORS1!sClieName)
          xlSheet.Cells(lFila, 4) = Format(LeerCampo(ADORS1!nPremCant), "##,##0")
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!nPuntCant), "##,##0")
          xlSheet.Cells(lFila, 6) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 7) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 8) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
            xlSheet.Cells(lFila, 9) = "CANJE"
            lSubTotalPunto = lSubTotalPunto + CLng(xlSheet.Cells(lFila, 5))
          Else
            xlSheet.Cells(lFila, 9) = "CANJE EXTORNADO"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalPunto, "##,##0") + " Puntos Canjeados"
      
        lTotalPunto = lTotalPunto + lSubTotalPunto
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalPunto, "##,##0") + " Puntos Canjeados"
  
  End If
  
  ReporteCanjePuntoPremio = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteCanjeTicket(xlSheet As Excel.Worksheet) As Boolean

  'Inserta la parte de Títulos y SubTitulos
  
  On Error GoTo LineaError
  
  Dim lFila As Long
  Dim lColumna As Long
  
  ReporteCanjeTicket = False
  
  'Columna
  
  If optGrupo(kGRUPO1).Value Then
  
    xlSheet.Columns(1).ColumnWidth = 7
    xlSheet.Columns(2).ColumnWidth = 8.5
    xlSheet.Columns(3).ColumnWidth = 26
    xlSheet.Columns(4).ColumnWidth = 20
    xlSheet.Columns(5).ColumnWidth = 8.5
    xlSheet.Columns(6).ColumnWidth = 8.5
    xlSheet.Columns(7).ColumnWidth = 12
    xlSheet.Columns(8).ColumnWidth = 13
    xlSheet.Columns(9).ColumnWidth = 12
    xlSheet.Columns(10).ColumnWidth = 15
    
    lColumna = 10
    
  Else
  
    xlSheet.Columns(1).ColumnWidth = 13
    xlSheet.Columns(2).ColumnWidth = 8.5
    xlSheet.Columns(3).ColumnWidth = 40
    xlSheet.Columns(4).ColumnWidth = 8.5
    xlSheet.Columns(5).ColumnWidth = 8.5
    xlSheet.Columns(6).ColumnWidth = 12
    xlSheet.Columns(7).ColumnWidth = 13
    xlSheet.Columns(8).ColumnWidth = 12
    xlSheet.Columns(9).ColumnWidth = 15
    
    
    lColumna = 9
    
  End If
  
  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, lColumna)).Merge
  xlSheet.Range(xlSheet.Cells(lFila + 1, 1), xlSheet.Cells(lFila + 1, lColumna)).Merge
  
  xlSheet.Cells(lFila, 1).Value = "CANJE DE TICKETS"
  xlSheet.Cells(lFila + 1, 1).Value = "DEL " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " AL " + Format(dtpFFin.Value, "dd/mm/yyyy")
  
  lFila = lFila + 4
   
  'SubTítulo
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).NumberFormat = "@"
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Bold = True
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Size = 8
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).HorizontalAlignment = xlCenter
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.LineStyle = xlContinuous
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.Weight = 2
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeTop).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeBottom).Weight = 3
  xlSheet.Cells(lFila, 1).Borders(xlEdgeLeft).Weight = 3
  xlSheet.Cells(lFila, lColumna).Borders(xlEdgeRight).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.ColorIndex = 15
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.Pattern = xlSolid
  
  If optGrupo(kGRUPO1).Value Then
    xlSheet.Cells(lFila, 1).Value = "Hora"
    xlSheet.Cells(lFila, 2).Value = "Tarjeta"
    xlSheet.Cells(lFila, 3).Value = "Cliente"
    xlSheet.Cells(lFila, 4).Value = "Premio"
    xlSheet.Cells(lFila, 5).Value = "Cantidad"
    xlSheet.Cells(lFila, 6).Value = "Tickets.Canj."
    xlSheet.Cells(lFila, 7).Value = "Usuario"
    xlSheet.Cells(lFila, 8).Value = "Fecha Extorno"
    xlSheet.Cells(lFila, 9).Value = "Usuar.Extor."
    xlSheet.Cells(lFila, 10).Value = "Tipo"
  Else
    xlSheet.Cells(lFila, 1).Value = "Fecha Acum."
    xlSheet.Cells(lFila, 2).Value = "Tarjeta"
    xlSheet.Cells(lFila, 3).Value = IIf(optGrupo(kGRUPO2).Value, "Premio", "Cliente")
    xlSheet.Cells(lFila, 4).Value = "Cantidad"
    xlSheet.Cells(lFila, 5).Value = "Tickets.Canj."
    xlSheet.Cells(lFila, 6).Value = "Usuario"
    xlSheet.Cells(lFila, 7).Value = "Fecha Extorno"
    xlSheet.Cells(lFila, 8).Value = "Usuar.Extor."
    xlSheet.Cells(lFila, 9).Value = "Tipo"
  End If
  
  lFila = lFila + 2
  
  If optGrupo(kGRUPO1).Value Then
    If Not ReporteCanjeTicketFecha(xlSheet, lFila) Then Exit Function
  ElseIf optGrupo(kGRUPO2).Value Then
    If Not ReporteCanjeTicketCliente(xlSheet, lFila) Then Exit Function
  Else
    If Not ReporteCanjeTicketPremio(xlSheet, lFila) Then Exit Function
  End If
  
  ReporteCanjeTicket = True
    
  Exit Function
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Function

Private Function ReporteCanjeTicketFecha(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalTicket As Long
  Dim lTotalTicket As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteCanjeTicketFecha = False
  
  sSQL = "SELECT DISTINCT FORMAT(dCanjDate, 'yyyy/mm/dd') AS dFecha " + _
         "FROM Canje_Ticket " + _
         "WHERE FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 1 DESC"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalTicket = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = Format(LeerCampo(ADORS!dFecha), "dd/mm/yyyy")
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sPremDesc, sClieApel, sClieName " + _
             "FROM Canje_Ticket a, Premio_Ticket b, Cliente c " + _
             "WHERE a.cPremCode = b.cPremCode AND " + _
             "a.cClieCode = c.cClieCode AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') = '$' " + _
             "Order by sClieApel + ' ' + sClieName, sPremDesc, dCanjDate DESC"
      sSQL = VBsprintf(sSQL, Format(LeerCampo(ADORS!dFecha), "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalTicket = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 5), xlSheet.Cells(lFila + lRegistros - 1, 6)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 5), xlSheet.Cells(lFila + lRegistros - 1, 6)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 10)).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, 10), xlSheet.Cells(lFila + lRegistros - 1, 10)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dCanjDate), "hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sClieApel) + " " + LeerCampo(ADORS1!sClieName)
          xlSheet.Cells(lFila, 4) = LeerCampo(ADORS1!sPremDesc)
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!nPremCant), "##,##0")
          xlSheet.Cells(lFila, 6) = Format(LeerCampo(ADORS1!nTickCant), "##,##0")
          xlSheet.Cells(lFila, 7) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 8) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 9) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
            xlSheet.Cells(lFila, 10) = "CANJE"
            lSubTotalTicket = lSubTotalTicket + CLng(xlSheet.Cells(lFila, 6))
          Else
            xlSheet.Cells(lFila, 10) = "CANJE EXTORNADO"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalTicket, "##,##0") + " Tickets Canjeados"
      
        lTotalTicket = lTotalTicket + lSubTotalTicket
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 10)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalTicket, "##,##0") + " Tickets Canjeados"
  
  End If
  
  ReporteCanjeTicketFecha = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteCanjeTicketCliente(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalTicket As Long
  Dim lTotalTicket As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteCanjeTicketCliente = False
  
  sSQL = "SELECT DISTINCT a.cClieCode, sClieApel + ' ' + sClieName AS sName " + _
         "FROM Canje_Ticket a, Cliente b " + _
         "WHERE a.cClieCode = b.cClieCode AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 2"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalTicket = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = LeerCampo(ADORS!sName)
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sPremDesc " + _
             "FROM Canje_Ticket a, Premio_Ticket b " + _
             "WHERE a.cPremCode = b.cPremCode AND " + _
             "a.cClieCode = $ AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
             "Order by sPremDesc, dCanjDate DESC"
      sSQL = VBsprintf(sSQL, LeerCampo(ADORS!cClieCode), _
             Format(dtpFInicio.Value, "yyyy/mm/dd"), _
             Format(dtpFFin.Value, "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalTicket = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).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, 9), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dCanjDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sPremDesc)
          xlSheet.Cells(lFila, 4) = Format(LeerCampo(ADORS1!nPremCant), "##,##0")
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!nTickCant), "##,##0")
          xlSheet.Cells(lFila, 6) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 7) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 8) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
            xlSheet.Cells(lFila, 9) = "CANJE"
            lSubTotalTicket = lSubTotalTicket + CLng(xlSheet.Cells(lFila, 5))
          Else
            xlSheet.Cells(lFila, 9) = "CANJE EXTORNADO"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalTicket, "##,##0") + " Tickets Canjeados"
      
        lTotalTicket = lTotalTicket + lSubTotalTicket
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalTicket, "##,##0") + " Tickets Canjeados"
  
  End If
  
  ReporteCanjeTicketCliente = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function
Private Function ReporteCanjeTicketPremio(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotalTicket As Long
  Dim lTotalTicket As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteCanjeTicketPremio = False
  
  sSQL = "SELECT DISTINCT a.cPremCode, sPremDesc " + _
         "FROM Canje_Ticket a, Premio_Ticket b " + _
         "WHERE a.cPremCode = b.cPremCode AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 2"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotalTicket = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = LeerCampo(ADORS!sPremDesc)
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sClieApel, sClieName " + _
             "FROM Canje_Ticket a, Cliente b " + _
             "WHERE a.cClieCode = b.cClieCode AND " + _
             "a.cPremCode = $ AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
             "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
             "Order by sClieApel + ' ' + sClieName, dCanjDate DESC"
      sSQL = VBsprintf(sSQL, LeerCampo(ADORS!cPremCode), _
             Format(dtpFInicio.Value, "yyyy/mm/dd"), _
             Format(dtpFFin.Value, "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotalTicket = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 4), xlSheet.Cells(lFila + lRegistros - 1, 5)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 9)).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, 9), xlSheet.Cells(lFila + lRegistros - 1, 9)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dCanjDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!nTarjNumb)
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sClieApel) + " " + LeerCampo(ADORS1!sClieName)
          xlSheet.Cells(lFila, 4) = Format(LeerCampo(ADORS1!nPremCant), "##,##0")
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!nTickCant), "##,##0")
          xlSheet.Cells(lFila, 6) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 7) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 8) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
            xlSheet.Cells(lFila, 9) = "CANJE"
            lSubTotalTicket = lSubTotalTicket + CLng(xlSheet.Cells(lFila, 5))
          Else
            xlSheet.Cells(lFila, 9) = "CANJE EXTORNADO"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotalTicket, "##,##0") + " Tickets Canjeados"
      
        lTotalTicket = lTotalTicket + lSubTotalTicket
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 9)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotalTicket, "##,##0") + " Tickets Canjeados"
  
  End If
  
  ReporteCanjeTicketPremio = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteIngreso() As Boolean

  'Genera Reporte Ingreso de Premios por Fecha
  
  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 lColumna As Long
  
  ReporteIngreso = False
  
  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
  
  If optGrupo(kGRUPO1).Value Then
  
    xlSheet.Columns(1).ColumnWidth = 7
    xlSheet.Columns(2).ColumnWidth = 28
    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 = 16
    
    lColumna = 7
    
  Else
  
    xlSheet.Columns(1).ColumnWidth = 15
    xlSheet.Columns(2).ColumnWidth = 15
    xlSheet.Columns(3).ColumnWidth = 15
    xlSheet.Columns(4).ColumnWidth = 15
    xlSheet.Columns(5).ColumnWidth = 15
    xlSheet.Columns(6).ColumnWidth = 16
    
    lColumna = 6
    
  End If
  
  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, lColumna)).Merge
  xlSheet.Range(xlSheet.Cells(lFila + 1, 1), xlSheet.Cells(lFila + 1, lColumna)).Merge
  
  xlSheet.Cells(lFila, 1).Value = "INGRESO DE PREMIOS (TICKETS)"
  xlSheet.Cells(lFila + 1, 1).Value = "DEL " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " AL " + Format(dtpFFin.Value, "dd/mm/yyyy")
  
  lFila = lFila + 4
   
  'SubTítulo
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).NumberFormat = "@"
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Bold = True
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Font.Size = 8
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).HorizontalAlignment = xlCenter
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.LineStyle = xlContinuous
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders.Weight = 2
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeTop).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Borders(xlEdgeBottom).Weight = 3
  xlSheet.Cells(lFila, 1).Borders(xlEdgeLeft).Weight = 3
  xlSheet.Cells(lFila, lColumna).Borders(xlEdgeRight).Weight = 3
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.ColorIndex = 15
  xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, lColumna)).Interior.Pattern = xlSolid
  
  If optGrupo(kGRUPO1).Value Then
    xlSheet.Cells(lFila, 1).Value = "Hora"
    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"
  Else
    xlSheet.Cells(lFila, 1).Value = "Fecha Ingreso"
    xlSheet.Cells(lFila, 2).Value = "Cantidad"
    xlSheet.Cells(lFila, 3).Value = "Usuario"
    xlSheet.Cells(lFila, 4).Value = "Fecha Extorno"
    xlSheet.Cells(lFila, 5).Value = "Usuar.Extor."
    xlSheet.Cells(lFila, 6).Value = "Tipo"
  End If
  
  lFila = lFila + 2
  
  If optGrupo(kGRUPO1).Value Then
    If Not ReporteIngresoFecha(xlSheet, lFila) Then GoTo LineaError1
  Else
    If Not ReporteIngresoPremio(xlSheet, lFila) Then GoTo LineaError1
  End If
  
  'Mostrar
  xlApp.WindowState = xlMaximized
  xlApp.Visible = True
  
  ReporteIngreso = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
LineaError1:
  
  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
  
End Function

Private Function ReporteIngresoFecha(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotal As Long
  Dim lTotal As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteIngresoFecha = False
  
  sSQL = "SELECT DISTINCT FORMAT(dIngrDate, 'yyyy/mm/dd') AS dFecha " + _
         "FROM Ingreso_Premio_Ticket " + _
         "WHERE FORMAT(dIngrDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dIngrDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 1 DESC"
  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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotal = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      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 = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Merge
      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 = Format(LeerCampo(ADORS!dFecha), "dd/mm/yyyy")
    
      lFila = lFila + 1
    
      sSQL = "SELECT a.*, sPremDesc " + _
             "FROM Ingreso_Premio_Ticket a, Premio_Ticket b " + _
             "WHERE a.cPremCode = b.cPremCode AND " + _
             "FORMAT(dIngrDate, 'yyyy/mm/dd') = '$' " + _
             "Order by sPremDesc, dIngrDate Desc"
      sSQL = VBsprintf(sSQL, Format(LeerCampo(ADORS!dFecha), "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotal = 0
      
      If lRegistros <> 0 Then
        
        '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 m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dIngrDate), "hh:mm")
          xlSheet.Cells(lFila, 2) = LeerCampo(ADORS1!sPremDesc)
          xlSheet.Cells(lFila, 3) = Format(LeerCampo(ADORS1!nIngrCant), "##,##0")
          xlSheet.Cells(lFila, 4) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 5) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 6) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
        
            If LeerCampo(ADORS1!cAjusFlag) <> CStr(kSI) Then
              xlSheet.Cells(lFila, 7) = "INGRESO"
            Else
              xlSheet.Cells(lFila, 7) = "AJUSTE"
              xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Font.ColorIndex = 11
            End If
            
            lSubTotal = lSubTotal + CLng(xlSheet.Cells(lFila, 3))
        
          Else
            xlSheet.Cells(lFila, 7) = "INGR.EXTORNADO"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        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 = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotal, "##,##0") + " Premios"
      
        lTotal = lTotal + lSubTotal
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    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 = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 7)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotal, "##,##0") + " Premios"
  
  End If
  
  ReporteIngresoFecha = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function

Private Function ReporteIngresoPremio(xlSheet As Excel.Worksheet, lFila As Long) As Boolean

  'Inserta la parte de datos en el reporte
  
  On Error GoTo LineaError
  
  Dim lRegistrosGrupo As Long
  Dim lRegistros As Long
  Dim l As Long
  Dim m As Long
  
  Dim lSubTotal As Long
  Dim lTotal As Long
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim ADORS1 As ADODB.Recordset
  
  ReporteIngresoPremio = False
  
  sSQL = "SELECT DISTINCT a.cPremCode, sPremDesc " + _
         "FROM Premio_Ticket a, Ingreso_Premio_Ticket b " + _
         "WHERE a.cPremCode = b.cPremCode AND " + _
         "FORMAT(dIngrDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dIngrDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by 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
    
  lRegistrosGrupo = ADORS.RecordCount
  lTotal = 0
    
  If lRegistrosGrupo <> 0 Then
  
    For l = 1 To lRegistrosGrupo
    
      'Grupo
      xlSheet.Cells(lFila, 1).NumberFormat = "@"
      xlSheet.Cells(lFila, 1).Font.Bold = True
      xlSheet.Cells(lFila, 1).Font.Size = 8
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Borders.LineStyle = xlContinuous
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Borders.Weight = 3
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Merge
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Interior.ColorIndex = 15
      xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Interior.Pattern = xlSolid
    
      xlSheet.Cells(lFila, 1).Value = LeerCampo(ADORS!sPremDesc)
    
      lFila = lFila + 1
    
      sSQL = "SELECT * " + _
             "FROM Ingreso_Premio_Ticket " + _
             "WHERE cPremCode = $ AND " + _
             "FORMAT(dIngrDate, 'yyyy/mm/dd') >= '$' AND " + _
             "FORMAT(dIngrDate, 'yyyy/mm/dd') <= '$' " + _
             "Order by dIngrDate Desc"
      sSQL = VBsprintf(sSQL, LeerCampo(ADORS!cPremCode), _
             Format(dtpFInicio.Value, "yyyy/mm/dd"), _
             Format(dtpFFin.Value, "yyyy/mm/dd"))
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS1) Then GoTo Salir
    
      lRegistros = ADORS1.RecordCount
      lSubTotal = 0
      
      If lRegistros <> 0 Then
        
        'Datos
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 6)).NumberFormat = "@"
        xlSheet.Range(xlSheet.Cells(lFila, 2), xlSheet.Cells(lFila + lRegistros - 1, 2)).NumberFormat = "##,##0"
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 6)).Font.Size = 8
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 6)).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 2), xlSheet.Cells(lFila + lRegistros - 1, 2)).HorizontalAlignment = xlRight
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 6)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila + lRegistros - 1, 6)).Borders.Weight = 2
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Borders(xlEdgeTop).Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila + lRegistros - 1, 1), xlSheet.Cells(lFila + lRegistros - 1, 6)).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, 6), xlSheet.Cells(lFila + lRegistros - 1, 6)).Borders(xlEdgeRight).Weight = 3
    
        For m = 1 To lRegistros
      
          xlSheet.Cells(lFila, 1) = Format(LeerCampo(ADORS1!dIngrDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 2) = Format(LeerCampo(ADORS1!nIngrCant), "##,##0")
          xlSheet.Cells(lFila, 3) = LeerCampo(ADORS1!sUserDesc)
          xlSheet.Cells(lFila, 4) = Format(LeerCampo(ADORS1!dExtoDate), "dd/mm/yyyy hh:mm")
          xlSheet.Cells(lFila, 5) = LeerCampo(ADORS1!sUseEDesc)
        
          If LeerCampo(ADORS1!dExtoDate) = "" Then
        
            If LeerCampo(ADORS1!cAjusFlag) <> CStr(kSI) Then
              xlSheet.Cells(lFila, 6) = "INGRESO"
            Else
              xlSheet.Cells(lFila, 6) = "AJUSTE"
              xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Font.ColorIndex = 11
            End If
            
            lSubTotal = lSubTotal + CLng(xlSheet.Cells(lFila, 2))
        
          Else
            xlSheet.Cells(lFila, 6) = "INGR.EXTORNADO"
            xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Font.ColorIndex = 53
          End If
          
          ADORS1.MoveNext
          
          lFila = lFila + 1
      
        Next
        
        'SubTotal
        xlSheet.Cells(lFila, 1).NumberFormat = "@"
        xlSheet.Cells(lFila, 1).Font.Bold = True
        xlSheet.Cells(lFila, 1).Font.Size = 8
        xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Borders.LineStyle = xlContinuous
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Borders.Weight = 3
        xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Merge
  
        xlSheet.Cells(lFila, 1) = "SubTotal: " + Format(lSubTotal, "##,##0") + " Premios"
      
        lTotal = lTotal + lSubTotal
        
        lFila = lFila + 2
      
      End If
      
      ADORS.MoveNext
            
    Next
    
    'Total
    xlSheet.Cells(lFila, 1).NumberFormat = "@"
    xlSheet.Cells(lFila, 1).Font.Bold = True
    xlSheet.Cells(lFila, 1).Font.Size = 8
    xlSheet.Cells(lFila, 1).HorizontalAlignment = xlLeft
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Borders.LineStyle = xlContinuous
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Borders.Weight = 3
    xlSheet.Range(xlSheet.Cells(lFila, 1), xlSheet.Cells(lFila, 6)).Merge
  
    xlSheet.Cells(lFila, 1) = "Total: " + Format(lTotal, "##,##0") + " Premios"
  
  End If
  
  ReporteIngresoPremio = True
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Set ADORS1 = Nothing
  
End Function



