Subversion Repositories wpShopGermany4

Rev

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