Subversion Repositories wpShopGermany4

Rev

Rev 7753 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2975 daniel 1
<?php
2
 
3
	/**
4004 thomas 4
	 * FPDF Template für die Generierung des Lieferscheins
2975 daniel 5
	 */
7352 daniel 6
 
7
	require_once WPSG_PATH_LIB.'FPDF_1.81/fpdf.php';
8
	require_once WPSG_PATH_LIB.'FPDI_2.2.0/autoload.php';
3560 daniel 9
	require_once WPSG_PATH_LIB.'wpsg_fpdf.class.php';
2975 daniel 10
 
11
	global $absender_left, $absender_top, $adress_left, $adress_top, $dndata_left, $dndata_top;
12
 
3827 daniel 13
	if (!function_exists('AddDeliverynotePage'))
2975 daniel 14
	{
15
 
16
		function AddDeliverynotePage($shop, $pdf)
17
		{
18
 
19
			global $absender_left, $absender_top, $adress_left, $adress_top, $dndata_left, $dndata_top;
20
 
6066 hartmut 21
			$rdata_left = 0;
2975 daniel 22
			$pdf->AddPage();
23
 
6066 hartmut 24
			if (file_exists($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_bp.pdf"))
2975 daniel 25
			{
26
 
6066 hartmut 27
				$pagecount = $pdf->setSourceFile($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_bp.pdf");
2975 daniel 28
				$tplidx = $pdf->importPage(1, '/MediaBox');
29
				$pdf->useTemplate($tplidx, 0, 0, 210);
30
 
31
			}
6066 hartmut 32
			else if (file_exists($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_bp.jpg"))
2975 daniel 33
			{
34
 
6066 hartmut 35
				$pdf->image($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_bp.jpg", 0, 0, 210, 297, 'jpg');
2975 daniel 36
 
37
			}
7094 florian 38
 
39
 
6066 hartmut 40
			if (file_exists($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_logo.jpg"))
2975 daniel 41
			{
7094 florian 42
 
6066 hartmut 43
				list($width, $height, $type, $attr) = getimagesize($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_logo.jpg");
7094 florian 44
 
45
				// Umrechnung von Inch zu Pixel
2975 daniel 46
				$wPix = (25.4 * $width) / 96;
47
				$hPix = (25.4 * $height) / 96;
7094 florian 48
 
49
				$leftPos = 110 - $wPix;
50
				$midPos = $wPix * 2.6 - $width / 2;
51
				$rightPos = 210 - $wPix;
52
 
53
				$abscissa = $rightPos;
54
				$ordinate = 0;
55
 
56
				$transparency = str_replace("%", "", $shop->get_option('wpsg_mod_deliverynote_logo_transparency'));
57
				if($transparency !== "100") $transparency = str_replace(array("0", "00"), "", $transparency);
58
 
59
				$alpha = 1;
60
				if(!is_null($transparency) && $transparency !== "100") $alpha = "0.$transparency";
61
				if(!is_null($transparency) && $transparency === "100") $alpha = $transparency;
62
 
63
				$logo_pos = $shop->get_option('wpsg_mod_deliverynote_logo_position');
64
 
65
				if(isset($logo_pos) && $logo_pos === "left") { $abscissa = $leftPos; $ordinate = 20; }
66
				if(isset($logo_pos) && $logo_pos === "center") { $abscissa = $midPos; $ordinate = 20; }
67
				if(isset($logo_pos) && $logo_pos === "right") { $abscissa = $rightPos; }
68
 
69
				$pdf->SetAlpha($alpha);
70
				$pdf->image($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_logo.jpg", $abscissa, $ordinate, $wPix, $hPix);
71
				$pdf->SetAlpha(1);
72
 
2975 daniel 73
			}
74
 
75
			// Absenderadresszeile (Wird in der Konfiguration hinterlegt)
76
			$pdf->SetFont('Arial', '', 6);
4286 daniel 77
			$pdf->Text($absender_left, $absender_top, $shop->replaceUniversalPlatzhalter($shop->get_option("wpsg_mod_deliverynote_adressrow"), $shop->view['order']['id']));
2975 daniel 78
 
6066 hartmut 79
			if (wpsg_getStr($shop->view['kunde']['kuerzel']) != "") $shop->view['kunde']['kuerzel'] = $shop->view['kunde']['kuerzel'].'-';
7332 daniel 80
 
2975 daniel 81
			// Adresse des Kunden
82
			$pdf->SetFont('Arial', '', 12);
83
			$pdf->Text($adress_left, $adress_top, $shop->view['data']['firma']);
84
			$pdf->Text($adress_left, $adress_top + 5, $shop->view['data']['vname'].' '.$shop->view['data']['name']);
7247 daniel 85
			$pdf->Text($adress_left, $adress_top + 10, $shop->view['data']['strasse'].' '.$shop->view['data']['nr']);
3742 daniel 86
			$pdf->Text($adress_left, $adress_top + 15, $shop->view['data']['plz'].' '.$shop->view['data']['ort']);
6364 hartmut 87
			//if ($shop->get_option('wpsg_mod_deliverynote_hideCountry') != '1') $pdf->Text($adress_left, $adress_top + 20, strtoupper($shop->view['oOrder']->getShippingCountryName()));
88
			if ($shop->get_option('wpsg_mod_deliverynote_hideCountry') != '1') $pdf->Text($adress_left, $adress_top + 20, $shop->view['data']['land']);
3742 daniel 89
 
2975 daniel 90
			// Lieferscheindaten
91
			$pdf->SetFont('Arial', 'B', 16);
92
			$pdf->Text($dndata_left, $dndata_top, $shop->view['title']);
93
			$pdf->SetFont('Arial', 'B', 9);
94
			$pdf->Text($dndata_left, $dndata_top + 6, $shop->view['lnr']);
95
			$pdf->SetFont('Arial', '', 9);
96
 
97
			$pdf->Text($rdata_left + 100, $dndata_top, __("Kunden-Nr", "wpsg"));
98
			$pdf->Text($rdata_left + 100, $dndata_top + 6, (($shop->view['customer']['knr'] != '')?$shop->view['customer']['knr']:$shop->view['customer']['id']));
99
 
100
			$pdf->Text($rdata_left + 125, $dndata_top, __("Best. Nr.", "wpsg"));
101
			$pdf->Text($rdata_left + 125, $dndata_top + 6, ((trim($shop->view['order']['onr']) != '')?$shop->view['order']['onr']:$shop->view['order']['id']));
102
 
103
			$pdf->Text($rdata_left + 145, $dndata_top, __("Bestelldatum", "wpsg"));
3013 daniel 104
			$pdf->Text($rdata_left + 145, $dndata_top + 6, wpsg_formatTimestamp(strtotime($shop->view['order']['cdate']), true));
2975 daniel 105
 
106
			$pdf->Text($rdata_left + 170, $dndata_top, __("Lieferdatum", "wpsg"));
107
			$pdf->Text($rdata_left + 170, $dndata_top + 6, wpsg_formatTimestamp($shop->view['lDatum'], true));
108
 
3506 daniel 109
			if ($shop->view['oOrder']->isInnerEu())
110
			{
7153 thomas 111
 
112
            	$pdf->SetFont('Arial', '', 9);
113
                $pdf->Text($adress_left, $rdata_top + 11.5, __("Innergemeinschaftliche Lieferung.", "wpsg"));
114
 
115
            } else if (!$shop->view['oOrder']->isInnerEu() && $shop->view['oOrder']->getShippingCountryID() != $shop->getDefaultCountry(true)) {
116
 
117
			// Nicht InnerEU und Nicht Inland
118
 
119
             	$pdf->SetFont('Arial', '', 9);
120
                $pdf->Text($adress_left, $rdata_top + 11.5, __("Steuerfreie Ausfuhrlieferung.", "wpsg"));
121
 
3506 daniel 122
			}
7709 daniel 123
 
2975 daniel 124
			// Benutzerdefinierte Felder
7709 daniel 125
			$arTexte = $shop->callMod('wpsg_mod_deliverynote', 'getTexte', array($shop->view['order']['id']));
2975 daniel 126
 
127
			foreach ((array)$arTexte as $text)
128
			{
129
 
130
				if (isset($text['aktiv']) && $text['aktiv'] == 1)
131
				{
132
 
133
					$pdf->SetFont('Arial', 'B', ((intval($text['fontsize']) > 0)?intval($text['fontsize']):10));
5382 daniel 134
					$pdf->wpsg_SetTextColor($text['color']);
135
					$pdf->wpsg_MultiCell($text['x'], $text['y'], 5, $text['text']);
136
					$pdf->wpsg_SetTextColor("#000000");
2975 daniel 137
 
138
				}
139
 
140
			}
141
 
142
		}
143
 
144
	}
145
 
146
	// Positionierung der Absenderadresszeile
147
	$absender_left				= 25;
148
	$absender_top				= 50;
149
 
150
	// Positionierung der Zieladress
151
	$adress_left 				= 25;
152
	$adress_top					= 55;
153
 
154
	// Positionierund des Lieferscheinkopfes
155
	$dndata_left				= 25;
156
	$dndata_top					= 90;
157
 
158
	// Positionierung der Produktdaten
159
	$prod_left					= 25;
160
	$prod_top					= 105;
161
 
162
	// Anzahl an Produkten pro Seite
163
	$prod_break					= 10;
164
 
165
	$pdf = new wpsg_fpdf();
166
	$pdf->SetAutoPageBreak(true, 5);
167
	AddDeliverynotePage($this, $pdf);
168
 
169
	$filename = $this->view['filename'].".pdf";
170
 
171
	$bKopf = false; $pnr = 1; $offset = 0; $count = 0;
172
	foreach ($this->view['data']['products'] as $p)
173
	{
3417 daniel 174
 
7919 daniel 175
		if (!is_array($p)) continue;
176
 
3417 daniel 177
		$product_data = $this->loadProduktArray($this->getProduktID($p['p_id']));
178
 
2975 daniel 179
		if (!$bKopf)
180
		{
181
 
182
			$pdf->SetFont('Arial', 'B', 9);
183
			$pdf->setXY($prod_left, $prod_top);
184
			$pdf->Cell(10, 8, __("Nr.", "wpsg"), 1, 0, 'C');
185
 
186
			$pdf->setXY($prod_left + 10, $prod_top);
187
			$pdf->Cell(137, 8, "Name", 1, 0, 'L');
188
 
189
			$pdf->setXY($prod_left + 147, $prod_top);
190
			$pdf->Cell(15, 8, __("Menge", "wpsg"), 1, 0, 'C');
191
 
192
			$offset = 8;
193
			$bKopf = true;
194
 
195
		}
3417 daniel 196
 
197
		/*
6165 hartmut 198
		if ($this->hasMod('wpsg_mod_productvariants') && isset($p['mod_vp_varkey']))
3417 daniel 199
		{
2975 daniel 200
 
6165 hartmut 201
			$variante = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($p['mod_vp_varkey']));
3417 daniel 202
			$anr = $variante['akey'];
203
 
204
		}
205
		else
206
		{
207
 
208
			$anr = $product_data['anr'];
209
 
210
		}*/
211
 
212
		$pdf->SetFont('Arial', '', 9);
2975 daniel 213
		$pdf->setXY($prod_left, $prod_top + $offset);
214
 
3748 daniel 215
		if ($this->get_option('wpsg_mod_deliverynote_anr') === '1')
216
		{
217
 
218
			$anr = $this->getProductAnr($p['productkey']);
219
			$pdf->Cell(10, 8, $anr, 0, 0, 'C'); /* Artikelnummer anzeigen */
220
 
221
		}
222
		else
223
		{
224
 
225
			$pdf->Cell(10, 8, $pnr.".", 0, 0, 'C');
226
 
227
		}
4909 thomas 228
 
7021 thomas 229
		/* Wenn Detailname vorhanden, wird der Detailname auf dem Lieferschein verwendet*/
4909 thomas 230
		$produkt_text = $this->getProductName($this->getProduktID($p['p_id']), true);
7021 thomas 231
 
232
		/* Wenn Detailname nicht vorhanden, wird der Name auf dem Lieferschein verwendet*/
233
		$produkt_text = $this->getProductName($this->getProduktID($p['p_id']), false);
234
 
2975 daniel 235
		$produktBeschreibung = trim(strip_tags($p['beschreibung']));
236
 
237
		if ($this->isOtherLang())
238
		{
239
 
5921 daniel 240
			$trans_db = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `lang_parent` = '".wpsg_q($this->getProduktID($p['productkey']))."' AND `lang_code` = '".wpsg_q($this->getCurrentLanguageCode())."'");
2975 daniel 241
 
242
			if (is_array($trans_db) && sizeof($trans_db) > 0)
243
			{
244
 
245
				$produkt_text = $trans_db['name'];
246
				$produktBeschreibung = trim(strip_tags($trans_db['beschreibung']));
247
 
248
			}
249
 
250
		}
251
 
252
		$height = 0; // Höhe der Zeile für den Rahmen
253
 
254
		$pdf->setXY($prod_left + 10, $prod_top + $offset);
255
 
256
		// Produktvariablen
257
		if ($this->hasMod('wpsg_mod_productvars') && $this->get_option("wpsg_mod_rechnungen_showpv") == "1")
258
		{
259
 
3709 daniel 260
			$arPV = $this->callMod('wpsg_mod_productvars', 'getAllProductVarValues', array($this->view['data']['id'], $p['productkey']));
261
 
262
			if (wpsg_isSizedArray($arPV))
2975 daniel 263
			{
264
 
3709 daniel 265
				foreach ($arPV as $pv)
266
				{
2975 daniel 267
 
3709 daniel 268
					$produkt_text .= "\r\n".$pv['name'].': '.$pv['value'];
269
					$height += 5;
270
 
271
				}
2975 daniel 272
 
273
			}
3709 daniel 274
 
275
		}
2975 daniel 276
 
3748 daniel 277
		if ($this->get_option('wpsg_mod_deliverynote_anr') === '2')
278
		{
279
 
280
			$anr = $this->getProductAnr($p['productkey']);
281
			$produkt_text .= "\r\n".wpsg_translate(__('Artikelnummer: #1#', 'wpsg'), $anr);
282
 
283
		}
284
 
2975 daniel 285
		$produkt_text_cell_width = 137;
286
		$produkt_text_width = $pdf->GetStringWidth($produkt_text);
287
 
288
		$height += 5 * ceil($produkt_text_width / $produkt_text_cell_width) + 3;
289
 
290
		$height_y = $pdf->getY();
5382 daniel 291
		$height = 2 + $pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $offset + 1.5, 5, $produkt_text, 0, 'L', 0, $produkt_text_cell_width);
2975 daniel 292
 
293
		$pdf->setXY($prod_left + 147, $prod_top + $offset);
294
		$pdf->Cell(15, 8, $p['menge'], 0, 0, 'C');
295
 
296
		/**
297
		 * Produktbeschreibung anzeigen Ja/Nein
298
		*/
299
		$pBeschreibungHeight = 0;
300
		if ($this->get_option("wpsg_mod_deliverynote_pdf_beschreibung") == "1" && trim(strip_tags($p['beschreibung'])) != '')
301
		{
302
 
303
			$produktBeschreibung = nl2br($produktBeschreibung);
304
			preg_match_all('/\<br \/\>/', $produktBeschreibung, $treffer);
305
			$produktBeschreibung = strip_tags($produktBeschreibung);
306
 
307
			$pBeschreibungWidth = $pdf->getStringWidth($produktBeschreibung);
308
			$pBeschreibungHeight = 5 * (ceil($pBeschreibungWidth / $produkt_text_cell_width) + @sizeof($treffer[0]));
309
 
310
			$pdf->SetFont('Arial', 'I', 9);
311
 
312
			$cellY = $pdf->getY();
5382 daniel 313
			$pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $height + $offset - 1, 5, $produktBeschreibung, 0, 'L', 0, $produkt_text_cell_width);
2975 daniel 314
			$pBeschreibungHeight = $pdf->getY() - $cellY - $height + 1;
315
			$pdf->SetFont('Arial', '', 9);
316
 
317
		}
318
 
319
		$height += $pBeschreibungHeight;
320
 
321
		/**
5765 thomas 322
		 * Produktattribute ?
323
		 */
324
		if ($this->get_option('wpsg_rechnungen_produktattribute') == '1')
325
		{
326
 
327
			$attributeInfo = $this->callMod('wpsg_mod_produktattribute', 'getProductAttributeByProductId', array($this->getProduktId($p['id'])));
328
 
329
			foreach ($attributeInfo as $pa)
330
			{
331
 
332
				$pa_text = $pa['name'].': '.$pa['value'];
333
				$height += $pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $height + $offset - 0.5, 5, $pa_text, 0, 'L', 0, $produkt_text_cell_width);
334
 
335
			}
336
		}
337
 
338
		/**
2975 daniel 339
		 * Variante ?
340
		 */
6165 hartmut 341
		//$p['productkey'] = 'pv_6|4:1|7:3';
342
		if ($this->get_option("wpsg_mod_deliverynote_pdf_varianten") == "1" && preg_match('/pv_(.*)/', $p['productkey']))
2975 daniel 343
		{
344
 
6165 hartmut 345
			$variInfo = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($p['productkey']));
2975 daniel 346
 
5382 daniel 347
			$height += $pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $height + $offset - 1.5, 5, wpsg_translate(__('Variante: #1#', 'wpsg'), $variInfo['key']), 0, 'L', 0, $produkt_text_cell_width);
2975 daniel 348
 
349
		}
350
 
351
		// Jetzt die Rahmen zeichnen
352
		$pdf->Rect($prod_left, $prod_top + $offset, 10, $height);
353
		$pdf->Rect($prod_left + 10, $prod_top + $offset, 137, $height);
354
		$pdf->Rect($prod_left + 147, $prod_top + $offset, 15, $height);
355
 
356
		$offset += $height;
357
 
358
		$pnr ++;
359
		$count ++;
360
 
361
		$summe += $p['price'] * $p['menge'];
362
 
363
		if ($pdf->getY() > 220 || ($count >= $prod_break && sizeof($this->view['data']['products']) > ($pnr - 1)))
364
		{
365
 
3827 daniel 366
			AddDeliverynotePage($this, $pdf);
2975 daniel 367
			$bKopf = false; $offset = 0; $count = 0;
368
 
369
		}
370
 
371
	}
372
 
373
	$offset += 5;
374
 
375
	if ($this->view['fussText'] != "")
376
	{
377
 
5382 daniel 378
		$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset, 5, $this->view['fussText']);
2975 daniel 379
		$pdf->SetFont('Arial', 'B', 9);
380
		$offset += 10;
381
 
382
	}
6901 daniel 383
 
384
    ob_end_clean();
2975 daniel 385
 
386
	if ($this->view['preview'])
387
	{
388
		$pdf->Output($this->view['filename'], 'I');
389
	}
390
	else
391
	{
392
 
393
		$pdf->Output($this->callMod('wpsg_mod_deliverynote', 'getFilePath', array($this->view['order']['id'])).$this->view['filename'], 'F');
394
 
7753 daniel 395
		if (wpsg_isTrue($this->view['output'])) $pdf->Output($filename, 'I');
2975 daniel 396
 
397
	}
398