-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Esta biblioteca tiene como objetivo facilitar la generación de facturas electrónicas en los formatos aceptados por FACe: Factura-e, UBL o CII. Incluye la generación de los documentos, su firma mediante XAdES y el envío a través de los servicios web REST de FACe.
Tras la adaptación de nuestros sistemas de facturación a VERI*FACTU, debemos seguir avanzando frente a los retos que plantea la Ley Crea y Crece y la directiva europea ViDA (VAT in Digital Age), que marcarán las obligaciones en temas de facturación en un futuro cercano.
Integrar nuestros sistemas con FACe puede ser un buen punto de partida para practicar, mientras esperamos que se concreten dichas obligaciones y se publiquen sus especificaciones técnicas.
El Punto General de Entrada de Facturas Electrónicas de la AGE (FACe) ha funcionado hasta ahora —y sigue siendo la infraestructura en producción— mediante un servicio web basado en el estándar Factura-e.
La nueva versión introduce los servicios web REST y el estándar UBL, que ha reemplazado a Factura-e como referencia en factura electrónica. Este cambio responde a la intención de España de alinearse con la normativa europea. Aunque todavía desconocemos las especificaciones del futuro “repositorio universal de facturas” de la AEAT, resulta interesante comenzar a adaptar nuestros sistemas al trabajo con FACe.
Este ejercicio nos permitirá ofrecer a nuestros usuarios la nueva funcionalidad de envío de facturas a las Administraciones Públicas y, al mismo tiempo, prepararnos para un futuro próximo en el que la facturación electrónica será de uso generalizado.
A continuación, se detallan los apartados principales de esta documentación:
El acceso a la parametrización del sistema se realiza mediante la propiedad estática Settings.Current, podemos acceder y establecer sus valores en tiempo de ejecución, o podemos guardarlo en el disco y editarlas desde el archivo de configuración cuando el software no se esté ejecutando. Para guardar la configuración en el disco debemos utilizar el método estático Save de la clase Settings:
Settings.Save();La configuración del sistema se almacena en un archivo xml que tiene por defecto el nombre de 'Settings.xml'. La ubicación del archivo de configuración se encuentra en la siguiente carpeta del sistema:
// Carpeta del sistema dónde se ubica el archivo Settings.xml
var settingsFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
System.IO.Path.DirectorySeparatorChar + "FACe";Por lo general en sistemas Windows 'C:\ProgramData\FACe' y en sistemas linux '/usr/share/FACe'. Las distintas variables de configuración resultan resumidas en la siguiente tabla:
| Propiedad | Descripción |
|---|---|
| InstallationNumber | Número de instalación del sistema informático de facturación. |
| CertificatePassword | Password del certificado. Este valor sólo es necesario si tenemos establecido el valor para 'CertificatePath' y el certificado tiene clave de acceso. Sólo se utiliza en los certificados cargados desde el sistema de archivos. |
| CertificatePath | Ruta al archivo del certificado a utilizar. Sólo se utiliza en los certificados cargados desde el sistema de archivos. |
| CertificateSerial | Número de serie del certificado a utilizar. Mediante este número de serie se selecciona del almacén de certificados de windows el certificado con el que realizar las comunicaciones. |
| CertificateThumbprint | Hash o Huella digital del certificado a utilizar. Mediante esta huella digital se selecciona del almacén de certificados de windows el certificado con el que realizar las comunicaciones. |
| LoggingEnabled | Indica si está activado el log de mensajes del sistema. |
| LogPath | Ruta al directorio que actuará almacenamiento del registro de mensajes del sistema. |
Las propiedades del bloque FACeSettings de la clase Settings son las siguientes:
| Propiedad | Descripción |
|---|---|
| FACeEndPointPrefix | EndPoint del API REST de FACe para envío facturas. |
Podemos hacer uso de la Interoperabilidad COM con objeto de utilizar la funcionalidad de FACe en Visual Basic 6, php, Microsoft Excel, Ms Office con VBA...
Si compilamos el proyecto FACe.Com.PlataformaDestino para la plataforma de destino que necesitemos, podremos hacer uso de la Iteroperabilidad COM de Microsoft para utilizar las funcionalidades de FACe .
En el ejemplo siguiente vamos a ver como utilizar la librería dll generada en Excel, haciendo uso de VBA (Visual Basic para Aplicaciones).
Si abrimos la aplicación Excel, en el menú de la izquierda en la parte de abajo encontraremos el item 'Cuenta':

Al pulsar 'Cuenta' encontraremos un panel dónde está la opción de 'Acerca de Excel':

En este punto encontraremos si tenemos la versión de 32 bits o de 64 bits:

En el ejemplo tenemos 32 bits:

Entonces necesitamos utilizar la biblioteca compilada para esta plataforma de destino:
Puede descargar la librería según sus necesidades:
Descargue el archivo dll de la plataforma que necesite. Tendrá que registrarla mediante el programa RegAsm.exe que se encuentra en la carpeta de su Net Framework (ejecutando la ventana de comandos como administrador):
32 bits
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe "C:\Program Files (x86)\Irene Solutions SL\FACeLib\FACe.dll" /register /codebase /tlb
64 bits
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe "C:\Program Files (x86)\Irene Solutions SL\FACeLib\FACe.dll" /register /codebase /tlb
Una vez registrada la biblioteca con RegAsm.exe podemos utilizar el componente COM desde VBA añadiendo la correspondiente referencia:
Después de este trabajo, ya podemos utilizar la funcionalidades de FACe. En el código siguiente ilustra la utilización de distintas funciones de la biblioteca:
Dim invoice As New FeInvoice ' Factura
Dim seller As New FeParty ' Vendedor
Dim buyer As New FeParty ' Comprador
Dim oc As New FeParty ' Oficina contable
Dim og As New FeParty ' Organo gestor
Dim ut As New FeParty ' Unidad tramitadora
Dim taxItemIva As New FeTaxItem ' Linea de impuestos (IVA)
Dim taxItemIrpf As New FeTaxItem ' Linea de impuestos (IRPF)
Dim invoiceLine As New FeInvoiceLine ' Linea de factura
Dim installemt As New FeInstallment ' Linea de vencimiento
' Factura
With invoice
.InvoiceID = "FR-VB-011"
.InvoiceDate = DateTime.Now
.SellerID = "B12959755"
.SellerName = "IRENE SOLUTIONS SL"
.BuyerID = "P1207700D"
.BuyerName = "AYUNTAMIENTO DE MONCOFA"
End With
' Vendedor
With seller
.TaxID = "B12959755"
.PartyType = "J" ' J=Persona juridica / P=Persona fisica
.Address = "PZ ESTANY COLOBRI 3B"
.PostalCode = "12530"
.City = "BURRIANA"
.Region = "CASTELLON"
.Phone = " 964679395"
.Mail = "info@irenesolutions.com"
.WebAddress = "https://www.irenesolutions.com"
End With
' Comprador
With buyer
.TaxID = "P1207700D"
.PartyType = "J" ' J=Persona juridica / P=Persona fisica
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
.Phone = "964580421"
.Mail = "info@moncofa.com"
.WebAddress = "https://www.moncofa.com"
End With
' Oficina contable
With oc
.PartyRole = "OC"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
' Organo gestor
With og
.PartyRole = "OG"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
' Unidad tramitadora
With ut
.PartyRole = "UT"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
invoice.InsertParty seller
invoice.InsertParty buyer
invoice.InsertParty oc
invoice.InsertParty og
invoice.InsertParty ut
' Linea de impuestos (IVA)
With taxItemIva
.TaxClass = "TO" ' TaxesOutputs (soportados)
.TaxBase = 100
.TaxRate = 21
.TaxAmount = 21
End With
' Linea de impuestos (IRPF)
With taxItemIrpf
.Tax = "04" ' IRPF
.TaxClass = "TW" ' TaxesWithheld (retenciones)
.TaxBase = 100
.TaxRate = 15
.TaxAmount = -15
End With
invoice.InsertTaxItem taxItemIva
invoice.InsertTaxItem taxItemIrpf
' Linea de factura
With invoiceLine
.ItemPosition = 1
.BuyerReference = "PEDIDO0001"
.ItemID = "COD001"
.ItemName = "SERVICIOS DESARROLLO SOFTWARE"
.Quantity = 1
.NetPrice = 100
.DiscountRate = 4.76
.DiscountAmount = 5
.NetAmount = 100
.GrossAmount = 105
.TaxesOutputBase = 100
.TaxesOutputRate = 21
.TaxesOutputAmount = 21
End With
invoice.InsertInvoiceLine invoiceLine
' Linea de vencimiento
With installemt
.DueDate = DateTime.Now
.Amount = 106
.PaymentMeans = "04"
.BankAccountType = "IBAN"
.BankAccount = "ES7731127473172720020181"
End With
invoice.InsertInstallment installemt
Debug.Print invoice.GetFacturae
Configuramos nuestra ServiceKey
Dim settings As New FeSettings
' Cargo la configuración
settings.Load
Debug.Print settings.Api.ServiceKey
' Cambio el certificado
settings.Api.ServiceKey = "1234567"
' Guardo la configuración
settings.Save
Cambiamos el certificado
Dim settings As New FeSettings
' Cargo la configuración
settings.Load
Debug.Print settings.CertificatePath
' Cambio el certificado
settings.CertificatePath = "C:\CERT.pfx"
settings.CertificatePassword = "123"
' Guardo la configuración
settings.Save
Es importante tener correctamente configurado el certificado para ejecutar este ejemplo.
Dim invoice As New FeInvoice ' Factura
Dim seller As New FeParty ' Vendedor
Dim buyer As New FeParty ' Comprador
Dim oc As New FeParty ' Oficina contable
Dim og As New FeParty ' Organo gestor
Dim ut As New FeParty ' Unidad tramitadora
Dim taxItemIva As New FeTaxItem ' Linea de impuestos (IVA)
Dim taxItemIrpf As New FeTaxItem ' Linea de impuestos (IRPF)
Dim invoiceLine As New FeInvoiceLine ' Linea de factura
Dim installemt As New FeInstallment ' Linea de vencimiento
' Factura
With invoice
.InvoiceID = "FR-VB-011"
.InvoiceDate = DateTime.Now
.SellerID = "B12959755"
.SellerName = "IRENE SOLUTIONS SL"
.BuyerID = "P1207700D"
.BuyerName = "AYUNTAMIENTO DE MONCOFA"
End With
' Vendedor
With seller
.TaxID = "B12959755"
.PartyType = "J" ' J=Persona juridica / P=Persona fisica
.Address = "PZ ESTANY COLOBRI 3B"
.PostalCode = "12530"
.City = "BURRIANA"
.Region = "CASTELLON"
.Phone = " 964679395"
.Mail = "info@irenesolutions.com"
.WebAddress = "https://www.irenesolutions.com"
End With
' Comprador
With buyer
.TaxID = "P1207700D"
.PartyType = "J" ' J=Persona juridica / P=Persona fisica
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
.Phone = "964580421"
.Mail = "info@moncofa.com"
.WebAddress = "https://www.moncofa.com"
End With
' Oficina contable
With oc
.PartyRole = "OC"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
' Organo gestor
With og
.PartyRole = "OG"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
' Unidad tramitadora
With ut
.PartyRole = "UT"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
invoice.InsertParty seller
invoice.InsertParty buyer
invoice.InsertParty oc
invoice.InsertParty og
invoice.InsertParty ut
' Linea de impuestos (IVA)
With taxItemIva
.TaxClass = "TO" ' TaxesOutputs (soportados)
.TaxBase = 100
.TaxRate = 21
.TaxAmount = 21
End With
' Linea de impuestos (IRPF)
With taxItemIrpf
.Tax = "04" ' IRPF
.TaxClass = "TW" ' TaxesWithheld (retenciones)
.TaxBase = 100
.TaxRate = 15
.TaxAmount = -15
End With
invoice.InsertTaxItem taxItemIva
invoice.InsertTaxItem taxItemIrpf
' Linea de factura
With invoiceLine
.ItemPosition = 1
.BuyerReference = "PEDIDO0001"
.ItemID = "COD001"
.ItemName = "SERVICIOS DESARROLLO SOFTWARE"
.Quantity = 1
.NetPrice = 100
.DiscountRate = 4.76
.DiscountAmount = 5
.NetAmount = 100
.GrossAmount = 105
.TaxesOutputBase = 100
.TaxesOutputRate = 21
.TaxesOutputAmount = 21
End With
invoice.InsertInvoiceLine invoiceLine
' Linea de vencimiento
With installemt
.DueDate = DateTime.Now
.Amount = 106
.PaymentMeans = "04"
.BankAccountType = "IBAN"
.BankAccount = "ES7731127473172720020181"
End With
invoice.InsertInstallment installemt
invoice.SaveFacturaeSigned "C:\testfile.xml"
Es importante tener correctamente configurado tuServiceKey para ejecutar este ejemplo. Puede conseguirla aquí
Dim invoice As New FeInvoice ' Factura
Dim seller As New FeParty ' Vendedor
Dim buyer As New FeParty ' Comprador
Dim oc As New FeParty ' Oficina contable
Dim og As New FeParty ' Organo gestor
Dim ut As New FeParty ' Unidad tramitadora
Dim taxItemIva As New FeTaxItem ' Linea de impuestos (IVA)
Dim taxItemIrpf As New FeTaxItem ' Linea de impuestos (IRPF)
Dim invoiceLine As New FeInvoiceLine ' Linea de factura
Dim installemt As New FeInstallment ' Linea de vencimiento
' Factura
With invoice
.InvoiceID = "FR-VB-018"
.InvoiceDate = DateTime.Now
.SellerID = "B12959755"
.SellerName = "IRENE SOLUTIONS SL"
.BuyerID = "P1207700D"
.BuyerName = "AYUNTAMIENTO DE MONCOFA"
End With
' Vendedor
With seller
.TaxID = "B12959755"
.PartyType = "J" ' J=Persona juridica / P=Persona fisica
.Address = "PZ ESTANY COLOBRI 3B"
.PostalCode = "12530"
.City = "BURRIANA"
.Region = "CASTELLON"
.Phone = " 964679395"
.Mail = "info@irenesolutions.com"
.WebAddress = "https://www.irenesolutions.com"
End With
' Comprador
With buyer
.TaxID = "P1207700D"
.PartyType = "J" ' J=Persona juridica / P=Persona fisica
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
.Phone = "964580421"
.Mail = "info@moncofa.com"
.WebAddress = "https://www.moncofa.com"
End With
' Oficina contable
With oc
.PartyRole = "OC"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
' Organo gestor
With og
.PartyRole = "OG"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
' Unidad tramitadora
With ut
.PartyRole = "UT"
.PartyID = "L01120770"
.Address = "PLAZA CONSTITUCION, 1"
.PostalCode = "12593"
.City = "MONCOFAR"
.Region = "CASTELLON"
End With
invoice.InsertParty seller
invoice.InsertParty buyer
invoice.InsertParty oc
invoice.InsertParty og
invoice.InsertParty ut
' Linea de impuestos (IVA)
With taxItemIva
.TaxClass = "TO" ' TaxesOutputs (soportados)
.TaxBase = 100
.TaxRate = 21
.TaxAmount = 21
End With
' Linea de impuestos (IRPF)
With taxItemIrpf
.Tax = "04" ' IRPF
.TaxClass = "TW" ' TaxesWithheld (retenciones)
.TaxBase = 100
.TaxRate = 15
.TaxAmount = -15
End With
invoice.InsertTaxItem taxItemIva
invoice.InsertTaxItem taxItemIrpf
' Linea de factura
With invoiceLine
.ItemPosition = 1
.BuyerReference = "PEDIDO0001"
.ItemID = "COD001"
.ItemName = "SERVICIOS DESARROLLO SOFTWARE"
.Quantity = 1
.NetPrice = 100
.DiscountRate = 4.76
.DiscountAmount = 5
.NetAmount = 100
.GrossAmount = 105
.TaxesOutputBase = 100
.TaxesOutputRate = 21
.TaxesOutputAmount = 21
End With
invoice.InsertInvoiceLine invoiceLine
' Linea de vencimiento
With installemt
.DueDate = DateTime.Now
.Amount = 106
.PaymentMeans = "04"
.BankAccountType = "IBAN"
.BankAccount = "ES7731127473172720020181"
End With
invoice.InsertInstallment installemt
' Realizamos el envío
Dim sendResult As FeInvoiceResult
Set sendResult = invoice.Send
Debug.Print sendResult.ResultCode
Debug.Print sendResult.ResultMessage
Debug.Print sendResult.CSV