Index: /controller/wpsg_OrderController.class.php
===================================================================
--- /controller/wpsg_OrderController.class.php	(revision 8070)
+++ /controller/wpsg_OrderController.class.php	(revision 8071)
@@ -1748,6 +1748,4 @@
 						}
 						
-						die('test');
-					
 					} else if (is_numeric($_REQUEST['wpsg_action']) || preg_match('/\d+\_\d+/', $_REQUEST['wpsg_action'])) {
 
Index: /controller/wpsg_ShopController.class.php
===================================================================
--- /controller/wpsg_ShopController.class.php	(revision 8070)
+++ /controller/wpsg_ShopController.class.php	(revision 8071)
@@ -97,4 +97,5 @@
 		const STATUS_ZAHLUNGAKZEPTIERT = 100;
 		const STATUS_RECHNUNGGESCHRIEBEN = 110;
+		const STATUS_SAMMELRECHNUNGGESCHRIEBEN = 120;
 		const STATUS_ZAHLUNGFEHLGESCHLAGEN = 200;
 		const STATUS_WAREVERSENDET = 250;
@@ -2220,5 +2221,5 @@
 		public function protectDirectory($path, $arEnableFiles = []) {
 
-            if (!file_exists($path)) mkdir($path, 0775, true);
+            if (!file_exists($path)) { mkdir($path, 0775, true); }
 
             $htaccess = \trailingslashit($path).'.htaccess';
Index: /mods/mod_rechnungen/wpsg_invoice.php
===================================================================
--- /mods/mod_rechnungen/wpsg_invoice.php	(revision 8070)
+++ /mods/mod_rechnungen/wpsg_invoice.php	(revision 8071)
@@ -39,4 +39,39 @@
 			
 			return $this->__get('gnr') !== '';
+			
+		}
+		
+		public function isMultiInvoice() {
+			
+			return $this->getMeta('version') === '3';
+			
+		}
+
+		/**
+		 * @throws \Exception
+		 */
+		public function getFilePath() {
+			
+			if ($this->isMultiInvoice()) {
+				
+				$ym = date('Y/m', strtotime($this->__get('datum')));
+				
+				if ($this->shop->isMultiBlog()) {
+ 					
+ 					$path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_rechnungen/'.$ym.'/multi/'; 					
+ 					 					
+ 				} else {
+ 					
+ 					$path = WPSG_PATH_CONTENT.'uploads/wpsg/wpsg_rechnungen/'.$ym.'/multi/';
+ 					 					
+ 				}
+				 
+			} else throw new \Exception(_('Noch nicht implementiert'));
+			
+			\wpsg_ShopController::getShop()->protectDirectory($path);
+			
+			$path .= $this->getId().'.pdf';
+			
+			return $path;
 			
 		}
Index: /mods/wpsg_mod_rechnungen.class.php
===================================================================
--- /mods/wpsg_mod_rechnungen.class.php	(revision 8070)
+++ /mods/wpsg_mod_rechnungen.class.php	(revision 8071)
@@ -364,6 +364,6 @@
 			if ($oOrder->status == wpsg_ShopController::STATUS_UNVOLLSTAENDIG) return;
 			
-			$this->shop->view['mod_rechnungen']['arRechnungen'] = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `o_id` = '".wpsg_q($order_id)."' AND `storno` = '0000-00-00 00:00:00' AND `gnr` = '' ORDER BY `rnr` DESC");
-			$this->shop->view['mod_rechnungen']['arRechnungen_storno'] = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `o_id` = '".wpsg_q($order_id)."' AND `storno` != '0000-00-00 00:00:00' AND `gnr` = '' ORDER BY `rnr` DESC");
+			$this->shop->view['mod_rechnungen']['arRechnungen'] = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE (`o_id` = '".wpsg_q($order_id)."' OR FIND_IN_SET('".intval($order_id)."', `o_ids`)) AND `storno` = '0000-00-00 00:00:00' AND `gnr` = '' ORDER BY `rnr` DESC");
+			$this->shop->view['mod_rechnungen']['arRechnungen_storno'] = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE (`o_id` = '".wpsg_q($order_id)."'  OR FIND_IN_SET('".intval($order_id)."', `o_ids`))) AND `storno` != '0000-00-00 00:00:00' AND `gnr` = '' ORDER BY `rnr` DESC");
  
 			$this->shop->view['mod_rechnungen']['arRechnungen_gesamt'] = $this->db->fetchAssoc("
@@ -375,5 +375,8 @@
 					`".WPSG_TBL_RECHNUNGEN."` 
 				WHERE 
-					`o_id` = '".wpsg_q($order_id)."' 
+					(
+						`o_id` = '".wpsg_q($order_id)."' OR 
+						FIND_IN_SET('".intval($order_id)."', `o_ids`)
+					) 
 				ORDER BY 
 					`id` ASC
@@ -1634,6 +1637,4 @@
 
 		public function writeMultiRechnung($order_ids, $preview) {
-
-			$preview = true;
 			
 			$this->shop->view['multi_data']['oids'] = $order_ids;
@@ -1693,4 +1694,28 @@
 				$oCalculation->fromDB($o_id);
 
+				if (!$preview) {
+					
+					// Status Ã€ndern
+					if ($_REQUEST['wpsg_Multirechnung_status'] === "1") {
+							
+						$this->shop->setOrderStatus($o_id, intval($_REQUEST['wpsg_Multirechnung_status_neu']), false);
+												
+					}
+					
+					// Url Benachrichtigung
+					if (wpsg_isSizedString($_REQUEST['wpsg_Multirechnung_url'], '1')) {
+						
+						$this->shop->notifyURL(
+							$this->shop->get_option('wpsg_rechnungen_url'), 
+							false, 
+							false, 
+							$o_id, 
+							2						
+						);
+						
+					}
+					
+				}
+				
 				$arCalculation = $oCalculation->getCalculationArray();
 				
@@ -1758,12 +1783,5 @@
 				
 				$this->shop->update_option("wpsg_rechnungen_start", ($rnr_nr + 1));
-				
-				// Status Ã€ndern
-				if ($_REQUEST['wpsg_Multirechnung_status'] == "1") {
-						
-					$this->shop->setOrderStatus($order_id, wpsg_sinput("key", $_REQUEST['wpsg_Multirechnung_status_neu']), false);
-											
-				}
- 
+				 
 				$r_id = $this->db->importQuery(
 					WPSG_TBL_RECHNUNGEN,
@@ -1774,8 +1792,10 @@
 					)
 				);
-				
+								
 				$oInvoice = \wpsg\wpsg_invoice::getInstance($r_id);				
 				$oInvoice->setMeta('version', '3');
-								
+				
+				$this->shop->view['file_path'] = $oInvoice->getFilePath();
+				
 			}
 			
@@ -1846,18 +1866,5 @@
 									
 				}
-								
-				// Url Benachrichtigung
-				if (wpsg_isSizedString($_REQUEST['wpsg_Multirechnung_url'], '1')) {
-					
-					$this->shop->notifyURL(
-						$this->shop->get_option('wpsg_rechnungen_url'), 
-						false, 
-						false, 
-						$this->shop->view['data']['id'], 
-						2						
-					);
-					
-				}
-				
+												
 			}
 			
@@ -2149,135 +2156,145 @@
             $rechnung = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `id` = '".wpsg_q($r_id)."'");
 
-            $file_path_old = str_replace('/wpsg/', '/', $this->getFilePath('')).$rechnung['o_id'].'/';
-
-            if ($rechnung['gnr'] != "")
-            {
-
-                /**
-                 * Damit alte Rechnungskorrekturen noch angezeigt werden
-                 */
-                if (file_exists($this->getFilePath($rechnung['o_id']).$rechnung['id'].'.pdf'))
-                {
-
-                    $file = $this->getFilePath($rechnung['o_id']).$rechnung['id'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
-
-                }
-                else if (file_exists($this->getFilePath($rechnung['o_id']).$rechnung['gnr'].'.pdf'))
-                {
-
-                    $file = $this->getFilePath($rechnung['o_id']).$rechnung['gnr'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
-
-                }
-                else if (file_exists($this->getFilePath($rechnung['o_id']).'G'.$rechnung['id'].'.pdf'))
-                {
-
-                    $file = $this->getFilePath($rechnung['o_id']).'G'.$rechnung['id'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
-
-                }
-                else if (file_exists($this->getFilePath($rechnung['o_id']).'G'.$rechnung['gnr'].'.pdf'))
-                {
-
-                    $file = $this->getFilePath($rechnung['o_id']).'G'.$rechnung['gnr'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
-
-                } //
-                else if (file_exists($file_path_old.'/'.$rechnung['id'].'.pdf'))
-                {
-
-                    $file = $file_path_old.'/'.$rechnung['id'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
-
-                }
-                else if (file_exists($file_path_old.'/R'.$rechnung['gnr'].'.pdf'))
-                {
-
-                    $file = $file_path_old.'/R'.$rechnung['gnr'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
-
-                }
-                else if (file_exists($file_path_old.'/R'.$rechnung['id'].'.pdf'))
-                {
-
-                    $file = $file_path_old.'/R'.$rechnung['id'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
-
-                }
-                else if (file_exists($file_path_old.'/'.$rechnung['gnr'].'.pdf'))
-                {
-
-                    $file = $file_path_old.'/'.$rechnung['gnr'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
-
-                }
-
-            }
-            else {
-
-                /**
-                 * Damit alte Rechnungen noch angezeigt werden
-                 */
-                if (file_exists($this->getFilePath($rechnung['o_id']).$rechnung['id'].'.pdf'))
-                {
-
-                    $file = $this->getFilePath($rechnung['o_id']).$rechnung['id'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
-
-                }
-                else if (file_exists($this->getFilePath($rechnung['o_id']).$rechnung['rnr'].'.pdf'))
-                {
-
-                    $file = $this->getFilePath($rechnung['o_id']).$rechnung['rnr'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
-
-                }
-                else if (file_exists($this->getFilePath($rechnung['o_id']).'R'.$rechnung['id'].'.pdf'))
-                {
-
-                    $file = $this->getFilePath($rechnung['o_id']).'R'.$rechnung['id'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
-
-                }
-                else if (file_exists($this->getFilePath($rechnung['o_id']).'R'.$rechnung['rnr'].'.pdf'))
-                {
-
-                    $file = $this->getFilePath($rechnung['o_id']).'R'.$rechnung['rnr'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
-
-                }
-                else if (file_exists($file_path_old.'/'.$rechnung['id'].'.pdf'))
-                {
-
-                    $file = $file_path_old.'/'.$rechnung['id'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
-
-                }
-                else if (file_exists($file_path_old.'/R'.$rechnung['rnr'].'.pdf'))
-                {
-
-                    $file = $file_path_old.'/R'.$rechnung['rnr'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
-
-                }
-                else if (file_exists($file_path_old.'/R'.$rechnung['id'].'.pdf'))
-                {
-
-                    $file = $file_path_old.'/R'.$rechnung['id'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
-
-                }
-                else if (file_exists($file_path_old.'/'.$rechnung['rnr'].'.pdf'))
-                {
-
-                    $file = $file_path_old.'/'.$rechnung['rnr'].'.pdf';
-                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
-
-                }
-
-            }
-
-            return $file;
+			$oInvoice = \wpsg\wpsg_invoice::getInstance(intval($r_id));
+			
+			if ($oInvoice->isMultiInvoice()) {
+				
+				return $oInvoice->getFilePath();
+				
+			} else {
+				
+	            $file_path_old = str_replace('/wpsg/', '/', $this->getFilePath('')).$rechnung['o_id'].'/';
+	
+	            if ($rechnung['gnr'] != "")
+	            {
+	
+	                /**
+	                 * Damit alte Rechnungskorrekturen noch angezeigt werden
+	                 */
+	                if (file_exists($this->getFilePath($rechnung['o_id']).$rechnung['id'].'.pdf'))
+	                {
+	
+	                    $file = $this->getFilePath($rechnung['o_id']).$rechnung['id'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($this->getFilePath($rechnung['o_id']).$rechnung['gnr'].'.pdf'))
+	                {
+	
+	                    $file = $this->getFilePath($rechnung['o_id']).$rechnung['gnr'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($this->getFilePath($rechnung['o_id']).'G'.$rechnung['id'].'.pdf'))
+	                {
+	
+	                    $file = $this->getFilePath($rechnung['o_id']).'G'.$rechnung['id'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($this->getFilePath($rechnung['o_id']).'G'.$rechnung['gnr'].'.pdf'))
+	                {
+	
+	                    $file = $this->getFilePath($rechnung['o_id']).'G'.$rechnung['gnr'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
+	
+	                } //
+	                else if (file_exists($file_path_old.'/'.$rechnung['id'].'.pdf'))
+	                {
+	
+	                    $file = $file_path_old.'/'.$rechnung['id'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($file_path_old.'/R'.$rechnung['gnr'].'.pdf'))
+	                {
+	
+	                    $file = $file_path_old.'/R'.$rechnung['gnr'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($file_path_old.'/R'.$rechnung['id'].'.pdf'))
+	                {
+	
+	                    $file = $file_path_old.'/R'.$rechnung['id'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($file_path_old.'/'.$rechnung['gnr'].'.pdf'))
+	                {
+	
+	                    $file = $file_path_old.'/'.$rechnung['gnr'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['gnr'].'.pdf"');
+	
+	                }
+	
+	            }
+	            else {
+	
+	                /**
+	                 * Damit alte Rechnungen noch angezeigt werden
+	                 */
+	                if (file_exists($this->getFilePath($rechnung['o_id']).$rechnung['id'].'.pdf'))
+	                {
+	
+	                    $file = $this->getFilePath($rechnung['o_id']).$rechnung['id'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($this->getFilePath($rechnung['o_id']).$rechnung['rnr'].'.pdf'))
+	                {
+	
+	                    $file = $this->getFilePath($rechnung['o_id']).$rechnung['rnr'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($this->getFilePath($rechnung['o_id']).'R'.$rechnung['id'].'.pdf'))
+	                {
+	
+	                    $file = $this->getFilePath($rechnung['o_id']).'R'.$rechnung['id'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($this->getFilePath($rechnung['o_id']).'R'.$rechnung['rnr'].'.pdf'))
+	                {
+	
+	                    $file = $this->getFilePath($rechnung['o_id']).'R'.$rechnung['rnr'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($file_path_old.'/'.$rechnung['id'].'.pdf'))
+	                {
+	
+	                    $file = $file_path_old.'/'.$rechnung['id'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($file_path_old.'/R'.$rechnung['rnr'].'.pdf'))
+	                {
+	
+	                    $file = $file_path_old.'/R'.$rechnung['rnr'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($file_path_old.'/R'.$rechnung['id'].'.pdf'))
+	                {
+	
+	                    $file = $file_path_old.'/R'.$rechnung['id'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
+	
+	                }
+	                else if (file_exists($file_path_old.'/'.$rechnung['rnr'].'.pdf'))
+	                {
+	
+	                    $file = $file_path_old.'/'.$rechnung['rnr'].'.pdf';
+	                    header('Content-Disposition: attachment; filename="'.$rechnung['rnr'].'.pdf"');
+	
+	                }
+	
+	            }
+	
+	            return $file;
+
+			}
 
         }
@@ -2494,27 +2511,5 @@
  				}
 
-		    } else if ($order_id === 'multi') {
-				 
-				$ym = date('Y/m/');
-				 
-				if ($this->shop->isMultiBlog()) {
- 					
- 					$path = WP_CONTENT_DIR.'/'.WPSG_MB_UPLOADS.'/wpsg/wpsg_rechnungen/'.$ym;
- 					
- 					$url_content = WPSG_URL_CONTENT.WPSG_MB_UPLOADS.'/wpsg/wpsg_rechnungen/'.$ym;
- 					
- 					if ($url) $strReturn = $url_content.'/'.$order_id.'/';
- 					else $strReturn = $path.'/'.$order_id.'/';
- 					
- 				} else {
- 					
- 					$path = WPSG_PATH_CONTENT.'uploads/wpsg/wpsg_rechnungen/'.$ym;
- 					
- 					if ($url) $strReturn = WPSG_URL_CONTENT.'uploads/wpsg/wpsg_rechnungen/'.$ym.$order_id.'/';
- 					else $strReturn = $path.$order_id.'/';
- 					
- 				}
-				
- 			} else {	
+		    } else {	
  			    
  			    // Rechnung aus Bestellung
@@ -2545,5 +2540,5 @@
 						
 			$this->shop->protectDirectory($path);
-						
+			
 			return $strReturn;
 			 
Index: /views/mods/mod_rechnungen/multi_invoice_pdf.phtml
===================================================================
--- /views/mods/mod_rechnungen/multi_invoice_pdf.phtml	(revision 8070)
+++ /views/mods/mod_rechnungen/multi_invoice_pdf.phtml	(revision 8071)
@@ -192,14 +192,5 @@
     $sum_multi_offset = 0;
     $orders = $this->view['multi_data']['orders']; 
-
-    $sum_topay_brutto = 0;
-    $sum_topay_netto = 0;
-    $sum_productsum_brutto = 0;
-    $sum_productsum_netto = 0;
-    $sum_shipping_brutto = 0;
-    $sum_shipping_netto = 0;
-    $sum_payment_brutto = 0;
-    $sum_payment_netto = 0;
-    	
+     	
 	// moMwSt
 	$bNoTax = false;
@@ -725,5 +716,5 @@
 		$pdf->Text($prod_left + 80, $prod_top + $offset, __("Summe", "wpsg"));
 		$pdf->setXY($prod_left + 140, $prod_top + $offset - 5);
-		$pdf->Cell(37, 8, wpsg_ff($sum_productsum_brutto + $arCalculation['sum']['preis_rabatt'], $this->get_option('wpsg_currency')), 0, 0, 'R');
+		$pdf->Cell(37, 8, wpsg_ff($arCalculation['sum']['brutto'], $this->get_option('wpsg_currency')), 0, 0, 'R');
 		
 		$offset += 5;
@@ -791,7 +782,9 @@
 		$pdf->setFont('Arial', '', '9');
 
-        foreach ($orders as $oCoupons){
-
-            foreach ($arCalculation['coupon'] as $c) {
+		foreach ($this->view['multi_data']['order_data'] as $order_data) {
+        
+			$arCalculationOrder = $order_data['arCalculation'];
+
+            foreach ($arCalculationOrder['coupon'] as $c) {
                 
                 $offset += 5;
@@ -873,10 +866,4 @@
 	$offset += 5;
 		
-	if (!file_exists($this->callMod('wpsg_mod_rechnungen', 'getFilePath', array($data['id'])))) {
-		
-		mkdir($this->callMod('wpsg_mod_rechnungen', 'getFilePath', array($data['id'])), 0777, true);
-		
-	}
-		
 	$filename = $this->view['filename'].".pdf";
 	 
@@ -890,8 +877,5 @@
 	} else {
 		
-		$pdf->Output($this->callMod('wpsg_mod_rechnungen', 'getFilePath', array('multi')).$filename, 'F');
-		
-		// Hier wird der Dateiname an FPD ÃŒbergeben. Er soll sich aus der Rechnungsnummer ergeben, auch wenn das Dokument ÃŒber die ID gespeichert ist.
-		if ($this->view['output'] === true) $pdf->Output($this->view['filename_out'], 'I');
+		$pdf->Output($this->view['file_path'], 'F');
 		
 	}
