Type A Solution tutorial
There are two ways that an accounting software could be in accordance with the fiscal law. The "type A" and the "type B". In type B the creator of the accounting software must modify his software in order to be aware of the EAFDSS device. This is considered to be the best approach. If you want to go that way please read the library tutorial. There are however some cases that the modification of the accounting software is not possible. In that case there is a need of another approach, the type A. In that method the software is not aware at all of what an EAFDSS is, and all requirements by the law should be taken care by an external system.
Usually the way to create such an external system is in the printing layer. What we should is the following:
- Intercept the invoice that it is to be printed
- Get a sign of the invoice using the EAFDSS library
- Save a copy of the invoice and it's signature
- Print the invoice with it's sign appended
Additionally in case you need a reprint of an invoice you should use another application that fetches the previously saved invoice (in step 3) and reprints it without getting a new signature this time.
In the next paragraph we will see how to roughly create such a system using the most commonly used printing system in modern linux systems - the CUPS.
In order to achieve step 1, we change the cups configuration files in order to create a pre-filter to the text to postscript converter. We modify "etc/cups/mime.convs"
text/plain text/plain-eafdss 10 texteafdss text/plain-eafdss application/postscript 33 texttops
and create the "/etc/cups/local.types"
text/plain-eafdss
This way when we print a text, before it becomes postscript it will go through our texteafdss filter. Now if you have the distribution of the EAFDSS library go to the "examples/TypeA" directory and run the "OpenEAFDSS-TypeA-Install.sh" script as root:
#!/bin/sh if [ `id -u` -ne 0 ]; then echo "You will need root priviledges for installation" exit; fi if [ $1 ] && [ $1 = '-u' ] ; then rm -rf /etc/OpenEAFDSS /var/spool/eafdss /var/spool/eafdss-db /usr/lib/cups/filter/texteafdss /usr/local/bin/OpenEAFDSS-TypeA.pl else install -o lp -g lp -m 775 -d /var/spool/eafdss install -o lp -g lp -m 775 -d /var/spool/eafdss-db install -o lp -g lp -m 775 -d /etc/OpenEAFDSS install -o lp -g lp -m 774 OpenEAFDSS-TypeA-Filter.pl /usr/lib/cups/filter/texteafdss install -o lp -g lp -m 774 OpenEAFDSS-TypeA.ini /etc/OpenEAFDSS/OpenEAFDSS-TypeA.ini install -o lp -g lp -m 775 OpenEAFDSS-TypeA.pl /usr/local/bin/OpenEAFDSS-TypeA.pl fi
This will take care to install files with the correct permissions and directories according to the configuration file /etc/OpenEAFDSS/OpenEAFDSS-TypeA.ini
[main] sqlite=/var/spool/eafdss-db/TypeA.sqlite abc_dir=/var/spool/eafdss charset=utf-8 [device] driver=SDNP param=miles sn=ABC02000001
Now, let's take a look at who "texteafdss" does it's job. At the beginning are just some code for taking the parameters from the CUPS system.
$ENV{'TMPDIR'} = "/tmp"; } } if ($#ARGV < 5) { ($job_id, $user, $job_name, $copies, $options) = ('', '', '', '', ''); } else { ($job_id, $user, $job_name, $copies, $options, $fname) = @ARGV; }
later we use a function as safety measure not to sign print jobs that don't look like invoices. So if we can't find the magic word "INVOICE" we bail out.
There is a requirement by the law to sign only documents encoded in the iso8859-7 character set. So in case our invoice is in another character set, like utf-8, we have to convert it before we sign it. Here we use the iconv command, so make sure to have it installed in the system.
Check if this is a reprint, and raise a flag.
my($reprint, $signature); if ( $options =~ m/eafddssreprint/ ) { $options =~ /eafddssreprint=(.*) /; $reprint = $1; } else { $reprint = 0; }
If this is not a reprint, sign the invoice
if ($reprint) { $signature = $reprint; } else { my($dh) = new EAFDSS( "DRIVER" => "EAFDSS::" . $DRIVER . "::" . $PARAM, "SN" => $SN, "DIR" => $ABC_DIR, "DEBUG" => $debug ); if (! $dh) { } $signature = $dh->Sign($fname); if (! $signature) { my($errNo) = $dh->error(); my($errMsg) = $dh->errMessage($errNo); } else { } }
And then save a copy. Here we use sqlite, so make sure to also have it installed on your system.
if ($reprint == 0) { my($insert) = "INSERT INTO invoices (tm, job_id, user, job_name, copies, options, signature, text) " . " VALUES ( date('now'), '$job_id', '$user', '$job_name', '$copies', '$options', '$signature', '$invoice');"; }
Finally print the invoice and the document.
In case there is a need for a reprint you can use the OpenEAFDSS-TypeA.pl utility
View it, and optionally reprint it

You should note that this solution is neither optimal nor complete. It is just helping hand to see what it takes more or less to develop such a system with the EAFDSS library.


