PHP Class: ESR Einzahlungsscheine

class.Einzahlungsschein.php

Last changes on this page: April 16, 2012

Yeehaa, the class now also red and orange Einzahlungsscheine, however this page has not yet been updated. See example files after downloading the source code.

This is what you can create with this class. Click to see better.

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

  1. Download source code right here, right now!
  2. Get FPDF (German or English)
  3. Get OCRB font
    (get here and convert here or get the already converted font right here [ZIP, 20kB])
  4. Move OCRB font files into the font folder of the FPDF class.
  5. 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('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.

//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:

//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.

/* 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.

51 Gedanken zu „PHP Class: ESR Einzahlungsscheine“

  1. Hallo,
    Habe die Klasse mittlerweile mehr oder weniger verstanden – tolle Arbeit, gerade für rote ESR!
    Leider gibt es gerade bei denen ein Problem: Orange ESR können ein gerahmtes Betragsfeld haben; bei roten erhält man aber scheinbar immer nur geboxte Felder. Damit wir der Betrag durch Deine Klasse nicht sauber in die Boxen geschrieben (das habe ich vor einiger Zeit mal kommentiert). Könntest Du es so anpassen, dass der Betrag explodiert und sauber in die Boxen geschrieben wird, wenn man rote ESR verwendet?
    Danke!

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>