Index: /views/mods/mod_rechnungen/accounting_pdf.phtml
===================================================================
--- /views/mods/mod_rechnungen/accounting_pdf.phtml	(revision 8189)
+++ /views/mods/mod_rechnungen/accounting_pdf.phtml	(revision 8190)
@@ -34,12 +34,7 @@
 	if ($this->getFrontendTaxView() === WPSG_NETTO) $taxdisplay = 'netto';
 	else $taxdisplay = 'brutto';
-	
+
 	// Damit die Steuer bei der Kleinunternehmerregelung nicht angezeigt wird leer ich den Array sicherheitshalber
-	if ($this->get_option('wpsg_kleinunternehmer') == '1')
-	{
-		
-		unset($this->view['basket']['mwst']);
-		
-	}
+	if ( ($this->get_option('wpsg_kleinunternehmer') == '1') || ($this->view['oCalculationOrder']->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_SMALLBUSINESS) ) unset($this->view['basket']['mwst']);
 	
 	if (!function_exists('AddRechnungPage'))
@@ -107,5 +102,5 @@
 	
 				$pdf->Text($rdata_left + 35, $rdata_top, __("FÃ€llig am", "wpsg"));
-				$pdf->Text($rdata_left + 35, $rdata_top + 6, $shop->view['faelligkeitdatum']);
+				$pdf->Text($rdata_left + 35, $rdata_top + 6, date("d.m.Y", strtotime($shop->view['faelligkeitdatum'])));
 				
 			}
@@ -126,5 +121,5 @@
 			
 			$pdf->Text($rdata_left + 155, $rdata_top, __("Datum", "wpsg")); 
-			$pdf->Text($rdata_left + 155, $rdata_top + 6, $shop->view['rDatum']);
+			$pdf->Text($rdata_left + 155, $rdata_top + 6, date("d.m.Y", strtotime($shop->view['rDatum'])));
 					
 			if ($shop->view['oOrder']->isInnerEu())
@@ -164,14 +159,39 @@
 		
 	}
-	//wpsg_debug($this->view); die();
+
 	$pdf = new wpsg_fpdf();	
 	$pdf->SetAutoPageBreak(true, 5);
 	AddRechnungPage($this, $pdf);
+
+	if ( ($this->view['oCalculationOrder']->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_B2B && $this->view['oOrder']->isInnerEu()) 
+	|| ($this->view['oCalculationOrder']->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_SMALLBUSINESS) 
+	) $bNoTax = true;
+	else $bNoTax = false;
+
+	$bTaxCol = false;
+	if ($this->get_option('wpsg_showMwstAlways') === '1') $bTaxCol = true;
+	else if (!$bNoTax) $bTaxCol = true;
+
+
+	if ($bNoTax) {
+
+		$discount_value = $this->view['basket']['arCalculation']['sum']['discount_netto'];
+		$shipping_cost = $this->view['basket']['arCalculation']['sum']['shipping_netto'];
+		$payment_cost = $this->view['basket']['arCalculation']['sum']['payment_netto'];
+
+	} else {
+
+		$discount_value = $this->view['basket']['arCalculation']['sum']['discount_brutto'];
+		$shipping_cost = $this->view['basket']['arCalculation']['sum']['shipping_brutto'];
+		$payment_cost = $this->view['basket']['arCalculation']['sum']['payment_brutto'];
+
+	}
 				
 	$summe = 0;
 	
 	$bKopf = false; $pnr = 1; $offset = 0; $count = 0;
-	foreach ($this->view['basket']['produkte'] as $p)
-	{
+	foreach ($this->view['basket']['arCalculation']['product'] as $p)
+	{
+		$product = wpsg_product::getInstance($p['product_id']);
 			 
 		if (!$bKopf)
@@ -183,7 +203,7 @@
 
 			$pdf->setXY($prod_left + 10, $prod_top);
-			$pdf->Cell( ((sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')?87:102), 8, "Name", 1, 0, 'L');
-			
-			if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
+			$pdf->Cell( (($bTaxCol)?87:102), 8, "Name", 1, 0, 'L');
+			
+			if ($bTaxCol)
 			{
 			
@@ -210,29 +230,16 @@
 		$pdf->setXY($prod_left, $prod_top + $offset);
 		
-		if ($this->get_option('wpsg_mod_rechnungen_anr') == '1')
-		{
-			
-			$pdf->Cell(10, 8, $p['anr'], 0, 0, 'C');
-			
-		}
-		else
-		{
-		
-			$pdf->Cell(10, 8, $pnr.".", 0, 0, 'C');
-			
-		}
-
-		/* Wenn Detailname vorhanden, wird der Detailname auf Rechnung verwendet */
-		$produkt_text = $this->getProductName($this->getProduktID($p['id']), true);
-		
-		/* Falls Detailname vorhanden, wird jetzt der Produktname verwendet */
-		/* $produkt_text = $this->getProductName($this->getProduktID($p['id']), false); */
-		
-		$produktBeschreibung = trim(strip_tags($p['beschreibung']));
+		if ($this->get_option('wpsg_mod_rechnungen_anr') == '1') $pdf->Cell(10, 8, $product->getNr(), 0, 0, 'C');
+		else $pdf->Cell(10, 8, $pnr.".", 0, 0, 'C');
+
+		if ($this->get_option('wpsg_rechnungen_pdetailname') == '1') $produkt_text = $this->getProductName($this->getProduktID($p['product_id']), true);
+		else $produkt_text = $this->getProductName($this->getProduktID($p['product_id']), false);
+		
+		$produktBeschreibung = trim(strip_tags($product->getShortDescription()));
 		
 		if ($this->isOtherLang())
 		{ 
 			
-			$trans_db = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `lang_parent` = '".wpsg_q($this->getProduktID($p['id']))."' AND `lang_code` = '".wpsg_q($this->getCurrentLanguageCode())."'");
+			$trans_db = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `lang_parent` = '".wpsg_q($this->getProduktID($p['product_id']))."' AND `lang_code` = '".wpsg_q($this->getCurrentLanguageCode())."'");
 			
 			if (is_array($trans_db) && sizeof($trans_db) > 0)
@@ -274,5 +281,5 @@
         {
 
-            $anr = $this->getProductAnr($p['productkey']);
+            $anr = $this->getProductAnr($product->getProductKey());
             $produkt_text .= "\r\n".wpsg_translate(__('Artikelnummer: #1#', 'wpsg'), $anr);
 
@@ -280,8 +287,5 @@
 
 		$produkt_text_cell_width = 102;
-		if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
-		{
-			$produkt_text_cell_width = 87;	
-		}
+		if ($bTaxCol) $produkt_text_cell_width = 87;
 		
 		$produkt_text_width = $pdf->GetStringWidth($produkt_text);
@@ -296,31 +300,22 @@
 		//$pdf->Cell((($this->arMwSt == "-1")?102:87), 8, $produkt_text, 0, 0, 'L');
 
-		if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
-		{
+		if ($bTaxCol) {
 		
 			$pdf->setXY($prod_left + 97, $prod_top + $offset);		
-			$pdf->Cell(15, 8, (($this->view['basket']['noMwSt'] == '1')?'0.00 %':wpsg_ff($p['mwst_value'], '%')), 0, 0, 'C');
+			$pdf->Cell(15, 8, (($bNoTax)?'0.00 %':wpsg_ff($this->view['basket']['arCalculation']['tax'][$p['tax_key']]['tax_value'], '%')), 0, 0, 'C');
 			
 		}
 		
 		$pdf->setXY($prod_left + 112, $prod_top + $offset);
-		$pdf->Cell(15, 8, $p['menge'], 0, 0, 'C');
+		$pdf->Cell(15, 8, $p['amount'], 0, 0, 'C');
 						
-		if (wpsg_ShopController::get_option('wpsg_preisangaben') == WPSG_NETTO)
-		{
-			$preis = $p['preis_netto'];
-			
-			//TODO
-		}
-		else
-		{
-			$preis = $p['preis_brutto'];
-		}
+		if ( ( wpsg_ShopController::get_option('wpsg_preisangaben') == WPSG_NETTO ) || $bNoTax ) $preis_single = $p['netto_calculated_single'];
+		else $preis_single =  $p['brutto_calculated_single'];
 		
 		$pdf->setXY($prod_left + 127, $prod_top + $offset);
-		$pdf->Cell(25, 8, wpsg_ff($preis, $this->get_option('wpsg_currency')), 0, 0, 'R');
+		$pdf->Cell(25, 8, wpsg_ff($preis_single, $this->get_option('wpsg_currency')), 0, 0, 'R');
 		
 		$pdf->setXY($prod_left + 152, $prod_top + $offset);
-		$pdf->Cell(25, 8, wpsg_ff($preis * $p['menge'], $this->get_option('wpsg_currency')), 0, 0, 'R');		
+		$pdf->Cell(25, 8, wpsg_ff($preis_single * $p['amount'], $this->get_option('wpsg_currency')), 0, 0, 'R');		
 
 		/**
@@ -328,5 +323,5 @@
 		 */
 		$pBeschreibungHeight = 0;
-		if ($this->get_option("wpsg_rechnungen_pbeschreibung") == "1" && trim(strip_tags($p['beschreibung'])) != '')
+		if ($this->get_option("wpsg_rechnungen_pbeschreibung") == "1" && trim(strip_tags($product->getShortDescription())) != '')
 		{
 			
@@ -354,10 +349,11 @@
 		if ($this->get_option('wpsg_rechnungen_produktattribute') == '1')
 		{
-				
-			$attributeInfo = $this->callMod('wpsg_mod_produktattribute', 'getProductAttributeByProductId', array($this->getProduktId($p['id'])));
+
+			$attributeInfo = $this->callMod('wpsg_mod_produktattribute', 'getProductAttributeByProductId', array($this->getProduktId($p['product_id'])));
 		
 			foreach ($attributeInfo as $pa)
 			{
-					
+
+				if ($pa['value'] == "") $pa['value'] = "Keine Angabe";
 				$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);
@@ -369,8 +365,8 @@
 		 * Variante ? 
 		 */
-		if (preg_match('/pv_(.*)/', $p['productkey']))
-		{
-			
-			$variInfo = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($p['productkey']));
+		if (preg_match('/pv_(.*)/', $p['product_key']))
+		{
+			
+			$variInfo = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', array($p['product_key']));
 
 			$height += $pdf->wpsg_MultiCell($prod_left + 10, $prod_top + $height + $offset - 0.5, 5, wpsg_translate(__('Variante: #1#', 'wpsg'), $variInfo['key']), 0, 'L', 0, $produkt_text_cell_width);			
@@ -380,5 +376,5 @@
 		}
 		
-		if ($this->hasMod('wpsg_mod_deliverynote'))
+		if ($this->hasMod('wpsg_mod_deliverynote') && ($this->get_option('wpsg_rechnungen_deliverynote') == '1'))
 		{
 			
@@ -404,12 +400,7 @@
 		$pdf->Rect($prod_left, $prod_top + $offset, 10, $height);
 		
-		$pdf->Rect($prod_left + 10, $prod_top + $offset, ((sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')?87:102), $height);
-		
-		if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
-		{
-		
-			$pdf->Rect($prod_left + 97, $prod_top + $offset, 15, $height);
-			
-		}
+		$pdf->Rect($prod_left + 10, $prod_top + $offset, (($bTaxCol)?87:102), $height);
+		
+		if ($bTaxCol) $pdf->Rect($prod_left + 97, $prod_top + $offset, 15, $height);
 		
 		$pdf->Rect($prod_left + 112, $prod_top + $offset, 15, $height);
@@ -422,7 +413,10 @@
 		$count ++;
 				
-		$summe += $p['price'] * $p['menge'];
-		
-		if ($pdf->getY() > 220 || ($count >= $prod_break && sizeof($this->view['basket']['produkte']) > ($pnr - 1)))		
+		if ($bNoTax) $price = $p['netto'];
+		else $price = $p['brutto'];
+
+		$summe += $price * $p['amount'];
+		
+		if ($pdf->getY() > 220 || ($count >= $prod_break && sizeof($this->view['basket']['arCalculation']['product']) > ($pnr - 1)))		
 		{
 			
@@ -434,42 +428,4 @@
 	} // produkte
  
-	// Gutschein
-	/*
-	if ((isset($this->view['basket']['gs'])) && ($this->view['basket']['gs_value'] > 0))
-	{
-		
-		$pdf->SetFont('Arial', '', 9);
-		$pdf->setXY($prod_left, $prod_top + $offset);
-		$pdf->Cell(10, 8, $pnr.'.', 1, 0, 'C'); $pnr ++;
-
-		$pdf->setXY($prod_left + 10, $prod_top + $offset);
-		$pdf->Cell( ((sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')?87:102), 8, wpsg_translate(__('Gutschein (#1#)', 'wpsg'), $this->view['basket']['gs']['code']), 1, 0, 'L');
-		
-		if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
-		{
-		
-			$mwst = __('anteilig', 'wpsg');
-				
-			$pdf->setXY($prod_left + 97, $prod_top + $offset);
-			$pdf->Cell(15, 8, $mwst, 1, 0, 'C');
-			
-		}
-		
-		$pdf->setXY($prod_left + 112, $prod_top + $offset);
-		$pdf->Cell(15, 8, '1', 1, 0, 'C');		
-					
-		$gs_value_einzel = '-'.wpsg_ff($this->view['basket']['sum']['gs'], $this->get_option('wpsg_currency'));
-		$gs_value_gesamt = '-'.wpsg_ff($this->view['basket']['sum']['gs'], $this->get_option('wpsg_currency'));
-		
-		$pdf->setXY($prod_left + 127, $prod_top + $offset);
-		$pdf->Cell(25, 8, $gs_value_einzel, 1, 0, 'R');
-		
-		$pdf->setXY($prod_left + 152, $prod_top + $offset);
-		$pdf->Cell(25, 8, $gs_value_gesamt, 1, 0, 'R');
-		 												
-		$offset += 8; 
-		
-	} 
-	*/
 	if (wpsg_isSizedArray($this->view['basket']['arCalculation']['voucher'])) {
 		
@@ -481,7 +437,7 @@
 			
 			$pdf->setXY($prod_left + 10, $prod_top + $offset);
-			$pdf->Cell( ((sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')?87:102), 8, wpsg_translate(__('Gutschein (#1#)', 'wpsg'), $v['code']), 1, 0, 'L');
-			
-			if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
+			$pdf->Cell( (($bTaxCol)?87:102), 8, wpsg_translate(__('Gutschein (#1#)', 'wpsg'), $v['code']), 1, 0, 'L');
+			
+			if ($bTaxCol)
 			{
 				
@@ -512,5 +468,5 @@
 	
 	// Versandkosten
-	if ($this->view['basket']['sum']['preis_shipping'] != '' && $this->view['basket']['sum']['preis_shipping'] != 0)
+	if ( ($shipping_cost != '') && ($shipping_cost != 0) )
 	{
 			 
@@ -520,23 +476,14 @@
 
 		$pdf->setXY($prod_left + 10, $prod_top + $offset);
-		$pdf->Cell( ((sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')?87:102), 8, wpsg_translate(__('Versandkosten "#1#"', 'wpsg'), $this->view['oOrder']->getShippingLabel()), 1, 0, 'L');
-		
-		if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
-		{
-		
-			if ($this->arShipping[$this->view['data']['type_shipping']]['mwst_null'] == '1' && $this->view['basket']['noMwSt'] == '1')
-			{
-				
-				$mwst = 0;
-				
-			}
-			else
-			{
-				
-				if ($this->view['basket']['arCalculation']['shipping'][0]['tax_key'] === '0') {
-					
-					$mwst = _('anteilig');
-					
-				} else {
+		$pdf->Cell( (($bTaxCol)?87:102), 8, wpsg_translate(__('Versandkosten "#1#"', 'wpsg'), $this->view['oOrder']->getShippingLabel()), 1, 0, 'L');
+		
+		if ($bTaxCol)
+		{
+		
+			if ($this->arShipping[$this->view['data']['type_shipping']]['mwst_null'] == '1' && $bNoTax) $mwst = wpsg_ff(0.00, '%');
+			else {
+				
+				if ($this->view['basket']['arCalculation']['shipping'][0]['tax_key'] === '0') $mwst = _('anteilig');
+				else {
 					
 					$mwst = wpsg_ff($this->view['basket']['arCalculation']['shipping'][0]['tax'], '%');
@@ -556,56 +503,15 @@
 					
 		$pdf->setXY($prod_left + 127, $prod_top + $offset);
-		$pdf->Cell(25, 8, wpsg_ff($this->view['basket']['sum']['preis_shipping'], $this->get_option('wpsg_currency')), 1, 0, 'R');
+		$pdf->Cell(25, 8, wpsg_ff($shipping_cost, $this->get_option('wpsg_currency')), 1, 0, 'R');
 		
 		$pdf->setXY($prod_left + 152, $prod_top + $offset);
-		$pdf->Cell(25, 8, wpsg_ff($this->view['basket']['sum']['preis_shipping'], $this->get_option('wpsg_currency')), 1, 0, 'R');
+		$pdf->Cell(25, 8, wpsg_ff($shipping_cost, $this->get_option('wpsg_currency')), 1, 0, 'R');
 		 												
 		$offset += 8;
 
-		// Zusammengesetzte Versandarten darstellen
-		/*
-		if (wpsg_isSizedArray($this->view['basket']['shipping']['methods'])) {
-		
-			foreach ($this->view['basket']['shipping']['methods'] as $shipping) {
-					
-				$pdf->SetFont('Arial', '', 9);
-				$pdf->setXY($prod_left, $prod_top + $offset);
-				$pdf->Cell(10, 8, '', 1, 0, 'C'); $pnr ++;
-					
-				$pdf->setXY($prod_left + 10, $prod_top + $offset);
-				$pdf->Cell( ((sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')?87:102), 8, $this->getShippingName($shipping), 1, 0, 'L');
-					
-				if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
-				{
-				
-					if ($this->view['basket']['shipping'][$shipping]['tax_rata'] == 1) { $mwst = __('Anteilig', 'wpsg'); }
-					else { $mwst = wpsg_ff($this->view['basket']['shipping'][$shipping]['mwst'], '%'); }
-					
-					$pdf->setXY($prod_left + 97, $prod_top + $offset);
-					$pdf->Cell(15, 8, $mwst, 1, 0, 'C');
-					
-				}
-				
-				$pdf->setXY($prod_left + 112, $prod_top + $offset);
-				$pdf->Cell(15, 8, '1', 1, 0, 'C');
-					
-				$pdf->setXY($prod_left + 127, $prod_top + $offset);
-				$pdf->Cell(25, 8, wpsg_ff($this->view['basket']['shipping'][$shipping]['preis_shipping_brutto'], $this->get_option('wpsg_currency')), 1, 0, 'R');
-				
-				$pdf->setXY($prod_left + 152, $prod_top + $offset);
-				$pdf->Cell(25, 8, wpsg_ff($this->view['basket']['shipping'][$shipping]['preis_shipping_brutto'], $this->get_option('wpsg_currency')), 1, 0, 'R');
-					
-				$offset += 8;
-				
-			}
-		
-		}
-		*/
-			
-		
 	}
 	
 	// Zahlungskosten
-	if ($this->view['basket']['sum']['preis_payment'] != '' && $this->view['basket']['sum']['preis_payment'] != 0)
+	if ( ($payment_cost != '') && ($payment_cost != 0) )
 	{
 		
@@ -615,15 +521,15 @@
 
 		$pdf->setXY($prod_left + 10, $prod_top + $offset);
-		$pdf->Cell( ((sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')?87:102), 8, $this->arPayment[$this->view['data']['type_payment']]['name'], 1, 0, 'L');
-		
-		if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
-		{
-		
-			if ($this->arPayment[$this->view['data']['type_payment']]['mwst_null'] == '1' && $this->view['basket']['noMwSt'] == '1')
-			{
-				$mwst = 0;
-			}
-			else
-			{
+		$pdf->Cell( (($bTaxCol)?87:102), 8, $this->arPayment[$this->view['data']['type_payment']]['name'], 1, 0, 'L');
+		
+		if ($bTaxCol)
+		{
+		
+			if ($this->arPayment[$this->view['data']['type_payment']]['mwst_null'] == '1' && $bNoTax)
+			{
+
+				$mwst = wpsg_ff(0.00, '%');
+
+			} else {
 				
 				if ($this->view['basket']['arCalculation']['payment'][0]['tax_key'] === '0') {
@@ -649,8 +555,8 @@
 					
 		$pdf->setXY($prod_left + 127, $prod_top + $offset);
-		$pdf->Cell(25, 8, wpsg_ff($this->view['basket']['sum']['preis_payment'], $this->get_option('wpsg_currency')), 1, 0, 'R');
+		$pdf->Cell(25, 8, wpsg_ff($payment_cost, $this->get_option('wpsg_currency')), 1, 0, 'R');
 		
 		$pdf->setXY($prod_left + 152, $prod_top + $offset);
-		$pdf->Cell(25, 8, wpsg_ff($this->view['basket']['sum']['preis_payment'], $this->get_option('wpsg_currency')), 1, 0, 'R');
+		$pdf->Cell(25, 8, wpsg_ff($payment_cost, $this->get_option('wpsg_currency')), 1, 0, 'R');
 		 												
 		$offset += 8;
@@ -671,20 +577,11 @@
 		
 		$pdf->setXY($prod_left + 10, $prod_top + $offset);
-		$pdf->Cell( ((sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')?87:102), 8, $label, 1, 0, 'L');
-		
-		if (sizeof($this->view['basket']['mwst']) >= 1 || $this->get_option('wpsg_showMwstAlways') == '1')
-		{
-		
-			if ($this->view['basket']['noMwSt'] == '1')
-			{
-				$mwst = 0;
-			}
-			else
-			{ 
-				
-				
-				$mwst = wpsg_ff($this->view['storno_fee_tax_value'], '%');
-				
-			}
+		$pdf->Cell( (($bTaxCol)?87:102), 8, $label, 1, 0, 'L');
+		
+		if ($bTaxCol)
+		{
+		
+			if ($bNoTax) $mwst = wpsg_ff(0.00, '%');
+			else $mwst = wpsg_ff($this->view['storno_fee_tax_value'], '%');
 			
 			$pdf->setXY($prod_left + 97, $prod_top + $offset);
@@ -716,57 +613,94 @@
 	}
 	
-	$offset += 10;
-	if ($this->get_option('wpsg_kleinunternehmer'))
-	{
-
+	$offset += 10; // Abstand zwischen Tabelle und Auswertung
+
+	if ( $this->get_option('wpsg_kleinunternehmer') || ($this->view['oCalculationOrder']->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_SMALLBUSINESS) )
+	{
+		
 		$pdf->Text($prod_left, $prod_top + $offset, __("Es ergibt sich folgender Gesamtbetrag", "wpsg").':');
 		$pdf->Text($prod_left + 80, $prod_top + $offset, __("Summe", "wpsg"));
 		$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-		$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['sum']['preis_gesamt_brutto'] + $this->view['basket']['sum']['preis_rabatt'], $this->get_option('wpsg_currency')), 0, 0, 'R');
-		$offset += 5;
-		
-	}
-	else
-	{
-		
-		if ($this->view['basket']['noMwSt'] == '1')
+		$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['arCalculation']['sum']['brutto'] + $this->view['basket']['arCalculation']['sum']['discount_brutto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+		if ( !$bNoTax || ($arCalculation['sum']['topay_brutto'] != $arCalculation['sum']['brutto']) ) $offset += 5;
+
+	} else {
+		
+		if ($bNoTax)
 		{
 			
 			$pdf->Text($prod_left, $prod_top + $offset, __("Es ergibt sich folgender Gesamtbetrag", "wpsg").':');
-			$pdf->Text($prod_left + 80, $prod_top + $offset, __("BRUTTOBETRAG", "wpsg"));
+			$pdf->Text($prod_left + 80, $prod_top + $offset, __("Summe", "wpsg"));
 			$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-			$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['sum']['preis_gesamt_netto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+			$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['arCalculation']['sum']['brutto'] + $this->view['basket']['arCalculation']['sum']['discount_brutto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+			//if ( !$bNoTax || ($arCalculation['sum']['topay_brutto'] != $arCalculation['sum']['brutto']) ) 
 			$offset += 5;
-			
-			$pdf->Text($prod_left + 80, $prod_top + $offset, __("MwSt. GESAMT", "wpsg"));
-			$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-			$pdf->Cell(37, 8, wpsg_ff(0, $this->get_option('wpsg_currency')), 0, 0, 'R');
-					
-		}
-		else  
-		{
-			
-			$pdf->Text($prod_left, $prod_top + $offset, __("Der Gesamtbetrag setzt sich wie folgt zusammen", "wpsg"));
-				 
+
+			if ( !(($this->view['oOrder']->isInnerEu()) && ($this->view['oCalculationOrder']->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_B2B)) ) {
+
+				if (sizeof($this->view['basket']['arCalculation']['tax']) >= 1)
+				{
+
+					$mw_count = 0;
+					foreach ($this->view['basket']['arCalculation']['tax'] as $mw)
+					{
+
+						if ( $mw['tax_value'] > 0 && $mw['sum'] > 0 ) {
+
+							$offset += 5;
+							$pdf->Text($prod_left + 80, $prod_top + $offset, __("MwSt. ", "wpsg").wpsg_ff($mw['tax_value'], '%'));
+							$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
+							$pdf->Cell(37, 8, wpsg_ff($mw['sum'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+						
+							$mw_count++;
+
+						}
+
+					}
+					
+				}
+				
+				if ($mw_count >= 2)
+				{
+					
+					$offset += 5;
+					$pdf->Text($prod_left + 80, $prod_top + $offset, __("MwSt. GESAMT", "wpsg"));
+					$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
+					$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['arCalculation']['sum']['brutto'] - $this->view['basket']['arCalculation']['sum']['netto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+					
+				}
+			
+			} else if ( !($arCalculation['sum']['topay_brutto'] != $arCalculation['sum']['brutto']) ) $offset -= 5; 
+
+		} else {
+			
+			$pdf->Text($prod_left, $prod_top + $offset, __("Der Gesamtbetrag setzt sich wie folgt zusammen", "wpsg").':');
+			
 			$pdf->Text($prod_left + 80, $prod_top + $offset, __("NETTOBETRAG", "wpsg"));
 			$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-			$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['sum']['preis_gesamt_netto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
-							
-			if (sizeof($this->view['basket']['mwst']) >= 1)
-			{
-				
-				foreach ($this->view['basket']['mwst'] as $mw)
+			$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['arCalculation']['sum']['netto'] + $this->view['basket']['arCalculation']['sum']['discount_netto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+			
+			if (sizeof($this->view['basket']['arCalculation']['tax']) >= 1)
+			{
+
+				$mw_count = 0;
+				foreach ($this->view['basket']['arCalculation']['tax'] as $mw)
 				{
-					
-					$offset += 5;
-					$pdf->Text($prod_left + 80, $prod_top + $offset, __("MwSt. ", "wpsg").wpsg_ff($mw['value'], '%'));
-					$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-					$pdf->Cell(37, 8, wpsg_ff($mw['sum'], $this->get_option('wpsg_currency')), 0, 0, 'R');
-					
-				}
-				
-			}
-		 	
-			if (sizeof($this->view['basket']['mwst']) > 1)
+
+					if ( $mw['tax_value'] > 0 && $mw['sum'] > 0) {
+
+						$offset += 5;
+						$pdf->Text($prod_left + 80, $prod_top + $offset, __("MwSt. ", "wpsg").wpsg_ff($mw['tax_value'], '%'));
+						$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
+						$pdf->Cell(37, 8, wpsg_ff($mw['sum'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+					
+						$mw_count++;
+
+					}
+
+				}
+				
+			}
+			
+			if ($mw_count >= 2)
 			{
 				
@@ -774,35 +708,38 @@
 				$pdf->Text($prod_left + 80, $prod_top + $offset, __("MwSt. GESAMT", "wpsg"));
 				$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-				$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['sum']['preis_gesamt_brutto'] - $this->view['basket']['sum']['preis_gesamt_netto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
-			
-			}
-	
-		} 
+				$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['arCalculation']['sum']['brutto'] - $this->view['basket']['arCalculation']['sum']['netto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+				
+			}
+			
+		}
 		
 	}
 	
 	// Rabatt
-	if ($this->view['basket']['sum']['preis_rabatt'] > 0)
+	if ($discount_value > 0)
 	{
 		
 		$offset += 5;
-		
 		$pdf->Text($prod_left + 80, $prod_top + $offset, __("Rabatt", "wpsg"));
 		$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-		$pdf->Cell(37, 8, '-'.wpsg_ff($this->view['basket']['sum']['preis_rabatt'], $this->get_option('wpsg_currency')), 0, 0, 'R');
-		
-	}
-	
+		$pdf->Cell(37, 8, '-'.wpsg_ff($discount_value, $this->get_option('wpsg_currency')), 0, 0, 'R');
+		
+	}
+
 	// Wertgutschein
-	if ($arCalculation['sum']['topay_brutto'] !== $arCalculation['sum']['brutto']) {
-		
-		$offset += 5;
-		$pdf->Text($prod_left + 80, $prod_top + $offset, __("Bruttobetrag", "wpsg"));
-		$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-		
-		$pdf->setFont('Arial', '', '9');
-		$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['sum']['preis_gesamt_brutto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
-		$pdf->setFont('Arial', '', '9');
-		
+	if ( $arCalculation['sum']['topay_brutto'] != $arCalculation['sum']['brutto'] ) {
+
+		if (!$bNoTax) {
+		
+			$offset += 5;
+			$pdf->Text($prod_left + 80, $prod_top + $offset, __("SUMME", "wpsg"));
+			$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
+			
+			$pdf->setFont('Arial', '', '9');
+			$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['arCalculation']['sum']['brutto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+			$pdf->setFont('Arial', '', '9');
+		
+		} else if (!($mw_count >= 2)) $offset -= 5;
+
 		foreach ($arCalculation['coupon'] as $c) {
 			
@@ -819,5 +756,5 @@
 		$offset += 5;
 		$pdf->setFont('Arial', 'B', '9');
-		$pdf->Text($prod_left + 80, $prod_top + $offset, __("SUMME", "wpsg"));
+		$pdf->Text($prod_left + 80, $prod_top + $offset, __("ZU ZAHLEN", "wpsg"));
 		$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
 		
@@ -828,82 +765,79 @@
 		
 	} else {
-	
+
 		$offset += 5;
-		$pdf->Text($prod_left + 80, $prod_top + $offset, __("SUMME", "wpsg"));
+		$pdf->setFont('Arial', 'B', '9');
+		$pdf->Text($prod_left + 80, $prod_top + $offset, __("GESAMTSUMME", "wpsg"));
 		$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-	
+		
 		/* Endbetrag wird fett ausgegeben */
-		$pdf->setFont('Arial', 'B', '9');
-		$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['sum']['preis_gesamt_brutto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+		$pdf->Cell(37, 8, wpsg_ff($arCalculation['sum']['topay_brutto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
 		$pdf->setFont('Arial', '', '9');
-			
-		/* Endbetrag wird normal ausgegeben */
-		//$pdf->Cell(37, 8, wpsg_ff($this->view['basket']['sum']['preis_gesamt_brutto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
-		
-	}
-	
-	if ($this->get_option('wpsg_kleinunternehmer') == '1')
-	{
- 
-		$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset + 5, 5, $this->get_option('wpsg_kleinunternehmer_text')); 
-		$offset += 15;
-		
-	}
-	
-	if ($this->hasMod('wpsg_mod_deliverynote'))
+				
+	}
+	
+	if (($this->get_option('wpsg_kleinunternehmer') == '1') || ($this->view['oCalculationOrder']->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_SMALLBUSINESS) )
+	{
+
+		$offset += 3;
+		$pdf->setFont('Arial', '', '8');
+		$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset, 5, '('.$this->get_option('wpsg_kleinunternehmer_text').')');
+		$offset += 8;
+		
+	}
+
+	$offset += 5;
+	
+	if ($this->hasMod('wpsg_mod_deliverynote') && ($this->get_option('wpsg_rechnungen_deliverynote') == '1'))
 	{
 		
 		$arDN_order = $this->callMod('wpsg_mod_deliverynote', 'loadDeliveryNotesFromOrder', array($this->view['data']['id']));
 		$delivery_date = $this->callMod('wpsg_mod_deliverynote', 'getDeliveryTime', array($this->view['data']['id']));
-		
+
 		// Wenn es ein Gesamtlieferdatum gibt und nur einen Lieferschein, dann unter der Bestellung anzeigen
 		if ($delivery_date !== false && sizeof($arDN_order) == 1)
 		{
 			
-			$offset += 10; 
-			
-			$pdf->wpsg_MultiCell($prod_left, $prod_top + $offset, 5, wpsg_translate(__('Lieferung: #1#', 'wpsg'), date('d.m.Y', $delivery_date)));
-
-			$offset += 5;
-			
-		}
-		
-	}
-	
-	$offset += 5;
-	
+			$pdf->setFont('Arial', 'B', '9');
+			$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset, 5, __('Lieferung:', 'wpsg'));
+			$pdf->setFont('Arial', '', '9');
+			$pdf->wpsg_MultiCell($prod_left + 16, $prod_top + $offset, 5, wpsg_translate(__('#1#', 'wpsg'), date('d.m.Y', $delivery_date)));
+			$offset += 8;
+			
+		}
+		
+	}
+
 	if ($this->view['fussText'] != "")
 	{
-	
-		//$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset, 5, utf8_encode($this->view['fussText']));		
+		
+		$pdf->setFont('Arial', '', '9');	
 		$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset, 5, $this->view['fussText']);
-		$pdf->SetFont('Arial', 'B', 9);
-		$offset += 10;	
-		
-	}
-	
+		$offset += 8;
+		
+	}
+	
+	$offset += 10;
+
 	$shipping_adress = false;
-
-	if ($this->hasMod('wpsg_mod_shippingadress') && $this->callMod('wpsg_mod_shippingadress', 'check_different_shippingadress', array('k_id' => $this->view['data']['k_id'], 'o_id' => $this->view['data']['id'])))
-	{
- 
+	if ($this->hasMod('wpsg_mod_shippingadress') && $this->callMod('wpsg_mod_shippingadress', 'check_different_shippingadress', array('k_id' => $this->view['data']['k_id'], 'o_id' => $this->view['data']['id']))) {
+		
 		$pdf->setFont('Arial', 'B', 9);
 		$pdf->Text($prod_left, $prod_top + $offset, __("Lieferanschrift", "wpsg").":");
-		$offset += 5;
-		
-		$pdf->setFont('Arial', '', 9);		
-		
-		$shipping_adress = "";
-		if ($this->view['data']['shipping_firma'] != "")
-		{
-			$shipping_adress .= $this->view['data']['shipping_firma']."\r\n";
-		}
-		$shipping_adress .= $this->view['data']['shipping_vname'].' '.$this->view['data']['shipping_name']."\r\n";
-		$shipping_adress .= $this->view['data']['shipping_strasse']."\r\n";
-		//$shipping_adress .= $this->view['data']['shipping_land']['kuerzel'].'-';
-		
-		$shipping_adress .= $this->view['data']['shipping_plz'].' '.$this->view['data']['shipping_ort']."\r\n";
-		$shipping_adress .= $this->view['data']['shipping_land']['name'];
-		
+		$offset += 2;
+		
+		$pdf->setFont('Arial', '', 9);
+		
+			$shipping_adress = "";
+			if ($this->view['data']['shipping_firma'] != "")
+			{
+				$shipping_adress .= $this->view['data']['shipping_firma']."\r\n";
+			}
+			$shipping_adress .= $this->view['data']['shipping_vname'].' '.$this->view['data']['shipping_name']."\r\n";
+			$shipping_adress .= $this->view['data']['shipping_strasse'].' '.$this->view['data']['shipping_nr']."\r\n";
+			// $shipping_adress .= $this->view['data']['shipping_land']['kuerzel'].'-';
+			
+			$shipping_adress .= $this->view['data']['shipping_plz'].' '.$this->view['data']['shipping_ort']."\r\n";
+			$shipping_adress .= $this->view['data']['shipping_land']['name'];	
 		
 		$start = $pdf->getY();
@@ -914,45 +848,44 @@
 		
 	}
-		
-	
-	$offset += 5;
-	 
+		 
 	// Bestellvariablen
 	if ($this->hasMod('wpsg_mod_ordervars') && $this->get_option('wpsg_mod_rechnungen_showov') == '1')
 	{
-		
-		$bvars = @unserialize($this->view['data']['bvars']);		
-		if (!is_array($bvars)) $bvars = array();
-		
-		$strBVars = "";
-		foreach ($bvars as $bvars_id => $bvars_value)
-		{
-				
-			$bvars = $this->db->fetchRow("SELECT * FROM `".wpsg_q(WPSG_TBL_ORDERVARS)."` WHERE `id` = '".wpsg_q($bvars_id)."' ORDER BY `pos` ASC, `id` ASC ");
-			
-			if ($bvars['typ'] == "1") // Auswahl
-			{
-				if ($bvars_value <= 0) $bvars_value = __("Keine Angabe", "wpsg");
-			}
-			else if ($bvars['typ'] == "2") // Texteingabe
-			{
-				if (trim($bvars_value) == "") $bvars_value = __("Keine Angabe", "wpsg");
-			}
-			else if ($bvars['typ'] == "3") // Checkbox
-			{
-				if ($bvars_value <= 0) $bvars_value = __("Keine Angabe", "wpsg");					
-			}
-			
-			$bvars_name = $this->callMod('wpsg_mod_ordervars', 'getNameById', array($bvars_id));			
-			$strBVars .= "\r\n".$bvars_name.": ".$bvars_value;	
-			
-		}
-		
-		$pdf->SetFont('Arial', 'B', 9);	
-		$pdf->Text($prod_left, $prod_top + $offset, __("Angaben wÃ€hrend der Bestellung", "wpsg").":");
+
+		$pdf->SetFont('Arial', 'B', 9);
+		$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset - 7, 5, __("Angaben wÃ€hrend der Bestellung", "wpsg").":");
+		
 		$pdf->SetFont('Arial', '', 9);
-		$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset, 5, $strBVars);
-		
-	}  
+
+			$bvars = @unserialize($this->view['data']['bvars']);
+			if (!is_array($bvars)) $bvars = array();
+			
+			$strBVars = "";
+			foreach ($bvars as $bvars_id => $bvars_value)
+			{
+				
+				$bvars = $this->db->fetchRow("SELECT * FROM `".wpsg_q(WPSG_TBL_ORDERVARS)."` WHERE `id` = '".wpsg_q($bvars_id)."' ORDER BY `pos` ASC, `id` ASC ");
+				
+				if ($bvars['typ'] == "1") // Auswahl
+				{
+					if ($bvars_value <= 0) $bvars_value = __("Keine Angabe", "wpsg");
+				}
+				else if ($bvars['typ'] == "2") // Texteingabe
+				{
+					if (trim($bvars_value) == "") $bvars_value = __("Keine Angabe", "wpsg");
+				}
+				else if ($bvars['typ'] == "3") // Checkbox
+				{
+					if ($bvars_value <= 0) $bvars_value = __("Keine Angabe", "wpsg");
+				}
+				
+				$bvars_name = $this->callMod('wpsg_mod_ordervars', 'getNameById', array($bvars_id));
+				$strBVars .= "\r\n".$bvars_name.": ".$bvars_value;
+				
+			}
+		
+		$pdf->wpsg_MultiCell($prod_left - 1, $prod_top + $offset - 6, 5, $strBVars);
+
+	}
 	
 	if (!file_exists($this->callMod('wpsg_mod_rechnungen', 'getFilePath', array($this->view['data']['id']))))
@@ -968,4 +901,7 @@
 
     ob_end_clean();
+
+	wpsg_debug($pdf->Output($filename, 'I'));
+	die();
 
 	if ($this->view['preview']) {
@@ -981,3 +917,4 @@
 			
 	} 
-	 
+
+?>
