class.Einzahlungsschein.php
Last changes on this page: April 30, 2010
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 flattr.
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:
require_once('classes/ezs/class.Einzahlungsschein.php');
//Create a new Einzahlungsschein, position on page is 50mm from top and 30mm from the left
$ezs = new createEinzahlungsschein(50, 30);
//Set data of your bank. Name, zip code with city and banking account (you'll get that one from your bank)
$ezs->setBankData("Berner Kantonalbank", "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 this 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.
require_once('classes/ezs/class.Einzahlungsschein.php');
require_once('classes/fpdf/fpdf.php');
//Create a new pdf to create your invoice, already using FPDF
//(if you don't understand this part you should have a look at the FPDF documentation)
$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetAutoPageBreak(margin,0);
$pdf->SetFont('Arial','',9);
$pdf->Cell(50, 4,"Add some stuff, whatever you need.");
//now simply include your Einzahlungsschein, sending your pdf instance to the Einzahlungsschein class
$ezs = new createEinzahlungsschein(190, 0, $pdf);
$ezs->setBankData("Berner Kantonalbank", "3001 Bern", "01-200000-7");
$ezs->setRecipientData("My Company Ltd.", "Company Address Rd. 23", "3001 City", "999999");
$ezs->setPayerData("Heinz Müller", "Payer Court Street 23", "3072 Payertown", "Switzerland");
$ezs->setPaymentData(100.00,111111);
$ezs->createEinzahlungsschein(false);
//output
$pdf->output();
?>
Create Einzahlungsschein to print it on single Einzahlungsscheine.
Have a bunch of single Einzahlungsscheine and need to print them? Here you go:
//The actual measurements may vary on your printer.
$ezs = new createEinzahlungsschein(52, 87, false, "L", "A4");
Save the Einzahlungsschein to a file
You can save the Einzahlungsschein into a 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.

