1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
<?php
/**
* This file provides the correspondence class
*
* @author Camil Staps
*
* BusinessAdmin: administrative software for small companies
* Copyright (C) 2015 Camil Staps (ViviSoft)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* An extension of FPDF to generate personalized correspondence PDFs
*/
class correspondence extends FPDF {
/**
* @var $contact Holds the contact this correspondence will be sent to
* @var $language Holds the language this correspondence should be sent in
*/
var $contact, $language;
/**
* If you'd want, you could change these constants to encode an RGB colour for headings in your PDFs
*/
const HEAD_RED = 0;
const HEAD_GREEN = 0;
const HEAD_BLUE = 0;
/**
* Array holding the translations
*
* @see _() A function to translate
*/
protected static $translations = array(
'adres' => array(
'en' => 'Address',
'nl' => 'Adres'),
'amount' => array(
'en' => 'Amount',
'nl' => 'Subtotaal'),
'amount-due' => array(
'en' => 'Total amount due',
'nl' => 'Te voldoen'),
'biccode' => array(
'en' => 'The BIC code of our bank is %%.',
'nl' => 'De BIC-code van de bank is %%.'),
'btwnr' => array(
'en' => 'VAT nr',
'nl' => 'BTW nr'),
'description' => array(
'en' => 'Description',
'nl' => 'Omschrijving'),
'due-date' => array(
'en' => 'Due date',
'nl' => 'Vervaldatum'),
'email' => array(
'en' => 'Email',
'nl' => 'Email'),
'iban' => array(
'en' => 'IBAN',
'nl' => 'IBAN'),
'invoice' => array(
'en' => 'Invoice',
'nl' => 'Factuur'),
'invoice-date' => array(
'en' => 'Invoice date',
'nl' => 'Factuurdatum'),
'invoice-nr' => array(
'en' => 'Invoice number',
'nl' => 'Factuurnummer'),
'price-excl' => array(
'en' => 'Price excl.',
'nl' => 'Prijs excl.'),
'price-incl' => array(
'en' => 'Price incl.',
'nl' => 'Prijs incl.'),
'request' => array(
'en' => 'You are kindly requested to transfer the total amount before the due date to the provided IBAN nr.',
'nl' => 'U wordt vriendelijk verzocht het te voldoen bedrag voor de vervaldatum van de factuur over te maken naar opgegeven IBAN-nummer.'),
'tel-nr' => array(
'en' => 'Tel.',
'nl' => 'Tel.'),
'total' => array(
'en' => 'Total',
'nl' => 'Totaal'),
'vat' => array(
'en' => 'VAT',
'nl' => 'BTW'),
);
/**
* @var $page_height The height of a page in millimeters
* @var $margin_bottom The bottom margin in millimeters
*/
protected static $page_height = 297; // A4
protected static $margin_bottom = 30;
/**
* Translate a string
*
* @see $translations The array holding the translations
*
* @param string $key The string to translate
* @param string $lang The language to translate to (two-letter code)
*
* @return string The translated string
*/
public function _($key) {
if (!array_key_exists($key, self::$translations))
return $key;
return self::$translations[$key][$this->language];
}
/**
* Create a new PDF
*
* @param string $orientation See the FPDF class specs
* @param string $unit See the FPDF class specs
* @param string $size See the FPDF class specs
*/
function __construct() {
$this->FPDF('P','mm','A4');
$this->SetMargins(30,20,20);
$this->SetAuthor(constants::invoice_name);
$this->SetCreator('BusinessAdmin Correspondence Generator');
$this->SetDisplayMode('fullpage','continuous');
}
/**
* Workaround for euro signs
*
* Euro signs in FPDF should be chr(128). Other signs don't have to be changed.
*
* @return a valuta symbol that can be used in FPDF
*/
public static function valuta() {
switch (constants::invoice_valuta) {
case '€':
return chr(128);
default:
return constants::invoice_valuta;
}
}
/**
* Set the language of the correspondence (used to translate stuff)
*
* @param string $lang The language, two letter code ('en', 'nl', ...)
*/
function SetLangauge($lang) {
$supported = array('nl', 'en');
if (!in_array($lang, $supported)) {
throw new Exception("Language not supported");
} else {
$this->language = $lang;
}
}
/**
* Set the contact to whom this correspondence will be sent (used for the address)
*
* @param contact $contact The contact
*/
function SetContact($contact) {
$this->contact = $contact;
$this->language = $contact->getLanguage();
}
/**
* Makes a header with your details and the address of the contact
*/
function CorrespondenceHeader() {
if (file_exists(constants::files_folder . 'logo-correspondence.png')) {
$this->Image(constants::files_folder . 'logo-correspondence.png',30,20,50);
}
$this->SetFont('Helvetica','',7);
$this->Cell(110,20);
$this->Cell(12,1,' ','T');
$this->Cell(2,1);
$this->Cell(35,1,' ','T');
$this->Ln();
$this->Cell(110,3.5);
$this->SetFont('','B');
$this->Cell(12,3.5,$this->_('adres'),'',0,'R');
$this->Cell(2,3.5);
$this->SetFont('','');
$this->Cell(35,3.5, constants::invoice_name);
$this->Ln();
$this->Cell(124,3.5);
$this->Cell(35,3.5, constants::invoice_address_1);
$this->Ln();
$this->Cell(124,3.5);
$this->Cell(35,3.5, constants::invoice_address_2);
$this->Ln();
$this->Cell(124,3.5);
$this->Cell(35,3.5, constants::invoice_address_3);
$this->Ln();
$this->Cell(160,1.5);
$this->Ln();
$this->Cell(110,3.5);
$this->SetFont('','B');
$this->Cell(12,3.5,$this->_('btwnr'),'',0,'R');
$this->Cell(2,3.5);
$this->SetFont('','');
$this->Cell(35,3.5, constants::invoice_tax_nr);
$this->Ln();
$this->Cell(160,1.5);
$this->Ln();
$this->Cell(110,3.5);
$this->SetFont('','B');
$this->Cell(12,3.5, $this->_('iban'),'',0,'R');
$this->Cell(2,3.5);
$this->SetFont('','');
$this->Cell(35,3.5, constants::invoice_iban);
$this->Ln();
$this->Cell(160,1.5);
$this->Ln();
$this->Cell(110,3.5);
$this->SetFont('','B');
$this->Cell(12,3.5, $this->_('tel-nr'),'',0,'R');
$this->Cell(2,3.5);
$this->SetFont('','',7);
$this->Cell(35,3.5, constants::invoice_tel_nr);
$this->Ln();
$this->Cell(110,3.5);
$this->SetFont('','B');
$this->Cell(12,3.5, $this->_('email'),'',0,'R');
$this->Cell(2,3.5);
$this->SetFont('','');
$this->Cell(35,3.5, constants::invoice_email);
$this->Ln();
$this->Cell(110,1);
$this->Cell(12,1,' ','B');
$this->Cell(2,1);
$this->Cell(35,1,' ','B');
$this->Ln();
$this->Cell(160,15);
$this->Ln();
$this->SetFont('','',11);
$this->SetXY(30,56.5);
$this->Cell(90,5.5,utf8_decode($this->contact->getName()));
$this->Ln();
$this->SetXY(30,61.5);
$this->Cell(90,5.5,utf8_decode($this->contact->getAddress()));
$this->Ln();
$this->SetXY(30,66.5);
$this->Cell(90,5.5,utf8_decode($this->contact->getPostalCode().' '.$this->contact->getCity()));
$this->Ln();
$this->SetXY(30,71.5);
$this->Cell(90,5.5,utf8_decode($this->contact->getCountry()));
$this->Ln();
}
/**
* Put PDF information
*/
function _putinfo()
{
$this->_out('/Producer '.$this->_textstring('BusinessAdmin Correspondence Generator'));
if(!empty($this->title))
$this->_out('/Title '.$this->_textstring($this->title));
if(!empty($this->subject))
$this->_out('/Subject '.$this->_textstring($this->subject));
if(!empty($this->author))
$this->_out('/Author '.$this->_textstring($this->author));
if(!empty($this->keywords))
$this->_out('/Keywords '.$this->_textstring($this->keywords));
if(!empty($this->creator))
$this->_out('/Creator '.$this->_textstring($this->creator));
$this->_out('/CreationDate '.$this->_textstring('D:'.@date('YmdHis')));
}
/**
* Have we reached the bottom of the page yet?
*
* @return bool
*/
public function endOfPage() {
return ($this->GetY() > self::$page_height - self::$margin_bottom);
}
/**
* Start a new page if we're on the end
*/
public function addPageIfOnEnd() {
if ($this->endOfPage()) {
$this->Ln();
$this->AddPage();
$this->Cell(100, 5, ''); // blank line
$this->Ln();
}
}
}
|