Attribute VB_Name = "funciones"
Global seleccion As Integer
Global modificar As Boolean
Global ticket As Long
Global seleccionarmesas As Boolean
Global MesaActual As Integer
                        'Numero mesa, numero producto, precio. Si numero producto=999, poner precio.
Global mesa(61, 999, 4) 'el tercer numero se usa tambien para saber estado si cobrado=0 o pendiente=1
                        ' ultimo numero: 4. cantidad de productos
Global pass As String

' Conectar con la base de datos
' que contiene los precios de los botones

Option Explicit
Dim Ruta As String

Public MiBase As Database
Public TablaPrecios As Recordset
Public TablaTicket As Recordset
Public config As Recordset

Public Sub ponerticket()
    Dim t As Recordset
    
    Dim tmpdata As String
     tmpdata = "SELECT idticket FROM ticketprecio ORDER BY idticket ASC"

    Panel.Data3.RecordSource = tmpdata
    Panel.Data3.Refresh
    Panel.Data3.Recordset.MoveLast
    ticket = Panel.Data3.Recordset.Fields(0)
    ticket = ticket + 1
    Panel.Label1.Caption = ticket

End Sub

Public Sub EnlazarBase()
Ruta = "" & App.Path & "\precios.mdb"
Set MiBase = OpenDatabase(Ruta)
Set TablaPrecios = MiBase.OpenRecordset("precios")
Set TablaTicket = MiBase.OpenRecordset("ticketprecio")



Panel.Data1.DatabaseName = "" & App.Path & "\precios.mdb"
Panel.Data2.DatabaseName = "" & App.Path & "\precios.mdb"
Panel.Data3.DatabaseName = "" & App.Path & "\precios.mdb"

'Panel.MSComm1.CommPort = 4
'Panel.MSComm1.Settings = "9600,N,8,1"
'Panel.MSComm1.PortOpen = True
'Panel.MSComm1.InputLen = 0
'Panel.MSComm1.RThreshold = 1
'Panel.MSComm1.SThreshold = 1


End Sub

'--------------------------------------


Public Sub nombrebotones(indice As Integer)
Dim I As Integer
Dim j As Integer
TablaPrecios.MoveFirst

    For j = 0 To indice
        TablaPrecios.MoveNext
        
    Next j
TablaPrecios.MovePrevious
    For I = 0 To 62
        Panel.btnSeleccion(I).Caption = ("" & TablaPrecios("boton"))
    Panel.btnSeleccion(I).BackColor = 12632256
    
        Panel.btnSeleccion(I).Visible = True
    
        TablaPrecios.MoveNext
    Next I
        
End Sub

Public Sub mesabotones() 'Poner nombre de las mesas de la 1 a la 30

Dim I As Integer
Dim K As Integer
K = 0
    For I = 0 To 55
        Panel.btnSeleccion(I).Caption = ("Mesa " & I + 1)
        If mesa(I + 1, 0, 0) <> 0 Then
            If mesa(I + 1, 0, 2) = 1 Then
                Panel.btnSeleccion(I).BackColor = &H8080FF
            Else
                Panel.btnSeleccion(I).BackColor = &H80000005
            End If
           ' Panel.lblMesa(k).Visible = True
          '  Panel.lblMesa(k).Caption = i + 1
          '  k = k + 1
        End If
    Next I
    For K = 56 To 62
        Panel.btnSeleccion(K).Visible = False
    Next K
    
    
End Sub

'Agregar producto al pulsar un boton
Public Sub agregaProducto(id As Integer)
Dim I As Integer
Dim fecha As Date
fecha = Now
fecha = DateAdd("h", -4, fecha)
fecha = Format(fecha, "short date")


 
    TablaPrecios.MoveFirst
    For I = 0 To id
        TablaPrecios.MoveNext
    Next I
    TablaPrecios.MovePrevious
    If TablaPrecios("boton") <> "" Then
        Panel.LTotal = Panel.LTotal + CDbl("0" & TablaPrecios("precio"))
        
        
        'recorrer lista mirando si ID Producto esta, y si esta, poner uno mas, sino agregar
        
        Dim Y As Long
        Dim encontrado As Boolean
        encontrado = False
        
        With Panel.MSFlexGrid1
            For Y = .FixedRows To .Rows - 1
                If .TextMatrix(Y, 2) = I Then
                .TextMatrix(Y, 0) = .TextMatrix(Y, 0) + 1
                .TextMatrix(Y, 5) = CDbl(.TextMatrix(Y, 4)) * CDbl(.TextMatrix(Y, 0))
                
                encontrado = True
                End If
            
            
            Next Y
        End With
        
        
    If encontrado = False Then
        
        Panel.MSFlexGrid1.AddItem ("1" & vbTab & _
        ticket & vbTab & _
        I & vbTab & _
        TablaPrecios("ticket") & vbTab & _
        CDbl("0" & TablaPrecios("precio")) & vbTab & _
        CDbl("0" & TablaPrecios("precio")) & vbTab & _
        CDate(fecha))
    End If
    
    
        'recorrer lista mirando si ID Producto esta, y si esta, poner uno mas, sino agregar
        
        'visor TablaPrecios("ticket"), Panel.LTotal, TablaPrecios("precio")
      
        Dim X As Long
        With Panel.MSFlexGrid1
            For X = .FixedRows To .Rows - 1
            
                .TextMatrix(X, 4) = Format(.TextMatrix(X, 4), "###0.00")
                .TextMatrix(X, 5) = Format(.TextMatrix(X, 5), "###0.00")
            Next X
        End With
     
        Panel.MSFlexGrid1.Row = Panel.MSFlexGrid1.Rows - 1
        Panel.MSFlexGrid1.TopRow = Panel.MSFlexGrid1.Rows - 1
        
    End If
    
'listamesas
    
End Sub

Public Sub modificarProducto(id As Integer)
Dim I As Integer
id = id + seleccion
    TablaPrecios.MoveFirst
    For I = 0 To id
        TablaPrecios.MoveNext
    Next I
    TablaPrecios.MovePrevious
    Precio.Show
    Precio.nBoton.Text = ("" & TablaPrecios("boton"))
    Precio.nTicket.Text = ("" & TablaPrecios("ticket"))
    Precio.nPrecio.Text = CDbl("0" & TablaPrecios("precio"))


End Sub

Public Sub actualizalista()

Panel.MSFlexGrid1.Visible = True
Panel.MSFlexGrid1.ColWidth(0) = 320 ' cantidad
Panel.MSFlexGrid1.ColWidth(1) = 0 ' numero de ticket
Panel.MSFlexGrid1.ColWidth(2) = 0 ' numero de producto
Panel.MSFlexGrid1.ColWidth(3) = 2600 '2600 nombre
Panel.MSFlexGrid1.ColWidth(4) = 0 ' precio unidad
Panel.MSFlexGrid1.ColWidth(5) = 800 ' precio  total
Panel.MSFlexGrid1.ColWidth(6) = 0 ' fecha
Panel.MSFlexGrid1.ColAlignment(4) = 7
Panel.MSFlexGrid1.ColAlignment(5) = 7
Panel.MSFlexGrid1.ColAlignment(3) = 1
Panel.MSFlexGrid1.Rows = 0
Panel.LTotal = 0

End Sub
Public Sub actualizarprecio()
Dim Precio As Double
Dim I As Integer

    For I = 0 To Panel.MSFlexGrid1.Rows - 1
        Precio = Panel.MSFlexGrid1.TextMatrix(I, 5) + Precio
    Next I
Panel.LTotal = Precio
'visor "           ", CStr(Precio), "     "

End Sub
Public Sub estadisticas(fecha As Date, fecha2 As Date)

frmEstadisticas.Show
    frmEstadisticas.Data1.DatabaseName = "" & App.Path & "\precios.mdb"
    frmEstadisticas.MSFlexGrid1.Rows = 0
    frmEstadisticas.MSFlexGrid1.ColWidth(0) = 800
    frmEstadisticas.MSFlexGrid1.ColWidth(1) = 2200
    frmEstadisticas.MSFlexGrid1.ColAlignment(1) = 1
    frmEstadisticas.LTotal.Caption = 0
    frmEstadisticas.lTotalMesas.Caption = 0
    frmEstadisticas.lTotalBarra.Caption = 0
    frmEstadisticas.lTotalBebidaM.Caption = 0
    frmEstadisticas.lTotalComidaM.Caption = 0
  '  frmEstadisticas.LFecha.Caption = fecha
  '  frmEstadisticas.LFecha2.Caption = fecha2
  '  frmEstadisticas.LTicket.Caption = ticket
    
    frmEstadisticas.TFecha.Text = fecha
    frmEstadisticas.TFecha2.Text = fecha2
    frmEstadisticas.TTicket.Text = ticket
    
    frmEstadisticas.MSFlexGrid2.Visible = False
    frmEstadisticas.MSFlexGrid1.Visible = True
    
    Dim tmpdata As String
    tmpdata = "SELECT * FROM ticketprecio WHERE fecha BETWEEN #" & Format(CDate(fecha), "mm\/dd\/yyyy") & "# and #" & Format(CDate(fecha2), "mm\/dd\/yyyy") & "# ORDER BY id ASC" '& Date & " ORDER BY id DESC"

    frmEstadisticas.Data1.RecordSource = tmpdata
    frmEstadisticas.Data1.Refresh
    
    Dim I As Long
    Dim t As Long
    Dim echo As Boolean
    echo = False
    I = 0
  '  frmEstadisticas.LTicket.Caption = 0
    frmEstadisticas.TTicket.Text = 0
    
    If Not frmEstadisticas.Data1.Recordset.EOF Then
        frmEstadisticas.Data1.Recordset.MoveFirst
        t = frmEstadisticas.Data1.Recordset.Fields(1)
        frmEstadisticas.Data1.Recordset.MoveLast
        t = frmEstadisticas.Data1.Recordset.Fields(1) - t
        frmEstadisticas.Data1.Recordset.MoveFirst
      '  frmEstadisticas.LTicket.Caption = t + 1
         frmEstadisticas.TTicket.Text = t + 1
    End If
    
    While Not (frmEstadisticas.Data1.Recordset.EOF)
        While I < frmEstadisticas.MSFlexGrid1.Rows And Not echo
            If frmEstadisticas.Data1.Recordset.Fields(4) = frmEstadisticas.MSFlexGrid1.TextMatrix(I, 1) Then
                frmEstadisticas.MSFlexGrid1.TextMatrix(I, 0) = frmEstadisticas.MSFlexGrid1.TextMatrix(I, 0) + 1
                echo = True
            End If
            I = I + 1
        Wend
        
        If Not echo Then
            frmEstadisticas.MSFlexGrid1.AddItem ("1" & vbTab & frmEstadisticas.Data1.Recordset.Fields(4))
        End If
        echo = False
        I = 0
        
        
        If frmEstadisticas.Data1.Recordset.Fields(7) < 60 Then 'si es una mesa..
         '   MsgBox (frmEstadisticas.Data1.Recordset.Fields(2))
         'si es bebida, sumar en bebida
         If frmEstadisticas.Data1.Recordset.Fields(2) > 630 And frmEstadisticas.Data1.Recordset.Fields(2) < 694 Then
 
             frmEstadisticas.lTotalBebidaM.Caption = frmEstadisticas.lTotalBebidaM.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
         Else ' si No es bebida
            frmEstadisticas.lTotalComidaM.Caption = frmEstadisticas.lTotalComidaM.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
         End If
             
            frmEstadisticas.lTotalMesas.Caption = frmEstadisticas.lTotalMesas.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
          
          
          
        Else ' si no es una mesa
          frmEstadisticas.lTotalBarra.Caption = frmEstadisticas.lTotalBarra.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
        End If
        frmEstadisticas.LTotal.Caption = frmEstadisticas.LTotal.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
        
    
      
        ' Poner en formato 0,00
        frmEstadisticas.lTotalBebidaM.Caption = Format(frmEstadisticas.lTotalBebidaM.Caption, "###0.00")
        frmEstadisticas.lTotalComidaM.Caption = Format(frmEstadisticas.lTotalComidaM.Caption, "###0.00")
        frmEstadisticas.lTotalBarra.Caption = Format(frmEstadisticas.lTotalBarra.Caption, "###0.00")
        frmEstadisticas.lTotalMesas.Caption = Format(frmEstadisticas.lTotalMesas.Caption, "###0.00")
        frmEstadisticas.LTotal.Caption = Format(frmEstadisticas.LTotal.Caption, "###0.00")
        
                
        frmEstadisticas.Data1.Recordset.MoveNext
    Wend
    
    frmEstadisticas.MSFlexGrid1.Col = 0
    frmEstadisticas.MSFlexGrid1.Sort = flexSortNumericDescending
    frmEstadisticas.lista.Caption = "Lista de productos"



End Sub

Public Sub visor(linea1 As String, total As String, Precio As String)
Dim strtexto As String

strtexto = linea1
strtexto = Replace(strtexto, "á", "a")
strtexto = Replace(strtexto, "é", "e")
strtexto = Replace(strtexto, "í", "i")
strtexto = Replace(strtexto, "ó", "o")
strtexto = Replace(strtexto, "ú", "u")
strtexto = Replace(strtexto, "Á", "A")
strtexto = Replace(strtexto, "É", "E")
strtexto = Replace(strtexto, "Í", "I")
strtexto = Replace(strtexto, "Ó", "O")
strtexto = Replace(strtexto, "Ú", "U")
strtexto = Replace(strtexto, "Ñ", "N")
strtexto = Replace(strtexto, "ñ", "n")
linea1 = strtexto

Dim strchrs As String
Dim l1 As String
Dim l2 As String

    Precio = Format(Precio, "###0.00")
    total = Format(total, "###0.00")
    
    'MsgBox (linea1 & vbCrLf & total & vbCrLf & Precio)
     
    'l1 = linea1 & Space(13 - Len(linea1)) & Space(7 - Len(Precio)) & Precio
    'l2 = "TOTAL:      " & Space(8 - Len(total)) & total
        
        

   ' Panel.MSComm1.Output = Chr(27) & "QA" & l1 & vbCr
   ' Panel.MSComm1.Output = Chr(27) & "QB" & l2 & vbCr
    
End Sub

Public Function formatFL2024(ByVal strtexto As String) As String

strtexto = Replace(strtexto, "á", Chr$(160))
strtexto = Replace(strtexto, "é", Chr$(130))
strtexto = Replace(strtexto, "í", Chr$(161))
strtexto = Replace(strtexto, "ó", Chr$(162))
strtexto = Replace(strtexto, "ú", Chr$(163))
strtexto = Replace(strtexto, "Ñ", Chr$(156))
strtexto = Replace(strtexto, "ñ", Chr$(155))

formatFL2024 = strtexto

End Function
Public Sub recordarticket(t As Long)
If t < ticket Then
    frmEstadisticas.LTotal.Caption = 0
    frmEstadisticas.lTotalMesas.Caption = 0
    frmEstadisticas.lTotalBarra.Caption = 0
    frmEstadisticas.lTotalBebidaM.Caption = 0
    frmEstadisticas.lTotalComidaM.Caption = 0
    
    frmEstadisticas.MSFlexGrid1.Visible = False
    frmEstadisticas.MSFlexGrid2.Visible = True
    frmEstadisticas.MSFlexGrid2.Rows = 0
    frmEstadisticas.MSFlexGrid2.ColWidth(0) = 320
    frmEstadisticas.MSFlexGrid2.ColWidth(1) = 0
    frmEstadisticas.MSFlexGrid2.ColWidth(2) = 2000
    frmEstadisticas.MSFlexGrid2.ColWidth(3) = 800


    frmEstadisticas.MSFlexGrid2.ColAlignment(2) = 1

    
    frmEstadisticas.lista.Caption = "Ticket " & t

    
    
    Dim tmpdata As String
     tmpdata = "SELECT * FROM ticketprecio WHERE idticket = " & t

    frmEstadisticas.Data1.RecordSource = tmpdata
    frmEstadisticas.Data1.Refresh
    If frmEstadisticas.Data1.Recordset.RecordCount <> 0 Then
    
    frmEstadisticas.Data1.Recordset.MoveFirst
    While Not (frmEstadisticas.Data1.Recordset.EOF)
    
    
    'Agregar a la lista
        Dim Y As Long
        Dim encontrado As Boolean
        encontrado = False
        
        With frmEstadisticas.MSFlexGrid2
            For Y = .FixedRows To .Rows - 1
                If .TextMatrix(Y, 1) = frmEstadisticas.Data1.Recordset.Fields(2) Then
                    .TextMatrix(Y, 0) = .TextMatrix(Y, 0) + 1
                    .TextMatrix(Y, 3) = CDbl(.TextMatrix(Y, 3)) + CDbl(frmEstadisticas.Data1.Recordset.Fields(5))
                    
                    encontrado = True
                End If
            
            
            Next Y
        End With
        
        If encontrado = False Then
    
            
            frmEstadisticas.MSFlexGrid2.AddItem ("1" & vbTab & frmEstadisticas.Data1.Recordset.Fields(2) & vbTab & frmEstadisticas.Data1.Recordset.Fields(4) & vbTab & frmEstadisticas.Data1.Recordset.Fields(5))
            
        End If
    
       '  frmEstadisticas.LTotal.Caption = frmEstadisticas.LTotal.Caption + frmEstadisticas.Data1.Recordset.Fields(1)
        
                If frmEstadisticas.Data1.Recordset.Fields(7) < 60 Then 'si es una mesa..
                
         '   MsgBox (frmEstadisticas.Data1.Recordset.Fields(2))
         'si es bebida, sumar en bebida
         If frmEstadisticas.Data1.Recordset.Fields(2) > 630 And frmEstadisticas.Data1.Recordset.Fields(2) < 694 Then
 
             frmEstadisticas.lTotalBebidaM.Caption = frmEstadisticas.lTotalBebidaM.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
         Else ' si No es bebida
            frmEstadisticas.lTotalComidaM.Caption = frmEstadisticas.lTotalComidaM.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
         End If
             
            frmEstadisticas.lTotalMesas.Caption = frmEstadisticas.lTotalMesas.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
            
            frmEstadisticas.lista.Caption = "Ticket " & t & " Mesas"

          
          
          
        Else ' si no es una mesa
          frmEstadisticas.lTotalBarra.Caption = frmEstadisticas.lTotalBarra.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
          frmEstadisticas.lista.Caption = "Ticket " & t & " Barra"
        End If
        frmEstadisticas.LTotal.Caption = frmEstadisticas.LTotal.Caption + frmEstadisticas.Data1.Recordset.Fields(5)
        
        
        
        
        
        
        
        
        
        frmEstadisticas.Data1.Recordset.MoveNext
        
        
        
        
        
        
        
        
    Wend
    
            ' Poner en formato 0,00
        frmEstadisticas.lTotalBebidaM.Caption = Format(frmEstadisticas.lTotalBebidaM.Caption, "###0.00")
        frmEstadisticas.lTotalComidaM.Caption = Format(frmEstadisticas.lTotalComidaM.Caption, "###0.00")
        frmEstadisticas.lTotalBarra.Caption = Format(frmEstadisticas.lTotalBarra.Caption, "###0.00")
        frmEstadisticas.lTotalMesas.Caption = Format(frmEstadisticas.lTotalMesas.Caption, "###0.00")
        frmEstadisticas.LTotal.Caption = Format(frmEstadisticas.LTotal.Caption, "###0.00")
        
        
        Dim X As Long
        With frmEstadisticas.MSFlexGrid2
            For X = .FixedRows To .Rows - 1
                .TextMatrix(X, 3) = Format(.TextMatrix(X, 3), "###0.00")
            Next X
        End With
    End If
End If
End Sub

Public Sub cambiamesa(Index As Integer)

Dim I As Integer
Dim producto As Integer

For I = 0 To 999
    mesa(MesaActual, I, 0) = 0 ' CERO numero producto, UNO, precio
Next I

For I = 0 To Panel.MSFlexGrid1.Rows - 1
    If Panel.MSFlexGrid1.TextMatrix(I, 2) <> 0 Then
        mesa(MesaActual, I, 0) = Panel.MSFlexGrid1.TextMatrix(I, 2) 'nombre
        mesa(MesaActual, I, 1) = Panel.MSFlexGrid1.TextMatrix(I, 5) 'precio
        mesa(MesaActual, I, 3) = Panel.MSFlexGrid1.TextMatrix(I, 0) 'cantidad de productos
    End If

Next I

actualizalista 'poner lista a 0.


MesaActual = Index + 1


If Index = 60 Then
Panel.Mesa2.Caption = "B"
Else
Panel.Mesa2.Caption = MesaActual
End If

'MsgBox (MesaActual)
producto = 1
I = 0
While (producto <> 0) And (I < 999)

    producto = mesa(MesaActual, I, 0)
    If producto <> 0 Then
        If producto <> 999 Then
            Dim j As Long
            For j = 1 To mesa(MesaActual, I, 3)
                 agregaProducto (producto - 1)
            Next j
            
        Else
            Panel.MSFlexGrid1.AddItem ("1" & vbTab & funciones.ticket & vbTab & _
                                    "999" & vbTab & "PRECIO LIBRE" & vbTab & CDbl(mesa(MesaActual, I, 1)) & vbTab & _
                                    CDbl(mesa(MesaActual, I, 1)) & vbTab & Date)
            
            Panel.LTotal = CDbl(Panel.LTotal) + CDbl(mesa(MesaActual, I, 1)) 'sumar precio
            
                   Dim X As Long 'actualizar formato precio
        With Panel.MSFlexGrid1
            For X = .FixedRows To .Rows - 1
                .TextMatrix(X, 5) = Format(.TextMatrix(X, 5), "###0.00")
            Next X
        End With
     
        Panel.MSFlexGrid1.Row = Panel.MSFlexGrid1.Rows - 1 'actualizar lista
        Panel.MSFlexGrid1.TopRow = Panel.MSFlexGrid1.Rows - 1
        
        
        End If
    End If
    I = I + 1
'MsgBox (i)
Wend


End Sub

Public Sub listamesas()
Dim I As Integer
Dim K As Integer
K = 0
    For I = 0 To 29
        If mesa(I + 1, 0, 0) <> 0 Then
            Panel.lblMesa(K).Visible = True
            Panel.lblMesa(K).Caption = I + 1
            K = K + 1
        End If
    Next I
End Sub


Public Sub ImprimirTicket()

 Dim cabecera As String
        Dim pie As String
        Dim I As Integer
        Dim texto As String
        Dim dinero As String
        Dim imprimir As String
        Dim strtexto As String
        Dim cantidad As String
        Dim unidad As String
        
        

        
           cabecera = _
        "CALLE MARBELLA 16" & vbCrLf & _
        "29640 FUENGIROLA MALAGA" & vbCrLf & _
        "CIF: B-02784379  TLF: 951330598"
        
        'Format(LTotal, "###0.00") Panel.Mesa2.Caption
        
        pie = "TICKET:       " & ticket & "             Mesa: " & Format(Panel.Mesa2.Caption, "00") & vbCrLf & _
        Date & "                 " & Time & vbCrLf & _
        "     PAGO AL CONTADO.IVA INCLUIDO " & vbCrLf & _
        "         GRACIAS POR SU VISITA"
            
        Open "COM3" For Output As #1
       
       ' Open Printer.Port For Output As #1
        
        Print #1, Chr(27) + Chr(112) + Chr(0) + Chr(40) + Chr(40) 'Abrir cajon
       ' Width #1, 20
 '     Print #1, Chr(27) & "W" & Chr(1); "Hola, mundo" & Chr(27) & "W" & Chr(0)  'Imprime en ancho doble
 '       Print #1, Chr(15) & "Nro. de boleta" & Chr(17) 'Imprime condensado
  '      Print #1, Chr(15) & "Nro. de boleta" & Chr(17) 'Imprime condensado
  
        Print #1, Chr(27) & Chr$(33) & Chr$(32) 'Imprime negrita
        Print #1, "PIZZERIA IL MAESTRO"
        Print #1, Chr(27) & Chr$(33) & Chr$(0) 'Imprime normal
        
        
        Print #1, cabecera
        'Print #1, "------------------------"
        Print #1, "Cnt Producto             Unidad  Total" '38 (antes 24)
        Print #1, "======================================" '38 (antes 24)
        
        For I = 0 To Panel.MSFlexGrid1.Rows - 1
            texto = Panel.MSFlexGrid1.TextMatrix(I, 3)
            
    
        strtexto = texto
        strtexto = Replace(strtexto, "á", "a")
        strtexto = Replace(strtexto, "é", "e")
        strtexto = Replace(strtexto, "í", "i")
        strtexto = Replace(strtexto, "ó", "o")
        strtexto = Replace(strtexto, "ú", "u")
        strtexto = Replace(strtexto, "Á", "A")
        strtexto = Replace(strtexto, "É", "E")
        strtexto = Replace(strtexto, "Í", "I")
        strtexto = Replace(strtexto, "Ó", "O")
        strtexto = Replace(strtexto, "Ú", "U")
        strtexto = Replace(strtexto, "Ñ", "N")
        strtexto = Replace(strtexto, "ñ", "n")
        texto = strtexto
            
            
            cantidad = Panel.MSFlexGrid1.TextMatrix(I, 0)
            dinero = Panel.MSFlexGrid1.TextMatrix(I, 5)
            unidad = Panel.MSFlexGrid1.TextMatrix(I, 4)

            imprimir = Space(3 - Len(cantidad)) & cantidad & " "
            
            
            imprimir = imprimir & texto & Space(20 - Len(texto))
            imprimir = imprimir & Space(7 - Len(unidad)) & unidad
            imprimir = imprimir & Space(7 - Len(dinero)) & dinero
            
            Print #1, imprimir
            imprimir = ""
        Next I
        
   
        Print #1, "======================================"
 
        Print #1, "TOTAL:            " & Space(20 - Len(frmTotal.LTotal.Caption)) & frmTotal.LTotal.Caption 'reducido espacio 9
        Print #1, "ENTREGADO:        " & Space(20 - Len(frmTotal.LRecibido.Caption)) & frmTotal.LRecibido.Caption
        Print #1, "CAMBIO:           " & Space(20 - Len(frmTotal.LCambio.Caption)) & frmTotal.LCambio.Caption
        Print #1, "______________________________________"

        Print #1, pie
        
        Print #1, Chr(27) & "d" & Chr$(3) '11 lineas
 

        
       ' Print #1, "."
       ' Print #1, "============================"
        Print #1, Chr(27) + Chr(105)
        Close #1
End Sub

Public Sub ImprimirTicketMesa()

 Dim cabecera As String
        Dim pie As String
        Dim I As Integer
        Dim texto As String
        Dim dinero As String
        Dim imprimir As String
        Dim strtexto As String
                Dim cantidad As String
        Dim unidad As String
        

        
           cabecera = _
        "CALLE MARBELLA 16" & vbCrLf & _
        "29640 FUENGIROLA MALAGA" & vbCrLf & _
        "CIF: B-02784379  TLF: 951330598"
        
        'Format(LTotal, "###0.00") Panel.Mesa2.Caption
        
        pie = "TICKET:       " & ticket & "             Mesa: " & Format(Panel.Mesa2.Caption, "00") & vbCrLf & _
        Date & "                 " & Time & vbCrLf & _
        "     PAGO AL CONTADO.IVA INCLUIDO " & vbCrLf & _
        "         GRACIAS POR SU VISITA"
            
        Open "COM3" For Output As #1
       
       ' Open Printer.Port For Output As #1
        
        Print #1, Chr(27) + Chr(112) + Chr(0) + Chr(40) + Chr(40) 'Abrir cajon
       ' Width #1, 20
 '     Print #1, Chr(27) & "W" & Chr(1); "Hola, mundo" & Chr(27) & "W" & Chr(0)  'Imprime en ancho doble
 '       Print #1, Chr(15) & "Nro. de boleta" & Chr(17) 'Imprime condensado
  '      Print #1, Chr(15) & "Nro. de boleta" & Chr(17) 'Imprime condensado
  
        Print #1, Chr(27) & Chr$(33) & Chr$(32) 'Imprime negrita
        Print #1, "PIZZERIA IL MAESTRO"
        Print #1, Chr(27) & Chr$(33) & Chr$(0) 'Imprime normal
        
        
        Print #1, cabecera
        'Print #1, "------------------------"
        Print #1, "Cnt Producto             Unidad  Total" '38 (antes 24)
        Print #1, "======================================" '38 (antes 24)
        
        For I = 0 To Panel.MSFlexGrid1.Rows - 1
            texto = Panel.MSFlexGrid1.TextMatrix(I, 3)
            
    
        strtexto = texto
        strtexto = Replace(strtexto, "á", "a")
        strtexto = Replace(strtexto, "é", "e")
        strtexto = Replace(strtexto, "í", "i")
        strtexto = Replace(strtexto, "ó", "o")
        strtexto = Replace(strtexto, "ú", "u")
        strtexto = Replace(strtexto, "Á", "A")
        strtexto = Replace(strtexto, "É", "E")
        strtexto = Replace(strtexto, "Í", "I")
        strtexto = Replace(strtexto, "Ó", "O")
        strtexto = Replace(strtexto, "Ú", "U")
        strtexto = Replace(strtexto, "Ñ", "N")
        strtexto = Replace(strtexto, "ñ", "n")
        texto = strtexto
            
            
            cantidad = Panel.MSFlexGrid1.TextMatrix(I, 0)
            dinero = Panel.MSFlexGrid1.TextMatrix(I, 5)
            unidad = Panel.MSFlexGrid1.TextMatrix(I, 4)

            imprimir = Space(3 - Len(cantidad)) & cantidad & " "
            
            
            imprimir = imprimir & texto & Space(20 - Len(texto))
            imprimir = imprimir & Space(7 - Len(unidad)) & unidad
            imprimir = imprimir & Space(7 - Len(dinero)) & dinero
            
            Print #1, imprimir
            imprimir = ""
        Next I
        
   
        Print #1, "======================================"
    
        Print #1, "TOTAL:            " & Space(20 - Len(frmTotal.LTotal.Caption)) & frmTotal.LTotal.Caption 'reducido espacio 9
 '       Print #1, "ENTREGADO:        " & Space(20 - Len(frmTotal.LRecibido.Caption)) & frmTotal.LRecibido.Caption
  '      Print #1, "CAMBIO:           " & Space(20 - Len(frmTotal.LCambio.Caption)) & frmTotal.LCambio.Caption
        Print #1, "______________________________________"

        Print #1, pie
        
        Print #1, Chr(27) & "d" & Chr$(3) '11 lineas
 

        
       ' Print #1, "."
       ' Print #1, "============================"
        Print #1, Chr(27) + Chr(105)
        Close #1
End Sub

