Index: /controller/wpsg_OrderController.class.php
===================================================================
--- /controller/wpsg_OrderController.class.php	(revision 8368)
+++ /controller/wpsg_OrderController.class.php	(revision 8369)
@@ -787,36 +787,48 @@
 					$this->shop->view['data']['shipping_land'] = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q(wpsg_getInt($this->shop->view['data']['shipping_land']))."'");
 
-					$temp = $this->db->fetchRow("
-						SELECT
-							A.*
-						FROM
-							`".WPSG_TBL_ADRESS."` AS A
-						WHERE
-							A.`id` = '".wpsg_q($this->shop->view['data']['shipping_adress_id'])."'
-					");
-
-					$this->shop->view['data']['shipping_land'] = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q(wpsg_getStr($temp['land']))."'");
-
-					$this->shop->view['kunde'] = $this->db->fetchRow("
-						SELECT
-							K.*
-						FROM
-							`".WPSG_TBL_KU."` AS K
-						WHERE
-							K.`id` = '".wpsg_q($this->shop->view['data']['k_id'])."'
-					");
-
-					$this->shop->view['kunde']['land'] = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q(wpsg_getInt($this->shop->view['kunde']['land']))."'");
-
-					$temp = $this->db->fetchRow("
-						SELECT
-							A.*
-						FROM
-							`".WPSG_TBL_ADRESS."` AS A
-						WHERE
-							A.`id` = '".wpsg_q($this->shop->view['data']['adress_id'])."'
-					");
-
-					$this->shop->view['kunde']['land'] = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q($temp['land'])."'");
+					if (intval($this->shop->view['data']['shipping_adress_id']??0) > 0) {
+						
+						$temp = $this->db->fetchRow("
+							SELECT
+								A.*
+							FROM
+								`".WPSG_TBL_ADRESS."` AS A
+							WHERE
+								A.`id` = '".wpsg_q($this->shop->view['data']['shipping_adress_id'])."'
+						");
+						
+						$this->shop->view['data']['shipping_land'] = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q(wpsg_getStr($temp['land']))."'");
+						
+					}
+					
+					if (intval($this->shop->view['data']['k_id']??0) > 0) {
+						
+						$this->shop->view['kunde'] = $this->db->fetchRow("
+							SELECT
+								K.*
+							FROM
+								`".WPSG_TBL_KU."` AS K
+							WHERE
+								K.`id` = '".wpsg_q($this->shop->view['data']['k_id'])."'
+						");
+						
+						$this->shop->view['kunde']['land'] = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q(wpsg_getInt($this->shop->view['kunde']['land']))."'");
+						
+					}
+
+					if (intval($this->shop->view['data']['adress_id']??0) > 0) {
+						
+						$temp = $this->db->fetchRow("
+							SELECT
+								A.*
+							FROM
+								`".WPSG_TBL_ADRESS."` AS A
+							WHERE
+								A.`id` = '".wpsg_q($this->shop->view['data']['adress_id'])."'
+						");
+						
+						$this->shop->view['kunde']['land'] = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_LAND."` WHERE `id` = '".wpsg_q($temp['land'])."'");
+						
+					}
 
 				}
Index: /lib/wpsg_exceptionhandler.class.php
===================================================================
--- /lib/wpsg_exceptionhandler.class.php	(revision 8368)
+++ /lib/wpsg_exceptionhandler.class.php	(revision 8369)
@@ -65,5 +65,5 @@
 			}
 
-            if ($break) die(wpsg_debug($typeLabel.": ".$msg."\r\n".$backtrace, true));
+            if ($break) die(wpsg_debug($typeLabel.": ".$msg."\r\n".($backtrace??''), true));
 
         } // static function myCallbackMethod($ex)
Index: /mods/wpsg_mod_prepayment.class.php
===================================================================
--- /mods/wpsg_mod_prepayment.class.php	(revision 8368)
+++ /mods/wpsg_mod_prepayment.class.php	(revision 8369)
@@ -270,10 +270,10 @@
 		 */
 		private function generateBase64QrCode(QrBill\QrBill $qrBill) {
-
-			$tmpfname = tempnam("/tmp", "swissqrcode").'.png';
-			$qrCode = $qrBill->getQrCode(QrBill\QrCode\QrCode::FILE_FORMAT_PNG);
-			$qrCode->writeFile($tmpfname);
-			$base64QrCode = base64_encode(file_get_contents($tmpfname));
-
+ 
+	 $tmpfname = tempnam("/tmp", "swissqrcode").'.png';
+	 $qrCode = $qrBill->getQrCode(QrBill\QrCode\QrCode::FILE_FORMAT_PNG);
+	 $qrCode->writeFile($tmpfname);
+	 $base64QrCode = base64_encode(file_get_contents($tmpfname));
+ 
 			return $base64QrCode;
 			
@@ -348,5 +348,5 @@
 							$this->shop->get_option('wpsg_shopdata_street'), 
 							$this->shop->get_option('wpsg_shopdata_zip').' '.wpsg_getStr($this->shop->get_option('wpsg_shopdata_city')), 
-							wpsg_getStr($oCountryB->getShorttext()) 
+							($oCountryB->getShorttext()??'')
 						)
 					);
@@ -363,5 +363,5 @@
 							$kundendaten['plz'], 
 							wpsg_getStr($kundendaten['ort']),
-							wpsg_getStr($oCountryC->getShorttext()) 
+							$oCountryC->getShorttext()??''
 						)
 					);
@@ -406,5 +406,5 @@
 
 					// wpsg_debug($qrBill->getViolations());
-
+ 
 					$qrCode = array(
 						'title' => 'QR-Rechnung',
@@ -496,5 +496,5 @@
 							$kundendaten['plz'], 
 							wpsg_getStr($kundendaten['ort']),
-							wpsg_getStr($oCountryC->getShorttext()) 
+							($oCountryC->getShorttext()??'')
 						)
 					);
Index: /mods/wpsg_mod_rechnungen.class.php
===================================================================
--- /mods/wpsg_mod_rechnungen.class.php	(revision 8368)
+++ /mods/wpsg_mod_rechnungen.class.php	(revision 8369)
@@ -9,10 +9,10 @@
 
 		var $lizenz = 1;
-		var $id = 1400;		
+		var $id = 1400;
 		var $version = "9.9.9";
 		var $hilfeURL = 'http://wpshopgermany.de/?p=718';
 		var $free = false;
 		
-		var $data = array(); 
+		var $data = array();
 		
 		/**
@@ -31,5 +31,5 @@
 				'name' => __('Name', 'wpsg'),
 				'strasse' => __('StraÃe', 'wpsg'),
-				'plzort' => __('PLZ/Ort', 'wpsg'),	
+				'plzort' => __('PLZ/Ort', 'wpsg'),
 				'land' => __('Land', 'wpsg'),
 				'tel' => __('Tel', 'wpsg'),
@@ -46,5 +46,5 @@
 				'user3' => __('Benutzer 3', 'wpsg'),
 				'user4' => __('Benutzer 4', 'wpsg'),
-				'user5' => __('Benutzer 5', 'wpsg')	
+				'user5' => __('Benutzer 5', 'wpsg')
 			);
 			
@@ -54,7 +54,7 @@
 			
 		} // public function __construct()
-		 
-		public function install() { 
-			 
+		
+		public function install() {
+			
 			require_once(WPSG_PATH_WP.'/wp-admin/includes/upgrade.php');
 			
@@ -106,6 +106,6 @@
 		} // public function delOrder($order_id)
 		
-		public function template_redirect() 
-		{ 
+		public function template_redirect()
+		{
 			
 			if (wpsg_isSizedString($_REQUEST['wpsg_action'], 'wpsg_mod_rechnungen_download'))
@@ -123,5 +123,5 @@
 				$this->doDownload($_REQUEST['r_id']);
 				
-			}	
+			}
 			
 		} // public function template_redirect()
@@ -130,5 +130,5 @@
 
             $nInvoiceToCorrect = $this->db->fetchOne("
-                SELECT COUNT(*) FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `o_id` > 0 OR `o_ids` != '' 
+                SELECT COUNT(*) FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `o_id` > 0 OR `o_ids` != ''
             ");
 
@@ -154,5 +154,5 @@
 
                 $arInvoiceToCorrect = $this->db->fetchAssoc("
-                    SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `o_id` > 0 OR `o_ids` != '' 
+                    SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `o_id` > 0 OR `o_ids` != ''
                 ");
 
@@ -191,7 +191,7 @@
 				
 				$this->resetAction();
-				$this->shop->addBackendMessage(__('Grundeinstellungen wieder hergestellt', 'wpsg'));			
+				$this->shop->addBackendMessage(__('Grundeinstellungen wieder hergestellt', 'wpsg'));
 	
-				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module&modul='.$_REQUEST['modul']); 
+				$this->shop->redirect(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module&modul='.$_REQUEST['modul']);
 				
 			}
@@ -219,5 +219,5 @@
 			else if ($_REQUEST['do'] == 'add')
 			{
-				 
+				
 				$foot_text = $this->shop->get_option("wpsg_rechnungen_footer");
 				if (!is_array($foot_text)) $foot_text = @unserialize($foot_text);
@@ -264,5 +264,5 @@
 
 				if ($ending != "jpg" && $ending != "jpeg" && $ending != "pdf") {
-				    
+				 
 					$this->shop->addBackendError(__("UngÃŒltiger Dateityp (Briefpapier) ! Es sind nur JPG und PDF Dateien erlaubt!", "wpsg"));
 					
@@ -306,5 +306,5 @@
 
 				if ($ending != "jpg" && $ending != "jpeg") {
-				    
+				 
 					$this->shop->addBackendError(__("UngÃŒltiger Dateityp (Logo) ! Es sind nur JPG und PDF Dateien erlaubt!", "wpsg"));
 					
@@ -335,5 +335,5 @@
 					!wpsg_checkInput($v['y'], WPSG_SANITIZE_FLOAT) ||
 					!wpsg_checkInput($v['color'], WPSG_SANITIZE_HEXCOLOR) ||
-					!wpsg_checkInput($v['fontsize'],WPSG_SANITIZE_INT)			
+					!wpsg_checkInput($v['fontsize'],WPSG_SANITIZE_INT)
 				) {
 					
@@ -348,5 +348,5 @@
 					
 					die("_");
-					*/ 
+					*/
 					
 					$this->shop->addBackendError(__('Bitte ÃŒberprÃŒfen Sie die Textfelder.', 'wpsg'));
@@ -391,5 +391,5 @@
 		public function settings_edit()
 		{
-						
+			
 			if (file_exists($this->getPaperPath().'wpsg_rechnungen_bp.jpg'))
 			{
@@ -415,5 +415,5 @@
 
 			$this->shop->view['fields'] = $this->fields;
-			$this->shop->view['foottext_list'] = $this->foottext_list();			
+			$this->shop->view['foottext_list'] = $this->foottext_list();
 			$this->shop->view['arTexte'] = $this->shop->get_option('wpsg_mod_rechnungen_texte');
 			
@@ -426,7 +426,7 @@
 				$this->shop->view['arTexte'] = array();
 				
-			} 
-						
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_rechnungen/settings_edit.phtml');			
+			}
+			
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_rechnungen/settings_edit.phtml');
 			
 		} // public function settings_edit()
@@ -440,16 +440,16 @@
 			
 			$strQuery = "
-				SELECT 
-				    I.* 
-				FROM 
+				SELECT
+				    I.*
+				FROM
 				    `".WPSG_TBL_RECHNUNGEN."` AS I
 				        LEFT JOIN `".WPSG_TBL_ORDER_INVOICE."` AS ORDER_INVOICE ON (I.`id` = ORDER_INVOICE.`invoice_id`)
-				WHERE  
+				WHERE
 					ORDER_INVOICE.`order_id` = '".intval($order_id)."' AND
-				    I.`storno` = '0000-00-00 00:00:00' AND 
-					I.`gnr` = '' 
+				    I.`storno` = '0000-00-00 00:00:00' AND
+					I.`gnr` = ''
 				GROUP BY
-				    I.`id` 
-				ORDER BY 
+				    I.`id`
+				ORDER BY
 					I.`rnr` DESC
 			";
@@ -458,16 +458,16 @@
 			
 			$strQuery = "
-				SELECT 
-				    INVOICE.* 
-				FROM 
+				SELECT
+				    INVOICE.*
+				FROM
 					`".WPSG_TBL_RECHNUNGEN."` AS INVOICE
 					    LEFT JOIN `".WPSG_TBL_ORDER_INVOICE."` AS ORDER_INVOICE ON (ORDER_INVOICE.`invoice_id` = INVOICE.`id`)
-				WHERE  
+				WHERE
 					ORDER_INVOICE.`order_id` = '".intval($order_id)."' AND
-					INVOICE.`storno` != '0000-00-00 00:00:00' AND 
-					INVOICE.`gnr` = '' 
+					INVOICE.`storno` != '0000-00-00 00:00:00' AND
+					INVOICE.`gnr` = ''
 				GROUP BY
 				    INVOICE.`id`
-				ORDER BY 
+				ORDER BY
 					INVOICE.`rnr` DESC
 			";
@@ -476,16 +476,16 @@
  
 			$this->shop->view['mod_rechnungen']['arRechnungen_gesamt'] = $this->db->fetchAssoc("
-				SELECT 
-					INVOICE.*, 
+				SELECT
+					INVOICE.*,
 					UNIX_TIMESTAMP(INVOICE.`datum`) AS ts_datum,
 					UNIX_TIMESTAMP(INVOICE.`storno`) AS ts_storno
-				FROM 
+				FROM
 					`".WPSG_TBL_RECHNUNGEN."` AS INVOICE
 					    LEFT JOIN `".WPSG_TBL_ORDER_INVOICE."` AS ORDER_INVOICE ON (INVOICE.`id` = ORDER_INVOICE.`invoice_id`)
-				WHERE  
-					ORDER_INVOICE.`order_id` = '".intval($order_id)."' 
+				WHERE
+					ORDER_INVOICE.`order_id` = '".intval($order_id)."'
 				GROUP BY
 				    INVOICE.`id`
-				ORDER BY 
+				ORDER BY
 					INVOICE.`id` ASC
 			");
@@ -498,5 +498,5 @@
 		} // public function order_view_content($order_id) { }
 		
-		public function order_view_row(&$p, $i) { 
+		public function order_view_row(&$p, $i) {
 
 			$this->shop->view['wpsg_mod_rechnungen']['product'] = $p;
@@ -511,5 +511,5 @@
 		} // public function order_view_row(&$p, $i)
 		
-		public function order_view_orderdata_after($order_id) { 
+		public function order_view_orderdata_after($order_id) {
 			
 			$oOrder = wpsg_order::getInstance($order_id);
@@ -523,5 +523,5 @@
 		
 		public function order_ajax() {
-			 
+			
 			if(isset($_REQUEST['edit_id'])) if (!wpsg_checkInput($_REQUEST['edit_id'], WPSG_SANITIZE_INT)) throw \wpsg\Exception::getSanitizeException();
 			if(isset($_REQUEST['r_id'])) if (!wpsg_checkInput($_REQUEST['r_id'], WPSG_SANITIZE_INT)) throw \wpsg\Exception::getSanitizeException();
@@ -529,7 +529,7 @@
 			if (isset($_REQUEST['wpsg_rechnungen_preview'])) {
 				
-				if (wpsg_isSizedInt($_REQUEST['edit_id'])) \check_admin_referer('wpsg-mod_invoice-order_ajax-rechnung-'.wpsg_getInt($_REQUEST['edit_id'])); 
+				if (wpsg_isSizedInt($_REQUEST['edit_id'])) \check_admin_referer('wpsg-mod_invoice-order_ajax-rechnung-'.wpsg_getInt($_REQUEST['edit_id']));
 				else wpsg_checkNounce('Admin', 'module', ['modul' => 'wpsg_mod_rechnungen', 'do' => 'orderAjax', 'wpsg_rechnungen_preview' => '1']);
-				 
+				
 				// Vorschau einer Rechnung aus der Bestellverwaltung
 				$this->writeRechnung(wpsg_getInt($_REQUEST['edit_id']), true, true);
@@ -601,5 +601,5 @@
 				$rechnung = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `id` = '".wpsg_q($_REQUEST['r_id'])."'");
 				$oInvoice = \wpsg\wpsg_invoice::getInstance(intval($_REQUEST['r_id']));
-
+ 
 				if ($rechnung['id'] != $_REQUEST['r_id'] || !in_array(intval($_REQUEST['edit_id']), $oInvoice->getOrderIds())) die(__("Rechnung existiert nicht oder passt nicht zur Bestellung!", "wpsg"));
 				
@@ -616,5 +616,5 @@
                 $rn_file_copy = dirname($oInvoice->getFilePath()).DIRECTORY_SEPARATOR.'copy_'.basename($oInvoice->getFilePath());
 
-				// Nun schauen ob die Original Rechnung existiert				
+				// Nun schauen ob die Original Rechnung existiert
 				if ($rechnung['gnr'] != "") {
 
@@ -639,13 +639,13 @@
 					$rn_file = $oInvoiceOrigin->getFilePath();
 				
-				} 
+				}
 				
 				if (!file_exists($rn_file)) die(__("Die Originalrechnung existiert nicht im Dateisystem.", 'wpsg'));
 
 				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.'FPDI_2.2.0/autoload.php';
 				require_once WPSG_PATH_LIB.'wpsg_fpdf.class.php';
 				
-				$pdf = new wpsg_fpdf(); 
+				$pdf = new wpsg_fpdf();
 				$pagecount = $pdf->setSourceFile($rn_file);
 
@@ -653,22 +653,22 @@
 
 					$tplidx = $pdf->importPage($i, '/MediaBox');
-					$pdf->addPage(); 
+					$pdf->addPage();
 					$pdf->useTemplate($tplidx, 0, 0);
 
-					$pdf->SetTextColor(125, 125, 125); 
+					$pdf->SetTextColor(125, 125, 125);
 					$pdf->SetFont('Arial', '', 200);
 					
 					$pdf->SetAlpha(0.25);
 					$pdf->TextWithRotation(45, 225, "KOPIE", 45, 0);
-					$pdf->SetAlpha(0);					
-					
-				}
-				 
+					$pdf->SetAlpha(0);
+					
+				}
+				
 				$pdf->Output($rn_file_copy, 'F');
  
 				$rn_file_copy = $this->copyTemp($rn_file_copy, $nr);
-								
+				
 				// Bestellung in anderer Sprache ?
-				if (trim($this->shop->view['order']['language']) != '') $this->shop->setTempLocale($this->shop->view['order']['language']);				
+				if (trim($this->shop->view['order']['language']) != '') $this->shop->setTempLocale($this->shop->view['order']['language']);
 				
 				// Mail versenden
@@ -686,9 +686,9 @@
 				
 				$arFiles = array($rn_file_copy);
- 				
+ 			
 				if ($this->shop->get_option('wpsg_widerrufsformular_invoice') === '1' && wpsg_isSizedString($this->shop->get_option('wpsg_revocationform'))) {
 
 					$revocationFile = WPSG_PATH_UPLOADS.'wpsg_revocation/'.$this->shop->get_option('wpsg_revocationform');
-						
+					
 					if (file_exists($revocationFile) && is_file($revocationFile)) {
 				
@@ -696,5 +696,5 @@
 				
 					}
-						
+					
 				}
 				
@@ -721,10 +721,26 @@
                 
 				$pdf->Output(basename($rn_file_copy), 'I');
-                
+    
 				exit;
 				
-			}
-			
-		} // public function order_ajax() 
+			} else if (isset($_REQUEST['do']) && $_REQUEST['do'] == 'rebuildadmin') {
+				
+				\check_admin_referer('wpsg-mod_invoice-order_ajax-rebuildadmin-'.wpsg_getInt($_REQUEST['edit_id']));
+				
+				$rechnung = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `id` = '".wpsg_q($_REQUEST['r_id'])."'");
+				$oInvoice = \wpsg\wpsg_invoice::getInstance(intval($_REQUEST['r_id']));
+ 
+				if ($rechnung['id'] != $_REQUEST['r_id'] || !in_array(intval($_REQUEST['edit_id']), $oInvoice->getOrderIds())) die(__("Rechnung existiert nicht oder passt nicht zur Bestellung!", "wpsg"));
+				
+				$this->writeRechnung(
+					intval($_REQUEST['edit_id']),
+					false,
+					true,
+					$oInvoice
+				);
+				
+			}
+			
+		} // public function order_ajax()
 		
 		private function getAdresse($kid)
@@ -763,5 +779,5 @@
 					C.`deleted` != '1'
 			");
-				
+			
 		}
 
@@ -772,14 +788,14 @@
 			wpsg_saveEMailConfig("accountingmail");
 			wpsg_saveEMailConfig("rechnungscopy");
-			 
+			
 		} // public function admin_emailconf_save()
 		
-		public function admin_emailconf() 
-		{ 
+		public function admin_emailconf()
+		{
 			
 			echo wpsg_drawEMailConfig(
 				'invoicemail',
 				__('E-Mail bei neuer Rechnung an den Kunden', 'wpsg'),
-				__('Diese Mail bekommt der Kunde wenn die Rechnung geschrieben wird.', 'wpsg')); 
+				__('Diese Mail bekommt der Kunde wenn die Rechnung geschrieben wird.', 'wpsg'));
 		
 			echo wpsg_drawEMailConfig(
@@ -804,5 +820,5 @@
 
 		private function writeGutschrift($order_id, $gnr_id, $storno_fee, $bPreview) {
-				
+			
 			if (!$bPreview) {
 			
@@ -823,5 +839,5 @@
 				WHERE
 					O.`id` = '".wpsg_q($order_id)."'
-			");		
+			");
 			
 			$this->shop->view['payment'] = $this->shop->getPaymentName(@$this->shop->view['data']['type_payment'], $order_id);
@@ -830,7 +846,7 @@
 			
 			$this->getAdresse($this->shop->view['data']['k_id']);
-						 
+			
 			$this->shop->view['fussText'] = false;
-						
+			
 			$oCalculation = new \wpsg\wpsg_calculation();
 			$oCalculationOrder = \wpsg\wpsg_calculation::getOrderCalculation($order_id);
@@ -841,7 +857,7 @@
 				$discount = $oCalculationOrder->getDiscount();
 				if ($discount !== null) $oCalculation->addDiscount(
-					$discount['set'], 
-					$discount['bruttonetto'], 
-					$discount['tax_key'], 
+					$discount['set'],
+					$discount['bruttonetto'],
+					$discount['tax_key'],
 					$discount['amount']
 				);
@@ -893,5 +909,5 @@
 			$this->shop->view['rDatum'] = date('d.m.Y');
 			
-			$oDefaultCountry = $oOrder->getInvoiceCountry();	
+			$oDefaultCountry = $oOrder->getInvoiceCountry();
 			$oCalculation->addCountry($oDefaultCountry->id, $oDefaultCountry->mwst, $oDefaultCountry->mwst_a,$oDefaultCountry->mwst_b, $oDefaultCountry->mwst_c, $oDefaultCountry->mwst_d, true);
 			
@@ -899,5 +915,5 @@
 				 
 				$oCalculation->addShipping(
-					$oOrder->__get('shipping_set'), 
+					$oOrder->__get('shipping_set'),
 					$oOrder->__get('shipping_bruttonetto'),
 					$oOrder->__get('shipping_tax_key'),
@@ -906,5 +922,5 @@
 				
 				$oCalculation->addPayment(
-					$oOrder->__get('payment_set'), 
+					$oOrder->__get('payment_set'),
 					$oOrder->__get('payment_bruttonetto'),
 					$oOrder->__get('payment_tax_key'),
@@ -922,5 +938,5 @@
 				
 				if ($order_product_info['set'] === '1') {
-					 
+					
 					$oOrderProduct = wpsg_order_product::getInstance($order_product_id);
 				
@@ -930,7 +946,7 @@
 						if (!is_array($invoice_data)) $invoice_data = [];
 						
-						$invoice_data[] = [						
+						$invoice_data[] = [
 							'amount' => $order_product_info['amount'],
-							'invoice_id' => $gnr_id						
+							'invoice_id' => $gnr_id
 						];
 						
@@ -948,5 +964,5 @@
 						$oOrderProduct->getId(),
 						(($oOrderProduct->getProduct()->data['euleistungsortregel'] === '1')?true:false)
-					); 
+					);
 					
 					$p = [
@@ -958,5 +974,5 @@
 						'price' => $oOrderProduct->getPrice($tax_view),
 						'weight' => $oOrderProduct->weight,
-						'anr' => $oOrderProduct->getProduct()->getNr(), 
+						'anr' => $oOrderProduct->getProduct()->getNr(),
 						'mwst_value' => $oOrder->getInvoiceCountry()->getTax($oOrderProduct->getTaxKey()),
 						'preis_netto' => $oOrderProduct->getPrice(WPSG_NETTO),
@@ -964,5 +980,5 @@
 						'name' => $oOrderProduct->getProduct()->getProductName(false),
 						'detailname' => $oOrderProduct->getProduct()->getProductName(true),
-						'beschreibung' => $oOrderProduct->getDescription()						
+						'beschreibung' => $oOrderProduct->getDescription()
 					];
 
@@ -975,5 +991,5 @@
 					
 						if ($produkt_trans['id'] > 0) {
-								
+							
 							$p['name'] = $produkt_trans['name'];
 							$p['beschreibung'] = $produkt_trans['beschreibung'];
@@ -997,5 +1013,5 @@
 				'sum' => [
 					'preis_gesamt_netto' => $oCalculation->getSum(WPSG_NETTO),
-					'preis_gesamt_brutto' => $oCalculation->getSum(WPSG_BRUTTO),					
+					'preis_gesamt_brutto' => $oCalculation->getSum(WPSG_BRUTTO),
 				]
 			];
@@ -1013,5 +1029,5 @@
 				}
 				
-			} 
+			}
 			
 			if ($storno_fee !== '') {
@@ -1019,5 +1035,5 @@
 				if (strpos($storno_fee, '%') !== false) {
 					
-					$storno_proz = str_replace('%', '', $storno_fee);					
+					$storno_proz = str_replace('%', '', $storno_fee);
 					$storno_fee_value = $this->shop->view['basket']['sum']['preis_gesamt_brutto'] - ($this->shop->view['basket']['sum']['preis_gesamt_brutto'] / 100 * $storno_proz);
 					
@@ -1043,5 +1059,5 @@
 				
 					$oInvoice->setMeta('include_shipping', '1');
-									
+					
 				}
 				
@@ -1061,8 +1077,8 @@
 			
 			$this->shop->restoreTempLocale();
-						
+			
 		} // private function writeGutschrift($order_id)
 		
-		public function writeRechnung($order_id, $preview, $bOutput = true) {
+		public function writeRechnung($order_id, $preview, $bOutput = true, ?\wpsg\wpsg_invoice $_oInvoice = null) {
 			
 			$bOK = false;
@@ -1079,5 +1095,5 @@
 			}
 			
-			if (!$bOK && !$preview) throw new \Exception(__('Kein Produkt ausgewÃ€hlt!', 'wpsg'));
+			if (!$bOK && !$preview && $_oInvoice === null) throw new \Exception(__('Kein Produkt ausgewÃ€hlt!', 'wpsg'));
 			
 			$this->shop->view['output'] = $bOutput;
@@ -1095,7 +1111,7 @@
 			
 			$this->getAdresse($this->shop->view['data']['k_id']??0);
-			 
+			
 			$oOrder = wpsg_order::getInstance($order_id);
-						
+			
 			$custom_data = @unserialize($this->shop->view['data']['custom_data']);
 		
@@ -1108,10 +1124,10 @@
                 else throw \wpsg\Exception::getSanitizeException();
 
-            }
+            } else if ($_oInvoice !== null) $this->shop->view['rDatum'] = $_oInvoice->getDate('Y-m-d');
 		
 			if ($this->shop->hasMod('wpsg_mod_shippingadress') && $this->shop->callMod('wpsg_mod_shippingadress', 'check_different_shippingadress', array('k_id' => @$this->shop->view['data']['k_id'], 'o_id' => @$this->shop->view['data']['id']))) {
 				
 				$temp = $this->db->fetchRow("
-					SELECT 
+					SELECT
 						*
 					FROM
@@ -1134,5 +1150,5 @@
 				$this->shop->view['data']['shipping_land']['name'] = $t['kuerzel'];
 				
-			}	
+			}
 			
 			$this->shop->view['payment'] = $this->shop->getPaymentName(@$this->shop->view['data']['type_payment'], $order_id);
@@ -1140,5 +1156,5 @@
 			
 			if (($_REQUEST['wpsg_rechnungen_faelligkeit']??'') == '1') {
-			    
+			 
 				if (wpsg_checkInput($_REQUEST['wpsg_rechnungen_faelligkeitsdatum'], WPSG_SANITIZE_DATE_EN)) $this->shop->view['faelligkeitdatum'] = $_REQUEST['wpsg_rechnungen_faelligkeitsdatum'];
 				else throw \wpsg\Exception::getSanitizeException();
@@ -1146,5 +1162,5 @@
 			}
 			
-			$oCalculation = new \wpsg\wpsg_calculation();			
+			$oCalculation = new \wpsg\wpsg_calculation();
 			$oCalculationOrder = \wpsg\wpsg_calculation::getOrderCalculation($order_id);
 
@@ -1160,10 +1176,10 @@
 					$country['b_'.$country['id']],
 					$country['c_'.$country['id']],
-					$country['d_'.$country['id']],					
+					$country['d_'.$country['id']],
 					$country['default']
 				);
 				
 			}
-						
+			
 			if (intval($_REQUEST['wpsg_rechnungen_discount_voucher_coupon']??0) > 0) {
 				
@@ -1173,7 +1189,7 @@
 					
 					$oCalculation->addDiscount(
-						$discount['set'], 
-						$discount['bruttonetto'], 
-						$discount['tax_key'], 
+						$discount['set'],
+						$discount['bruttonetto'],
+						$discount['tax_key'],
 						$discount['amount']
 					);
@@ -1222,12 +1238,13 @@
 			
 			// $oCalculation->addCountry($oDefaultCountry->id, $oDefaultCountry->mwst, $oDefaultCountry->mwst_a,$oDefaultCountry->mwst_b, $oDefaultCountry->mwst_c, $oDefaultCountry->mwst_d, true);
-						
+			
 			$arProduct = [];
-			$sum = []; 
+			$sum = [];
 			$sum['weight_gesamt'] = 0;
 
 			$tax_view = WPSG_NETTO;
-
+ 
             if (isset($_REQUEST['invoice_products'])) {
+				
                 foreach ($_REQUEST['invoice_products'] as $order_product_id => $order_product_info) {
 
@@ -1294,12 +1311,91 @@
                 }
 
-            }
-
+            } else if ($_oInvoice !== null) {
+				 
+				$oOrder = \wpsg_order::getInstance($order_id);
+				
+				foreach ($oOrder->getOrderProducts() as $oOrderProduct) {
+				
+					$order_product_info = null;
+					
+					$invoice_data = json_decode($oOrderProduct->getMeta('wpsg_mod_rechnungen_data', false, 'null'), true);
+					if (!is_array($invoice_data)) $invoice_data = [];
+					print_r($invoice_data);
+					foreach ($invoice_data as $oi) {
+						
+						if ($oi['invoice_id'] === $_oInvoice->getId()) {
+							
+							$order_product_info = $oi; break;
+							
+						}
+						
+					}
+					
+					if ($order_product_info === null) die("-.-");
+					
+					$oCalculation->addProduct(
+						$oOrderProduct->getPrice($tax_view),
+						$tax_view,
+						$oOrderProduct->getProduct()->__get('mwst_key'),
+						$order_product_info['amount'],
+						$oOrderProduct->getProductKey(),
+						$oOrderProduct->getProductIndex(),
+						$oOrderProduct->getId(),
+						(($oOrderProduct->getProduct()->data['euleistungsortregel'] === '1') ? true : false)
+					);
+					
+					$p = [
+						'oOrderProduct' => $oOrderProduct,
+						'id' => $oOrderProduct->getProductKey(),
+						'product_index' => $oOrderProduct->getProductIndex(),
+						'productkey' => $oOrderProduct->getProductKey(),
+						'menge' => $order_product_info['amount'],
+						'price' => $oOrderProduct->getPrice($tax_view),
+						'weight' => $oOrderProduct->weight,
+						'anr' => $oOrderProduct->getProduct()->getNr(),
+						'mwst_value' => $oOrder->getInvoiceCountry()->getTax($oOrderProduct->getTaxKey()),
+						'preis_netto' => $oOrderProduct->getPrice(WPSG_NETTO),
+						'preis_brutto' => $oOrderProduct->getPrice(WPSG_BRUTTO),
+						'name' => $oOrderProduct->getProduct()->getProductName(false),
+						'detailname' => $oOrderProduct->getProduct()->getProductName(true),
+						'beschreibung' => $oOrderProduct->getDescription()
+					];
+
+					$sum['weight_gesamt'] += $p['weight'];
+
+					if ($oCalculationOrder->getTaxMode() === \wpsg\wpsg_calculation::TAXMODE_B2B) {
+
+						$p['preis_brutto'] = $p['preis_netto'];
+						$p['mwst_value'] = 0;
+
+					}
+
+					// Ãbersetzung
+					if ($this->shop->isOtherLang()) {
+
+						$produkt_trans = $this->db->fetchRow("SELECT * FROM `" . WPSG_TBL_PRODUCTS . "` WHERE `lang_parent` = '" . wpsg_q($oOrderProduct->getProduct()->getId()) . "' AND `lang_code` = '" . wpsg_q($this->shop->getCurrentLanguageCode()) . "'");
+
+						if ($produkt_trans['id'] > 0) {
+
+							$p['name'] = $produkt_trans['name'];
+							$p['beschreibung'] = $produkt_trans['beschreibung'];
+							$p['detailname'] = $produkt_trans['detailname'];
+
+						}
+
+					}
+
+					$arProduct[] = $p;
+				
+				}
+				
+			}
+ 
 			$oCalculation->setWeight($sum['weight_gesamt']);
-							
+			
 			if (($_REQUEST['wpsg_rechnungen_shippay']??'0') === '1') {
 				
 				$oCalculation->addShipping(
-					$oOrder->__get('shipping_set'), 
+					$oOrder->__get('shipping_set'),
 					$oOrder->__get('shipping_bruttonetto'),
 					$oOrder->__get('shipping_tax_key'),
@@ -1308,5 +1404,5 @@
 				
 				$oCalculation->addPayment(
-					$oOrder->__get('payment_set'), 
+					$oOrder->__get('payment_set'),
 					$oOrder->__get('payment_bruttonetto'),
 					$oOrder->__get('payment_tax_key'),
@@ -1345,5 +1441,5 @@
 				}
 				
-			} 			
+			}
 			
 			if ($this->shop->view['basket']['arCalculation']['sum']['discount_netto'] < 0) {
@@ -1355,5 +1451,5 @@
 				
 			}
-				
+			
 			if (($_REQUEST['wpsg_rechnungen_shippay']??'0') === '1') {
 				
@@ -1363,20 +1459,28 @@
 			}
 			
-			// Rechnungsnummer bilden
-			$rnr_format = $this->shop->get_option("wpsg_rechnungen_format");
-			if ($rnr_format == "") $rnr_format = "%nr%";
-				
-			// Neue Fortlaufende Nummer				
-			$rnr_nr = intval($this->shop->get_option("wpsg_rechnungen_start"));
-			if ($rnr_nr <= 0) $rnr_nr = 1;
-				
-			// Ersetzungen
-			$rnr = preg_replace("/\%nr\%/i", $rnr_nr, $rnr_format);
-			$rnr = preg_replace("/\%Jahr\%/i", date("Y"), $rnr);
-			$rnr = preg_replace("/\%Monat\%/i", date("m"), $rnr);
-			$rnr = preg_replace("/\%Tag\%/i", date("d"), $rnr);
-							
-			$rnr = $this->shop->replaceUniversalPlatzhalter($rnr, $order_id);
-			$oInvoice = null;
+			if ($_oInvoice !== null) {
+				
+				$rnr = $_oInvoice->getNr();
+				
+			} else {
+				
+				// Rechnungsnummer bilden
+				$rnr_format = $this->shop->get_option("wpsg_rechnungen_format");
+				if ($rnr_format == "") $rnr_format = "%nr%";
+				
+				// Neue Fortlaufende Nummer
+				$rnr_nr = intval($this->shop->get_option("wpsg_rechnungen_start"));
+				if ($rnr_nr <= 0) $rnr_nr = 1;
+				
+				// Ersetzungen
+				$rnr = preg_replace("/\%nr\%/i", $rnr_nr, $rnr_format);
+				$rnr = preg_replace("/\%Jahr\%/i", date("Y"), $rnr);
+				$rnr = preg_replace("/\%Monat\%/i", date("m"), $rnr);
+				$rnr = preg_replace("/\%Tag\%/i", date("d"), $rnr);
+				
+				$rnr = $this->shop->replaceUniversalPlatzhalter($rnr, $order_id);
+				$oInvoice = null;
+				
+			}
 			
 			if ($preview) {
@@ -1385,7 +1489,7 @@
 				$this->shop->view['rnr'] = $rnr.' - '.__('Vorschau', 'wpsg');
 				$r_id = "Vorschau";
-												
-			} else {
-				 
+				
+			} else if ($_oInvoice === null) {
+				
 				$this->shop->view['preview'] = false;
 				$this->shop->view['rnr'] = $rnr;
@@ -1395,7 +1499,7 @@
 				// Status Ã€ndern
 				if ($_REQUEST['wpsg_rechnungen_status'] == "1") {
-						
+					
 					$this->shop->setOrderStatus($order_id, wpsg_sinput("key", $_REQUEST['wpsg_rechnungen_status_neu']), false);
-											
+					
 				}
  
@@ -1417,6 +1521,16 @@
 				
 					$oInvoice->setMeta('include_shipping', '1');
-									
-				}
+					
+				}
+				
+			} else {
+				
+				$rnr = $_oInvoice->getNr();
+				$r_id = $_oInvoice->getId();
+				$oInvoice = $_oInvoice;
+				
+				$this->shop->view['preview'] = false;
+				$this->shop->view['rnr'] = $rnr;
+				
 				
 			}
@@ -1430,8 +1544,8 @@
 			$this->shop->view['invoice'] = true;
 			
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_rechnungen/invoice_pdf.phtml');	
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_rechnungen/invoice_pdf.phtml');
  
-			if (!$preview) {
-				 
+			if (!$preview && $_oInvoice === null) {
+				
 				foreach ($this->shop->view['basket']['produkte'] as $p) {
 					
@@ -1442,7 +1556,7 @@
 					if (!is_array($invoice_data)) $invoice_data = [];
 					
-					$invoice_data[] = [						
+					$invoice_data[] = [
 						'amount' => $p['menge'],
-						'invoice_id' => $r_id						
+						'invoice_id' => $r_id
 					];
 					
@@ -1465,5 +1579,5 @@
 					else { $mail_html = false; }
 					
-					$empfaenger = $_REQUEST['wpsg_rechnungen_email']; 
+					$empfaenger = $_REQUEST['wpsg_rechnungen_email'];
 
 					$arFiles = array($file);
@@ -1474,7 +1588,7 @@
 					
 						if (file_exists($revocationFile) && is_file($revocationFile)) {
-								
+							
 							$arFiles[] = $revocationFile;
-								
+							
 						}
 					
@@ -1492,19 +1606,19 @@
 						"cdate" => "NOW()",
 						"o_id" => wpsg_q($this->shop->view['data']['id']),
-					    "title" => wpsg_q(wpsg_translate(__('Rechnungsmail an #1#', 'wpsg'), $empfaenger)),				
+					    "title" => wpsg_q(wpsg_translate(__('Rechnungsmail an #1#', 'wpsg'), $empfaenger)),
 						"mailtext" => wpsg_q($mail_text)
-					));						
-									
-				}
-								
+					));
+					
+				}
+				
 				// Url Benachrichtigung
 				if (wpsg_isSizedString($_REQUEST['wpsg_rechnungen_url'], '1')) {
 					
 					$this->shop->notifyURL(
-						$this->shop->get_option('wpsg_rechnungen_url'), 
-						false, 
-						false, 
-						$this->shop->view['data']['id'], 
-						2						
+						$this->shop->get_option('wpsg_rechnungen_url'),
+						false,
+						false,
+						$this->shop->view['data']['id'],
+						2
 					);
 					
@@ -1580,7 +1694,7 @@
 					// Status Ã€ndern
 					if ($_REQUEST['wpsg_Multirechnung_status'] === "1") {
-							
+						
 						$this->shop->setOrderStatus($o_id, intval($_REQUEST['wpsg_Multirechnung_status_neu']), false);
-												
+						
 					}
 					
@@ -1589,13 +1703,13 @@
 						
 						$this->shop->notifyURL(
-							$this->shop->get_option('wpsg_rechnungen_url'), 
-							false, 
-							false, 
-							$o_id, 
-							2						
+							$this->shop->get_option('wpsg_rechnungen_url'),
+							false,
+							false,
+							$o_id,
+							2
 						);
 						
 					}
-										
+					
 				}
 				
@@ -1603,5 +1717,5 @@
 				
 				foreach ($arCalculation['coupon'] as $c) $arCalculationSum['coupon'][] = $c;
-								
+				
 				$this->shop->view['multi_data']['order_data'][$o_id] = [
 					'oCalculation' => $oCalculation,
@@ -1641,9 +1755,9 @@
 			$rnr_format = $this->shop->get_option("wpsg_rechnungen_format");
 			if ($rnr_format == "") $rnr_format = "%nr%";
-				
-			// Neue Fortlaufende Nummer				
+			
+			// Neue Fortlaufende Nummer
 			$rnr_nr = intval($this->shop->get_option("wpsg_rechnungen_start"));
 			if ($rnr_nr <= 0) $rnr_nr = 1;
-				
+			
 			// Ersetzungen
 			$rnr = preg_replace("/\%nr\%/i", $rnr_nr, $rnr_format);
@@ -1651,7 +1765,7 @@
 			$rnr = preg_replace("/\%Monat\%/i", date("m"), $rnr);
 			$rnr = preg_replace("/\%Tag\%/i", date("d"), $rnr);
-							
+			
 			$rnr = $this->shop->replaceUniversalPlatzhalter($rnr, $order_id);
-			 
+			
 			if ($preview) {
 				
@@ -1660,12 +1774,12 @@
 				
 				$r_id = "Vorschau";
-												
+				
 			} else {
-				 
+				
 				$this->shop->view['preview'] = false;
 				$this->shop->view['rnr'] = $rnr;
 				
 				$this->shop->update_option("wpsg_rechnungen_start", ($rnr_nr + 1));
-				 
+				
 				$r_id = $this->db->importQuery(
 					WPSG_TBL_RECHNUNGEN,
@@ -1695,5 +1809,5 @@
 						if (!is_array($invoice_data)) $invoice_data = [];
 						
-						$invoice_data[] = [						
+						$invoice_data[] = [
 							'amount' => $oOrderProduct->getAmount(),
 							'invoice_id' => $oInvoice->getId()
@@ -1715,5 +1829,5 @@
 			$this->shop->view['oOrder'] = $this->shop->cache->loadOrderObject($order_id);
 
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_rechnungen/multi_invoice_pdf.phtml');	
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_rechnungen/multi_invoice_pdf.phtml');
 
 			if (!$preview) {
@@ -1722,8 +1836,8 @@
 					
 					//Mail versenden
-					$oInvoice = \wpsg\wpsg_invoice::getInstance($r_id);				
+					$oInvoice = \wpsg\wpsg_invoice::getInstance($r_id);
 					$oInvoice->setMeta('version', '3');
 
-					$file = $oInvoice->getFilePath(); 
+					$file = $oInvoice->getFilePath();
 					$file = $this->copyTemp($file, $rnr);
 
@@ -1733,6 +1847,6 @@
 					else { $mail_html = false; }
 					
-					$empfaenger = $_REQUEST['wpsg_Multirechnung_email']; 
-													 
+					$empfaenger = $_REQUEST['wpsg_Multirechnung_email'];
+					
 					$header = "";
 					$arFiles = array($file);
@@ -1743,7 +1857,7 @@
 					
 						if (file_exists($revocationFile) && is_file($revocationFile)) {
-								
+							
 							$arFiles[] = $revocationFile;
-								
+							
 						}
 					
@@ -1756,6 +1870,6 @@
 					
 					$this->shop->restoreTempLocale();
-										
-					// Log in jede Bestellung eintragen 
+					
+					// Log in jede Bestellung eintragen
 					foreach ($order_ids as $order_id) {
 						
@@ -1764,12 +1878,12 @@
 							"cdate" => "NOW()",
 							"o_id" => wpsg_q($order_id),
-						    "title" => wpsg_q(wpsg_translate(__('Rechnungsmail an #1#', 'wpsg'), $empfaenger)),				
+						    "title" => wpsg_q(wpsg_translate(__('Rechnungsmail an #1#', 'wpsg'), $empfaenger)),
 							"mailtext" => wpsg_q($mail_text)
 						));
 
 					}
-									
-				}
-												
+					
+				}
+				
 			}
 
@@ -1806,13 +1920,13 @@
 			if (isset($_REQUEST['wpsg_storno_preview'])) $bPreview = true;
 			else $bPreview = false;
-												
+			
 			// Gutschriftnummer bilden
 			$gnr_format = $this->shop->get_option("wpsg_gutschrift_format");
 			if ($gnr_format == "") $gnr_format = "%nr%";
-				
-			// Neue Fortlaufende Nummer				
+			
+			// Neue Fortlaufende Nummer
 			$gnr_nr = intval($this->shop->get_option("wpsg_gutschrift_start"));
 			if ($gnr_nr <= 0) $gnr_nr = 1;
-				
+			
 			// StornierungsgebÃŒhr
 			if (($_REQUEST['storno_fee_set']??'0') === '1') $storno_fee = $_REQUEST['storno_fee_value'];
@@ -1828,5 +1942,5 @@
 
 			$gnr = $this->shop->replaceUniversalPlatzhalter($gnr, $_REQUEST['edit_id']);
-				
+			
 			if (!$bPreview) {
 				
@@ -1844,13 +1958,13 @@
 				
 			} else {
-								
+				
 				$g_id = $gnr_nr;
 			
 			}
- 			
+ 		
 			$this->writeGutschrift($_REQUEST['edit_id'], $g_id, $storno_fee, $bPreview);
-				
+			
 			if (isset($_REQUEST['storno_send'])) {
-											
+				
 				// Mail an Kunden senden
 				//public function mail($e_mail, $subject, $message, $headers, $anhang = array())
@@ -1877,5 +1991,5 @@
 					$to = $_REQUEST['storno_mail'];
 					
-					$arFiles = array($file);						
+					$arFiles = array($file);
 					$this->shop->sendMail($mail_text, $to, 'accountingmail', $arFiles, false, false, $mail_html);
 				
@@ -1890,5 +2004,5 @@
 					
 					$subject = wpsg_translate(__('Rechnungskorrekturmail an #1#', 'wpsg'), $this->shop->view['kunde']['email']);
-													
+					
 					// In Bestelllog eintragen
 					$this->db->ImportQuery(WPSG_TBL_OL, array(
@@ -1901,5 +2015,5 @@
 				}
 
-			} 
+			}
 			
 			$this->shop->restoreTempLocale();
@@ -1908,5 +2022,5 @@
 			
 		}
-		 
+		
 		public function setOrderStatus_after($order_id, $status_id, $inform) {
 			
@@ -1916,5 +2030,5 @@
 			
 		} // public function setOrderStatus($order_id, $status_id, $inform)
-		 
+		
 		/**
 		 * @param wpsg_order_product $oOrderProduct
@@ -1945,6 +2059,6 @@
 
 					} catch (\Exception $e) { }
-										
-				} 
+					
+				}
 				
 				return $amount_storno;
@@ -1955,5 +2069,5 @@
 				
 			}
-						
+			
 		}
 
@@ -2023,6 +2137,6 @@
 
 					} catch (\Exception $e) { }
-										
-				} 
+					
+				}
 				
 				return $oOrderProduct->getAmount() - $amount_invoiced;
@@ -2033,5 +2147,5 @@
 				
 			}
-						
+			
 		}
 		
@@ -2051,5 +2165,5 @@
 			
 		} // private function copyTemp($file, $r_id)
-         
+        
         public function getDownloadFile($r_id) {
 
@@ -2084,5 +2198,5 @@
 		public function getFrontendLink($r_id)
 		{
-			 
+			
 			$hash = md5($this->shop->get_option('wpsg_salt').'wpsg'.$r_id.'wpsg'.$this->shop->get_option('wpsg_salt'));
 			
@@ -2092,5 +2206,5 @@
 			
 			return $url;
-			 
+			
 		} // public function getFrontendLink($r_id)
 
@@ -2100,10 +2214,10 @@
 		public function getRechnungstexte($order_id)
 		{
-									
+			
 			$arTexte = $this->shop->get_option("wpsg_mod_rechnungen_texte");
 			
 			if (wpsg_isSizedArray($arTexte))
 			{
-						
+				
 				foreach ($arTexte as $k => $v)
 				{
@@ -2201,5 +2315,5 @@
  			
 			$oOrder = wpsg_order::getInstance($order_id, true);
-			 
+			
 			$_REQUEST['invoice_products'] = [];
 			$_REQUEST['wpsg_rechnungen_datum'] = date('Y-m-d');
@@ -2228,5 +2342,5 @@
 				
 			}
- 			
+ 		
 			$_REQUEST['wpsg_rechnungen_email'] = $customer_data['email'];
  			$_REQUEST['wpsg_rechnungen_fusstext'] = '';
@@ -2234,5 +2348,5 @@
  			$_REQUEST['wpsg_rechnungen_status'] = '1';
 			$_REQUEST['wpsg_rechnungen_status_neu'] = '110';
- 				 
+ 			
  			// FÃ€lligkeit anzeigen wenn ein Wert im Backend fÃŒr die Tage gesetzt ist.
  			if (intval($this->shop->get_option('wpsg_rechnungen_faelligkeit')) > 0) {
@@ -2242,5 +2356,5 @@
  			
  			}
- 				
+ 			
  			// StandardfuÃtext setzen, sollte er definiert sein
  			if ($this->shop->get_option('wpsg_rechnungen_foottext_standard') !== false) {
@@ -2252,7 +2366,7 @@
  				if (isset($foot_text[$this->shop->get_option('wpsg_rechnungen_foottext_standard')]))
  				{
- 						
+ 					
  					$_REQUEST['wpsg_rechnungen_fusstext'] = $foot_text[$this->shop->get_option('wpsg_rechnungen_foottext_standard')][1];
- 						
+ 					
  				}
  			
@@ -2262,5 +2376,5 @@
  			
 			    $this->writeRechnung($order_id, false, false);
-			    			    
+			    
 		    } catch (Exception $e) {
 			    
Index: /views/mods/mod_prepayment/order_done.phtml
===================================================================
--- /views/mods/mod_prepayment/order_done.phtml	(revision 8368)
+++ /views/mods/mod_prepayment/order_done.phtml	(revision 8369)
@@ -29,9 +29,12 @@
 		<?php 
 
+		try {
+			
 			$img = array();
 			$img = $this->callMod('wpsg_mod_prepayment', 'genQRCode', array($this->view['o_id'], $this->view['wpsg_mod_prepayment']['subject'], $this->view['basket']['sum']['preis_gesamt_brutto'], 10, PhpGirocode::OUTPUT_BASE64, $this->get_option('wpsg_mod_prepayment_qrcode_country'), $this->view['basket']));
-
+ 		
+			
 		?>
-
+ 
 		<div class="wpsg_mod_prepayment_info_wrap">
 			<?php foreach ($img as $i) { ?>
@@ -77,4 +80,5 @@
 		</div>
 
+		<?php } catch (\Exception $e) { } ?>
 
 	<?php } else if ($this->get_option('wpsg_mod_prepayment_qrcode_country') == '1') { ?>
Index: /views/mods/mod_rechnungen/order_view.phtml
===================================================================
--- /views/mods/mod_rechnungen/order_view.phtml	(revision 8368)
+++ /views/mods/mod_rechnungen/order_view.phtml	(revision 8369)
@@ -31,6 +31,12 @@
                         <?php echo $oInvoice->getNr(true); ?>
                     </div>
-                    <div style="text-align:right;">
-                        
+                    <div style="text-align:right; white-space:nowrap;">
+                    
+						<a target="_blank" href="<?php
+						
+							echo wp_nonce_url(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Order&mod=wpsg_mod_rechnungen&noheader=1&action=ajax&edit_id='.$_REQUEST['edit_id'].'&r_id='.$r['id'].'&do=rebuildadmin', 'wpsg-mod_invoice-order_ajax-rebuildadmin-'.$_REQUEST['edit_id']);
+							
+						?>" style="color:red;"><?php echo __('Neu erstellen', 'wpsg'); ?></a>
+						
                         <a target="_blank" onclick="if (!confirm('<?php echo __('Sind Sie sicher, dass Sie eine Kopie dieser Rechnung/Rechnungskorrektur erneut an den Kunden senden mÃ¶chten?', 'wpsg'); ?>')) return false;" href="<?php 
                             
@@ -38,8 +44,8 @@
                                 // Multirechnung
                                 $r_o_ids = array_map('intval', explode(',', $r['o_ids']));
-                                echo wp_nonce_url(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Order&mod=wpsg_mod_rechnungen&noheader=1&action=ajax&edit_id='.$r_o_ids[0].'&r_id='.$r['id'].'&do=copy', 'wpsg-mod_invoice-order_ajax-copy-'.$r_o_ids[0]);
+                                echo wp_nonce_url(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Order&mod=wpsg_mod_rechnungen&noheader=1&action=ajax&edit_id='.$_REQUEST['edit_id'].'&r_id='.$r['id'].'&do=copy', 'wpsg-mod_invoice-order_ajax-copy-'.$_REQUEST['edit_id']);
                             } else {
                                 // normale Rechnung
-                                echo wp_nonce_url(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Order&mod=wpsg_mod_rechnungen&noheader=1&action=ajax&edit_id='.$this->view['data']['id'].'&r_id='.$r['id'].'&do=copy', 'wpsg-mod_invoice-order_ajax-copy-'.$this->view['data']['id']);
+                                echo wp_nonce_url(WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Order&mod=wpsg_mod_rechnungen&noheader=1&action=ajax&edit_id='.$_REQUEST['edit_id'].'&r_id='.$r['id'].'&do=copy', 'wpsg-mod_invoice-order_ajax-copy-'.$_REQUEST['edit_id']);
                             }
 
@@ -60,5 +66,5 @@
 <style>
     
-    #wpsg_mod_rechnungen_order_view .grid { display:grid; width:100%; grid-template-columns:150px 1fr 100px; row-gap:0.25rem; }
+    #wpsg_mod_rechnungen_order_view .grid { display:grid; width:100%; grid-template-columns:150px 1fr 250px; row-gap:0.25rem; column-gap:1rem; }
     
 </style>
