Rev 7332 | Rev 7753 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
/**
* FPDF Template für die Generierung des Lieferscheins
*/
require_once WPSG_PATH_LIB.'FPDF_1.81/fpdf.php';
require_once WPSG_PATH_LIB.'FPDI_2.2.0/autoload.php';
require_once WPSG_PATH_LIB.'wpsg_fpdf.class.php';
global $absender_left, $absender_top, $adress_left, $adress_top, $dndata_left, $dndata_top;
if (!function_exists('AddDeliverynotePage'))
{
function AddDeliverynotePage($shop, $pdf)
{
global $absender_left, $absender_top, $adress_left, $adress_top, $dndata_left, $dndata_top;
$rdata_left = 0;
$pdf->AddPage();
if (file_exists($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_bp.pdf"))
{
$pagecount = $pdf->setSourceFile($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_bp.pdf");
$tplidx = $pdf->importPage(1, '/MediaBox');
$pdf->useTemplate($tplidx, 0, 0, 210);
}
else if (file_exists($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_bp.jpg"))
{
$pdf->image($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_bp.jpg", 0, 0, 210, 297, 'jpg');
}
if (file_exists($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_logo.jpg"))
{
list($width, $height, $type, $attr) = getimagesize($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_logo.jpg");
// Umrechnung von Inch zu Pixel
$wPix = (25.4 * $width) / 96;
$hPix = (25.4 * $height) / 96;
$leftPos = 110 - $wPix;
$midPos = $wPix * 2.6 - $width / 2;
$rightPos = 210 - $wPix;
$abscissa = $rightPos;
$ordinate = 0;
$transparency = str_replace("%", "", $shop->get_option('wpsg_mod_deliverynote_logo_transparency'));
if($transparency !== "100") $transparency = str_replace(array("0", "00"), "", $transparency);
$alpha = 1;
if(!is_null($transparency) && $transparency !== "100") $alpha = "0.$transparency";
if(!is_null($transparency) && $transparency === "100") $alpha = $transparency;
$logo_pos = $shop->get_option('wpsg_mod_deliverynote_logo_position');
if(isset($logo_pos) && $logo_pos === "left") { $abscissa = $leftPos; $ordinate = 20; }
if(isset($logo_pos) && $logo_pos === "center") { $abscissa = $midPos; $ordinate = 20; }
if(isset($logo_pos) && $logo_pos === "right") { $abscissa = $rightPos; }
$pdf->SetAlpha($alpha);
$pdf->image($shop->callMod('wpsg_mod_deliverynote', 'getFilePath', array(''))."wpsg_deliverynote_logo.jpg", $abscissa, $ordinate, $wPix, $hPix);
$pdf->SetAlpha(1);
}
// Absenderadresszeile (Wird in der Konfiguration hinterlegt)
$pdf->SetFont('Arial', '', 6);
$pdf->Text($absender_left, $absender_top, $shop->replaceUniversalPlatzhalter($shop->get_option("wpsg_mod_deliverynote_adressrow"), $shop->view['order']['id']));
if (wpsg_getStr($shop->view['kunde']['kuerzel']) != "") $shop->view['kunde']['kuerzel'] = $shop->view['kunde']['kuerzel'].'-';
// Adresse des Kunden
$pdf->SetFont('Arial', '', 12);
$pdf->Text($adress_left, $adress_top, $shop->view['data']['firma']);
$pdf->Text($adress_left, $adress_top + 5, $shop->view['data']['vname'].' '.$shop->view['data']['name']);
$pdf->Text($adress_left, $adress_top + 10, $shop->view['data']['strasse'].' '.$shop->view['data']['nr']);
$pdf->Text($adress_left, $adress_top + 15, $shop->view['data']['plz'].' '.$shop->view['data']['ort']);
//if ($shop->get_option('wpsg_mod_deliverynote_hideCountry') != '1') $pdf->Text($adress_left, $adress_top + 20, strtoupper($shop->view['oOrder']->getShippingCountryName()));
if ($shop->get_option('wpsg_mod_deliverynote_hideCountry') != '1') $pdf->Text($adress_left, $adress_top + 20, $shop->view['data']['land']);
// Lieferscheindaten
$pdf->SetFont('Arial', 'B', 16);
$pdf->Text($dndata_left, $dndata_top, $shop->view['title']);
$pdf->SetFont('Arial', 'B', 9);
$pdf->Text($dndata_left, $dndata_top + 6, $shop->view['lnr']);
$pdf->SetFont('Arial', '', 9);
$pdf->Text($rdata_left + 100, $dndata_top, __("Kunden-Nr", "wpsg"));
$pdf->Text($rdata_left + 100, $dndata_top + 6, (($shop->view['customer']['knr'] != '')?$shop->view['customer']['knr']:$shop->view['customer']['id']));
$pdf->Text($rdata_left + 125, $dndata_top, __("Best. Nr.", "wpsg"));
$pdf->Text($rdata_left + 125, $dndata_top + 6, ((trim($shop->view['order']['onr']) != '')?$shop->view['order']['onr']:$shop->view['order']['id']));
$pdf->Text($rdata_left + 145, $dndata_top, __("Bestelldatum", "wpsg"));
$pdf->Text($rdata_left + 145, $dndata_top + 6, wpsg_formatTimestamp(strtotime($shop->view['order']['cdate']), true));
$pdf->Text($rdata_left + 170, $dndata_top, __("Lieferdatum", "wpsg"));
$pdf->Text($rdata_left + 170, $dndata_top + 6, wpsg_formatTimestamp($shop->view['lDatum'], true));
if ($shop->view['oOrder']->isInnerEu())
{
$pdf->SetFont('Arial', '', 9);
$pdf->Text($adress_left, $rdata_top + 11.5, __("Innergemeinschaftliche Lieferung.", "wpsg"));
} else if (!$shop->view['oOrder']->isInnerEu() && $shop->view['oOrder']->getShippingCountryID() != $shop->getDefaultCountry(true)) {
// Nicht InnerEU und Nicht Inland
$pdf->SetFont('Arial', '', 9);
$pdf->Text($adress_left, $rdata_top + 11.5, __("Steuerfreie Ausfuhrlieferung.", "wpsg"));
}
// Benutzerdefinierte Felder
$arTexte = $shop->callMod('wpsg_mod_deliverynote', 'getTexte', array($shop->view['data']['id']));
foreach ((array)$arTexte as $text)
{
if (isset($text['aktiv']) && $text['aktiv'] == 1)
{
$pdf->SetFont('Arial', 'B', ((intval($text['fontsize']) > 0)?intval($text['fontsize']):10));
$pdf->wpsg_SetTextColor($text['color']);
$pdf->wpsg_MultiCell($text['x'], $text['y'], 5, $text['text']);
$pdf->wpsg_SetTextColor("#000000");
}
}
}
}
// Positionierung der Absenderadresszeile
$absender_left = 25;
$absender_top = 50;
// Positionierung der Zieladress
$adress_left = 25;
$adress_top = 55;
// Positionierund des Lieferscheinkopfes
$dndata_left = 25;
$dndata_top = 90;
// Positionierung der Produktdaten
$prod_left = 25;
$prod_top = 105;
// Anzahl an Produkten pro Seite
$prod_break = 10;
$pdf = new wpsg_fpdf();
$pdf->SetAutoPageBreak(true, 5);
AddDeliverynotePage($this, $pdf);
$filename = $this->view['filename'].".pdf";
$bKopf = false; $pnr = 1; $offset = 0; $count = 0;
foreach ($this->view['data']['products'] as $p)
{
$product_data = $this->loadProduktArray($this->getProduktID($p['p_id']));
if (!$bKopf)
{
$pdf->SetFont('Arial', 'B', 9);
$pdf->setXY($prod_left, $prod_top);
$pdf->Cell(10, 8, __("Nr.", "wpsg"), 1, 0, 'C');
$pdf->setXY($prod_left + 10, $prod_top);
$pdf->Cell(137, 8, "Name", 1, 0, 'L');
$pdf->setXY($prod_left + 147, $prod_top);
$pdf->Cell(15, 8, __("Menge", "wpsg"), 1, 0, 'C');
$offset = 8;
$bKopf = true;
}
/*
if ($this->hasMod('wpsg_mod_productvariants') && isset($p['mod_vp_varkey']))
{
$variante = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($p['mod_vp_varkey']));
$anr = $variante['akey'];
}
else
{
$anr = $product_data['anr'];
}*/
$pdf->SetFont('Arial', '', 9);
$pdf->setXY($prod_left, $prod_top + $offset);
if ($this->get_option('wpsg_mod_deliverynote_anr') === '1')
{
$anr = $this->getProductAnr($p['productkey']);
$pdf->Cell(10, 8, $anr, 0, 0, 'C'); /* Artikelnummer anzeigen */
}
else
{
$pdf->Cell(10, 8, $pnr.".", 0, 0, 'C');
}
/* Wenn Detailname vorhanden, wird der Detailname auf dem Lieferschein verwendet*/
$produkt_text = $this->getProductName($this->getProduktID($p['p_id']), true);
/* Wenn Detailname nicht vorhanden, wird der Name auf dem Lieferschein verwendet*/
$produkt_text = $this->getProductName($this->getProduktID($p['p_id']), false);
$produktBeschreibung = trim(strip_tags($p['beschreibung']));
if ($this->isOtherLang())
{
$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())."'");
if (is_array($trans_db) && sizeof($trans_db) > 0)
{
$produkt_text = $trans_db['name'];
$produktBeschreibung = trim(strip_tags($trans_db['beschreibung']));
}
}
$height = 0; // Höhe der Zeile für den Rahmen
$pdf->setXY($prod_left + 10, $prod_top + $offset);
// Produktvariablen
if ($this->hasMod('wpsg_mod_productvars') && $this->get_option("wpsg_mod_rechnungen_showpv") == "1")
{
$arPV = $this->callMod('wpsg_mod_productvars', 'getAllProductVarValues', array($this->view['data']['id'], $p['productkey']));
if (wpsg_isSizedArray($arPV))
{
foreach ($arPV as $pv)
{
$produkt_text .= "\r\n".$pv['name'].': '.$pv['value'];
$height += 5;
}
}
}
if ($this->get_option('wpsg_mod_deliverynote_anr') === '2')
{
$anr = $this->getProductAnr($p['productkey']);
$produkt_text .= "\r\n".wpsg_translate(__('Artikelnummer: #1#', 'wpsg'), $anr);
}
$produkt_text_cell_width = 137;
$produkt_text_width = $pdf->GetStringWidth($produkt_text);
$height += 5 * ceil($produkt_text_width / $produkt_text_cell_width) + 3;
$height_y = $pdf->getY();
$height = 2 + $pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $offset + 1.5, 5, $produkt_text, 0, 'L', 0, $produkt_text_cell_width);
$pdf->setXY($prod_left + 147, $prod_top + $offset);
$pdf->Cell(15, 8, $p['menge'], 0, 0, 'C');
/**
* Produktbeschreibung anzeigen Ja/Nein
*/
$pBeschreibungHeight = 0;
if ($this->get_option("wpsg_mod_deliverynote_pdf_beschreibung") == "1" && trim(strip_tags($p['beschreibung'])) != '')
{
$produktBeschreibung = nl2br($produktBeschreibung);
preg_match_all('/\<br \/\>/', $produktBeschreibung, $treffer);
$produktBeschreibung = strip_tags($produktBeschreibung);
$pBeschreibungWidth = $pdf->getStringWidth($produktBeschreibung);
$pBeschreibungHeight = 5 * (ceil($pBeschreibungWidth / $produkt_text_cell_width) + @sizeof($treffer[0]));
$pdf->SetFont('Arial', 'I', 9);
$cellY = $pdf->getY();
$pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $height + $offset - 1, 5, $produktBeschreibung, 0, 'L', 0, $produkt_text_cell_width);
$pBeschreibungHeight = $pdf->getY() - $cellY - $height + 1;
$pdf->SetFont('Arial', '', 9);
}
$height += $pBeschreibungHeight;
/**
* Produktattribute ?
*/
if ($this->get_option('wpsg_rechnungen_produktattribute') == '1')
{
$attributeInfo = $this->callMod('wpsg_mod_produktattribute', 'getProductAttributeByProductId', array($this->getProduktId($p['id'])));
foreach ($attributeInfo as $pa)
{
$pa_text = $pa['name'].': '.$pa['value'];
$height += $pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $height + $offset - 0.5, 5, $pa_text, 0, 'L', 0, $produkt_text_cell_width);
}
}
/**
* Variante ?
*/
//$p['productkey'] = 'pv_6|4:1|7:3';
if ($this->get_option("wpsg_mod_deliverynote_pdf_varianten") == "1" && preg_match('/pv_(.*)/', $p['productkey']))
{
$variInfo = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($p['productkey']));
$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);
}
// Jetzt die Rahmen zeichnen
$pdf->Rect($prod_left, $prod_top + $offset, 10, $height);
$pdf->Rect($prod_left + 10, $prod_top + $offset, 137, $height);
$pdf->Rect($prod_left + 147, $prod_top + $offset, 15, $height);
$offset += $height;
$pnr ++;
$count ++;
$summe += $p['price'] * $p['menge'];
if ($pdf->getY() > 220 || ($count >= $prod_break && sizeof($this->view['data']['products']) > ($pnr - 1)))
{
AddDeliverynotePage($this, $pdf);
$bKopf = false; $offset = 0; $count = 0;
}
}
$offset += 5;
if ($this->view['fussText'] != "")
{
$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset, 5, $this->view['fussText']);
$pdf->SetFont('Arial', 'B', 9);
$offset += 10;
}
ob_end_clean();
if ($this->view['preview'])
{
$pdf->Output($this->view['filename'], 'I');
}
else
{
$pdf->Output($this->callMod('wpsg_mod_deliverynote', 'getFilePath', array($this->view['order']['id'])).$this->view['filename'], 'F');
if ($this->view['output'] === true) $pdf->Output($filename, 'I');
}
?>