Attribute VB_Name = "MReimpresion"
Public Sub Imprimir_CierreX(Optional IntAnchoTicket As Integer = 40)
  Dim LHead1, LHead2, LHead3, LHead4, LHead5, LHead6, LHead7, LHead8, LHead9, LHead10 As String
  
' Imprimir la Cabecera
  
  LHead1 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD1)), Trim(GHEAD1))
  LHead2 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD2)), Trim(GHEAD2))
  LHead3 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD3)), Trim(GHEAD3))
  LHead4 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD4)), Trim(GHEAD4))
  LHead5 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD5)), Trim(GHEAD5))
  LHead6 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD6)), Trim(GHEAD6))
  LHead7 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD7)), Trim(GHEAD7))
  LHead8 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD8)), Trim(GHEAD8))
  LHead9 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD9)), Trim(GHEAD9))
  LHead10 = Alineacion("C", IntAnchoTicket, Len(Trim(GHEAD10)), Trim(GHEAD10))
  
  Printer.Print ""  ' El Primer Print no es Tomado en Cuenta

  If Trim(LHead1) <> Empty Then
    Printer.Print LHead1
  End If
  If Trim(LHead2) <> Empty Then
    Printer.Print LHead2
  End If
  If Trim(LHead3) <> Empty Then
    Printer.Print LHead3
  End If
  If Trim(LHead4) <> Empty Then
    Printer.Print LHead4
  End If
  If Trim(LHead5) <> Empty Then
    Printer.Print LHead5
  End If
  If Trim(LHead6) <> Empty Then
    Printer.Print LHead6
  End If
  If Trim(LHead7) <> Empty Then
    Printer.Print LHead7
  End If
  If Trim(LHead8) <> Empty Then
    Printer.Print LHead8
  End If
  If Trim(LHead9) <> Empty Then
    Printer.Print LHead9
  End If
  If Trim(LHead10) <> Empty Then
    Printer.Print LHead10
  End If
 
 ' Imprimir la Linea
     
  Dim LLinea1 As String
  
  LLinea1 = Alineacion("C", IntAnchoTicket, Len(Trim(GstrLinea1)), Trim(GstrLinea1))
  
  Dim strTitulo As String
  strTitulo = Alineacion("C", IntAnchoTicket, Len("CIERRE (X)"), "CIERRE (X)")
  Printer.Print strTitulo
  
  If Trim(LLinea1) <> Empty Then
    Printer.Print LLinea1
  End If
  
  Printer.EndDoc
End Sub


' Cargar los codigos y simbolos de monedas
Sub Cargar_Datos_Monedas(ByRef StrMdaBase As String, ByRef StrMdaCaja As String, _
                         ByRef StrSimbMdaCaja As String, ByRef StrSimbMdaExt As String, _
                         StrNroPtoVta As String)
    
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
On Error GoTo errhandler
    ' MONEDA BASE
    StrSql = "Select CURYORIG from Setup"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    ' seleciona la moneda base del sistema
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    If Not rs.EOF Then
        StrMdaBase = rs!CURYORIG
    Else
        StrMdaBase = ""
    End If
    
    If rs.State = 1 Then rs.Close
    
    ' MONEDA CAJA
    StrSql = "select CURYID from OP_SalesPointSetting where SalesPoint='" & StrNroPtoVta & "'"
    ' selecciona la moneda configurada para la caja
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    If Not rs.EOF Then
        StrMdaCaja = rs!CURYID
    Else
        StrMdaCaja = ""
    End If
    
    If rs.State = 1 Then rs.Close
    ' SIMBOLOS
    StrSql = "select DescrMoney from CURRENCY where CuryId='" & StrMdaBase & "'"
    ' selecciona el simbolo de la moneda base
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    If Not rs.EOF Then
        StrSimbMdaCaja = rs!DescrMoney
    Else
        StrSimbMdaCaja = ""
    End If
    
    If rs.State = 1 Then rs.Close
    StrSql = "select DescrMoney from CURRENCY where CuryId<>'" & StrMdaCaja & "'"
    ' selecciona el simbolo de la moneda de caja
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    If Not rs.EOF Then
        StrSimbMdaExt = rs!DescrMoney
    Else
        StrSimbMdaExt = ""
    End If
    
    'GetObjectContext.SetComplete
    
Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_OP_FACTURACION.Cargar_Datos_Monedas", Err.Description
End Sub

' colocar datos para criterios de cierre
Sub Cargar_Datos_Cierre(IntLugarVenta As Integer, StrPtoVta As String, IntTurnoActual As Integer, StrSalesPersonID As String, StrFechaProceso As String, IntCierreXCierreZ As Integer, DblTipoCambioActual As Double)
'    StrNroPtoVta = StrPtoVta
'    StrSalesPerId = StrSalesPersonID
'    StrFechaCierre = StrFechaProceso
'    IntTipoCierre = IntCierreXCierreZ
'    IntTurno = IntTurnoActual
'    IntLugar = IntLugarVenta
'    DblTipoCambio = DblTipoCambioActual
'    BlnOK = True ' inicialmente todo bien
End Sub

' Numero de  Serie de la maquina registradora
Public Function Obtener_Serie_Maq_Reg(StrNroPtoVta As String) As String
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset

   On Error GoTo errhandler

   StrSql = "Select SerialNumber from Op_Salespointsetting where salespoint='" & Trim(StrNroPtoVta) & "'"

   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic

   'Set obtenercabezeratransgrabadas = rs

   If Not rs.EOF Then
    If Not IsNull(rs!SERIALNUMBER) Then
        Obtener_Serie_Maq_Reg = Trim(rs!SERIALNUMBER)
    Else
        Obtener_Serie_Maq_Reg = ""
    End If
   Else
    Obtener_Serie_Maq_Reg = ""
   End If
   
   'GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
   
   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_Serie_Maq_Reg ", Err.Description

End Function

' Fecha de cierre
Public Function Obtener_Fecha_Cierre(StrFechaCierre As String) As String
    Obtener_Fecha_Cierre = StrFechaCierre & " " & Time
End Function

' El tipo de cambio actual
Public Function Obtener_Tipo_Cambio(StrNroPtoVta As String, StrFechaCierre As String) As Double
   Dim StrSql As String
   Dim rs As ADODB.Recordset
   Dim cmd As ADODB.Recordset

   On Error GoTo errhandler

   StrSql = "ObtenerRTipoCambio '" & StrNroPtoVta & "','" & StrFechaCierre & "'"

   Set rs = New ADODB.Recordset
   rs.CursorLocation = adUseClient
   rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic

   Set obtenercabezeratransgrabadas = rs

   If Not rs.EOF Then
    Obtener_Tipo_Cambio = IIf(IsNull(rs!Rate), 0, rs!Rate)
   Else
    Obtener_Tipo_Cambio = 0
   End If

   'GetObjectContext.SetComplete
   Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_Tipo_Cambio", Err.Description
End Function

Sub Obtener_GranTotal(IntLugar As Integer, IntTipoCierre As Integer, _
                      ByRef DblGranTotal As Double, DblVtaTotal As Double, _
                      StrNroPtoVta As String, StrFechaCierre As String)
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
On Error GoTo errhandler
    
    StrSql = "Obtener_GranTotal '" & StrNroPtoVta & "','" & StrFechaCierre & "'"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        DblGranTotal = IIf(IsNull(rs!TOTZETA), 0, rs!TOTZETA)
    Else
        DblGranTotal = 0
    End If
    
    If IntTipoCierre = 1 Then  ' CIERRE X
        DblGranTotal = DblGranTotal
    End If
    If IntTipoCierre = 2 Then  ' CIERRE Z
        DblGranTotal = DblGranTotal + DblVtaTotal
    End If
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
   'GetObjectContext.SetAbort
   
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_GranTotal", Err.Description
End Sub

' Numero total de cierres zetas
Sub Obtener_NroZetas(IntTipoCierre As Integer, StrNroPtoVta As String, ByRef IntNroZeta As Integer, StrFechaCierre As String)
    Dim rs As ADODB.Recordset
    Dim StrSql As String

On Error GoTo errhandler
    
    StrSql = "SELECT NBRZETA FROM OP_ZETA WHERE SALESPOINT='" & StrNroPtoVta & "' AND DATEPROCESALES<='" & StrFechaCierre & "' ORDER BY DATEPROCESALES DESC"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        IntNroZeta = IIf(IsNull(rs!NBRZETA), 1, rs!NBRZETA + 1)
    Else
        IntNroZeta = 1
    End If
    
    If IntTipoCierre = 1 Then ' Cierre X
        IntNroZeta = IntNroZeta - 1
    End If
    'GetObjectContext.SetComplete
    
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_NroZetas", Err.Description
End Sub

' Detalle de cierre
Function Obtener_Detalle_Cierre(IntLugar As Integer, IntTipoCierre As Integer) As Recordset
    Dim StrSql As String
    Dim rs As ADODB.Recordset
    
    If IntLugar = 1 Then ' Tienda
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = "OP_CierreX_Market_Detalles '" & StrNroPtoVta & "','" & StrSalesPerId & "','" & StrFechaCierre & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = "OP_RCierreZ_Detalles '" & StrNroPtoVta & "','" & StrFechaCierre & "'"
        End If
    End If
    If IntLugar = 2 Then ' Playa
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = "OP_CierreX_Combustible_Detalles '" & StrNroPtoVta & "'," & IntTurno & ",'" & StrFechaCierre & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = "OP_RCierreZ_Detalles '" & StrNroPtoVta & "','" & StrFechaCierre & "'"
        End If
    End If
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set Obtener_Detalle_Cierre = rs
    
    'GetObjectContext.SetComplete
    Exit Function
    
On Error GoTo errhandler

errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_Detalle_Cierre", Err.Description
End Function

 ' cargar las variables que detallan la cabecera del cierre
Sub Cabecera_Cierre(IntLugar As Integer, IntTipoCierre As Integer, IntTurno As Integer, _
                    StrFechaCierre As String, StrNroPtoVta As String, StrSalesPerId As String, _
                    ByRef StrSerieMaqReg As String, _
                    ByRef StrFecha As String, _
                    ByRef IntNroTransacciones As Integer, _
                    ByRef DblTicketBolIni As Double, ByRef DblTicketBolFin As Double, _
                    ByRef DblTicketFacIni As Double, ByRef DblTicketFacFin As Double, _
                    StrMdaBase As String, StrMdaCaja As String, _
                    ByRef DblValorVta As Double, ByRef DblVtaNoAfecta As Double, _
                    ByRef DblIGV As Double, ByRef DblVtaTotal As Double, _
                    ByRef IntNroTicketAnul As Integer, ByRef DblTotalTicketAnul As Double, _
                    ByRef DblGranTotal As Double, ByRef IntNroZeta As Integer)
On Error GoTo errhandler
    ' serie de maquina registradora
    StrSerieMaqReg = Obtener_Serie_Maq_Reg(StrNroPtoVta)
    ' fecha de proceso (jalada del servidor)
    StrFecha = Obtener_Fecha_Cierre(StrFechaCierre)
    
    Call Obtener_RDatos_Transacciones(IntLugar, StrNroPtoVta, StrSalesPerId, IntTurno, _
                                     IntTipoCierre, Format(StrFechaCierre, "yyyyMMdd"), IntNroTransacciones, DblTicketBolIni, DblTicketBolFin, _
                                     DblTicketFacIni, DblTicketFacFin)
                                     
    Call Obtener_Datos_Ventas(IntLugar, IntTipoCierre, StrNroPtoVta, _
                              StrSalesPerId, IntTurno, Format(StrFechaCierre, "yyyyMMdd"), _
                              StrMdaBase, StrMdaCaja, DblValorVta, _
                              DblVtaNoAfecta, DblIGV, DblVtaTotal)
    
    Call Obtener_Datos_Ventas_Anulados(IntLugar, IntTipoCierre, Format(StrFechaCierre, "yyyyMMdd"), _
                                       StrMdaBase, StrMdaCaja, StrNroPtoVta, IntTurno, StrSalesPerId, IntNroTicketAnul, DblTotalTicketAnul)
    
    ' el total zeta acumulado
    Call Obtener_GranTotal(IntLugar, IntTipoCierre, DblGranTotal, DblVtaTotal, StrNroPtoVta, Format(StrFechaCierre, "yyyyMMdd"))
    ' el numero de zeta correspondiente
    Call Obtener_NroZetas(IntTipoCierre, StrNroPtoVta, IntNroZeta, Format(StrFechaCierre, "yyyyMMdd"))
        
    'GetObjectContext.SetComplete
        
    Exit Sub
errhandler:

    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_OP_FACTURACION.Cabecera_Cierre", Err.Description
End Sub

Sub Obtener_Datos_Ventas_Anulados(IntLugar As Integer, IntTipoCierre As Integer, StrFechaCierre As String, _
                                  StrMdaBase As String, StrMdaCaja As String, StrNroPtoVta As String, IntTurno As Integer, _
                                  StrSalesPerId As String, ByRef IntNroTicketAnul As Integer, _
                                  ByRef DblTotalTicketAnul As Double)
    Dim rs As ADODB.Recordset
    Dim StrSql As String

On Error GoTo errhandler

    If IntLugar = 1 Then ' Tienda
        If IntTipoCierre = 1 Then ' Cierre X
             StrSql = " OP_CierreX_Market_TicketsAnul '" & StrNroPtoVta & "','" & StrSalesPerId & "','" & StrFechaCierre & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
             StrSql = " OP_RCierreZ_TicketsAnul '" & StrNroPtoVta & "','" & StrFechaCierre & "'"
        End If
    End If
    If IntLugar = 2 Then ' Playa
        If IntTipoCierre = 1 Then ' Cierre X
             StrSql = " OP_CierreX_Combustible_TicketsAnul '" & StrNroPtoVta & "'," & IntTurno & ",'" & StrFechaCierre & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
             StrSql = " OP_RCierreZ_TicketsAnul '" & StrNroPtoVta & "','" & StrFechaCierre & "'"
        End If
    End If
    
    Set rs = New ADODB.Recordset
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        ' numero de transacciones anuladas
        IntNroTicketAnul = IIf(IsNull(rs!NTICKETSANUL), 0, rs!NTICKETSANUL)
        ' total de las transacciones anuladas
        If StrMdaBase = StrMdaCaja Then
            DblTotalTicketAnul = IIf(IsNull(rs!TOTALANULPEN), 0, rs!TOTALANULPEN)
        Else
            DblTotalTicketAnul = IIf(IsNull(rs!TOTALANULUSD), 0, rs!TOTALANULUSD)
        End If
    Else
        ' numero de transacciones anuladas
        IntNroTicketAnul = 0
        ' total de las transacciones anuladas
        DblTotalTicketAnul = 0
    End If
    
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_Datos_Ventas_Anulados", Err.Description
End Sub

Sub Obtener_Datos_Ventas(IntLugar As Integer, IntTipoCierre As Integer, StrNroPtoVta As String, _
                         StrSalesPerId As String, IntTurno As Integer, StrFechaCierre As String, _
                         StrMdaBase As String, StrMdaCaja As String, ByRef DblValorVta As Double, _
                         ByRef DblVtaNoAfecta As Double, ByRef DblIGV As Double, ByRef DblVtaTotal As Double)
    Dim rs As ADODB.Recordset
    Dim StrSql As String

On Error GoTo errhandler

    If IntLugar = 1 Then ' Tienda
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = " OP_CierreX_Market_Montos '" & StrNroPtoVta & "','" & StrSalesPerId & "','" & StrFechaCierre & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = " OP_RCierreZ_Montos '" & StrNroPtoVta & "','" & StrFechaCierre & "'"
        End If
    End If
    If IntLugar = 2 Then ' Playa
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = " OP_CierreX_Combustible_Montos '" & StrNroPtoVta & "'," & IntTurno & ",'" & StrFechaCierre & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = " OP_RCierreZ_Montos '" & StrNroPtoVta & "','" & StrFechaCierre & "'"
        End If
    End If
    
    Set rs = New ADODB.Recordset
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        If StrMdaBase = StrMdaCaja Then
            ' total de la venta (sin IGV)
            DblValorVta = IIf(IsNull(rs!SUBTOTALPEN), 0, rs!SUBTOTALPEN)
            ' total de la venta no afecta al IGV
            DblVtaNoAfecta = IIf(IsNull(rs!NOAFECTOPEN), 0, rs!NOAFECTOPEN)
            ' total de IGV
            DblIGV = IIf(IsNull(rs!TAXIGVPEN), 0, rs!TAXIGVPEN)
            ' total de la venta + IGV
            DblVtaTotal = IIf(IsNull(rs!TOTALPEN), 0, rs!TOTALPEN)
        Else
            ' total de la venta (sin IGV)
            DblValorVta = IIf(IsNull(rs!SUBTOTALUSD), 0, rs!SUBTOTALUSD)
            ' total de la venta no afecta al IGV
            DblVtaNoAfecta = IIf(IsNull(rs!NOAFECTOUSD), 0, rs!NOAFECTOUSD)
            ' total de IGV
            DblIGV = IIf(IsNull(rs!TAXIGVUSD), 0, rs!TAXIGVUSD)
            ' total de la venta + IGV
            DblVtaTotal = IIf(IsNull(rs!TOTALUSD), 0, rs!TOTALUSD)
        End If
    Else
        ' total de la venta (sin IGV)
        DblValorVta = 0
        ' total de la venta no afecta al IGV
        DblVtaNoAfecta = 0
        ' total de IGV
        DblIGV = 0
        ' total de la venta + IGV
        DblVtaTotal = 0
    End If
    
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_Datos_Ventas", Err.Description
End Sub

Sub Obtener_RDatos_Transacciones(IntLugar As Integer, StrNroPtoVta As String, _
                                StrSalesPerId As String, IntTurno As Integer, _
                                IntTipoCierre As Integer, StrFechaCierre As String, _
                                ByRef IntNroTransacciones As Integer, _
                                ByRef DblTicketBolIni As Double, ByRef DblTicketBolFin As Double, _
                                ByRef DblTicketFacIni As Double, ByRef DblTicketFacFin As Double)
    Dim rs As ADODB.Recordset
    Dim StrSql As String

On Error GoTo errhandler

    StrSql = " Obtener_RDatos_Transacciones " & IntLugar & ",'" & StrNroPtoVta & "','" & StrSalesPerId & "'," & IntTurno & "," & IntTipoCierre & ",'" & StrFechaCierre & "'"
    
    Set rs = New ADODB.Recordset
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        ' cantidad de transacciones realizadas
        IntNroTransacciones = IIf(IsNull(rs!NumTrans), 0, rs!NumTrans)
        ' numero del ticket boleta inicial
        DblTicketBolIni = IIf(IsNull(rs!BolIni), 0, rs!BolIni)
        ' numero del ticket factura inicial
        DblTicketFacIni = IIf(IsNull(rs!FacIni), 0, rs!FacIni)
        ' numero del ticket boleta inicial
        DblTicketBolFin = IIf(IsNull(rs!BolFin), 0, rs!BolFin)
        ' numero del ticket factura inicial
        DblTicketFacFin = IIf(IsNull(rs!FacFin), 0, rs!FacFin)
    Else
        ' cantidad de transacciones realizadas
        IntNroTransacciones = 0
        ' numero del ticket boleta inicial
        DblTicketBolIni = 0
        ' numero del ticket factura inicial
        DblTicketFacIni = 0
        ' numero del ticket boleta inicial
        DblTicketBolFin = 0
        ' numero del ticket factura inicial
        DblTicketFacFin = 0
    End If
    
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_RDatos_Transacciones", Err.Description
End Sub

Sub Obtener_Cabeceras_Ticket(ByRef StrCab1 As String, ByRef StrCab2 As String, _
                             ByRef StrCab3 As String, ByRef StrCab4 As String, _
                             ByRef StrCab5 As String)
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
On Error GoTo errhandler
    
    StrSql = "Select head1,head2,head3,head4,head5 from OP_TicketForm"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic

    If Not rs.EOF Then
        StrCab1 = IIf(IsNull(rs!head1), "", Trim(rs!head1))
        StrCab2 = IIf(IsNull(rs!head2), "", Trim(rs!head2))
        StrCab3 = IIf(IsNull(rs!head3), "", Trim(rs!head3))
        StrCab4 = IIf(IsNull(rs!head4), "", Trim(rs!head4))
        StrCab5 = IIf(IsNull(rs!head5), "", Trim(rs!head5))
    End If

    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
   'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_Cabeceras_Ticket", Err.Description
End Sub

Sub ObtenerFechaHoraImpresion(StrFechaCierre As String, StrNroPtoVta As String, _
    DblTicketBolFin As Double, DblTicketFacFin As Double, StrFechaHoraImpresion As String, IntMinutos As Integer)
    
    Dim rs As ADODB.Recordset
    Dim StrSql As String

On Error GoTo errhandler

    StrSql = "ObtenerFechaUltimoTicket '" & StrFechaCierre & "','" & StrNroPtoVta & "'," & _
              DblTicketBolFin & "," & DblTicketFacFin
              
    Set rs = New ADODB.Recordset
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    StrFechaHoraImpresion = DateAdd("n", IntMinutos, rs!FechaUltimo)
    
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
    'GetObjectContext.SetAbort
   Err.Raise Err.Number, "DB_OP_FACTURACION.ObtenerFechaHoraImpresion", Err.Description
End Sub

Sub Imprimir_Cierre( _
 IntTipoCierre As Integer, IntLugar As Integer, StrNroPtoVta As String, _
 StrSalesPerId As String, StrFechaCierre As String, IntTurno As Integer, _
 IntNroSaltosLineas As Integer, StrCodCorte As String, IntAnchoTicket As Integer, _
 StrLineaSeparacion As String, StrSerieMaqReg As String, StrFecha As String, _
 DblTipoCambio As Double, IntNroTransacciones As Integer, DblTicketBolIni As Double, _
 DblTicketFacIni As Double, DblValorVta As Double, DblVtaNoAfecta As Double, _
 DblIGV As Double, DblVtaTotal As Double, IntNroTicketAnul As Integer, _
 DblTotalTicketAnul As Double, DblGranTotal As Double, IntNroZeta As Integer, _
 DblTotalTicketBol As Double, DblTotalTicketFac As Double, _
 DblTotalGral As Double, DblEfectivo As Double, DblVueltoEfectivo As Double, _
 DblNetoEfectivo As Double, DblTarjeta As Double, DblVueltoTarjeta As Double, _
 DblNetoTarjeta As Double, DblVale As Double, DblVueltoVale As Double, _
 DblNetoVale As Double, StrMdaBase As String, StrMdaCaja As String, _
 StrSimbMdaCaja As String, StrSimbMdaExt As String, StrCab1 As String, _
 StrCab2 As String, StrCab3 As String, StrCab4 As String, StrCab5 As String, _
 BlnOK As Boolean, _
 GintDecResultado As Integer, GintDecStock As Integer, _
 StrDatEmpresa As String, StrDatCabecera As String, StrResVenta As String, _
 StrResTipoPago As String, StrResCategoria As String, StrResProducto As String, _
 StrResVendedor As String, StrResCara As String, StrSalto As String, _
 StrFechaIni As String, StrFechaFin As String, IntMinutos As Integer)
 
    Dim StrCadenon As String
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
    Dim DblTicketBolFin As Double
    Dim DblTicketFacFin As Double
    
    Dim StrFechaHoraImpresion As String
    
On Error GoTo errhandler
    
    StrCadenon = ""
    
    ' llamada a procedimientos preliminares
    
     ' datos de monedas :  codigos y simbolos
    Call Cargar_Datos_Monedas(StrMdaBase, StrMdaCaja, StrSimbMdaCaja, StrSimbMdaExt, StrNroPtoVta)
    
    ' datos de impresoras : lineas de saltos, codigo de corte, ...
 '   Call Cargar_Datos_Impresora(StrNroPtoVta, IntNroSaltosLineas, StrCodCorte, IntAnchoTicket)
    
    ' datos de cabecera de tickets
'    Call Obtener_Cabeceras_Ticket(StrCab1, StrCab2, StrCab3, StrCab4, StrCab5)
    
    ' variables de cabeceras de cierre
    Call Cabecera_Cierre(IntLugar, IntTipoCierre, IntTurno, _
                         StrFechaCierre, StrNroPtoVta, StrSalesPerId, _
                         StrSerieMaqReg, StrFecha, _
                         IntNroTransacciones, DblTicketBolIni, DblTicketBolFin, _
                         DblTicketFacIni, DblTicketFacFin, StrMdaBase, StrMdaCaja, _
                         DblValorVta, DblVtaNoAfecta, DblIGV, DblVtaTotal, _
                         IntNroTicketAnul, DblTotalTicketAnul, DblGranTotal, IntNroZeta)
    
    ' obtiene la hora del ultimo ticket
    Call ObtenerFechaHoraImpresion(Format(StrFechaCierre, "yyyyMMdd"), StrNroPtoVta, DblTicketBolFin, DblTicketFacFin, StrFechaHoraImpresion, IntMinutos)
    
 '   Open "temp.txt" For Output As #fp
    
    Call Obtener_Linea_Ticket(StrLineaSeparacion)
    
    Dim LLinea As String
    LLinea = Alineacion("C", IntAnchoTicket, Len(Trim(StrLineaSeparacion)), Trim(StrLineaSeparacion))

    'Printer.Print ""
    'StrCadenon = StrCadenon & ""
    'Print #fp, ""
    'Printer.Print ""
    'StrCadenon = StrCadenon & ""
    'Print #fp, ""
    'Printer.Print ""
    'StrCadenon = StrCadenon & ""
    'Print #fp, ""
    
    '''''''''''''''''''''''
    ' impresion de cabecera
    '''''''''''''''''''''''
    
    StrCab1 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab1)), Trim(StrCab1))
    StrCab2 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab2)), Trim(StrCab2))
    StrCab3 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab3)), Trim(StrCab3))
    StrCab4 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab4)), Trim(StrCab4))
    StrCab5 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab5)), Trim(StrCab5))
'    StrCab6 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab6)), Trim(StrCab6))
'    StrCab7 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab7)), Trim(StrCab7))
'    StrCab8 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab8)), Trim(StrCab8))
'    StrCab9 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab9)), Trim(StrCab9))
'    StrCab10 = Alineacion("C", IntAnchoTicket, Len(Trim(StrCab10)), Trim(StrCab10))

    'Printer.Print ""  ' El Primer Print no es Tomado en Cuenta
    StrDatEmpresa = StrDatEmpresa & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print ""  ' A partir del Primero se toman en cuenta
    StrDatEmpresa = StrDatEmpresa & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print ""
    StrDatEmpresa = StrDatEmpresa & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print ""
    StrDatEmpresa = StrDatEmpresa & "" & vbCrLf
    'Print #fp, ""

    If Trim(StrCab1) <> Empty Then
      'Printer.Print StrCab1
      StrDatEmpresa = StrDatEmpresa & StrCab1 & vbCrLf
      'Print #fp, StrCab1
    End If
    If Trim(StrCab2) <> Empty Then
      'Printer.Print StrCab2
      StrDatEmpresa = StrDatEmpresa & StrCab2 & vbCrLf
      'Print #fp, StrCab2
    End If
    If Trim(StrCab3) <> Empty Then
      'Printer.Print StrCab3
      StrDatEmpresa = StrDatEmpresa & StrCab3 & vbCrLf
      'Print #fp, StrCab3
    End If
    If Trim(StrCab4) <> Empty Then
      'Printer.Print StrCab4
      StrDatEmpresa = StrDatEmpresa & StrCab4 & vbCrLf
      'Print #fp, StrCab4
    End If
    If Trim(StrCab5) <> Empty Then
      'Printer.Print StrCab5
      StrDatEmpresa = StrDatEmpresa & StrCab5 & vbCrLf
      'Print #fp, StrCab5
    End If
'    If Trim(StrCab6) <> Empty Then
'      'Printer.Print StrCab6
'      StrCadenon = StrCadenon & StrCab6 & vbCrLf
'      'Print #fp, StrCab6
'    End If
'    If Trim(StrCab7) <> Empty Then
'      'Printer.Print StrCab7
'      StrCadenon = StrCadenon & StrCab7 & vbCrLf
'      'Print #fp, StrCab7
'    End If
'    If Trim(StrCab8) <> Empty Then
'      'Printer.Print StrCab8
'      StrCadenon = StrCadenon & StrCab8 & vbCrLf
'      'Print #fp, StrCab8
'    End If
'    If Trim(StrCab9) <> Empty Then
'      'Printer.Print StrCab9
'      StrCadenon = StrCadenon & StrCab9 & vbCrLf
'      'Print #fp, StrCab9
'    End If
'    If Trim(StrCab10) <> Empty Then
'      'Printer.Print StrCab10
'      StrCadenon = StrCadenon & StrCab10 & vbCrLf
'      'Print #fp, StrCab10
'    End If
    
    'Printer.Print StrLineaSeparacion
    StrDatEmpresa = StrDatEmpresa & LLinea & vbCrLf
    'Print #fp, StrLineaSeparacion
    ' titulo
    If IntTipoCierre = 1 Then
        'Printer.Print Alineacion("C", IntAnchoTicket, Len("CIERRE (X)"), "CIERRE (X)")
        StrDatEmpresa = StrDatEmpresa & Alineacion("C", IntAnchoTicket, Len("CIERRE (X)"), "CIERRE (X)") & vbCrLf
        'Print #fp, Alineacion("C", IntAnchoTicket, Len("CIERRE (X)"), "CIERRE (X)")
    End If
    If IntTipoCierre = 2 Then
        'Printer.Print Alineacion("C", IntAnchoTicket, Len("CIERRE (X)"), "CIERRE (Z)")
        StrDatEmpresa = StrDatEmpresa & Alineacion("C", IntAnchoTicket, Len("CIERRE (X)"), "CIERRE (Z)") & vbCrLf
        'Print #fp, Alineacion("C", IntAnchoTicket, Len("CIERRE (X)"), "CIERRE (Z)")
    End If
    ' si el Cierre es X y el lugar es Tienda
    If IntTipoCierre = 1 And IntLugar = 1 Then
        ' operador
        'Printer.Print Alineacion("C", IntAnchoTicket, Len("(Vendedor : " & StrSalesPerID & ")"), "(Vendedor : " & StrSalesPerID & ")")
        StrDatEmpresa = StrDatEmpresa & Alineacion("C", IntAnchoTicket, Len("(Vendedor : " & StrSalesPerId & ")"), "(Vendedor : " & StrSalesPerId & ")") & vbCrLf
        'Print #fp, Alineacion("C", IntAnchoTicket, Len("(Vendedor : " & StrSalesPerID & ")"), "(Vendedor : " & StrSalesPerID & ")")
    End If
    'Printer.Print StrLineaSeparacion
    StrDatCabecera = StrDatCabecera & LLinea & vbCrLf
    'Print #fp, StrLineaSeparacion
    'Printer.Print ""
    StrDatCabecera = StrDatCabecera & "" & vbCrLf
    'Print #fp, ""

    Dim StrMaquinaReg_ As String
    StrMaquinaReg_ = Alineacion("I", IntAnchoTicket - 10, Len("Maq.Regist.No: " & StrSerieMaqReg), "Maq.Regist.No: " & StrSerieMaqReg)
    'Printer.Print StrMaquinaReg_
    StrDatCabecera = StrDatCabecera & StrMaquinaReg_ & vbCrLf
    'Print #fp, StrMaquinaReg_
    
    Dim StrFecha_ As String
    StrFecha_ = Alineacion("I", IntAnchoTicket - 10, Len("Fecha        : " & Format(StrFechaHoraImpresion, "dd/MM/yyyy hh:mm:ss")), "Fecha        : ") & Format(StrFechaHoraImpresion, "dd/MM/yyyy hh:mm:ss")

    'Printer.Print StrFecha_
    StrDatCabecera = StrDatCabecera & StrFecha_ & vbCrLf
    'Print #fp, StrFecha_
    
    Dim StrTipoCambio_ As String
    StrTipoCambio_ = Alineacion("I", IntAnchoTicket - 10, Len("Tipo de Cambio: " & GFormatodeNumero(DblTipoCambio, GintDecResultado)), "Tipo de Cambio: " & GFormatodeNumero(DblTipoCambio, GintDecResultado))
    'Printer.Print StrTipoCambio_
    StrDatCabecera = StrDatCabecera & StrTipoCambio_ & vbCrLf
    'Print #fp, StrTipoCambio_
    
    Dim StrNroTransacciones_ As String
    StrNroTransacciones_ = Alineacion("I", IntAnchoTicket - 10, Len("Nro. Transac. : " & IntNroTransacciones), "Nro. Transac. : " & IntNroTransacciones)
    'Printer.Print StrNroTransacciones_
    StrDatCabecera = StrDatCabecera & StrNroTransacciones_ & vbCrLf
    'Print #fp, StrNroTransacciones_
    
    Dim StrTicketBolIni_ As String
    StrTicketBolIni_ = Alineacion("I", IntAnchoTicket - 11, Len("Num. Ticket Boleta Ini. : "), "Num. Ticket Boleta Ini. : ") & FormatoTicket(Str(DblTicketBolIni))  'FormatoTicket(StrNumerodeTicket))
    'Printer.Print StrTicketBolIni_
    StrDatCabecera = StrDatCabecera & StrTicketBolIni_ & vbCrLf
    'Print #fp, StrTicketBolIni_
    
    Dim StrTicketBolFin_ As String
    StrTicketBolFin_ = Alineacion("I", IntAnchoTicket - 11, Len("Num. Ticket Boleta Fin. : "), "Num. Ticket Boleta Fin. : ") & FormatoTicket(Str(DblTicketBolFin))  'FormatoTicket(StrNumerodeTicket))
    'Printer.Print StrTicketBolFin_
    StrDatCabecera = StrDatCabecera & StrTicketBolFin_ & vbCrLf
    'Print #fp, StrTicketBolFIn_
    
    Dim StrTicketFacIni_ As String
    StrTicketFacIni_ = Alineacion("I", IntAnchoTicket - 11, Len("Num. Ticket Factura Ini.: "), "Num. Ticket Factura Ini.: ") & FormatoTicket(Str(DblTicketFacIni))
    'Printer.Print StrTicketFacIni_
    StrDatCabecera = StrDatCabecera & StrTicketFacIni_ & vbCrLf
    'Print #fp, StrTicketFacIni_
    
    Dim StrTicketFacFin_ As String
    StrTicketFacFin_ = Alineacion("I", IntAnchoTicket - 11, Len("Num. Ticket Factura Ini.: "), "Num. Ticket Factura Fin.: ") & FormatoTicket(Str(DblTicketFacFin))
    'Printer.Print StrTicketFacFin_
    StrDatCabecera = StrDatCabecera & StrTicketFacFin_ & vbCrLf
    'Print #fp, StrTicketFacFin_

    Dim DblPorcIGV As Double
    DblPorcIGV = Obtener_Porcentaje_IGV
    
    Dim StrValorVenta_ As String
    
    ''' PUCHUC ---> StrValorVenta_ = "Valor Venta  " & StrSimbMdaCaja & " : " & Alineacion("D", IntAnchoTicket - 14 - 7, Len(GFormatodeNumero(DblValorVta, GintDecResultado)), GFormatodeNumero(DblValorVta, GintDecResultado))
    StrValorVenta_ = "Valor Venta  " & StrSimbMdaCaja & " : " & Alineacion("D", IntAnchoTicket - 14 - 7, Len(GFormatodeNumero(DblVtaTotal / (1 + DblPorcIGV / 100), GintDecResultado)), GFormatodeNumero(DblVtaTotal / (1 + DblPorcIGV / 100), GintDecResultado))
    'StrValorVenta_ = Alineacion("I", IntAnchoTicket - 10, Len("Valor Venta : " & GFormatodeNumero(DblValorVta, GintDecResultado)), "Valor Venta : " & GFormatodeNumero(DblValorVta, GintDecResultado))
    'Printer.Print StrValorVenta_
    StrDatCabecera = StrDatCabecera & StrValorVenta_ & vbCrLf
    'Print #fp, StrValorVenta_

    Dim StrVtaNoAfecta_ As String
    StrVtaNoAfecta_ = "No Afecto    " & StrSimbMdaCaja & " : " & Alineacion("D", IntAnchoTicket - 14 - 7, Len(GFormatodeNumero(DblVtaNoAfecta, GintDecResultado)), GFormatodeNumero(DblVtaNoAfecta, GintDecResultado))
    'StrVtaNoAfecta_ = Alineacion("I", IntAnchoTicket - 10, Len("No Afecto   : " & GFormatodeNumero(DblVtaNoAfecta, GintDecResultado)), "No Afecto   : " & GFormatodeNumero(DblVtaNoAfecta, GintDecResultado))
    'Printer.Print StrVtaNoAfecta_
    StrDatCabecera = StrDatCabecera & StrVtaNoAfecta_ & vbCrLf
    'Print #fp, StrVtaNoAfecta_

    Dim StrIGV_ As String
    ''' PUCHUC ---> StrIGV_ = "I.G.V.       " & StrSimbMdaCaja & " : " & Alineacion("D", IntAnchoTicket - 14 - 7, Len(GFormatodeNumero(DblIGV, GintDecResultado)), GFormatodeNumero(DblIGV / 100, GintDecResultado))
    StrIGV_ = "I.G.V.       " & StrSimbMdaCaja & " : " & Alineacion("D", IntAnchoTicket - 14 - 7, Len(GFormatodeNumero(DblVtaTotal - (DblVtaTotal / (1 + DblPorcIGV / 100)), GintDecResultado)), GFormatodeNumero(DblVtaTotal - (DblVtaTotal / (1 + DblPorcIGV / 100)), GintDecResultado))
    'StrIGV_ = Alineacion("I", IntAnchoTicket - 10, Len("I.G.V.      : " & GFormatodeNumero(DblIGV, GintDecResultado)), "I.G.V.      : " & GFormatodeNumero(DblIGV, GintDecResultado))
    'Printer.Print StrIGV_
    StrDatCabecera = StrDatCabecera & StrIGV_ & vbCrLf
    'Print #fp, StrIGV_

    Dim StrVtaTotal_ As String
    StrVtaTotal_ = "Venta Total  " & StrSimbMdaCaja & " : " & Alineacion("D", IntAnchoTicket - 14 - 7, Len(GFormatodeNumero(DblVtaTotal, GintDecResultado)), GFormatodeNumero(DblVtaTotal, GintDecResultado))
    'StrVtaTotal_ = Alineacion("I", IntAnchoTicket - 10, Len("Venta Total : " & GFormatodeNumero(DblVtaTotal, GintDecResultado)), "Venta Total : " & GFormatodeNumero(DblVtaTotal, GintDecResultado))
    'Printer.Print StrVtaTotal_
    StrDatCabecera = StrDatCabecera & StrVtaTotal_ & vbCrLf
    'Print #fp, StrVtaTotal_
    
    Dim StrNroTicketAnul_ As String
    StrNroTicketAnul_ = Alineacion("I", IntAnchoTicket - 10, Len("Num. Ticket Anulados : " & IntNroTicketAnul), "Num. Ticket Anulados : " & Str(IntNroTicketAnul))
    'Printer.Print StrNroTicketAnul_
    StrDatCabecera = StrDatCabecera & StrNroTicketAnul_ & vbCrLf
    'Print #fp, StrNroTicketAnul_
    
    Dim StrTotalTicketAnul_ As String
    StrTotalTicketAnul_ = "Total Ticket Anulados " & StrSimbMdaCaja & ":" & Alineacion("D", IntAnchoTicket - 21 - 7, Len(GFormatodeNumero(DblTotalTicketAnul, GintDecResultado)), GFormatodeNumero(DblTotalTicketAnul, GintDecResultado))
    'StrTotalTicketAnul_ = Alineacion("I", IntAnchoTicket - 10, Len("Total Ticket Anulados: " & GFormatodeNumero(DblTotalTicketAnul, GintDecResultado)), "Total Ticket Anulados: " & GFormatodeNumero(DblTotalTicketAnul, GintDecResultado))
    'Printer.Print StrTotalTicketAnul_
    StrDatCabecera = StrDatCabecera & StrTotalTicketAnul_ & vbCrLf
    'Print #fp, StrTotalTicketAnul_
    
    Dim StrGranTotal_ As String
    StrGranTotal_ = "Gran Total            " & StrSimbMdaCaja & ":" & Alineacion("D", IntAnchoTicket - 21 - 7, Len(GFormatodeNumero(DblGranTotal, GintDecResultado)), GFormatodeNumero(DblGranTotal, GintDecResultado))
    'StrGranTotal_ = Alineacion("I", IntAnchoTicket - 10, Len("Gran Total           : " & GFormatodeNumero(DblGranTotal, GintDecResultado)), "Gran Total           : " & GFormatodeNumero(DblGranTotal, GintDecResultado))
    'Printer.Print StrGranTotal_
    StrDatCabecera = StrDatCabecera & StrGranTotal_ & vbCrLf
    'Print #fp, StrGranTotal_
    
    Dim NroZeta_ As String
    NroZeta_ = Alineacion("I", IntAnchoTicket - 10, Len("Numero de Zeta       : " & DblGranTotal), "Numero de Zeta       : " & Str(IntNroZeta))
    'Printer.Print NroZeta_
    StrDatCabecera = StrDatCabecera & NroZeta_ & vbCrLf
    'Print #fp, NroZeta_
    
    If IntLugar = 2 And IntTipoCierre = 1 Then ' Playa
        Dim StrTurno_ As String
        StrTurno_ = Alineacion("I", IntAnchoTicket - 10, Len("Turno                : " & IntTurno), "Turno                : " & Str(IntTurno))
        'Printer.Print StrTurno_
        StrDatCabecera = StrDatCabecera & StrTurno_ & vbCrLf
        'Print #fp, StrTurno_
    End If

    ' separacion
    'Printer.Print ""
    StrResVenta = StrResVenta & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print ""
    StrResVenta = StrResVenta & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print Alineacion("C", IntAnchoTicket, Len("RESUMEN DE VENTA"), "RESUMEN DE VENTA")
    StrResVenta = StrResVenta & Alineacion("C", IntAnchoTicket, Len("RESUMEN DE VENTA"), "RESUMEN DE VENTA") & vbCrLf
    'Print #fp, Alineacion("C", IntAnchoTicket, Len("RESUMEN DE VENTA"), "RESUMEN DE VENTA")
    'Printer.Print LLinea
    StrResVenta = StrResVenta & LLinea & vbCrLf
    'Print #fp, LLinea
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    ' Resumen de Ventas
    If IntLugar = 1 Then ' Tienda
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = "OP_CierreX_Market_ResumenVta '" & StrNroPtoVta & "','" & StrSalesPerId & "','" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = "OP_RCierreZ_ResumenVta '" & StrNroPtoVta & "','" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
    End If
    If IntLugar = 2 Then ' Playa
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = "OP_CierreX_Combustible_ResumenVta '" & StrNroPtoVta & "'," & IntTurno & ",'" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = "OP_RCierreZ_ResumenVta '" & StrNroPtoVta & "','" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
    End If
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
        
    Dim StrTotalBol_ As String
    Dim StrTotalFac_ As String
    Dim StrTotalGral_ As String
    
    If Not rs.EOF Then
    '    Dim StrTotalBol_ As String
        StrTotalBol_ = "Total Ticket Boleta   " & StrSimbMdaCaja & ":" & Alineacion("D", IntAnchoTicket - 21 - 7, Len(GFormatodeNumero(rs!TOTALBOLPENAUT, GintDecResultado)), GFormatodeNumero(rs!TOTALBOLPENAUT, GintDecResultado))
        'StrTotalBol_ = Alineacion("I", IntAnchoTicket - 10, Len("Total Ticket Boleta  : " & GFormatodeNumero(rs!TOTALBOLPENAUT, GintDecResultado)), "Total Ticket Boleta  : " & GFormatodeNumero(rs!TOTALBOLPENAUT, GintDecResultado))
        'Printer.Print StrTotalBol_
        StrResVenta = StrResVenta & StrTotalBol_ & vbCrLf
        'Print #fp, StrTotalBol_
        
        StrTotalFac_ = "Total Ticket Factura  " & StrSimbMdaCaja & ":" & Alineacion("D", IntAnchoTicket - 21 - 7, Len(GFormatodeNumero(rs!TOTALFACPENAUT, GintDecResultado)), GFormatodeNumero(rs!TOTALFACPENAUT, GintDecResultado))
        'StrTotalFac_ = Alineacion("I", IntAnchoTicket - 10, Len("Total Ticket Factura : " & GFormatodeNumero(rs!TOTALFACPENAUT, GintDecResultado)), "Total Ticket Factura : " & GFormatodeNumero(rs!TOTALFACPENAUT, GintDecResultado))
        'Printer.Print StrTotalFac_
        StrResVenta = StrResVenta & StrTotalFac_ & vbCrLf
        'Print #fp, StrTotalFac_
        
        StrTotalGral_ = "Total General         " & StrSimbMdaCaja & ":" & Alineacion("D", IntAnchoTicket - 21 - 7, Len(GFormatodeNumero(rs!TOTALFACPENAUT + rs!TOTALBOLPENAUT, GintDecResultado)), GFormatodeNumero(rs!TOTALFACPENAUT + rs!TOTALBOLPENAUT, GintDecResultado))
        'StrTotalGral_ = Alineacion("I", IntAnchoTicket - 10, Len("Total General        : " & GFormatodeNumero(rs!TOTALFACPENAUT + rs!TOTALBOLPENAUT, GintDecResultado)), "Total General        : " & GFormatodeNumero(rs!TOTALFACPENAUT + rs!TOTALBOLPENAUT, GintDecResultado))
        'Printer.Print StrTotalGral_
        StrResVenta = StrResVenta & StrTotalGral_ & vbCrLf
        'Print #fp, StrTotalGral_
    Else
        StrTotalBol_ = "Total Ticket Boleta   " & StrSimbMdaCaja & ":" & Alineacion("D", IntAnchoTicket - 21 - 7, Len(GFormatodeNumero(0, GintDecResultado)), GFormatodeNumero(0, GintDecResultado))
        'StrTotalBol_ = Alineacion("I", IntAnchoTicket - 10, Len("Total Ticket Boleta  : " & GFormatodeNumero(0, GintDecResultado)), "Total Ticket Boleta  : " & GFormatodeNumero(0, GintDecResultado))
        'Printer.Print StrTotalBol_
        StrResVenta = StrResVenta & StrTotalBol_ & vbCrLf
        'Print #fp, StrTotalBol_
        
    '    Dim StrTotalFac_ As String
        StrTotalFac_ = "Total Ticket Factura  " & StrSimbMdaCaja & ":" & Alineacion("D", IntAnchoTicket - 21 - 7, Len(GFormatodeNumero(0, GintDecResultado)), GFormatodeNumero(0, GintDecResultado))
        'StrTotalFac_ = Alineacion("I", IntAnchoTicket - 10, Len("Total Ticket Factura : " & GFormatodeNumero(0, GintDecResultado)), "Total Ticket Factura : " & Format(0, Gintdecprecio))
        'Printer.Print StrTotalFac_
        StrResVenta = StrResVenta & StrTotalFac_ & vbCrLf
        'Print #fp, StrTotalFac_
        
     '   Dim StrTotalGral_ As String
        StrTotalGral_ = "Total General         " & StrSimbMdaCaja & ":" & Alineacion("D", IntAnchoTicket - 21 - 7, Len(GFormatodeNumero(0, GintDecResultado)), GFormatodeNumero(0, GintDecResultado))
        'StrTotalGral_ = Alineacion("I", IntAnchoTicket - 10, Len("Total General        : " & GFormatodeNumero(0, GintDecResultado)), "Total Ticket Factura : " & GFormatodeNumero(0, GintDecResultado))
        'Printer.Print StrTotalGral_
        StrResVenta = StrResVenta & StrTotalGral_ & vbCrLf
        'Print #fp, StrTotalGral_
    End If
    
    If rs.State = 1 Then rs.Close
    
    ' separacion
    'Printer.Print ""
    StrResTipoPago = StrResTipoPago & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print ""
    StrResTipoPago = StrResTipoPago & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print Alineacion("C", IntAnchoTicket, Len("RESUMEN POR TIPOS DE PAGO"), "RESUMEN POR TIPOS DE PAGO")
    StrResTipoPago = StrResTipoPago & Alineacion("C", IntAnchoTicket, Len("RESUMEN POR TIPOS DE PAGO"), "RESUMEN POR TIPOS DE PAGO") & vbCrLf
    'Print #fp, Alineacion("C", IntAnchoTicket, Len("RESUMEN POR TIPOS DE PAGO"), "RESUMEN POR TIPOS DE PAGO")
    'Printer.Print LLinea
    StrResTipoPago = StrResTipoPago & LLinea & vbCrLf
    'Print #fp, LLinea

    ' Resumen por Tipos de Pagos
    If IntLugar = 1 Then ' Tienda
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = "OP_CierreX_Market_ResumenTiposPago '" & StrNroPtoVta & "','" & StrSalesPerId & "','" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = "OP_RCierreZ_ResumenTiposPago '" & StrNroPtoVta & "','" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
    End If
    If IntLugar = 2 Then ' Playa
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = "OP_CierreX_Combustible_ResumenTiposPago '" & StrNroPtoVta & "'," & IntTurno & ",'" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = "OP_RCierreZ_ResumenTiposPago '" & StrNroPtoVta & "','" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
    End If

    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        ' EFECTIVO
        ' PEN
        
        Dim StrEfectivoPen_ As String
        StrEfectivoPen_ = Alineacion("I", 17, Len("EFECTIVO         "), "EFECTIVO         ")
        
        If StrMdaBase = StrMdaCaja Then
            StrEfectivoPen_ = StrEfectivoPen_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
            StrEfectivoPen_ = StrEfectivoPen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!EFECTIVOPEN), 0, rs!EFECTIVOPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!EFECTIVOPEN), 0, rs!EFECTIVOPEN), GintDecResultado))
        Else
            StrEfectivoPen_ = StrEfectivoPen_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
            StrEfectivoPen_ = StrEfectivoPen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!EFECTIVOPEN), 0, rs!EFECTIVOPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!EFECTIVOPEN), 0, rs!EFECTIVOPEN), GintDecResultado))
        End If

        ''StrEfectivoPen_ = Alineacion("I", IntAnchoTicket - 10, Len("Efectivo  : " & rs!EFECTIVOPEN), "Efectivo  : " & rs!EFECTIVOPEN)
        'Printer.Print StrEfectivoPen_
        StrResTipoPago = StrResTipoPago & StrEfectivoPen_ & vbCrLf
        'Print #fp, StrEfectivoPen_
        
        If IntLugar = 1 Then ' Tienda
            Dim StrVueltoEfectivoPen_ As String
            StrVueltoEfectivoPen_ = Alineacion("I", 17, Len("     VUELTO      "), "     VUELTO      ")
            
            If StrMdaBase = StrMdaCaja Then
                StrVueltoEfectivoPen_ = StrVueltoEfectivoPen_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
                StrVueltoEfectivoPen_ = StrVueltoEfectivoPen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!VUELTOPEN), 0, rs!VUELTOPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!VUELTOPEN), 0, rs!VUELTOPEN), GintDecResultado))
            Else
                StrVueltoEfectivoPen_ = StrVueltoEfectivoPen_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
                StrVueltoEfectivoPen_ = StrVueltoEfectivoPen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!VUELTOPEN), 0, rs!VUELTOPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!VUELTOPEN), 0, rs!VUELTOPEN), GintDecResultado))
            End If
            ''StrVueltoEfectivoPen_ = Alineacion("I", IntAnchoTicket - 10, Len("Vuelto    : " & rs!VUELTOPEN), "Vuelto     : " & rs!VUELTOPEN)
            
            'Printer.Print StrVueltoEfectivoPen_
            StrResTipoPago = StrResTipoPago & StrVueltoEfectivoPen_ & vbCrLf
            'Print #fp, StrVueltoEfectivoPen_
            
            Dim StrNetoEfectivoPen_ As String
            StrNetoEfectivoPen_ = Alineacion("I", 17, Len("     NETO        "), "     NETO        ")
            
            If StrMdaBase = StrMdaCaja Then
                StrNetoEfectivoPen_ = StrNetoEfectivoPen_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
                StrNetoEfectivoPen_ = StrNetoEfectivoPen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!EFECTIVOPEN), 0, rs!EFECTIVOPEN) - IIf(IsNull(rs!VUELTOPEN), 0, rs!VUELTOPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!EFECTIVOPEN), 0, rs!EFECTIVOPEN) - IIf(IsNull(rs!VUELTOPEN), 0, rs!VUELTOPEN), GintDecResultado))
            Else
                StrNetoEfectivoPen_ = StrNetoEfectivoPen_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
                StrNetoEfectivoPen_ = StrNetoEfectivoPen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!EFECTIVOPEN), 0, rs!EFECTIVOPEN) - IIf(IsNull(rs!VUELTOPEN), 0, rs!VUELTOPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!EFECTIVOPEN), 0, rs!EFECTIVOPEN) - IIf(IsNull(rs!VUELTOPEN), 0, rs!VUELTOPEN), GintDecResultado))
            End If
            ''StrNetoEfectivoPen_ = Alineacion("I", IntAnchoTicket - 10, Len("Neto       : " & (rs!EFECTIVOPEN - rs!VUELTOPEN)), "Neto       : " & (rs!EFECTIVOPEN - rs!VUELTOPEN))
            
            'Printer.Print StrNetoEfectivoPen_
            StrResTipoPago = StrResTipoPago & StrNetoEfectivoPen_ & vbCrLf
            'Print #fp, StrNetoEfectivoPen_
        End If
        If IntLugar = 1 Then ' Tienda
            ' USD
            Dim StrEfectivoUsd_ As String
            StrEfectivoUsd_ = Alineacion("I", 17, Len("                 "), "                 ")
            
            If StrMdaBase = StrMdaCaja Then
                StrEfectivoUsd_ = StrEfectivoUsd_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
                StrEfectivoUsd_ = StrEfectivoUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!EFECTIVOUSD), 0, rs!EFECTIVOUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!EFECTIVOUSD), 0, rs!EFECTIVOUSD), GintDecResultado))
            Else
                StrEfectivoUsd_ = StrEfectivoUsd_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
                StrEfectivoUsd_ = StrEfectivoUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!EFECTIVOUSD), 0, rs!EFECTIVOUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!EFECTIVOUSD), 0, rs!EFECTIVOUSD), GintDecResultado))
            End If
    
            ''StrEfectivoPen_ = Alineacion("I", IntAnchoTicket - 10, Len("Efectivo  : " & rs!EFECTIVOPEN), "Efectivo  : " & rs!EFECTIVOPEN)
            'Printer.Print StrEfectivoUsd_
            StrResTipoPago = StrResTipoPago & StrEfectivoUsd_ & vbCrLf
            'Print #fp, StrEfectivoUsd_
        
            Dim StrVueltoEfectivoUsd_ As String
            StrVueltoEfectivoUsd_ = Alineacion("I", 17, Len("     VUELTO      "), "     VUELTO      ")
            
            If StrMdaBase = StrMdaCaja Then
                StrVueltoEfectivoUsd_ = StrVueltoEfectivoUsd_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
                StrVueltoEfectivoUsd_ = StrVueltoEfectivoUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!VUELTOUSD), 0, rs!VUELTOUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!VUELTOUSD), 0, rs!VUELTOUSD), GintDecResultado))
            Else
                StrVueltoEfectivoUsd_ = StrVueltoEfectivoUsd_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
                StrVueltoEfectivoUsd_ = StrVueltoEfectivoUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!VUELTOUSD), 0, rs!VUELTOUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!VUELTOUSD), 0, rs!VUELTOUSD), GintDecResultado))
            End If
            ''StrVueltoEfectivoPen_ = Alineacion("I", IntAnchoTicket - 10, Len("Vuelto    : " & rs!VUELTOPEN), "Vuelto     : " & rs!VUELTOPEN)
            
            'Printer.Print StrVueltoEfectivoUsd_
            StrResTipoPago = StrResTipoPago & StrVueltoEfectivoUsd_ & vbCrLf
            'Print #fp, StrVueltoEfectivoUsd_
            
            Dim StrNetoEfectivoUsd_ As String
            StrNetoEfectivoUsd_ = Alineacion("I", 17, Len("     NETO        "), "     NETO        ")
            
            If StrMdaBase = StrMdaCaja Then
                StrNetoEfectivoUsd_ = StrNetoEfectivoUsd_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
                StrNetoEfectivoUsd_ = StrNetoEfectivoUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!EFECTIVOUSD), 0, rs!EFECTIVOUSD) - IIf(IsNull(rs!VUELTOUSD), 0, rs!VUELTOUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!EFECTIVOUSD), 0, rs!EFECTIVOUSD) - IIf(IsNull(rs!VUELTOUSD), 0, rs!VUELTOUSD), GintDecResultado))
            Else
                StrNetoEfectivoUsd_ = StrNetoEfectivoUsd_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
                StrNetoEfectivoUsd_ = StrNetoEfectivoUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!EFECTIVOUSD), 0, rs!EFECTIVOUSD) - IIf(IsNull(rs!VUELTOUSD), 0, rs!VUELTOUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!EFECTIVOUSD), 0, rs!EFECTIVOUSD) - IIf(IsNull(rs!VUELTOUSD), 0, rs!VUELTOUSD), GintDecResultado))
            End If
            
            'Printer.Print StrNetoEfectivoUsd_
            StrResTipoPago = StrResTipoPago & StrNetoEfectivoUsd_ & vbCrLf
            'Print #fp, StrNetoEfectivoUsd_
        End If
        
        ' TARJETAS
        ' PEN
        Dim StrTarjetaPen_ As String
        StrTarjetaPen_ = Alineacion("I", 17, Len("TARJETA          "), "TARJETA          ")
        
        If StrMdaBase = StrMdaCaja Then
            StrTarjetaPen_ = StrTarjetaPen_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
            StrTarjetaPen_ = StrTarjetaPen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!TARJETAPEN), 0, rs!TARJETAPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!TARJETAPEN), 0, rs!TARJETAPEN), GintDecResultado))
        Else
            StrTarjetaPen_ = StrTarjetaPen_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
            StrTarjetaPen_ = StrTarjetaPen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!TARJETAPEN), 0, rs!TARJETAPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!TARJETAPEN), 0, rs!TARJETAPEN), GintDecResultado))
        End If
        
        'Dim StrTarjetaPen_ As String
        ''StrTarjetaPen_ = Alineacion("I", IntAnchoTicket - 10, Len("Tarjeta     : " & rs!TARJETAPEN), "Tarjeta     : " & rs!TARJETAPEN)
        'Printer.Print StrTarjetaPen_
        StrResTipoPago = StrResTipoPago & StrTarjetaPen_ & vbCrLf
        'Print #fp, StrTarjetaPen_
        
        If IntLugar = 1 Then ' Tienda
            ' USD
            'Dim StrTarjetaPen_ As String
            'StrTarjetaPen_ = Alineacion("I", IntAnchoTicket - 10, Len("Tarjeta     : " & rs!TARJETAPEN), "Tarjeta     : " & rs!TARJETAPEN)
            Dim StrTarjetaUsd_ As String
            StrTarjetaUsd_ = Alineacion("I", 17, Len("                 "), "                 ")
            
            If StrMdaBase = StrMdaCaja Then
                StrTarjetaUsd_ = StrTarjetaUsd_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
                StrTarjetaUsd_ = StrTarjetaUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!TARJETAUSD), 0, rs!TARJETAUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!TARJETAUSD), 0, rs!TARJETAUSD), GintDecResultado))
            Else
                StrTarjetaUsd_ = StrTarjetaUsd_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
                StrTarjetaUsd_ = StrTarjetaUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!TARJETAUSD), 0, rs!TARJETAUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!TARJETAUSD), 0, rs!TARJETAUSD), GintDecResultado))
            End If

            'Printer.Print StrTarjetaUsd_
            StrResTipoPago = StrResTipoPago & StrTarjetaUsd_ & vbCrLf
            'Print #fp, StrTarjetaUsd_
        End If
        
        ' CREDITO
        ' PEN
        Dim StrValePen_ As String
        StrValePen_ = Alineacion("I", 17, Len("VALE             "), "VALE             ")
        
        If StrMdaBase = StrMdaCaja Then
            StrValePen_ = StrValePen_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
            StrValePen_ = StrValePen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!VALEPEN), 0, rs!VALEPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!VALEPEN), 0, rs!VALEPEN), GintDecResultado))
        Else
            StrValePen_ = StrValePen_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
            StrValePen_ = StrValePen_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!VALEPEN), 0, rs!VALEPEN), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!VALEPEN), 0, rs!VALEPEN), GintDecResultado))
        End If
        
        'Printer.Print StrValePen_
        StrResTipoPago = StrResTipoPago & StrValePen_ & vbCrLf
        'Print #fp, StrValePen_
        
        If IntLugar = 1 Then ' Tienda
            'USD
            Dim StrValeUsd_ As String
            StrValeUsd_ = Alineacion("I", 17, Len("                 "), "                 ")
                  
            If StrMdaBase = StrMdaCaja Then
                StrValeUsd_ = StrValeUsd_ & Alineacion("I", 7, Len(StrSimbMdaExt & " :"), StrSimbMdaExt & " :")
                StrValeUsd_ = StrValeUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!VALEUSD), 0, rs!VALEUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!VALEUSD), 0, rs!VALEUSD), GintDecResultado))
            Else
                StrValeUsd_ = StrValeUsd_ & Alineacion("I", 7, Len(StrSimbMdaCaja & " :"), StrSimbMdaCaja & " :")
                StrValeUsd_ = StrValeUsd_ & Alineacion("D", IntAnchoTicket - 17 - 7, Len(GFormatodeNumero(IIf(IsNull(rs!VALEUSD), 0, rs!VALEUSD), GintDecResultado)), GFormatodeNumero(IIf(IsNull(rs!VALEUSD), 0, rs!VALEUSD), GintDecResultado))
            End If
            
            'Printer.Print StrValeUsd_
            StrResTipoPago = StrResTipoPago & StrValeUsd_ & vbCrLf
            'Print #fp, StrValeUsd_
        End If
    End If
    
    If rs.State = 1 Then rs.Close
    
    If IntLugar = 1 Then ' Tienda
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = "OP_CierreX_Market_Detalles '" & StrNroPtoVta & "','" & Format(StrSalesPerId, "yyyyMMdd") & "','" & StrFechaCierre & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = "OP_RCierreZ_Detalles '" & StrNroPtoVta & "','" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
    End If
    If IntLugar = 2 Then ' Playa
        If IntTipoCierre = 1 Then ' Cierre X
            StrSql = "OP_CierreX_Combustible_Detalles '" & StrNroPtoVta & "'," & IntTurno & ",'" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
        If IntTipoCierre = 2 Then ' Cierre Z
            StrSql = "OP_RCierreZ_Detalles '" & StrNroPtoVta & "','" & Format(StrFechaCierre, "yyyyMMdd") & "'"
        End If
    End If

    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    ' RESUMEN POR CATEGORIA
    'If Not rs.EOF Then
    rs.Filter = "[SECCION]='CAT'"
    rs.Sort = "[CDCAT] ASC"
   '
    Dim StrCatId_ As String
    Dim StrCatDes_ As String
    Dim StrCatTotal_ As String
    Dim DblTotalCat_ As Double
    Dim StrLineaCat_ As String
    
    ' separacion
    'Printer.Print ""
    StrResCategoria = StrResCategoria & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print ""
    StrResCategoria = StrResCategoria & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print Alineacion("C", IntAnchoTicket, Len("RESUMEN POR CATEGORIA"), "RESUMEN POR CATEGORIA")
    StrResCategoria = StrResCategoria & Alineacion("C", IntAnchoTicket, Len("RESUMEN POR CATEGORIA"), "RESUMEN POR CATEGORIA") & vbCrLf
    'Print #fp, Alineacion("C", IntAnchoTicket, Len("RESUMEN POR CATEGORIA"), "RESUMEN POR CATEGORIA")
    'Printer.Print LLinea
    StrResCategoria = StrResCategoria & LLinea & vbCrLf
    'Print #fp, LLinea
    
    While Not rs.EOF
        StrCatId_ = Alineacion("I", 8, Len(rs!CDCAT), rs!CDCAT)
        StrCatDes_ = Alineacion("I", 20, Len(rs!DSCAT), rs!DSCAT)
        
        If StrMdaBase = StrMdaCaja Then
            StrCatTotal_ = Alineacion("D", 10, Len(GFormatodeNumero(rs!TOTALPEN, GintDecResultado)), GFormatodeNumero(rs!TOTALPEN, GintDecResultado))
            DblTotalCat_ = DblTotalCat_ + rs!TOTALPEN
        Else
            StrCatTotal_ = Alineacion("I", 10, Len(GFormatodeNumero(rs!TOTALUSD, GintDecResultado)), GFormatodeNumero(rs!TOTALUSD, GintDecResultado))
            DblTotalCat_ = DblTotalCat_ + rs!TOTALUSD
        End If
        StrLineaCat_ = StrCatId_ & " " & StrCatDes_ & " " & StrCatTotal_
        
        
        'Printer.Print StrLineaCat_
        StrResCategoria = StrResCategoria & StrLineaCat_ & vbCrLf
        'Print #fp, StrLineaCat_
        
        rs.MoveNext
    Wend
    StrLineaCat_ = Alineacion("D", IntAnchoTicket, Len("Total  " & StrSimbMdaCaja & " : " & GFormatodeNumero(DblTotalCat_, GintDecResultado)), _
                   "Total  " & StrSimbMdaCaja & " : " & GFormatodeNumero(DblTotalCat_, GintDecResultado))
    
    'Printer.Print StrLineaCat_
    StrResCategoria = StrResCategoria & StrLineaCat_ & vbCrLf
    'Print #fp, StrLineaCat_
    
    ' separacion
    'Printer.Print
    StrResProducto = StrResProducto & "" & vbCrLf
    'Printer.Print
    StrResProducto = StrResProducto & "" & vbCrLf
    'Printer.Print Alineacion("C", IntAnchoTicket, Len("RESUMEN POR PRODUCTOS"), "RESUMEN POR PRODUCTOS")
    StrResProducto = StrResProducto & Alineacion("C", IntAnchoTicket, Len("RESUMEN POR PRODUCTOS"), "RESUMEN POR PRODUCTOS") & vbCrLf
    'Printer.Print LLinea
    StrResProducto = StrResProducto & LLinea & vbCrLf
    
    ' RESUMEN POR PRODUCTO
    rs.Filter = "[SECCION]='INV'"
    rs.Sort = "[CDCAT] ASC"
    
    Dim StrProdId_ As String
    Dim StrProdDes_ As String
    Dim StrProdCant_ As String
    Dim StrTotalProd_ As String
    Dim StrProdTotal_ As String
    Dim DblProdTotal_ As Double
    Dim StrLineaProd_ As String
    
    While Not rs.EOF
        StrProdId_ = Alineacion("I", 7, Len(rs!CDCAT), rs!CDCAT)
        StrProdDes_ = Alineacion("I", 17, Len(rs!DSCAT), rs!DSCAT)
        StrProdCant_ = Alineacion("D", 6, Len(GFormatodeNumero(rs!CANTIDAD, GintDecStock)), GFormatodeNumero(rs!CANTIDAD, GintDecStock))
        
        If StrMdaBase = StrMdaCaja Then
            StrProdTotal_ = Alineacion("D", 7, Len(GFormatodeNumero(rs!TOTALPEN, GintDecResultado)), GFormatodeNumero(rs!TOTALPEN, GintDecResultado))
            DblProdTotal_ = DblProdTotal_ + rs!TOTALPEN
        Else
            StrProdTotal_ = Alineacion("D", 7, Len(GFormatodeNumero(rs!TOTALUSD, GintDecResultado)), GFormatodeNumero(rs!TOTALUSD, GintDecResultado))
            DblProdTotal_ = DblProdTotal_ + rs!TOTALUSD
        End If
        
        StrLineaProd_ = StrProdId_ & " " & StrProdDes_ & " " & StrProdCant_ & " " & StrProdTotal_
        
        'Printer.Print StrLineaProd_
        StrResProducto = StrResProducto & StrLineaProd_ & vbCrLf
        'Print #fp, StrLineaProd_
    
        rs.MoveNext
    Wend
    
    StrLineaProd_ = Alineacion("D", IntAnchoTicket, Len("Total  " & StrSimbMdaCaja & " : " & GFormatodeNumero(DblProdTotal_, GintDecResultado)), _
                    "Total  " & StrSimbMdaCaja & " : " & GFormatodeNumero(DblProdTotal_, GintDecResultado))
                    
    'Printer.Print StrLineaProd_
    StrResProducto = StrResProducto & StrLineaProd_ & vbCrLf
    'Print #fp, StrLineaProd_
    
    ' si el cierre es X y el lugar es Tienda
    If IntLugar = 1 And IntTipoCierre = 1 Then GoTo Salto01
    'If IntTipoCierre <> 1 And IntLugar <> 1 Then
        ' separacion
        'Printer.Print
        StrResVendedor = StrResVendedor & "" & vbCrLf
        'Print #fp, ""
        'Printer.Print
        StrResVendedor = StrResVendedor & "" & vbCrLf
        'Print #fp, ""
        'Printer.Print Alineacion("C", IntAnchoTicket, Len("RESUMEN POR VENDEDOR"), "RESUMEN POR VENDEDOR")
        StrResVendedor = StrResVendedor & Alineacion("C", IntAnchoTicket, Len("RESUMEN POR VENDEDOR"), "RESUMEN POR VENDEDOR") & vbCrLf
        'Print #fp, Alineacion("C", IntAnchoTicket, Len("RESUMEN POR VENDEDOR"), "RESUMEN POR VENDEDOR")
        'Printer.Print LLinea
        StrResVendedor = StrResVendedor & LLinea & vbCrLf
        'Print #fp, LLinea
        
        ' RESUMEN POR VENDEDOR
        rs.Filter = "[SECCION]='VEND'"
        rs.Sort = "[CDCAT] ASC"
        
        Dim StrVendId_ As String
        Dim StrVendDes_ As String
        Dim StrVendTotal_ As String
        Dim StrLineaVend_ As String
        Dim DblTotalVend_ As Double
        
        'GFormatodeNumero(rs!TOTALUSD, GintDecResultado)
        While Not rs.EOF
            StrVendId_ = Alineacion("I", 8, Len(rs!CDCAT), rs!CDCAT)
            StrVendDes_ = Alineacion("I", 20, Len(rs!DSCAT), rs!DSCAT)
            
            If StrMdaBase = StrMdaCaja Then
                StrVendTotal_ = Alineacion("D", 10, Len(GFormatodeNumero(rs!TOTALPEN, GintDecResultado)), GFormatodeNumero(rs!TOTALPEN, GintDecResultado))
                DblTotalVend_ = DblTotalVend_ + rs!TOTALPEN
            Else
                StrVendTotal_ = Alineacion("D", 10, Len(GFormatodeNumero(rs!TOTALUSD, GintDecResultado)), GFormatodeNumero(rs!TOTALUSD, GintDecResultado))
                DblTotalVend_ = DblTotalVend_ + rs!TOTALUSD
            End If
            
            StrLineaVend_ = StrVendId_ & " " & StrVendDes_ & " " & StrVendTotal_
                         
            'Printer.Print StrLineaVend_
            StrResVendedor = StrResVendedor & StrLineaVend_ & vbCrLf
            'Print #fp, StrLineaVend_
        
            rs.MoveNext
        Wend
        
        StrLineaVend_ = Alineacion("D", IntAnchoTicket, Len("Total  " & StrSimbMdaCaja & " : " & GFormatodeNumero(DblTotalVend_, GintDecResultado)), _
                        "Total  " & StrSimbMdaCaja & " : " & GFormatodeNumero(DblTotalVend_, GintDecResultado))
        
        'Printer.Print StrLineaVend_
        StrResVendedor = StrResVendedor & StrLineaVend_ & vbCrLf
        'Print #fp, StrLineaVend_
    'End If
    
Salto01:
    If IntLugar = 1 Then GoTo Salto02

    ' RESUMEN POR CARA
    rs.Filter = "[SECCION]='CAR'"
    rs.Sort = "[CDCARA] ASC,[CDCAT] ASC"
    
    ' separacion
    'Printer.Print
    StrResCara = StrResCara & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print
    StrResCara = StrResCara & "" & vbCrLf
    'Print #fp, ""
    'Printer.Print Alineacion("C", IntAnchoTicket, Len("RESUMEN POR CARA"), "RESUMEN POR CARA")
    StrResCara = StrResCara & Alineacion("C", IntAnchoTicket, Len("RESUMEN POR CARA"), "RESUMEN POR CARA") & vbCrLf
    'Print #fp, Alineacion("C", IntAnchoTicket, Len("RESUMEN POR CARA"), "RESUMEN POR CARA")
    'Printer.Print LLinea
    StrResCara = StrResCara & LLinea & vbCrLf
    'Print #fp, LLinea

    
    Dim StrCaraId_ As String
    Dim StrCaraProdId_ As String
    Dim StrCaraProdDes_ As String
    Dim StrCaraProdGal_ As String
    Dim StrCaraProdTotal_ As String
    Dim StrLineaCara_ As String
    Dim StrTmpCaraId_ As String
    
    Dim DblTotalCara_ As Double
    
    While Not rs.EOF
        If Trim(StrTmpCaraId_) <> Trim(rs!cdcara) Then
            StrTmpCaraId_ = rs!cdcara
            StrLineaCara_ = Alineacion("I", 14, Len("CARA : ") & rs!cdcara, "CARA : " & rs!cdcara)
            
            'Printer.Print StrLineaCara_
            StrResCara = StrResCara & StrLineaCara_ & vbCrLf
            'Print #fp, StrLineaCara_
        End If
        
        'StrCaraId_ = Alineacion("I", 10, Len(rs!cdcara), rs!cdcara)
        StrCaraProdId_ = Alineacion("I", 7, Len(rs!CDCAT), rs!CDCAT)
        StrCaraProdDes_ = Alineacion("I", 17, Len(rs!DSCAT), rs!DSCAT)
        StrCaraProdGal_ = Alineacion("I", 6, Len(GFormatodeNumero(rs!CANTIDAD, GintDecStock)), GFormatodeNumero(rs!CANTIDAD, GintDecStock))
        
        If StrMdaBase = StrMdaCaja Then
            StrCaraProdTotal_ = Alineacion("D", 7, Len(GFormatodeNumero(rs!TOTALPEN, GintDecResultado)), GFormatodeNumero(rs!TOTALPEN, GintDecResultado))
            DblTotalCara_ = DblTotalCara_ + rs!TOTALPEN
        Else
            StrCaraProdTotal_ = Alineacion("D", 7, Len(GFormatodeNumero(rs!TOTALUSD, GintDecResultado)), GFormatodeNumero(rs!TOTALUSD, GintDecResultado))
            DblTotalCara_ = DblTotalCara_ + rs!TOTALUSD
        End If
        
        StrLineaCara_ = StrCaraProdId_ & " " & _
                        StrCaraProdDes_ & " " & StrCaraProdGal_ & " " & _
                        StrCaraProdTotal_
        
        'Printer.Print StrLineaCara_
        StrResCara = StrResCara & StrLineaCara_ & vbCrLf
        'Print #fp, StrLineaCara_
    
        rs.MoveNext
    Wend
    
    StrLineaProd_ = Alineacion("D", IntAnchoTicket, Len("Total  " & StrSimbMdaCaja & " : " & GFormatodeNumero(DblTotalCara_, GintDecResultado)), _
                    "Total  " & StrSimbMdaCaja & " : " & GFormatodeNumero(DblTotalCara_, GintDecResultado))

    'Printer.Print StrLineaProd_
    StrResCara = StrResCara & StrLineaProd_ & vbCrLf
    'Print #fp, StrLineaProd_
    
Salto02:
    StrSalto = ""
    ' lineas de salto
    Dim Inti As Integer
    For Inti = 0 To IntNroSaltosLineas
        'Printer.Print ""
        StrSalto = StrSalto & "" & vbCrLf
        'Print #fp, ""
    Next
    
    StrSalto = StrSalto & StrCodCorte
    
    ' salida del documento
    ' If IntDestino = 1 Then ' por impresora
    '    Close #fp
    '    Printer.Print StrCadenon
    '    Printer.EndDoc
    'End If
    'If IntDestino = 2 Then ' por pantalla
        'Printer.KillDoc
        'Printer.EndDoc
    '    Print #1, StrCadenon
    '    Close #fp
    '    Shell "notepad.exe temp.txt", vbMaximizedFocus
    'End If
    
    'Imprimir_Cierre = StrCadenon
    
    BlnOK = True ' si todo fue correcto
    
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    BlnOK = False ' si algo fallo
'    Close #fp
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If

    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_OP_FACTURACION.Imprimir_Cierre", Err.Description
End Sub

Sub Actualizar_Datos_LuegodeCierreZ(StrNroPtoVta As String, StrFechaCierre As String, _
                                    DblGranTotal As Double, IntNroZeta As Integer)
    Dim cmd As ADODB.Command
    Dim StrSql As String
    
On Error GoTo errhandler
    
    'If BlnOK Then
        StrSql = "ACTUALIZA_DATOS_LUEGODECIERREZ " & _
        "'" & StrNroPtoVta & "','" & StrFechaCierre & "'," & DblGranTotal & "," & IntNroZeta
        
        Set cmd = New ADODB.Command
        
        cmd.CommandText = StrSql
        cmd.ActiveConnection = "FILEDSN=conexionsies"
        cmd.Execute
    'End If
    
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    'BlnOK = False ' si algo fallo
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.Actualiza_Datos_Zeta", Err.Description
End Sub

Sub Actualizar_Datos_LuegodeCierreX(StrNroPtoVta As String, IntLugar As Integer, _
                                    IntTurno As Integer, StrFechaCierre As String, _
                                    DblGranTotal As Double, IntNroZeta As Integer, _
                                    StrSalesPerId As String)
        Dim cmd As ADODB.Command
        Dim StrSql As String
        
On Error GoTo errhandler

    'If BlnOK Then
        StrSql = "ACTUALIZA_DATOS_LUEGODECIERREX '" & StrNroPtoVta & "'," & IntLugar & "," & IntTurno & ",'" & StrSalesPerId & "','" & Format(Trim(StrFechaCierre), "yyyyMMdd") & "'"
        
        Set cmd = New ADODB.Command
        
        cmd.CommandText = StrSql
        cmd.ActiveConnection = "FILEDSN=conexionsies"
        cmd.Execute
    'End If
    'GetObjectContext.SetComplete
    Exit Sub
        
errhandler:
    'BlnOK = False ' si algo fallo
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.Actualizar_Datos_LuegodeCierreX", Err.Description
End Sub

Sub Cargar_Datos_Impresora(StrNroPtoVta As String, ByRef IntNroSaltosLineas As Integer, _
                           ByRef StrCodCorte As String, ByRef IntAnchoTicket As Integer)
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    Dim PrinterTypeID As String
    
On Error GoTo errhandler

    StrSql = "SELECT PRINTERTYPEID FROM OP_SALESPOINTSETTING WHERE SALESPOINT='" & StrNroPtoVta & "'"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        PrinterTypeID = rs!PrinterTypeID
            
        rs.Close
        
        StrSql = "SP_SelProcOP_PRINTERTYPE '" & PrinterTypeID & "'"
        
        rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
        
        If Not rs.EOF Then
            IntNroSaltosLineas = IIf(IsNull(rs!JUMPLINES), 40, rs!JUMPLINES)
            StrCodCorte = IIf(IsNull(rs!IDCUTPAPER), "", rs!IDCUTPAPER)
            IntAnchoTicket = IIf(IsNull(rs!WIDELINES), 10, rs!WIDELINES)
        Else
            IntAnchoTicket = 40
            IntNroSaltosLineas = 10
        End If
    End If
    
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
    'GetObjectContext.SetAbort
    
    Err.Raise Err.Number, "DB_OP_FACTURACION.Cargar_Datos_Impresora", Err.Description
End Sub

Sub Obtener_Linea_Ticket(ByRef StrLineaSeparacion As String)
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
    StrSql = "SELECT LINES1 FROM OP_TICKETFORM"
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
On Error GoTo errhandler

    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        StrLineaSeparacion = IIf(IsNull(rs!LINES1), "-", rs!LINES1)
    Else
        StrLineaSeparacion = "-"
    End If
    
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_Linea_Ticket", Err.Description
End Sub

'devuelve:
' 0 : si no puede realizarse el cierre (ni pantalla, ni impresora)
' 1 : si existen transacciones pendientes
' 2 : si no hay transacciones pendientes
Function Ver_Transacciones_Pendientes(IntLugar As Integer, StrNroPtoVta As String) As Integer
    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    Dim StrNomTablaDBF As String
    
On Error GoTo errhandler
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    If IntLugar = 1 Then ' Tienda
        ' Segun Grober, para tiendas no se debe preocupar por esto
        ' asi que se asume todo bien
        Ver_Transacciones_Pendientes = 2
    End If
    If IntLugar = 2 Then ' Playa
    ' 1. Obtener la cara del punto de venta
        StrSql = "select side from OP_SalesPointVSSide where SalesPoint='" & StrNroPtoVta & "'"
        
        rs.Open StrSql, con, adOpenStatic
        
        Ver_Transacciones_Pendientes = 2 ' se asume que inicialmente no
                                         ' existen transacciones pendientes
        
        If Not rs.EOF Then
            ' armar el nombre de la tabla dbf
            StrNomTablaDBF = "Tran" & Trim(rs!side)
        Else
            ' si no hay configurado una cara
            StrNomTablaDBF = ""
            Ver_Transacciones_Pendientes = 0
        End If
    End If
    
    'GetObjectContext.SetComplete
    Exit Function
    
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If
    
    'GetObjectContext.SetAbort

    Err.Raise Err.Number, "DB_OP_FACTURACION.Ver_Transacciones_Pendientes", Err.Description
End Function

Function Ver_Transacciones_Pendientes2(IntLugar As Integer, StrNroPtoVta As String) As Recordset
    Dim con As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim StrSql As String

    
On Error GoTo errhandler
    Set con = New ADODB.Connection
    con.Open "FILEDSN=conexionsies"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    If IntLugar = 1 Then ' Tienda
        ' Segun Grober, para tiendas no se debe preocupar por esto
        ' asi que se asume todo bien
        'Ver_Transacciones_Pendientes2 = Empty
    End If
    If IntLugar = 2 Then ' PLaya
    ' 1. Obtener la cara del punto de venta
        StrSql = "select side from OP_SalesPointVSSide where SalesPoint='" & StrNroPtoVta & "'"
        
        rs.Open StrSql, con, adOpenStatic
        
        'Ver_Transacciones_Pendientes2 = Empty ' se asume que inicialmente no
                                         ' existen transacciones pendientes
        
        'If Not rs.EOF Then
            ' armar el nombre de la tabla dbf
        '    Ver_Transacciones_Pendientes2 = "Tran" & Trim(rs!side)
        'Else
            ' si no hay configurado una cara
            
        '    Ver_Transacciones_Pendientes2 = Empty
        'End If
        
        Set Ver_Transacciones_Pendientes2 = rs
    End If
        
    'GetObjectContext.SetComplete
    Exit Function
    
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    If Not con Is Nothing Then
        Set con = Nothing
    End If
    
    'GetObjectContext.SetAbort

    Err.Raise Err.Number, "DB_OP_FACTURACION.Ver_Transacciones_Pendientes2", Err.Description
End Function

Function MensajeOK() As Boolean
    MensajeOK = True

'    If BlnOK Then
'        If IntTipoCierre = 1 Then ' Cierre X
'            MsgBox "Proceso de Cierre X realizado", vbInformation, "Mensaje"
'        End If
'        If IntTipoCierre = 2 Then ' Cierre Z
'            MsgBox "Proceso de Cierre Z realizado", vbInformation, "Mensaje"
'        End If
'    Else
'        If IntTipoCierre = 1 Then ' Cierre X
'            MsgBox "Fallo en el Proceso de Cierre X", vbCritical, "Error"
'        End If
'        If IntTipoCierre = 2 Then ' Cierre Z
'            MsgBox "Fallo en el Proceso de Cierre Z", vbCritical, "Error"
'        End If
'    End If
End Function

Function Obtener_Porcentaje_IGV() As Double
    Dim rs As ADODB.Recordset
    
On Error GoTo erryhandler
    
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    
    rs.Open "select TAXVALUEIGV from setup", "FILEDSN=conexionsies", adOpenStatic
    
    If Not rs.EOF Then
        Obtener_Porcentaje_IGV = rs!TAXVALUEIGV
    Else
        Obtener_Porcentaje_IGV = 0
    End If
    
    'GetObjectContext.SetComplete
    Exit Function
erryhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.Obtener_Porcentaje_IGV", Err.Description
End Function


Function Tran_Facturado(rstran As ADODB.Recordset) As Boolean
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
    Set rs = New ADODB.Recordset
    
    Tran_Facturado = True
    
    While Not rstran.EOF
        StrSql = "Select * from OP_TRAN " & _
        "where " & _
        " numero='" & Trim(rstran!numero) & "' and " & _
        " soles='" & Trim(rstran!soles) & "' and " & _
        " producto='" & Trim(rstran!producto) & "' and " & _
        " precio='" & Trim(rstran!precio) & "' and " & _
        " galones='" & Trim(rstran!galones) & "' and " & _
        " cara='" & Trim(rstran!cara) & "' and " & _
        " fecha='" & Trim(rstran!fecha) & "' and " & _
        " hora='" & Trim(rstran!hora) & "' and " & _
        " turno='" & Trim(rstran!hora) & "' and " & _
        " estado='" & Trim(rstran!estado) & "'"
        
        rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
        
        If Not rs.EOF Then
            If Not IsNull(rs!numero) And Not IsNull(rs!turno) Then
                Tran_Facturado = False
                Exit Function
            End If
        End If
        
        rstran.MoveNext
    Wend
    
    'GetObjectContext.SetComplete
    Exit Function
erryhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.Tran_Facturado", Err.Description
End Function

Function Tipo_Negocio(StrNroPtoVta As String) As String
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
On Error GoTo errhandler
    
    StrSql = "Select BusinessType from OP_SalesPointSetting " & _
    " where SalesPoint='" & StrNroPtoVta & "'"
    
    Set rs = New ADODB.Recordset
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    Tipo_Negocio = rs!BusinessType
    
    'GetObjectContext.SetComplete
    Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.Tipo_Negocio", Err.Description
End Function

Function ListarAlmacenes() As ADODB.Recordset
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
On Error GoTo errhandler
    Set rs = New ADODB.Recordset

    StrSql = "Select * from Site"
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set ListarAlmacenes = rs
    
    'GetObjectContext.SetComplete
    Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.ListarAlmacenes", Err.Description
End Function

Function ListarPtoVtas(StrSiteId As String) As ADODB.Recordset
    Dim rs As ADODB.Recordset
    Dim StrSql As String
    
On Error GoTo errhandler
    
    Set rs = New ADODB.Recordset

    StrSql = "SELECT SALESPOINT AS PtoVtaID,SALESPOINT as Descr" & _
    " FROM OP_SALESPOINTSETTING " & _
    " WHERE SITEID='" & Trim(StrSiteId) & "'"
    
    rs.Open StrSql, "FILEDSN=conexionsies", adOpenStatic
    
    Set ListarPtoVtas = rs
    
    'GetObjectContext.SetComplete
    Exit Function
errhandler:
    If Not rs Is Nothing Then
        Set rs = Nothing
    End If
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.ListarPtoVtas", Err.Description
End Function


Sub Crear_VW_RCierreZ(StrFechaIni As String, StrFechaFin As String, StrSite As String, StrPtoVtas As String)
    Dim cmd As ADODB.Command
    Dim StrSql As String
    
On Error GoTo errhandler
        
    Set cmd = New ADODB.Command
    
    cmd.ActiveConnection = "FILEDSN=conexionsies"
    
    StrSql = "if exists " & _
    " (select * from sysobjects where id = object_id(N'[dbo].[VW_RCIERREZ]') and " & _
    " OBJECTPROPERTY(id, N'IsView') = 1) drop view [dbo].[VW_RCIERREZ]"
    
    cmd.CommandText = StrSql
    cmd.Execute
    
    StrSql = "CREATE VIEW dbo.VW_RCIERREZ AS " & _
  "SELECT OP_SALES.DOCTYPEID, OP_SALES.NBRDOCUMENT,OP_SALES.SITEID, OP_SALES.CURYID,OP_SALES.DOCSTATUSID, OP_SALES.SALESPERID," & _
    "OP_SALES.USERID, OP_SALES.DATEDOC,OP_SALES.DATEPROCESALES, OP_SALES.PERPOST,OP_SALES.TOTALPEN, OP_SALES.TOTALUSD, OP_SALES.SUBTOTALPEN,OP_SALES.SUBTOTALUSD," & _
    "OP_SALES.TAXIGVPEN, OP_SALES.TAXIGVUSD,OP_SALES.TAXISCPEN, OP_SALES.TAXISCUSD,OP_SALES.TOTALNOTAFFECTPEN,OP_SALES.TOTALNOTAFFECTUSD, OP_SALES.TOTCASHPEN," & _
    "OP_SALES.TOTRETURNEDPEN,OP_SALES.TOTRETURNEDUSD, OP_SALES.TOTCASHUSD,OP_SALES.custidss, OP_SALES.taxregnbr,OP_SALES.CUSTNAME, OP_SALES.PLACA," & _
    "OP_SALES.NBRBONUS, OP_SALES.CURYTYPEID,OP_SALES.STKCLOSEDX, OP_SALES.CURYRATE,OP_SALES.SALESPOINT, OP_SALESDET.INVTIDSKU,OP_SALESDET.CURYID AS CURYIDDET," & _
    "OP_SALESDET.SEQUENCE,OP_SALESDET.DOCSTATUSID AS DOCSTATUSIDDET,OP_SALESDET.DATEDOC AS DATEDOCDET,OP_SALESDET.DATEPROCESALES AS DATEPROCESALESDET," & _
    "OP_SALESDET.PERPOST AS PERPOSTDET,OP_SALESDET.NBRTURN, OP_SALESDET.NBRSIDE,OP_SALESDET.NBRTRANSACFUEL,OP_SALESDET.PORCENTTAXIGV," & _
    "OP_SALESDET.PORCENTTAXISC,OP_SALESDET.TOTALPEN AS TOTALPENDET,OP_SALESDET.TOTALUSD AS TOTALUSDDET, OP_SALESDET.TAXPEN,OP_SALESDET.TAXUSD," & _
    "OP_SALESDET.STKITEM, OP_SALESDET.STKFISI,OP_SALESDET.SLS_PRICE, OP_SALESDET.SLSPRICESALE,OP_SALESDET.STDCOSTPEN, OP_SALESDET.STDCOSTUSD," & _
    "OP_SALESDET.INVTIDALTER,OP_SALESDET.DESCRINVENTORY, OP_SALESDET.QTY,OP_SALESDET.USERID AS USERIDDET, OP_SALESDET.KIT, OP_SALES.TYPEPAYMENTID, IN_CATEGORY.CLASSID," & _
    "IN_CATEGORY.DESCR AS DESCATEGORIA,IN_INVENTORY.DESCR AS DESCRPRODUCTO,OP_SALESPERSON.SALESPERNAME,OP_SALESCARD.TOTCARDPEN,OP_SALESCARD.TOTCARDUSD " & _
  "FROM OP_SALES INNER JOIN OP_SALESDET ON OP_SALES.DOCTYPEID = OP_SALESDET.DOCTYPEID AND OP_SALES.NBRDOCUMENT = OP_SALESDET.NBRDOCUMENT AND " & _
    "OP_SALES.SITEID = OP_SALESDET.SITEID INNER JOIN IN_INVENTORY ON OP_SALESDET.INVTIDSKU = IN_INVENTORY.INVTIDSKU INNER JOIN IN_CATEGORY ON " & _
    "IN_INVENTORY.CLASSID = IN_CATEGORY.CLASSID INNER JOIN OP_SALESPERSON ON OP_SALES.SALESPERID = OP_SALESPERSON.SALESPERID INNER JOIN OP_SETUP ON " & _
    "OP_SALES.DOCTYPEID = OP_SETUP.DOCTYPEIDTICKET LEFT JOIN OP_SALESCARD ON " & _
    "OP_SALES.DOCTYPEID = OP_SALESCARD.DOCTYPEID AND OP_SALES.NBRDOCUMENT = OP_SALESCARD.NBRDOCUMENT AND OP_SALES.SITEID = OP_SALESCARD.SITEID " & _
  "WHERE OP_SALES.DATEPROCESALES BETWEEN '" & Format(StrFechaIni, "yyyyMMdd") & "' AND '" & Format(StrFechaFin, "yyyyMMdd") & "' AND OP_SALES.SITEID='" & StrSite & "' AND OP_SALES.SALESPOINT IN(" & StrPtoVtas & ")"
    
    cmd.CommandText = StrSql
    cmd.Execute
      
    'GetObjectContext.SetComplete
    Exit Sub
errhandler:
    If Not cmd Is Nothing Then
        Set cmd = Nothing
    End If
    'GetObjectContext.SetAbort
    Err.Raise Err.Number, "DB_OP_FACTURACION.Crear_VW_RCierreZ", Err.Description
End Sub


