Subversion Repositories wpShopGermany4

Rev

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