Impresora Fiscal en Access
Access
2.209 visualizaciones desde el 28 de Mayo del 2020
Estracto de código en access para el manejo de Impresora Fiscal





(1)














Function ImprimirFactura(IdFactura As Double)
DoCmd.Hourglass TrueDim Sql As String
Dim Rs As ADODB.RecordsetSet Rs = New ADODB.Recordset
Sql = "SELECT FacturaEncabezado.IdFactura, FacturaEncabezado.NoEnviar, FacturaDetalle.IdFacDet AS IdFacturaDetalle, FacturaEncabezado.NumeroFac, 1 AS TipoDocumento, Clientes.Rif, Clientes.NomCliente, Clientes.Direccion, IIf(IsNull([Telefono]),IIf(IsNull([Celular]),[TeleOficina],[Celular]),[Telefono]) AS Telfs, Productos.idProducto AS CodPropio, Len(IIf(IsNull([FacturaDetalle].[Descripcion]),[Productos].[DescProducto],[FacturaDetalle].[Descripcion])) AS Expr3, IIf(IsNull([FacturaDetalle].[Descripcion]),Mid([Productos].[DescProducto],1,45),Mid([FacturaDetalle].[Descripcion],1,45)) AS Expr1, IIf(IsNull([FacturaDetalle].[Descripcion]),Mid([Productos].[DescProducto],46,126),Mid([FacturaDetalle].[Descripcion],46,126)) AS Expr2,"
Sql = Sql & " FacturaDetalle.Cantidad, Round([SubTotal]/[FacturaDetalle].[cantidad],2) AS PrecioUnitQ, Format(Int([PrecioUnit]),'00000000') AS PrecioInt, left(Format((Round([PrecioUnit],2)-Int([PrecioUnit]))*100,'00'),2) AS PrecioDec, Format(Int([FacturaDetalle].[Cantidad]),'00000') AS CantidadInt"
Sql = Sql & " , Format(([FacturaDetalle].[Cantidad]-Int([FacturaDetalle].[Cantidad]))*1000,'000') AS CantidadDec, Chr([CodigoFiscalFac]) AS Comando, Format(Int([PrecioUnit]),'00000000') & Format(([PrecioUnit]-Int([PrecioUnit]))*100,'00') AS PrecioCre, Format(Int([FacturaDetalle].[Cantidad]),'00000') & Format(([FacturaDetalle].[Cantidad]-Int([FacturaDetalle].[Cantidad]))*1000,'000') AS CantidadCre, IIf([IVAPorcenFac]=0,False,True) AS Retensiones"
Sql = Sql & " , Format(Int([CxcEfectivo]),'00000000000') & Format(([CxcEfectivo]-Int([CxcEfectivo]))*100,'00') AS Efectivo, Format(Int([CxcCheques]),'00000000000') & Format(([CxcCheques]-Int([CxcCheques]))*100,'00') AS Cheque, Format(Int([TarjetasDebito]),'00000000000') & Format(([TarjetasDebito]-Int([TarjetasDebito]))*100,'00') AS Debito, Format(Int([TarjetasCredito]),'00000000000') & Format(([TarjetasCredito]-Int([TarjetasCredito]))*100,'00') AS Credito, Format(Int([CxcTransferencias]),'00000000000') & Format(([CxcTransferencias]-Int([CxcTransferencias]))*100,'00') AS Transferencia"
Sql = Sql & " , Format(Int([CxcNC]),'00000000000') & Format(([CxcNC]-Int([CxcNC]))*100,'00') AS NC, Format(Int([Porcendescuento]),'00') & Format(([Porcendescuento]-Int([Porcendescuento]))*100,'00') AS Descuento, Format(Int([CxcDeposito]),'00000000000') & Format(([CxcDeposito]-Int([CxcDeposito]))*100,'00') AS Deposito, FacturaEncabezado.Status, Productos.IdProducto, TipoPago.DescTipPago, Format(Int([CxcAporte]),'00000000000') & Format(([CxcAporte]-Int([CxcAporte]))*100,'00') AS Aporte, FacturaEncabezado.Usuario, FormaPago.PagoForma, FacturaEncabezado.IdPedido, FacturaEncabezado.Recolector, FacturaEncabezado.Concepto, 'Nro Compras ' & UCase(Format([FacturaEncabezado].[Fecha],'mmm')) & ':' & [Compras] AS CompraMes"
Sql = Sql & " FROM (((((((FacturaEncabezado INNER JOIN FacturaDetalle ON FacturaEncabezado.IdFactura = FacturaDetalle.IdFactura) LEFT JOIN Productos ON FacturaDetalle.IdRepuesto = Productos.IdProducto) INNER JOIN Clientes ON FacturaEncabezado.IdCliente = Clientes.IdCliente) LEFT JOIN FacturasPagosEnca ON (FacturaEncabezado.IdCxcEncabezado = FacturasPagosEnca.IdCxcEncabezado) AND (FacturaEncabezado.IdFactura = FacturasPagosEnca.IdFactura)) INNER JOIN Impuestos ON FacturaDetalle.IVAPorcenFac = Impuestos.Valor) INNER JOIN TipoPago ON FacturaEncabezado.IdTipoPago = TipoPago.IdTipoPago) INNER JOIN FormaPago ON FacturaEncabezado.IdFormaPago = FormaPago.IdFormaPago) LEFT JOIN ComprasFactura ON Clientes.IdCliente = ComprasFactura.IdCliente"
Sql = Sql & " WHERE (((FacturaEncabezado.IdFactura) = " & IdFactura & ")) ORDER BY FacturaDetalle.IdFacDet"
Efectivo = ""
Cheque = ""
Debito = ""
Credito = ""
CestaTicket = ""
Transferencia = ""
Seguro = ""
Aporte = ""
Deposito = ""
Descuent = ""
FacAfec = ""
Nc = ""
DescDetalle1 = ""
DescDetalle2 = ""
vPasoImp = 0Rs.Open Sql, CodeProject.Connection, adOpenDynamic, adLockOptimistic
If Not Rs.EOF Then Seguir = 1 Rs.MoveFirst Dim cmd As New ADODB.CommandEncabezado = "iR*" & Nz(Left(Rs!RIF, 12))
Hacer = SendCmd(Status, Error, Encabezado)
Encabezado = "iS*" & Nz(Left(LimpiarNombre(Trim(Rs!NomCliente)), 55))
Hacer = SendCmd(Status, Error, Encabezado)
If Len(Trim(Rs!NomCliente)) > 55 Then
Encabezado = "i01" & Nz(Mid(LimpiarNombre(Trim(Rs!NomCliente)), 56, 126))
Hacer = SendCmd(Status, Error, Encabezado)
End If
Encabezado = "i02Dir. " & Nz(Left(LimpiarDesc(Trim(Rs!Direccion)), 52))
Hacer = SendCmd(Status, Error, Encabezado)
If Len(Trim(Rs!Direccion)) > 52 Then
Encabezado = "i03" & Nz(Mid(LimpiarDesc(Trim(Rs!Direccion)), 53, 126))
Hacer = SendCmd(Status, Error, Encabezado)
End If
Encabezado = "i04Telf." & Nz(Left(Trim(Rs!Telfs), 40)) & IIf(Nz(Rs!NoEnviar, 0) = 0, "", " NO ENVIAR FACTURA")
Hacer = SendCmd(Status, Error, Encabezado)
Encabezado = "i05Nro.Documento." & Trim(Rs!NumeroFac) & IIf(Nz(Rs!NoEnviar, 0) = 0, "", " NO ENVIAR FACTURA")
Hacer = SendCmd(Status, Error, Encabezado)
Encabezado = "i06Recolector :" & Nz(Trim(Rs!Recolector)) & IIf(Nz(Rs!NoEnviar, 0) = 0, "", " NO ENVIAR FACTURA")
Hacer = SendCmd(Status, Error, Encabezado)
Encabezado = "i07Cesta :" & Nz(Left(Rs!Concepto, 55))
Hacer = SendCmd(Status, Error, Encabezado)
If Nz(Rs!NoEnviar, 0) = 0 Then
Encabezado = "i08Pedido Nro." & Nz(Trim(DLookup("IdPedidoMySql", "PedidoEncabezado", "IdPedido = " & Rs!IdPedido))) & " " & Trim(Rs!CompraMes)
Hacer = SendCmd(Status, Error, Encabezado)
Else
Encabezado = "i08Pedido Nro." & Nz(Trim(DLookup("IdPedidoMySql", "PedidoEncabezado", "IdPedido = " & Rs!IdPedido))) & " NO ENVIAR FACTURA"
Hacer = SendCmd(Status, Error, Encabezado)
End If
Transferencia = Nz(Rs!Transferencia)
Credito = Nz(Rs!Credito)
Debito = Nz(Rs!Debito)
Efectivo = Nz(Rs!Efectivo)
Cheque = Nz(Rs!Cheque)
Deposito = Nz(Rs!Deposito)
Aporte = Nz(Rs!Aporte)
Nc = Nz(Rs!Nc)
Descuent = Nz(Rs!Descuento)
vChequeo = ReadFpStatus(Status, Error)
If Error <> 0 Then
Rs.Close Set Rs = NothingMe.MostrarZ = UCase(ErrorFiscal(Error))
Beep
Beep
Beep
Beep
Beep
Else
Rs.MoveFirst Do While Not Rs.EOFDescDetalle1 = LimpiarDesc(Rs!Expr1)
Encabezado = Rs!comando & Trim(Rs!precioint) & Trim(Rs!preciodec) & Trim(Rs!Cantidadint) & Trim(Rs!CantidadDec) & Nz(DescDetalle1)
Hacer = SendCmd(Status, Error, Encabezado)
If Rs!Expr3 > 45 Then
DescDetalle2 = LimpiarDesc(Rs!Expr2)
Encabezado = "@" & DescDetalle2
Hacer = SendCmd(Status, Error, Encabezado)
End If
vChequeo = ReadFpStatus(Status, Error)
If Error <> 0 Then
Seguir = 0Exit Do
End If
Rs.MoveNextLoop
'''''''''''''''''''''''''''''''''''''''''''' ' Imprime el Subtotal If Seguir = 0 Then Rs.Close Set Rs = NothingMe.MostrarZ = UCase(ErrorFiscal(Error))
Beep
Beep
Beep
Beep
Beep
Else
Encabezado = "3"
Hacer = SendCmd(Status, Error, Encabezado)
vChequeo = ReadFpStatus(Status, Error)
If Error <> 0 Then
Rs.Close Set Rs = NothingMe.MostrarZ = UCase(ErrorFiscal(Error))
Beep
Beep
Beep
Beep
Beep
Else
' Descuentos por PorcentajeIf Val(Descuent) > 0 Then
Encabezado = "p" & "-" & Descuent
Hacer = SendCmd(Status, Error, Encabezado)
End If
'End If ''''''''''''''''''''''''''''''''''''''''''''''''''' ' Cierre de Factura y asignacion del modo de pago ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''' vPasoPago = FalseIf Val(Transferencia) > 0 Then
Encabezado = "101" & "Transferencia"
Hacer = SendCmd(Status, Error, Encabezado)
vPasoPago = TrueEnd If
If Val(Credito) > 0 Then
Encabezado = "102" & "Tarjeta Credito"
Hacer = SendCmd(Status, Error, Encabezado)
vPasoPago = TrueEnd If
If Val(Debito) > 0 Then
Encabezado = "103" & "Tarjeta Debito"
Hacer = SendCmd(Status, Error, Encabezado)
vPasoPago = TrueEnd If
If Val(Efectivo) > 0 Then
Encabezado = "104" & "Efectivo"
Hacer = SendCmd(Status, Error, Encabezado)
vPasoPago = TrueEnd If
If Val(Cheque) > 0 Then
Encabezado = "105" & "Cheque"
Hacer = SendCmd(Status, Error, Encabezado)
vPasoPago = TrueEnd If
If Val(Deposito) > 0 Then
Encabezado = "106" & "Deposito"
Hacer = SendCmd(Status, Error, Encabezado)
vPasoPago = TrueEnd If
If Val(Aporte) > 0 Then
Encabezado = "107" & "Aporte"
Hacer = SendCmd(Status, Error, Encabezado)
vPasoPago = TrueEnd If
If Val(Nc) > 0 Then
Encabezado = "108" & "Nota de Credito"
Hacer = SendCmd(Status, Error, Encabezado)
vPasoPago = TrueEnd If
If vPasoPago = False ThenEncabezado = "101" & "Transferencia"
Hacer = SendCmd(Status, Error, Encabezado)
End If
' Obtener el Numero de Factura Fiscal y Numero de Maquina FiscalSet cmd.ActiveConnection = CodeProject.Connection
cmd.CommandText = "Update FacturaEncabezado Set Fecha = '" & Date & "', FechaVen = '" & Date & "', Impresa = -1 Where IdFactura = " & Nz(IdFactura, 0)
cmd.ExecuteEncabezado = "S1"
Hacer = UploadStatusCmd(Status, Error, Encabezado, strCarpetaPrograma & "cadenafarmacia.txt")
Open strCarpetaPrograma & "cadenafarmacia.txt" For Input As 1
Line Input #1, strLineastrCaracter = Mid(strLinea, 22, 8)
Me.NumeroFiscalFac = strCaracter
strCaracter = Mid(strLinea, 93, 10)
Me.MaquinaFiscalFac = strCaracter
Close #1 '''''''''''''''''''''''' Rs.Close Set Rs = Nothingcmd.CommandText = "Update FacturaEncabezado Set ODS = '" & vPasoImp & "', NumeroFiscalFac = '" & Nz(Me.NumeroFiscalFac) & "', MaquinaFiscalFac = '" & Nz(Me.MaquinaFiscalFac) & "' Where IdFactura = " & Nz(IdFactura, 0)
cmd.ExecuteMe.Mostrar = "Se Imprimió la Factura : " & Me.NumeroFiscalFac & " a las " & Time()
End If
End If
End If
Else
Rs.Close Set Rs = NothingEnd If
DoCmd.Hourglass FalseEnd Function
Comentarios sobre la versión: 2019 (1)