Skip to content

Instantly share code, notes, and snippets.

@capocasa
Last active May 31, 2023 11:54
Show Gist options
  • Save capocasa/40a78b5ffab3f657f6c06fa7c2a6ba03 to your computer and use it in GitHub Desktop.
Save capocasa/40a78b5ffab3f657f6c06fa7c2a6ba03 to your computer and use it in GitHub Desktop.
NimEric German Tax Upload
## Nimeric
##
## This is a proof-of-concept to link to the official german tax upload, that is
## distributed as a proprietary cross platform C library with headers called "eric".
##
## Obtaining these files requires a free developer account at elster.de developer area.
## To actually use them, a vendor ID needs to be applied for on the same site.
##
## This requires placing the libericapi.so and other library files "liberic/lib" sub-directory, and placing
## the headers in the liberic/headers sub-directory.
##
import strutils
import futhark
# Tell futhark where to find the C libraries you will compile with, and what
# header files you wish to import.
importc:
path "liberic/include"
"ericapi.h"
# Tell Nim how to compile against the library. If you have a dynamic library
# this would simply be a `--passL:"-l<library name>`
{.passL: "-L./liberic/lib -lericapi".}
var cert: EricZertifikatHandle
var pinInfo: ptr uint32
var pluginPathL = cstring"liberic/lib/plugins2/"
let pluginPath = cast[ptr byteChar](pluginPathL)
var logPathL = cstring"."
let logPath = cast[ptr byteChar](logPathL)
var certPathL = cstring"test-softidnr-pse.pfx"
let certPath = cast[ptr byteChar](certPathL)
var pinL = cstring"123456"
let pin = cast[ptr byteChar](pinL)
var pdfPathL = cstring"./test.pdf"
let pdfPath = cast[ptr byteChar](pdfPathL)
var r:cint
r = EricInitialisiere(pluginPath, logPath)
if r != 0:
raise newException(IOError, "EricInitialisiere: Error $1" % $r)
r = EricGetHandleToCertificate(cert.addr, pinInfo, certPath)
if r != 0:
raise newException(IOError, "EricGetHandleToCertificate: Error $1" % $r)
var response = EricRueckgabePufferErzeugen()
var status = EricRueckgabePufferErzeugen()
var certXml = EricRueckgabePufferErzeugen()
var printParams = ericDruckParameterT(
version: 2.cuint,
vorschau: 1.cuint,
ersteSeite: 0.cuint,
duplexDruck: 0.cuint,
pdfName: pdfPath,
fussText: nil
)
r = Ericholezertifikateigenschaften(cert, pin, certXml)
if r != 0:
raise newException(IOError, "Ericholezertifikateigenschaften: Error $1" % $r)
const dataVersion = "ESt_2020"
const dataBuffer = readFile("ESt_2020.xml")
r = EricBearbeiteVorgang(dataBuffer,dataVersion,ERIC_DRUCKE.cuint,printParams.addr,nil,nil,response,status)
r = EricCloseHandleToCertificate(cert)
if r != 0:
raise newException(IOError, "EricCloseHandleToCertificate: Error $1" % $r)
r = EricBeende()
if r != 0:
raise newException(IOError, "EricBeende: Error $1" % $r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment