Dim printFont As System.Drawing.Font = New Font("Arial", 10)
Dim topMargin As Double = e.MarginBounds.Top
Dim yPos As Double = 0
Dim linesPerPage As Double = 0
Dim count As Integer = 0
Dim texto As String = ""
Dim LNormal As New Font("Arial", 9)
Dim LChiquita As New Font("Arial", 8)
Dim LGrande As New Font("Arial", 11)
Dim XCliente, XNit, XFecha, XIdv, XTipo, XCajera As String
Dim NXVta As String
NXVta = FTpv.Label19.Text
'IMPRIMIMOS NOTA DE VENTA
If Op7 = True Then
' Calculamos el número de líneas que caben en cada página
linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)
Dim formato As New StringFormat()
formato.Alignment = StringAlignment.Far
formato.LineAlignment = StringAlignment.Near
'CALCULAMOS NUMERO DE FILA
yPos = 30
' Imprimimos las cabeceras
e.Graphics.DrawString("LUJAN SUPERMERCADO", LGrande, Brushes.Black, 40, yPos)
yPos += 20
e.Graphics.DrawString("CASA MATRIZ", LNormal, Brushes.Black, 80, yPos)
yPos += 15
e.Graphics.DrawString("Calle Avaroa Nº 125 entre Arenales y ", LChiquita, Brushes.Black, 30, yPos)
yPos += 15
e.Graphics.DrawString("y 24 de Septiembre Zona B/25 de Diciembre", LChiquita, Brushes.Black, 20, yPos)
yPos += 15
e.Graphics.DrawString("Tel. 922-0956 Telf. Fax 922-3496", LChiquita, Brushes.Black, 30, yPos)
yPos += 15
e.Graphics.DrawString("Montero - Santa Cruz - Bolivia", LChiquita, Brushes.Black, 40, yPos)
yPos += 20
e.Graphics.DrawString("NOTA DE VENTA ", LGrande, Brushes.Black, 60, yPos)
yPos += 20
e.Graphics.DrawString("..............................................................................", LChiquita, Brushes.Black, 0, yPos)
'DATOS DEL CLIENTE
T = New DataTable
Com.CommandText = "select v.id, v.idv, v.idcli, v.senor, d.idpro, d.detalle, d.cant, u.corto as und, d.precio, d.monto, v.ccon, v.nauto, v.totalc, v.fecha, v.hora, v.tipov, v.cajera, v.bs, v.cambio, v.nt from t_venta_d d, t_venta v, t_unidad u where v.idv = d.idv and d.und = u.nombre and v.idv = " & "'" & NXVta & "'" & " order by d.idvd "
D.SelectCommand = Com
D.Fill(T)
XCliente = "NOMBRE: " & T.Rows(0).Item("SENOR").ToString
XIdv = "Nº VENTA: " & T.Rows(0).Item("IDV").ToString
XNit = "NIT/ CI: " & T.Rows(0).Item("IDCLI").ToString
XFecha = "FECHA: " & Format(T.Rows(0).Item("FECHA"), "dd/MM/yyyy") + " " + vbTab + Format(CDate(T.Rows(0).Item("HORA").ToString), "hh:mm")
XTipo = T.Rows(0).Item("TIPOV").ToString
XCajera = T.Rows(0).Item("CAJERA").ToString
'ÀGORA IMPRIMIMOS LOS DATOS
yPos += 15
e.Graphics.DrawString(XIdv, LNormal, Brushes.Black, 0, yPos)
yPos += 15
e.Graphics.DrawString(XFecha, LNormal, Brushes.Black, 0, yPos)
yPos += 15
Dim x1, x2 As Integer
XCliente = XCliente & " "
If Len(XCliente) > 30 Then
For x1 = 0 To Len(XCliente) - 1
If XCliente(x1) = " " Then
If x1 > 30 Then
e.Graphics.DrawString(Mid(XCliente, 1, x2 - 1), LNormal, Brushes.Black, 0, yPos)
yPos += 15
e.Graphics.DrawString(Mid(XCliente, x2, Len(XCliente)), LNormal, Brushes.Black, 60, yPos)
yPos += 15
Exit For
Else
'nuevo comienzo
x2 = x1 + 1
End If
End If
Next
Else
e.Graphics.DrawString(XCliente, LNormal, Brushes.Black, 0, yPos)
yPos += 15
End If
e.Graphics.DrawString(XNit, LNormal, Brushes.Black, 0, yPos)
yPos += 15
e.Graphics.DrawString("..............................................................................", LChiquita, Brushes.Black, 0, yPos)
'AGORA DETALLE
yPos += 10
texto = "CANTIDAD " + " PRECIO " + " IMPORTE"
e.Graphics.DrawString(texto, LNormal, Brushes.Black, 0, yPos)
yPos += 10
e.Graphics.DrawString("..............................................................................", LChiquita, Brushes.Black, 0, yPos)
'IMPRIMIR DETALLE
yPos += 15
For X As Integer = 0 To T.Rows.Count - 1
e.Graphics.DrawString(Mid(T.Rows(X).Item("DETALLE").ToString, 1, 30), LNormal, Brushes.Black, 0, yPos)
yPos += 15
e.Graphics.DrawString(Math.Round(T.Rows(X).Item("CANT"), 2), LNormal, Brushes.Black, 10, yPos)
e.Graphics.DrawString(T.Rows(X).Item("UND").ToString, LNormal, Brushes.Black, 60, yPos)
e.Graphics.DrawString(Math.Round(T.Rows(X).Item("PRECIO"), 2), LNormal, Brushes.Black, 160, yPos, formato)
e.Graphics.DrawString(Math.Round(T.Rows(X).Item("MONTO"), 2), LNormal, Brushes.Black, 240, yPos, formato)
yPos += 15
Next
e.Graphics.DrawString("..............................................................................", LChiquita, Brushes.Black, 0, yPos)
yPos += 15
e.Graphics.DrawString("TOTAL A PAGAR: ", LNormal, Brushes.Black, 0, yPos)
e.Graphics.DrawString(Math.Round(T.Rows(0).Item("TOTALC"), 2), LNormal, Brushes.Black, 240, yPos, formato)
yPos += 15
e.Graphics.DrawString("TOTAL RECIBIDO: ", LNormal, Brushes.Black, 0, yPos)
e.Graphics.DrawString(Math.Round(T.Rows(0).Item("BS"), 2), LNormal, Brushes.Black, 240, yPos, formato)
yPos += 15
e.Graphics.DrawString("TOTAL CAMBIO: ", LNormal, Brushes.Black, 0, yPos)
e.Graphics.DrawString(Math.Round(T.Rows(0).Item("CAMBIO"), 2), LNormal, Brushes.Black, 240, yPos, formato)
yPos += 30
Dim largo = Len(CStr(Format(CDec(T.Rows(0).Item("TOTALC")), "#,###.00")))
Dim decimales = Mid(CStr(Format(CDec(T.Rows(0).Item("TOTALC")), "#,###.00")), largo - 2)
Dim Letras = UCase(ALetras(Math.Round(T.Rows(0).Item("TOTALC"), 2), " Bs."))
'IMPRESION DE LETRAS NUMERICAS
Letras = "SON: " & Letras & " "
If Len(Letras) > 29 Then
For x1 = 0 To Len(Letras) - 1
If Letras(x1) = " " Then
If x1 > 29 Then
e.Graphics.DrawString(Mid(Letras, 1, x2 - 1), LNormal, Brushes.Black, 0, yPos)
yPos += 15
e.Graphics.DrawString(Mid(Letras, x2, Len(Letras)).Trim, LNormal, Brushes.Black, 0, yPos)
yPos += 15
Exit For
Else
'nuevo comienzo
x2 = x1 + 1
End If
End If
Next
Else
e.Graphics.DrawString(Letras, LNormal, Brushes.Black, 0, yPos)
yPos += 15
End If
yPos += 10
'verificar EL TAMAÑO DE LETRAS PARA DIVIDUIRLO Y SABER CUANTAS LINEAS PUEDEN SER Y PONERLO EN UN CICLO
e.Graphics.DrawString("VENDEDOR: ", LNormal, Brushes.Black, 0, yPos)
e.Graphics.DrawString(T.Rows(0).Item("CAJERA").ToString, LNormal, Brushes.Black, 75, yPos)
e.Graphics.DrawString(T.Rows(0).Item("TIPOV").ToString, LNormal, Brushes.Black, 150, yPos)
yPos += 40
e.Graphics.DrawString("GRACIAS POR SU PREFERENCIA!!! ", LNormal, Brushes.Black, 10, yPos)
yPos += 20
e.HasMorePages = False
End If