-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinvoicepdfoxorder.php
726 lines (618 loc) · 27.3 KB
/
invoicepdfoxorder.php
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
<?php
/**
* This file is part of OXID eSales Invoice PDF module.
*
* OXID eSales Invoice PDF module 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.
*
* OXID eSales Invoice PDF module 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 OXID eSales Invoice PDF module. If not, see <http://www.gnu.org/licenses/>.
*
* @category module
* @package oeinvoicepdf
* @author OXID eSales AG
* @link http://www.oxid-esales.com
* @copyright (C) OXID eSales AG 2003-2016
*/
/**
* Order pdf generator class
*/
class InvoicepdfOxOrder extends InvoicepdfOxOrder_parent
{
/**
* PDF language
*
* @var int
*/
protected $_iSelectedLang = 0;
/**
* Cached active shop object
*
* @var object
*/
protected $_oActShop = null;
/**
* Order arctiles VAT's
*
* @var array
*/
protected $_aVATs = array();
/**
* Order currency object
*
* @var object
*/
protected $_oCur = null;
/**
* Set language for pdf generation.
*
* @param integer $iLang Language id.
*/
public function setSelectedLang($iLang)
{
$this->_iSelectedLang = $iLang;
}
/**
* Returns active shop object.
*
* @return oxshop $oUser
*/
protected function _getActShop()
{
// shop is allready loaded
if ($this->_oActShop !== null) {
return $this->_oActShop;
}
$this->_oActShop = oxNew('oxShop');
$this->_oActShop->load($this->getConfig()->getShopId());
return $this->_oActShop;
}
/**
* Returns translated string.
*
* @param string $sString string to translate
*
* @return string
*/
public function translate($sString)
{
return \OxidEsales\Eshop\Core\Registry::getLang()->translateString($sString, $this->getSelectedLang());
}
/**
* Formats pdf page footer.
*
* @param object $oPdf pdf document object
*/
public function pdfFooter($oPdf)
{
$oShop = $this->_getActShop();
$oPdf->line(15, 272, 195, 272);
$oPdfBlock = oxNew('InvoicepdfBlock');
/* column 1 - company name, shop owner info, shop address */
$oPdf->setFont($oPdfBlock->getFont(), '', 7);
$oPdf->text(15, 275, strip_tags($oShop->oxshops__oxcompany->getRawValue()));
$oPdf->text(15, 278, strip_tags($oShop->oxshops__oxfname->getRawValue()) . ' ' . strip_tags($oShop->oxshops__oxlname->getRawValue()));
$oPdf->text(15, 281, strip_tags($oShop->oxshops__oxstreet->getRawValue()));
$oPdf->text(15, 284, strip_tags($oShop->oxshops__oxzip->value) . ' ' . strip_tags($oShop->oxshops__oxcity->getRawValue()));
$oPdf->text(15, 287, strip_tags($oShop->oxshops__oxcountry->getRawValue()));
/* column 2 - phone, fax, url, email address */
if ($oShop->oxshops__oxtelefon->value) {
$oPdf->text(85, 275, $this->translate('ORDER_OVERVIEW_PDF_PHONE') . strip_tags($oShop->oxshops__oxtelefon->value));
}
if ($oShop->oxshops__oxtelefax->value) {
$oPdf->text(85, 278, $this->translate('ORDER_OVERVIEW_PDF_FAX') . strip_tags($oShop->oxshops__oxtelefax->value));
}
$oPdf->text(85, 281, strip_tags($oShop->oxshops__oxurl->value));
$oPdf->text(85, 284, strip_tags($oShop->oxshops__oxorderemail->value));
/* column 3 - bank information */
$oPdf->text(150, 275, strip_tags($oShop->oxshops__oxbankname->getRawValue()));
if ($oShop->oxshops__oxibannumber->value) {
$oPdf->text(150, 278, $this->translate('ORDER_OVERVIEW_PDF_ACCOUNTNR') . strip_tags($oShop->oxshops__oxibannumber->value));
}
if ($oShop->oxshops__oxbiccode->value) {
$oPdf->text(150, 281, $this->translate('ORDER_OVERVIEW_PDF_BANKCODE') . strip_tags($oShop->oxshops__oxbiccode->value));
}
if ($oShop->oxshops__oxvatnumber->value) {
$oPdf->text(150, 284, $this->translate('ORDER_OVERVIEW_PDF_VATID') . strip_tags($oShop->oxshops__oxvatnumber->value));
}
if ($oShop->oxshops__oxtaxnumber->value) {
$oPdf->text(150, 287, $this->translate('ORDER_OVERVIEW_PDF_TAXID') . strip_tags($oShop->oxshops__oxtaxnumber->value));
}
$myConfig = $this->getConfig();
$footerImage = $myConfig->getImageDir() . '/pdf_footer.jpg';
if(file_exists($footerImage)) {
$aSize = getimagesize($footerImage);
//image footer
if ($aSize && ($myConfig->getRequestParameter('pdftype') == 'standart' or $myConfig->getRequestParameter('pdftype') == 'dnote')) {
$iMargin = 195 - $aSize[0] * 0.2;
$oPdf->setLink($oShop->oxshops__oxurl->value);
$oPdf->image($footerImage, $iMargin, 246, $aSize[0] * 0.2, $aSize[1] * 0.2, '', $oShop->oxshops__oxurl->value);
}
}
}
/**
* Adds shop logo to page header. Returns position for next texts in pdf.
*
* @param object $oPdf pdf document object
*
* @return int
*/
public function pdfHeaderPlus($oPdf)
{
// new page with shop logo
$this->pdfHeader($oPdf);
$oPdfBlock = oxNew('InvoicepdfBlock');
// column names
$oPdf->setFont($oPdfBlock->getFont(), '', 8);
$oPdf->text(15, 50, $this->translate('ORDER_OVERVIEW_PDF_AMOUNT'));
$oPdf->text(30, 50, $this->translate('ORDER_OVERVIEW_PDF_ARTID'));
$oPdf->text(45, 50, $this->translate('ORDER_OVERVIEW_PDF_DESC'));
$oPdf->text(160, 50, $this->translate('ORDER_OVERVIEW_PDF_UNITPRICE'));
$sText = $this->translate('ORDER_OVERVIEW_PDF_ALLPRICE');
$oPdf->text(195 - $oPdf->getStringWidth($sText), 50, $sText);
// line separator
$oPdf->line(15, 52, 195, 52);
return 56;
}
/**
* Creating new page with shop logo. Returning position to continue data writing.
*
* @param object $oPdf pdf document object
*
* @return int
*/
public function pdfHeader($oPdf)
{
// adding new page ...
$oPdf->addPage();
// loading active shop
$oShop = $this->_getActShop();
$myConfig = $this->getConfig();
$pdfLogoPath = $this->getConfig()->getImagePath('pdf_logo.jpg');
//check if pdf logo exists
if (file_exists($pdfLogoPath)) {
$aSize = getimagesize($pdfLogoPath);
//logo
if ($myConfig->getRequestParameter('pdftype') === 'standart' or $myConfig->getRequestParameter('pdftype') === 'dnote') {
$iMargin = 195 - $aSize[0] * 0.2;
$oPdf->setLink($oShop->oxshops__oxurl->value);
$oPdf->image($pdfLogoPath, $iMargin, 10, $aSize[0] * 0.2, $aSize[1] * 0.2, '', $oShop->oxshops__oxurl->value);
}
return 14 + $aSize[1] * 0.2;
} else {
//we have no logo
return 14;
}
}
/**
* Generates order pdf report file.
*
* @param string $sFilename name of report file
* @param int $iSelLang active language
* @param string $target the target I: send to browser, S: retrun as string
* more option see pdf lib.
* @return string|null
*/
public function genPdf($sFilename, $iSelLang = 0, $target = 'I')
{
// setting pdf language
$this->setSelectedLang($iSelLang);
$blIsNewOrder = 0;
// setting invoice number
if (!$this->oxorder__oxbillnr->value) {
$this->oxorder__oxbillnr->setValue($this->getNextBillNum());
$blIsNewOrder = 1;
}
// setting invoice date
if ($this->oxorder__oxbilldate->value == '0000-00-00') {
$this->oxorder__oxbilldate->setValue(date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))));
$blIsNewOrder = 1;
}
// saving order if new number or date
if ($blIsNewOrder) {
$this->save();
}
// initiating pdf engine
$oPdf = oxNew('InvoicepdfPDF');
$oPdf->setPrintHeader(false);
$oPdf->open();
// adding header
$this->pdfHeader($oPdf);
// adding info data
switch (\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('pdftype')) {
case ('dnote'):
case ('dnote_without_logo'):
$this->exportDeliveryNote($oPdf);
break;
default:
$this->exportStandart($oPdf);
}
// adding footer
$this->pdfFooter($oPdf);
// outputting file to browser
return $oPdf->output($sFilename, $target);
}
/**
* Set billing address info to pdf.
*
* @param object $oPdf pdf document object
*/
protected function _setBillingAddressToPdf($oPdf)
{
$oLang = \OxidEsales\Eshop\Core\Registry::getLang();
$sSal = $this->oxorder__oxbillsal->value;
try {
$sSal = $oLang->translateString($this->oxorder__oxbillsal->value, $this->getSelectedLang());
} catch (Exception $e) {
}
$oPdfBlock = oxNew('InvoicepdfBlock');
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(15, 59, $sSal);
$oPdf->text(15, 63, $this->oxorder__oxbillfname->getRawValue() . ' ' . $this->oxorder__oxbilllname->getRawValue());
$oPdf->text(15, 67, $this->oxorder__oxbillcompany->getRawValue());
$oPdf->text(15, 71, $this->oxorder__oxbillstreet->getRawValue() . ' ' . $this->oxorder__oxbillstreetnr->value);
$oPdf->setFont($oPdfBlock->getFont(), 'B', 10);
$oPdf->text(15, 75, $this->oxorder__oxbillzip->value . ' ' . $this->oxorder__oxbillcity->getRawValue());
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(15, 79, $this->oxorder__oxbillcountry->getRawValue());
$oPdf->text(15, 83, $this->oxorder__oxbillemail->getRawValue());
}
/**
* Set delivery address info to pdf.
*
* @param object $oPdf pdf document object
*/
protected function _setDeliveryAddressToPdf($oPdf)
{
$oLang = \OxidEsales\Eshop\Core\Registry::getLang();
$sSal = $this->oxorder__oxdelsal->value;
try {
$sSal = $oLang->translateString($this->oxorder__oxdelsal->value, $this->getSelectedLang());
} catch (Exception $e) {
}
$oPdfBlock = oxNew('InvoicepdfBlock');
$oPdf->setFont($oPdfBlock->getFont(), '', 6);
$oPdf->text(15, 87, $this->translate('ORDER_OVERVIEW_PDF_DELIVERYADDRESS'));
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(15, 91, $sSal);
$oPdf->text(15, 95, $this->oxorder__oxdellname->getRawValue() . ' ' . $this->oxorder__oxdelfname->getRawValue());
$oPdf->text(15, 99, $this->oxorder__oxdelcompany->getRawValue());
$oPdf->text(15, 103, $this->oxorder__oxdelstreet->getRawValue() . ' ' . $this->oxorder__oxdelstreetnr->value);
$oPdf->setFont($oPdfBlock->getFont(), 'B', 10);
$oPdf->text(15, 107, $this->oxorder__oxdelzip->value . ' ' . $this->oxorder__oxdelcity->getRawValue());
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(15, 111, $this->oxorder__oxdelcountry->getRawValue());
}
/**
* Set order articles info and articles VAT's to pdf.
*
* @param object $oPdf pdf document object
* @param int &$iStartPos text start position from top
* @param bool $blShowPrice show articles prices / VAT info or not
*/
protected function _setOrderArticlesToPdf($oPdf, &$iStartPos, $blShowPrice = true)
{
if (!$this->_oArticles) {
$this->_oArticles = $this->getOrderArticles(true);
}
$oCurr = $this->getCurrency();
$oPdfBlock = oxNew('InvoicepdfBlock');
// product list
foreach ($this->_oArticles as $key => $oOrderArt) {
// starting a new page ...
if ($iStartPos > 243) {
$this->pdffooter($oPdf);
$iStartPos = $this->pdfheaderplus($oPdf);
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
} else {
$iStartPos = $iStartPos + 4;
}
// sold amount
$oPdf->text(20 - $oPdf->getStringWidth($oOrderArt->oxorderarticles__oxamount->value), $iStartPos, $oOrderArt->oxorderarticles__oxamount->value);
// product number
$oPdf->setFont($oPdfBlock->getFont(), '', 8);
$oPdf->text(28, $iStartPos, $oOrderArt->oxorderarticles__oxartnum->value);
// product title
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(45, $iStartPos, substr(strip_tags($this->_replaceExtendedChars($oOrderArt->oxorderarticles__oxtitle->getRawValue(), true)), 0, 58));
if ($blShowPrice) {
$oLang = \OxidEsales\Eshop\Core\Registry::getLang();
// product VAT percent
$oPdf->text(140 - $oPdf->getStringWidth($oOrderArt->oxorderarticles__oxvat->value), $iStartPos, $oOrderArt->oxorderarticles__oxvat->value);
// product price
$dUnitPrice = ($this->isNettoMode()) ? $oOrderArt->oxorderarticles__oxnprice->value : $oOrderArt->oxorderarticles__oxbprice->value;
$dTotalPrice = ($this->isNettoMode()) ? $oOrderArt->oxorderarticles__oxnetprice->value : $oOrderArt->oxorderarticles__oxbrutprice->value;
$sText = $oLang->formatCurrency($dUnitPrice, $this->_oCur) . ' ' . $this->_oCur->name;
$oPdf->text(163 - $oPdf->getStringWidth($sText), $iStartPos, $sText);
// total product price
$sText = $oLang->formatCurrency($dTotalPrice, $this->_oCur) . ' ' . $this->_oCur->name;
$oPdf->text(195 - $oPdf->getStringWidth($sText), $iStartPos, $sText);
}
// additional variant info
if ($oOrderArt->oxorderarticles__oxselvariant->value) {
$iStartPos = $iStartPos + 4;
$oPdf->text(45, $iStartPos, substr($oOrderArt->oxorderarticles__oxselvariant->value, 0, 58));
}
}
}
/**
* Exporting standard invoice pdf
*
* @param object $oPdf pdf document object
*/
public function exportStandart($oPdf)
{
// preparing order curency info
$myConfig = $this->getConfig();
$oPdfBlock = oxNew('InvoicepdfBlock');
$this->_oCur = $myConfig->getCurrencyObject($this->oxorder__oxcurrency->value);
if (!$this->_oCur) {
$this->_oCur = $myConfig->getActShopCurrencyObject();
}
// loading active shop
$oShop = $this->_getActShop();
// shop information
$oPdf->setFont($oPdfBlock->getFont(), '', 6);
$oPdf->text(15, 55, $oShop->oxshops__oxname->getRawValue() . ' - ' . $oShop->oxshops__oxstreet->getRawValue() . ' - ' . $oShop->oxshops__oxzip->value . ' - ' . $oShop->oxshops__oxcity->getRawValue());
// billing address
$this->_setBillingAddressToPdf($oPdf);
// delivery address
if ($this->oxorder__oxdellname->value) {
$this->_setDeliveryAddressToPdf($oPdf);
}
// loading user
$oUser = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
$oUser->load($this->oxorder__oxuserid->value);
// user info
$sText = $this->translate('ORDER_OVERVIEW_PDF_FILLONPAYMENT');
$oPdf->setFont($oPdfBlock->getFont(), '', 5);
$oPdf->text(195 - $oPdf->getStringWidth($sText), 55, $sText);
// customer number
$sCustNr = $this->translate('ORDER_OVERVIEW_PDF_CUSTNR') . ' ' . $oUser->oxuser__oxcustnr->value;
$oPdf->setFont($oPdfBlock->getFont(), '', 7);
$oPdf->text(195 - $oPdf->getStringWidth($sCustNr), 59, $sCustNr);
// setting position if delivery address is used
if ($this->oxorder__oxdellname->value) {
$iTop = 115;
} else {
$iTop = 91;
}
// shop city
$sText = $oShop->oxshops__oxcity->getRawValue() . ', ' . date('d.m.Y', strtotime($this->oxorder__oxbilldate->value));
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(195 - $oPdf->getStringWidth($sText), $iTop + 8, $sText);
// shop VAT number
if ($oShop->oxshops__oxvatnumber->value) {
$sText = $this->translate('ORDER_OVERVIEW_PDF_TAXIDNR') . ' ' . $oShop->oxshops__oxvatnumber->value;
$oPdf->text(195 - $oPdf->getStringWidth($sText), $iTop + 12, $sText);
$iTop += 8;
} else {
$iTop += 4;
}
// invoice number
$sText = $this->translate('ORDER_OVERVIEW_PDF_COUNTNR') . ' ' . $this->oxorder__oxbillnr->value;
$oPdf->text(195 - $oPdf->getStringWidth($sText), $iTop + 8, $sText);
// marking if order is canceled
if ($this->oxorder__oxstorno->value == 1) {
$this->oxorder__oxordernr->setValue($this->oxorder__oxordernr->getRawValue() . ' ' . $this->translate('ORDER_OVERVIEW_PDF_STORNO'), oxField::T_RAW);
}
// order number
$oPdf->setFont($oPdfBlock->getFont(), '', 12);
$oPdf->text(15, $iTop, $this->translate('ORDER_OVERVIEW_PDF_PURCHASENR') . ' ' . $this->oxorder__oxordernr->value);
// order date
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$aOrderDate = explode(' ', $this->oxorder__oxorderdate->value);
$sOrderDate = \OxidEsales\Eshop\Core\Registry::get("oxUtilsDate")->formatDBDate($aOrderDate[0]);
$oPdf->text(15, $iTop + 8, $this->translate('ORDER_OVERVIEW_PDF_ORDERSFROM') . $sOrderDate . $this->translate('ORDER_OVERVIEW_PDF_ORDERSAT') . $oShop->oxshops__oxurl->value);
$iTop += 16;
// product info header
$oPdf->setFont($oPdfBlock->getFont(), '', 8);
$oPdf->text(15, $iTop, $this->translate('ORDER_OVERVIEW_PDF_AMOUNT'));
$oPdf->text(30, $iTop, $this->translate('ORDER_OVERVIEW_PDF_ARTID'));
$oPdf->text(45, $iTop, $this->translate('ORDER_OVERVIEW_PDF_DESC'));
$oPdf->text(135, $iTop, $this->translate('ORDER_OVERVIEW_PDF_VAT'));
$oPdf->text(148, $iTop, $this->translate('ORDER_OVERVIEW_PDF_UNITPRICE'));
$sText = $this->translate('ORDER_OVERVIEW_PDF_ALLPRICE');
$oPdf->text(195 - $oPdf->getStringWidth($sText), $iTop, $sText);
// separator line
$iTop += 2;
$oPdf->line(15, $iTop, 195, $iTop);
// #345
$siteH = $iTop;
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
// order articles
$this->_setOrderArticlesToPdf($oPdf, $siteH, true);
// generating pdf file
$oArtSumm = oxNew('InvoicepdfArticleSummary', $this, $oPdf);
$iHeight = $oArtSumm->generate($siteH);
if ($siteH + $iHeight > 258) {
$this->pdfFooter($oPdf);
$iTop = $this->pdfHeader($oPdf);
$oArtSumm->ajustHeight($iTop - $siteH);
$siteH = $iTop;
}
$oArtSumm->run($oPdf);
$siteH += $iHeight + 8;
$oPdf->text(15, $siteH, $this->translate('ORDER_OVERVIEW_PDF_GREETINGS'));
//order remark
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
if ($this->oxorder__oxdeladdinfo->value) {
$oPdf->text(15, $siteH + 10, $this->translate('ORDER_OVERVIEW_PDF_ADDINFO') . $this->oxorder__oxdeladdinfo->getRawValue());
}
}
/** * Generating delivery note pdf.
*
* @param object $oPdf pdf document object
*/
public function exportDeliveryNote($oPdf)
{
$myConfig = $this->getConfig();
$oShop = $this->_getActShop();
$oPdfBlock = oxNew('InvoicepdfBlock');
$oLang = \OxidEsales\Eshop\Core\Registry::getLang();
$sSal = $this->oxorder__oxdelsal->value;
try {
$sSal = $oLang->translateString($this->oxorder__oxdelsal->value, $this->getSelectedLang());
} catch (Exception $e) {
}
// loading order currency info
$this->_oCur = $myConfig->getCurrencyObject($this->oxorder__oxcurrency->value);
if (!isset($this->_oCur)) {
$this->_oCur = $myConfig->getActShopCurrencyObject();
}
// shop info
$oPdf->setFont($oPdfBlock->getFont(), '', 6);
$oPdf->text(15, 55, $oShop->oxshops__oxname->getRawValue() . ' - ' . $oShop->oxshops__oxstreet->getRawValue() . ' - ' . $oShop->oxshops__oxzip->value . ' - ' . $oShop->oxshops__oxcity->getRawValue());
// delivery address
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
if ($this->oxorder__oxdelsal->value) {
$oPdf->text(15, 59, $sSal);
$oPdf->text(15, 63, $this->oxorder__oxdellname->getRawValue() . ' ' . $this->oxorder__oxdelfname->getRawValue());
$oPdf->text(15, 67, $this->oxorder__oxdelcompany->getRawValue());
$oPdf->text(15, 71, $this->oxorder__oxdelstreet->getRawValue() . ' ' . $this->oxorder__oxdelstreetnr->value);
$oPdf->setFont($oPdfBlock->getFont(), 'B', 10);
$oPdf->text(15, 75, $this->oxorder__oxdelzip->value . ' ' . $this->oxorder__oxdelcity->getRawValue());
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(15, 79, $this->oxorder__oxdelcountry->getRawValue());
} else {
// no delivery address - billing address is used for delivery
$this->_setBillingAddressToPdf($oPdf);
}
// loading user info
$oUser = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
$oUser->load($this->oxorder__oxuserid->value);
// user info
$sText = $this->translate('ORDER_OVERVIEW_PDF_FILLONPAYMENT');
$oPdf->setFont($oPdfBlock->getFont(), '', 5);
$oPdf->text(195 - $oPdf->getStringWidth($sText), 70, $sText);
// customer number
$sCustNr = $this->translate('ORDER_OVERVIEW_PDF_CUSTNR') . ' ' . $oUser->oxuser__oxcustnr->value;
$oPdf->setFont($oPdfBlock->getFont(), '', 7);
$oPdf->text(195 - $oPdf->getStringWidth($sCustNr), 73, $sCustNr);
// shops city
$sText = $oShop->oxshops__oxcity->getRawValue() . ', ' . date('d.m.Y');
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(195 - $oPdf->getStringWidth($sText), 95, $sText);
$iTop = 99;
// shop VAT number
if ($oShop->oxshops__oxvatnumber->value) {
$sText = $this->translate('ORDER_OVERVIEW_PDF_TAXIDNR') . ' ' . $oShop->oxshops__oxvatnumber->value;
$oPdf->text(195 - $oPdf->getStringWidth($sText), $iTop, $sText);
$iTop += 4;
}
// invoice number
$sText = $this->translate('ORDER_OVERVIEW_PDF_COUNTNR') . ' ' . $this->oxorder__oxbillnr->value;
$oPdf->text(195 - $oPdf->getStringWidth($sText), $iTop, $sText);
// canceled order marker
if ($this->oxorder__oxstorno->value == 1) {
$this->oxorder__oxordernr->setValue($this->oxorder__oxordernr->getRawValue() . ' ' . $this->translate('ORDER_OVERVIEW_PDF_STORNO'), oxField::T_RAW);
}
// order number
$oPdf->setFont($oPdfBlock->getFont(), '', 12);
$oPdf->text(15, 108, $this->translate('ORDER_OVERVIEW_PDF_DELIVNOTE') . ' ' . $this->oxorder__oxordernr->value);
// order date
$aOrderDate = explode(' ', $this->oxorder__oxorderdate->value);
$sOrderDate = \OxidEsales\Eshop\Core\Registry::get("oxUtilsDate")->formatDBDate($aOrderDate[0]);
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$oPdf->text(15, 119, $this->translate('ORDER_OVERVIEW_PDF_ORDERSFROM') . $sOrderDate . $this->translate('ORDER_OVERVIEW_PDF_ORDERSAT') . $oShop->oxshops__oxurl->value);
// product info header
$oPdf->setFont($oPdfBlock->getFont(), '', 8);
$oPdf->text(15, 128, $this->translate('ORDER_OVERVIEW_PDF_AMOUNT'));
$oPdf->text(30, 128, $this->translate('ORDER_OVERVIEW_PDF_ARTID'));
$oPdf->text(45, 128, $this->translate('ORDER_OVERVIEW_PDF_DESC'));
// line separator
$oPdf->line(15, 130, 195, 130);
// product list
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$siteH = 130;
// order articles
$this->_setOrderArticlesToPdf($oPdf, $siteH, false);
// sine separator
$oPdf->line(15, $siteH + 2, 195, $siteH + 2);
$siteH += 4;
// payment date
$oPdf->setFont($oPdfBlock->getFont(), '', 10);
$text = $this->translate('ORDER_OVERVIEW_PDF_PAYUPTO') . date('d.m.Y', strtotime('+' . $this->getPaymentTerm() . ' day', strtotime($this->oxorder__oxbilldate->value)));
$oPdf->text(15, $siteH + 4, $text);
}
/**
* Replaces some special characters to HTML compatible symbol codes.
* SWITCHED OFF NOW ( 2.2 )
*
* @param string $sValue initial value
* @param bool $blReverse (default false) if false - checks if we do have already htmlentities inside
*
* @return string
*/
protected function _replaceExtendedChars($sValue, $blReverse = false)
{
// we need to replace this for compatibility with XHTML
// as this function causes a lot of trouble with editor
// we switch it off, even if this means that fields do not validate through xhtml
// return $sValue;
// we need to replace this for compatibility with XHTML
$aReplace = array(chr(169) => "©", chr(128) => "€", "\"" => """, "'" => "'");
// #899C reverse html entities and references transformation is used in invoicepdf module
// so this part must be enabled. Now it works with html references like {
if ($blReverse) {
// replace now
if (version_compare(PHP_VERSION, '5.3.4') >= 0) {
$encoding = $this->getConfig()->isUtf() ? 'UTF-8' : 'ISO-8859-1';
$aTransTbl = get_html_translation_table(HTML_ENTITIES, ENT_COMPAT, $encoding);
} else {
$aTransTbl = get_html_translation_table(HTML_ENTITIES, ENT_COMPAT);
}
$aTransTbl = array_flip($aTransTbl) + array_flip($aReplace);
$sValue = strtr($sValue, $aTransTbl);
$sValue = getStr()->preg_replace_callback('/\&\#([0-9]+)\;/m', function($matches){'return chr(\$matches[1])';} , $sValue);
}
return $sValue;
}
/**
* Returns order articles VATS's.
*
* @return array
*/
public function getVats()
{
// for older orders
return $this->getProductVats(false);
}
/**
* Returns order currency object.
*
* @return object
*/
public function getCurrency()
{
return $this->_oCur;
}
/**
* Returns order currency object.
*
* @return object
*/
public function getSelectedLang()
{
return $this->_iSelectedLang;
}
/**
* Method returns config param iPaymentTerm, default value is 7;
*
* @return int
*/
public function getPaymentTerm()
{
if (null === $iPaymentTerm = $this->getConfig()->getConfigParam('iPaymentTerm')) {
$iPaymentTerm = 7;
}
return $iPaymentTerm;
}
}