Subversion Repositories wpShopGermany4

Rev

Rev 7352 | 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
 
175
		$product_data = $this->loadProduktArray($this->getProduktID($p['p_id']));
176
 
2975 daniel 177
		if (!$bKopf)
178
		{
179
 
180
			$pdf->SetFont('Arial', 'B', 9);
181
			$pdf->setXY($prod_left, $prod_top);
182
			$pdf->Cell(10, 8, __("Nr.", "wpsg"), 1, 0, 'C');
183
 
184
			$pdf->setXY($prod_left + 10, $prod_top);
185
			$pdf->Cell(137, 8, "Name", 1, 0, 'L');
186
 
187
			$pdf->setXY($prod_left + 147, $prod_top);
188
			$pdf->Cell(15, 8, __("Menge", "wpsg"), 1, 0, 'C');
189
 
190
			$offset = 8;
191
			$bKopf = true;
192
 
193
		}
3417 daniel 194
 
195
		/*
6165 hartmut 196
		if ($this->hasMod('wpsg_mod_productvariants') && isset($p['mod_vp_varkey']))
3417 daniel 197
		{
2975 daniel 198
 
6165 hartmut 199
			$variante = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($p['mod_vp_varkey']));
3417 daniel 200
			$anr = $variante['akey'];
201
 
202
		}
203
		else
204
		{
205
 
206
			$anr = $product_data['anr'];
207
 
208
		}*/
209
 
210
		$pdf->SetFont('Arial', '', 9);
2975 daniel 211
		$pdf->setXY($prod_left, $prod_top + $offset);
212
 
3748 daniel 213
		if ($this->get_option('wpsg_mod_deliverynote_anr') === '1')
214
		{
215
 
216
			$anr = $this->getProductAnr($p['productkey']);
217
			$pdf->Cell(10, 8, $anr, 0, 0, 'C'); /* Artikelnummer anzeigen */
218
 
219
		}
220
		else
221
		{
222
 
223
			$pdf->Cell(10, 8, $pnr.".", 0, 0, 'C');
224
 
225
		}
4909 thomas 226
 
7021 thomas 227
		/* Wenn Detailname vorhanden, wird der Detailname auf dem Lieferschein verwendet*/
4909 thomas 228
		$produkt_text = $this->getProductName($this->getProduktID($p['p_id']), true);
7021 thomas 229
 
230
		/* Wenn Detailname nicht vorhanden, wird der Name auf dem Lieferschein verwendet*/
231
		$produkt_text = $this->getProductName($this->getProduktID($p['p_id']), false);
232
 
2975 daniel 233
		$produktBeschreibung = trim(strip_tags($p['beschreibung']));
234
 
235
		if ($this->isOtherLang())
236
		{
237
 
5921 daniel 238
			$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 239
 
240
			if (is_array($trans_db) && sizeof($trans_db) > 0)
241
			{
242
 
243
				$produkt_text = $trans_db['name'];
244
				$produktBeschreibung = trim(strip_tags($trans_db['beschreibung']));
245
 
246
			}
247
 
248
		}
249
 
250
		$height = 0; // Höhe der Zeile für den Rahmen
251
 
252
		$pdf->setXY($prod_left + 10, $prod_top + $offset);
253
 
254
		// Produktvariablen
255
		if ($this->hasMod('wpsg_mod_productvars') && $this->get_option("wpsg_mod_rechnungen_showpv") == "1")
256
		{
257
 
3709 daniel 258
			$arPV = $this->callMod('wpsg_mod_productvars', 'getAllProductVarValues', array($this->view['data']['id'], $p['productkey']));
259
 
260
			if (wpsg_isSizedArray($arPV))
2975 daniel 261
			{
262
 
3709 daniel 263
				foreach ($arPV as $pv)
264
				{
2975 daniel 265
 
3709 daniel 266
					$produkt_text .= "\r\n".$pv['name'].': '.$pv['value'];
267
					$height += 5;
268
 
269
				}
2975 daniel 270
 
271
			}
3709 daniel 272
 
273
		}
2975 daniel 274
 
3748 daniel 275
		if ($this->get_option('wpsg_mod_deliverynote_anr') === '2')
276
		{
277
 
278
			$anr = $this->getProductAnr($p['productkey']);
279
			$produkt_text .= "\r\n".wpsg_translate(__('Artikelnummer: #1#', 'wpsg'), $anr);
280
 
281
		}
282
 
2975 daniel 283
		$produkt_text_cell_width = 137;
284
		$produkt_text_width = $pdf->GetStringWidth($produkt_text);
285
 
286
		$height += 5 * ceil($produkt_text_width / $produkt_text_cell_width) + 3;
287
 
288
		$height_y = $pdf->getY();
5382 daniel 289
		$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 290
 
291
		$pdf->setXY($prod_left + 147, $prod_top + $offset);
292
		$pdf->Cell(15, 8, $p['menge'], 0, 0, 'C');
293
 
294
		/**
295
		 * Produktbeschreibung anzeigen Ja/Nein
296
		*/
297
		$pBeschreibungHeight = 0;
298
		if ($this->get_option("wpsg_mod_deliverynote_pdf_beschreibung") == "1" && trim(strip_tags($p['beschreibung'])) != '')
299
		{
300
 
301
			$produktBeschreibung = nl2br($produktBeschreibung);
302
			preg_match_all('/\<br \/\>/', $produktBeschreibung, $treffer);
303
			$produktBeschreibung = strip_tags($produktBeschreibung);
304
 
305
			$pBeschreibungWidth = $pdf->getStringWidth($produktBeschreibung);
306
			$pBeschreibungHeight = 5 * (ceil($pBeschreibungWidth / $produkt_text_cell_width) + @sizeof($treffer[0]));
307
 
308
			$pdf->SetFont('Arial', 'I', 9);
309
 
310
			$cellY = $pdf->getY();
5382 daniel 311
			$pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $height + $offset - 1, 5, $produktBeschreibung, 0, 'L', 0, $produkt_text_cell_width);
2975 daniel 312
			$pBeschreibungHeight = $pdf->getY() - $cellY - $height + 1;
313
			$pdf->SetFont('Arial', '', 9);
314
 
315
		}
316
 
317
		$height += $pBeschreibungHeight;
318
 
319
		/**
5765 thomas 320
		 * Produktattribute ?
321
		 */
322
		if ($this->get_option('wpsg_rechnungen_produktattribute') == '1')
323
		{
324
 
325
			$attributeInfo = $this->callMod('wpsg_mod_produktattribute', 'getProductAttributeByProductId', array($this->getProduktId($p['id'])));
326
 
327
			foreach ($attributeInfo as $pa)
328
			{
329
 
330
				$pa_text = $pa['name'].': '.$pa['value'];
331
				$height += $pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $height + $offset - 0.5, 5, $pa_text, 0, 'L', 0, $produkt_text_cell_width);
332
 
333
			}
334
		}
335
 
336
		/**
2975 daniel 337
		 * Variante ?
338
		 */
6165 hartmut 339
		//$p['productkey'] = 'pv_6|4:1|7:3';
340
		if ($this->get_option("wpsg_mod_deliverynote_pdf_varianten") == "1" && preg_match('/pv_(.*)/', $p['productkey']))
2975 daniel 341
		{
342
 
6165 hartmut 343
			$variInfo = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($p['productkey']));
2975 daniel 344
 
5382 daniel 345
			$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 346
 
347
		}
348
 
349
		// Jetzt die Rahmen zeichnen
350
		$pdf->Rect($prod_left, $prod_top + $offset, 10, $height);
351
		$pdf->Rect($prod_left + 10, $prod_top + $offset, 137, $height);
352
		$pdf->Rect($prod_left + 147, $prod_top + $offset, 15, $height);
353
 
354
		$offset += $height;
355
 
356
		$pnr ++;
357
		$count ++;
358
 
359
		$summe += $p['price'] * $p['menge'];
360
 
361
		if ($pdf->getY() > 220 || ($count >= $prod_break && sizeof($this->view['data']['products']) > ($pnr - 1)))
362
		{
363
 
3827 daniel 364
			AddDeliverynotePage($this, $pdf);
2975 daniel 365
			$bKopf = false; $offset = 0; $count = 0;
366
 
367
		}
368
 
369
	}
370
 
371
	$offset += 5;
372
 
373
	if ($this->view['fussText'] != "")
374
	{
375
 
5382 daniel 376
		$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset, 5, $this->view['fussText']);
2975 daniel 377
		$pdf->SetFont('Arial', 'B', 9);
378
		$offset += 10;
379
 
380
	}
6901 daniel 381
 
382
    ob_end_clean();
2975 daniel 383
 
384
	if ($this->view['preview'])
385
	{
386
		$pdf->Output($this->view['filename'], 'I');
387
	}
388
	else
389
	{
390
 
391
		$pdf->Output($this->callMod('wpsg_mod_deliverynote', 'getFilePath', array($this->view['order']['id'])).$this->view['filename'], 'F');
392
 
393
		if ($this->view['output'] === true) $pdf->Output($filename, 'I');
394
 
395
	}
396
 
397
?>