Index: /changelog
===================================================================
--- /changelog	(revision 8454)
+++ /changelog	(revision 8455)
@@ -641,2 +641,5 @@
 - Bugfix: DB Udpdate nach Plugin Update wird ausgefÃŒhrt
 - Feature: Update Log um zukÃŒnftige Probleme beim Update zu erkennen
+
+#4.4.11
+- Bugfix: Korrektur von Rechnungen mit Gutscheinen die zum Rechnungszeitpunkt nicht mehr gÃŒltig sind
Index: /lib/wpsg_calculation.class.php
===================================================================
--- /lib/wpsg_calculation.class.php	(revision 8454)
+++ /lib/wpsg_calculation.class.php	(revision 8455)
@@ -20,4 +20,7 @@
 	     */
         private $order_id = null;
+		
+		/** @var bool Wenn die Berechnung von einer Bestellung gemacht wird dÃŒrfen bestimmte Bedingungen nicht mehr geprÃŒft werden z.B. Gutschein GÃŒltigkeit */
+		public $order_finish = false;
         
         /**
@@ -185,5 +188,5 @@
 			$tax_key = $this->normalizeTaxKey($tax_key);
 			
-			if (strpos($set, '-') === false) $set = '-'.$set; 
+			if (strpos($set, '-') === false) $set = '-'.$set;
 			
 			$this->arCalculationRow['voucher_'.$id.'-'.$order_voucher_id] = [
@@ -515,5 +518,5 @@
 
 					$country_id = $this->getTargetCountry()['id'];
-					 
+					
                 	foreach ($cr['set'] as $set) {
 		
@@ -538,5 +541,5 @@
 
 							if ($cr['type'] === 'voucher') {
-
+ 
 								// Ein Gutschein kann nur fÃŒr bestimmte Produktgruppen/Produkte gelten, das prÃŒfe ich hier und ziehe Produktpreise ab, wenn nicht zulÃ€ssig
 								// Ist partial === true, wurde der Gutschein nicht auf alle Produkte angewendet
@@ -546,5 +549,5 @@
 								$netto_scope = $this->arCalculation['sum']['netto'];
 								$brutto_scope = $this->arCalculation['sum']['brutto'];
-
+ 
 								$cr['data']['partial'] = false;
 
@@ -553,8 +556,8 @@
 									if ($cr2['type'] === 'product') {
 
-										if (!$oVoucher->isUsabel($cr2['data']['product_id'])) {
-
+										if ($oVoucher->isUsabel($cr2['data']['product_id']) === false && $this->order_finish === false) {
+ 
 											list($set_netto, $set_brutto) = $this->calculateTaxPart($cr2['bruttonetto'], $cr2['set'], $cr2['tax_key']);
-
+ 
 											$netto_scope -= $set_netto;
 											$brutto_scope -= $set_brutto;
@@ -574,5 +577,5 @@
 
 							}
-
+ 
 							// Prozentualer Wert
 							$set_netto = $netto_scope / 100 * wpsg_tf($set);
@@ -651,5 +654,5 @@
 														
 					}
-					 
+					
 					$cr['set'] = array_values($cr['set'])[0];
 						
@@ -705,5 +708,5 @@
 					
 					$tax = $brutto - $netto;
-					       					
+					
 					$this->arCalculation[$cr['type']][] = $cr['data'] + [
 						'type' => $cr['type'],
@@ -1262,8 +1265,10 @@
 
 			$this->order_id = $id;
-			
+						
             $db_order = $this->db->fetchRow("SELECT O.*, A.`land` FROM `".WPSG_TBL_ORDER."` AS O LEFT JOIN `".WPSG_TBL_ADRESS."` AS A ON (O.`adress_id` = A.`id`) WHERE O.`id` = '".wpsg_q($id)."' ");
             $db_products = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_ORDERPRODUCT."` WHERE `o_id` = '".wpsg_q($id)."' ");
 
+			if (intval($db_order['status']) !== \wpsg_ShopController::STATUS_UNVOLLSTAENDIG) $this->order_finish = true;
+			
             if (!wpsg_isSizedInt($db_order['calculation'])) {
             	
@@ -1326,5 +1331,5 @@
             			
 					} else {
-            			
+						 
             			$this->addVoucher($v['set_value'], $v['bruttonetto'], $v['tax_key'], 1, $v['code'], $v['voucher_id'], $v['id']);
             			
Index: /mods/wpsg_mod_rechnungen.class.php
===================================================================
--- /mods/wpsg_mod_rechnungen.class.php	(revision 8454)
+++ /mods/wpsg_mod_rechnungen.class.php	(revision 8455)
@@ -135,4 +135,24 @@
 		public function template_redirect()
 		{
+			
+			/*
+			if (isset($_REQUEST['correctInvoice'])) {
+				
+				$_REQUEST['wpsg_rechnungen_discount_voucher_coupon'] = '1';
+				$_REQUEST['wpsg_rechnungen_shippay'] = '1';
+				$_REQUEST['wpsg_rechnungen_datum'] = '2024-11-13';
+				$_REQUEST['rnr'] = '205154';
+				$_REQUEST['wpsg_rechnungen_fusstext'] = 'Der Betrag wurde per PayPal gezahlt. Wir danken fÃŒr Ihre Bestellung und wÃŒnschen erholsamen Schlaf.';
+				$_REQUEST['invoice_products'] = [
+					'46889' => [
+						'set' => '1',
+						'amount' => '1'
+					]
+				];
+				
+				$this->writeRechnung(27762, true, true); exit;
+				
+			}
+			*/
 			
 			if (wpsg_isSizedString($_REQUEST['wpsg_action'], 'wpsg_mod_rechnungen_download'))
@@ -1193,4 +1213,6 @@
 			
 			$oCalculation = new \wpsg\wpsg_calculation();
+			$oCalculation->order_finish = true;
+			
 			$oCalculationOrder = \wpsg\wpsg_calculation::getOrderCalculation($order_id);
 
@@ -1520,5 +1542,8 @@
 				
 				$this->shop->view['preview'] = true;
-				$this->shop->view['rnr'] = $rnr.' - '.__('Vorschau', 'wpsg');
+				
+				if (isset($_REQUEST['rnr'])) $this->shop->view['rnr'] = $_REQUEST['rnr'];
+				else $this->shop->view['rnr'] = $rnr.' - '.__('Vorschau', 'wpsg');
+				
 				$r_id = "Vorschau";
 				
