Files
sharang f778cbb1a8
ci / shared (push) Successful in 13s
ci / test (push) Successful in 26m31s
ci / image (push) Successful in 40s
feat(erpsetup): quotes name the Leistungsbeschreibung versions (#117)
2026-11-09 10:25:59 +00:00

382 lines
32 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package erpsetup
// The BreakPilot look of the documents ERPNext sends: the company address,
// the letter head (logo, sender block, legal footer), one print format for
// offers, order confirmations and invoices, and the invoice e-mail. The
// templates read their data from ERPNext (company, address, bank account,
// customer mandate), so a change there needs no new run.
//
// Print formats are rendered by wkhtmltopdf: tables for layout, no flexbox.
// A custom (Jinja) print format must place the letter head and the footer
// itself; ERPNext only does that for its standard formats.
import "strings"
// companyName is the ERPNext Company the documents belong to.
const companyName = "Breakpilot GmbH" // as in the Handelsregister (small p)
// Legal lines every business letter of a GmbH carries (§ 35a GmbHG) that
// ERPNext has no field for. Same text as the platform mails.
const (
legalRegister = "Sitz Bodman-Ludwigshafen · Amtsgericht Freiburg, HRB 736403"
legalDirectors = "Geschäftsführer: Benjamin Bönisch, Sharang Deepak Parnerkar"
)
const (
letterHeadName = "BreakPilot"
emailTemplateRE = "BreakPilot Rechnung"
printFormatRE = "BreakPilot Rechnung"
printFormatSO = "BreakPilot Auftragsbestätigung"
printFormatQuote = "BreakPilot Angebot"
)
// brandingFields: the SEPA creditor identifier on the Company. It is printed
// on every invoice paid by direct debit (pre-notification).
func brandingFields() []map[string]any {
f := customField("Company", "sepa_creditor_id", "Gläubiger-Identifikationsnummer (SEPA)", "Data", "tax_id", false)
f["description"] = "Von der Deutschen Bundesbank vergeben, z. B. DE98ZZZ09999999999. Erscheint auf Rechnungen mit SEPA-Lastschrift."
return []map[string]any{f}
}
// companyAddressDoc is the registered office, marked as the company's own
// address so ERPNext puts it on every sales document.
func companyAddressDoc() map[string]any {
return map[string]any{
"doctype": "Address", "address_title": companyName, "address_type": "Billing",
"address_line1": "In Steinäckern 16", "pincode": "78351", "city": "Bodman-Ludwigshafen",
"country": "Germany", "email_id": "kontakt@breakpilot.com",
"is_your_company_address": 1, "is_primary_address": 1,
"links": []map[string]any{{"link_doctype": "Company", "link_name": companyName}},
}
}
func letterHeadDoc() map[string]any {
return map[string]any{
"doctype": "Letter Head", "name": letterHeadName, "letter_head_name": letterHeadName,
"source": "HTML", "footer_source": "HTML", "is_default": 1, "disabled": 0,
"content": letterHeadHTML, "footer": letterFooterHTML,
}
}
func printFormatDoc(name, doctype, module string) map[string]any {
return map[string]any{
"doctype": "Print Format", "name": name, "doc_type": doctype, "module": module,
"standard": "No", "custom_format": 1, "print_format_type": "Jinja", "disabled": 0,
"pdf_generator": "wkhtmltopdf", "default_print_language": "de",
"margin_top": 12, "margin_bottom": 28, "margin_left": 18, "margin_right": 15,
"html": documentHTML,
}
}
func printFormats() []map[string]any {
return []map[string]any{
printFormatDoc(printFormatRE, "Sales Invoice", "Accounts"),
printFormatDoc(printFormatSO, "Sales Order", "Selling"),
printFormatDoc(printFormatQuote, "Quotation", "Selling"),
}
}
// docTypeSetter sets a DocType-level property (default print format, default
// e-mail template) through a Property Setter.
func docTypeSetter(doctype, prop, value string) map[string]any {
return map[string]any{
"doctype": "Property Setter", "name": doctype + "-main-" + prop,
"doctype_or_field": "DocType", "doc_type": doctype,
"property": prop, "property_type": "Data", "value": value,
}
}
func brandingSetters() []map[string]any {
return []map[string]any{
docTypeSetter("Sales Invoice", "default_print_format", printFormatRE),
docTypeSetter("Sales Order", "default_print_format", printFormatSO),
docTypeSetter("Quotation", "default_print_format", printFormatQuote),
docTypeSetter("Sales Invoice", "default_email_template", emailTemplateRE),
}
}
func emailTemplateDoc() map[string]any {
return map[string]any{
"doctype": "Email Template", "name": emailTemplateRE, "enabled": 1,
"reference_doctype": "Sales Invoice",
"subject": "Rechnung {{ name }} – Breakpilot",
"use_html": 1, "response_html": invoiceMailHTML,
}
}
// Brand colours (as in the platform mails and the portal).
var brand = strings.NewReplacer(
"$INK", "#14162B", "$MUTED", "#5E6384", "$FAINT", "#8B8FAE",
"$ACCENT", "#4F46E5", "$ACCENT2", "#7C3AED", "$LINE", "#E4E6F0",
"$REGISTER_BR", "Sitz Bodman-Ludwigshafen<br>Amtsgericht Freiburg, HRB 736403",
"$DIRECTORS_BR", "Geschäftsführer:<br>Benjamin Bönisch<br>Sharang Deepak Parnerkar",
"$REGISTER", legalRegister, "$DIRECTORS", legalDirectors,
"$LB_VERSIONS", lbVersionsJinja(),
)
// logoPNG is the chevron from the portal favicon (120×115, rendered from
// product-docs docs/public/logo.svg). ERPNext strips data: URLs from saved
// HTML and wkhtmltopdf does not draw inline SVG, so the logo is a private
// File that frappe inlines as base64 when it renders a PDF
// (frappe.utils.pdf.inline_private_images) — no network access needed.
const logoPNG = "iVBORw0KGgoAAAANSUhEUgAAAHgAAABzCAYAAABTo8YRAAAVJUlEQVR42u2de3RdVZ3HP7997k2atIU2aYE+GJG2Kug8QAf7QhmwKTDLJm2pgKPga6AUHAdFtGkLoVTKQx0eMipVBMZZjiI2DSC0oQ4KpZVadM2MVqC0FJv0mVdL0uTec/Zv/jjnhvSZ1z659wa+a3Wtrq6evfc53/v77e/+7d/+bWEQonJaIwJ4FgLR9wh8FvhHYAKQBOqB3wA/kkB/rZ5YgGUvlGZ76M4h2R6AS1S9XwmGN2FF2DxmBGfuapwFLAX+GjBHeWQXcB/CPSitmX8cTEQbB23kDILhTQA0nbGdM3c1Xgp8H/jb47znKUAVShUwLNvjjwODxoKXTG4EoPW0nRRvP+UyhH+LCOwJ0sC9QBXwJoPIigeFBWfI3fjdOynefsqlvSSXaF7+l4jgYQCLpzZk+7WcIO8teNHURkShddw+htaV9tZyD8egs+S8tuAlk0Ny/5AamSH37n6QS2TJXxpMlpy3Fpxxywf+ag/Ddoy+DPpluYcjDdwrUKV5bsl5R3BmKQSwdMNIlkxpzFjuyY678iN3fXPGXZOHRCeyPYDeIkPu/vdtZ4loZs51TW7m23wR0K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84gC/xfuCwcrApuwaJSTNbtsBxqeOEaVUoR5wCeBs4HMHTH7Q6vlx1ECdotJpFD1qH7q7b1DFBdml+0IzyKjBBbPEz6K8FngfGBMtNnvRyK5BnhIVF7GWFCoXjOe/wfeGlh1ytfpJwAAAABJRU5ErkJggg=="
const logoFileName = "breakpilot-chevron.png"
const logoFileURL = "/private/files/" + logoFileName
func logoFileDoc() map[string]any {
return map[string]any{
"doctype": "File", "file_name": logoFileName, "is_private": 1,
"content": logoPNG, "decode": 1,
}
}
const logoSVG = `<img alt="Breakpilot" width="30" height="29" style="display:block;" src="` + logoFileURL + `">`
// Shared Jinja: the company's own address and its bank account.
const companyVars = `{%- set bp_addr = frappe.db.get_value("Address", {"is_your_company_address": 1, "is_primary_address": 1, "disabled": 0}, ["address_line1", "pincode", "city", "email_id"], as_dict=1) or {"address_line1": "In Steinäckern 16", "pincode": "78351", "city": "Bodman-Ludwigshafen", "email_id": "kontakt@breakpilot.com"} -%}
{%- set bp_bank = frappe.db.get_value("Bank Account", {"is_company_account": 1, "company": doc.company}, ["bank", "iban"], as_dict=1) or {} -%}`
var letterHeadHTML = brand.Replace(strings.ReplaceAll(`${companyVars}
<table style="width:100%;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;">
<tr>
<td style="vertical-align:middle;padding:0 0 6px 0;">
<table style="border-collapse:collapse;"><tr>
<td style="vertical-align:middle;padding-right:8px;">`+logoSVG+`</td>
<td style="vertical-align:middle;font-size:20px;font-weight:bold;letter-spacing:-0.4px;color:$INK;">Break<span style="color:$ACCENT;">Pilot</span></td>
</tr></table>
</td>
<td style="vertical-align:middle;text-align:right;font-size:8.5pt;line-height:1.45;color:$MUTED;">
{{ bp_addr.email_id or "kontakt@breakpilot.com" }} · www.breakpilot.com
</td>
</tr>
</table>
<div style="border-bottom:1.5px solid $ACCENT;margin:2px 0 0 0;"></div>`, "${companyVars}", companyVars))
// USt-IdN&zwnj;r.: the server's Arial substitute (NimbusSans) sets "Nr." as
// a single № glyph; the zero-width non-joiner keeps the letters.
var letterFooterHTML = brand.Replace(strings.ReplaceAll(`${companyVars}
{%- set bp_bic = frappe.db.get_value("Bank", bp_bank.bank, "swift_number") if bp_bank.bank else "" -%}
<div style="border-top:1px solid $LINE;"></div>
<table style="width:100%;border-collapse:collapse;font-family:Arial,Helvetica,sans-serif;color:$FAINT;">
<tr>
<td style="vertical-align:top;padding:5px 8px 0 0;width:24%;font-size:6.5pt;line-height:1.45;white-space:nowrap;"><b style="color:$MUTED;">{{ doc.company }}</b><br>{{ bp_addr.address_line1 }}<br>{{ bp_addr.pincode }} {{ bp_addr.city }}</td>
<td style="vertical-align:top;padding:5px 8px 0 0;width:27%;font-size:6.5pt;line-height:1.45;">$REGISTER_BR<br>USt-IdN&zwnj;r. {{ frappe.db.get_value("Company", doc.company, "tax_id") or "" }}</td>
<td style="vertical-align:top;padding:5px 8px 0 0;width:21%;font-size:6.5pt;line-height:1.45;">$DIRECTORS_BR</td>
<td style="vertical-align:top;padding:5px 0 0 0;width:28%;font-size:6.5pt;line-height:1.45;">{% if bp_bank.iban %}{{ bp_bank.bank }}<br>IBAN {{ bp_bank.iban }}{% if bp_bic %}<br>BIC {{ bp_bic }}{% endif %}{% endif %}</td>
</tr>
</table>`, "${companyVars}", companyVars))
// documentHTML is the body of the offer, the order confirmation and the
// invoice. § 14 Abs. 4 UStG: supplier and recipient, tax numbers, date,
// number, items with quantity and unit, service period, net by rate, tax
// rate and amount, gross; reverse-charge note where it applies.
var documentHTML = brand.Replace(`{%- set is_inv = doc.doctype == "Sales Invoice" -%}
{%- set is_so = doc.doctype == "Sales Order" -%}
{%- set title = ("Rechnungskorrektur" if doc.is_return else "Rechnung") if is_inv else ("Auftragsbestätigung" if is_so else "Angebot") -%}
{%- set doc_date = doc.posting_date if is_inv else doc.transaction_date -%}
{%- set bp_addr = frappe.db.get_value("Address", {"is_your_company_address": 1, "is_primary_address": 1, "disabled": 0}, ["address_line1", "pincode", "city", "email_id"], as_dict=1) or {"address_line1": "In Steinäckern 16", "pincode": "78351", "city": "Bodman-Ludwigshafen", "email_id": "kontakt@breakpilot.com"} -%}
{%- set cust = doc.customer if doc.doctype != "Quotation" else doc.party_name -%}
{%- set mandate = frappe.db.get_value("Customer", cust, ["sepa_mandate_reference", "sepa_mandate_type"], as_dict=1) if doc.doctype != "Quotation" or doc.quotation_to == "Customer" else None -%}
{%- set sepa = doc.payment_schedule and doc.payment_schedule[0].mode_of_payment == "SEPA-Lastschrift" -%}
{%- set transfer = doc.payment_schedule and doc.payment_schedule[0].mode_of_payment == "Überweisung" -%}
{%- set tpl = doc.taxes_and_charges or "" -%}
{%- set order_no = (doc.items[0].get("sales_order") if is_inv and doc.items else None) -%}
{%- set service_start = doc.get("from_date") or doc.get("delivery_date") -%}
{%- set units = doc.items | selectattr("rate", "ge", 0) | map(attribute="uom") | list if doc.items else [] -%}
{%- set interval = "monatlich" if units and units | select("equalto", "Monat") | list | length == units | length else ("jährlich" if units and units | select("equalto", "Jahr") | list | length == units | length else "") -%}
{%- set has_mandate = mandate and mandate.sepa_mandate_reference -%}
{%- set period_from = doc.get("from_date") or (doc.items[0].get("service_start_date") if doc.items else None) -%}
{%- set period_to = doc.get("to_date") or (doc.items[0].get("service_end_date") if doc.items else None) -%}
{%- if letter_head and not no_letterhead %}<div class="letter-head">{{ letter_head }}</div>{% endif %}
<style>
.action-banner { display: none !important; }
.bp { font-family: Arial, Helvetica, sans-serif; font-size: 9.5pt; color: $INK; line-height: 1.45; }
.bp table { border-collapse: collapse; font-size: 9.5pt; }
.bp td, .bp th { font-size: 9.5pt; }
.bp .sender { font-size: 7pt; color: $FAINT; border-bottom: 0.5px solid $LINE; padding-bottom: 2px; margin-bottom: 6px; }
.bp .meta td { padding: 1px 0; font-size: 8.5pt; vertical-align: top; }
.bp .meta td.k { color: $MUTED; padding-right: 12px; }
.bp h1 { font-size: 16pt; margin: 26px 0 4px 0; color: $INK; font-weight: bold; }
.bp .items { width: 100%; margin-top: 14px; }
.bp .items th { font-size: 8pt; color: $MUTED; font-weight: normal; text-align: left; border-bottom: 1px solid $INK; padding: 4px 6px 4px 0; }
.bp .items td { vertical-align: top; border-bottom: 0.5px solid $LINE; padding: 6px 6px 6px 0; }
.bp .r { text-align: right; }
.bp .desc { font-size: 7.5pt; color: $MUTED; }
.bp .nw { white-space: nowrap; }
.bp .totals { margin-left: auto; margin-top: 10px; min-width: 45%; }
.bp .totals td { padding: 2px 0 2px 16px !important; }
.bp .totals tr.grand td { border-top: 1px solid $INK; font-weight: bold; font-size: 10.5pt; padding-top: 5px !important; }
.bp .note { margin-top: 18px; font-size: 8.5pt; }
.bp .sepa-head { margin: 10px 0 2px 0; }
.bp .note p.sepa-head + p { margin-top: 0; }
.bp .muted { color: $MUTED; }
</style>
<div class="bp">
<table style="width:100%;margin-top:18px;"><tr>
<td style="vertical-align:top;width:58%;">
<div class="sender">{{ doc.company }} · {{ bp_addr.address_line1 }} · {{ bp_addr.pincode }} {{ bp_addr.city }}</div>
<b>{{ doc.customer_name }}</b><br>
{%- set ca = frappe.db.get_value("Address", doc.customer_address, ["address_line1", "address_line2", "pincode", "city", "country"], as_dict=1) if doc.customer_address else None %}
{%- if ca %}
{{ ca.address_line1 }}<br>{% if ca.address_line2 %}{{ ca.address_line2 }}<br>{% endif %}
{{ ca.pincode or "" }} {{ ca.city }}{% if ca.country and ca.country != "Germany" %}<br>{{ _(ca.country) | upper }}{% endif %}
{%- else %}
{{ doc.address_display or "" }}
{%- endif %}
</td>
<td style="vertical-align:top;">
<table class="meta" style="margin-left:auto;">
<tr><td class="k">Nummer</td><td class="nw"><b>{{ doc.name }}</b></td></tr>
<tr><td class="k">Datum</td><td>{{ frappe.utils.formatdate(doc_date) }}</td></tr>
{%- if cust and cust != doc.customer_name %}<tr><td class="k">Kundennummer</td><td>{{ cust }}</td></tr>{% endif %}
{%- if is_inv and order_no %}<tr><td class="k">Auftragsnummer</td><td class="nw">{{ order_no }}</td></tr>{% endif %}
{%- if doc.get("vertragsgrundlage") %}<tr><td class="k">Vertragsgrundlage</td><td>{{ doc.vertragsgrundlage }}</td></tr>{% endif %}
{%- if is_so and service_start %}<tr><td class="k">Leistungsbeginn</td><td>{{ frappe.utils.formatdate(service_start) }}</td></tr>{% endif %}
{%- if is_so and interval %}<tr><td class="k">Abrechnungsintervall</td><td>{{ interval }}</td></tr>{% endif %}
{%- if doc.get("tax_id") %}<tr><td class="k">Ihre USt-IdN&zwnj;r.</td><td>{{ doc.tax_id }}</td></tr>{% endif %}
{%- if is_inv and not doc.is_return %}<tr><td class="k">Fällig am</td><td>{{ frappe.utils.formatdate(doc.due_date) }}</td></tr>{% endif %}
{%- if doc.doctype == "Quotation" and doc.valid_till %}<tr><td class="k">Gültig bis</td><td>{{ frappe.utils.formatdate(doc.valid_till) }}</td></tr>{% endif %}
{%- if doc.get("po_no") %}<tr><td class="k">Ihre Bestellung</td><td>{{ doc.po_no }}</td></tr>{% endif %}
</table>
</td>
</tr></table>
<h1>{{ title }}</h1>
{%- if is_inv and doc.is_return and doc.return_against %}<div class="muted">zu Rechnung {{ doc.return_against }}</div>{% endif %}
{%- if is_inv %}
<div class="muted">Leistungszeitraum: {% if period_from and period_to %}{{ frappe.utils.formatdate(period_from) }} – {{ frappe.utils.formatdate(period_to) }}{% else %}Das Leistungsdatum entspricht dem Rechnungsdatum.{% endif %}</div>
{%- endif %}
<table class="items">
<thead><tr>
<th style="width:5%;">Pos.</th><th>Leistung</th><th class="r" style="width:12%;">Menge</th><th class="r" style="width:15%;">Einzelpreis</th><th class="r" style="width:15%;">Betrag</th>
</tr></thead>
<tbody>
{%- for it in doc.items %}
<tr>
<td>{{ loop.index }}</td>
<td><b>{{ it.item_name }}</b><br><span class="desc">{{ it.item_code }}{% if it.description and it.description != it.item_name %} · {{ it.description | striptags }}{% endif %}{% if it.get("service_start_date") and it.get("service_end_date") and not doc.get("from_date") %}<br>Zeitraum {{ frappe.utils.formatdate(it.service_start_date) }} – {{ frappe.utils.formatdate(it.service_end_date) }}{% endif %}</span></td>
<td class="r nw">{{ ("%g"|format(it.qty)) | replace(".", ",") }} {{ it.uom }}</td>
<td class="r nw">{{ it.get_formatted("rate", doc) }}</td>
<td class="r nw">{{ it.get_formatted("amount", doc) }}</td>
</tr>
{%- endfor %}
</tbody>
</table>
{%- set net_discount = (doc.total or 0) - (doc.net_total or 0) -%}
<table class="totals">
{%- if net_discount > 0.005 %}
<tr><td>Zwischensumme</td><td class="r">{{ doc.get_formatted("total") }}</td></tr>
<tr><td>Rabatt</td><td class="r">− {{ frappe.utils.fmt_money(net_discount, currency=doc.currency) }}</td></tr>
{%- endif %}
<tr><td>Summe netto</td><td class="r">{{ doc.get_formatted("net_total") }}</td></tr>
{%- for t in doc.taxes %}{% if t.tax_amount_after_discount_amount %}
<tr><td>{{ t.description }}{% if t.rate and "%" not in t.description %} ({{ ("%g"|format(t.rate)) | replace(".", ",") }} %){% endif %}</td><td class="r">{{ t.get_formatted("tax_amount_after_discount_amount", doc) }}</td></tr>
{%- endif %}{% endfor %}
<tr class="grand"><td>{% if doc.doctype == "Quotation" and interval == "monatlich" %}Monatlicher Gesamtbetrag{% else %}Gesamtbetrag{% endif %}</td><td class="r">{{ doc.get_formatted("rounded_total" if doc.rounded_total else "grand_total") }}</td></tr>
</table>
<div class="note">
{%- if "an Unternehmen in der EU" in tpl %}
<p><b>Steuerschuldnerschaft des Leistungsempfängers</b> (Reverse Charge, § 13b UStG / Art. 196 MwStSystRL).</p>
{%- elif "Drittland" in tpl %}
<p>Nicht im Inland steuerbare Leistung.</p>
{%- endif %}
{%- if doc.doctype == "Quotation" %}
{#- The Pilotrabatt is a negative line item (eu_einvoice cannot carry a
document-level discount), so count negative lines as well as the
document discount. -#}
{%- set line_discount = 0 - (doc.items | selectattr("rate", "lt", 0) | sum(attribute="amount")) if doc.items else 0 -%}
{%- set total_discount = net_discount + line_discount -%}
{#- padding, not margin: wkhtmltopdf drops a margin at a page break, and the
block usually moves whole to page 2, which has no letter head. -#}
<div style="page-break-inside:avoid;padding-top:28px;">
<p class="sepa-head"><b>Vertragsbedingungen</b></p>
<table class="meta" style="margin-top:2px;page-break-inside:avoid;">
<tr><td class="k">Vertragsart</td><td>Monatlich wiederkehrende SaaS- und Hosting-Leistungen (Abonnement).</td></tr>
<tr><td class="k">Vertragsbeginn</td><td>{{ doc.get("contract_start") or "Mit Bereitstellung der gebuchten Dienste gemäß Auftragsbestätigung." }}</td></tr>
<tr><td class="k">Laufzeit / Kündigung</td><td>Keine Mindestlaufzeit; der Vertrag läuft auf unbestimmte Zeit. Monatlich kündbar mit einer Frist von einem Monat zum Monatsende.</td></tr>
<tr><td class="k">Abrechnung</td><td>Monatlich, jeweils zu Beginn des Leistungszeitraums.</td></tr>
<tr><td class="k">{% if interval == "monatlich" %}Monatliche Vergütung{% else %}Vergütung{% endif %}</td><td>{{ doc.get_formatted("net_total") }} netto zzgl. gesetzlicher Umsatzsteuer.{% if total_discount > 0.005 %} Der darin enthaltene monatliche Nachlass von {{ frappe.utils.fmt_money(total_discount, currency=doc.currency) }} gilt dauerhaft, einschließlich etwaiger Verlängerungen.{% endif %}</td></tr>
{#- Mehrverbrauch: for Prüfwerk the extra Prüfobjekte (CRA-CSA-CLD-TGT) and
Prüftage (CRA-CSA-CLD-DAY) at the rates on the quote's price list, except
on an Enterprise quote (no limits); for Managed Git and the Starter bundle
the users beyond the included ones. A missing rate reads "gemäß der
jeweils gültigen Preisliste". -#}
{%- set item_codes = " " ~ ((doc.items or []) | map(attribute="item_code") | join(" ")) ~ " " -%}
{%- set pw_overage = " CRA-CSA-" in item_codes and " CRA-CSA-CLD-ENT " not in item_codes -%}
{%- set more_users = " INF-GIT-CLD-STD " in item_codes or " INF-GIT-CLD-BUS " in item_codes or " INF-GIT-CLD-ENT " in item_codes or " PLT-BNDL-" in item_codes -%}
{%- if pw_overage or more_users %}
{%- set price_list = doc.selling_price_list or "Standard Selling" %}
<tr><td class="k">Mehrverbrauch</td><td>
{%- if pw_overage %}
{%- set tgt_rate = frappe.db.get_value("Item Price", {"item_code": "CRA-CSA-CLD-TGT", "price_list": price_list, "selling": 1}, "price_list_rate") %}
{%- set day_rate = frappe.db.get_value("Item Price", {"item_code": "CRA-CSA-CLD-DAY", "price_list": price_list, "selling": 1}, "price_list_rate") %}
{%- if tgt_rate or day_rate %}Zusätzliche Prüfobjekte werden {% if tgt_rate %}mit {{ frappe.utils.fmt_money(tgt_rate, currency=doc.currency) }} netto je Monat{% else %}gemäß der jeweils gültigen Preisliste{% endif %} berechnet, Prüftage nach verbrauchtem Monatskontingent {% if day_rate %}mit {{ frappe.utils.fmt_money(day_rate, currency=doc.currency) }} netto{% else %}gemäß der jeweils gültigen Preisliste{% endif %}
{%- else %}Zusätzliche Prüfobjekte und Prüftage nach verbrauchtem Monatskontingent werden gemäß der jeweils gültigen Preisliste berechnet{% endif %} (Leistungsbeschreibung Prüfwerk, Abschnitt 7).
{%- endif %}
{%- if more_users %}{% if pw_overage %} {% endif %}Weitere Nutzer über die enthaltenen Nutzer hinaus werden je Modul nach Preisliste berechnet (Leistungsbeschreibung Breakpilot Plattform, Abschnitt 4).{% endif %}</td></tr>
{%- endif %}
{#- The Leistungsbeschreibungen by module and version (catalog.go lbVersions):
each LB says the version named in the quote applies. -#}
{%- set lb_versions = $LB_VERSIONS -%}
<tr><td class="k">Vertragsgrundlagen</td><td>{{ doc.get("vertragsgrundlage") or ("Es gelten die SaaS-Vertragsbedingungen, die Leistungsbeschreibungen (" ~ lb_versions ~ "), das SLA und die AVV (Art. 28 DSGVO) in der jeweils vereinbarten Fassung. Auf Anfrage erhalten Sie die Dokumente vorab; nach Vertragsschluss stehen sie im Breakpilot-Kundenportal zum Abruf bereit.") }}</td></tr>
<tr><td class="k">Annahme</td><td>Durch schriftliche oder elektronische Annahme dieses Angebots{% if doc.valid_till %} bis zum {{ frappe.utils.formatdate(doc.valid_till) }}{% endif %}.</td></tr>
</table>
</div>
{%- endif %}
{%- if is_inv and not doc.is_return %}
{%- if sepa and has_mandate %}
{%- set creditor = frappe.db.get_value("Company", doc.company, "sepa_creditor_id") %}
<p class="sepa-head"><b>SEPA-Lastschrift</b></p>
<p>Den Rechnungsbetrag von <b>{{ doc.get_formatted("rounded_total" if doc.rounded_total else "grand_total") }}</b> ziehen wir am <b>{{ frappe.utils.formatdate(doc.due_date) }}</b> auf Grundlage des erteilten SEPA-Lastschriftmandats ein.<br>
{%- if creditor %}Gläubiger-Identifikationsnummer: {{ creditor }}<br>{% endif %}
Mandatsreferenz: {{ mandate.sepa_mandate_reference }}<br>
Bitte sorgen Sie für ausreichende Kontodeckung.</p>
{%- else %}
<p>Bitte überweisen Sie den Rechnungsbetrag bis zum <b>{{ frappe.utils.formatdate(doc.due_date) }}</b> unter Angabe der Rechnungsnummer <b>{{ doc.name }}</b>.</p>
{%- endif %}
{%- elif not is_inv and sepa %}
{%- set term = frappe.db.get_value("Payment Term", doc.payment_schedule[0].payment_term, ["credit_days", "due_date_based_on"], as_dict=1) if doc.payment_schedule[0].payment_term else None -%}
<p>Zahlungsart: SEPA-Lastschrift{% if term and term.credit_days and term.due_date_based_on == "Day(s) after invoice date" %}, Einzug {{ term.credit_days }} Tage nach Rechnungsdatum{% endif %}, {{ "gemäß erteiltem SEPA-Lastschriftmandat" if has_mandate else "nach Erteilung eines gültigen SEPA-Lastschriftmandats" }}. Vor jedem Einzug informieren wir Sie mindestens 14 Tage im Voraus über Betrag und Fälligkeit (Vorabinformation; kürzere Frist nach Vereinbarung).</p>
{%- elif not is_inv and transfer %}
{%- set term = frappe.db.get_value("Payment Term", doc.payment_schedule[0].payment_term, ["credit_days", "due_date_based_on"], as_dict=1) if doc.payment_schedule[0].payment_term else None -%}
<p>Zahlungsart: Überweisung{% if term and term.credit_days and term.due_date_based_on == "Day(s) after invoice date" %}, zahlbar innerhalb von {{ term.credit_days }} Tagen nach Rechnungsdatum{% endif %}.</p>
{%- endif %}
{%- if doc.get("terms") %}<div class="muted">{{ doc.terms }}</div>{% endif %}
<p class="muted">Vielen Dank für Ihr Vertrauen.</p>
</div>
</div>
{%- if footer and not no_letterhead %}
<div id="footer-html" class="visible-pdf">
<div class="letter-head-footer">{{ footer }}</div>
<p class="visible-pdf" style="text-align:right;font-family:Arial,Helvetica,sans-serif;font-size:6.5pt;color:$FAINT;margin:2px 0 0 0;">Seite <span class="page"></span> von <span class="topage"></span></p>
</div>
{%- endif %}`)
// invoiceMailHTML goes with the PDF when an invoice is sent from ERPNext.
// Email templates render with the document's fields as top-level names.
var invoiceMailHTML = brand.Replace(`<div style="font-family:Arial,Helvetica,sans-serif;font-size:14px;line-height:1.6;color:$INK;">
<p>Guten Tag,</p>
<p>anbei erhalten Sie unsere Rechnung <b>{{ name }}</b> vom {{ frappe.utils.formatdate(posting_date) }} über <b>{{ frappe.utils.fmt_money(grand_total, currency=currency) }}</b>.</p>
{% if payment_schedule and payment_schedule[0].mode_of_payment == "SEPA-Lastschrift" and frappe.db.get_value("Customer", customer, "sepa_mandate_reference") -%}
<p>Den Betrag ziehen wir am {{ frappe.utils.formatdate(due_date) }} per SEPA-Lastschrift ein. Die Einzelheiten stehen auf der Rechnung.</p>
{%- else -%}
<p>Bitte überweisen Sie den Betrag bis zum {{ frappe.utils.formatdate(due_date) }}.</p>
{%- endif %}
<p>Bei Fragen zur Rechnung antworten Sie einfach auf diese E-Mail.</p>
<table style="font-size:13px;line-height:1.5;color:$INK;border-collapse:collapse;margin-top:18px;"><tr><td>
<div style="font-size:12px;color:#71769B;">Mit freundlichen Grüßen</div>
<div style="font-size:16px;font-weight:bold;margin:1px 0 10px;">Ihr Breakpilot-Team</div>
<div style="font-weight:bold;">{{ company }}</div>
<div style="color:#43466A;">In Steinäckern 16, 78351 Bodman-Ludwigshafen</div>
<div style="color:#43466A;"><a href="mailto:kontakt@breakpilot.com" style="color:$ACCENT;text-decoration:none;">kontakt@breakpilot.com</a> · <a href="https://www.breakpilot.com" style="color:$ACCENT;text-decoration:none;">www.breakpilot.com</a></div>
<div style="border-top:1px solid #E1E1EA;margin:12px 0 9px;width:300px;max-width:100%;font-size:0;line-height:0;">&nbsp;</div>
<div style="font-size:11px;color:$FAINT;">USt-IdNr. DE464808363 · $REGISTER</div>
<div style="font-size:11px;color:$FAINT;">$DIRECTORS</div>
</td></tr></table>
</div>`)