Projekt

Allgemein

Profil

GX-Bug #41640 » gmOrderPDF.php

/admin/gm/classes/ - Till Tepelmann, 15.04.2015 10:56

 
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
		
300
		if($actual_y < 10)
301
		{
302
			$actual_y = 10;
303
		}
304
		
305
		parent::SetY($actual_y);
306
		parent::SetX(parent::getInnerWidth() / 2 + parent::getLeftMargin());
307
		parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), $this->pdf_company_adress_right, '0', 'R', 0);
308

    
309
		// -> STORNO
310
		if(!empty($this->pdf_cancel))
311
		{
312
			parent::getFont($this->pdf_fonts['CANCEL']);
313

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

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

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

    
328
		// -> font face/style/size/color
329
		parent::getFont($this->pdf_fonts['COMPANY_LEFT']);
330

    
331
		parent::SetY($this->pdf_customer_adr_pos);
332
		parent::SetX(parent::GetX());
333

    
334
        if(!empty($this->pdf_company_adress_left)) {
335
            parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), $this->pdf_company_adress_left, '0', 'L', 0);
336
        }
337

    
338
		// -> font face/style/size/color
339
		parent::getFont($this->pdf_fonts['CUSTOMER']);
340

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

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

    
348
		return;
349
	}
350

    
351
	/*
352
	 * 	-> create Body
353
	 */
354
	function getOrderHeader()
355
	{
356

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

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

    
373
		$y = parent::GetY();
374

    
375
		// -> font face/style/size/color
376
		parent::getFont($this->pdf_fonts['HEADING']);
377

    
378
		parent::SetY($y);
379
		parent::SetX(parent::getLeftMargin());
380
		parent::MultiCell(parent::getInnerWidth() / 2, parent::getCellHeight(), $this->pdf_heading, '0', 'L', 0);
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
		parent::getFont($this->pdf_fonts['HEADING_CONDITIONS']);
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::SetY($y);
405
		parent::SetX(parent::getLeftMargin() + parent::getInnerWidth() * 0.75);
406
		parent::MultiCell(parent::getInnerWidth() * 0.25, parent::getCellHeight(), PDF_PAGE . " " . parent::PageNo(), '0', 'R', 0);
407

    
408
		parent::SetY(parent::GetY());
409

    
410
		parent::SetX(parent::getLeftMargin());
411

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

    
415
		parent::MultiCell(parent::getInnerWidth(), 3, '', 'T', '', 0);
416
	}
417

    
418
	/*
419
	 * 	-> create Body
420
	 */
421
	function getBody()
422
	{
423

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

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

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

    
446
			$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());
447
		}
448

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

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

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

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

    
474
			$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);
475

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

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

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

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

    
504
			parent::SetX(parent::getLeftMargin());
505
			parent::MultiCell(parent::getInnerWidth(), 3, '', 'T', '', 0);
506

    
507
			$y = parent::GetY();
508

    
509
			foreach($this->order_total as $key => $value)
510
			{
511

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

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

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

    
526
				$actual_y = $this->getActualY($y);
527

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

    
532
				$y = $this->getActualY($actual_y);
533
			}
534
		}
535

    
536

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

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

    
546
			$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);
547

    
548
			parent::SetY($y);
549

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

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

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

    
561
			$y = parent::GetY();
562

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

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

    
572
				$actual_y = $this->getActualY($y);
573

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

    
578
				$y = $this->getActualY($actual_y);
579
			}
580
		}
581

    
582
		return;
583
	}
584

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

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

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

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

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

    
616
				$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());
617
			}
618

    
619
			// -> set draw color
620

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

    
626
			return ($y + 2);
627
		}
628

    
629
		return;
630
	}
631

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

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

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

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

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

    
682
		parent::SetLineWidth(0.1);
683

    
684
		parent::Line(parent::getLeftMargin(), parent::getFooterPos(), parent::getInnerWidth() + parent::getLeftMargin(), parent::getFooterPos());
685

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

    
693
		return;
694
	}
695

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

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

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

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

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

    
746
				$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());
747
			}
748

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

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

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

    
767
		$get_y = $this->getActualY($get_y);
768

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

    
773
		$get_y = $this->getActualY($get_y);
774

    
775
		if($this->pdf_type == 'invoice')
776
		{
777

    
778
			if($this->pdf_show_tax)
779
			{
780

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

    
785
				$get_y = $this->getActualY($get_y);
786

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

    
791
				$get_y = $this->getActualY($get_y);
792

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

    
797
				$get_y = $this->getActualY($get_y);
798
			}
799
			else
800
			{
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]);
804
				parent::MultiCell($this->pdf_order_data_cell_width[4], parent::getCellHeight(), $cell_5, $border, 'R', 0);
805

    
806
				$get_y = $this->getActualY($get_y);
807

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

    
812
				$get_y = $this->getActualY($get_y);
813
			}
814
		}
815

    
816
		return $get_y;
817
	}
818

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

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

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

    
836
		$pos_x = parent::getLeftMargin() + parent::getInnerWidth() - $mm_x;
837

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

    
840
		parent::SetY(parent::getTopMargin() + $mm_y);
841
	}
842

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

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

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

    
877
			foreach($product as $value)
878
			{
879
				$count = 0;
880

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

    
890
				if($count_max < $count)
891
				{
892
					$count_max = $count;
893
				}
894

    
895
				$i++;
896
			}
897
		}
898

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

    
905
				for($j = 0; $j < count($attribute); $j++)
906
				{
907

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

    
926
		return(($count_max + $count_attributes + $count_max_attributes) * parent::getCellHeight());
927
	}
928

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

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

    
960
		parent::SetY(parent::GetY() + 15);
961

    
962
		parent::SetX(parent::getLeftMargin());
963

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

    
969
		$this->tMargin = $t_top_margin;
970
		
971
		return;
972
	}
973

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

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

    
983
		parent::SetY(parent::GetY() + 15);
984

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

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

    
992
		$this->tMargin = $t_top_margin;
993
		
994
		return;
995
	}
996

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

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

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