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 03: Create one thousand orange payment slips</title> |
18
|
|
|
</head> |
19
|
|
|
<body> |
20
|
|
|
<h1>SwissPaymentSlipFpdf Example 03: Create one thousand orange payment slips</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\OrangePaymentSlipData; |
30
|
|
|
use SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip; |
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
|
|
|
// create 1000 payment slips |
44
|
|
|
for ($slipNr = 1; $slipNr <= 1000; $slipNr++) { |
45
|
|
|
// Add page, don't break page automatically |
46
|
|
|
$fPdf->AddPage(); |
47
|
|
|
$fPdf->SetAutoPageBreak(false); |
48
|
|
|
|
49
|
|
|
// Insert a dummy invoice text, not part of the payment slip itself |
50
|
|
|
$fPdf->SetFont('Helvetica', '', 9); |
51
|
|
|
$fPdf->Cell(50, 4, "Just some dummy text."); |
52
|
|
|
|
53
|
|
|
// Create a payment slip data container (value object) |
54
|
|
|
$paymentSlipData = new OrangePaymentSlipData(); |
55
|
|
|
|
56
|
|
|
// Fill the data container with your data |
57
|
|
|
$paymentSlipData->setBankData('Seldwyla Bank', '8001 Zürich'); |
58
|
|
|
$paymentSlipData->setAccountNumber('01-145-6'); |
59
|
|
|
$paymentSlipData->setRecipientData('H. Muster AG', 'Versandhaus', 'Industriestrasse 88', '8000 Zürich'); |
60
|
|
|
$paymentSlipData->setPayerData('Rutschmann Pia', 'Marktgasse 28', '9400 Rorschach', 'Slip # ' . $slipNr); |
61
|
|
|
$paymentSlipData->setAmount(2830.50); |
62
|
|
|
$paymentSlipData->setReferenceNumber('7520033455900012'); |
63
|
|
|
$paymentSlipData->setBankingCustomerId('215703'); |
64
|
|
|
|
65
|
|
|
// Create a payment slip object, pass in the prepared data container |
66
|
|
|
$paymentSlip = new OrangePaymentSlip($paymentSlipData, 0, 191); |
67
|
|
|
|
68
|
|
|
// Create an instance of the FPDF implementation |
69
|
|
|
$paymentSlipFpdf = new PaymentSlipFpdf($fPdf, $paymentSlip); |
|
|
|
|
70
|
|
|
|
71
|
|
|
// "Print" the slip with its elements according to their attributes |
72
|
|
|
$paymentSlipFpdf->createPaymentSlip($paymentSlip); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Output PDF named example_fpdf_thousand_slips.pdf to examples folder |
76
|
|
|
$pdfName = 'example_fpdf_thousand_slips.pdf'; |
77
|
|
|
$pdfPath = __DIR__ . DIRECTORY_SEPARATOR . $pdfName; |
78
|
|
|
$fPdf->Output($pdfPath, 'F'); |
79
|
|
|
|
80
|
|
|
echo sprintf('Payment slips created in <a href="%s">%s</a><br>', $pdfName, $pdfPath); |
81
|
|
|
|
82
|
|
|
echo "<br>"; |
83
|
|
|
|
84
|
|
|
$time_end = microtime(true); |
85
|
|
|
$time = $time_end - $time_start; |
86
|
|
|
echo "Generation took $time seconds <br>"; |
87
|
|
|
echo 'Peak memory usage: ' . memory_get_peak_usage() / 1024 / 1024; |
88
|
|
|
?> |
89
|
|
|
</body> |
90
|
|
|
</html> |
91
|
|
|
|
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.