Projekt

Allgemein

Profil

GX-Bug #43344 » gmOrderPDF.php

Timo Backhaus, 02.10.2015 14:28

 
1
<?php
2
/* --------------------------------------------------------------
3
  gmOrderPDF.php 2015-04-22 gm
4
  Gambio GmbH
5
  http://www.gambio.de
6
  Copyright (c) 2015 Gambio GmbH
7
  Released under the GNU General Public License (Version 2)
8
  [http://www.gnu.org/licenses/gpl-2.0.html]
9
  --------------------------------------------------------------
10
 */
11

    
12
if(file_exists(DIR_FS_CATALOG . 'PdfCreator/tcpdf.php')) {
13
	require_once(DIR_FS_CATALOG . 'PdfCreator/tcpdf.php');
14
}
15

    
16
MainFactory::load_class('gmPDF');
17

    
18
/*
19
 * 	class to create packingslip and invoice pdf
20
*/
21
class gmOrderPDF_ORIGIN extends gmPDF
22
{
23
	/*
24
	 * 	type of document, invoice or packingslip
25
	 */
26
	var $pdf_type;
27

    
28
	/*
29
	 * 	use following features 
30
	 */
31
	var $pdf_use_logo;
32
	var $pdf_use_conditions;
33
	var $pdf_use_withdrawal;
34
	var $pdf_use_products_model;
35

    
36
	/*
37
	 * 	margins and positions of the elements 
38
	 */
39
	var $pdf_customer_adr_pos;
40
	var $pdf_heading_margin_bottom;
41
	var $pdf_heading_margin_top;
42
	var $pdf_order_info_margin_top;
43

    
44
	/*
45
	 * 	logo
46
	 */
47
	var $pdf_logo_path;
48
	var $pdf_link;
49

    
50
	/*
51
	 * 	contents
52
	 */
53
	var $pdf_company_adress_left;
54
	var $pdf_company_adress_right;
55
	var $pdf_cancel;
56
	var $pdf_customer_adress;
57
	var $pdf_heading;
58
	var $pdf_heading_info;
59
	var $pdf_heading_conditions;
60
	var $pdf_heading_withdrawal;
61
	var $pdf_conditions;
62
	var $pdf_withdrawal;
63
	var $pdf_show_tax;
64
	var $pdf_ot_gm_tax_free;
65

    
66
	/*
67
	 * 	pdf draw color
68
	 */
69
	var $pdf_draw_color;
70

    
71
	/*
72
	 * 	pdf fonts, array
73
	 */
74
	var $pdf_fonts = array();
75

    
76
	/*
77
	 * 	arrays, containing the order/total/info data or footer
78
	 */
79
	var $order_data = array();
80
	var $order_total = array();
81
	var $order_info = array();
82
	var $pdf_footer = array();
83

    
84
	/*
85
	 * 	values generated in class
86
	 */
87
	var $pdf_last_header_pos_right;
88
	var $pdf_last_header_pos_left;
89
	var $pdf_order_data_cell_width = array();
90
	var $pdf_order_total_cell_width = array();
91
	var $pdf_order_info_cell_width = array();
92
	var $pdf_is_attachment;
93

    
94
	/*
95
	 * 	constructor
96
	 */
97
	function __construct($type, $order_right, $order_data, $order_total, $order_info, $pdf_footer, $pdf_fonts, $gm_pdf_values, $gm_order_pdf_values, $gm_use_products_model)
98
	{
99

    
100
		// -> set type
101
		$this->pdf_type = $type;
102

    
103
		// -> set fonts
104
		$this->pdf_fonts = $pdf_fonts;
105

    
106
		// -> set right side of order
107
		$this->pdf_company_adress_right = $order_right;
108

    
109
		// -> set order data
110
		$this->order_data = $order_data;
111

    
112
		// -> set order total data 
113
		$this->order_total = $order_total;
114

    
115
		// -> set order total data 
116
		$this->order_info = $order_info;
117

    
118
		// -> set footer
119
		$this->pdf_footer = $pdf_footer;
120

    
121
		// -> call parent constructor
122
		parent::__construct($gm_pdf_values);
123

    
124
		// -> set defaults
125
		$this->pdf_draw_color				= parent::getRGB($gm_order_pdf_values['GM_PDF_DRAW_COLOR']);			
126
		$this->pdf_customer_adr_pos			= $gm_order_pdf_values['GM_PDF_CUSTOMER_ADR_POS'];
127
		$this->pdf_heading_margin_bottom	= $gm_order_pdf_values['GM_PDF_HEADING_MARGIN_BOTTOM'];
128
		$this->pdf_heading_margin_top		= $gm_order_pdf_values['GM_PDF_HEADING_MARGIN_TOP'];
129
		$this->pdf_order_info_margin_top	= $gm_order_pdf_values['GM_PDF_ORDER_INFO_MARGIN_TOP'];
130
		$this->pdf_use_logo					= $gm_order_pdf_values['GM_LOGO_PDF_USE'];
131
		$this->pdf_logo_path				= $gm_order_pdf_values['GM_PDF_LOGO_LINK'];
132
		$this->pdf_link						= $gm_order_pdf_values['GM_PDF_LINK'];
133
		$this->pdf_company_adress_left		= $gm_order_pdf_values['GM_PDF_COMPANY_ADRESS_LEFT'];
134
		$this->pdf_customer_adress			= $gm_order_pdf_values['GM_PDF_CUSTOMER_ADRESS'];
135
		$this->pdf_heading					= $gm_order_pdf_values['GM_PDF_HEADING'];
136
		$this->pdf_heading_info				= $gm_order_pdf_values['GM_PDF_HEADING_INFO'];
137
		$this->pdf_heading_conditions		= $gm_order_pdf_values['GM_PDF_HEADING_CONDITIONS'];
138
		$this->pdf_heading_withdrawal		= $gm_order_pdf_values['GM_PDF_HEADING_WITHDRAWAL'];
139
		$this->pdf_conditions				= $gm_order_pdf_values['GM_PDF_CONDITIONS'];
140
		$this->pdf_withdrawal				= $gm_order_pdf_values['GM_PDF_WITHDRAWAL'];
141
		$this->pdf_use_conditions			= $gm_order_pdf_values['GM_PDF_USE_CONDITIONS'];
142
		$this->pdf_use_withdrawal			= $gm_order_pdf_values['GM_PDF_USE_WITHDRAWAL'];
143
		$this->pdf_show_tax					= $gm_order_pdf_values['GM_PDF_SHOW_TAX'];
144
		$this->pdf_cancel					= $gm_order_pdf_values['GM_PDF_CANCEL'];
145
		$this->pdf_use_products_model		= $gm_use_products_model;
146

    
147
		// -> to set the author of the pdfument
148
		parent::SetAuthor($this->pdf_company_adress_left);
149

    
150
		// -> to the title of the pdfument
151
		parent::SetTitle($this->pdf_heading);
152

    
153
		// -> to set the subject of the pdfument
154
		parent::SetSubject($this->pdf_heading);
155

    
156
		// -> to set the keywords of the pdfument
157
		parent::SetKeywords(str_replace("\n", ",", $this->pdf_company_adress_right));
158

    
159
		// -> to set the creator of the pdfument
160
		parent::SetCreator('fpdf.org/gambio.de');
161

    
162

    
163
		$t_order_tax_sql = "SELECT * 
164
								FROM " . TABLE_ORDERS_TOTAL . " 
165
								WHERE 
166
									orders_id='" . (int)$_GET['oID'] . "' AND 
167
									class = 'ot_tax'";
168
		$t_order_tax_result = xtc_db_query($t_order_tax_sql);
169

    
170

    
171
		// -> check if ot_gm_tax_free is installed in conf
172
		if($this->is_ot_gm_tax_free() && gm_get_conf('TAX_INFO_TAX_FREE') == 'true' || xtc_db_num_rows($t_order_tax_result) == 0)
173
		{
174
			$this->pdf_show_tax = 0;
175
			$this->pdf_ot_gm_tax_free = true;
176
		}
177
		else
178
		{
179
			$this->pdf_show_tax = 1;
180
			$this->pdf_ot_gm_tax_free = false;
181
		}
182

    
183
		// -> width factor for the order data table
184
		if($this->pdf_type == 'invoice')
185
		{
186

    
187
			// remove attributes col if there are no attributes
188
			if($this->pdf_use_products_model == false)
189
			{
190

    
191
				// check if col tax is in use
192
				if($this->pdf_show_tax == 0)
193
				{
194
					// remove col tax
195
					$this->pdf_order_data_cell_width = array(parent::getInnerWidth() * 0, parent::getInnerWidth() * 0.5, parent::getInnerWidth() * 0.1, parent::getInnerWidth() * 0, parent::getInnerWidth() * 0.2, parent::getInnerWidth() * 0.2);
196
				}
197
				else
198
				{
199
					// show col tax
200
					$this->pdf_order_data_cell_width = array(parent::getInnerWidth() * 0, parent::getInnerWidth() * 0.4, parent::getInnerWidth() * 0.1, parent::getInnerWidth() * 0.1, parent::getInnerWidth() * 0.25, parent::getInnerWidth() * 0.15);
201
				}
202
			}
203
			else
204
			{
205

    
206
				// check if col tax is in use
207
				if($this->pdf_show_tax == 0)
208
				{
209
					// remove col tax
210
					$this->pdf_order_data_cell_width = array(parent::getInnerWidth() * 0.15, parent::getInnerWidth() * 0.35, parent::getInnerWidth() * 0.1, parent::getInnerWidth() * 0, parent::getInnerWidth() * 0.2, parent::getInnerWidth() * 0.2);
211
				}
212
				else
213
				{
214
					// show col tax
215
					$this->pdf_order_data_cell_width = array(parent::getInnerWidth() * 0.15, parent::getInnerWidth() * 0.3, parent::getInnerWidth() * 0.1, parent::getInnerWidth() * 0.1, parent::getInnerWidth() * 0.2, parent::getInnerWidth() * 0.15);
216
				}
217
			}
218
		}
219
		else
220
		{
221

    
222
			if($this->pdf_use_products_model == false)
223
			{
224
				$this->pdf_order_data_cell_width = array(parent::getInnerWidth() * 0, parent::getInnerWidth() * 0.9, parent::getInnerWidth() * 0.1);
225
			}
226
			else
227
			{
228
				$this->pdf_order_data_cell_width = array(parent::getInnerWidth() * 0.15, parent::getInnerWidth() * 0.75, parent::getInnerWidth() * 0.1);
229
			}
230
		}
231

    
232
		// -> width factor for the order total table
233
		$this->pdf_order_total_cell_width = array(parent::getInnerWidth() * 0.8, parent::getInnerWidth() * 0.2);
234

    
235
		// -> width factor for the order info table
236
		$this->pdf_order_info_cell_width = array(0 => parent::getInnerWidth() * 0.3, 1 => parent::getInnerWidth() * 0.7);
237

    
238
		return;
239
	}
240

    
241
	/*
242
	 * 	-> define PDF Body 
243
	 */
244
	function Body()
245
	{
246

    
247
		parent::AddPage();
248

    
249
		// -> check if header not fixed on every page, then put it out once a time
250
		if($this->pdf_fix_header == 0 && $this->pdf_use_header == 1)
251
		{
252
			// -> call function of daughter class
253
			$this->getHeader();
254
		}
255
		
256
		$this->getOrderHeader();
257
		$this->getBody();
258
		
259
		// -> use conditions - show them in a newpage
260
		if($this->pdf_use_conditions)
261
		{
262
			$this->pdf_is_attachment = $this->pdf_heading_conditions;
263
			parent::AddPage();
264
			$this->getConditions();
265
		}
266

    
267
		// -> use withdrawal - show them in a newpage
268
		if($this->pdf_use_withdrawal)
269
		{
270
			$this->pdf_is_attachment = $this->pdf_heading_withdrawal;
271
			parent::AddPage();
272
			$this->getWithdrawal();
273
		}
274

    
275
		return;
276
	}
277

    
278
	/*
279
	 * 	-> create Header
280
	 */
281
	function getHeader()
282
	{
283

    
284
		/*
285
		 * 	-> right side
286
		 */
287

    
288
		// -> check if logo is used
289
		if($this->pdf_use_logo == 1)
290
		{
291
			$this->getLogo();
292
			parent::Ln(3);
293
		}
294

    
295
		// -> font face/style/size/color
296
		$this->getFontInDependencyOfTheContent($this->pdf_fonts['COMPANY_RIGHT'], $this->pdf_company_adress_right);
297

    
298
        $actual_y = parent::GetY();
299
        $actual_y += parent::getTopMargin();
300
		
301
		if($actual_y < 10)
302
		{
303
			$actual_y = 10;
304
		}
305
		
306
		parent::SetY($actual_y);
307
		parent::SetX(parent::getInnerWidth() / 2 + parent::getLeftMargin());
308
		parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), $this->pdf_company_adress_right, '0', 'R', 0);
309

    
310
		// -> STORNO
311
		if(!empty($this->pdf_cancel))
312
		{
313
			$this->getFontInDependencyOfTheContent($this->pdf_fonts['CANCEL'], $this->pdf_cancel);
314

    
315
			parent::SetY(parent::GetY());
316
			parent::SetX(parent::getInnerWidth() / 2 + parent::getLeftMargin());
317
			parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), $this->pdf_cancel, '0', 'R', 0);
318
		}
319

    
320
		//	-> get last y position of the right side
321
		$this->pdf_last_header_pos_right = parent::GetY();
322

    
323
		/*
324
		 * 	-> left side
325
		 */
326
		// -> set draw color
327
		parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
328

    
329
		// -> font face/style/size/color
330
		$this->getFontInDependencyOfTheContent($this->pdf_fonts['COMPANY_LEFT'], $this->pdf_company_adress_left);
331

    
332
		parent::SetY($this->pdf_customer_adr_pos);
333
		parent::SetX(parent::GetX());
334
		parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), $this->pdf_company_adress_left, '0', 'L', 0);
335

    
336
		// -> font face/style/size/color
337
		$this->getFontInDependencyOfTheContent($this->pdf_fonts['CUSTOMER'], $this->pdf_customer_adress);
338

    
339
		parent::SetY(parent::GetY());
340
		parent::SetX(parent::GetX());
341
		parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), $this->pdf_customer_adress, '0', 'L', 0);
342

    
343
		//	-> get last y position of the left side
344
		$this->pdf_last_header_pos_left = parent::GetY();
345

    
346
		return;
347
	}
348

    
349
	/*
350
	 * 	-> create Body
351
	 */
352
	function getOrderHeader()
353
	{
354

    
355
		//	-> set new y position for following elements
356
		if($this->pdf_fix_header == 0 && parent::PageNo() != 1)
357
		{
358
			parent::SetY(parent::GetY());
359
		}
360
		else
361
		{
362
			$y = $this->getPos();
363
			parent::SetY($y);
364
		}
365

    
366
		if($this->pdf_fix_header == 1 || parent::PageNo() == 1)
367
		{
368
			parent::Ln((int)$this->pdf_heading_margin_top);
369
		}
370

    
371
		$y = parent::GetY();
372

    
373
		// -> font face/style/size/color
374
		$this->getFontInDependencyOfTheContent($this->pdf_fonts['HEADING'], $this->pdf_heading);
375

    
376
		parent::SetY($y);
377
		parent::SetX(parent::getLeftMargin());
378
		parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), $this->pdf_heading, '0', 'L', 0);
379

    
380
		parent::GetFont($this->pdf_fonts['HEADING']);
381

    
382
		parent::SetY($y);
383
		parent::SetX(parent::getLeftMargin() + parent::getInnerWidth() / 2);
384
		parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), PDF_PAGE . " " . parent::PageNo(), '0', 'R', 0);
385

    
386
		parent::Ln((int)$this->pdf_heading_margin_bottom);
387
	}
388

    
389
	/*
390
	 * 	-> get header for withdrawal/conditions
391
	 */
392
	function getCondralHeader()
393
	{
394

    
395
		$y = parent::GetY() + 15;
396

    
397
		// -> font face/style/size/color
398
		$this->getFontInDependencyOfTheContent($this->pdf_fonts['HEADING_CONDITIONS'], $this->pdf_is_attachment);
399

    
400
		parent::SetY($y);
401
		parent::SetX(parent::getLeftMargin());
402
		parent::MultiCell(parent::getInnerWidth() * 0.75, parent::getCellHeight(), $this->pdf_is_attachment, '0', 'L', 0);
403

    
404
		parent::getFont($this->pdf_fonts['HEADING_CONDITIONS']);
405

    
406
		parent::SetY($y);
407
		parent::SetX(parent::getLeftMargin() + parent::getInnerWidth() * 0.75);
408
		parent::MultiCell(parent::getInnerWidth() * 0.25, parent::getCellHeight(), PDF_PAGE . " " . parent::PageNo(), '0', 'R', 0);
409

    
410
		parent::SetY(parent::GetY());
411

    
412
		parent::SetX(parent::getLeftMargin());
413

    
414
		// -> set draw color
415
		parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
416

    
417
		parent::MultiCell(parent::getInnerWidth(), 3, '', 'T', '', 0);
418
	}
419

    
420
	/*
421
	 * 	-> create Body
422
	 */
423
	function getBody()
424
	{
425

    
426
		// -> font face/style/size/color
427
		parent::getFont($this->pdf_fonts['HEADING_ORDER']);
428

    
429
		/*
430
		 * -> order data table
431
		 */
432
		if($this->pdf_ot_gm_tax_free)
433
		{
434
			$y = $this->getCells(PDF_HEADING_MODEL, PDF_HEADING_ARTICLE_NAME, PDF_HEADING_UNIT, PDF_HEADING_NETTO_PRICE, PDF_HEADING_SINGLE_PRICE, PDF_HEADING_PRICE, '', $this->pdf_fonts_size, '', parent::GetY());
435
		}
436
		else
437
		{
438
			$t_sql = 'SELECT allow_tax FROM ' . TABLE_ORDERS_PRODUCTS . ' WHERE orders_id = "' . (int)$_GET['oID'] . '" LIMIT 1';
439
			$t_result = xtc_db_query($t_sql);
440
			$t_allow_tax = '1';
441

    
442
			if(xtc_db_num_rows($t_result) == 1)
443
			{
444
				$t_result_array = xtc_db_fetch_array($t_result);
445
				$t_allow_tax = $t_result_array['allow_tax'];
446
			}
447

    
448
			$y = $this->getCells(PDF_HEADING_MODEL, PDF_HEADING_ARTICLE_NAME, PDF_HEADING_UNIT, PDF_HEADING_NETTO_PRICE, ($t_allow_tax) ? PDF_HEADING_SINGLE_PRICE . PDF_HEADING_INCL : PDF_HEADING_SINGLE_PRICE . PDF_HEADING_EXCL, PDF_HEADING_PRICE, '', $this->pdf_fonts_size, '', parent::GetY());
449
		}
450

    
451
		// -> set draw color
452
		parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
453
		parent::SetLineWidth(0.1);
454
		parent::Line(parent::getLeftMargin(), $y, parent::getInnerWidth() + parent::getLeftMargin(), $y);
455

    
456
		parent::Ln(2);
457
		$y = $y + 2;
458
		
459
		/*
460
		 * -> order data
461
		 */
462
		foreach($this->order_data as $product)
463
		{
464
			// -> font face/style/size/color
465
			parent::getFont($this->pdf_fonts['ORDER']);
466

    
467
			$new_y = $this->is_newPage($product, $product['PRODUCTS_ATTRIBUTES'], $y);
468
			if(!empty($new_y))
469
			{
470
				$y = $new_y;
471
			}
472

    
473
			// -> font face/style/size/color
474
			parent::getFont($this->pdf_fonts['ORDER']);
475

    
476
			$y = $this->getCells($product['PRODUCTS_MODEL'], $product['PRODUCTS_NAME'], $product['PRODUCTS_QTY'] . ' ' . $product['PRODUCTS_UNIT'], $product['PRODUCTS_TAX'], $product['PRODUCTS_PRICE_SINGLE'], $product['PRODUCTS_PRICE'], '', $this->pdf_fonts_size, '0', $y);
477

    
478
			if(!empty($product['PRODUCTS_ATTRIBUTES']))
479
			{
480
				foreach($product['PRODUCTS_ATTRIBUTES'] as $attribute)
481
				{
482
					$y = $this->getCells($attribute[0], '- ' . $attribute[1], '', '', '', '', '', $this->pdf_fonts_size, '', $y);
483
				}
484
			}
485
		}
486

    
487
		/*
488
		 * -> order total data 
489
		 */
490
		if($this->pdf_type == 'invoice')
491
		{
492
			// -> font face/style/size/color
493
			parent::getFont($this->pdf_fonts['ORDER_TOTAL']);
494

    
495
			$get_y = $this->is_newPageOt($this->order_total, $y, 2, parent::getCellHeight(), $this->pdf_order_total_cell_width);
496

    
497
			if(!empty($get_y))
498
			{
499
				parent::SetY($get_y);
500
			}
501
			else
502
			{
503
				parent::SetY($y);
504
			}
505

    
506
			parent::SetX(parent::getLeftMargin());
507
			parent::MultiCell(parent::getInnerWidth(), 3, '', 'T', '', 0);
508

    
509
			$y = parent::GetY();
510

    
511
			foreach($this->order_total as $key => $value)
512
			{
513

    
514
				if(strpos_wrapper($value['TITLE'], '<b>') !== false)
515
				{
516
					$style = "B";
517
				}
518
				elseif(isset($style))
519
					unset($style);
520

    
521
				// -> font face/style/size/color
522
				parent::getFont($this->pdf_fonts['ORDER_TOTAL'], $style);
523

    
524
				parent::SetY($y);
525
				parent::SetX(parent::getLeftMargin());
526
				parent::MultiCell($this->pdf_order_total_cell_width[0], parent::getCellHeight(), trim(strip_tags($value['TITLE'])), '0', 'R', 0);
527

    
528
				$actual_y = $this->getActualY($y);
529

    
530
				parent::SetY($y);
531
				parent::SetX(parent::getLeftMargin() + $this->pdf_order_total_cell_width[0]);
532
				parent::MultiCell($this->pdf_order_total_cell_width[1], parent::getCellHeight(), trim(strip_tags($value['TEXT'])), '0', 'R', 0);
533

    
534
				$y = $this->getActualY($actual_y);
535
			}
536
		}
537

    
538

    
539
		/*
540
		 * -> order info data
541
		 */
542
		if(!empty($this->order_info))
543
		{
544

    
545
			// -> font face/style/size/color
546
			parent::getFont($this->pdf_fonts['ORDER_INFO']);
547

    
548
			$y = $this->is_newPageOi($this->order_info, parent::GetY(), (int)$this->pdf_order_info_margin_top, (parent::getCellHeight()) + 3, $this->pdf_order_info_cell_width);
549

    
550
			parent::SetY($y);
551

    
552
			// -> font face/style/size/color
553
			$this->getFontInDependencyOfTheContent($this->pdf_fonts['HEADING_ORDER_INFO'], $this->pdf_heading_info);
554

    
555
			parent::SetY($y);
556
			parent::SetX(parent::getLeftMargin());
557
			parent::MultiCell(parent::getInnerWidth(), parent::getCellHeight(), $this->pdf_heading_info, '0', 'L', 0);
558

    
559
			$this->getFontInDependencyOfTheContent($this->pdf_fonts['HEADING_ORDER_INFO'], '');
560

    
561
			parent::SetY(parent::GetY());
562
			parent::SetX(parent::getLeftMargin());
563
			parent::MultiCell(parent::getInnerWidth(), 3, '', 'T', '', 0);
564

    
565
			$y = parent::GetY();
566

    
567
			foreach($this->order_info as $key => $value)
568
			{
569
				// -> font face/style/size/color
570
				$this->getFontInDependencyOfTheContent($this->pdf_fonts['ORDER_INFO'], $value[0]);
571

    
572
				parent::SetY($y);
573
				parent::SetX(parent::getLeftMargin());
574
				parent::MultiCell($this->pdf_order_info_cell_width[0], parent::getCellHeight(), $value[0], '0', 'L', 0);
575

    
576
				$actual_y = $this->getActualY($y);
577

    
578
				$this->getFontInDependencyOfTheContent($this->pdf_fonts['ORDER_INFO'], $value[1]);
579

    
580
				parent::SetY($y);
581
				parent::SetX(parent::getLeftMargin() + $this->pdf_order_info_cell_width[0]);
582
				parent::MultiCell($this->pdf_order_info_cell_width[1], parent::getCellHeight(), $value[1], '0', 'L', 0);
583

    
584
				$y = $this->getActualY($actual_y);
585
			}
586
		}
587

    
588
		return;
589
	}
590

    
591
	/*
592
	 * 	-> to get a new page if previous is full
593
	 */
594
	function is_newPage($product, $attributes, $y)
595
	{
596

    
597
		if(($this->getMaxCellHeight($product, $attributes, $this->pdf_order_data_cell_width) + $y) > $this->pdf_footer_position - 5)
598
		{
599
			parent::AddPage();
600
			$this->getOrderHeader();
601
			$y = parent::GetY();
602

    
603
			// -> font face/style/size/color
604
			parent::getFont($this->pdf_fonts['HEADING_ORDER']);
605

    
606
			if($this->pdf_ot_gm_tax_free)
607
			{
608
				$y = $this->getCells(PDF_HEADING_MODEL, PDF_HEADING_ARTICLE_NAME, PDF_HEADING_UNIT, PDF_HEADING_NETTO_PRICE, PDF_HEADING_SINGLE_PRICE, PDF_HEADING_PRICE, '', $this->pdf_fonts_size, '', parent::GetY());
609
			}
610
			else
611
			{
612
				$t_sql = 'SELECT allow_tax FROM ' . TABLE_ORDERS_PRODUCTS . ' WHERE orders_id = "' . (int)$_GET['oID'] . '" LIMIT 1';
613
				$t_result = xtc_db_query($t_sql);
614
				$t_allow_tax = '1';
615

    
616
				if(xtc_db_num_rows($t_result) == 1)
617
				{
618
					$t_result_array = xtc_db_fetch_array($t_result);
619
					$t_allow_tax = $t_result_array['allow_tax'];
620
				}
621

    
622
				$y = $this->getCells(PDF_HEADING_MODEL, PDF_HEADING_ARTICLE_NAME, PDF_HEADING_UNIT, PDF_HEADING_NETTO_PRICE, ($t_allow_tax) ? PDF_HEADING_SINGLE_PRICE . PDF_HEADING_INCL : PDF_HEADING_SINGLE_PRICE . PDF_HEADING_EXCL, PDF_HEADING_PRICE, '', $this->pdf_fonts_size, '', parent::GetY());
623
			}
624

    
625
			// -> set draw color
626

    
627
			parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
628
			parent::SetLineWidth(0.1);
629
			parent::Line(parent::getLeftMargin(), $y, parent::getInnerWidth() + parent::getLeftMargin(), $y);
630
			parent::Ln(2);
631

    
632
			return ($y + 2);
633
		}
634

    
635
		return;
636
	}
637

    
638
	/*
639
	 * 	-> to get a new page if previous is full order_total and order_info
640
	 */
641
	function is_newPageOt($order, $y, $break, $extra, $table_size)
642
	{
643
		if(($this->getMaxHeight($order, $table_size) + $y + $break + $extra) >= ($this->h - parent::getPageBreak()))
644
		{
645
			parent::AddPage();
646
			$this->getOrderHeader();
647
			return parent::GetY();
648
		}
649
		else
650
		{
651
			parent::Ln($break);
652
			return;
653
		}
654
	}
655

    
656
	/*
657
	 * 	-> to get a new page if previous is full order_total and order_info
658
	 */
659
	function is_newPageOi($order, $y, $break, $extra, $table_size)
660
	{
661
		if(($this->getMaxHeight($order, $table_size) + $y + $break + $extra) >= ($this->h - parent::getPageBreak()))
662
		{
663
			parent::AddPage();
664
			$this->getOrderHeader();
665
		}
666
		else
667
		{
668
			parent::Ln($break);
669
		}
670
		
671
		return parent::GetY();
672
	}
673

    
674
	/*
675
	 * 	-> create Footer
676
	 */
677
	function getFooter()
678
	{
679
		// -> get footer cell width
680
		$footer_cell_width = parent::getInnerWidth() / count($this->pdf_footer);
681

    
682
		// -> font face/style/size/color
683
		parent::getFont($this->pdf_fonts['FOOTER']);
684

    
685
		// -> set draw color
686
		parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
687

    
688
		parent::SetLineWidth(0.1);
689

    
690
		parent::Line(parent::getLeftMargin(), parent::getFooterPos()+5, parent::getInnerWidth() + parent::getLeftMargin(), parent::getFooterPos()+5);
691

    
692
		for($i = 0; $i < count($this->pdf_footer); $i++)
693
		{
694
			parent::SetY(parent::getFooterPos() + 7);
695
			parent::SetX(parent::getLeftMargin() + ($footer_cell_width * $i));
696
			parent::MultiCell($footer_cell_width, parent::getCellHeight(), $this->pdf_footer[$i], '0', 'L', 0);
697
		}
698

    
699
		return;
700
	}
701

    
702
	/*
703
	 * 	-> get actual y position
704
	 */
705
	function getActualY($get_y)
706
	{
707
		$actual_y = parent::GetY();
708
		
709
		if($get_y < $actual_y)
710
		{
711
			$get_y = $actual_y;
712
		}
713
		
714
		return $get_y;
715
	}
716

    
717
	/*
718
	 * 	-> draw table for order
719
	 */
720
	function getCells($cell_1, $cell_2, $cell_3, $cell_4, $cell_5, $cell_6, $font_style = '', $font_size = '', $border = '', $y)
721
	{
722
		$this->AutoPageBreak = false;
723
		if($this->pdf_use_products_model)
724
		{
725
			$get_y = $this->getActualY($y);
726

    
727
			parent::SetY($y);
728
			parent::SetX(parent::getLeftMargin());			
729
			parent::MultiCell($this->pdf_order_data_cell_width[0], parent::getCellHeight(), $cell_1, $border, 'L', 0);
730
		}    
731

    
732
		if($y + parent::getCellHeight() > $this->pdf_footer_position - 5)
733
		{
734
			parent::AddPage();
735
			$this->getOrderHeader();
736
			
737
			if($this->pdf_ot_gm_tax_free)
738
			{
739
				$y = $this->getCells(PDF_HEADING_MODEL, PDF_HEADING_ARTICLE_NAME, PDF_HEADING_UNIT, PDF_HEADING_NETTO_PRICE, PDF_HEADING_SINGLE_PRICE, PDF_HEADING_PRICE, '', $this->pdf_fonts_size, '', parent::GetY());
740
			}
741
			else
742
			{
743
				$t_sql = 'SELECT allow_tax FROM ' . TABLE_ORDERS_PRODUCTS . ' WHERE orders_id = "' . (int)$_GET['oID'] . '" LIMIT 1';
744
				$t_result = xtc_db_query($t_sql);
745
				$t_allow_tax = '1';
746

    
747
				if(xtc_db_num_rows($t_result) == 1)
748
				{
749
					$t_result_array = xtc_db_fetch_array($t_result);
750
					$t_allow_tax = $t_result_array['allow_tax'];
751
				}
752

    
753
				$y = $this->getCells(PDF_HEADING_MODEL, PDF_HEADING_ARTICLE_NAME, PDF_HEADING_UNIT, PDF_HEADING_NETTO_PRICE, ($t_allow_tax) ? PDF_HEADING_SINGLE_PRICE . PDF_HEADING_INCL : PDF_HEADING_SINGLE_PRICE . PDF_HEADING_EXCL, PDF_HEADING_PRICE, '', $this->pdf_fonts_size, '', parent::GetY());
754
			}
755

    
756
			parent::getFont($this->pdf_fonts['ORDER']);
757

    
758
			// -> set draw color
759
			parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
760
			parent::SetLineWidth(0.1);
761
			parent::Line(parent::getLeftMargin(), $y, parent::getInnerWidth() + parent::getLeftMargin(), $y);
762

    
763
			parent::Ln(2);
764
			$y = $y + 2;
765
			$get_y = $y;
766
		}  
767
            
768
		$get_y = $this->getActualY($get_y);
769
		
770
		// Artikel
771
		parent::SetY($y);
772
		parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0]);
773
		parent::MultiCell($this->pdf_order_data_cell_width[1], parent::getCellHeight(), $cell_2, $border, 'L', 0);
774
               
775
		$get_y = $this->getActualY($get_y);
776
		
777
		// Menge	
778
		parent::SetY($y);
779
		parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0] + $this->pdf_order_data_cell_width[1]);
780
		parent::MultiCell($this->pdf_order_data_cell_width[2], parent::getCellHeight(), $cell_3, $border, 'C', 0);
781

    
782
		$get_y = $this->getActualY($get_y); 
783
		
784
		if($this->pdf_type == 'invoice')
785
		{
786

    
787
			if($this->pdf_show_tax)
788
			{
789

    
790
				parent::SetY($y);
791
				parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0] + $this->pdf_order_data_cell_width[1] + $this->pdf_order_data_cell_width[2]);
792
				parent::MultiCell($this->pdf_order_data_cell_width[3], parent::getCellHeight(), $cell_4, $border, 'R', 0);
793

    
794
				$get_y = $this->getActualY($get_y);
795

    
796
				parent::SetY($y);
797
				parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0] + $this->pdf_order_data_cell_width[1] + $this->pdf_order_data_cell_width[2] + $this->pdf_order_data_cell_width[3]);
798
				parent::MultiCell($this->pdf_order_data_cell_width[4], parent::getCellHeight(), $cell_5, $border, 'R', 0);
799

    
800
				$get_y = $this->getActualY($get_y);
801

    
802
				parent::SetY($y);
803
				parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0] + $this->pdf_order_data_cell_width[1] + $this->pdf_order_data_cell_width[2] + $this->pdf_order_data_cell_width[3] + $this->pdf_order_data_cell_width[4]);
804
				parent::MultiCell($this->pdf_order_data_cell_width[5], parent::getCellHeight(), $cell_6, $border, 'R', 0);
805

    
806
				$get_y = $this->getActualY($get_y);
807
			}
808
			else
809
			{
810

    
811
				parent::SetY($y);
812
				parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0] + $this->pdf_order_data_cell_width[1] + $this->pdf_order_data_cell_width[2]);
813
				parent::MultiCell($this->pdf_order_data_cell_width[4], parent::getCellHeight(), $cell_5, $border, 'R', 0);
814

    
815
				$get_y = $this->getActualY($get_y);
816

    
817
				parent::SetY($y);
818
				parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0] + $this->pdf_order_data_cell_width[1] + $this->pdf_order_data_cell_width[2] + $this->pdf_order_data_cell_width[4]);
819
				parent::MultiCell($this->pdf_order_data_cell_width[5], parent::getCellHeight(), $cell_6, $border, 'R', 0);
820

    
821
				$get_y = $this->getActualY($get_y);
822
			}
823
		} 
824
		
825
		$this->AutoPageBreak = true;
826
		    
827
		return $get_y;
828
	}
829

    
830
	/*
831
	 * 	-> get Logo
832
	 */
833
	function getLogo()
834
	{
835
		$logo_size = getimagesize($this->pdf_logo_path);
836

    
837
		$mm_x = $logo_size[0] / $this->k;
838
		$mm_y = $logo_size[1] / $this->k;
839

    
840
		if($mm_x > parent::getInnerWidth() / 2)
841
		{
842
			$size_factor = (parent::getInnerWidth() / 2 - 1) / $mm_x;
843
			$mm_x = parent::getInnerWidth() / 2 - 1;
844
			$mm_y *= $size_factor;
845
		}
846

    
847
		$pos_x = parent::getLeftMargin() + parent::getInnerWidth() - $mm_x;
848

    
849
		parent::Image($this->pdf_logo_path, $pos_x, parent::getTopMargin(), $mm_x, $mm_y, substr(strrchr($logo_size['mime'], '/'), 1), $this->pdf_link);
850

    
851
		parent::SetY(parent::getTopMargin() + $mm_y);
852
	}
853

    
854
	/*
855
	 * 	-> get position where body starts
856
	 */
857
	function getPos()
858
	{
859
		// -> if header used get last y position of the left & right part of it 
860
		if($this->pdf_use_header == 1)
861
		{
862
			if($this->pdf_last_header_pos_right > $this->pdf_last_header_pos_left)
863
			{
864
				return $this->pdf_last_header_pos_right;
865
			}
866
			else
867
			{
868
				return $this->pdf_last_header_pos_left;
869
			}
870

    
871
			// -> if header not used get the actual y position
872
		}
873
		else
874
		{
875
			return parent::GetY();
876
		}
877
	}
878

    
879
	/*
880
	 * 	-> get position of the page break 
881
	 */
882
	function getMaxCellHeight($product, $attributes, $table_size)
883
	{
884
		if(!empty($product))
885
		{
886
			$i = 0;
887

    
888
			foreach($product as $value)
889
			{
890
				$count = 0;
891

    
892
				if(parent::GetStringWidth($value) + 1 > $table_size[$i])
893
				{
894
					$count = $count + parent::countMaxHeight(parent::GetStringWidth($value) + 1, $table_size[$i]);
895
				}
896
				else if(parent::GetStringWidth($value) != 0)
897
				{
898
					$count++;
899
				}
900

    
901
				if($count_max < $count)
902
				{
903
					$count_max = $count;
904
				}
905

    
906
				$i++;
907
			}
908
		}
909

    
910
		if(!empty($attributes))
911
		{
912
			foreach($attributes as $attribute)
913
			{
914
				$count_attributes++;
915

    
916
				for($j = 0; $j < count($attribute); $j++)
917
				{
918

    
919
					$count = 0;
920
					$string_width = parent::GetStringWidth($attribute[$j]);
921
					if($string_width + 1 > $table_size[$j])
922
					{
923
						$count = $count + parent::countMaxHeight($string_width, $table_size[$j]);
924
					}
925
					if($string_width != 0)
926
					{
927
						$count++;
928
					}
929
					if($count_max_attributes < $count)
930
					{
931
						$count_max_attributes = $count;
932
					}
933
				}
934
			}
935
		}
936

    
937
		return(($count_max + $count_attributes + $count_max_attributes) * parent::getCellHeight());
938
	}
939

    
940
	/*
941
	 * 	-> get position of the page break 
942
	 */
943

    
944
	function getMaxHeight($order, $table_size)
945
	{
946
		$count = 0;
947
		
948
		foreach($order as $value)
949
		{
950
			$count++;
951
			
952
			foreach($value as $index => $text)
953
			{
954
				$exploded = explode(PHP_EOL, $text); 
955
				$count += count($exploded) - 1; // -1 cause the first line is already included in the $count
956
				
957
				foreach($exploded as $sentence)
958
				{
959
					$width = parent::GetStringWidth($sentence); 
960
					
961
					if($width > $table_size[$index])
962
					{
963
						$count += parent::countMaxHeight($width, $table_size[$index]);
964
					}
965
				}
966
			}
967
		}
968
		
969
		return($count * parent::getCellHeight());
970
	}
971

    
972
	function getMaxHeight_custom($order, $table_size)
973
	{
974
		foreach($order as $value)
975
		{
976
			$count++;
977
			
978
			for($j = 0; $j < count($value); $j++)
979
			{
980
				$string_width = parent::GetStringWidth($value[$j]);
981
				if($string_width + 1 > $table_size[$j])
982
				{
983
					//echo $table_size[$j] . " - " . $string_width . " - " . $value[$j] . "<br>";
984
					$count = $count + parent::countMaxHeight($string_width, $table_size[$j]);
985
				}
986
			}
987
		}
988
		
989
		return($count * parent::getCellHeight());
990
	}
991

    
992
	/*
993
	 * 	-> get the Conditions 
994
	 */
995
	function getConditions()
996
	{
997
		// -> font face/style/size/color
998
		parent::getFont($this->pdf_fonts['CONDITIONS']);
999

    
1000
		parent::SetY(parent::GetY() + 15);
1001

    
1002
		parent::SetX(parent::getLeftMargin());
1003

    
1004
		$t_top_margin = $this->tMargin;
1005
		$this->tMargin = parent::GetY();
1006
		
1007
		parent::MultiCell(parent::getInnerWidth(), parent::getCellHeight(), $this->pdf_conditions, 0, 'L', 0);
1008

    
1009
		$this->tMargin = $t_top_margin;
1010
		
1011
		return;
1012
	}
1013

    
1014
	/*
1015
	 * 	-> get the withdrawal 
1016
	 */
1017
	function getWithdrawal()
1018
	{
1019

    
1020
		// -> font face/style/size/color
1021
		$this->getFontInDependencyOfTheContent($this->pdf_fonts['CONDITIONS'], $this->pdf_withdrawal);
1022

    
1023
		parent::SetY(parent::GetY() + 15);
1024

    
1025
		parent::SetX(parent::getLeftMargin());
1026
		
1027
		$t_top_margin = $this->tMargin;
1028
		$this->tMargin = parent::GetY();
1029

    
1030
		parent::MultiCell(parent::getInnerWidth(), parent::getCellHeight(), $this->pdf_withdrawal, 0, 'L', 0);
1031

    
1032
		$this->tMargin = $t_top_margin;
1033
		
1034
		return;
1035
	}
1036

    
1037
	/*
1038
	 * 	-> check if ot_gm_tax_free is installed
1039
	 */
1040
	function is_ot_gm_tax_free()
1041
	{
1042
		$t_query = xtc_db_query("
1043
									SELECT
1044
										*
1045
									FROM
1046
										configuration
1047
									WHERE
1048
										configuration_value
1049
									LIKE
1050
										'%ot_gm_tax_free%'
1051
			");
1052

    
1053
		if(xtc_db_num_rows($t_query) > 0)
1054
		{
1055
			return true;
1056
		}
1057
		else
1058
		{
1059
			return false;
1060
		}
1061
	}
1062

    
1063
	/**
1064
	 * @param $p_value
1065
	 *
1066
	 * @return bool
1067
	 */
1068
	function isRealText($p_value)
1069
	{
1070
		$outcome = true;
1071

    
1072
		if(is_string($p_value) === false)
1073
		{
1074
			$outcome = false;
1075
		}
1076
		else
1077
		{
1078
			$value = trim($p_value);
1079
			if($value === '')
1080
			{
1081
				$outcome = false;
1082
			}
1083
		}
1084

    
1085
		return $outcome;
1086
	}
1087

    
1088

    
1089
	/**
1090
	 * @param $pdf_font
1091
	 * @param $content
1092
	 */
1093
	function getFontInDependencyOfTheContent($pdf_font, $content)
1094
	{
1095

    
1096
		if('u' === $pdf_font[1] && false === $this->isRealText($content))
1097
		{
1098
				$pdf_font[1] = '';
1099
		}
1100

    
1101
		parent::getFont($pdf_font);
1102
	}
1103
}
1104

    
1105
MainFactory::load_origin_class('gmOrderPDF');
    (1-1/1)