From 632dc0d1776a5ced38ef0dffd592e05675b245d7 Mon Sep 17 00:00:00 2001 From: data Date: Mon, 23 Feb 2026 18:37:50 +0100 Subject: [PATCH] =?UTF-8?q?v1.3:=20E-Mail-Platzhalter,=20Fallback-Tags=20f?= =?UTF-8?q?=C3=BCr=20Vorname/Nachname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Alle Platzhalter auch als __KEY__-Format für E-Mail-Vorlagen - billing_or_thirdparty_firstname/name mit Kundenname-Fallback - Dokumentation aktualisiert Co-Authored-By: Claude Opus 4.6 --- ChangeLog.md | 6 ++ README.md | 93 +++++++++++-------- .../modDeliveryInvoiceAddress.class.php | 2 +- .../functions_deliveryinvoiceaddress.lib.php | 79 +++++++++++++--- 4 files changed, 127 insertions(+), 53 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index b31604f..c8d2367 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # CHANGELOG MODULE DELIVERYINVOICEADDRESS FOR [DOLIBARR ERP CRM](https://www.dolibarr.org) +## 1.3 + +- Neu: Alle Platzhalter auch als `__KEY__`-Format für E-Mail-Vorlagen +- Neu: `billing_or_thirdparty` Fallback-Platzhalter (Rechnungskontakt oder Kundenname) +- Neu: `billing_or_thirdparty_firstname` und `billing_or_thirdparty_name` mit Fallback + ## 1.2 - Fix: `{*_contact_name}` liefert jetzt Nachname statt Vorname diff --git a/README.md b/README.md index 6771113..e971dff 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DeliveryInvoiceAddress -Dolibarr-Modul zur Verwendung von Rechnungs-, Liefer- und Serviceadressen in ODT-Vorlagen. +Dolibarr-Modul zur Verwendung von Rechnungs-, Liefer- und Serviceadressen in ODT-Vorlagen und E-Mail-Templates. ## Funktionen @@ -9,6 +9,7 @@ Dolibarr-Modul zur Verwendung von Rechnungs-, Liefer- und Serviceadressen in ODT - Serviceadresse für Servicedokumente - Automatische Erkennung des Dokumenttyps (Angebot/Auftrag/Rechnung) - CUSTOMER-Kontakt als Fallback für BILLING bei Angeboten/Aufträgen +- Fallback-Platzhalter: Rechnungskontakt oder automatisch Kundenname ## Installation @@ -23,58 +24,66 @@ Dolibarr-Modul zur Verwendung von Rechnungs-, Liefer- und Serviceadressen in ODT | Auftrag (Commande) | `commande` | BILLING, CUSTOMER, SERVICE, SHIPPING | | Rechnung (Facture) | `facture` | BILLING, SERVICE, SHIPPING | -## Verfügbare ODT-Tags +## Verfügbare Platzhalter + +Alle Platzhalter sind in zwei Formaten verfügbar: +- **ODT-Vorlagen**: `{key}` (z.B. `{billing_contact_fullname}`) +- **E-Mail-Vorlagen**: `__KEY__` (z.B. `__BILLING_CONTACT_FULLNAME__`) ### Rechnungsadresse (Billing) -| Tag | Beschreibung | -|-----|--------------| -| `{billing_contact_firstname}` | Vorname | -| `{billing_contact_name}` | Nachname | -| `{billing_contact_fullname}` | Vorname + Nachname (berücksichtigt `MAIN_FIRSTNAME_NAME_POSITION`) | -| `{billing_contact_address}` | Straße und Hausnummer | -| `{billing_contact_zip}` | Postleitzahl | -| `{billing_contact_town}` | Ort | -| `{billing_contact_country}` | Land | +| ODT-Tag | E-Mail-Tag | Beschreibung | +|---------|------------|--------------| +| `{billing_contact_firstname}` | `__BILLING_CONTACT_FIRSTNAME__` | Vorname | +| `{billing_contact_name}` | `__BILLING_CONTACT_NAME__` | Nachname | +| `{billing_contact_fullname}` | `__BILLING_CONTACT_FULLNAME__` | Vorname + Nachname | +| `{billing_contact_address}` | `__BILLING_CONTACT_ADDRESS__` | Straße und Hausnummer | +| `{billing_contact_zip}` | `__BILLING_CONTACT_ZIP__` | Postleitzahl | +| `{billing_contact_town}` | `__BILLING_CONTACT_TOWN__` | Ort | +| `{billing_contact_country}` | `__BILLING_CONTACT_COUNTRY__` | Land | ### Lieferadresse (Delivery/Shipping) -| Tag | Beschreibung | -|-----|--------------| -| `{delivery_contact_firstname}` | Vorname | -| `{delivery_contact_name}` | Nachname | -| `{delivery_contact_fullname}` | Vorname + Nachname | -| `{delivery_contact_address}` | Straße und Hausnummer | -| `{delivery_contact_zip}` | Postleitzahl | -| `{delivery_contact_town}` | Ort | -| `{delivery_contact_country}` | Land | +| ODT-Tag | E-Mail-Tag | Beschreibung | +|---------|------------|--------------| +| `{delivery_contact_firstname}` | `__DELIVERY_CONTACT_FIRSTNAME__` | Vorname | +| `{delivery_contact_name}` | `__DELIVERY_CONTACT_NAME__` | Nachname | +| `{delivery_contact_fullname}` | `__DELIVERY_CONTACT_FULLNAME__` | Vorname + Nachname | +| `{delivery_contact_address}` | `__DELIVERY_CONTACT_ADDRESS__` | Straße und Hausnummer | +| `{delivery_contact_zip}` | `__DELIVERY_CONTACT_ZIP__` | Postleitzahl | +| `{delivery_contact_town}` | `__DELIVERY_CONTACT_TOWN__` | Ort | +| `{delivery_contact_country}` | `__DELIVERY_CONTACT_COUNTRY__` | Land | ### Serviceadresse (Service) -| Tag | Beschreibung | -|-----|--------------| -| `{service_contact_firstname}` | Vorname | -| `{service_contact_name}` | Nachname | -| `{service_contact_fullname}` | Vorname + Nachname | -| `{service_contact_address}` | Straße und Hausnummer | -| `{service_contact_zip}` | Postleitzahl | -| `{service_contact_town}` | Ort | -| `{service_contact_country}` | Land | +| ODT-Tag | E-Mail-Tag | Beschreibung | +|---------|------------|--------------| +| `{service_contact_firstname}` | `__SERVICE_CONTACT_FIRSTNAME__` | Vorname | +| `{service_contact_name}` | `__SERVICE_CONTACT_NAME__` | Nachname | +| `{service_contact_fullname}` | `__SERVICE_CONTACT_FULLNAME__` | Vorname + Nachname | +| `{service_contact_address}` | `__SERVICE_CONTACT_ADDRESS__` | Straße und Hausnummer | +| `{service_contact_zip}` | `__SERVICE_CONTACT_ZIP__` | Postleitzahl | +| `{service_contact_town}` | `__SERVICE_CONTACT_TOWN__` | Ort | +| `{service_contact_country}` | `__SERVICE_CONTACT_COUNTRY__` | Land | + +### Fallback-Platzhalter (Rechnungskontakt ODER Kundenname) + +Zeigt den Rechnungskontakt an, wenn zugeordnet. Sonst automatisch den Kundennamen. + +| ODT-Tag | E-Mail-Tag | Beschreibung | +|---------|------------|--------------| +| `{billing_or_thirdparty}` | `__BILLING_OR_THIRDPARTY__` | Fullname oder Kundenname | +| `{billing_or_thirdparty_firstname}` | `__BILLING_OR_THIRDPARTY_FIRSTNAME__` | Vorname (leer bei Fallback) | +| `{billing_or_thirdparty_name}` | `__BILLING_OR_THIRDPARTY_NAME__` | Nachname oder Kundenname | ## Verwendung in ODT-Vorlagen -### Beispiel: Rechnungsadresse mit Fallback auf Kundenadresse +### Beispiel: Automatischer Fallback (empfohlen) ``` -[!-- IF {billing_contact_fullname} --] -{billing_contact_fullname} +{billing_or_thirdparty} {billing_contact_address} {billing_contact_zip} {billing_contact_town} -[!-- ELSE {billing_contact_fullname} --] -{company_name} -{company_address} -{company_zip} {company_town} -[!-- ENDIF {billing_contact_fullname} --] ``` ### Beispiel: Zwei Adressen nebeneinander @@ -86,6 +95,14 @@ Rechnungsadresse: Lieferadresse: {billing_contact_zip} {billing_contact_town} {delivery_contact_zip} {delivery_contact_town} ``` +## Verwendung in E-Mail-Vorlagen + +``` +Sehr geehrte/r __BILLING_OR_THIRDPARTY__, + +anbei erhalten Sie Ihre Rechnung __REF__. +``` + ## Kontakte zuordnen 1. Öffne das Dokument (Angebot/Auftrag/Rechnung) @@ -125,6 +142,6 @@ GPL v3 oder höher ## Version -- **Version:** 1.2 +- **Version:** 1.3 - **Dolibarr:** 15.0+ - **PHP:** 7.1+ diff --git a/core/modules/modDeliveryInvoiceAddress.class.php b/core/modules/modDeliveryInvoiceAddress.class.php index 3cba8c9..82d9a90 100755 --- a/core/modules/modDeliveryInvoiceAddress.class.php +++ b/core/modules/modDeliveryInvoiceAddress.class.php @@ -76,7 +76,7 @@ class modDeliveryInvoiceAddress extends DolibarrModules $this->editor_squarred_logo = ''; // Must be image filename into the module/img directory followed with @modulename. Example: 'myimage.png@deliveryinvoiceaddress' // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated', 'experimental_deprecated' or a version string like 'x.y.z' - $this->version = '1.2'; + $this->version = '1.3'; // Url to the file with your last numberversion of this module //$this->url_last_version = 'http://www.example.com/versionmodule.txt'; diff --git a/core/substitutions/functions_deliveryinvoiceaddress.lib.php b/core/substitutions/functions_deliveryinvoiceaddress.lib.php index 4f88eb8..7ab633b 100755 --- a/core/substitutions/functions_deliveryinvoiceaddress.lib.php +++ b/core/substitutions/functions_deliveryinvoiceaddress.lib.php @@ -1,13 +1,19 @@ 'billing_contact', - 'CUSTOMER' => 'billing_contact', // Fallback für Angebote/Aufträge + 'CUSTOMER' => 'billing_contact', 'SERVICE' => 'service_contact', 'SHIPPING' => 'delivery_contact', ); @@ -38,12 +44,19 @@ function deliveryinvoiceaddress_completesubstitutionarray(&$substitutionarray, $ // Felder pro Kontakt $fields = array('firstname', 'name', 'fullname', 'address', 'zip', 'town', 'country'); - // Alle Platzhalter leer initialisieren + // Alle Platzhalter leer initialisieren (ODT + E-Mail-Format) foreach (array('billing_contact', 'service_contact', 'delivery_contact') as $prefix) { foreach ($fields as $field) { $substitutionarray[$prefix.'_'.$field] = ''; + $substitutionarray['__'.strtoupper($prefix.'_'.$field).'__'] = ''; } } + $substitutionarray['billing_or_thirdparty'] = ''; + $substitutionarray['__BILLING_OR_THIRDPARTY__'] = ''; + $substitutionarray['billing_or_thirdparty_firstname'] = ''; + $substitutionarray['__BILLING_OR_THIRDPARTY_FIRSTNAME__'] = ''; + $substitutionarray['billing_or_thirdparty_name'] = ''; + $substitutionarray['__BILLING_OR_THIRDPARTY_NAME__'] = ''; // Kontaktdaten per JOIN direkt laden $sql = "SELECT tc.code, sp.rowid, sp.firstname, sp.lastname, sp.address, sp.zip, sp.town,"; @@ -82,14 +95,52 @@ function deliveryinvoiceaddress_completesubstitutionarray(&$substitutionarray, $ $fullname = trim($lastname.' '.$firstname); } - $substitutionarray[$prefix.'_firstname'] = $firstname; - $substitutionarray[$prefix.'_name'] = $lastname; - $substitutionarray[$prefix.'_fullname'] = $fullname; - $substitutionarray[$prefix.'_address'] = $obj->address ?? ''; - $substitutionarray[$prefix.'_zip'] = $obj->zip ?? ''; - $substitutionarray[$prefix.'_town'] = $obj->town ?? ''; - $substitutionarray[$prefix.'_country'] = $obj->country ?? ''; + $data = array( + 'firstname' => $firstname, + 'name' => $lastname, + 'fullname' => $fullname, + 'address' => $obj->address ?? '', + 'zip' => $obj->zip ?? '', + 'town' => $obj->town ?? '', + 'country' => $obj->country ?? '', + ); + + // ODT-Format + E-Mail-Format setzen + foreach ($data as $field => $value) { + $substitutionarray[$prefix.'_'.$field] = $value; + $substitutionarray['__'.strtoupper($prefix.'_'.$field).'__'] = $value; + } } $db->free($resql); + + // Fallback-Platzhalter: Rechnungskontakt oder Kundenname + $hasContact = !empty($substitutionarray['billing_contact_name']); + + if ($hasContact) { + $substitutionarray['billing_or_thirdparty'] = $substitutionarray['billing_contact_fullname']; + $substitutionarray['billing_or_thirdparty_firstname'] = $substitutionarray['billing_contact_firstname']; + $substitutionarray['billing_or_thirdparty_name'] = $substitutionarray['billing_contact_name']; + } else { + // Fallback auf Kundenname (thirdparty) + $thirdpartyName = ''; + if (!empty($object->thirdparty) && is_object($object->thirdparty)) { + $thirdpartyName = $object->thirdparty->name ?? ''; + } elseif (!empty($object->socid)) { + $sqltp = "SELECT nom as name FROM ".MAIN_DB_PREFIX."societe WHERE rowid = ".((int) $object->socid); + $restp = $db->query($sqltp); + if ($restp && $db->num_rows($restp) > 0) { + $objtp = $db->fetch_object($restp); + $thirdpartyName = $objtp->name ?? ''; + } + } + $substitutionarray['billing_or_thirdparty'] = $thirdpartyName; + $substitutionarray['billing_or_thirdparty_firstname'] = ''; + $substitutionarray['billing_or_thirdparty_name'] = $thirdpartyName; + } + + // E-Mail-Format (__KEY__) spiegeln + $substitutionarray['__BILLING_OR_THIRDPARTY__'] = $substitutionarray['billing_or_thirdparty']; + $substitutionarray['__BILLING_OR_THIRDPARTY_FIRSTNAME__'] = $substitutionarray['billing_or_thirdparty_firstname']; + $substitutionarray['__BILLING_OR_THIRDPARTY_NAME__'] = $substitutionarray['billing_or_thirdparty_name']; }