Index: /controller/wpsg_OrderController.class.php
===================================================================
--- /controller/wpsg_OrderController.class.php	(revision 7209)
+++ /controller/wpsg_OrderController.class.php	(revision 7210)
@@ -192,4 +192,5 @@
 
                 $oCustomer = wpsg_customer::getInstance($customer_id);
+				$oDefaultCountry = $this->shop->getDefaultCountry();                
                 
                 $order_id = $this->db->ImportQuery(WPSG_TBL_ORDER, Array(
@@ -199,5 +200,12 @@
                     'cdate' => 'NOW()',
                     'adress_id' => wpsg_q($oCustomer->adress_id),
-                    'k_id' => wpsg_q($customer_id)                    
+                    'k_id' => wpsg_q($customer_id),
+					'calculation' => '1',
+					'shop_country_id' => wpsg_q($oDefaultCountry->id),
+					'shop_country_tax' => wpsg_q($oDefaultCountry->mwst),
+					'shop_country_tax_a' => wpsg_q($oDefaultCountry->mwst_a),
+					'shop_country_tax_b' => wpsg_q($oDefaultCountry->mwst_b),
+					'shop_country_tax_c' => wpsg_q($oDefaultCountry->mwst_c),
+					'shop_country_tax_d' => wpsg_q($oDefaultCountry->mwst_d)
                 ));
                                                  
@@ -913,38 +921,5 @@
 
 				parse_str($_REQUEST['form_data'], $form_data);
-
-				/* TODO alt
-				$k_id = $this->db->fetchOne("SELECT `k_id` FROM `".WPSG_TBL_ORDER."` WHERE `id` = '".wpsg_q($_REQUEST['edit_id'])."' ");
-
-				$this->db->UpdateQuery(WPSG_TBL_KU, array(
-					'firma' => wpsg_q($form_data['dialog_firma']),
-					'title' => wpsg_q($form_data['dialog_title']),
-					'vname' => wpsg_q($form_data['dialog_vname']),
-					'name' => wpsg_q($form_data['dialog_name']),
-					'strasse' => wpsg_q($form_data['dialog_strasse']),
-					'plz' => wpsg_q($form_data['dialog_plz']),
-					'ort' => wpsg_q($form_data['dialog_ort']),
-					'land' => wpsg_q($form_data['dialog_land'])
-				), " `id` = '".wpsg_q($k_id)."' ");
-				*/
-
-				/*
-				$a_id = $this->db->fetchOne("SELECT `adress_id` FROM `".WPSG_TBL_ORDER."` WHERE `id` = '".wpsg_q($_REQUEST['edit_id'])."' ");
-
-				if ($a_id > 0) {
-					$this->db->UpdateQuery(WPSG_TBL_ADRESS, array(
-						'firma' => wpsg_q($form_data['dialog_firma']),
-						'title' => wpsg_q($form_data['dialog_title']),
-						'vname' => wpsg_q($form_data['dialog_vname']),
-						'name' => wpsg_q($form_data['dialog_name']),
-						'strasse' => wpsg_q($form_data['dialog_strasse']),
-						'plz' => wpsg_q($form_data['dialog_plz']),
-						'ort' => wpsg_q($form_data['dialog_ort']),
-						'land' => wpsg_q($form_data['dialog_land'])
-					), " `id` = '".wpsg_q($a_id)."' ");
-				}
-				*/
-
-
+ 
 				if (wpsg_isSizedInt($form_data['dialog_all']))
 				{
@@ -994,20 +969,19 @@
 					if (wpsg_isSizedInt($form_data['dialog_shipping']))
 					{
+						
 						$oOrder->updateShippingAdress($adress_data);
 
-						/* TODO alt
-						$this->db->UpdateQuery(WPSG_TBL_ORDER, array(
-							'shipping_firma' => wpsg_q($form_data['dialog_firma']),
-							'shipping_title' => wpsg_q($form_data['dialog_title']),
-							'shipping_vname' => wpsg_q($form_data['dialog_vname']),
-							'shipping_name' => wpsg_q($form_data['dialog_name']),
-							'shipping_strasse' => wpsg_q($form_data['dialog_strasse']),
-							'shipping_plz' => wpsg_q($form_data['dialog_plz']),
-							'shipping_ort' => wpsg_q($form_data['dialog_ort']),
-							'shipping_land' => wpsg_q($form_data['dialog_land'])
-						), " `id` = '".wpsg_q($_REQUEST['edit_id'])."' ");
-						*/
+					} 
+					
+					if ($order_id == $_REQUEST['edit_id']) {
+						
+						$this->db->UpdateQuery(WPSG_TBL_KU, [
+							'ustidnr' => wpsg_q($form_data['dialog_ustidnr'])
+						], " `id` = '".wpsg_q($oOrder->getCustomer()->id)."' ");
+						
 					}
-				}
+					
+				}
+				
 				die("1");
 
@@ -1129,5 +1103,20 @@
 		{
 			 
-		    if (wpsg_isSizedString($_REQUEST['subaction'], 'removeProduct')) {
+			if (wpsg_isSizedString($_REQUEST['subaction'], 'updateCalculation')) {
+				
+				$oCalculation = new \wpsg\wpsg_calculation();
+				$oCalculation->fromDB($_REQUEST['edit_id']);
+				
+				$oCalculation->setTaxMode($_REQUEST['tax_mode']);
+				
+				$oCalculation->toDB($_REQUEST['edit_id']);
+				
+				$this->shop->view['oCalculation'] = $oCalculation;
+				
+				wpsg_header::JSONData([
+					'product_table' => $this->shop->render(WPSG_PATH_VIEW.'order/product_table.phtml', false)
+				]);
+				
+			} else if (wpsg_isSizedString($_REQUEST['subaction'], 'removeProduct')) {
 
                 $oCalculation = new \wpsg\wpsg_calculation();
@@ -1264,5 +1253,19 @@
 
                     exit;
-                                    
+                    
+				} else if (wpsg_isSizedString($_REQUEST['do'], 'updatePrice')) {
+			
+		        	parse_str($_REQUEST['form_data'], $form_data);
+		        	
+					$product_key = $_REQUEST['product_id'];					
+					$this->shop->callMods('getProductKeyFromRequest',[&$product_key, $_REQUEST['product_id'], $form_data]);
+					
+					$arProduct = $this->shop->loadProduktArray($_REQUEST['product_id'],['product_key' => $product_key]);
+					 
+					if ($this->shop->getBackendTaxview() === WPSG_BRUTTO) echo wpsg_ff($arProduct['preis'], 'EUR');
+					else echo wpsg_ff($arProduct['preis_netto'], 'EUR');
+					
+					exit;
+		        	
                 } else if (wpsg_isSizedString($_REQUEST['do'], 'product')) {
 
@@ -1296,6 +1299,12 @@
                     $order_product_id = ((wpsg_isSizedInt($_REQUEST['order_product_id']))?$_REQUEST['order_product_id']:false);
 		            $oProduct = wpsg_product::getInstance($_REQUEST['product_id']);
-					 
-					$oCalculation->addProduct($_REQUEST['add_price'], $this->shop->getBackendTaxview(), $oProduct->mwst_key, $_REQUEST['add_amount'], $_REQUEST['product_id'], false, $order_product_id);
+					
+		            $product_key = $_REQUEST['product_id'];					
+		            $this->shop->callMods('getProductKeyFromRequest',[&$product_key, $_REQUEST['product_id'], $_REQUEST]);
+		            
+		            if ($_REQUEST['add_eu'] === '1') $eu = true;
+		            else $eu = false;
+		            
+					$oCalculation->addProduct($_REQUEST['add_price'], $this->shop->getBackendTaxview(), $oProduct->mwst_key, $_REQUEST['add_amount'], $product_key, false, $order_product_id, $eu);
 			
 					$oCalculation->toDB($_REQUEST['edit_id']);
@@ -1449,5 +1458,5 @@
 			else
 			{
-                
+				
 				$this->shop->render(WPSG_PATH_VIEW.'/order/view.phtml');
 
Index: /lib/filter_functions.inc.php
===================================================================
--- /lib/filter_functions.inc.php	(revision 7209)
+++ /lib/filter_functions.inc.php	(revision 7210)
@@ -81,5 +81,5 @@
             //if (strpos($_SERVER['REQUEST_URI'], 'network') !== false) echo 'network';
             //if ($GLOBALS['wpsg_sc']->bLicence === true) echo 'licence';    
-            
+			
             if ($GLOBALS['wpsg_sc']->bLicence === true)
             {
Index: /lib/install.php
===================================================================
--- /lib/install.php	(revision 7209)
+++ /lib/install.php	(revision 7210)
@@ -133,5 +133,5 @@
    		dp_cron_planed datetime NOT NULL,
    		dp_cron_done datetime NOT NULL,   		 
-   		kleinunternehmer INT(1) NOT NULL,
+   		kleinunternehmer INT(1) NOT NULL COMMENT 'DEPRECATED Durch taxmode ersetzt',
    		custom_data MEDIUMBLOB NOT NULL,
    		admincomment TEXT NOT NULL,
@@ -186,4 +186,6 @@
    		target_country_tax_c INT(1) COMMENT 'Steuersatz C',
    		target_country_tax_d INT(1) COMMENT 'Steuersatz D',
+   		calculation INT(1) COMMENT '1 wenn die Bestellung mit der neuen Calculation Klasse berechnet wurde',
+   		tax_mode INT(1) COMMENT 'Art der Besteuerung Kleinunternehmer/1, Endkunden/2, Firmenkunden/3',
    		KEY adress_id (adress_id),
    		KEY shipping_adress_id (shipping_adress_id),
@@ -216,4 +218,5 @@
 		allowedpayments VARCHAR( 255 ) NOT NULL, 
 		allowedshipping VARCHAR( 255 ) NOT NULL,
+		euleistungsortregel INT(1) NOT NULL,
 		PRIMARY KEY  (id),
    		KEY o_id (o_id),
Index: /lib/wpsg_calculation.class.php
===================================================================
--- /lib/wpsg_calculation.class.php	(revision 7209)
+++ /lib/wpsg_calculation.class.php	(revision 7210)
@@ -28,5 +28,14 @@
         /** @var array  */
     	private $arCalculationRow = null;
-                                
+            
+		/** @var bool Ist bei alten rekonstriuerten Berechnungen true */
+    	public $restored = false;
+    			
+    	private $tax_mode = '2';
+	
+		const TAXMODE_SMALLBUSINESS = '1';
+    	const TAXMODE_B2C = '2';
+    	const TAXMODE_B2B = '3';
+    	    	
         public function __construct() {
             
@@ -39,4 +48,16 @@
         }        
         
+        public function setTaxMode($tax_mode) {
+        	
+        	$this->tax_mode = $tax_mode;
+        	
+		}
+        
+		public function getTaxMode() {
+        	
+        	return $this->tax_mode; 
+        	
+		}
+		
         /** 
          * Setzt das Standardland fÃŒr die Steuerberechnung wenn im $tax_key kein Land definiert ist 
@@ -44,4 +65,6 @@
         public function addCountry($country_id, $tax_mode, $tax_a, $tax_b, $tax_c, $tax_d, $default = true) {
             
+        	if (array_key_exists($country_id, $this->arCountry)) return; 
+        	
             $this->arCountry[$country_id] = [
             	'tax_mode' => $tax_mode,
@@ -54,4 +77,52 @@
             
         }
+        
+        public function getTargetCountry() {
+	
+			foreach ($this->arCountry as $country_id => $c) {
+		
+				if ($c['default'] !== true) return $c;
+		
+			}
+	
+			throw new \Exception(__('Kein Rechnungslaud fÃŒr die Berechnung gesetzt.', 'wpsg'));
+        	
+		}
+        
+        public function getTargetCountryID() {
+	
+			foreach ($this->arCountry as $country_id => $c) {
+		
+				if ($c['default'] !== true) return $country_id;
+		
+			}
+	
+			throw new \Exception(__('Kein Rechnungslaud fÃŒr die Berechnung gesetzt.', 'wpsg'));
+        	
+		}
+        
+		public function getDefaultCountry() {
+			
+			foreach ($this->arCountry as $country_id => $c) {
+				
+				if ($c['default'] === true) return $c;
+				
+			}
+			
+			throw new \Exception(__('Kein Standardland fÃŒr die Berechnung gesetzt.', 'wpsg'));
+        	
+		}
+		
+        public function getDefaultCountryID() {
+        	
+        	foreach ($this->arCountry as $country_id => $c) {
+        		
+        		if ($c['default'] === true) return $country_id;
+        		
+			}
+        	
+			throw new \Exception(__('Kein Standardland fÃŒr die Berechnung gesetzt.', 'wpsg'));
+			
+		}
         
         public function removeVoucher() {
@@ -125,9 +196,19 @@
         }
         
-        public function addProduct($set, $bruttonetto, $tax_key, $amount, $product_key, $product_index = false, $order_product_id = false) {
+        public function addProduct($set, $bruttonetto, $tax_key, $amount, $product_key, $product_index = false, $order_product_id = false, $eu = false) {
             					
-            $tax_key = $this->normalizeTaxKey($tax_key);
+            $tax_key = $this->normalizeTaxKey($tax_key, (($eu === true)?$this->getTargetCountryID():$this->getDefaultCountryID()));
           
             if ($product_index === false) $product_index = $this->getMaxProductIndex();
+            
+            if (wpsg_isSizedInt($order_product_id)) {
+            
+            	foreach ($this->arCalculationRow as $k => $item) {
+            	
+            		if ($item['type'] === 'product' && $item['data']['order_product_id'] == $order_product_id) unset($this->arCalculationRow[$k]);
+            	
+				}
+				
+			}
             
             $this->arCalculationRow[] = [
@@ -141,5 +222,6 @@
 					'product_key' => $product_key,
 					'product_index' => $product_index,
-					'order_product_id' => $order_product_id
+					'order_product_id' => $order_product_id,
+					'eu' => $eu
 				]
 			];
@@ -225,5 +307,5 @@
 	            	
                 foreach ($this->arCalculationRow as $cr) {
-                	            
+                	             
                 	$this->addTax($cr['tax_key']);
                 	$this->calculateTaxProportionally($cr['bruttonetto']);
@@ -253,4 +335,28 @@
 						}
 																		
+					}
+	
+					$country_id = preg_replace('/(.*)\_/', '',$cr['tax_key']);
+	
+					if ($this->arCountry[$country_id]['tax_mode'] == '1') {
+						
+						// Land ist auf "Keine Steuer" gestellt
+						$brutto = $netto;
+						
+					} else {
+					
+						if ($this->tax_mode === self::TAXMODE_SMALLBUSINESS) {
+						
+							// Kleinunternehmer	
+							
+							$brutto = $netto;
+							
+						} else if ($this->tax_mode === self::TAXMODE_B2B) {
+							
+							// Endkunde
+							if ($this->arCountry[$this->getTargetCountryID()]['tax_mode'] == '2') $brutto = $netto;
+							
+						}
+						
 					}
 					  
@@ -287,9 +393,9 @@
 						
 					if (in_array($cr['type'], ['product', 'voucher'])) {
-						
+												
 						$this->arCalculation['sum']['productsum_netto'] += $netto;
 						$this->arCalculation['sum']['productsum_brutto'] += $brutto;
-					} 
-										
+					}
+		
 				}
 				
@@ -365,4 +471,7 @@
 			$db_data['price_rabatt_netto'] = '';
 			$db_data['price_rabatt_brutto'] = '';
+			
+			$db_data['calculation'] = '1';
+			$db_data['tax_mode'] = $this->getTaxMode();
 			
             foreach ($this->arCalculationRow as $cr) {
@@ -459,5 +568,5 @@
             */
 
-            $arOrderProductID = [];
+            $arOrderProductID = [-1];
             
             // Produkte speichern
@@ -476,5 +585,6 @@
 					'mwst_key' => wpsg_q($p['tax_key']),
 					'product_set' => wpsg_q($p['set']),
-					'product_bruttonetto' => wpsg_q($p['bruttonetto'])
+					'product_bruttonetto' => wpsg_q($p['bruttonetto']),
+					'euleistungsortregel' => wpsg_q($p['eu'])
 				];
 				
@@ -493,10 +603,6 @@
             }
             
-            if (wpsg_isSizedArray($arOrderProductID)) {
-                
-                $this->db->Query("DELETE FROM `".WPSG_TBL_ORDERPRODUCT."` WHERE `o_id` = '".wpsg_q($id)."' AND `id` NOT IN (".wpsg_q(implode(',', $arOrderProductID)).") ");
-                
-            }
-	
+            $this->db->Query("DELETE FROM `".WPSG_TBL_ORDERPRODUCT."` WHERE `o_id` = '".wpsg_q($id)."' AND `id` NOT IN (".wpsg_q(implode(',', $arOrderProductID)).") ");
+            	
 			$this->arCalculation = null;
                 
@@ -504,5 +610,101 @@
             
         } // public function toDB($id = false)
-
+	
+		/**
+		 * LÃ€dt eine alte Bestellung, die mit der alten wpsg_basket Klasse berechnet wurde
+		 * 
+		 * @param $db_order
+		 * @param $db_products
+		 */
+		public function fromDBFallback($db_order, $db_products) {
+        	
+			// LÃ€nder
+			$oDefaultCountry = $this->shop->getDefaultCountry();
+			
+			$this->addCountry($oDefaultCountry->id, $oDefaultCountry->mwst, $oDefaultCountry->mwst_a,$oDefaultCountry->mwst_b, $oDefaultCountry->mwst_c, $oDefaultCountry->mwst_d, true);
+			
+			if (wpsg_isSizedInt($db_order['adress_id'])) {
+				
+				$country_id = $this->db->fetchOne("
+					SELECT
+						A.`land`
+					FROM
+						`".WPSG_TBL_ADRESS."` AS A
+					WHERE
+						A.`id` = '".wpsg_q($db_order['adress_id'])."'
+				");
+				
+				$oInvoiceCountry = \wpsg_country::getInstance($country_id);
+				 
+				if (!$oInvoiceCountry->isLoaded()) throw new \Exception(wpsg_translate(__('Land mit der ID #1# existiert nicht mehr.', 'wpsg'), $country_id));
+				
+				$this->addCountry($oInvoiceCountry->id, $oInvoiceCountry->mwst, $oInvoiceCountry->mwst_a,$oInvoiceCountry->mwst_b, $oInvoiceCountry->mwst_c, $oInvoiceCountry->mwst_d, false);
+				 
+			} else {
+				
+				$oInvoiceCountry = $oDefaultCountry;
+				
+			}
+		 
+			if (isset($this->shop->arShipping[$db_order['type_shipping']])) {
+				
+				$shipping = $this->shop->arShipping[$db_order['type_shipping']];
+					
+				$this->addShipping($shipping['price'],$this->shop->getBackendTaxview(),$shipping['mwst_key'],$db_order['type_shipping']);
+				
+			} else {
+				
+				$this->addShipping($db_order['shipping_set'],$db_order['shipping_bruttonetto'],$db_order['shipping_tax_key'],$db_order['type_shipping']);
+				
+			}
+			
+			if (isset($this->shop->arPayment[$db_order['type_payment']])) {
+				
+				$payment = $this->shop->arPayment[$db_order['type_payment']];
+		 
+				$this->addPayment($payment['price'],$this->shop->getBackendTaxview(),$payment['mwst'],$db_order['type_payment']);
+				
+			} else {
+				
+				$this->addPayment($db_order['payment_set'],$db_order['payment_bruttonetto'],$db_order['payment_tax_key'],$db_order['type_payment']);
+				
+			}
+			
+			// Produkte
+			foreach ($db_products as $db_p) {
+				
+				$product_data = $this->db->fetchRow("SELECT `euleistungsortregel` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id` = '".wpsg_q($db_p['p_id'])."' ");
+				
+				if ($this->shop->getBackendTaxview() === WPSG_BRUTTO) $product_set = $db_p['price_brutto'];
+				else $product_set = $db_p['price_netto'];
+				
+				$tax_key = $db_p['mwst_key'];
+				
+				// c_1
+				if ($product_data['euleistungsortregel'] === '1') $eu = '1';
+				$eu = '0';
+							
+				$this->addProduct($product_set, $this->shop->getBackendTaxview(), $tax_key, $db_p['menge'],$db_p['productkey'], $db_p['product_index'], $db_p['id'], $eu);
+				
+			}
+			
+			// Rabatte
+			if (wpsg_isSizedString($db_order['discount_set'])) {
+				
+				$this->addDiscount($db_order['discount_set'], $db_order['discount_bruttonetto'], $db_order['discount_tax_key']);
+				
+			}
+			
+			// Gutschein
+			if (wpsg_isSizedString($db_order['gs_set'])) {
+				
+				$this->addVoucher($db_order['gs_set'], $db_order['voucher_bruttonetto'], $db_order['gs_tax_key'], 1, $db_order['gs_code'],$db_order['gs_id']);
+				
+			}
+			
+			$this->restored = true;
+			
+		} // public function fromDBFallback($db_order, $db_products) {
+		
         public function fromDB($id) {
             
@@ -510,13 +712,23 @@
             $db_products = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_ORDERPRODUCT."` WHERE `o_id` = '".wpsg_q($id)."' ");
             
+            if (!wpsg_isSizedInt($db_order['calculation'])) {
+            	
+            	return $this->fromDBFallback($db_order, $db_products);
+            	
+			}
+            
+			$this->setTaxMode($db_order['tax_mode']);
+			
             $this->addCountry($db_order['shop_country_id'], $db_order['shop_country_tax'], $db_order['shop_country_tax_a'],$db_order['shop_country_tax_b'], $db_order['shop_country_tax_c'], $db_order['shop_country_tax_d'], true);
 			$this->addCountry($db_order['target_country_id'], $db_order['target_country_tax'], $db_order['target_country_tax_a'],$db_order['target_country_tax_b'], $db_order['target_country_tax_c'], $db_order['target_country_tax_d'], false);
-            
+			
+			// Versand- und Zahlungsart
             $this->addShipping($db_order['shipping_set'],$db_order['shipping_bruttonetto'],$db_order['shipping_tax_key'],$db_order['shipping_key']);
             $this->addPayment($db_order['payment_set'], $db_order['payment_bruttonetto'], $db_order['payment_tax_key'],$db_order['payment_key']);
             
+            // Produkte
             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']);
+            	
+                $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));
                 
             }
@@ -535,17 +747,5 @@
             	
 			}            
-            
-			if (wpsg_isSizedInt($db_order['shop_country_id'])) {
-            	
-            	$this->addCountry($db_order['shop_country_id'], $db_order['shop_country_tax'], $db_order['shop_country_tax_a'], $db_order['shop_country_tax_b'], $db_order['shop_country_tax_c'], $db_order['shop_country_tax_d']);
-            	
-			} else {
-            	
-            	$oDefaultCountry = $this->shop->getDefaultCountry();
-            	
-            	$this->addCountry($oDefaultCountry->id, $oDefaultCountry->mwst, $oDefaultCountry->mwst_a, $oDefaultCountry->mwst_b, $oDefaultCountry->mwst_c, $oDefaultCountry->mwst_d);
-            	
-			}
-			
+            			
         } // public function fromDB($id)
         
@@ -661,5 +861,5 @@
          * Im Array sollen die Tax SchlÃŒssel immer mit Land gespeichert sein
          */
-        private function normalizeTaxKey($tax_key) {
+        private function normalizeTaxKey($tax_key, $country_id = false) {
 
             if ($tax_key == '') $tax_key = '0';
@@ -667,12 +867,8 @@
             if ($tax_key != '0' && !preg_match('/\_\d+$/', $tax_key)) {
             	
-            	foreach ($this->arCountry as $country_id => $c) {
-            		
-            		if ($c['default'] === true) return $tax_key.'_'.$country_id;
-            		
-				}
-            	
-            	throw new \Exception(__('Kein Standardland fÃŒr Berechnung gesetzt.', 'wspg'));
-				
+            	if ($country_id === false) $country_id = $this->getDefaultCountryID();
+            	
+            	return $tax_key.'_'.$country_id;
+            					
 			} else return $tax_key;
             
@@ -752,37 +948,11 @@
 				
 				$arTaxKey = explode('_', $tax_key);
-				
-				$country = \wpsg_country::getInstance($arTaxKey[1]);
-				$tax_value = $country->getTax($arTaxKey[0]);
-				
+								
 				$this->arCalculation['tax'][$tax_key] = [
 					'key' => $tax_key,
-					'tax_value' => $tax_value
+					'tax_value' => $this->arCountry[$arTaxKey[1]][$tax_key]
 				];
 				
-			}
-        	
-        	/*
-            if (!isset($this->arCalculation['tax'][$tax_key])) {
-                   
-                $arTaxKey = explode('_', $tax_key);
-                
-                $country = \wpsg_country::getInstance($arTaxKey[1]);
-                $tax_value = $country->getTax($arTaxKey[0]);
-                
-                $this->arCalculation['tax'][$tax_key] = [
-                    'key' => $tax_key,
-                    'netto' => $price_netto,
-                    'brutto' => 0,
-                    'tax_value' => $tax_value,
-                    'sum_tax' => 0
-                ];
-                
-            } else {
-                
-                $this->arCalculation['tax'][$tax_key]['netto'] += $price_netto;
-                
-            }
-        	*/
+			} 
             
         }
Index: /model/wpsg_order.class.php
===================================================================
--- /model/wpsg_order.class.php	(revision 7209)
+++ /model/wpsg_order.class.php	(revision 7210)
@@ -79,5 +79,7 @@
 		public function updateAdress($adress_data)
 		{
-				
+			
+			$order_data = [];
+			
 			$insert = false;
 				
@@ -104,10 +106,6 @@
 		
 				$adress_id = $this->db->ImportQuery(WPSG_TBL_ADRESS, $adress_data);
-		
-				$this->db->UpdateQuery(WPSG_TBL_ORDER, array(
-						'adress_id' => wpsg_q($adress_id)
-				), " `id` = '".wpsg_q($this->id)."' ");
-		
-				$this->data['adress_id'] = $adress_id;
+				
+				$order_data['adress_id'] = wpsg_q($adress_id);
 		
 			}
@@ -119,4 +117,29 @@
 			}
 				
+			if (isset($adress_data['land'])) {
+				
+				$oCountry = wpsg_country::getInstance($adress_data['land']);
+				
+				$order_data['target_country_id'] = wpsg_q($adress_data['land']);
+				$order_data['target_country_tax'] = wpsg_q($oCountry->mwst);
+				$order_data['target_country_tax_a'] = wpsg_q($oCountry->mwst_a);
+				$order_data['target_country_tax_b'] = wpsg_q($oCountry->mwst_b);
+				$order_data['target_country_tax_c'] = wpsg_q($oCountry->mwst_c);
+				$order_data['target_country_tax_d'] = wpsg_q($oCountry->mwst_d);
+			
+			}
+			
+			if (wpsg_isSizedArray($order_data)) {
+			
+				$this->db->UpdateQuery(WPSG_TBL_ORDER, $order_data, " `id` = '".wpsg_q($this->id)."' ");
+				
+				foreach ($order_data as $k => $v) {
+					
+					$this->data[$k] = $v;
+					
+				}
+				
+			}
+			
 			$this->adress_data = $adress_data;
 				
Index: /system/tests/wpsg_calculationTestTest.php
===================================================================
--- /system/tests/wpsg_calculationTestTest.php	(revision 7209)
+++ /system/tests/wpsg_calculationTestTest.php	(revision 7210)
@@ -68,4 +68,6 @@
 	
 		public function test3() {
+			
+			//$this->markTestSkipped(); return;
 			
 			$b = new \wpsg\wpsg_calculation();
@@ -99,5 +101,86 @@
 		}
 	
-		 
+		public function test4() {
+		
+			//$this->markTestSkipped(); return;
+		
+			$b = new \wpsg\wpsg_calculation();
+		
+			$b->addCountry(1, 0, 0, 7, 19, 0, true);
+		
+			$b->addShipping('119', WPSG_BRUTTO, 'c','sss');
+			$b->addProduct('119', WPSG_BRUTTO, 'c', 10,'1');
+			$b->addPayment('119', WPSG_BRUTTO, 'c', 'ppp');
+			
+			$b->setTaxMode(\wpsg\wpsg_calculation::TAXMODE_SMALLBUSINESS);
+			
+			$ar = $b->getCalculationArray();
+			
+			$this->assertTrue($this->compareArray($ar, [
+				'sum' => [
+					'product_netto' => 1000,
+					'product_brutto' => 1000,
+					'netto' => 1200,
+					'brutto' => 1200,
+				]
+			]));
+		
+		}
+	
+		public function test5() {
+		
+			//$this->markTestSkipped(); return;
+		
+			$b = new \wpsg\wpsg_calculation();
+		
+			$b->addCountry(1, 0, 0, 7, 19, 0, true); // Standardland
+			$b->addCountry(2, 2, 0, 7, 19, 0, false); // Rechnungsland
+		
+			$b->addShipping('119', WPSG_BRUTTO, 'c','sss');
+			$b->addPayment('119', WPSG_BRUTTO, 'c', 'ppp');
+			
+			$b->addProduct('119', WPSG_BRUTTO, 'c', 10,'1');
+			
+			$b->setTaxMode(\wpsg\wpsg_calculation::TAXMODE_B2B);
+		
+			$ar = $b->getCalculationArray();
+		
+			$this->assertTrue($this->compareArray($ar, [
+				'sum' => [
+					'product_netto' => 1000,
+					'product_brutto' => 1000,
+					'netto' => 1200,
+					'brutto' => 1200,
+				]
+			]));
+		
+		}
+	
+		public function test6() {
+		
+			//$this->markTestSkipped(); return;
+		
+			$b = new \wpsg\wpsg_calculation();
+		
+			$b->addCountry(1, 0, 0, 7, 19, 0, true); // Standardland
+			$b->addCountry(2, 2, 0, 7, 20, 0, false); // Rechnungsland
+		
+			$b->addShipping('119', WPSG_BRUTTO, 'c','sss');
+			$b->addPayment('119', WPSG_BRUTTO, 'c', 'ppp');
+		
+			$b->addProduct('120', WPSG_BRUTTO, 'c', 10,'1', false, false,true);
+				
+			$ar = $b->getCalculationArray();
+		
+			$this->assertTrue($this->compareArray($ar, [
+				'sum' => [
+					'product_netto' => 1000,
+					'product_brutto' => 1200,
+					'netto' => 1200,
+					'brutto' => 1438,
+				]
+			]));
+		
+		}
 	 	
 		private function compareArray($a, $b_check, $key = '') {
Index: /views/css/admin.css
===================================================================
--- /views/css/admin.css	(revision 7209)
+++ /views/css/admin.css	(revision 7210)
@@ -266,4 +266,5 @@
 .wpsg_order .col_nr .glyphicon.admincomment { color:red; }
 .wpsg_order .wpsg-order-tab { padding-top:15px; padding-bottom:15px; }
+.wpsg_order_view #restored_notice { margin-bottom:15px; color:red; }
 
 #wpsg-bs.wpsg_order_view .editableform textarea { height:150px;}
Index: /views/mods/mod_productvars/order_view_row.phtml
===================================================================
--- /views/mods/mod_productvars/order_view_row.phtml	(revision 7209)
+++ /views/mods/mod_productvars/order_view_row.phtml	(revision 7210)
@@ -11,9 +11,9 @@
 <tr class="wpsg_<?php echo (($this->view['wpsg_mod_productvars']['i'] == 0)?'odd':'even'); ?> wpsg_productvars">
 	<td class="wpsg_cell_name"><?php echo __($pv['name'], 'wpsg'); ?></td>	
-	<td align="right" colspan="<?php echo ((sizeof($this->view['basket']['mwst']) > 1 || $this->get_option('wpsg_showMwstAlways') == '1')?'4':'3'); ?>">
+	<td align="right" colspan="<?php echo $this->view['colspan']; ?>">
 		
 		<div class="wpsg_editable" id="wpsg_productvar_<?php echo $k.'_'.$product_index; ?>"><?php echo wpsg_hspc($pv['value']); ?></div>
 		
-		<script type="text/javascript">/* <![CDATA[ */
+		<script type="text/javascript">/
 
 			<?php if ($pv['typ'] == 2) { /* Textfeld */ ?> 		                                            
@@ -59,5 +59,5 @@
 			<?php } ?>
         
-		/* ]]> */</script>
+		</script>
 		
 	</td>
Index: /views/order/backendEdit/addProduct_product_selected.phtml
===================================================================
--- /views/order/backendEdit/addProduct_product_selected.phtml	(revision 7209)
+++ /views/order/backendEdit/addProduct_product_selected.phtml	(revision 7210)
@@ -40,8 +40,16 @@
     <?php } ?>
     
-    <?php echo wpsg_drawForm_Input('add_price', __('Produktpreis', 'wpsg').' '.(($this->getBackendTaxView() === WPSG_BRUTTO)?'(BRUTTO)':'(NETTO'), (($oOrderProduct !== false)?$oOrderProduct->getPrice($this->getBackendTaxView()):$oProduct->getPrice($this->getBackendTaxView()))); ?>
+    <?php echo wpsg_drawForm_Input('add_price', __('Produktpreis', 'wpsg').' '.(($this->getBackendTaxView() === WPSG_BRUTTO)?'(BRUTTO)':'(NETTO'), wpsg_ff((($oOrderProduct !== false)?$oOrderProduct->getPrice($this->getBackendTaxView()):$oProduct->getPrice($this->getBackendTaxView())), $this->get_option('wpsg_currency'))); ?>
     <?php echo wpsg_drawForm_Input('add_amount', __('Menge', 'wpsg'), (($oOrderProduct !== false)?$oOrderProduct->getCount():'1')); ?>
-    
-    <?php if ($this->callMod('wpsg_mod_productvariants', 'isVariantsProduct', [$oProduct->id])) { $arVariants = $this->callMod('wpsg_mod_productvariants', 'getVariants', [$oProduct->id, true, true, true]); ?> 
+    <?php echo wpsg_drawForm_Checkbox('add_eu',__('EU-Leistungsortregel anwenden', 'wpsg'),(($oOrderProduct !== false)?$oOrderProduct->euleistungsortregel:'1')) ?>
+	
+    <?php if ($this->callMod('wpsg_mod_productvariants', 'isVariantsProduct', [$oProduct->id])) { 
+    	
+    	$arVariants = $this->callMod('wpsg_mod_productvariants', 'getVariants', [$oProduct->id, true, true, true]); 
+    	
+    	if ($oOrderProduct !== false) $arVariantenInfoArray = $this->callMod('wpsg_mod_productvariants', 'getVariantenInfoArray', [$oOrderProduct->getProductKey()]);
+    	else $arVariantenInfoArray = [];
+    	 
+    	?> 
         
         <?php if (wpsg_isSizedArray($arVariants)) { ?>
@@ -56,9 +64,31 @@
                 ?>
             
-                <?php echo wpsg_drawForm_Select('wpsg_vp['.$var_id.']', $var_data['name'], $arVariSelect,''); ?>
+                <?php echo wpsg_drawForm_Select('wpsg_vp['.$var_id.']', $var_data['name'], $arVariSelect,$arVariantenInfoArray[$var_data['id']]['vari_id'], ['field_class' => 'varichange']); ?>
                 
             <?php } ?>
         
         <?php } ?>
+		
+		<script>
+			
+			jQuery('.varichange').on('change', function() {
+
+				jQuery('#add_price').val('..');
+				
+				jQuery.ajax( {
+					url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=view&subaction=addProduct&do=updatePrice&noheader=1&product_id=<?php echo $oProduct->id; ?>',
+					data: {
+						form_data: jQuery('#wpsg_product_add_form').serialize()
+					},
+					success: function(data) {
+
+						jQuery('#add_price').val(data);
+
+					}
+				} );
+				
+			} );
+			
+		</script>
         
     <?php } ?> 
Index: /views/order/product_table.phtml
===================================================================
--- /views/order/product_table.phtml	(revision 7209)
+++ /views/order/product_table.phtml	(revision 7210)
@@ -4,5 +4,5 @@
      * Template fÃŒr die Produkttabelle im Backend der Bestellverwaltung
      */
-    
+	    
     $arCalculation = $this->view['oCalculation']->getCalculationArray(true);
 	$arTax = $this->view['oCalculation']->getTaxLabelArray();
@@ -16,5 +16,5 @@
     if ($this->getBackendTaxView() === WPSG_NETTO) $display = 'netto';
     else $display = 'brutto';
-    
+ 
 ?>
 
@@ -23,7 +23,15 @@
 	.wpsg_row_small td { font-size:0.8em; }
 	#wpsg-bs .wpsg_row_small  .wpsg-glyphlink-td > span { margin-top:0px; }
+	/*.wpsg_productrow_add td { border-top:0px !important; }*/
 
 </style>
 
+<?php echo wpsg_drawForm_Select('tax_mode', __('Besteuerung'), [
+		\wpsg\wpsg_calculation::TAXMODE_SMALLBUSINESS => __('Kleinunternehmerregelung'),
+		\wpsg\wpsg_calculation::TAXMODE_B2C => __('Endkundenbesteuerung'),
+		\wpsg\wpsg_calculation::TAXMODE_B2B => __('Firmenkundenbesteuerung')
+	], $this->view['oCalculation']->getTaxMode(), ['onchange' => 'WPSG_BE.updateCalculation();']); ?>
+
+<br />
 
 <table class="wpsg_produkte table">
@@ -44,11 +52,19 @@
 		<?php $i = 0; foreach ($arCalculation['product'] as $p) { $i ++; $product_price = $p[$display]; ?>
 			<tr class="wpsg_<?php echo (($i % 2 == 0)?'odd':'even'); ?>">
-				<td class="wpsg_cell_name">
+				<td colspan="<?php echo $this->view['colspan'] + 1; ?>">
+					
+					<?php if (wpsg_isTrue($p['eu'])) { ?>
+						<img src="<?php echo WPSG_URL; ?>views/gfx/eu.png" alt="<?php echo __('Produkt unterliegt der EU-Leistungsortregel', 'wpsg'); ?>" title="<?php echo __('Produkt unterliegt der EU-Leistungsortregel', 'wpsg'); ?>" height="14" />
+					<?php } ?>
+					
 					<a href="<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Produkt&action=edit&edit_id=<?php echo $p['product_id']; ?>" title="<?php echo __('Zum Produkt', 'wpsg'); ?>">
 						<?php echo wpsg_hspc($this->getProductName($p['product_id'])); ?>
 					</a>
 					<a href="#" class="wpsg-glyphlink-td" title="<?php echo __('Produkt bearbeiten', 'wpsg'); ?>" onclick="return WPSG_BE_Product.editProduct(<?php echo $p['order_product_id']; ?>);"><span class="glyphicon glyphicon-pencil"></span></a>
-					<a href="#" class="wpsg-glyphlink-td" title="<?php echo __('Produkt lÃ¶schen', 'wpsg'); ?>" onclick="return WPSG_BE_Product.remvoeProduct(<?php echo $p['order_product_id']; ?>);"><span class="glyphicon glyphicon-trash"></span></a>
-				</td>
+					<a href="#" class="wpsg-glyphlink-td" title="<?php echo __('Produkt lÃ¶schen', 'wpsg'); ?>" onclick="return WPSG_BE_Product.removeProduct(<?php echo $p['order_product_id']; ?>);"><span class="glyphicon glyphicon-trash"></span></a>
+				</td>
+			</tr>
+			<tr class="wpsg_<?php echo (($i % 2 == 0)?'odd':'even'); ?> wpsg_productrow_add">
+				<td class="wpsg_cell_name"></td>
 				<td class="wpsg_cell_preis"><?php echo wpsg_ff($product_price); ?> <?php echo $this->get_option('wpsg_currency'); ?></td>
 				<?php if (sizeof($arCalculation['tax']) > 1 || $this->get_option('wpsg_showMwstAlways') == '1') { ?>
@@ -277,3 +293,2 @@
 </table>
 	
-<?php wpsg_debug($arCalculation); ?>
Index: /views/order/view.phtml
===================================================================
--- /views/order/view.phtml	(revision 7209)
+++ /views/order/view.phtml	(revision 7210)
@@ -104,4 +104,12 @@
     <div class="wpsg_admin_content form-horizontal">
 
+		<?php if ($this->view['oCalculation']->restored) { ?>
+
+			<div id="restored_notice">
+				<strong>Die Berechnung dieser Bestellung wurde rekonstruiert, da zum Bestellzeitpunkt nicht alle Shop Einstellungen erfasst wurden. Bitte ÃŒberprÃŒfen sie die Berechnung und vergleichen diese ggf. mit dem Bestellprotokoll. </strong>
+			</div>
+			
+		<?php } ?>
+		
         <?php $i = 0; foreach ($this->view['arSubAction'] as $k => $v) { $i ++; ?>
         <div id="tab<?php echo $k; ?>" style="display:<?php echo ((wpsg_getStr($_COOKIE['wpsg_order_view_tab'], 'general') == $k)?'block':'none'); ?>;" class="wpsg_order_view_tab_content">
Index: /views/order/view_customerdata.phtml
===================================================================
--- /views/order/view_customerdata.phtml	(revision 7209)
+++ /views/order/view_customerdata.phtml	(revision 7210)
@@ -138,9 +138,9 @@
 	    <?php } ?>
 	<?php } ?>                    
-    <?php if ($this->view['pflicht']['ustidnr'] != '2') { ?>
-	    <?php if (strlen($this->view['data']['ustidnr']) > 0) { ?>
-	   		<?php echo wpsg_drawForm_Text(__('UStIdNr.', 'wpsg'), $this->view['data']['ustidnr'], array('text' => true)); ?>
-	    <?php } ?>
-	<?php } ?>                    
+    
+	    
+	<?php echo wpsg_drawForm_Text(__('UStIdNr.', 'wpsg'), $this->view['data']['ustidnr'], array('text' => true)); ?>
+	<br />
+	                    
     <?php $this->callMods('wpsg_order_view_customerdata', array(&$this->view['data']['id'])); ?>
 
Index: /views/order/view_orderdata.phtml
===================================================================
--- /views/order/view_orderdata.phtml	(revision 7209)
+++ /views/order/view_orderdata.phtml	(revision 7210)
@@ -18,4 +18,30 @@
 	<script type="text/javascript">
 	
+		var WPSG_BE = {
+			
+			updateCalculation: function() {
+
+				var tax_mode = jQuery('#tax_mode').val();
+				
+				jQuery('#wpsg_product_table_wrap').html('<img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />');
+
+				jQuery.ajax( {
+					url: '<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Order&action=view&subaction=updateCalculation&noheader=1&edit_id=<?php echo $_REQUEST['edit_id']; ?>',
+					data: {
+						tax_mode: tax_mode
+					},
+					success: function(data) {
+
+						jQuery('#wpsg_product_table_wrap').html(data.product_table);
+
+					}
+				} );
+
+				return false;
+				
+			}
+			
+		};
+		
 		var WPSG_BE_Pay_Ship = {
 				 
@@ -91,6 +117,6 @@
 				
 			},
-			
-			remvoeProduct: function(order_product_id) {
+
+			removeProduct: function(order_product_id) {
 	
 				jQuery('#wpsg_product_table_wrap').html('<img src="<?php echo WPSG_URL; ?>views/gfx/ajax-loader.gif" alt="<?php echo __('Bitte warten ...', 'wpsg'); ?>" />');
