Index: /changelog
===================================================================
--- /changelog	(revision 8462)
+++ /changelog	(revision 8463)
@@ -643,5 +643,6 @@
 
 #4.4.11
-- Bugfix: Korrektur von Rechnungen mit Gutscheinen die zum Rechnungszeitpunkt nicht mehr gÃŒltig sind
+- Bugfix: Korrektur von Rechnungen mit Gutscheinen, die zum Rechnungszeitpunkt nicht mehr gÃŒltig sind
+- Bugfix: Fehler beim Aktivieren des Downloadprodukte-Moduls ohne angelegte Produkte behoben
 - Bugfix: Lagerbestandsspalte Produktverwaltung korrigiert
 - Bugfix: Uploads bei Downloadprodukten korrigiert
Index: /lib/filter_functions.inc.php
===================================================================
--- /lib/filter_functions.inc.php	(revision 8462)
+++ /lib/filter_functions.inc.php	(revision 8463)
@@ -404,6 +404,8 @@
         if ($key === false) $key = $GLOBALS['wpsg_sc']->get_option('wpsg_key', true);
 
+		var_dump($GLOBALS['wpsg_sc']->get_url_post_content('https://api.maennchen1.de/',));
+
         try {
-			
+
             $api_return = $GLOBALS['wpsg_sc']->get_url_post_content('https://api.maennchen1.de/', array(
                 'f' => $func,
Index: /lib/install.php
===================================================================
--- /lib/install.php	(revision 8462)
+++ /lib/install.php	(revision 8463)
@@ -94,10 +94,11 @@
    		id int(25) NOT NULL AUTO_INCREMENT,
    		knr VARCHAR(255) NOT NULL,
-   		paypal_payer_id VARCHAR(255) NOT NULL,   		
+   		paypal_payer_id VARCHAR(255) NOT NULL,
    		geb DATE NOT NULL,
    		status VARCHAR(255) NOT NULL,
    		email VARCHAR(500) NOT NULL COMMENT 'E-Mail Adresse des Kunden',
    		email_einvoice VARCHAR(500) NOT NULL COMMENT 'E-Mail Adresse fÃŒr eRechnung',
-   		ustidnr VARCHAR(100) NOT NULL,   		
+   		leitweg_id VARCHAR(500) NOT NULL COMMENT 'Leitweg-ID fÃŒr eRechnung',
+   		ustidnr VARCHAR(100) NOT NULL,
    		custom TEXT NOT NULL,
    		comment TEXT NOT NULL,
Index: /lib/wpsg_basket.class.php
===================================================================
--- /lib/wpsg_basket.class.php	(revision 8462)
+++ /lib/wpsg_basket.class.php	(revision 8463)
@@ -734,4 +734,5 @@
 					'email' => wpsg_q(wpsg_getStr($this->arCheckout['email'])),
 					'email_einvoice' => $this->arCheckout['email_einvoice']??'',
+					'leitweg_id' => $this->arCheckout['leitweg_id']??'',
 					'invisible' => 1,
 					'geb' => wpsg_q(wpsg_toDate(wpsg_getStr($this->arCheckout['geb']))),
@@ -1102,4 +1103,16 @@
 					}
 					
+				}
+
+				if (intval($custom_config['leitweg']) === 1 && trim($this->arCheckout['leitweg_id']??'') !== '') { // E-Mail fÃŒr eRechnung wird abgefragt und ist angegeben
+
+					if (empty($this->arCheckout['leitweg_id'])) {
+
+						$this->shop->addFrontendError(__('Bitte die Eingabe der E-Mail Adresse fÃŒr eRechnung ÃŒberprÃŒfen!', 'wpsg'));
+						$_SESSION['wpsg']['errorFields'][] = 'leitweg_input';
+						$bError = true;
+
+					}
+
 				}
 				
Index: /model/wpsg_customer.class.php
===================================================================
--- /model/wpsg_customer.class.php	(revision 8462)
+++ /model/wpsg_customer.class.php	(revision 8463)
@@ -630,5 +630,12 @@
 				
 		} // public function getQueryParts($arFilter = array())
-		
+
+
+		public function getLeitwegId(): string {
+
+			return $this->__get('leitweg_id');
+
+		}
+
 	} // class wpsg_order extends wpsg_model
 	
Index: /model/wpsg_order.class.php
===================================================================
--- /model/wpsg_order.class.php	(revision 8462)
+++ /model/wpsg_order.class.php	(revision 8463)
@@ -759,5 +759,5 @@
 						
 		} // public function getInvoiceCountry()
-		
+
 		/**
 		 * Gibt das KÃŒrzel des Rechnungslandes zurÃŒck
@@ -785,5 +785,15 @@
 			
 		} // public function getInvoiceCountryName()
-		
+
+		/**
+		 * Gibt die Leitweg-ID der Bestellung zurÃŒck
+		 */
+		public function getLeitwegId(): string
+		{
+
+			return $this->getCustomer()->getLeitwegId();
+
+		}	// public function getLeitwegId()
+
 		/* Lieferadresse */
 		
Index: /mods/mod_rechnungen/eInvoice.php
===================================================================
--- /mods/mod_rechnungen/eInvoice.php	(revision 8462)
+++ /mods/mod_rechnungen/eInvoice.php	(revision 8463)
@@ -14,5 +14,5 @@
 	use wpsg\wpsg_invoice;
 	use \wpsg_order;
-	
+
 	use horstoeko\zugferd\{
 		ZugferdDocumentBuilder, ZugferdProfiles, codelists\ZugferdInvoiceType, ZugferdDocumentPdfBuilder
@@ -46,5 +46,5 @@
 				$pdf_file = $oInvoice->getFilePath();
 				$pdf_path = dirname($pdf_file).DIRECTORY_SEPARATOR;
-				
+
 				$document = ZugferdDocumentBuilder::CreateNew($profil_id);
 				
@@ -55,17 +55,16 @@
 					->setDocumentSeller($shop->get_option('wpsg_shopdata_name', default: ''))
 					->addDocumentSellerContact(
-						$shop->get_option('wpsg_shopdata_owner', default: ''),
+						$shop->get_option('wpsg_shopdata_owner'),
 						null,
 						null,
 						null,
-						$shop->get_option('wpsg_shopdata_email', default: '')
+						$shop->get_option('wpsg_shopdata_email')
 					)
-					->setDocumentSellerContact(
-						$shop->get_option('wpsg_shopdata_owner', default: ''),
-						null,
-						null,
-						null,
-						$shop->get_option('wpsg_shopdata_email', default: '')
+
+//					->setDocumentBuyerReference("04011000-12345ABCXYZ-86")
+					->setDocumentBuyerReference(
+						$oOrder->getLeitwegId(),
 					)
+
 					//->addDocumentSellerGlobalId("4000001123452", "0088")
 					->addDocumentSellerTaxRegistration("FC", $shop->get_option('wpsg_shopdata_taxnr', default: ''))
@@ -79,5 +78,8 @@
 						\wpsg_country::getInstance(intval($shop->get_option('wpsg_shopdata_country')))->getShorttext()
 					)
-					->setDocumentBuyer($oOrder->getInvoiceSalutationTitle(), strval($oOrder->getId()))
+					->addDocumentBuyerTaxRegistration(
+						$oOrder->getInvoiceFax(),
+					)
+					->setDocumentBuyer($oOrder->getInvoiceFirstName() . " " . $oOrder->getInvoiceName(), strval($oOrder->getId()))
 					->setDocumentBuyerAddress(
 						$oOrder->getInvoiceStreet(),
@@ -87,4 +89,11 @@
 						$oOrder->getInvoiceCity(),
 						$oOrder->getInvoiceCountryKuerzel()
+					)
+					->setDocumentBuyerContact(
+						$oOrder->getInvoiceName() . " " . $oOrder->getInvoiceFirstName(),
+						"",
+						$oOrder->getInvoicePhone(),
+						$oOrder->getInvoiceFax(),
+						""
 					);
 				
@@ -95,16 +104,23 @@
 					
 				}
-				
+
+				$PaymentNettoPos = 0; $PaymentNettoNeg = 0;
+				$PaymentNetto = wpsg_calculation::getOrderCalculation($order_id)->getCalculationArray()['sum']['payment_brutto_calculated'];
+				if ($PaymentNetto > 0) {$PaymentNettoPos = $PaymentNetto;}
+				elseif ($PaymentNetto < 0) {$PaymentNettoNeg = $PaymentNetto;}
+
 				$document->setDocumentSummation(
 					$oInvoice->getSumBrutto(),
-					$oInvoice->getSumBrutto(),
+					wpsg_calculation::getOrderCalculation($order_id)->getCalculationArray()['sum']['topay_brutto'] /* - totalPrepaidAmount (BT-113) */,
 					$oInvoice->getSumNetto(),
+					wpsg_calculation::getOrderCalculation($order_id)->getCalculationArray()['sum']['shipping_brutto_calculated'] + $PaymentNettoPos,
+					wpsg_calculation::getOrderCalculation($order_id)->getCalculationArray()['sum']['voucher_brutto'] + $PaymentNettoNeg,
+					$oInvoice->getSumNetto(),
+					$oInvoice->getSumBrutto() - $oInvoice->getSumNetto(),
 					0.0,
-					0.0,
-					$oInvoice->getSumNetto(),
-					$oInvoice->getSumBrutto() - $oInvoice->getSumNetto()
+					0.0
 				);
-				
-				// $document->addDocumentPaymentTerm("Zahlbar innerhalb 30 Tagen netto bis 04.04.2018, 3% Skonto innerhalb 10 Tagen bis 15.03.2018")
+
+//				 $document->addDocumentPaymentTerm("Zahlbar innerhalb 30 Tagen netto bis 04.04.2018, 3% Skonto innerhalb 10 Tagen bis 15.03.2018")
 				
 				foreach ($oInvoice->getItems() as $oInvoiceItem) {
Index: /mods/mod_rechnungen/lib/vendor/horstoeko/zugferd/src/ZugferdDocumentBuilder.php
===================================================================
--- /mods/mod_rechnungen/lib/vendor/horstoeko/zugferd/src/ZugferdDocumentBuilder.php	(revision 8462)
+++ /mods/mod_rechnungen/lib/vendor/horstoeko/zugferd/src/ZugferdDocumentBuilder.php	(revision 8463)
@@ -134,5 +134,5 @@
 
     /**
-     * Write the content of a invoice object to a DOMDocument instance
+     * Write the content of an invoice object to a DOMDocument instance
      *
      * @return DOMDocument
Index: /mods/mod_rechnungen/wpsg_invoice.php
===================================================================
--- /mods/mod_rechnungen/wpsg_invoice.php	(revision 8462)
+++ /mods/mod_rechnungen/wpsg_invoice.php	(revision 8463)
@@ -258,5 +258,5 @@
 
 		/**
-		 * @return \wpsg_order 
+		 * @return \wpsg_order
 		 */
 		public function getOrder() {
Index: /mods/wpsg_mod_downloadprodukte.class.php
===================================================================
--- /mods/wpsg_mod_downloadprodukte.class.php	(revision 8462)
+++ /mods/wpsg_mod_downloadprodukte.class.php	(revision 8463)
@@ -81,5 +81,6 @@
 		public function product_addedit_content(&$product_content, &$product_data)
 		{
-			
+			if (intval($product_data['id']) <= 0) return;
+
 			$this->shop->view['data'] = $product_data;
 			$this->shop->view['prodFiles'] = $this->getProdFileListe($product_data['id']);
Index: /mods/wpsg_mod_kundenverwaltung.class.php
===================================================================
--- /mods/wpsg_mod_kundenverwaltung.class.php	(revision 8462)
+++ /mods/wpsg_mod_kundenverwaltung.class.php	(revision 8463)
@@ -1940,4 +1940,5 @@
 			wpsg_checkRequest('email', [WPSG_SANITIZE_EMAIL, ['allowEmpty' => true]], __('E-Mail', 'wpsg'), $data);
 			wpsg_checkRequest('email_einvoice', [WPSG_SANITIZE_EMAIL, ['allowEmpty' => true]], __('E-Mail fÃŒr eRechnung', 'wpsg'), $data);
+			wpsg_checkRequest('leitweg_id', [WPSG_SANITIZE_TEXTFIELD, ['allowEmpty' => true]], __('Leitweg-ID', 'wpsg'), $data);
 			wpsg_checkRequest('ustidnr', [WPSG_SANITIZE_USTIDNR, ['allowEmpty' => true]], __('UStIdNr.', 'wpsg'), $data);
 			wpsg_checkRequest('comment', [WPSG_SANITIZE_TEXTAREA], __('Kundenkommentar', 'wpsg'), $data);
Index: /views/admin/kundendaten_tab1.phtml
===================================================================
--- /views/admin/kundendaten_tab1.phtml	(revision 8462)
+++ /views/admin/kundendaten_tab1.phtml	(revision 8463)
@@ -22,4 +22,5 @@
 <?php echo wpsg_drawForm_Checkbox('pflicht[emailconfirm]', __('E-Mail Adresse (Wiederholung)', 'wpsg'), $this->view['pflicht']['emailconfirm']); ?>
 <?php echo wpsg_drawForm_Checkbox('pflicht[eInvoice]', __('E-Mail Adresse fÃŒr eRechnung abfragen (optional)', 'wpsg'), $this->view['pflicht']['eInvoice']??0); ?>
+<?php echo wpsg_drawForm_Checkbox('pflicht[leitweg]', __('Leitweg-ID fÃŒr eRechnung abfragen (optional)', 'wpsg'), $this->view['pflicht']['leitweg']??0); ?>
 <?php echo wpsg_drawForm_Select('pflicht[tel]', __('Telefon', 'wpsg'), $arSelect, $this->view['pflicht']['tel'])?>
 <?php echo wpsg_drawForm_Select('pflicht[fax]', __('Fax', 'wpsg'), $arSelect, $this->view['pflicht']['fax'])?>
Index: /views/mods/mod_kundenverwaltung/edit.phtml
===================================================================
--- /views/mods/mod_kundenverwaltung/edit.phtml	(revision 8462)
+++ /views/mods/mod_kundenverwaltung/edit.phtml	(revision 8463)
@@ -65,9 +65,13 @@
                         	<?php echo wpsg_drawForm_Input('email', __('E-Mail', 'wpsg'), @$this->view['data']['email']); ?>
                         <?php } ?>
-						
-						<?php if ($oCustomer->getEMailEInvoice() !== null) { ?>
-							<?php echo wpsg_drawForm_Input('email_einvoice', __('E-Mail fÃŒr eRechnung', 'wpsg'), $oCustomer->getEMailEInvoice()); ?>
+
+						<?php if ($this->view['pflicht']['eInvoice'] != '0') { ?>
+							<?php echo wpsg_drawForm_Input('email_einvoice', __('E-Mail fÃŒr eRechnung', 'wpsg'), $this->view['data']['email_einvoice']??''); ?>
 						<?php } ?>
-						
+
+                        <?php if (($this->view['pflicht']['leitweg']??'') != '0') { ?>
+                            <?php echo wpsg_drawForm_Input('leitweg_id', __('Leitweg-ID', 'wpsg'), @$this->view['data']['leitweg_id']??''); ?>
+                        <?php } ?>
+
                         <?php if ($this->view['pflicht']['firma'] != '2') { ?>
                         	<?php echo wpsg_drawForm_Input('firma', __('Firma', 'wpsg'), @$this->view['data']['firma']); ?>
Index: /views/order/view_customerdata.phtml
===================================================================
--- /views/order/view_customerdata.phtml	(revision 8462)
+++ /views/order/view_customerdata.phtml	(revision 8463)
@@ -56,7 +56,9 @@
 					<?php } ?>
 				<?php } ?>
-				
-				<?php echo wpsg_drawForm_Input('email_einvoice', __('E-Mail fÃŒr eInvoice', 'wpsg'), $this->view['data']['email_einvoice']); ?>
-				
+
+				<?php echo wpsg_drawForm_Input('email_einvoice', __('E-Mail fÃŒr eRechnung', 'wpsg'), $this->view['data']['email_einvoice']); ?>
+
+                <?php echo wpsg_drawForm_Input('leitweg_id', __('Leitweg-ID fÃŒr eRechnung', 'wpsg'), $this->view['data']['leitweg_id']); ?>
+
                 <br />
                 <?php if ($this->view['pflicht']['strasse'] != '2') { ?>
Index: /views/warenkorb/checkout.phtml
===================================================================
--- /views/warenkorb/checkout.phtml	(revision 8462)
+++ /views/warenkorb/checkout.phtml	(revision 8463)
@@ -218,4 +218,18 @@
 					/>
 				</div>
+				<?php } ?>
+
+				<?php if (intval($this->view['pflicht']['leitweg']??0) === 1) { ?>
+                    <div class="wpsg_checkoutblock" id="wpsg_leitweg_id">
+                        <label for="wpsg_leitweg_id_input" class="wpsg_checkout"><?php echo __("Leitweg-ID (fÃŒr eRechnung, optional)", "wpsg"); ?></label>
+                        <input
+                                class="wpsg_input_text wpsg_checkout <?php echo ((in_array("leitweg_id", (array)$this->view['error']))?'wpsg_error':''); ?>"
+                                type="text"
+                                id="wpsg_email_leitweg_id_input"
+                                name="wpsg[checkout][leitweg_id]"
+                                value="<?php echo htmlspecialchars($this->view['basket']['checkout']['leitweg_id']??''); ?>"
+                                autocomplete="off"
+                        />
+                    </div>
 				<?php } ?>
 				
Index: /views/warenkorb/done.phtml
===================================================================
--- /views/warenkorb/done.phtml	(revision 8462)
+++ /views/warenkorb/done.phtml	(revision 8463)
@@ -1,5 +1,5 @@
-<?php 
+<?php
 
-	/**
+/**
 	 * Template, welches nach erfolgreicher Bestellung angezeigt wird
 	 */
@@ -33,6 +33,10 @@
 	Zahlungsart: <?php echo $this->arShipping[$this->view['basket']['checkout']['payment']]['name']; ?>
 	Versandart: <?php echo $this->arShipping[$this->view['basket']['checkout']['shipping']]['name']; ?>
+    Berechnungs-Array: <?php var_dump(wpsg_calculation::getOrderCalculation($this->view['o_id'])->getCalculationArray()['sum']); ?>
 	*/
-	
+
+namespace wpsg;
+use wpsg_order;
+
 ?>
 <div class="wpsg wpsg_done">
Index: /wpshopgermany.php
===================================================================
--- /wpshopgermany.php	(revision 8462)
+++ /wpshopgermany.php	(revision 8463)
@@ -36,5 +36,5 @@
 	define('WPSG_TBL_ORDERPRODUCT', $prefix.'wpsg_order_products');
 	define('WPSG_TBL_KU', $prefix.'wpsg_kunden');
-	define('WPSG_TBL_KG', $prefix.'wpsg_customergroup');
+	define('WPSG_TBL_KG', $prefix.'wpsg_customer group');
 	define('WPSG_TBL_VZ', $prefix.'wpsg_versandzonen');
 	define('WPSG_TBL_LAND', $prefix.'wpsg_laender');
