class.Einzahlungsschein.php
Last changes on this page: April 16, 2012
Eine PHP-Klasse, mit welcher sich Schweizer Einzahlungsscheine mit ESR-Nummer generieren lassen.
To my English speaking friends:
A php class to create Swiss Einzahlungsscheine with ESR number. There seems to be a bit of a confusion how an Einzahlungsschein should be called in English. You can choose: payment slip, paying in slip, pay-in slip, pay slip, credit slip… whatever! I decided to stick with Einzahlungsschein. It just a Swiss thing anyways, right?
This class is based on FPDF, a php class to create pdf files. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
You’re welcome!
Do you like this class? You’re invited to donate a few bucks.
You know, Thank You Economy and all that stuff…
I promise I won’t get high on it.
Getting started
ESR or BESR is a way to handle Swiss Einzahlungsscheine completely automatically. It’s the orange Einzahlungsscheine, not the red ones. A reference number on the Einzahlungsschein allows you to use software to track who paid your invoices and how didn’t. You need to set up your ESR accounts with your bank before this class is any helpful for you!
There’s more to an Einzahlungsschein than just some correct placement of texts. There are check digits within the reference numbers which have to be calculated correctly based on your data. And there’s even some standards about which fonts to use. This class takes care of all that stuff.
Installation
- Download source code right here, right now!
- Get FPDF (German or English)
- Get OCRB font
(get here and convert here or get the already converted font right here [ZIP, 20kB]) - Move OCRB font files into the font folder of the FPDF class.
- Open class.Einzahlungsschein.php and adjust the path to the FPDF class file.
Example
Here’s a simple example of how to create an Einzahlungsschein:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | require_once('class.einzahlungsschein.php'); //create instance $ezs = new Einzahlungsschein(190, 0); //set data of you banking account $ezs->setBankData("Berner Kantonalbank AG", "3001 Bern", "01-200000-7"); //Set data of you as recipient of the money. Name, address, zip code with town and you customer identification code (also provided by your bank) $ezs->setRecipientData("My Company Ltd.", "Company Address Rd. 23", "3001 City", "999999"); //Set data of the person who has to pay the bill. You have four lines for name and address $ezs->setPayerData("Heinz Müller", "Payer Court Street 23", "3072 Payertown", "Switzerland"); //Set payment data: Amount in Swiss francs and your individual reference number for this bill (max. 20 digits) $ezs->setPaymentData(100.00,111111); //Do the magic! Yes, we want to output the result and yes we want to include an actual image of an Einzahlungsschein. $ezs->createEinzahlungsschein(true, true); |
But you can do more!
Invoice with attached Einzahlungsschein
A very common usage is to create an invoice with an Einzahlungsschein attached to it. In thiscase you can create your invoice first and then simply add the Einzahlungsschein. The whole thing will be printed on a sheet of paper with the actual Einzahlungsschein already attached to it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | //Create a new pdf to create your invoice, already using FPDF $pdf = new FPDF('P','mm','A4'); $pdf->AddPage(); $pdf->SetAutoPageBreak(0,0); $pdf->SetFont('Arial','',9); $pdf->Cell(50, 4, "Just some dummy text."); //now simply include your Einzahlungsschein, sending your pdf instance to the Einzahlungsschein class $ezs = new Einzahlungsschein(196, 0, $pdf); $ezs->setBankData("Berner Kantonalbank AG", "3001 Bern", "01-200000-7"); $ezs->setRecipientData("My Company Ltd.", "Exampleway 61", "3001 Bern", "123456"); $ezs->setPayerData("Heinz Müller", "Beispielweg 23", "3072 Musterlingen"); $ezs->setPaymentData(100.00,111111); $ezs->createEinzahlungsschein(false); //ouput the initial pdf $pdf->output(); |
Create Einzahlungsschein to print it on single Einzahlungsscheine.
Have a bunch of single Einzahlungsscheine and need to print them? Here you go:
1 2 3 | //Create a A4 page in landscape mode and place the Einzahlungsschein 52mm from the top and 87mm from the left. //The actual measurements may vary on your printer. $ezs = new Einzahlungsschein(52, 87, false, "L", "A4"); |
Save the Einzahlungsschein to a file
You can save the Einzahlungsschein into a file.
1 2 3 4 5 | /* Output? True! Image of Einzahlungsschein? Up to you, here true! * Add a filename. And an action what to do with the file. * For options for the last parameter see * http://www.fpdf.org/en/doc/output.htm */ $ezs->createEinzahlungsschein(true, true, "filename.pdf", "I"); |
Feedback?
Get in touch: @sprain on Twitter or email me.
Kommentare
Kommentar abgeben
Trackbacks
-
04. April 2012 um 16:31 Uhr
ESR Einzahlungsschein mit Magento | Marco's

Hi there
I absolutely love your class. I just test-installed and tried it and it works like a charm.
However, I really need it to print red ES as well, and since my knowledge of PHP is limited, I simply can’t figure out how to properly explode and place the amount … it has these amount boxes, you know. Also, I’d need the software to fill the comment box (and of course, leave out the bottom line as well as reference number altogether).
Do you think you could kindly change your script for me, so Red ES are also a possibility? You would absolutely rescue my project :D
Thanks a lot!
Best, Thomas
@Thomas
Good idea. Maybe over the holiday’s break I’ll get to do that.
Bei mir wird das Image nicht mit erzeugt. Pfade stimmen alle. Gibts dafür ne Lösung?
Die Lösung bei Marc nach E-Mail-Abklärung:
Das Bild des EZS erscheint nur, wenn der entsprechende Parameter gesetzt ist.
Im example.php des Downloads ist der zweite Wert nicht gesetzt und somit standardmässig auf false.
Bei mir ist der Ausdruck mit der Grafik einwandfrei. Wenn ich abe einen Einzahlungsschein dagegenhalte bin ich mit allem eine Zeile zu weit unten und die Schrift könnte etwas grösser sein.
Leider habe ich die einstellungen dazu noch nicht gefunden. Wenn ich “$marginTop = 0″ auf “$marginTop = -10″ ändere passirt nichts.
Was mach ich falsch?
@all
Tinus Positionierungsproblem liess sich nach Abklärung ganz einfach mit den Positionen im Constructor feinjustieren:
Vielen Dank für deinen Code – funktioniert einwandfrei! Jetzt versuche ich das Ding noch in den Onlineshop (Magento) einzubauen.
Hi sprain – gerade zufällig hier rüber gestolpert. Freut mich, dass du die modulo10-Funktion gebrauchen konntest. Ich hätte damals fast überbissen, als ich den alltickets-shop gecodet hatte und ESR-Scheine bedrucken musste :D
@bacbos
Ha, bist du also der Typ aus dem Forum, wo ich die Funktion her habe? Zufälle gibts :)
Hallo Sprain
deine Klasse gefällt mir ausgezeichnet. Ich möchte auch gerne die Klasse so abändern, dass das Generieren von roten Einzahlungsscheinen möglich ist. Kannst du mir sagen, wie ich vorgehen muss, resp. was ich an der Klasse ändern muss?
Danke im voraus bestens und wünsche dir eine gute Zeit.
Heinz
@all
Die nächste Version der Klasse mit roten Einzahlungsscheinen ist praktisch fertig und folgt sehr bald!
Hallo Sprain
Geniale Klasse! Vielen Dank. Bei mir werden Umlaute in den Strings, die auf dem EZS aufgedruckt werden nicht richtig ausgegeben, ö wird zu ? etc… Im restlichen Dokument funktionierts. Hast du mir einen Tipp?
Im Voraus schon vielen Dank und Gruss,
Adrian.
@Adrian, das hat mit dem Zeichensatz zu tun.
Mit UTF8 geht das zb. so, schreib im HTML-Header einfach:
Gruss Dave
kanns nicht schreiben, wird automatisch gelöscht….
such einfach mal nach html header charset,
Gruss dave
@Adrian,
das hat mit dem Charset deiner HTMl/PHP datei zu tun.
Du musst im HTML Header was reinschreiben, kann das aber hier nicht posten weils automatisch gefiltert wird.
such einfach mal nach html header charset,
Gruss dave
Hi Sprain
ich warte sehnlichst auf die von Dir angekündigte Version für die roten Einzahlungsscheine. Gibts schon news?
Greez
Oli
@Oliver
Rote Einzahlungsscheine sind drin, nur die Doku hier ist nicht aktuell.
Wow, tolle Klasse. Wir haben noch das Problem, dass die Kodierzeile im weissen Bereich (der OCR-Font) je nach PDF-Reader falsch oder gar nicht dargestellt wird. Wir generieren die PDFs mit TCPDF (sprich haben deine Klasse leicht angepasst). Weisst du vielleicht wieso der OCR-Font nicht klappt?
@Sam
Hmm, leider keine Ahnung. Da es je nach Reader unterschiedlich ist, vermute ich mal, dass es vielleicht an TCPDF liegt, denn mit FPDF hatte ich dieses Problem noch nie.
Gib Bescheid, wenn du etwas rausfindest!
Hallo.
Gibt es eine Möglichkeit die Papierquelle (Fach) des Druckers zu bestimmen, also durch ein Befehl, wenn man die PDF Datei öffnet,
Drucker hat zwei unterschiedliche Papierquellen, oft muss Rechnung mit ESR und Ohne, normales Papier drucken, möchte aber nicht jedes mal Drucker-Eigenschaften öffnen usw.
für eine Lösung würde ich auch Finanziell entgegenkommen.
Hallo.
Vielen Dank für diese Klasse. Bin gerade am umstellen auf ESR, darum kommt sie mir sehr gelegen.
Noch eine Anmerkung: Laut einigen Quellen darf die Referenznummer höchsten 27 Zeichen lang sein (inkl. Prüfsumme). Je nach Bankkennnummer generiert die Klasse aber längere Referenznummern. Ich habe daher auf Zeile 461 in der Funktion createCompleteReferenceNumber das 2. Argument von str_pad von “20″ auf “(26- strlen($this->ezs_bankingCustomerIdentification))” geändert. Nun funktionniert auch das mit den 27 Zeichen.
@Luegge
Danke für den Input! Du darfst gerne auch gleich einen Pull Request auf Github veranlassen :)
Hallo
Ich hab Probleme mit dem Script
Warning: filesize() [function.filesize]: stat failed for ..\pdf\font\96787a06563b0a75083534590b589c05_ocrb10.z in C:\www\www.curasoft.ch\pdf\fpdf.php on line 1170
FPDF error: Font file not found
irgendwie findet er das font file nicht
ich habe ocrb10.php am richtigen Ort hintergelegt
Vielen Dank im Voraus
Mathias
@Mathias
Es sind zwei Files, die du dort ablegen musst. ocrb10.php und das File mit der Endung .z – sind die beide dort?
ocrb10.php ist dort das file mit der Endung .z nicht.
Wie komme ich zum file mit der Endung .z?
lg
mathias
@Mathias
Oben auf dieser Seite den Teil “Installation” lesen und alles wird gut :)
hat sich erledigt … sorry für die Störung.
Ich war so blöd und habe das z file nicht reinkopiert :-(
dir vielen Dank und Merci
lg mathias
hallo
2 Fragen
1. wie spreche ich die roten Einzahlungsscheine an?
2. Mein Kunde hat nur eine Postcheckkonto bei der Postfinance. Kann ich nun einfach die Postcheckontonummer als Kontonummer nehmen?
Dir schon mal vielen Dank im Voraus.
lg mathias
@Mathias
Siehe example_red.php.
Genaueres zur Handhabung mit Postfinance weiss ich nicht. Frag am Besten direkt dort nach.
Hallo!
Absolut klasse Extension. Ich hatte Sie bei einem Kunden lange im Einsatz.
Für alle die neben der ESR Erzeugung auch noch an einem Mahnsystem interessiert sind: http://www.customweb.com/shop/de/magento-besr-invoice-slip.html
LG Jonas
Hallo zusammen
Bin schon lange auf der Suche nach einem Modul der ESR erzeugt für meinen Shop der auf Gambio läuft.
Leider bis heute ohne Erfolg.
Gruss
Urs