Erstellen einer ODT-Dokumentvorlage

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search

Diese Seite beschreibt, wie man eine ODT-Dokumentvorlage erstellt, um Dokumente mit der ODT-Generierung zu erstellen. Wenn Sie wissen möchten, wie man eine PDF-Vorlage erstellt, sehen Sie sich die Seite Create a PDF document template an. Zum Erstellen einer PDF-Vorlage sind PHP-Entwicklungskenntnisse erforderlich, aber nicht zum Erstellen einer ODT-Vorlage.

Voraussetzung

  • Dolibarr: 3.1+
  • OpenOffice: 3.2+, LibreOffice, ...

Erstellen Sie Ihr Dokument

  • Erstellen Sie von Grund auf ein leeres OpenOffice-Dokument oder nehmen Sie ein bereitgestelltes Beispiel. Sie finden sie installiert in einem Unterverzeichnis von Verzeichnis documents/doctemplates
  • Bearbeiten Sie Ihr Dokument mit allen Funktionen Ihrer Office-Suite.

Fügen Sie die Tags in Ihr Dokument ein, die Sie sehen möchten. Tags werden während der Dokumentengenerierung automatisch von Dolibarr ersetzt. Eine Liste aller verfügbaren Tags wird im nächsten Kapitel bereitgestellt. Hier ein Beispiel einer Vorlage für ein Angebot, welches mit LibreOffice erstellt wurde. File:Dolibarr-Vorlage-Angebot demo.pdf


Warning.png Warnung: Tags müssen mit {} oder [] für Arrays umschlossen werden (siehe später) und dürfen in der Office-Suite nicht gestoppt werden (kein Backspace und kein Copy-Paste). Wenn dies nicht geschieht, fügt die Office-Suite unsichtbare Informationen hinzu, die die Erkennung/Ersetzung unmöglich machen. Mit LibreOffice können Sie auch die Tastenkombination Ctrl+M verwenden, um die Direktformatierung von Tags zu entfernen.

Tags

Hier ist eine Liste von Tags, die durch entsprechende Informationen ersetzt werden:

Firmen-/Stiftungsinformationen

{mycompany_logo} : Your company logo
{mycompany_name} : Your company name
{mycompany_address} : Your company address
{mycompany_zip} : Your company zip
{mycompany_town} : Your company town
{mycompany_country} : Your company country (label)
{mycompany_country_code} : Your company country (code: FR, US, IT...)
{mycompany_state} : Your company state (label)
{mycompany_state_code} : Your company state (code)
{mycompany_phone}
{mycompany_fax}
{mycompany_email}
{mycompany_web}
{mycompany_barcode}
{mycompany_capital}
{mycompany_juridicalstatus}
{mycompany_managers}
{mycompany_idprof1}
{mycompany_idprof2}
{mycompany_idprof3}
{mycompany_idprof4}
{mycompany_idprof5}
{mycompany_idprof6}
{mycompany_vatnumber} : Your company VAT number
{mycompany_object}
{mycompany_note_private} : Your company private note

Kunden-, Interessenten- oder Lieferanteninformationen

{company_name} : Customer or Supplier company name
{company_name_alias}
{company_address}
{company_zip}
{company_town}
{company_country} : Customer or Supplier company country (label)
{company_country_code} : Customer or Supplier company country (code: FR, US, IT...)
{company_state}
{company_state_code}
{company_phone}
{company_fax}
{company_email}
{company_web}
{company_barcode}
{company_customercode} : Company customer code
{company_suppliercode} : Company supplier code
{company_customeraccountancycode} : Company customer accountancy code
{company_supplieraccountancycode} : Company supplier accountancy code
{company_capital}
{company_juridicalstatus}
{company_outstanding_limit}
{company_idprof1}
{company_idprof2}
{company_idprof3}
{company_idprof4}
{company_idprof5}
{company_idprof6}
{company_vatnumber} : Customer or Supplier company VAT number
{company_note_public} : Customer or Supplier company public note
{company_note_private} : Customer or Supplier company private note
{company_default_bank_iban}
{company_default_bank_bic}

Extra fields:
{company_options_xxx} : Value of extra field (where xxx is code of extra field)

Kontakte

Das sind die Tags für den Kontakt der Rechnung für Rechnungen (Typ BILLING), Kontakt des Angebots für Angebote (Typ CUSTOMER), Kontakt der Bestellung für Verkaufsaufträge (Typ CUSTOMER). Es gibt keine Tags für den Lieferkontakt.

{contact_civility}
{contact_fullname}
{contact_lastname}
{contact_firstname}
{contact_address}
{contact_zip}
{contact_town}
{contact_state_id}
{contact_state_code}
{contact_state}
{contact_country_id}
{contact_country_code}
{contact_country}
{contact_poste}
{contact_socid}
{contact_statut}
{contact_code}
{contact_email}
{contact_jabberid}
{contact_phone_pro}
{contact_phone_perso}
{contact_phone_mobile}
{contact_fax}
{contact_birthday}
{contact_default_lang}
{contact_note_public}
{contact_note_private}

Extra fields:
{contact_options_xxx} : Value of extra field (where xxx is code of extra field)

For contact ODT, you may need also to surround the substitutions variables with

[!-- BEGIN companycontacts--][!-- END companycontacts--]

Benutzerinformationen

{myuser_lastname}
{myuser_firstname}
{myuser_fullname}
{myuser_phone}
{myuser_fax}
{myuser_mobile}
{myuser_address}
{myuser_login}
{myuser_email}
{myuser_zip}
{myuser_town}
{myuser_country}
{myuser_country_code}
{myuser_state}
{myuser_state_code}
{myuser_logo}
{myuser_job}
{myuser_web}

Weitere Informationen

{current_date}
{current_datehour}
{current_server_date}
{current_server_datehour}
{current_date_locale}
{current_datehour_locale}
{current_server_date_locale}
{current_server_datehour_locale}

{__(XXX)__} = Translated value of a translation key XXX - Note: Translation must be inside a language file that was previously loaded with $langs->load("languagefile")
{__[XXX]__} = Value of the constant XXX (into setup)

You may also use
{__XXX__} = To use a constant defined for email templates, that may also be available into ODT templates. For exemple {__ONLINE_PAYMENT_URL__}, {__DAY__}, {__REF__}, ...

Objektinformationen (Rechnung, Geschäftsangebot, Bestellung, ...)

{object_id}
{object_ref}
{object_ref_ext}
{object_label}
{object_ref_customer}
{object_ref_supplier}
{object_note_private}
{object_note_public}
or
{object_note}

Dates
{object_hour}
{object_date}
{object_date_rfc}
{object_date_creation}
{object_date_modification}
{object_date_validation}
{object_date_limit} : Specific to invoices
{object_date_end} : Specific to proposals : End date of validity of proposal
{object_date_delivery_planed} : Specific to order
{object_date_close}

Amounts (numeric data):
{object_total_ht}
{object_total_vat}
{object_total_localtax1}
{object_total_localtax2}
{object_total_ttc}
{object_total_discount_ht}
{object_total_vat_x} (is vat total for rate x. x can be for example 20, 8.5, 5.99 ... See also note*}

Amounts (in output language format):
{object_total_ht_locale} 
{object_total_vat_locale} 
{object_total_localtax1_locale}
{object_total_localtax2_locale}
{object_total_ttc_locale}
{object_total_discount_ht_locale}
{object_total_vat_locale_x} (is vat total for rate x. x can be for example 20, 8.5, 5.99 ... See also note*}

Multicurrency:
{object_multicurrency_code}
{object_multicurrency_tx}
{object_multicurrency_total_ht}
{object_multicurrency_total_tva}
{object_multicurrency_total_ttc}
{object_multicurrency_total_ht_locale}
{object_multicurrency_total_tva_locale}
{object_multicurrency_total_ttc_locale}

Specific to proposals :
{object_availability_id}
{object_availability_code}
{object_availability}

Specific to invoices :
{object_payment_mode}
{object_payment_mode_code}
{object_payment_term}
{object_payment_term_code}
{object_incoterms}
{object_bank_iban}
{object_bank_bic}
{object_bank_label}
{object_bank_number}
{object_bank_proprio}
{object_source_invoice_ref}
{object_already_payed} : Amount already payed (numeric)
{object_already_deposit}
{object_already_creditnote}
{object_already_payed_all}
{object_remain_to_pay} : Remaining to pay amount (numeric)
{object_already_payed_locale} : Amount already payed (output language format)
{object_already_deposit_locale}
{object_already_creditnote_locale}
{object_already_payed_all_locale}
{object_remain_to_pay_locale} : Remaining to pay amount (output language format)

Specific to Shipments :
{object_date_delivery}
{object_hour_delivery} 
{object_tracking_number}
{object_tracking_url}
{object_shipping_method}
{object_weight}
{object_width}
{object_height}
{object_depth}
{object_size}
{order_ref} : Ref of origin order used to generate the shipment
{order_ref_customer} : Ref on customer side of origin order used to generate the shipment

Specific to the Project linked to the object (if applicable):
{object_project_ref}
{object_project_title}
{object_project_description}
{object_project_date_start}
{object_project_date_end}

Specific to the Product directly linked to the object (if applicable):
{object_product_ref}
{object_product_label}

Extra fields:
{object_options_xxx} : Value of extra field (where xxx is code of extra field)

For ODT with supplier prices, you may need also to surround the substitutions variables with

[!-- BEGIN supplierprices--][!-- END supplierprices--]

Info.png

Für das Tag {object_total..._x}, wenn es keinen Betrag für den Steuersatz x gibt, wird der Schlüssel nicht ersetzt. Sie können daher die Bedingungssyntax verwenden, um anstelle des Schlüssels die 0 anzuzeigen, wenn der Wert nicht definiert ist:

/** 		Function called to complete substitution array (before generating on ODT, or a personalized email)
 * 		functions xxx_completesubstitutionarray are called by make_substitutions() if file
 * 		is inside directory htdocs/core/substitutions
 * 
 *		@param	array		$substitutionarray	Array with substitution key=>val
 *		@param	Translate	$langs			Output langs
 *		@param	Object		$object			Object to use to get values
 * 		@return	void					The entry parameter $substitutionarray is modified
 */
function mymodule_completesubstitutionarray(&$substitutionarray,$langs,$object)
{
   global $conf,$db;

   $myvalue='Put here calculated value to insert';
   $substitutionarray['myowntag']=$myvalue;
}

Die Funktion wird vor der Dokumentengenerierung aufgerufen, um das Substitutionsarray zu vervollständigen, damit das Tag myowntag durch den in $myvalue definierten Wert ersetzt wird. Sie können beliebig viele Tags hinzufügen und den Code schreiben, um die Werte zu definieren (Recherche in der Datenbank, in Dateien, Berechnungen, Verwendung von empfangenen oder globalen Variablen...).

Achtung: Der erste Parameter in der Funktionsdeklaration muss mit & beginnen, da er vom Code geändert wird und verändert zurückgegeben werden muss.

Damit Ihre Substitutionsfunktion aufgerufen wird, müssen Sie Folgendes tun:

  • Stellen Sie sicher, dass Ihre Substitutionsdatei im Verzeichnis htdocs/monmodule/core/substitutions gespeichert ist.
  • Erstellen Sie ein Modul (siehe Seite Développement module) mit seiner Modulbeschreibungsdatei.
  • Stellen Sie sicher, dass die Modulbeschreibungsdatei einen Eintrag enthält, um anzugeben, dass eine Substitutionsdatei aufgerufen werden soll. Dies sollte eine
$this->module_parts = array('substitutions' => 1)
  • Modul aktivieren (ein Modul muss aktiviert und deaktiviert werden, um Änderungen in seiner Deskriptordatei zu berücksichtigen)

Andere benutzerdefinierte Tags für Zeilen

Diese Funktion ist seit Dolibarr v3.3 (zukünftige Entwicklungsversion) verfügbar.

Ähnlich wie im vorherigen Kapitel müssen Sie eine Funktion auf die gleiche Weise definieren, jedoch mit einigen Unterschieden:

  • Erstellen oder bearbeiten Sie dieselbe Datei wie zuvor (siehe vorheriges Kapitel).
  • Hier sind die Unterschiede: Schreiben Sie in der Datei eine andere Funktion mit fast demselben Namen, jedoch mit '_lines' als Suffix, und fügen Sie auch eine neue Variable $lines hinzu:
/** 		Function called to complete substitution array for lines (before generating on ODT, or a personalized email)
 * 		functions xxx_completesubstitutionarray_lines are called by make_substitutions() if file
 * 		is inside directory htdocs/core/substitutions
 * 
 *		@param	array		$substitutionarray	Array with substitution key=>val
 *		@param	Translate	$langs			Output langs
 *		@param	Object		$object			Object to use to get values
 *              @param  Object          $line                   Current line being processed, use this object to get values
 * 		@return	void					The entry parameter $substitutionarray is modified
 */
function mymodule_completesubstitutionarray_lines(&$substitutionarray,$langs,$object,$line) {
{
   global $conf,$db;

   $myvalue='Put here calculated value to insert';
   $substitutionarray['myowntag']=$myvalue;
}

Im Gegensatz zur vorherigen Funktion, die immer nur einmal aufgerufen wird, wird diese Funktion jedes Mal bei der Bearbeitung einer Produktzeile aufgerufen und gibt Ihnen jedes Mal ein anderes $line-Objekt, das Sie bearbeiten können. Dadurch können Sie für jedes Produkt unterschiedliche Tag-Ersetzungen vornehmen.

Speichern Sie Ihr Dokument

Um Ihre Dokumentvorlage in der Liste der verfügbaren Vorlagen zu sehen, legen Sie sie im entsprechenden Unterverzeichnis ab, das sich im Verzeichnis documents/doctemplates befindet.