Projekt

Allgemein

Profil

GX-Bug #41647 » gmOrderPDF.php

/admin/gm/classes/ - Till Tepelmann, 02.04.2015 11:40

 
1
<?php
2
/* --------------------------------------------------------------
3
  gmOrderPDF.php 2014-07-30 gm
4
  Gambio GmbH
5
  http://www.gambio.de
6
  Copyright (c) 2014 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
		parent::getFont($this->pdf_fonts['COMPANY_RIGHT']);
297

    
298
        $actual_y = parent::GetY();
299
        $actual_y = $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
			parent::getFont($this->pdf_fonts['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
		parent::getFont($this->pdf_fonts['COMPANY_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
		parent::getFont($this->pdf_fonts['CUSTOMER']);
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
		parent::getFont($this->pdf_fonts['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::SetY($y);
381
		parent::SetX(parent::getLeftMargin() + parent::getInnerWidth() / 2);
382
		parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), PDF_PAGE . " " . parent::PageNo(), '0', 'R', 0);
383

    
384
		parent::Ln((int)$this->pdf_heading_margin_bottom);
385
	}
386

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

    
393
		$y = parent::GetY() + 15;
394

    
395
		// -> font face/style/size/color
396
		parent::getFont($this->pdf_fonts['HEADING_CONDITIONS']);
397

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

    
402
		parent::SetY($y);
403
		parent::SetX(parent::getLeftMargin() + parent::getInnerWidth() * 0.75);
404
		parent::MultiCell(parent::getInnerWidth() * 0.25, parent::getCellHeight(), PDF_PAGE . " " . parent::PageNo(), '0', 'R', 0);
405

    
406
		parent::SetY(parent::GetY());
407

    
408
		parent::SetX(parent::getLeftMargin());
409

    
410
		// -> set draw color
411
		parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
412

    
413
		parent::MultiCell(parent::getInnerWidth(), 3, '', 'T', '', 0);
414
	}
415

    
416
	/*
417
	 * 	-> create Body
418
	 */
419
	function getBody()
420
	{
421

    
422
		// -> font face/style/size/color
423
		parent::getFont($this->pdf_fonts['HEADING_ORDER']);
424

    
425
		/*
426
		 * -> order data table
427
		 */
428
		if($this->pdf_ot_gm_tax_free)
429
		{
430
			$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());
431
		}
432
		else
433
		{
434
			$t_sql = 'SELECT allow_tax FROM ' . TABLE_ORDERS_PRODUCTS . ' WHERE orders_id = "' . (int)$_GET['oID'] . '" LIMIT 1';
435
			$t_result = xtc_db_query($t_sql);
436
			$t_allow_tax = '1';
437

    
438
			if(xtc_db_num_rows($t_result) == 1)
439
			{
440
				$t_result_array = xtc_db_fetch_array($t_result);
441
				$t_allow_tax = $t_result_array['allow_tax'];
442
			}
443

    
444
			$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());
445
		}
446

    
447
		// -> set draw color
448
		parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
449
		parent::SetLineWidth(0.1);
450
		parent::Line(parent::getLeftMargin(), $y, parent::getInnerWidth() + parent::getLeftMargin(), $y);
451

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

    
463
			$new_y = $this->is_newPage($product, $product['PRODUCTS_ATTRIBUTES'], $y);
464
			if(!empty($new_y))
465
			{
466
				$y = $new_y;
467
			}
468

    
469
			// -> font face/style/size/color
470
			parent::getFont($this->pdf_fonts['ORDER']);
471

    
472
			$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);
473

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

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

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

    
493
			if(!empty($get_y))
494
			{
495
				parent::SetY($get_y);
496
			}
497
			else
498
			{
499
				parent::SetY($y);
500
			}
501

    
502
			parent::SetX(parent::getLeftMargin());
503
			parent::MultiCell(parent::getInnerWidth(), 3, '', 'T', '', 0);
504

    
505
			$y = parent::GetY();
506

    
507
			foreach($this->order_total as $key => $value)
508
			{
509

    
510
				if(strpos_wrapper($value['TITLE'], '<b>') !== false)
511
				{
512
					$style = "B";
513
				}
514
				elseif(isset($style))
515
					unset($style);
516

    
517
				// -> font face/style/size/color
518
				parent::getFont($this->pdf_fonts['ORDER_TOTAL'], $style);
519

    
520
				parent::SetY($y);
521
				parent::SetX(parent::getLeftMargin());
522
				parent::MultiCell($this->pdf_order_total_cell_width[0], parent::getCellHeight(), trim(strip_tags($value['TITLE'])), '0', 'R', 0);
523

    
524
				$actual_y = $this->getActualY($y);
525

    
526
				parent::SetY($y);
527
				parent::SetX(parent::getLeftMargin() + $this->pdf_order_total_cell_width[0]);
528
				parent::MultiCell($this->pdf_order_total_cell_width[1], parent::getCellHeight(), trim(strip_tags($value['TEXT'])), '0', 'R', 0);
529

    
530
				$y = $this->getActualY($actual_y);
531
			}
532
		}
533

    
534

    
535
		/*
536
		 * -> order info data
537
		 */
538
		if(!empty($this->order_info))
539
		{
540

    
541
			// -> font face/style/size/color
542
			parent::getFont($this->pdf_fonts['ORDER_INFO']);
543

    
544
			$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);
545

    
546
			parent::SetY($y);
547

    
548
			// -> font face/style/size/color
549
			parent::getFont($this->pdf_fonts['HEADING_ORDER_INFO']);
550

    
551
			parent::SetY($y);
552
			parent::SetX(parent::getLeftMargin());
553
			parent::MultiCell(parent::getInnerWidth(), parent::getCellHeight(), $this->pdf_heading_info, '0', 'L', 0);
554

    
555
			parent::SetY(parent::GetY());
556
			parent::SetX(parent::getLeftMargin());
557
			parent::MultiCell(parent::getInnerWidth(), 3, '', 'T', '', 0);
558

    
559
			$y = parent::GetY();
560

    
561
			foreach($this->order_info as $key => $value)
562
			{
563
				// -> font face/style/size/color
564
				parent::getFont($this->pdf_fonts['ORDER_INFO']);
565

    
566
				parent::SetY($y);
567
				parent::SetX(parent::getLeftMargin());
568
				parent::MultiCell($this->pdf_order_info_cell_width[0], parent::getCellHeight(), $value[0], '0', 'L', 0);
569

    
570
				$actual_y = $this->getActualY($y);
571

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

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

    
580
		return;
581
	}
582

    
583
	/*
584
	 * 	-> to get a new page if previous is full
585
	 */
586
	function is_newPage($product, $attributes, $y)
587
	{
588

    
589
		if(($this->getMaxCellHeight($product, $attributes, $this->pdf_order_data_cell_width) + $y) > $this->pdf_footer_position - 5)
590
		{
591
			parent::AddPage();
592
			$this->getOrderHeader();
593
			$y = parent::GetY();
594

    
595
			// -> font face/style/size/color
596
			parent::getFont($this->pdf_fonts['HEADING_ORDER']);
597

    
598
			if($this->pdf_ot_gm_tax_free)
599
			{
600
				$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());
601
			}
602
			else
603
			{
604
				$t_sql = 'SELECT allow_tax FROM ' . TABLE_ORDERS_PRODUCTS . ' WHERE orders_id = "' . (int)$_GET['oID'] . '" LIMIT 1';
605
				$t_result = xtc_db_query($t_sql);
606
				$t_allow_tax = '1';
607

    
608
				if(xtc_db_num_rows($t_result) == 1)
609
				{
610
					$t_result_array = xtc_db_fetch_array($t_result);
611
					$t_allow_tax = $t_result_array['allow_tax'];
612
				}
613

    
614
				$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());
615
			}
616

    
617
			// -> set draw color
618

    
619
			parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
620
			parent::SetLineWidth(0.1);
621
			parent::Line(parent::getLeftMargin(), $y, parent::getInnerWidth() + parent::getLeftMargin(), $y);
622
			parent::Ln(2);
623

    
624
			return ($y + 2);
625
		}
626

    
627
		return;
628
	}
629

    
630
	/*
631
	 * 	-> to get a new page if previous is full order_total and order_info
632
	 */
633
	function is_newPageOt($order, $y, $break, $extra, $table_size)
634
	{
635
		if(($this->getMaxHeight($order, $table_size) + $y + $break + $extra) >= ($this->h - parent::getPageBreak()))
636
		{
637
			parent::AddPage();
638
			$this->getOrderHeader();
639
			return parent::GetY();
640
		}
641
		else
642
		{
643
			parent::Ln($break);
644
			return;
645
		}
646
	}
647

    
648
	/*
649
	 * 	-> to get a new page if previous is full order_total and order_info
650
	 */
651
	function is_newPageOi($order, $y, $break, $extra, $table_size)
652
	{
653
		if(($this->getMaxHeight($order, $table_size) + $y + $break + $extra) >= ($this->h - parent::getPageBreak()))
654
		{
655
			parent::AddPage();
656
			$this->getOrderHeader();
657
		}
658
		else
659
		{
660
			parent::Ln($break);
661
		}
662
		
663
		return parent::GetY();
664
	}
665

    
666
	/*
667
	 * 	-> create Footer
668
	 */
669
	function getFooter()
670
	{
671
		// -> get footer cell width
672
		$footer_cell_width = parent::getInnerWidth() / count($this->pdf_footer);
673

    
674
		// -> font face/style/size/color
675
		parent::getFont($this->pdf_fonts['FOOTER']);
676

    
677
		// -> set draw color
678
		parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
679

    
680
		parent::SetLineWidth(0.1);
681

    
682
		parent::Line(parent::getLeftMargin(), parent::getFooterPos(), parent::getInnerWidth() + parent::getLeftMargin(), parent::getFooterPos());
683

    
684
		for($i = 0; $i < count($this->pdf_footer); $i++)
685
		{
686
			parent::SetY(parent::getFooterPos() + 2);
687
			parent::SetX(parent::getLeftMargin() + ($footer_cell_width * $i));
688
			parent::MultiCell($footer_cell_width, parent::getCellHeight(), $this->pdf_footer[$i], '0', 'L', 0);
689
		}
690

    
691
		return;
692
	}
693

    
694
	/*
695
	 * 	-> get actual y position
696
	 */
697
	function getActualY($get_y)
698
	{
699
		$actual_y = parent::GetY();
700
		
701
		if($get_y < $actual_y)
702
		{
703
			$get_y = $actual_y;
704
		}
705
		
706
		return $get_y;
707
	}
708

    
709
	/*
710
	 * 	-> draw table for order
711
	 */
712
	function getCells($cell_1, $cell_2, $cell_3, $cell_4, $cell_5, $cell_6, $font_style = '', $font_size = '', $border = '', $y)
713
	{
714
		if($this->pdf_use_products_model)
715
		{
716
			$get_y = $this->getActualY($y);
717

    
718
			parent::SetY($y);
719
			parent::SetX(parent::getLeftMargin());
720
			parent::MultiCell($this->pdf_order_data_cell_width[0], parent::getCellHeight(), $cell_1, $border, 'L', 0);
721
		}
722

    
723
		if($y + parent::getCellHeight() > $this->pdf_footer_position - 5)
724
		{
725
			parent::AddPage();
726
			$this->getOrderHeader();
727
			
728
			if($this->pdf_ot_gm_tax_free)
729
			{
730
				$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());
731
			}
732
			else
733
			{
734
				$t_sql = 'SELECT allow_tax FROM ' . TABLE_ORDERS_PRODUCTS . ' WHERE orders_id = "' . (int)$_GET['oID'] . '" LIMIT 1';
735
				$t_result = xtc_db_query($t_sql);
736
				$t_allow_tax = '1';
737

    
738
				if(xtc_db_num_rows($t_result) == 1)
739
				{
740
					$t_result_array = xtc_db_fetch_array($t_result);
741
					$t_allow_tax = $t_result_array['allow_tax'];
742
				}
743

    
744
				$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());
745
			}
746

    
747
			parent::getFont($this->pdf_fonts['ORDER']);
748
			
749
			// -> set draw color
750
			parent::SetDrawColor((int)$this->pdf_draw_color['r'], (int)$this->pdf_draw_color['g'], (int)$this->pdf_draw_color['b']);
751
			parent::SetLineWidth(0.1);
752
			parent::Line(parent::getLeftMargin(), $y, parent::getInnerWidth() + parent::getLeftMargin(), $y);
753

    
754
			parent::Ln(2);
755
			$y = $y + 2;
756
			$get_y = $y;
757
		}
758

    
759
		$get_y = $this->getActualY($get_y);
760
		
761
		parent::SetY($y);
762
		parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0]);
763
		parent::MultiCell($this->pdf_order_data_cell_width[1], parent::getCellHeight(), $cell_2, $border, 'L', 0);
764

    
765
		$get_y = $this->getActualY($get_y);
766

    
767
		parent::SetY($y);
768
		parent::SetX(parent::getLeftMargin() + $this->pdf_order_data_cell_width[0] + $this->pdf_order_data_cell_width[1]);
769
		parent::MultiCell($this->pdf_order_data_cell_width[2], parent::getCellHeight(), $cell_3, $border, 'C', 0);
770

    
771
		$get_y = $this->getActualY($get_y);
772

    
773
		if($this->pdf_type == 'invoice')
774
		{
775

    
776
			if($this->pdf_show_tax)
777
			{
778

    
779
				parent::SetY($y);
780
				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]);
781
				parent::MultiCell($this->pdf_order_data_cell_width[3], parent::getCellHeight(), $cell_4, $border, 'R', 0);
782

    
783
				$get_y = $this->getActualY($get_y);
784

    
785
				parent::SetY($y);
786
				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]);
787
				parent::MultiCell($this->pdf_order_data_cell_width[4], parent::getCellHeight(), $cell_5, $border, 'R', 0);
788

    
789
				$get_y = $this->getActualY($get_y);
790

    
791
				parent::SetY($y);
792
				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]);
793
				parent::MultiCell($this->pdf_order_data_cell_width[5], parent::getCellHeight(), $cell_6, $border, 'R', 0);
794

    
795
				$get_y = $this->getActualY($get_y);
796
			}
797
			else
798
			{
799

    
800
				parent::SetY($y);
801
				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]);
802
				parent::MultiCell($this->pdf_order_data_cell_width[4], parent::getCellHeight(), $cell_5, $border, 'R', 0);
803

    
804
				$get_y = $this->getActualY($get_y);
805

    
806
				parent::SetY($y);
807
				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]);
808
				parent::MultiCell($this->pdf_order_data_cell_width[5], parent::getCellHeight(), $cell_6, $border, 'R', 0);
809

    
810
				$get_y = $this->getActualY($get_y);
811
			}
812
		}
813

    
814
		return $get_y;
815
	}
816

    
817
	/*
818
	 * 	-> get Logo
819
	 */
820
	function getLogo()
821
	{
822
		$logo_size = getimagesize($this->pdf_logo_path);
823

    
824
		$mm_x = $logo_size[0] / $this->k;
825
		$mm_y = $logo_size[1] / $this->k;
826

    
827
		if($mm_x > parent::getInnerWidth() / 2)
828
		{
829
			$size_factor = (parent::getInnerWidth() / 2 - 1) / $mm_x;
830
			$mm_x = parent::getInnerWidth() / 2 - 1;
831
			$mm_y *= $size_factor;
832
		}
833

    
834
		$pos_x = parent::getLeftMargin() + parent::getInnerWidth() - $mm_x;
835

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

    
838
		parent::SetY(parent::getTopMargin() + $mm_y);
839
	}
840

    
841
	/*
842
	 * 	-> get position where body starts
843
	 */
844
	function getPos()
845
	{
846
		// -> if header used get last y position of the left & right part of it 
847
		if($this->pdf_use_header == 1)
848
		{
849
			if($this->pdf_last_header_pos_right > $this->pdf_last_header_pos_left)
850
			{
851
				return $this->pdf_last_header_pos_right;
852
			}
853
			else
854
			{
855
				return $this->pdf_last_header_pos_left;
856
			}
857

    
858
			// -> if header not used get the actual y position
859
		}
860
		else
861
		{
862
			return parent::GetY();
863
		}
864
	}
865

    
866
	/*
867
	 * 	-> get position of the page break 
868
	 */
869
	function getMaxCellHeight($product, $attributes, $table_size)
870
	{
871
		if(!empty($product))
872
		{
873
			$i = 0;
874

    
875
			foreach($product as $value)
876
			{
877
				$count = 0;
878

    
879
				if(parent::GetStringWidth($value) + 1 > $table_size[$i])
880
				{
881
					$count = $count + parent::countMaxHeight(parent::GetStringWidth($value) + 1, $table_size[$i]);
882
				}
883
				else if(parent::GetStringWidth($value) != 0)
884
				{
885
					$count++;
886
				}
887

    
888
				if($count_max < $count)
889
				{
890
					$count_max = $count;
891
				}
892

    
893
				$i++;
894
			}
895
		}
896

    
897
		if(!empty($attributes))
898
		{
899
			foreach($attributes as $attribute)
900
			{
901
				$count_attributes++;
902

    
903
				for($j = 0; $j < count($attribute); $j++)
904
				{
905

    
906
					$count = 0;
907
					$string_width = parent::GetStringWidth($attribute[$j]);
908
					if($string_width + 1 > $table_size[$j])
909
					{
910
						$count = $count + parent::countMaxHeight($string_width, $table_size[$j]);
911
					}
912
					if($string_width != 0)
913
					{
914
						$count++;
915
					}
916
					if($count_max_attributes < $count)
917
					{
918
						$count_max_attributes = $count;
919
					}
920
				}
921
			}
922
		}
923

    
924
		return(($count_max + $count_attributes + $count_max_attributes) * parent::getCellHeight());
925
	}
926

    
927
	/*
928
	 * 	-> get position of the page break 
929
	 */
930
	function getMaxHeight($order, $table_size)
931
	{
932
		foreach($order as $value)
933
		{
934
			$count++;
935
			
936
			for($j = 0; $j < count($value); $j++)
937
			{
938
				$string_width = parent::GetStringWidth($value[$j]);
939
				if($string_width + 1 > $table_size[$j])
940
				{
941
					//echo $table_size[$j] . " - " . $string_width . " - " . $value[$j] . "<br>";
942
					$count = $count + parent::countMaxHeight($string_width, $table_size[$j]);
943
				}
944
			}
945
		}
946
		
947
		return($count * parent::getCellHeight());
948
	}
949

    
950
	/*
951
	 * 	-> get the Conditions 
952
	 */
953
	function getConditions()
954
	{
955
		// -> font face/style/size/color
956
		parent::getFont($this->pdf_fonts['CONDITIONS']);
957

    
958
		parent::SetY(parent::GetY() + 15);
959

    
960
		parent::SetX(parent::getLeftMargin());
961

    
962
		$t_top_margin = $this->tMargin;
963
		$this->tMargin = parent::GetY();
964
		
965
		parent::MultiCell(parent::getInnerWidth(), parent::getCellHeight(), $this->pdf_conditions, 0, 'L', 0);
966

    
967
		$this->tMargin = $t_top_margin;
968
		
969
		return;
970
	}
971

    
972
	/*
973
	 * 	-> get the withdrawal 
974
	 */
975
	function getWithdrawal()
976
	{
977

    
978
		// -> font face/style/size/color
979
		parent::getFont($this->pdf_fonts['CONDITIONS']);
980

    
981
		parent::SetY(parent::GetY() + 15);
982

    
983
		parent::SetX(parent::getLeftMargin());
984
		
985
		$t_top_margin = $this->tMargin;
986
		$this->tMargin = parent::GetY();
987

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

    
990
		$this->tMargin = $t_top_margin;
991
		
992
		return;
993
	}
994

    
995
	/*
996
	 * 	-> check if ot_gm_tax_free is installed
997
	 */
998
	function is_ot_gm_tax_free()
999
	{
1000
		$t_query = xtc_db_query("
1001
									SELECT
1002
										*
1003
									FROM
1004
										configuration
1005
									WHERE
1006
										configuration_value
1007
									LIKE
1008
										'%ot_gm_tax_free%'
1009
			");
1010

    
1011
		if(xtc_db_num_rows($t_query) > 0)
1012
		{
1013
			return true;
1014
		}
1015
		else
1016
		{
1017
			return false;
1018
		}
1019
	}
1020
}
1021

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