1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Swiss Payment Slip FPDF |
4
|
|
|
* |
5
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
6
|
|
|
* @copyright 2012-2015 Some nice Swiss guys |
7
|
|
|
* @author Marc Würth <[email protected]> |
8
|
|
|
* @author Manuel Reinhard <[email protected]> |
9
|
|
|
* @author Peter Siska <[email protected]> |
10
|
|
|
* @link https://github.com/ravage84/SwissPaymentSlipFpdf |
11
|
|
|
*/ |
12
|
|
|
?> |
13
|
|
|
<!DOCTYPE html> |
14
|
|
|
<html> |
15
|
|
|
<head> |
16
|
|
|
<meta charset="utf-8"> |
17
|
|
|
<title>SwissPaymentSlipFpdf Example 02: Create a red payment slip</title> |
18
|
|
|
</head> |
19
|
|
|
<body> |
20
|
|
|
<h1>SwissPaymentSlipFpdf Example 02: Create a red payment slip</h1> |
21
|
|
|
<?php |
22
|
|
|
// Measure script execution/generating time |
23
|
|
|
$time_start = microtime(true); |
24
|
|
|
|
25
|
|
|
// Make sure the classes get auto-loaded |
26
|
|
|
require __DIR__ . '/../vendor/autoload.php'; |
27
|
|
|
|
28
|
|
|
// Import necessary classes |
29
|
|
|
use SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlipData; |
30
|
|
|
use SwissPaymentSlip\SwissPaymentSlip\RedPaymentSlip; |
31
|
|
|
use SwissPaymentSlip\SwissPaymentSlipFpdf\PaymentSlipFpdf; |
32
|
|
|
use fpdf\FPDF; |
33
|
|
|
|
34
|
|
|
// Make sure FPDF has access to the additional fonts |
35
|
|
|
define('FPDF_FONTPATH', __DIR__ . '/../src/Resources/font'); |
36
|
|
|
|
37
|
|
|
// Create an instance of FPDF, setup default settings |
38
|
|
|
$fPdf = new FPDF('P', 'mm', 'A4'); |
39
|
|
|
|
40
|
|
|
// Add OCRB font to FPDF |
41
|
|
|
$fPdf->AddFont('OCRB10'); |
42
|
|
|
|
43
|
|
|
// Add page, don't break page automatically |
44
|
|
|
$fPdf->AddPage(); |
45
|
|
|
$fPdf->SetAutoPageBreak(false); |
46
|
|
|
|
47
|
|
|
// Insert a dummy invoice text, not part of the payment slip itself |
48
|
|
|
$fPdf->SetFont('Helvetica', '', 9); |
49
|
|
|
$fPdf->Cell(50, 4, "Just some dummy text."); |
50
|
|
|
|
51
|
|
|
// Create a payment slip data container (value object) |
52
|
|
|
$paymentSlipData = new RedPaymentSlipData(); |
53
|
|
|
|
54
|
|
|
// Fill the data container with your data |
55
|
|
|
$paymentSlipData->setBankData('Seldwyla Bank', '8021 Zürich'); |
56
|
|
|
$paymentSlipData->setAccountNumber('80-939-3'); |
57
|
|
|
$paymentSlipData->setRecipientData('Muster AG', 'Bahnhofstrasse 5', '8001 Zürich'); |
58
|
|
|
$paymentSlipData->setIban('CH3808888123456789012'); |
59
|
|
|
$paymentSlipData->setPayerData('M. Beispieler', 'Bahnhofstrasse 356', '', '7000 Chur'); |
60
|
|
|
$paymentSlipData->setAmount(8479.25); |
61
|
|
|
$paymentSlipData->setPaymentReasonData('Rechnung', 'Nr.7496'); |
62
|
|
|
|
63
|
|
|
// Create a payment slip object, pass in the prepared data container |
64
|
|
|
$paymentSlip = new RedPaymentSlip($paymentSlipData, 0, 191); |
65
|
|
|
|
66
|
|
|
// Create an instance of the FPDF implementation |
67
|
|
|
$paymentSlipFpdf = new PaymentSlipFpdf($fPdf, $paymentSlip); |
|
|
|
|
68
|
|
|
|
69
|
|
|
// "Print" the slip with its elements according to their attributes |
70
|
|
|
$paymentSlipFpdf->createPaymentSlip($paymentSlip); |
71
|
|
|
|
72
|
|
|
// Output PDF named example_fpdf_red_slip.pdf to examples folder |
73
|
|
|
$pdfName = 'example_fpdf_red_slip.pdf'; |
74
|
|
|
$pdfPath = __DIR__ . DIRECTORY_SEPARATOR . $pdfName; |
75
|
|
|
$fPdf->Output($pdfPath, 'F'); |
76
|
|
|
|
77
|
|
|
echo sprintf('Payment slip created in <a href="%s">%s</a><br>', $pdfName, $pdfPath); |
78
|
|
|
|
79
|
|
|
echo "<br>"; |
80
|
|
|
|
81
|
|
|
$time_end = microtime(true); |
82
|
|
|
$time = $time_end - $time_start; |
83
|
|
|
echo "Generation took $time seconds <br>"; |
84
|
|
|
echo 'Peak memory usage: ' . memory_get_peak_usage() / 1024 / 1024; |
85
|
|
|
?> |
86
|
|
|
</body> |
87
|
|
|
</html> |
88
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.