Index: /controller/wpsg_OrderController.class.php
===================================================================
--- /controller/wpsg_OrderController.class.php	(revision 8064)
+++ /controller/wpsg_OrderController.class.php	(revision 8065)
@@ -96,9 +96,9 @@
 		    $oCalculation = new \wpsg\wpsg_calculation();
 		    $oCalculation->fromDB($_REQUEST['edit_id']);
-		     
+			
             $oCalculation->addShipping(
 				$_REQUEST['shipping_price'],
 				$this->shop->getBackendTaxview(),
-                $this->shop->arShipping[$_REQUEST['shipping_key']]['mwst_key'],
+                $this->shop->arShipping[$_REQUEST['shipping_key']]['tax_key'],
 				$_REQUEST['shipping_key']
             );
@@ -107,5 +107,5 @@
                 $_REQUEST['payment_price'],
 				$this->shop->getBackendTaxview(),
-                $this->shop->arPayment[$_REQUEST['payment_key']]['mwst_key'],
+                $this->shop->arPayment[$_REQUEST['payment_key']]['tax_key'],
 				$_REQUEST['payment_key']
             );
@@ -1289,5 +1289,5 @@
                     $oCalculation = new \wpsg\wpsg_calculation();
                     $oCalculation->fromDB($_REQUEST['edit_id']);
-
+					
                     $order_product_id = ((wpsg_isSizedInt($_REQUEST['order_product_id']))?$_REQUEST['order_product_id']:false);
 		            $oProduct = wpsg_product::getInstance($_REQUEST['product_id']);
Index: /lib/wpsg_calculation.class.php
===================================================================
--- /lib/wpsg_calculation.class.php	(revision 8064)
+++ /lib/wpsg_calculation.class.php	(revision 8065)
@@ -73,4 +73,10 @@
         	return $this->tax_mode; 
         	
+		}
+		
+		public function getCountry(): array {
+			
+			return $this->arCountry;
+			
 		}
 		
@@ -302,4 +308,6 @@
         public function addProduct($set, $bruttonetto, $tax_key, $amount, $product_key, $product_index = false, $order_product_id = false, $eu = false, $ses_data = false) {
 	
+			// wpsg_debug($set.": ".$bruttonetto.":".$tax_key.":".$amount);
+			
 			$targetCountry = false; 
 			
@@ -636,4 +644,7 @@
 					$country_id = $this->getTargetCountry()['id'];
 	
+					$netto_calculated_single = $netto;
+					$brutto_calculated_single = $brutto;
+					
 					if ($this->arCountry[$country_id]['tax_mode'] == '1') {
 	
@@ -689,4 +700,6 @@
 						'netto' => $netto,
 						'brutto' => $brutto,
+						'netto_calculated_single' => $netto_calculated_single,
+						'brutto_calculated_single' => $brutto_calculated_single,
 						'netto_single' => $netto_single,
 						'brutto_single' => $brutto_single,
@@ -698,6 +711,13 @@
 					];
 					
+					$this->arCalculationRow[$k_cr]['netto_calculated_single'] = $netto_calculated_single;
+					$this->arCalculationRow[$k_cr]['brutto_calculated_single'] = $brutto_calculated_single;
+					
 					wpsg_addSet($this->arCalculation['sum'][$cr['type'].'_netto'],$netto);
 					wpsg_addSet($this->arCalculation['sum'][$cr['type'].'_brutto'],$brutto);
+					
+					wpsg_addSet($this->arCalculation['sum'][$cr['type'].'_netto_calculated'],$netto_calculated_single * $cr['amount']);
+					wpsg_addSet($this->arCalculation['sum'][$cr['type'].'_brutto_calculated'],$brutto_calculated_single * $cr['amount']);
+					
 					wpsg_addSet($this->arCalculation['sum'][$cr['type'].'_tax'],$tax);
 					
@@ -859,4 +879,6 @@
             }
 
+			//wpsg_debug($this->arCalculation);
+			
             return $this->arCalculation;
 
@@ -946,5 +968,5 @@
             	    if (is_array($cr['set'])) $shipping_set = implode('#', $cr['set']);
             	    else $shipping_set = $cr['set'];
-
+					
             		$db_data['shipping_set'] = wpsg_q($shipping_set);
 					$db_data['shipping_key'] = wpsg_q($cr['data']['shipping_key']);
@@ -952,7 +974,7 @@
 					$db_data['shipping_tax_key'] = wpsg_q($this->clearTaxKey($cr['tax_key']));
 					$db_data['type_shipping'] = wpsg_q($cr['data']['shipping_key']);
-					$db_data['price_shipping'] = wpsg_q($arCalculation['sum']['shipping_'.$display]);
-					$db_data['price_shipping_netto'] = wpsg_q($arCalculation['sum']['shipping_netto']);
-					$db_data['price_shipping_brutto'] = wpsg_q($arCalculation['sum']['shipping_brutto']);
+					$db_data['price_shipping'] = wpsg_q($arCalculation['sum']['shipping_'.$display.'_calculated']??$arCalculation['sum']['shipping_'.$display]);
+					$db_data['price_shipping_netto'] = wpsg_q($arCalculation['sum']['shipping_netto_calculated']??$arCalculation['sum']['shipping_netto']);
+					$db_data['price_shipping_brutto'] = wpsg_q($arCalculation['sum']['shipping_brutto_calculated']??$arCalculation['sum']['shipping_brutto']);
 					$db_data['mwst_shipping'] = wpsg_q($arCalculation['sum']['shipping_brutto'] - $arCalculation['sum']['shipping_netto']);
             		
@@ -1073,6 +1095,6 @@
 					'product_index' => wpsg_q($p['product_index']),
 					'menge' => wpsg_q($p['amount']),
-					'price_netto' => wpsg_q($p['netto_single']),
-					'price_brutto' => wpsg_q($p['brutto_single']),
+					'price_netto' => wpsg_q($p['netto_calculated_single']??$p['netto_single']),
+					'price_brutto' => wpsg_q($p['brutto_calculated_single']??$p['brutto_single']),
 					'price' => wpsg_q($p[$display]),
 					'mwst_value' => wpsg_q($p['brutto_single'] - $p['netto_single']),
@@ -1256,5 +1278,14 @@
             foreach ($db_products as $db_p) {
             	
-                $this->addProduct($db_p['product_set'], $db_p['product_bruttonetto'], $db_p['mwst_key'], $db_p['menge'],$db_p['productkey'], $db_p['product_index'], $db_p['id'], (($db_p['euleistungsortregel'] === '1')?true:false));
+                $this->addProduct(
+					$db_p['product_set'], 
+					$db_p['product_bruttonetto'], 
+					$db_p['mwst_key'], 
+					$db_p['menge'],
+					$db_p['productkey'], 
+					$db_p['product_index'], 
+					$db_p['id'], 
+					(($db_p['euleistungsortregel'] === '1')?true:false)
+                );
                 
             }
@@ -1730,4 +1761,13 @@
 		}
 		
+		public function getPaymentSum($bruttonetto = WPSG_NETTO) {
+		
+			$arCalculation = $this->getCalculationArray();
+			
+			if ($bruttonetto === WPSG_BRUTTO) return $arCalculation['sum']['payment_brutto'];
+			else return $arCalculation['sum']['payment_netto'];
+						
+		}
+		
 		public function getSum($bruttonetto = WPSG_NETTO) {
 
Index: /mods/wpsg_mod_rechnungen.class.php
===================================================================
--- /mods/wpsg_mod_rechnungen.class.php	(revision 8064)
+++ /mods/wpsg_mod_rechnungen.class.php	(revision 8065)
@@ -1266,14 +1266,35 @@
 			$oCalculation = new \wpsg\wpsg_calculation();			
 			$oCalculationOrder = \wpsg\wpsg_calculation::getOrderCalculation($order_id);
+						
+			$oCalculation->setTaxMode($oCalculationOrder->getTaxMode());
+			
+			foreach ($oCalculationOrder->getCountry() as $country) {
+			
+				$oCalculation->addCountry(
+					$country['id'],
+					$country['tax_mode'],
+					$country['a_'.$country['id']],
+					$country['b_'.$country['id']],
+					$country['c_'.$country['id']],
+					$country['d_'.$country['id']],					
+					$country['default'],
+				);
+				
+			}
 			
 			if (intval($_REQUEST['wpsg_rechnungen_discount_voucher_coupon']??0) > 0) {
 				
 				$discount = $oCalculationOrder->getDiscount();
-				if ($discount !== null) $oCalculation->addDiscount(
-					$discount['set'], 
-					$discount['bruttonetto'], 
-					$discount['tax_key'], 
-					$discount['amount']
-				);
+				
+				if ($discount !== null) {
+					
+					$oCalculation->addDiscount(
+						$discount['set'], 
+						$discount['bruttonetto'], 
+						$discount['tax_key'], 
+						$discount['amount']
+					);
+
+				}
 				
 				$arVoucher = $oCalculationOrder->getVoucher();
@@ -1317,6 +1338,5 @@
 			}
 			
-			$oDefaultCountry = $oOrder->getInvoiceCountry();			
-			$oCalculation->addCountry($oDefaultCountry->id, $oDefaultCountry->mwst, $oDefaultCountry->mwst_a,$oDefaultCountry->mwst_b, $oDefaultCountry->mwst_c, $oDefaultCountry->mwst_d, true);
+			// $oCalculation->addCountry($oDefaultCountry->id, $oDefaultCountry->mwst, $oDefaultCountry->mwst_a,$oDefaultCountry->mwst_b, $oDefaultCountry->mwst_c, $oDefaultCountry->mwst_d, true);
 						
 			$arProduct = [];
@@ -1328,5 +1348,5 @@
 				if ($order_product_info['set'] === '1') {
 					
-					$oOrderProduct = wpsg_order_product::getInstance($order_product_id);
+					$oOrderProduct = wpsg_order_product::getInstance($order_product_id, true);
 					
 					$oCalculation->addProduct(
@@ -1354,4 +1374,10 @@
 					];
 					
+					if ($oCalculationOrder->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_B2B) {
+						
+						$p['preis_brutto'] = $p['preis_netto'];
+						
+					}
+					
 					// Ãbersetzung
 					if ($this->shop->isOtherLang()) {
@@ -1374,7 +1400,9 @@
 				
 			}
-									
+							
 			if (($_REQUEST['wpsg_rechnungen_shippay']??'0') === '1') {
-				 
+				
+				//die($oOrder->__get('shipping_bruttonetto')."=".$oOrder->__get('shipping_set'));
+				
 				$oCalculation->addShipping(
 					$oOrder->__get('shipping_set'), 
@@ -1392,4 +1420,6 @@
 				
 			}
+			
+			//die(wpsg_debug($oCalculation->getCalculationArray()));
 			
 			$this->shop->view['basket'] = [
@@ -1402,5 +1432,5 @@
 				'mwst' => []
 			];
-			 
+			 			
 			// Die Templates brauchen es leider noch etwas anders
 			foreach ($this->shop->view['basket']['arCalculation']['tax'] as $tax_key => $tax) {
@@ -1419,5 +1449,5 @@
 			if ($this->shop->view['basket']['arCalculation']['sum']['discount_netto'] < 0) {
 				
-				if ($this->shop->getFrontendTaxview() === WPSG_NETTO)
+				if ($this->shop->getFrontendTaxview() === WPSG_NETTO || $oCalculation->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_B2C)
 					$this->shop->view['basket']['sum']['preis_rabatt'] = -1 * $this->shop->view['basket']['arCalculation']['sum']['discount_netto'];
 				else
@@ -1429,4 +1459,5 @@
 				
 				$this->shop->view['basket']['sum']['preis_shipping'] = $oCalculation->getShippingSum(WPSG_BRUTTO);
+				$this->shop->view['basket']['sum']['preis_payment'] = $oCalculation->getPaymentSum(WPSG_BRUTTO);
 				
 			}
@@ -2261,8 +2292,10 @@
  			$customer_data = $this->shop->cache->loadKunden($order_data['k_id']);
  			
-			$oOrder = wpsg_order::getInstance($order_id);
+			$oOrder = wpsg_order::getInstance($order_id, true);
 			 
 			$_REQUEST['invoice_products'] = [];
 			$_REQUEST['wpsg_rechnungen_datum'] = date('Y-m-d');
+			$_REQUEST['wpsg_rechnungen_discount_voucher_coupon'] = '1';
+			$_REQUEST['wpsg_rechnungen_shippay'] = '1';
 			
 			// Komplettauswahl simulieren
Index: /views/mods/mod_rechnungen/invoice_pdf.phtml
===================================================================
--- /views/mods/mod_rechnungen/invoice_pdf.phtml	(revision 8064)
+++ /views/mods/mod_rechnungen/invoice_pdf.phtml	(revision 8065)
@@ -311,10 +311,10 @@
 		//$height += 3 + 5 + $pdf->getY() - $height_y;
 		//$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') {
 			
 			$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');
-			
+
 		}
 		
@@ -322,13 +322,12 @@
 		$pdf->Cell(15, 8, $p['menge'], 0, 0, 'C');
 		
-		if (wpsg_ShopController::get_option('wpsg_preisangaben') == WPSG_NETTO)
-		{
+		if (wpsg_ShopController::get_option('wpsg_preisangaben') == WPSG_NETTO) {
+			
 			$preis = $p['preis_netto'];
 			
-			//TODO
-		}
-		else
-		{
+		} else {
+			
 			$preis = $p['preis_brutto'];
+			
 		}
 		
Index: /views/order/backendEdit/editPayShipping.phtml
===================================================================
--- /views/order/backendEdit/editPayShipping.phtml	(revision 8064)
+++ /views/order/backendEdit/editPayShipping.phtml	(revision 8065)
@@ -35,6 +35,6 @@
     if ($this->getBackendTaxview() === WPSG_BRUTTO) {
         
-    	$price_shipping = wpsg_ff(wpsg_getInt($arCalculation['shipping'][0]['brutto_single']), $this->get_option('wpsg_currency'));
-		$price_payment = wpsg_ff(wpsg_getInt($arCalculation['payment'][0]['brutto_single']), $this->get_option('wpsg_currency'));
+    	$price_shipping = wpsg_ff($arCalculation['shipping'][0]['brutto_calculated_single']??0, $this->get_option('wpsg_currency'));
+		$price_payment = wpsg_ff($arCalculation['payment'][0]['brutto_single_calculated']??0, $this->get_option('wpsg_currency'));
     	         
         $price_suffix = ' ('.__('Brutto', 'wpsg').')';
@@ -42,6 +42,6 @@
     } else {
 	
-		$price_shipping = wpsg_ff(wpsg_getInt($arCalculation['shipping'][0]['netto_single']), $this->get_option('wpsg_currency'));
-		$price_payment = wpsg_ff(wpsg_getInt($arCalculation['payment'][0]['netto_single']), $this->get_option('wpsg_currency'));
+		$price_shipping = wpsg_ff($arCalculation['shipping'][0]['netto_calculated_single']??0, $this->get_option('wpsg_currency'));
+		$price_payment = wpsg_ff($arCalculation['payment'][0]['netto_calculated_single']??0, $this->get_option('wpsg_currency'));
 
         $price_suffix = ' ('.__('Netto', 'wpsg').')';
@@ -52,5 +52,5 @@
 
 <div id="editPayShipping">
-    
+    <?php wpsg_debug($price_shipping); ?>
     <?php echo wpsg_drawForm_Select('edit_shipping_type', __('Versandart', 'wpsg'), $arShippingSelect,$this->view['data']['type_shipping']); ?>
     <?php echo wpsg_drawForm_Input('edit_shipping_price', __('Kosten', 'wpsg').$price_suffix, $price_shipping);  ?> 
Index: /views/order/view_orderdata.phtml
===================================================================
--- /views/order/view_orderdata.phtml	(revision 8064)
+++ /views/order/view_orderdata.phtml	(revision 8065)
@@ -9,5 +9,15 @@
 ?>
 <div id="wpsg_produkte_table">
-
+    
+    <?php
+
+        // $oCalculation = new \wpsg\wpsg_calculation();
+        // $oCalculation->fromDB(525);        
+        // $oCalculation->addProduct($_REQUEST['add_price'], $this->shop->getBackendTaxview(), $oProduct->mwst_key, $_REQUEST['add_amount'], $product_key, $product_index, $order_product_id, $eu);        
+        // wpsg_debug($oCalculation->getCalculationArray()['product']);        
+        // die();
+        
+    ?>
+    
 	<?php echo wpsg_drawForm_AdminboxStart(__('Bestelldaten', 'wpsg')); ?>
     
