Created
July 23, 2018 22:55
-
-
Save mautematico/a8f80e21b7b31114d49109892b08b502 to your computer and use it in GitHub Desktop.
Tickets MyBusiness POS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Main() | |
Dim rstSeries | |
'Ambiente.Torreta.PortOpen = False | |
'Ambiente.Torreta.Settings = "9600,N,8,1" | |
'Ambiente.Torreta.RTSEnable = True | |
'Ambiente.Torreta.PortOpen = True | |
'Ambiente.Torreta.CommPort = 1 | |
'Ambiente.Torreta.OutPut = "ABC" | |
'Eventos | |
'Ambiente.Torreta.PortOpen = False | |
'cLineaNueva = Chr(13) | |
cLineaNueva = Chr(13) & Chr(10) | |
'If MsgBox( "Desea imprimir el ticket", vbQuestion + vbYesNo + vbDefaultButton2 ) = vbNo Then | |
' Exit Sub | |
'End If | |
' Creamos el recordSet del encabezado de la venta | |
Set rstEncabezado = Rst("SELECT * FROM ventas WHERE venta = " & prn.Documento, Ambiente.Connection ) | |
' Verificamos que la venta que se desea imprimir exista | |
if rstEncabezado.EOF Then | |
MsgBox "No existe la venta seleccionada",vbInformation | |
Exit Sub | |
end if | |
' Creamos el recordSet de las partidas que componen la venta | |
Set rstPartidas = Rst("SELECT partvta.prcantidad, partvta.iespecial, partvta.id_salida, partvta.kit, partvta.articulo, prods.precio1,prods.descrip, partvta.precio, partvta.cantidad, partvta.descuento, partvta.impuesto, partvta.preciobase, partvta.prdescrip, prods.serie FROM partvta INNER JOIN prods ON prods.articulo = partvta.articulo WHERE venta =" & rstEncabezado.fields("Venta"), Ambiente.Connection ) | |
' Traemos todos los datos del cliente | |
Set rstCliente = Rst("SELECT * FROM clients WHERE cliente = '" & rstEncabezado.fields("Cliente") & "'", Ambiente.Connection ) | |
' Traemos los datos de cobranza si es que existe | |
Set rstCobranza = Rst( "SELECT * FROM cobranza WHERE venta = " & rstEncabezado("venta"), Ambiente.Connection ) | |
cSalida = "" | |
'Esto abre el cajon de dinero | |
if Ambiente.rstEstacion("Cajon") <> 0 Then | |
cSalida = cSalida & Chr(27) & Chr(112) & Chr(48) & Chr(20) & Chr(20) | |
cSalida = cSalida & Chr(7) | |
' Sansung de inyeccin | |
' cSalida = cSalida & Chr(27) & Chr(112) & Chr(48) & Chr(49) | |
end if | |
Set rstTextTicket = CreaRecordSet( "SELECT * FROM tickettext", Ambiente.Connection ) | |
If rstTextTicket.EOF Then | |
cSalida = cSalida & "" & Ambiente.Empresa & cLineaNueva | |
cSalida = cSalida & "" & Trim( Ambiente.Direccion1 ) & cLineaNueva | |
cSalida = cSalida & "" & Trim( Ambiente.Direccion2 ) & cLineaNueva | |
cSalida = cSalida & "" & Trim( Ambiente.Telefonos ) & cLineaNueva | |
Else | |
'cSalida = cSalida & Replace(rstTextTicket("textheader"), Chr(10), "" ) | |
cSalida = cSalida & rstTextTicket("textheader") | |
End If | |
'cSalida = cSalida & "" & Trim( rstEncabezado("Usuario") ) & " " & Trim( Ambiente.Estacion ) & " Ticket: " & rstEncabezado("No_referen") & cLineaNueva | |
cSalida = cSalida & Trim( rstEncabezado("caja") ) & " " & Trim( rstEncabezado("Usuario") ) & " Ticket: " & rstEncabezado("No_referen") & cLineaNueva | |
cSalida = cSalida & Formato( rstEncabezado("f_emision"),"dd-MM-yyyy" ) & " Hora: " & rstEncabezado("usuHora") & cLineaNueva | |
cDatos = "" & rstEncabezado("datos") | |
If clAt( ":", Trim(cDatos) ) = 1 Then | |
cSalida = cDatos & cLineaNueva | |
Else | |
cSalida = cSalida & Trim( rstCliente("cliente") ) & " " & Trim( rstCliente("Nombre") ) & cLineaNueva | |
cSalida = cSalida & Trim( rstCliente("calle") ) & " " & Trim( rstCliente("colonia") ) & Chr(13) & Chr(10) | |
End If | |
cSalida = cSalida & Ambiente.rstEstacion("leyendacomodin") & " " & rstEncabezado("comodin") & cLineaNueva | |
'cSalida = cSalida & "Vendedor: " & rstEncabezado("Vend") & cLineaNueva | |
'msgbox Ambiente.Var9 | |
'cSalida = cSalida & Ambiente.Var9 & vbCrLf | |
'Ambiente.Var9 = "" | |
cSalida = cSalida & "CANT. DESCRIPCION CODIGO SUBTOTAL" & cLineaNueva | |
nImporteTotal = 0 | |
nImpuesto = 0 | |
nCantidadTotal = 0 | |
nDescuentoTotal = 0 | |
nImporteOrigen = 0 | |
'PrintText cSalida | |
While Not rstPartidas.EOF | |
nPrecio = rstPartidas("Precio") * ( 1 - (rstPartidas("Descuento")/100) ) * (1 + ( rstPartidas("impuesto") / 100 ) ) | |
nPrecioBase = Round( rstPartidas("PrecioBase") * (1 + ( rstPartidas("impuesto") / 100 ) ), 2) | |
nDescuento = (nPrecioBase - nPrecio) * rstPartidas("Cantidad") | |
If nPrecioBase > 0 Then | |
nDescPor = ( nPrecio / nPrecioBase ) * 100 | |
Else | |
nDescPor = 0 | |
End If | |
nDescuentoTotal = nDescuentoTotal + nDescuento | |
nImporte = nPrecio * rstPartidas("Cantidad") | |
nCantidad = PadL(Formato( rstPartidas("cantidad") / rstPartidas("prCantidad"), "##,##0" ),3) | |
cDescrip = PadR( Mid( rstPartidas("Descrip"), 1, 30 ), 30 ) | |
nCantidadTotal = nCantidadTotal + ( rstPartidas("cantidad") / rstPartidas("prcantidad") ) | |
nImporteTotal = nImporteTotal + nImporte | |
nImpuesto = nImpuesto + ( nImporteTotal * ( rstPartidas("impuesto") / 100 ) ) | |
nPrecio = 0 | |
nIEspecial = rstPartidas("Precio") * (Val2(rstPartidas("iespecial")) / 100) | |
nIVa = rstPartidas("Precio") * (rstPartidas("impuesto") / 100) | |
nPrecio = rstPartidas("Precio") + nIEspecial + nIVa | |
cPrecio = PadL(Trim(Formato( nPrecio, Ambiente.FDinero )),8) | |
cImporte = PadL(Trim(Formato( Round( nPrecio, 2) * rstPartidas("cantidad") * (1 - (rstPartidas("descuento") / 100)), Ambiente.FDinero )),8) | |
nPrecioOrigen = Round( rstPartidas("PrecioBase") * (1 + ( rstPartidas("impuesto") / 100 )),2) * rstPartidas("cantidad") | |
nImporteOrigen = nImporteOrigen + nPrecioOrigen | |
strSalida = PadL(Formato( nCantidad, "##,##0" ),2) & " " & Trim( rstPartidas("prdescrip") ) & " " & cDescrip & vbCrLf & " P/Pza. " & cPrecio & " " & rstPartidas("articulo") & " " & cImporte | |
'If rstPartidas("Precio1") > rstPartidas("Precio") Then | |
' nDescuentoPartida = ( rstPartidas("Precio1") - rstPartidas("Precio") ) * nCantidad | |
' strSalida = strSalida & " Descuento: " & Formato( nDescuentoPartida, "##,##0.00" ) & vbCrLf | |
'End If | |
cSalida = cSalida & strSalida & cLineaNueva | |
'If Not clEmpty( cNull( rstPartidas("prdescrip") ) ) Then | |
' cSalida = cSalida & Trim( rstPartidas("prdescrip") ) & vbCrLf | |
'End If | |
If rstPartidas("Kit") <> 0 Then | |
Set rstOpciones = CreaRecordSet( "SELECT partvtaopciones.articulo, prods.descrip FROM partvtaopciones INNER JOIN prods ON partvtaopciones.articulo = prods.articulo WHERE id_salida = " & rstPartidas("id_salida"), Ambiente.Connection ) | |
While Not rstOpciones.EOF | |
cSalida = cSalida & "Opcion:" & rstOpciones("descrip") & Chr(13) & Chr(10) | |
rstOpciones.MoveNext | |
Wend | |
End If | |
If rstPartidas("serie") <> 0 Then | |
If rstEncabezado("ticket") <> 0 Then | |
Set rstSeries = CreaRecordSet( _ | |
"SELECT * FROM series WHERE documento = 'TICKET' AND numeroDocumento = " & rstEncabezado( "no_referen" ) & " AND articulo = '" & rstPartidas("articulo") & "'", _ | |
Ambiente.Connection ) | |
Else | |
Set rstSeries = CreaRecordSet( _ | |
"SELECT * FROM series WHERE documento = 'REMISION' AND numeroDocumento = " & rstEncabezado( "no_referen" ) & " AND articulo = '" & rstPartidas("articulo") & "'", _ | |
Ambiente.Connection ) | |
End If | |
While Not rstSeries.EOF | |
Serie = Trim( rstSeries("serie") ) | |
Serie = PadL( Serie, 11 ) | |
Serie = Mid( Serie, Len( Serie ) - 10 ) | |
cSalida = cSalida & "SERIE: " & Serie & vbCrLf | |
rstSeries.MoveNext | |
Wend | |
End If | |
rstPartidas.MoveNext | |
Wend | |
'PrintText cSalida | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
'cSalida = cSalida & " Importe: " & PadL(Formato( Val2(rstEncabezado("importe")), Ambiente.FDinero ),10) & cLineaNueva | |
'cSalida = cSalida & " Impuesto: " & PadL(Formato( Val2(rstEncabezado("impuesto")), Ambiente.FDinero ),10) & cLineaNueva | |
'if Val2(rstEncabezado("iespecial")) > 0 Then | |
' cSalida = cSalida & " Impuesto 2%: " & PadL(Formato( Val2(rstEncabezado("iespecial")), Ambiente.FDinero ),10) & cLineaNueva | |
'end if | |
if nDescuentoTotal > 0 Then | |
'cSalida = cSalida & " Importe: " & PadL(Formato( nImporteOrigen, Ambiente.FDinero ),10) & cLineaNueva | |
'cSalida = cSalida & " Descuento: " & PadL(Formato( nDescuentoTotal, Ambiente.FDinero ),10) & cLineaNueva | |
end if | |
'cSalida = cSalida & " Importe: " & PadL(Formato( Val2(rstEncabezado("impuesto")) + Val2(rstEncabezado("importe")) + Val2(rstEncabezado("iespecial")), Ambiente.FDinero ),10) & cLineaNueva | |
'cSalida = cSalida & " Redondeo: " & PadL(Formato( Val2(rstEncabezado("Redondeo")), Ambiente.FDinero ),10) & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & PadL(Formato( nCantidadTotal, "###,###" ),4) & " ----- TOTALES ---- " & PadL(Formato( (Val2(rstEncabezado("impuesto")) + Val2(rstEncabezado("importe")) + Val2(rstEncabezado("iespecial")) + Val2(rstEncabezado("redondeo"))), "$" & Ambiente.FDinero ),10) & cLineaNueva | |
nPagoTotal = Val2(rstEncabezado("Pago1")) + Val2(rstEncabezado("Pago2")) + Val2(rstEncabezado("Pago3")) | |
if rstEncabezado("Pago1") > 0 Then | |
cSalida = cSalida & " Pago en " & rstEncabezado("Concepto1") & " " & PadL(Formato( Val2(rstEncabezado("Pago1")), "$" & Ambiente.FDinero ),9) & cLineaNueva | |
end if | |
if rstEncabezado("Pago2") > 0 Then | |
cSalida = cSalida & " Pago en " & rstEncabezado("Concepto2") & " " & PadL(Formato( Val2(rstEncabezado("Pago2")), "$" & Ambiente.FDinero ),9) & cLineaNueva | |
end if | |
if rstEncabezado("Pago3") > 0 Then | |
cSalida = cSalida & " Pago en " & rstEncabezado("Concepto3") & " " & PadL(Formato( Val2(rstEncabezado("Pago3")), "$" & Ambiente.FDinero ),9) & cLineaNueva | |
end if | |
Eventos | |
If rstEncabezado("Comision") > 0 Then | |
cSalida = cSalida & " Comisin: " & PadL(Formato( Val2(rstEncabezado("comision")), "$" & Ambiente.FDinero ),10) & cLineaNueva | |
End If | |
nComision = rstEncabezado("comision") | |
if nPagoTotal < (Val2(rstEncabezado("impuesto")) + Val2(rstEncabezado("importe")) + Val2(rstEncabezado("iespecial")) + Val2(rstEncabezado("redondeo"))) Then | |
cSalida = cSalida & " Credito: " & PadL(Formato( Val2(rstEncabezado("impuesto")) + Val2(rstEncabezado("iespecial")) + Val2(rstEncabezado("importe")) + Val2(rstEncabezado("redondeo")) - nPagoTotal, "$" & Ambiente.FDinero ),9) & cLineaNueva | |
else | |
cSalida = cSalida & " Cambio: " & PadL(Formato( nPagoTotal - nComision - Val2(rstEncabezado("impuesto")) - Val2(rstEncabezado("iespecial")) - Val2(rstEncabezado("importe")) - Val2(rstEncabezado("redondeo")), "$" & Ambiente.FDinero ),9) & cLineaNueva | |
end if | |
Set rstMoneda = CreaRecordSet( "SELECT * FROM monedas WHERE moneda = '" & Ucase(Trim(rstEncabezado("moneda"))) & "'", Ambiente.Connection ) | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & Letra( Round( Val2(rstEncabezado("impuesto")) + Val2(rstEncabezado("importe")) + Val2(rstEncabezado("iespecial")), 2 ), Trim(rstMoneda("Descrip")), True,rstMoneda("Nombre") ) & cLineaNueva | |
If rstTextTicket.EOF Then | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & "***** GRACIAS POR SU COMPRA *****" & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
cSalida = cSalida & cLineaNueva | |
Else | |
cSalida = cSalida & rstTextTicket("textend") | |
End If | |
' Esto manda un corte de papel | |
if Ambiente.rstEstacion("ticketcorte") <> 0 Then | |
cSalida = cSalida & Chr(27) & Chr(105) | |
end if | |
'EstableceImpresora "EPSON TM-U220D Receipt" | |
'IniciaDocumento | |
'Say 0,0, cSalida | |
'FinDocumento | |
'Exit Sub | |
If Ambiente.Tag = "HTML" Then | |
Ambiente.Tag = "" | |
cSalida = Replace( cSalida, cLineaNueva, "<br>" ) | |
cSalida = "<center><b>" & cSalida & "</b></center>" | |
CreaHtml "", (cSalida) | |
Else | |
'MsgBox cSalida | |
Script.sendToPrinter Ambiente, (cSalida), prn.Pantalla | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment