From 944a5bb442358b5f3b41d6564e14c58202f216b0 Mon Sep 17 00:00:00 2001
From: Stefan
Date: Wed, 16 Sep 2026 22:18:42 +0200
Subject: [PATCH] Refactor document name sanitization for consistent filename
generation
- Introduced FdsDocumentNames class to centralize the logic for sanitizing document names used in downloads.
- Updated FdsMfr to utilize the new SafeFileName method for generating safe filenames.
- Enhanced documentation for FdsDocumentNames and its methods to clarify usage and purpose.
- Added global.json file to configure testing framework settings.
---
.github/copilot-instructions.md | 2 +-
CLAUDE.md | 2 +-
CODEX.md | 2 +-
Fuchs.Tests/ReportDocFileNameTests.cs | 51 +++++++++++++++++++
.../IntranetController.Invoices2.cs | 16 ++----
.../IntranetController.PdfPreview.cs | 36 +++++++++++++
Fuchs/Program.cs | 32 ++++++++++++
Fuchs/js/intranet/modules/fis.inv_shared.js | 24 +++++++--
Fuchs/js/intranet/modules/fis.inv_txt_de.js | 1 +
Fuchs/wwwroot/web/fis.inv.de.js | 25 +++++++--
Fuchs/wwwroot/web/fis.inv.de.min.js | 2 +-
Fuchs/wwwroot/web/fis.req.de.js | 25 +++++++--
Fuchs/wwwroot/web/fis.req.de.min.js | 2 +-
Fuchs/wwwroot/web/tools.js | 5 +-
Fuchs_DataService/FdsMfr.cs | 9 ++--
Fuchs_DataService/FdsShared.cs | 27 ++++++++++
Fuchs_DataService/Fuchs_DataService.xml | 13 +++++
global.json | 5 ++
18 files changed, 245 insertions(+), 34 deletions(-)
create mode 100644 global.json
diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index 4cfdafe..69e058e 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -14,7 +14,7 @@
- Routes: `/{fn?}/{id?}/{code?}` → `IntranetController.Index`; `/do/{fn?}/{id?}/{code?}` → `IntranetController.Do`.
- Build app: `dotnet build Fuchs/Fuchs.csproj -c Debug`. Build all: `dotnet build Fuchs_Intranet.slnx -c Debug`.
- Frontend assets are source-built: run the gulp tasks in `Fuchs/` (`npx gulp min`, or `npx gulp all` when copied/static assets also need refreshing) whenever JS or SCSS/CSS sources change. The generated files under `Fuchs/wwwroot/web/` are what the app serves.
-- Test: `dotnet test Fuchs.Tests/Fuchs.Tests.csproj -c Debug`.
+- Test: `dotnet test --project Fuchs.Tests/Fuchs.Tests.csproj -c Debug` (the root `global.json` opts `dotnet test` into the Microsoft.Testing.Platform runner that xunit.v3 needs on the .NET 10 SDK; the positional-path form no longer works).
- Always build **and** run the test suite before committing. CA1416 (platform-compatibility) is suppressed solution-wide via the root `.editorconfig` — the app is Windows-only. The build may still emit other pre-existing analyzer warnings; only treat `: error` lines as failures.
- Submodules include the OCORE projects and `eRechnungLib` (ZUGFeRD/Factur-X + XRechnung generation) — invoices are moving to eRechnung output.
- Project structure (relative to `Fuchs/`):
diff --git a/CLAUDE.md b/CLAUDE.md
index 5dbdfc6..b4119d3 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -16,7 +16,7 @@
## Build & Test (workflow)
- Build app: `dotnet build Fuchs/Fuchs.csproj -c Debug`. Build all: `dotnet build Fuchs_Intranet.slnx -c Debug`.
- Frontend assets are source-built: run the gulp tasks in `Fuchs/` (`npx gulp min`, or `npx gulp all` when copied/static assets also need refreshing) whenever JS or SCSS/CSS sources change. The generated files under `Fuchs/wwwroot/web/` are what the app serves.
-- Test: `dotnet test Fuchs.Tests/Fuchs.Tests.csproj -c Debug`.
+- Test: `dotnet test --project Fuchs.Tests/Fuchs.Tests.csproj -c Debug` (the root `global.json` opts `dotnet test` into the Microsoft.Testing.Platform runner that xunit.v3 needs on the .NET 10 SDK; the positional-path form no longer works).
- Always build **and** run the test suite before committing. CA1416 (platform-compatibility) is suppressed solution-wide via the root `.editorconfig` — the app is Windows-only. The build may still emit other pre-existing analyzer warnings; only treat `: error` lines as failures.
- Commit only when asked. Co-author trailer: `Co-Authored-By: Claude Opus 4.8 `.
- The working tree may contain an untracked `Fuchs_Database/` SQL project — it is **not** part of app changes; never `git add -A` it into an unrelated commit. Stage explicit paths.
diff --git a/CODEX.md b/CODEX.md
index d69afc5..4508e36 100644
--- a/CODEX.md
+++ b/CODEX.md
@@ -16,7 +16,7 @@
## Build & Test (workflow)
- Build app: `dotnet build Fuchs/Fuchs.csproj -c Debug`. Build all: `dotnet build Fuchs_Intranet.slnx -c Debug`.
- Frontend assets are source-built: run the gulp tasks in `Fuchs/` (`npx gulp min`, or `npx gulp all` when copied/static assets also need refreshing) whenever JS or SCSS/CSS sources change. The generated files under `Fuchs/wwwroot/web/` are what the app serves.
-- Test: `dotnet test Fuchs.Tests/Fuchs.Tests.csproj -c Debug`.
+- Test: `dotnet test --project Fuchs.Tests/Fuchs.Tests.csproj -c Debug` (the root `global.json` opts `dotnet test` into the Microsoft.Testing.Platform runner that xunit.v3 needs on the .NET 10 SDK; the positional-path form no longer works).
- Always build **and** run the test suite before committing. CA1416 (platform-compatibility) is suppressed solution-wide via the root `.editorconfig` — the app is Windows-only. The build may still emit other pre-existing analyzer warnings; only treat `: error` lines as failures.
- Commit only when asked. Co-author trailer, when requested: `Co-Authored-By: Codex `.
- The working tree may contain an untracked `Fuchs_Database/` SQL project — it is **not** part of app changes; never `git add -A` it into an unrelated commit. Stage explicit paths.
diff --git a/Fuchs.Tests/ReportDocFileNameTests.cs b/Fuchs.Tests/ReportDocFileNameTests.cs
index 03146ec..301fa52 100644
--- a/Fuchs.Tests/ReportDocFileNameTests.cs
+++ b/Fuchs.Tests/ReportDocFileNameTests.cs
@@ -26,8 +26,59 @@ public class ReportDocFileNameTests
[InlineData("")]
[InlineData(" ")]
[InlineData("")]
+ [InlineData("
")]
public void SafeDocumentFileName_EmptyDocumentName_UsesFallback(string? documentName)
{
Assert.Equal("Rechnung_W7VAL.pdf", IntranetController.SafeDocumentFileName(documentName!, "Rechnung_W7VAL.pdf"));
}
+
+ ///
+ /// The stored-document path (FdsMfr.GetReportDoc) replaced exactly these characters
+ /// before the sanitiser was shared: = > | ! < /. The shared helper must still
+ /// produce the identical result for them — unifying the two paths may not loosen either.
+ ///
+ [Theory]
+ [InlineData("a>b|c!dSumme=100!.pdf
", "Summe_100_.pdf")]
+ public void SafeFileName_KeepsEveryReplacementTheStoredDocumentPathMade(string documentName, string expected)
+ {
+ Assert.Equal(expected, fds.FdsDocumentNames.SafeFileName(documentName, "X.pdf"));
+ }
+
+ ///
+ /// Characters the old stored-document path did NOT catch but Windows rejects — the reason
+ /// the sanitiser was unified (code review on ADR 0025): a stored and a regenerated document
+ /// must never diverge in filename safety.
+ ///
+ [Theory]
+ [InlineData("Angebot A\\B.pdf", "Angebot A_B.pdf")]
+ [InlineData("Re: 2026.pdf", "Re_ 2026.pdf")]
+ [InlineData("x*y?z\".pdf", "x_y_z_.pdf")]
+ [InlineData("tab\there.pdf", "tab_here.pdf")]
+ public void SafeFileName_ReplacesInvalidCharsTheStoredDocumentPathMissed(string documentName, string expected)
+ {
+ Assert.Equal(expected, fds.FdsDocumentNames.SafeFileName(documentName, "X.pdf"));
+ }
+
+ [Theory]
+ [InlineData("Rechnung R2026-0258.pdf")]
+ [InlineData("Wartung 2025/26 R2026-0001.pdf")]
+ [InlineData("a>b|c!d|z?*.pdf")]
+ [InlineData("")]
+ [InlineData(null)]
+ public void SafeDocumentFileName_MatchesSharedSanitiserForEveryInput(string? documentName)
+ {
+ Assert.Equal(
+ fds.FdsDocumentNames.SafeFileName(documentName, "Rechnung_X.pdf"),
+ IntranetController.SafeDocumentFileName(documentName!, "Rechnung_X.pdf"));
+ }
+
+ [Fact]
+ public void SafeFileName_ReturnsFallbackVerbatim_WhenNothingUsableRemains()
+ {
+ // The fallback is the caller's responsibility and is not sanitised or second-guessed.
+ Assert.Equal("W7VAL", fds.FdsDocumentNames.SafeFileName("", "W7VAL"));
+ Assert.Equal("", fds.FdsDocumentNames.SafeFileName("", ""));
+ }
}
diff --git a/Fuchs/Controllers/IntranetController.Invoices2.cs b/Fuchs/Controllers/IntranetController.Invoices2.cs
index ad02628..1bb452b 100644
--- a/Fuchs/Controllers/IntranetController.Invoices2.cs
+++ b/Fuchs/Controllers/IntranetController.Invoices2.cs
@@ -329,18 +329,12 @@ public partial class IntranetController
}
///
- /// Download filename for a regenerated document. DocumentName is derived from the user-typed
- /// invoice title, so it can carry path separators ("Wartung 2025/26") and stray editor markup;
- /// mirrors the cleanup FdsMfr.GetReportDoc applies to stored documents.
+ /// Download filename for a regenerated document — the one shared sanitiser
+ /// () that FdsMfr.GetReportDoc also
+ /// applies to stored documents, so both paths name the same DocumentName identically.
///
- internal static string SafeDocumentFileName(string documentName, string fallback)
- {
- string name = (documentName ?? "").Replace("
", "").Replace("
", "").Trim();
- if (name.Length == 0) name = fallback;
- foreach (char c in Path.GetInvalidFileNameChars())
- name = name.Replace(c, '_');
- return name.Length == 0 ? fallback : name;
- }
+ internal static string SafeDocumentFileName(string documentName, string fallback) =>
+ fds.FdsDocumentNames.SafeFileName(documentName, fallback);
private async Task HandleReportDocByName(string fn, string id, string code)
{
diff --git a/Fuchs/Controllers/IntranetController.PdfPreview.cs b/Fuchs/Controllers/IntranetController.PdfPreview.cs
index 63dc8ba..61e21a8 100644
--- a/Fuchs/Controllers/IntranetController.PdfPreview.cs
+++ b/Fuchs/Controllers/IntranetController.PdfPreview.cs
@@ -36,6 +36,28 @@ public partial class IntranetController
{
var result = await render();
sw.Stop();
+
+ // The client (postXT) gives up after a fixed timeout and aborts the connection while a
+ // slow render/regenerate-on-miss (ADR 0025) is still running server-side; that work is
+ // deliberately NOT cancelled — the regenerated document must still be stored so the
+ // next click is fast (ADR 0025) — but writing the now-finished result back to a socket
+ // the client already closed would only surface as a low-level framework/Kestrel
+ // exception that never reaches an EventId'd `_logger` call: it is either below the SQL
+ // sink's Warning floor or purely a debugger first-chance notification that never goes
+ // through ILogger at all — exactly the "exception in the debug console but nothing in
+ // fds__debuglog" gap. Recognise the disconnect here instead and log it deliberately, at
+ // Warning, so it is guaranteed to land in fds__debuglog (ADR 0024) — and skip the write.
+ if (HttpContext.RequestAborted.IsCancellationRequested)
+ {
+ FuchsTelemetry.PdfPreviews.Add(1,
+ new KeyValuePair("what", what),
+ new KeyValuePair("outcome", "client-disconnected"));
+ _logger.LogWarning(
+ "PDF preview {What} ref={RefId} user={User} finished in {Ms} ms but the client had already disconnected (timeout) — result discarded",
+ what, refId, UserAccountID, sw.ElapsedMilliseconds);
+ return new EmptyResult();
+ }
+
// A draft session that expired between page load and preview click is an expected
// client-driven outcome (the browser reopens the draft), not a render failure — keep
// it out of the failure telemetry/logging this guard exists to produce.
@@ -51,6 +73,20 @@ public partial class IntranetController
{
sw.Stop();
act?.SetStatus(ActivityStatusCode.Error, ex.Message);
+ // Same client-gone rationale as above, but the render itself threw (e.g. it tried to
+ // write partial output to the aborted connection). Still an expected outcome of a
+ // client timeout, not a render defect — logged at Warning, not Error, but still
+ // guaranteed to reach fds__debuglog (ADR 0024) rather than only a debug console.
+ if (HttpContext.RequestAborted.IsCancellationRequested)
+ {
+ FuchsTelemetry.PdfPreviews.Add(1,
+ new KeyValuePair("what", what),
+ new KeyValuePair("outcome", "client-disconnected"));
+ _logger.LogWarning(ex,
+ "PDF preview {What} ref={RefId} user={User} failed after {Ms} ms because the client had already disconnected",
+ what, refId, UserAccountID, sw.ElapsedMilliseconds);
+ return new EmptyResult();
+ }
FuchsTelemetry.PdfPreviews.Add(1,
new KeyValuePair("what", what),
new KeyValuePair("outcome", "failure"));
diff --git a/Fuchs/Program.cs b/Fuchs/Program.cs
index 3a90447..5f189dc 100644
--- a/Fuchs/Program.cs
+++ b/Fuchs/Program.cs
@@ -236,6 +236,38 @@ public class Program
// calls silently no-op instead of reaching Debug output / ErrorLog.txt.
OCORE.Logging.Logger = app.Logger;
+ // Exceptions that never pass through a request (Do()'s catch-all, PdfPreviewAsync,
+ // UseExceptionHandler) or a hosted service's own try/catch — a faulted fire-and-forget
+ // Task nobody awaited, or a crash on a non-request thread — are otherwise visible only
+ // as a debugger notification or a process exit: they never reach ILogger and therefore
+ // never reach fds__debuglog (ADR 0024). Route them through the app logger so the SQL
+ // sink and ErrorLog.txt both see them. On a terminating crash the fire-and-forget SQL
+ // write may not complete; the synchronous file sink (0003) is the record then.
+ TaskScheduler.UnobservedTaskException += (_, e) =>
+ {
+ app.Logger.LogError(new EventId(0, "Unobserved task exception"), e.Exception,
+ "Unobserved task exception: {Message}", e.Exception.GetBaseException().Message);
+ e.SetObserved();
+ };
+ AppDomain.CurrentDomain.UnhandledException += (_, e) =>
+ {
+ var ex = e.ExceptionObject as Exception;
+ app.Logger.LogCritical(new EventId(0, "Unhandled exception"), ex,
+ "Unhandled exception on a non-request thread (terminating={IsTerminating}): {Message}",
+ e.IsTerminating, ex?.Message ?? e.ExceptionObject?.ToString());
+ };
+
+ // One deliberate Critical entry per application start. Critical is the one level no
+ // provider filters (file sink, console, SQL sink at Warning+), so a fds__debuglog row
+ // with CodeReference 'Application started' proves on every restart that the whole
+ // log pipeline (ADR 0024) is working end to end — and its absence is itself the alarm.
+ // Registered on ApplicationStarted so it is written once the host and every sink are up.
+ app.Lifetime.ApplicationStarted.Register(() =>
+ app.Logger.LogCritical(new EventId(0, "Application started"),
+ "Fuchs started: version={Version} environment={Environment} machine={Machine} pid={Pid}",
+ typeof(Program).Assembly.GetName().Version?.ToString() ?? "?",
+ app.Environment.EnvironmentName, Environment.MachineName, Environment.ProcessId));
+
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/error");
diff --git a/Fuchs/js/intranet/modules/fis.inv_shared.js b/Fuchs/js/intranet/modules/fis.inv_shared.js
index b3ea0e9..7378ab4 100644
--- a/Fuchs/js/intranet/modules/fis.inv_shared.js
+++ b/Fuchs/js/intranet/modules/fis.inv_shared.js
@@ -133,13 +133,27 @@ $inv.pdfPreviewFailed = function (jqXHR, textStatus) {
alert(($ict.pvf || $t.f1) + (desc !== '' ? '\n' + desc : ''));
};
/* postXT never calls `error` for a timeout (it returns early), so the timeout is only
- observable from `complete`; this builds the complete handler for a preview call. */
-$inv.pdfPreviewComplete = function (layout) {
+ observable from `complete`; this builds the complete handler for a preview call.
+ `wait`, if given, is the "please wait" popup from `$inv.pdfWaitDlg` — it must close on
+ every outcome (success, error, timeout), so `complete` is the only place that reliably
+ covers all three. */
+$inv.pdfPreviewComplete = function (layout, wait) {
return (jqXHR, textStatus) => {
+ if (wait) { wait.c.trigger('modal_close'); }
if (layout) { layout.rC('freeze'); }
if (textStatus === 'timeout') { $inv.pdfPreviewFailed(jqXHR, textStatus); }
};
};
+/* A preview render can take anywhere from a couple of seconds to the full 120s timeout (a
+ cold miss regenerates + stores the PDF before rasterising it, ADR 0025); postXT's generic
+ `body.ldng` class has no CSS behind it, so nothing tells the user the click was received.
+ Same popup the MFR data fetch shows (see $inv.cInv2): spinner frame in a modal with the
+ explanation in the footer. Non-exclusive so it can sit on top of an open editor. */
+$inv.pdfWaitDlg = function () {
+ let o = $ocms.dlg($$.dc('rfrm').ldng(1), { exclusive: false, zindex_min: 50 });
+ if (o) { o.ft.rwText($ict.pvw); }
+ return o;
+};
/* ── Backend-authoritative draft editing controller (ADR 0006/0007) ───────────
The server holds the truth for an invoice draft in an in-memory session; this
object seeds it, sends single edits as deltas, and renders the totals footer +
@@ -1563,6 +1577,7 @@ $inv.disp = (id, typ) => {
break;
}
if (u !== '') {
+ let wait = $inv.pdfWaitDlg();
$ocms.postXT({
url: $ocms.url(u), data: { id: id || '', typ: 'img' }, timeout: $inv.pdfPreviewTimeout, success: (response) => {
let c = $$.dc('imagecollection pdfpreview'), vhr = Math.round(vh() * 0.88), invid = response.id;
@@ -1572,11 +1587,12 @@ $inv.disp = (id, typ) => {
$ocms.dlg(c, {
size: [vhr, Math.round(vw() * 0.88)], zindex_min: 50, form: false, exclusive:false
});
- }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete()
+ }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete(null, wait)
});
}
};
$inv.jdbn = function (ev) {
+ let wait = $inv.pdfWaitDlg();
$ocms.postXT({
url: $ocms.url('inv/rdocn'), data: { name: ev.data.id || '', typ: 'img' }, timeout: $inv.pdfPreviewTimeout, success: (response) => {
let c = $$.dc('imagecollection pdfpreview'), vhr = Math.round(vh() * 0.88), invid = response.id;
@@ -1586,7 +1602,7 @@ $inv.jdbn = function (ev) {
$ocms.dlg(c, {
size: [vhr, Math.round(vw() * 0.88)], zindex: 50, form: false
});
- }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete()
+ }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete(null, wait)
});
};
$inv.sp13b = () => {
diff --git a/Fuchs/js/intranet/modules/fis.inv_txt_de.js b/Fuchs/js/intranet/modules/fis.inv_txt_de.js
index ad0ffe6..5a02024 100644
--- a/Fuchs/js/intranet/modules/fis.inv_txt_de.js
+++ b/Fuchs/js/intranet/modules/fis.inv_txt_de.js
@@ -38,6 +38,7 @@
pna: 'Diese Seite ist in der Vorschau nicht verfügbar',
tpe: 'Die Anzahl von {0} Seiten wird aktuell nicht unterstützt',
eis: 'Der Rechnungsentwurf konnte nicht gespeichert werden.',
+ pvw: 'Das Dokument wird abgerufen und für die Vorschau aufbereitet.\nDer Vorgang kann bis zu 2 Minuten dauern.',
pvf: 'Die PDF-Vorschau konnte nicht erstellt werden.',
pvto: 'Der Server hat nicht rechtzeitig geantwortet (Zeitüberschreitung). Bitte versuchen Sie es erneut.',
pvgone: 'Der Entwurf ist auf dem Server nicht mehr vorhanden (Sitzung abgelaufen). Bitte öffnen Sie den Entwurf erneut.',
diff --git a/Fuchs/wwwroot/web/fis.inv.de.js b/Fuchs/wwwroot/web/fis.inv.de.js
index 82f0ba5..c206902 100644
--- a/Fuchs/wwwroot/web/fis.inv.de.js
+++ b/Fuchs/wwwroot/web/fis.inv.de.js
@@ -162,6 +162,7 @@ let $ict = {
pna: 'Diese Seite ist in der Vorschau nicht verfügbar',
tpe: 'Die Anzahl von {0} Seiten wird aktuell nicht unterstützt',
eis: 'Der Rechnungsentwurf konnte nicht gespeichert werden.',
+ pvw: 'Das Dokument wird abgerufen und für die Vorschau aufbereitet.\nDer Vorgang kann bis zu 2 Minuten dauern.',
pvf: 'Die PDF-Vorschau konnte nicht erstellt werden.',
pvto: 'Der Server hat nicht rechtzeitig geantwortet (Zeitüberschreitung). Bitte versuchen Sie es erneut.',
pvgone: 'Der Entwurf ist auf dem Server nicht mehr vorhanden (Sitzung abgelaufen). Bitte öffnen Sie den Entwurf erneut.',
@@ -712,13 +713,27 @@ $inv.pdfPreviewFailed = function (jqXHR, textStatus) {
alert(($ict.pvf || $t.f1) + (desc !== '' ? '\n' + desc : ''));
};
/* postXT never calls `error` for a timeout (it returns early), so the timeout is only
- observable from `complete`; this builds the complete handler for a preview call. */
-$inv.pdfPreviewComplete = function (layout) {
+ observable from `complete`; this builds the complete handler for a preview call.
+ `wait`, if given, is the "please wait" popup from `$inv.pdfWaitDlg` — it must close on
+ every outcome (success, error, timeout), so `complete` is the only place that reliably
+ covers all three. */
+$inv.pdfPreviewComplete = function (layout, wait) {
return (jqXHR, textStatus) => {
+ if (wait) { wait.c.trigger('modal_close'); }
if (layout) { layout.rC('freeze'); }
if (textStatus === 'timeout') { $inv.pdfPreviewFailed(jqXHR, textStatus); }
};
};
+/* A preview render can take anywhere from a couple of seconds to the full 120s timeout (a
+ cold miss regenerates + stores the PDF before rasterising it, ADR 0025); postXT's generic
+ `body.ldng` class has no CSS behind it, so nothing tells the user the click was received.
+ Same popup the MFR data fetch shows (see $inv.cInv2): spinner frame in a modal with the
+ explanation in the footer. Non-exclusive so it can sit on top of an open editor. */
+$inv.pdfWaitDlg = function () {
+ let o = $ocms.dlg($$.dc('rfrm').ldng(1), { exclusive: false, zindex_min: 50 });
+ if (o) { o.ft.rwText($ict.pvw); }
+ return o;
+};
/* ── Backend-authoritative draft editing controller (ADR 0006/0007) ───────────
The server holds the truth for an invoice draft in an in-memory session; this
object seeds it, sends single edits as deltas, and renders the totals footer +
@@ -2142,6 +2157,7 @@ $inv.disp = (id, typ) => {
break;
}
if (u !== '') {
+ let wait = $inv.pdfWaitDlg();
$ocms.postXT({
url: $ocms.url(u), data: { id: id || '', typ: 'img' }, timeout: $inv.pdfPreviewTimeout, success: (response) => {
let c = $$.dc('imagecollection pdfpreview'), vhr = Math.round(vh() * 0.88), invid = response.id;
@@ -2151,11 +2167,12 @@ $inv.disp = (id, typ) => {
$ocms.dlg(c, {
size: [vhr, Math.round(vw() * 0.88)], zindex_min: 50, form: false, exclusive:false
});
- }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete()
+ }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete(null, wait)
});
}
};
$inv.jdbn = function (ev) {
+ let wait = $inv.pdfWaitDlg();
$ocms.postXT({
url: $ocms.url('inv/rdocn'), data: { name: ev.data.id || '', typ: 'img' }, timeout: $inv.pdfPreviewTimeout, success: (response) => {
let c = $$.dc('imagecollection pdfpreview'), vhr = Math.round(vh() * 0.88), invid = response.id;
@@ -2165,7 +2182,7 @@ $inv.jdbn = function (ev) {
$ocms.dlg(c, {
size: [vhr, Math.round(vw() * 0.88)], zindex: 50, form: false
});
- }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete()
+ }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete(null, wait)
});
};
$inv.sp13b = () => {
diff --git a/Fuchs/wwwroot/web/fis.inv.de.min.js b/Fuchs/wwwroot/web/fis.inv.de.min.js
index 54d2387..c46f6d6 100644
--- a/Fuchs/wwwroot/web/fis.inv.de.min.js
+++ b/Fuchs/wwwroot/web/fis.inv.de.min.js
@@ -1 +1 @@
-let $rct={mdl:"Aufträge",or:"offene Aufträge",orr:"offene Aufträge (4 W)",rn:"Auftragsnummer",iov:{all:"Auftragsübersicht (alle)","":"Auftragsübersicht"},wk:"Woche",nd:"Keine Daten gefunden.",h:"Uhr",rq1:"Auftragsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",rq2:"Auftragsdaten werden geladen",rq1f:"Die Auftragsdaten von MFR konnten nicht oder nicht schnell genug abgerufen werde.\nMöchten Sie mit den bestehenden Daten trotzdem weitermachen?",note1:"Im Bruttobetrag sind {0} Lohnkosten enthalten (netto {1}). Die darin enthaltene Umsatzsteuer beträgt {2}.",note2:"Bitte beachten Sie, nach §14 Abs. 1 Umsatzsteuergesetz ist diese Rechnung ein Zahlungsbeleg oder eine andere beweiskräftige Unterlage für 2 Jahre nach Ablauf des Kalenderjahres der Ausstellung dieser Rechnung aufzubewahren, soweit nicht aufgrund anderer gesetzlicher Regelungen andere ggf.längere Aufbewahrungsfristen gelten.",note3:"Privathaushalten erstattet das Finanzamt bis zu {0} des Arbeitslohns mit der nächsten Steuererklärung.",note4:"Für bereits erbrachte Arbeiten, Dienstleistungen, Materiallieferungen und getätigte Bestellvorgänge zum oben genannten Bauvorhaben, die sich aus dem mit Ihnen geschlossenen Vertrag ergeben, stellen wir Ihnen vertragsgemäß unsere Akontozahlung in Rechnung. Eine Endabrechnung erhalten Sie als Schlussrechnung nach Abschluss des gesamten Bauvorhabens. Das Ausführungsdatum entnehmen Sie bitte dem Schlusstext dieser Rechnung. Wir danken Ihnen herzlich für das entgegengebrachte Vertrauen und bitten Sie um kurzfristigen Ausgleich der Akontorechnung.",note13b:"Gem. §13b Umsatzsteuergesetz unterliegen Sie der Steuerschuldnerschaft des Leistungsempfängers zur Umsatzsteuer aus dieser Rechnung mit einem Steuersatz von 19%.",crI:"Rechnung erstellen",crII:"Abschlagsrechnung erstellen",dII:"Für eine Abschlagsrechnung darf nur ein Auftrag gewählt werden.",dnS:"Für eine Rechnung muss mindestens ein Auftrag gewählt werden.",inv:"Rechnung",invs:"Rechnungen",req:"Auftrag",provP:"Leistungszeitraum",provD:"Leistungsdatum",cP:"Position ändern",iRb:"Zeile darunter einfügen",dR:"Zeile löschen",sV:"USt festlegen",cD:"Löschen?",mR:"Zeile verschieben",ctxM:"Weitere Aktionen",noteToggle:"Notiz ein-/ausblenden",sectionTitleEditTT:"Auftragsbezeichnung ändern",svcPart:"Service-Anteil",vat:"Umsatzsteuer",combP:"Positionen zusammenfassen",toSetP:"Auf Setpreis umstellen (Positionen ohne Preis)",toSetPc:"Der Set-Preis wird auf die Summe seiner Positionen gesetzt und die Positionen selbst verlieren ihren Preis. Das ist nicht rückgängig zu machen (der Betrag kann danach nur noch manuell geändert werden). Fortfahren?",toSetMc:"Jedes Set erhält die Summe seiner Positionen als Set-Preis; die Positionen des Sets werden ohne Preis dargestellt bzw. ausgeblendet. Positionen ausserhalb eines Sets bleiben unverändert einzeln aufgeführt. Das ist nicht rückgängig zu machen (die Set-Preise können danach nur noch manuell geändert werden). Fortfahren?",toSetMn:'Diese Rechnung enthält kein Set. Legen Sie zuerst über "Set-Struktur bearbeiten" ein Set an bzw. ordnen Sie Positionen einem Set zu.',iSum:"Zwischensumme",dtRel:"Freigegeben am: ",dtCr:"Erstellt am: ",rqV:"USt des Auftrags?",cthd:"wirklich aus-/einblenden ?",cst:{style:"currency",currency:"EUR"},sts:{IsWorkDone:"Arbeiten erledigt",Closed:"Auftrag geschlossen",SubcontractorPendingConfirmation:"Warten auf Bestätigung (Unterauftrag)",Scheduled:"Geplant",OfferIsRejected:"Angebot abgelehnt",OfferIsSend:"Offen (Angebot versandt)",CollaborationWaitingConfirmation:"Warten auf Bestätigung (Zusammenarbeit)",Released:"Freigegeben",OfferIsConfirmed:"Bestätigt",InProgress:"In Bearbeitung",ReadyForScheduling:"Zur Planung",Created:"Erstellt",Rejected:"Abgebrochen",Invoiced:"Rechnung gestellt","-":"-"},invHR:["Pos.","Menge","Artikelbezeichnung","VK","Summe"],frm:{invoicetitle:"Titel",invoiceaddress:"Adresse",loc:"Leistungsort / Lieferadresse",invoiceemail:"Email",invoiceemailcc:"Zusatzempfänger (CC)",provisionperiod:"Leistungsdatum / -zeitraum"},frmTT:{invoicetitle:"Rechnungstitel ändern",invoiceaddress:"Rechnungsempfänger-Adresse ändern",loc:"Leistungsort oder Lieferadresse ändern",invoiceemail:"Email-Adresse ändern und zusätzliche Email-Empfänger festlegen",provisionperiod:"Leistungsdatum oder -zeitraum ändern"}},$rcol={req:new fields_definition("Auftrag","Aufträge",[{name:"tags",label:"",type:"string",dfnc:function(e,t){""!==(e||"")&&($(this).aC("tags"),e.split(",").forEach((e=>{""!==e&&$(this).append($$.sc("tag "+e.replace(" ","_").replace("/","_").toLowerCase(),e))})))}},{name:"DateOfCreation",label:"Datum",type:"date",title:function(e){$(this).attr("title",$rct.dtCr+fdt(e.DateOfCreation).ne("-")+" \n"+$rct.dtRel+fdt(e.DateReleased).ne("-"))}},{name:"CustomerName",label:"Kunde (Firma)",type:"string"},{name:"Name",label:"Auftragsname",type:"string"},{name:"ExternalId",label:"Auftragsnummer",type:"string"},{name:"ParentExtenalId",label:"PAuftrag",type:"string"},{name:"InvoiceId",label:"RNummer",type:"string",dfnc:function(e,t){$(this).rwText(e," ").find("span").each((function(){$(this).aC("cla").click({id:$(this).text()},$inv.jdbn)}))}},{name:"State",label:"Status",type:"string"},{name:"WorkDoneAt",label:"Erledigt am",type:"date"},{name:"Description",label:"Beschreibung",type:"html"}]),itm:new fields_definition("Auftragsposition","Auftragspositionen",[{name:"NameOrNumber",label:"Bezeichnung",type:"string"},{name:"Type",label:"Typ",type:"select",required:!0,value:"Text",url:[{value:"Text",label:"Text"},{value:"Equipment",label:"Ausrüstung"},{value:"Material",label:"Material"},{value:"Service",label:"Arbeitsleistung"}],change:function(e){$req.quantChange.call(this,e)}},{name:"quantityhours",label:"Anzahl / Menge",type:"number",precision:"0.01",value:1,change:function(e){$inv.quantChange.call(this,e)}},{name:"UnitString",label:"Einheit",type:"select",url:["LFDM","Stck","Std.","QM","AW","Pauschal"],change:function(e){$inv.quantChange.call(this,e)}},{name:"net",label:"EinzelPreis netto",type:"number",precision:"0.01",value:0,change:function(e){$inv.quantChange.call(this,e)}},{name:"net_val",label:"GesamtPreis netto",type:"number",precision:"0.01",value:0},{name:"vat_val",label:"GesamtPreis USt",type:"number",precision:"0.01",value:0},{name:"svcnet_val",label:"Arbeitslohn netto",type:"number",precision:"0.01",value:0},{name:"svcvat_val",label:"Arbeitslohn USt",type:"number",precision:"0.01",value:0},{name:"net_pos",label:"Netto",type:"string"},{name:"bo_pos",label:"Brutto",type:"string"},{name:"vat",label:"USt",type:"string",value:"19,0%",change:function(e){$inv.quantChange.call(this,e)}},{name:"Note",label:"Details",type:"html",tinymce:!0}])},$ict={mdl:"Rechnungen",iov:{all:"Rechnungen (alle)","":"Rechnungen (nur fertige)","#d":"Rechnungen (nur Entwürfe)","#u":"Rechnungen (nur unbezahlt)","#r":"Rechnungen (nur angemahnt)","#a":"Rechnungen (nur Akonto)","#c":"Rechnungen (nur Storno)","#ru":"Rechnungen (nur angemahnt + unbez.)"},uba:", gesamter Zeitraum)",req:"Auftrag",inv:"Rechnung",rem:"Mahnung",in:"Rechnungsnummer",cc:"Kunde",wk:"Woche",nd:"Keine Daten gefunden.",dl:"Herunterladen",ed:"Bearbeiten",ced:"Bearbeitung fortsetzen",sItm:"Einzelheiten anzeigen",sPay:"Zahlungen anzeigen",cdI:"Entwurf der Rechnung löschen?",rel:"Neu Laden",relm:"Bitte laden Sie Liste manuell neu, um die Änderungen zu sehen.",dsp:"Rechnung anzeigen",storno:"Storno-Rechnung erstellen",credit:"Gutschrift erstellen",remd:"Mahnung erstellen",remdt:"Mahnung erstellen zur Rechnung {0}",remlst:"Mahnungen anzeigen",remdsp:"Mahnung anzeigen",remres:"Mahnung erneut senden",remresc:"Mahnung {0} wirklich erneut senden?",remresr:"Mahnung {0} wurde erfolgreich versandt.",setpyd:"Bezahlt markieren",cpyd:"Rechnung wirklich als bezahlt markieren?",setupd:"Bezahlt-Markierung aufheben",cupd:"Bezahlt-Markierung wirklich aufheben?",ivE:"Die Email-Adresse ist vermutlich nicht gültig.",ivEc:"\nMöchten Sie fortfahren?",pna:"Diese Seite ist in der Vorschau nicht verfügbar",tpe:"Die Anzahl von {0} Seiten wird aktuell nicht unterstützt",eis:"Der Rechnungsentwurf konnte nicht gespeichert werden.",pvf:"Die PDF-Vorschau konnte nicht erstellt werden.",pvto:"Der Server hat nicht rechtzeitig geantwortet (Zeitüberschreitung). Bitte versuchen Sie es erneut.",pvgone:"Der Entwurf ist auf dem Server nicht mehr vorhanden (Sitzung abgelaufen). Bitte öffnen Sie den Entwurf erneut.",iss:"Zwischenstand speichern.",p13b:"USt -> §13b",setm:"Set-Preisanzeige",setmo:{setprice:"Set mit Preis – Positionen ohne Preis",setonly:"Nur Set mit Preis – Positionen ausgeblendet"},setst:"Set-Struktur bearbeiten",setsHint:'Reihenfolge: Zeile per Drag & Drop an den oberen/unteren Rand einer anderen Zeile ziehen (davor/danach) oder ▲▼ nutzen. Zuordnung: Zeile auf die Mitte eines Sets ziehen (hinein) bzw. auf die Auftragszeile oder "oberste Ebene" (aus dem Set lösen); ◀▶ ändert die Ebene. Sets lassen sich über das Dreieck zu-/aufklappen und auch zugeklappt verschieben – ihre Positionen wandern mit. Änderungen werden sofort übernommen.',setsUp:"Nach oben (innerhalb der Ebene)",setsDown:"Nach unten (innerhalb der Ebene)",setsCollapse:"Set zuklappen",setsExpand:"Set aufklappen",setsHR:["","Pos.","Typ","Menge","Bezeichnung","Reihenfolge / Ebene"],setsRoot:"Hierher ziehen = aus dem Set lösen (oberste Ebene)",setsOut:"Eine Ebene höher (aus dem Set lösen)",setsIn:"Eine Ebene tiefer (dem vorangehenden Set zuordnen)",setsNew:"Neu:",setsInto:"in",setsTop:"oberste Ebene",setsTitle:"Bezeichnung",setsAdd:"Hinzufügen",setsNoTitle:"(ohne Bezeichnung)",settyp:{set:"Set",text:"Text",title:"Text",material:"Material",service:"Arbeitsleistung",equipment:"Ausrüstung",other:"Position",osum:"Zusammenfassung",intinvoiceallocation:"Abschlag",intinvoiceallocationdiff:"Abschlag (offen)"},ctp:"Ansprechpartner festlegen",mfr:"Von MFR neu abrufen",rq1:"Auftragsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",rq2:"Auftragsdaten werden geladen",iq1:"Rechnungsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",iq2:"Rechnungsdaten werden geladen",sis:"Rechnung als versandt markieren",srs:"Mahnung als versandt markieren",sisc:"Rechnung wirklich als versandt markieren?",srsc:"Mahnung wirklich als versandt markieren?",iSt:{dft:"Entwurf",uns:"nicht versandt",pyd:"bezahlt",cc:"storniert",op:"offen",due:"fällig",ovd:"überfällig",rem:"angemahnt"},rSt:["","Überfällig","2. Mahnung","3. Stufe"],pSt:{a:"Vollst.",p:"Teilz."},ivT:{i:"AbschlagsR.",f:"SchlussR",r:"Rechnung",c:"StornoR."},rovlh:"Übersicht der bisherigen Mahnungen",rovl:["Betreff","Betrag","Betrag gezahlt","fertiggestellt am"],remHR:["Rechnung","vom","Rechnungsbetrag","bereits bezahlt","noch offen"],translatePaymentTerm:e=>(e||"").replace("wd"," Werktagen").replace("d"," Tagen").replace("wk"," Wochen")||"10 Tagen",payi:{account:"Konto",name:"Zahler",text:"Verw.Zweck",InvoiceID:"Rechnung",amount:"Betrag",date:"Datum",manual:"Typ"}},$invcol={datev:new fields_definition("Rechnung","Rechnungen",[{name:"Umsatz (ohne Soll/Haben-Kz)",label:"Umsatz (ohne Soll/Haben-Kz)",type:"string"},{name:"vf",label:"vf",type:"string"},{name:"Soll/Haben-Kennzeichen",label:"Soll/Haben-Kennzeichen",type:"string"},{name:"Konto",label:"Konto",type:"string"},{name:"Gegenkonto",label:"Gegenkonto",type:"string"},{name:"BU-Schlüssel",label:"BU-Schlüssel",type:"string"},{name:"Belegdatum",label:"Belegdatum",type:"string"},{name:"Belegfeld 1",label:"Belegfeld 1",type:"string"},{name:"Belegfeld 2",label:"Belegfeld 2",type:"string"},{name:"Buchungstext",label:"Buchungstext",type:"string"}]),inv:new fields_definition("Rechnung","Rechnungen",[{name:"invstatus",label:"Status",type:"select",url:$ict.iSt},{name:"balance",label:"Umsatz",type:"string",dtype:"currency"},{name:"CustomerName",label:"Kunde",type:"string"},{name:"InvoiceId",label:"RNummer",type:"string"},{name:"InvoiceType",label:"Typ",type:"select",url:$ict.ivT},{name:"request",label:"Auftrag",type:"string",dtype:"num"},{name:"vat",label:"MwSt",type:"string",dtype:"num"},{name:"deb_cred",label:"Soll/Haben",type:"string"},{name:"customer",label:"Konto",type:"string",dtype:"num"},{name:"contra_account",label:"Gegenkonto",type:"string",dtype:"num"},{name:"Belegdatum",label:"Belegdatum",type:"date"},{name:"reminderstatus",label:"MahnStatus",type:"select",url:$ict.rSt},{name:"reminder",label:"# Mahnungen",type:"integer"},{name:"Buchungstext",label:"Buchungstext",type:"string"},{name:"Payment",label:"Zahlung",type:"string"}]),rem:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"amount",label:"Rechnungsbetrag",type:"number",precision:"0.01",value:1},{name:"amount_payed",label:"bereits bezahlt",type:"number",precision:"0.01",value:1}]),rem2:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"DocumentName",label:"Name",type:"string"},{name:"subject",label:"Betreff",type:"string"},{name:"DateSent",label:"Versanddatum",type:"date"},{name:"status",label:"Status",type:"string"},{name:"amount_open",label:"offener Betrag",type:"number",precision:"0.01"},{name:"InvoiceId",label:"RNummer",type:"string"}]),rid:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"type",label:"Typ",type:"select",url:[["f","einfache Zahlungserinnerung"],["m","Mahnung"],["l","letzte Mahnung"]],required:!0},{name:"level",label:"Stufe",type:"select",url:[["1","Stufe 1"],["2","Stufe 2"],["3","Stufe 3"],["4","Stufe 4"],["5","Stufe 5"],["6","Stufe 6"]],required:!0}]),ctp:new fields_definition("Ansprechpartner","Ansprechpartner",[{name:"name",label:"Name",type:"string"},{name:"email",label:"Email",type:"string"}])},gi=(e,t)=>$$.sc("glyphicon glyphicon-"+e).aC(t),$inv={init2:function(e,t){e=e||"inv",t=t||{},$ocms.getScript([],(function(){$inv.init3(e,t)}))},init3:async function(e,t){$fis.cf(!0);let n=$fis.lf(!0);$("#topbar").ocmsmenu([]),$("#activemodule").text($ict.mdl);let i=[(async()=>{await $fis.getAuth("fds_inv")>0&&($inv.prepLst(""),n.aC("fix"))})(),new Promise(((e,t)=>{$fis.prepAuth(["fds_reminder"])}))];await Promise.all(i)},prepLst:function(e){let t=new Date,n=$fis.lf(!0).ldng(1),i=new Date("2021-01-01");$fis.frm_list().IN((function(){}));let a=[];$.each($ict.iov,((e,t)=>{a.push({lbl:t,fnc:()=>{$inv.prepLst(e),n.aC("fix")}})})),$fis.lfm().ocmsmenu([{lbl:"Filter",itm:a}]);$$.i({placeholder:$ict.in}).appendTo($$.dc("mth ivn",n)).enterKey((function(e){let t=$(this),n=t.val()||"";e.stopPropagation(),t.parent().siblings().rC("selected"),n.length>3&&(t.parent().aC("selected"),$inv.renderinv("i:"+n,"s","all"),t.val(""))})),$$.i({placeholder:$ict.cc}).appendTo($$.dc("mth ivc",n)).enterKey((function(e){let t=$(this),n=t.val()||"";e.stopPropagation(),t.parent().siblings().rC("selected"),n.length>=3&&(t.parent().aC("selected"),$inv.renderinv("c:"+n,"s","all"),t.val(""))}));"#"===e.substr(0,1)&&$$.dc("mth extra",n).text($ict.iov[e].replace(")",$ict.uba)).click((function(t){let n=$(this);if(t.stopPropagation(),n.siblings().rC("selected"),!0===n.is(".selected")){n.toggleClass("selected");let t=fdt(new Date,"yy-MM-dd");$inv.renderinv(t,"a",e)}n.aC("selected")})),n.append("");let r=$$.dc("mthl",n),s=t.getFullYear(),l=t.getMonth()+1;for(let t=i.getFullYear();t<=s;t++){let n=$$.dc("yr").prependTo(r).text($ict.iov[e]+" - "+t.toString()).toggleClass("selected",t===s);n.click({yr:t},(function(e){e.stopPropagation(),n.siblings().rC("selected"),n.aC("selected")}));let a=$$.dc("mfrm",n);for(let n=0;n<(t!==s?12:l);n++){i=new Date(t,n,1);let r=$$.dc("mth").prependTo(a).text($ict.iov[e]+" - "+fdt(i,"MMM yyyy"));if(r.click({yr:t,mt:n},(function(t){if(t.stopPropagation(),r.siblings().rC("selected"),!0===r.is(".selected")){r.toggleClass("selected");let n=fdt(new Date(t.data.yr,t.data.mt,1),"yy-MM-dd");$inv.renderinv(n,"m",e)}r.aC("selected")})),""===e){$$.dc("mthdl",r).append(gi("compressed","ico")).click({yr:t,mt:n},(function(e){e.stopPropagation();let t=fdt(new Date(e.data.yr,e.data.mt,1),"yy-MM-dd");$inv.downloadzip(t,"m")}))}let s=getMonday(i),l=new Date(i);l.setMonth(l.getMonth()+1),l.setDate(0),l=getMonday(l);let d=$$.dc("wfrm",r);for(;s<=l;){let t=$$.dc("wk",d).text(($ict.wk||"W")+" "+fdt(s,"dd.MM.yy"));t.click({rd:new Date(s)},(function(n){n.stopPropagation();let i=fdt(n.data.rd,"yy-MM-dd");$inv.renderinv(i,"w",e),r.siblings().rC("selected").find(".wk").rC("selected"),r.aC("selected").find(".wk").rC("selected"),t.aC("selected")})),$$.dc("wkdl",t).append(gi("compressed","ico")).click({rd:new Date(s)},(function(e){e.stopPropagation();let t=fdt(e.data.rd,"yy-MM-dd");$inv.downloadzip(t,"w")})),s.setDate(s.getDate()+7)}}}n.ldng(0)},rerenderinv:function(){let e=$("#contentframe .invfrm:first");if(e.length>0){let t=e.data("sets")||{};t.mode&&$inv.renderinv(t.tgt,t.mode,t.includes)}},renderinv:function(e,t,n){let i=$fis.frm_list(!0,!0).ldng(1),a=$$.dc("invfrm",i).aC("md"+t).data("sets",$.extend({},{tgt:e,mode:t,includes:n})),r=$fis.lf();$ocms.postXT({url:$ocms.url("inv/invl"),data:{mode:t,tgt:e,includes:n},success:i=>{r.rC("fix").aC("hd"),$$.dc("ovhd",a).text(i.admin.title);let s=$$.tblset({},a),l=$invcol.inv,d=$$.tr(s.hd);$$.th(d);$.each(l.fields||[],((e,t)=>{$$.th(d).text(t.label),"vat"===t.name&&$$.th(d)})),$.each(i.invoices||[],((d,c)=>{let o=$$.tr(s.bdy);o.click((function(){r.rC("fix").aC("hd"),o.toggleClass("selected").siblings().rC("selected").find("td.av").rC("av"),o.find("td.av").rC("av"),!0===o.is(".selected")?$inv.iMn(c):$inv.eM()}));let u=$$.td(o,{class:"raux"});c.hasFile?($$.dc("idl ilbtn",u,{title:$ict.dl+"\n"+c.DocumentName}).append(gi("save-file","ico")).click({id:c.Id},$inv.downloadinv),$$.dc("idl ilbtn",u,{title:$ict.dsp+"\n"+c.DocumentName}).append(gi("eye-open","ico")).click({id:c.Id,typ:"inv"},$inv.jdisp)):!1===c.isFinal&&!0===$fis.isAuth("fds_inv",2)&&$$.dc("idl ilbtn",u,{title:$ict.ed}).append(gi("edit","ico")).click({id:c.Id},$inv.doContInv),$$.dc("iitm ilbtn",u,{title:$ict.sItm}).append(gi("list","ico")).click({id:c.Id},$inv.showitm),$$.dc("iitm ilbtn",u,{title:$ict.sPay}).append(gi("euro","ico")).click({id:c.Id},$inv.showpay),$.each(l.fields||[],((r,s)=>{let l,d,u=$$.td(o).aC(s.dtype);switch("select"===(s.type||"")?u.text((s.url||{})[c[s.name]]||""):u.text(c[s.name]),s.name||""){case"vat":l=$$.sel().appendTo($$.td(o,{class:"vsel"})),d=(i.admin.ust_options||"19,0%;16,0%;0,0%").split(";"),$.each(d,((e,t)=>{$$.opt(t,t).appendTo(l)})),l.click((function(e){e.stopPropagation()})).val(c[s.name]).change().change({frm:a,tgt:e,mode:t,id:c.Id,td:u,includes:n},$inv.setvat),u.toggleClass("hl",c[s.name].substr(0,2)!==d[0].substr(0,2)).click((function(e){e.stopPropagation(),$(this).toggleClass("av")}));break;case"balance":u.aC("sh_"+(c.SollHaben||"").toLowerCase());break;case"invstatus":case"reminderstatus":u.aC(("invstatus"===s.name?"is_":"rs_")+c[s.name])}}))}))},complete:()=>{i.ldng(0)}})},setvat:function(e){let t=$(this),n=e.data||{};$ocms.postXT({url:$ocms.url("inv/setvat"),data:{id:n.id,val:t.val()},success:e=>{n.td.rC("av"),$inv.renderinv(n.tgt,n.mode,n.includes)}})},downloadzip:function(e,t){$(this).empty();window.open($ocms.url("inv/datevzip?mode="+t+"&tgt="+encodeURIComponent(e)),"_blank")},showitm:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&$ocms.postXT({url:$ocms.url("inv/rqi"),data:{id:e.data.id},success:e=>{let t=$$.dc("rfrm");(e.requests||[]).length<1?t.text($ict.nd):$.each(e.requests||[],(function(e,n){let i=$$.dc("srq",t);$$.dc("nme",i).text(n.name);let a=$$.tblset({class:"if"},i);$.each(n.items||[],((e,t)=>{let n=$$.tr({id:"itm"+t.Id}).appendTo(a.bdy);$$.td(n).text(t.NameOrNumber),$$.td(n).text(t.Type),$$.td(n).aC("currency").text(t.net_pos),$$.td(n).aC("currency").text(t.bo_pos),$$.td(n).aC("num").text(t.vat)}))})),$ocms.dlg(t,{width:1e3})}})},showpay:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&$ocms.postXT({url:$ocms.url("inv/pyi"),data:{id:e.data.id},success:e=>{let t=$$.dc("rfrm");if((e.payments||[]).length<1)t.text($ict.nd);else{let n=$$.tblset({class:"if"},t),i=$$.tr(n.hd);$.each(["date","account","name","text","InvoiceID","amount","manual"],((e,t)=>{$$.th(i,$ict.payi[t])})),$.each(e.payments,((e,t)=>{let i=$$.tr({id:"itm"+t.banking_uid}).appendTo(n.bdy);$$.td(i).aC("date").text(t.date),$$.td(i).text(t.account),$$.td(i).text(t.name),$$.td(i).text(t.text),$$.td(i).text(t.InvoiceID),$$.td(i).aC("currency").text(t.amount),$$.td(i).text(t.manual)}))}$ocms.dlg(t,{width:1e3,title:"Übersicht der Zahlungen"})}})},downloadinv:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&window.open($ocms.url("inv/rdoc?id="+e.data.id),"_blank")},doContInv:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&$inv.cntInv({id:e.data.id})}},$$inv={init2:$inv.init2,auth:{}};export default $$inv;$inv.cInv=function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&!1!==$fis.isAuth("fds_inv",2)&&$inv.cInv2({id:e.data.id})},$inv.rMn=e=>{let t=[{lbl:$ict.req,itm:[]}];return!0===bool(e,!1)&&!0===$fis.isAuth("fds_inv",2)&&Array.prototype.push.apply(t[0].itm,[{lbl:$rct.crI,fnc:$inv.ccInv,data:{typ:"r"}},{lbl:$rct.crII,fnc:$inv.ccInv,data:{typ:"i"}}]),t.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(t)},$inv.iMnr=e=>{let t=booln(e.isFinal,!0),n=e.Id,i=booln(e.fds,!1),a=[{glyph:"glyphicon-menu-left",fnc:()=>{$fis.frm_edit().remove()}},{lbl:$ict.inv,itm:[]},{lbl:$ict.rem,itm:[]}];return!1===t&&!0===$fis.isAuth("fds_inv",2)?a[1].itm.push({lbl:$ict.ced,fnc:$inv.clCntInv}):!0===$fis.isAuth("fds_inv",1)&&a[1].itm.push({lbl:$ict.dsp,fnc:()=>$inv.disp(n,"inv")}),!0===i&&!0===t&&!0===$fis.isAuth("fds_inv",2)&&(a[1].itm.push({lbl:$ict.storno,fnc:()=>$inv.storno(n,i)}),a[1].itm.push({lbl:$ict.credit,fnc:()=>$inv.credit(n,i)})),!0===t&&!0===$fis.isAuth("fds_reminder",2)&&(a[2].itm.push({lbl:$ict.remd,fnc:()=>$inv.ccRem(n,e.InvoiceId)}),a[2].itm.push({lbl:$ict.remlst,fnc:()=>$inv.dspRem(n)})),!0===t&&!0===$fis.isAuth("fds_reminder",2)&&!1===booln(e.IsSent,!1)&&a[2].itm.push({lbl:$ict.srs,fnc:()=>$inv.srs(n)}),a.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(a)},$inv.iMn=e=>{let t=booln(e.isFinal,!0),n=e.Id,i=booln(e.fds,!1),a=[{glyph:"glyphicon-menu-left",fnc:()=>{$fis.frm_edit().remove()}},{lbl:$ict.inv,itm:[]},{lbl:$ict.rem,itm:[]}];return!1===t&&!0===$fis.isAuth("fds_inv",2)?a[1].itm.push({lbl:$ict.ced,fnc:()=>{$inv.cntInv({id:n})}}):!0===$fis.isAuth("fds_inv",1)&&a[1].itm.push({lbl:$ict.dsp,fnc:()=>$inv.disp(n,"inv")}),!0===$fis.isAuth("fds_inv",2)&&(a[1].itm.push({lbl:$ict.storno,fnc:()=>$inv.storno(n,i)}),a[1].itm.push({lbl:$ict.credit,fnc:()=>$inv.credit(n,i)})),!0===t&&!1===booln(e.IsPayed,!1)?(!0===$fis.isAuth("fds_reminder",2)&&a[2].itm.push({lbl:$ict.remd,fnc:()=>$inv.ccRem(n,e.InvoiceId)}),!0===$fis.isAuth("fds_inv",2)&&a[1].itm.push({lbl:$ict.setpyd,fnc:()=>$inv.setPyd(n)})):!0===t&&!0===booln(e.IsPayed,!1)&&"m"===(e.PaymentStatus||"")&&!0===$fis.isAuth("fds_inv",2)&&a[1].itm.push({lbl:$ict.setupd,fnc:()=>$inv.setUpd(n)}),!0===$fis.isAuth("fds_reminder",2)&&a[2].itm.push({lbl:$ict.remlst,fnc:()=>$inv.dspRem(n)}),!0===t&&!0===$fis.isAuth("fds_inv",2)&&!1===booln(e.IsSent,!1)&&a[1].itm.push({lbl:$ict.sis,fnc:()=>$inv.sis(n)}),!1===i&&a[1].itm.push({lbl:$ict.mfr,fnc:()=>$inv.mfrrel(n)}),$("#topbar").ocmsmenu(a)},$inv.emOpt=()=>"iss,p13b,ctp,setst,setm",$inv.eM=(e,t,n)=>{let i=[];return!0!==booln(e,!1)&&!0!==booln(t,!1)||i.push({glyph:"glyphicon-menu-left",fnc:()=>{$fis.lf(!0),$fis.frm_edit().remove()}}),!0===(n||"").split(",").includes("iss")&&i.push({lbl:$ict.iss,fnc:$inv.ssave}),!0===(n||"").split(",").includes("ctp")&&i.push({lbl:$ict.ctp,fnc:$inv.sctp}),!0===(n||"").split(",").includes("p13b")&&i.push({lbl:$ict.p13b,fnc:$inv.sp13b}),!0===(n||"").split(",").includes("setm")&&i.push({lbl:$ict.setm,fnc:$inv.ssetmode}),!0===(n||"").split(",").includes("setst")&&i.push({lbl:$ict.setst,fnc:()=>$inv.sets.open()}),!0===(n||"").split(",").includes("iss")&&(i.push({lbl:"Änderungshistorie",fnc:()=>$inv.d.history()}),i.push({lbl:"Änderungen verwerfen",fnc:()=>$inv.d.discard()})),!0===booln(e,!1)&&i.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(i)},$inv.pdfPreviewTimeout=12e4,$inv.pdfPreviewFailed=function(e,t){if(11110===(e||{}).internalCode)return void $ocms.login.dlg();let n=((e||{}).internalText||"").trim();""===n&&"timeout"===t&&(n=$ict.pvto),""===n&&410===(e||{}).status&&(n=$ict.pvgone),alert(($ict.pvf||$t.f1)+(""!==n?"\n"+n:""))},$inv.pdfPreviewComplete=function(e){return(t,n)=>{e&&e.rC("freeze"),"timeout"===n&&$inv.pdfPreviewFailed(t,n)}},$inv.d={tbl:()=>$("div.invoice_layout table.invi"),layout:()=>$("div.invoice_layout"),token:function(){return $inv.d.tbl().data("dtoken")||""},hashes:function(){let e=$inv.d.tbl().data("bai")||[],t={};return $.each(e,((e,n)=>{t[(n.Id||"").toString()]=JSON.stringify(n)})),t},seed:function(e){let t=$inv.d.layout();t.aC("freeze");let n=$ocms.postXT({url:$ocms.url("inv/dopen"),data:{payload:JSON.stringify(e)},success:e=>{$inv.d.tbl().data("dtoken",e.token).data("dver",e.version).data("dhashes",$inv.d.hashes()).data("dorder",$inv.d.order()),$fis.draft.bind(e.token,{onReady:()=>$inv.d.refresh(),onExpiring:e=>$inv.d.warnExpiry(e),onClosed:e=>$inv.d.closed(e)}),$inv.d.refresh()},error:()=>{t.rC("freeze")},complete:()=>{$inv.d.tbl().removeData("dseeding").removeData("dseedpromise")}});return $inv.d.tbl().data("dseedpromise",n),n},refresh:function(e){let t=$inv.d.token();""!==t&&$ocms.postXT({url:$ocms.url("inv/dstate"),data:{token:t},success:t=>{$inv.d.applyState(t),"function"==typeof e&&e(t)},error:e=>{e&&410===e.status&&$inv.d.closed("expired")},complete:()=>{$inv.d.layout().rC("freeze")}})},applyState:function(e){let t=$inv.d.tbl();if(t.length<1)return;let n=t.data("dver");"number"==typeof n&&"number"==typeof e.version&&e.version$$.dc("dnote").aC(e.style||"InvoiceNotes").text(e.text)))},applyItems:function(e,t){let n=e=>void 0===e?null:e;(t||[]).forEach((t=>{if(!t)return;let i=(t.Id||"").toString();if(""===i)return;let a=e.children("tbody").filter(((e,t)=>(($(t).data()||{}).Id||"").toString()===i)).first();if(a.length<1)return;let r=t.itm||[],s={},l=a.find("tr.title").first(),d=l.length?l:null;r.forEach((e=>{let t=(e.id||"").toString();if(""===t)return;s[t]=!0;let i=a.find("#itm"+t).first(),r=i.length<1;r&&(i=$$.tr(a,{id:"itm"+t,class:"itm"}));let l=i.data()||{},c=r||(l.Type||"")!==(e.typ||"")||l.net!==n(e.v)||l.net_val!==n(e.vt)||l.vat_val!==n(e.vv)||l.svcnet_val!==n(e.vs)||l.svcvat_val!==n(e.vsv)||(l.position||"")!==(null!=e.p?e.p:"")||(l.lvl||0)!==(e.lvl||0)||(l.SetItmId||null)!==(null!=e.SetItmId?e.SetItmId:null);$.extend(l,{Id:t,Type:e.typ,net:n(e.v),net_val:n(e.vt),vat_val:n(e.vv),svcnet_val:n(e.vs),svcvat_val:n(e.vsv),vat:e.vat,position:null!=e.p?e.p:"",SetItmId:null!=e.SetItmId?e.SetItmId:null,lvl:e.lvl||0}),r&&$.extend(l,{htmltext:e.t,quantity:e.q}),i.data(l),d?i.prev()[0]!==d[0]&&i.insertAfter(d):a.children().first()[0]!==i[0]&&a.prepend(i),d=i,c&&$inv.rrw.call(i)})),a.find("tr.itm").each(((e,t)=>{let n=(($(t).data()||{}).Id||"").toString();""===n||s[n]||$(t).remove()}))}))},applySetDisplay:function(e,t){e.find("tr.itm").each(((e,n)=>{let i=$(n),a=((i.data()||{}).Id||"").toString();if(""===a||!Object.prototype.hasOwnProperty.call(t,a))return;let r=t[a]||{};i.tC("sethdr",bool(r.h,!1)),!1===bool(r.p,!0)&&i.find("td.currency").text("")}))},sync:function(e){let t=$inv.d.token();if(""===t){let t=$inv.d.tbl().data("dseedpromise");return t?$.when(t).then((()=>$inv.d.sync(e))):$.when()}return $inv.d.layout().aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dpatch"),data:{token:t,delta:JSON.stringify(e)},success:()=>{$inv.d.refresh()},error:e=>{$inv.d.layout().rC("freeze"),e&&410===e.status&&$inv.d.closed("expired")}})},order:function(){return($inv.d.tbl().data("bai")||[]).map((e=>(e.Id||"").toString()))},syncChanged:function(e){let t=e.data("bai")||[],n=e.data("dhashes")||{},i={},a=[],r=[],s=[];$.each(t,((e,t)=>{let r=(t.Id||"").toString(),s=JSON.stringify(t);i[r]=s,n[r]!==s&&a.push(t)})),$.each(n,(e=>{void 0===i[e]&&r.push(e)}));let l=$inv.d.order(),d=e.data("dorder")||[];return e.data("dhashes",i).data("dorder",l),a.forEach((e=>s.push($inv.d.sync({Target:"block.replace",Ref:(e.Id||"").toString(),Value:e})))),r.forEach((e=>s.push($inv.d.sync({Target:"block.remove",Ref:e})))),d.length===l.length&&d.slice().sort().join(",")===l.slice().sort().join(",")&&d.join(",")!==l.join(",")&&s.push($inv.d.sync({Target:"block.order",Value:l})),$.when.apply($,s).promise()},syncField:function(e,t){let n={invoicetitle:"title",invoiceaddress:"address",invoiceemail:"email",invoiceemailcc:"emailcc",loc:"provisionlocation",provisionlocation:"provisionlocation",provisionperiod:"provisionperiod"}[e];n&&$inv.d.sync({Target:n,Value:t})},footer:function(e,t,n){let i=e.children("tfoot").empty();e.nextAll(".fnote").remove();let a=bool(n.p13b,!1),r=(e,t,n)=>$$.tdc("currency",$$.tr(i,{class:n||"tsum"}).append([$$.tdc("aux"),$$.td({colspan:4}).text(e)]),fnum(t,$rct.cst)),s=t=>$$.dc("fnote").insertAfter(e).rwText(t);r("Netto",t.total_net||0),!1===a&&$.each(t.vat||{},((e,t)=>r($rct.vat+" "+e+"%",t,"tvat"))),r("Summe",t.total_gross||0);let l=n.type||"";"i"===l?(s($rct.note2),s($rct.note4)):"c"===l?s($rct.note2):(s(string($rct.note3,[fnum(((t.service_net||0)+(t.service_vat||0))*(n.tax_servicerefund||0),$rct.cst)])).aC("ntax"),s($rct.note2),s(string($rct.note1,[fnum((t.service_net||0)+(t.service_vat||0),$rct.cst),fnum(t.service_net||0,$rct.cst),fnum(t.service_vat||0,$rct.cst)]))),!0===a&&s($rct.note13b)},validation:function(e){let t=$("div.invoice_layout");if(t.length<1)return;let n=t.children(".dvalidation");n.length<1&&(n=$$.dc("dvalidation"),t.prepend(n)),n.empty().tC("hidden",(e||[]).length<1),$.each(e||[],((e,t)=>$$.dc("dvmsg",n).aC(t.severity).text(t.message)))},preview:function(){let e=$inv.d.token();if(""===e)return;let t=$inv.d.layout(),n=($inv.d.tbl().data("new")||{}).invoiceemail||"";!1===$fis.ValidateEmail(n)&&!1===bool(confirm($ict.ivE+$ict.ivEc),!1)||(t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dpreview"),data:{token:e},timeout:$inv.pdfPreviewTimeout,success:n=>{t.rC("freeze");let i=$$.dc("imagecollection pdfpreview"),a=Math.round(.88*vh()),r=n.total;r>10&&$$.dc("note warn",i).text($ict.tpe),$.each(n.img||[],((e,t)=>{$$.dc("pdfp",i).append($$.img(t).css("max-height",(a-rpx(6)).toString()+"px"))}));for(let e=(n.img||[]).length+1;e<=r;e++)$$.dc("pdfp ph",i).append($$.dc("note",$ict.pna));$ocms.dlg(i,{size:[a,Math.round(.88*vw())],zindex:50,form:!1,button:$rct.crI,confirm:function(n){let i=$(this);t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dsave"),data:{token:e},success:e=>{$ocms.postXT({url:$ocms.url("req/sconf"),data:{id:e.invid},success:t=>{i.trigger("modal_close"),!0===t.hasFile&&window.open($ocms.url("req/idoc")+"?id="+e.invid,"_blank"),$inv.d.close(),$ocms.init("req"),$inv.rReload()},error:()=>{alert($t.f1),i.trigger("modal_close")},complete:()=>{t.rC("freeze")}})},error:()=>{t.rC("freeze"),alert($ict.eis)}})},cancel:function(e){confirm($ict.cdI)&&($inv.d.close(),$inv.rReload())}})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(t)}))},save:function(){let e=$inv.d.token();if(""===e)return;let t=$inv.d.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dsave"),data:{token:e},success:e=>{$inv.d.tbl().data("invid",e.invid)},error:()=>{alert($ict.eis)},complete:()=>{t.rC("freeze")}})},history:function(){let e=$inv.d.token();""!==e&&$ocms.postXT({url:$ocms.url("inv/dhistory"),data:{token:e},success:e=>{let t=$$.dc("dhist");if((e.history||[]).length<1)$$.dc("note",t).text("Noch keine Änderungen erfasst.");else{let n=$$.tblset({class:"invtbl fullwidth"},t);$$.tr(n.hd).append([$$.th().text("Zeit"),$$.th().text("Feld"),$$.th().text("Alt"),$$.th().text("Neu")]),$.each(e.history,((e,t)=>$$.tr(n.bdy).append([$$.tdc("keep",fdt(t.timestamp)),$$.td().text(t.target),$$.td().text(t.oldValue),$$.td().text(t.newValue)])))}$ocms.dlg(t,{width:800,form:!1})}})},discard:function(){let e=$inv.d.tbl().data("invid")||"";""!==e?!1!==confirm("Alle Änderungen verwerfen und den zuletzt gespeicherten Stand neu laden?")&&($inv.d.close(),$inv.cntInv({id:e})):alert("Es wurde noch kein Zwischenstand gespeichert, der wiederhergestellt werden könnte.")},warnExpiry:function(e){let t=Math.max(1,Math.round((e||0)/60));$fis.notifications.push({severity:"info",title:"Entwurf läuft ab",message:"Der Rechnungsentwurf läuft in etwa "+t+" Minute(n) ab. Bitte zwischenspeichern, sonst gehen die Änderungen verloren."})},closed:function(e){let t=$inv.d.token();$inv.d.tbl().removeData("dtoken"),""!==t&&$fis.draft.release(t),$fis.frm_edit().remove(),$fis.lf(!0),$fis.notifications.push({severity:"error",title:"Entwurf geschlossen",message:"expired"===e?"Der Rechnungsentwurf ist wegen Inaktivität abgelaufen. Nicht gespeicherte Änderungen sind verloren.":"Der Rechnungsentwurf wurde geschlossen."});try{$inv.rReload()}catch(e){}},close:function(){let e=$inv.d.token();""!==e&&($ocms.postXT({url:$ocms.url("inv/dclose"),data:{token:e}}),$fis.draft.release(e)),$inv.d.tbl().removeData("dtoken")}},$inv.rd={tbl:()=>$("div.invoice_layout table.invi"),layout:()=>$("div.invoice_layout"),token:function(){return $inv.rd.tbl().data("rdtoken")||""},seed:function(e){let t=$inv.rd.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dopen"),data:{payload:JSON.stringify(e)},success:e=>{$inv.rd.tbl().data("rdtoken",e.token).data("rdver",e.version),$fis.draft.bind(e.token,{onReady:()=>$inv.rd.refresh(),onExpiring:e=>$inv.rd.warnExpiry(e),onClosed:e=>$inv.rd.closed(e)}),$inv.rd.refresh()},error:()=>{t.rC("freeze")}})},refresh:function(e){let t=$inv.rd.token();""!==t&&$ocms.postXT({url:$ocms.url("rem/dstate"),data:{token:t},success:t=>{$inv.rd.applyState(t),"function"==typeof e&&e(t)},error:e=>{e&&410===e.status&&$inv.rd.closed("expired")},complete:()=>{$inv.rd.layout().rC("freeze")}})},applyState:function(e){let t=$inv.rd.tbl();if(t.length<1)return;let n=t.data("rdver");"number"==typeof n&&"number"==typeof e.version&&e.version{let t=$$[0]("p").aC("dnote intro").rwText(e);a.length?t.insertBefore(a):t.appendTo(n)})),((e||{}).closing||[]).forEach((e=>$$[0]("p").aC("dnote closing").rwText(e).appendTo(n)))},sync:function(e){let t=$inv.rd.token();""!==t&&($inv.rd.layout().aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dpatch"),data:{token:t,delta:JSON.stringify(e)},success:()=>{$inv.rd.refresh()},error:e=>{$inv.rd.layout().rC("freeze"),e&&410===e.status&&$inv.rd.closed("expired")}}))},syncField:function(e,t){if(""===$inv.rd.token())return;let n={subject:"subject",invoiceaddress:"address",invoiceemail:"email",text:"text"}[e];n&&$inv.rd.sync({Target:n,Value:t})},syncAmount:function(e,t){""!==$inv.rd.token()&&($inv.rd.sync({Target:"amount",Value:(null!=e?e:0).toString()}),$inv.rd.sync({Target:"amount_payed",Value:(null!=t?t:0).toString()}))},footer:function(e,t){let n=e.children("tfoot").empty(),i=$$.tr(n,{class:"tsum"}).append([$$.tdc("aux"),$$.td({colspan:4}).text("Offener Betrag")]);$$.tdc("currency",i,fnum(t.amount_open||0,$rct.cst))},validation:function(e){let t=$inv.rd.layout();if(t.length<1)return;let n=t.children(".dvalidation");n.length<1&&(n=$$.dc("dvalidation"),t.prepend(n)),n.empty().tC("hidden",(e||[]).length<1),$.each(e||[],((e,t)=>$$.dc("dvmsg",n).aC(t.severity).text(t.message)))},preview:function(){let e=$inv.rd.token();if(""===e)return;let t=$inv.rd.layout(),n=($inv.rd.tbl().data("new")||{}).invoiceemail||"";!1===$fis.ValidateEmail(n)&&!1===bool(confirm($ict.ivE+$ict.ivEc),!1)||(t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dpreview"),data:{token:e},timeout:$inv.pdfPreviewTimeout,success:n=>{t.rC("freeze");let i=$$.dc("imagecollection pdfpreview"),a=Math.round(.88*vh());$.each(n.img||[],((e,t)=>{$$.dc("pdfp",i).append($$.img(t).css("max-height",(a-rpx(6)).toString()+"px"))})),$ocms.dlg(i,{size:[a,Math.round(.88*vw())],zindex:50,form:!1,button:$ict.remd,confirm:function(n){let i=$(this);t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dsave"),data:{token:e},success:e=>{$ocms.postXT({url:$ocms.url("rem/conf"),data:{id:e.remid},success:()=>{i.trigger("modal_close"),window.open($ocms.url("rem/idoc")+"?id="+e.remid,"_blank"),$inv.rd.close(),$ocms.init("req"),$inv.rReload()},error:()=>{alert($t.f1),i.trigger("modal_close")},complete:()=>{t.rC("freeze")}})},error:()=>{t.rC("freeze"),alert($t.f1)}})},cancel:function(e){confirm($ict.cdI)&&($inv.rd.close(),$inv.rReload())}})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(t)}))},save:function(){let e=$inv.rd.token();if(""===e)return;let t=$inv.rd.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dsave"),data:{token:e},success:e=>{$inv.rd.tbl().data("remid",e.remid)},error:()=>{alert($t.f1)},complete:()=>{t.rC("freeze")}})},history:function(){let e=$inv.rd.token();""!==e&&$ocms.postXT({url:$ocms.url("rem/dhistory"),data:{token:e},success:e=>{let t=$$.dc("dhist");if((e.history||[]).length<1)$$.dc("note",t).text("Noch keine Änderungen erfasst.");else{let n=$$.tblset({class:"invtbl fullwidth"},t);$$.tr(n.hd).append([$$.th().text("Zeit"),$$.th().text("Feld"),$$.th().text("Alt"),$$.th().text("Neu")]),$.each(e.history,((e,t)=>$$.tr(n.bdy).append([$$.tdc("keep",fdt(t.timestamp)),$$.td().text(t.target),$$.td().text(t.oldValue),$$.td().text(t.newValue)])))}$ocms.dlg(t,{width:800,form:!1})}})},warnExpiry:function(e){let t=Math.max(1,Math.round((e||0)/60));$fis.notifications.push({severity:"info",title:"Entwurf läuft ab",message:"Der Mahnentwurf läuft in etwa "+t+" Minute(n) ab. Bitte zwischenspeichern, sonst gehen die Änderungen verloren."})},closed:function(e){let t=$inv.rd.token();$inv.rd.tbl().removeData("rdtoken"),""!==t&&$fis.draft.release(t),$fis.frm_edit().remove(),$fis.lf(!0),$fis.notifications.push({severity:"error",title:"Entwurf geschlossen",message:"expired"===e?"Der Mahnentwurf ist wegen Inaktivität abgelaufen. Nicht gespeicherte Änderungen sind verloren.":"Der Mahnentwurf wurde geschlossen."});try{$inv.rReload()}catch(e){}},close:function(){let e=$inv.rd.token();""!==e&&($ocms.postXT({url:$ocms.url("rem/dclose"),data:{token:e}}),$fis.draft.release(e)),$inv.rd.tbl().removeData("rdtoken")}},$inv.cInv2=function(e){let t=$$.dc("rfrm").ldng(1),n=$ocms.dlg(t,{width:1e3});n&&n.ft.rwText($rct.rq1);let i=()=>{$ocms.postXT({url:$ocms.url("req/get"),timeout:60,data:{id:e.id,mode:"r"},success:t=>{t.admin=t.admin||{};let n=$fis.lf(!0).aC("fix").rC("hd");if($fis.frm_edit().IN(),$inv.eM(!0,!0),(t.requests||[]).length<1)n.aC("fix").text($rct.nd);else{$$.dc("lh",n,$rct.mdl);let i=$$.d(),a=$$.ul({class:"rql"}).data({search:e.id,parent:t.admin.parent}).appendTo(n),r={},s=$rcol.req.lbl();$.each(t.requests||[],(function(e,t){let n=$$.li({class:"cli rli"}).data($.extend({},t)).appendTo(a),l=$$.dc("lihd",n).addClass(t.state);!0===booln(t.open,!1)&&l.append($$.sc("cbox").click((()=>{n.tC("checked"),i.find("li").rC("checked"),!0===n.is(".checked")?$inv.rMn(t.open):$inv.eM(!0)}))),l.append([$$.sc("eid",t.ExternalId),$$.sc("nme",t.Name)]),$$.dc("lidt",n).append([$$.dc("rqs").append([$$.s(s.State+": "),$$.s($rct.sts[t.State||"-"])]),$$.dc("ivn").append([$$.s(s.InvoiceId+": "),$$.s(t.InvoiceId||"- -")]),$$.dc("wda").append([$$.s(s.WorkDoneAt+": "),$$.s(fdt(t.WorkDoneAt,"dd.MM.yyyy"))])]),r[t.Id]=n})),(t.inv||[]).length>0&&($$.dc("lh",n,$rct.invs),i=$$.ul({class:"ivl"}).appendTo(n),$.each(t.inv||[],((e,t)=>{let n=$$.li({class:"cli ili"}).data($.extend({},t)).appendTo(i),r=$$.dc("lihd",n).addClass(t.invstatus);!1===booln(t.isFinal,!0)?r.append($$.sc("cbox").click((()=>{""!==(t.Id||"")&&(n.tC("checked").siblings().rC("checked"),a.find("li").rC("checked"),!0===n.is(".checked")?$inv.iMnr(t):$inv.eM(!0))}))):["","dft"].indexOf(t.invstatus)<0&&r.append($$.sc("dli").click((function(){$inv.disp(t.Id,"inv")}))),r.append($$.sc("nme",t.DocumentName||t.Id)),$$.dc("lidt",n).append([$$.dc("wda").append([$$.s(fdt(t.DateCreated,"dd.MM.yyyy"))]),$$.d().text($ict.iSt[t.invstatus]||t.invstatus)])})))}},complete:()=>{n&&n.c.trigger("modal_close")}})};$ocms.postXT({url:$ocms.url("req/pget"),timeout:90,data:{id:e.id},success:e=>{n&&n.ft.rwText($rct.rq2),i()},error:()=>{confirm($rct.rq1f)?(n&&n.ft.rwText($rct.rq2),i()):n&&n.c.trigger("modal_close")}})},$inv.ccInv=function(e){let t=(e.data||{}).typ||"r",n=$fis.lf(),i=n.children("ul.rql"),a=i.data("parent"),r=[];if(i.find("li.rli.checked").each((function(){r.push($(this).data("Id"))})),r.length<1)return void alert($rct.dnS);if("i"===t&&r.length>1)return void alert($rct.dII);let s=$fis.frm_edit(),l=$$.dc("invoice_layout",s).append($$.dc("btn sprev").click($inv.sprev)),d=$fis.cf().width()>l.width()+n.width()+20;n.tC("fix",d).tC("hd",!d),$inv.eM(!1,!0);let c=$$.dc("rfrm").ldng(1),o=$ocms.dlg(c,{width:1e3});o.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("req/iget"),timeout:60,data:{id:a,mode:"ful",typ:t,sel:r.join(",")},success:e=>{let t=$$.dc("srq",l),n=$$.tblset({class:"invi"},t);n.bdy.remove(),n.ft=$$[0]("tfoot"),e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b")),n.tbl.data($.extend({new:{},sms:{},itm:{}},{admin:e.admin,companies:e.companies,locations:e.locations}));let i=$$.tr(n.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(i,e))),n.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.requests||[],(function(t,i){if(0!==(i.Id||0)){let t=$inv.worknotes(i);i.text="i"===e.admin.type?$rct.req+jine([i.ExternalId,i.Name],": ").eine(" ",""):jine([jine([fdt(i.WorkDoneAt,"dd.MM.yy"),i.ExternalId]," - "+$rct.req+" "),t.ne(i.Name)],": \n");let a=$$.tbody(n.tbl).data($.extend({},i));$inv.rendersrq.call(a)}}));let a=$$.tr($$.tbody(n.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(a),n.ft.appendTo(n.tbl);let r,s,d=e.admin||{},c=(e,t,i,a,r)=>{let s=$$.dc("inpfrm",l).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",s).rwText(t);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{n.tbl.data("new")[i]=e}},r),$inv.eHtml)),n.tbl.data("new")[i]=t};c("tfrm",d.invoicetitle,"invoicetitle",0,null),c("adrfrm",d.invoiceaddress,"invoiceaddress",0,null),c("locfrm","","loc",1,{list:deepCopy(e.locations),lbl:"ref",property:"address"}),$inv.emailFrm(l,n,d.invoiceemail,d.invoiceemailcc),$$.dc("sndfrm",l).append($$.dc("content").text(d.sender)),d.provisionend&&(s=d.provisionstart?$rct.provP:$rct.provD,r=d.provisionstart?fdt(d.provisionstart,"dd.MM.yyyy")+" - "+fdt(d.provisionend,"dd.MM.yyyy"):fdt(d.provisionend,"dd.MM.yyyy")),c("admfrm",r,"provisionperiod",s,1),n.tbl.data("new").CustomValues=d.CustomValues||"",$$.dc("inpfrm ctpfrm",l).text(jObj(d.CustomValues,"contactName")),n.tbl.children("tbody").each($inv.bdysort),n.tbl.trigger("fds.inv"),$inv.eM(!1,!0,$inv.emOpt())},complete:()=>{o.c.trigger("modal_close")}})},$inv.ccStInv=function(e){let t=e.data||{},n=$fis.lf(),i=t.id,a=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sprev)),r=$fis.cf().width()>a.width()+n.width()+20;n.tC("fix",r).tC("hd",!r),$inv.eM(!1,!0);let s=$$.dc("rfrm").ldng(1),l=$ocms.dlg(s,{width:1e3});l.ft.rwText($ict.iq1),$ocms.postXT({url:$ocms.url("inv/pget"),timeout:90,data:{id:t.id},success:e=>{l&&l.ft.rwText($ict.iq2),$ocms.postXT({url:$ocms.url("inv/icget"),timeout:60,data:{id:i},success:e=>{let t=$$.dc("srq",a),n=$$.tblset({class:"invi"},t);n.bdy.remove(),n.ft=$$[0]("tfoot"),e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b")),n.tbl.data($.extend({new:{},sms:{},itm:{}},{admin:e.admin,companies:e.companies,locations:e.locations}));let i=$$.tr(n.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(i,e))),n.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.requests||[],(function(t,i){if(0!==(i.Id||0)){let t=$inv.worknotes(i);i.text="i"===e.admin.type?$rct.req+jine([i.ExternalId,i.Name],": ").eine(" ",""):jine([fdt(i.WorkDoneAt,"dd.MM.yy")+t.ne(i.Name)],": ");let a=$$.tbody(n.tbl).data($.extend({},i));$inv.rendersrq.call(a)}}));let r=$$.tr($$.tbody(n.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(r),n.ft.appendTo(n.tbl);let s,l,d=e.admin||{},c=(e,t,i,r,s)=>{let l=$$.dc("inpfrm",a).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(t);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{n.tbl.data("new")[i]=e}},s),$inv.eHtml)),n.tbl.data("new")[i]=t};c("tfrm",d.invoicetitle,"invoicetitle",0,null),c("adrfrm",d.invoiceaddress,"invoiceaddress",0,null),c("locfrm",d.provisionlocation,"loc",1,{list:deepCopy(e.locations),lbl:"ref",property:"address"}),$inv.emailFrm(a,n,d.invoiceemail,d.invoiceemailcc),$$.dc("sndfrm",a).append($$.dc("content").text(d.sender)),d.provisionend&&(l=d.provisionstart?$rct.provP:$rct.provD,s=d.provisionstart?fdt(d.provisionstart,"dd.MM.yyyy")+" - "+fdt(d.provisionend,"dd.MM.yyyy"):fdt(d.provisionend,"dd.MM.yyyy")),c("admfrm",s,"provisionperiod",l,1),n.tbl.data("new").CustomValues=d.CustomValues||"",$$.dc("inpfrm ctpfrm",a).text(jObj(d.CustomValues,"contactName")),n.tbl.children("tbody").each($inv.bdysort),n.tbl.trigger("fds.inv")},complete:()=>{l.c.trigger("modal_close")}})},error:()=>{l&&l.c.trigger("modal_close")}})},$inv.clCntInv=function(e){let t=$fis.lf(!1),n=[];t.find("li.ili.checked").each((function(){n.push($(this).data("Id"))})),1===n.length&&$inv.cntInv({id:n[0]})},$inv.cntInv=function(e){e=e||{};$fis.lf(!1).rC("fix").aC("hd");let t=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sedit));$inv.eM(!1,!0);let n=$$.dc("rfrm").ldng(1),i=$ocms.dlg(n,{width:1e3});i.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("inv/get"),timeout:60,data:{id:e.id},success:e=>{e.admin=e.admin||{};let n=e.inv||{},i=$$.dc("srq",t),a=$$.tblset({class:"invi"},i);a.bdy.remove(),a.ft=$$[0]("tfoot"),a.tbl.data($.extend({invid:n.Id,new:{},sms:{},itm:{},bai:[]},e));let r=$$.tr(a.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(r,e))),a.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.req||[],(function(e,t){let n=$$.tbody(a.tbl).data($.extend({},t));$inv.rendersrq.call(n)}));let s=$$.tr($$.tbody(a.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(s),a.ft.appendTo(a.tbl);let l=(e,n,i,r,s)=>{let l=$$.dc("inpfrm",t).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(n);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{a.tbl.data("new")[i]=e}},s),$inv.eHtml)),a.tbl.data("new")[i]=n};l("tfrm",n.InvoiceTitle,"invoicetitle",0,null),l("adrfrm",n.SendToAddress,"invoiceaddress",0,null),l("locfrm",n.ProvisionLocation,"loc",1,null),$inv.emailFrm(t,a,n.SendToEmail,n.SendToEmailCc),$$.dc("sndfrm",t).append($$.dc("content").text(e.admin.sender)),l("admfrm",n.ProvisionPeriod,"provisionperiod",!0===(n.ProvisionPeriod||"").includes("-")?$rct.provP:$rct.provD,1),a.tbl.data("new").CustomValues=n.CustomValues||"",$$.dc("inpfrm ctpfrm",t).text(jObj(n.CustomValues,"contactName")),a.tbl.children("tbody").each($inv.bdysort),a.tbl.trigger("fds.inv"),$inv.eM(!1,!0,$inv.emOpt())},complete:()=>{i.c.trigger("modal_close")}})},$inv.cSt=function(e){e=e||{};let t=$fis.lf(),n=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sedit)),i=$fis.cf().width()>n.width()+t.width()+20;t.tC("fix",i).tC("hd",!i),$inv.eM(!1,!0);let a=$$.dc("rfrm").ldng(1),r=$ocms.dlg(a,{width:1e3});r.ft.rwText($ict.iq1),$ocms.postXT({url:$ocms.url("inv/pget"),data:{id:e.id},success:t=>{r&&r.ft.rwText($ict.iq2),$ocms.postXT({url:$ocms.url("inv/storno"),data:{id:e.id,mode:e.mode},success:e=>{e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b"));let t=e.inv||{},i=$$.dc("srq",n),a=$$.tblset({class:"invi"},i);a.bdy.remove(),a.ft=$$[0]("tfoot"),a.tbl.data($.extend({invid:t.Id,new:{},sms:{},itm:{},bai:[]},e));let r=$$.tr(a.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(r,e))),a.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.req||[],(function(e,t){let n=$$.tbody(a.tbl).data($.extend({},t));$inv.rendersrq.call(n)}));let s=$$.tr($$.tbody(a.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(s),a.ft.appendTo(a.tbl);let l=(e,t,i,r,s)=>{let l=$$.dc("inpfrm",n).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(t);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{a.tbl.data("new")[i]=e}},s),$inv.eHtml)),a.tbl.data("new")[i]=t};l("tfrm",t.InvoiceTitle,"invoicetitle",0,null),l("adrfrm",t.SendToAddress,"invoiceaddress",0,null),l("locfrm",t.ProvisionLocation,"loc",1,null),$inv.emailFrm(n,a,t.SendToEmail,t.SendToEmailCc),$$.dc("sndfrm",n).append($$.dc("content").text(e.admin.sender)),l("admfrm",t.ProvisionPeriod,"provisionperiod",!0===(t.ProvisionPeriod||"").includes("-")?$rct.provP:$rct.provD,1),a.tbl.data("new").CustomValues=t.CustomValues||"",$$.dc("inpfrm ctpfrm",n).text(jObj(t.CustomValues,"contactName")),a.tbl.children("tbody").each($inv.bdysort),a.tbl.trigger("fds.inv")},complete:()=>{r.c.trigger("modal_close")}})},error:()=>{r&&r.c.trigger("modal_close")}})},$inv.adrCountries=[["DE","Deutschland"],["AT","Österreich"],["CH","Schweiz"],["FR","Frankreich"],["NL","Niederlande"],["BE","Belgien"],["LU","Luxemburg"],["IT","Italien"],["ES","Spanien"],["PL","Polen"],["DK","Dänemark"],["CZ","Tschechien"],["GB","Großbritannien"],["US","USA"]],$inv.composeAddress=function(e){let t=[],n=e=>{""!==(e=(""+(e||"")).trim())&&t.push(e)};n((e=e||{}).name),""!==(""+(e.contact||"")).trim()&&n("z.Hd. "+(""+e.contact).trim()),n(e.line2||e.addressLine2),n(e.street),n(((e.postalCode||"")+" "+(e.city||"")).trim());let i=(""+(e.countryCode||"")).toUpperCase();return""!==i&&"DE"!==i&&n(i),t.join("\n")},$inv.adrCurrent=function(e){let t=jObj((e.data("new")||{}).CustomValues,"sendToAddress");if("string"==typeof t&&"{"===t.trim().charAt(0))try{t=JSON.parse(t)}catch(e){t=null}if(t&&"object"==typeof t)return t;let n=(e.data("admin")||{}).invoiceaddressData;if("string"==typeof n&&"{"===n.trim().charAt(0))try{return JSON.parse(n)}catch(e){}else if(n&&"object"==typeof n)return n;return{}},$inv.eAddress=function(e){let t=$inv.d.tbl(),n=$inv.adrCurrent(t),i=[{name:"name",label:"Name / Firma",type:"text",value:n.name||"",required:!0},{name:"contact",label:"z.Hd. (optional)",type:"text",value:n.contact||""},{name:"street",label:"Straße + Nr.",type:"text",value:n.street||""},{name:"line2",label:"Adresszusatz (optional)",type:"text",value:n.line2||n.addressLine2||""},{name:"postalCode",label:"PLZ",type:"text",value:n.postalCode||""},{name:"city",label:"Ort",type:"text",value:n.city||""},{name:"countryCode",label:"Land",type:"select",url:$inv.adrCountries,value:n.countryCode||"DE"},{name:"vatId",label:"USt-IdNr. (nur bei Firmen)",type:"text",value:n.vatId||""},{name:"leitwegId",label:"Leitweg-ID (nur Behörden / B2G)",type:"text",value:n.leitwegId||""}],a=$$.dc("adr-conformity").append([$$.dc("hd").text("Hinweis zur DATEV-/eRechnungs-Konformität"),$$.dc("tx").text("Pflicht: Name, Straße, PLZ, Ort und Land. Die USt-IdNr. nur bei Firmen angeben — für eine Rechnung an eine Privatperson einfach leer lassen. Eine Leitweg-ID nur bei Behörden (B2G) — dann wird die Rechnung automatisch als XRechnung erzeugt.")]);$ocms.dlgform(i,{title:"Rechnungsempfänger",addcontent:a,success:function(t){let n={name:t.name||"",contact:t.contact||"",line2:t.line2||"",street:t.street||"",postalCode:t.postalCode||"",city:t.city||"",countryCode:t.countryCode||"DE",vatId:(""+(t.vatId||"")).trim(),leitwegId:(""+(t.leitwegId||"")).trim()},i=$inv.composeAddress(n);e.data&&e.data.t&&e.data.t.rwText(i),"function"==typeof(e.data||{}).change&&e.data.change(i),$inv.d.sync({Target:"address",Value:n})}})},$inv.provToIso=function(e){let t=(""+(e||"")).match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);return t?t[3]+"-"+("0"+t[2]).slice(-2)+"-"+("0"+t[1]).slice(-2):""},$inv.eProvisionPeriod=function(e){let t=(""+(e.data&&e.data.t?e.data.t.text():"")).trim().match(/\d{1,2}\.\d{1,2}\.\d{4}/g)||[],n=[{name:"von",label:"Leistungsdatum",type:"date",value:$inv.provToIso(t[0]||"")},{name:"bis",label:"Leistungszeitraum – bis (optional)",type:"date",value:$inv.provToIso(t[1]||"")}],i=$$.dc("adr-conformity").append([$$.dc("hd").text("Leistungsdatum / -zeitraum"),$$.dc("tx").text('Für ein einzelnes Datum nur „Leistungsdatum" ausfüllen; für einen Zeitraum zusätzlich das Bis-Datum. Nur strukturierte Datumsauswahl — für die E-Rechnung empfohlen.')]);$ocms.dlgform(n,{title:"Leistungsdatum / -zeitraum",addcontent:i,success:function(t){let n=(""+(t.von||"")).trim(),i=(""+(t.bis||"")).trim(),a=""===n?"":""===i||i===n?n:n+" - "+i;e.data&&e.data.t&&e.data.t.rwText(a),"function"==typeof(e.data||{}).change&&e.data.change(a),$inv.d.sync({Target:"provisionperiod",Value:a})}})},$inv.eEmail=function(e){let t=[{name:"email",label:$rct.frm.invoiceemail,type:"text",value:(e.data.t||$$.s()).text()},{name:"emailcc",label:$rct.frm.invoiceemailcc,type:"text",value:(e.data.ccT||$$.s()).text()}];$ocms.dlgform(t,{title:$rct.frm.invoiceemail,success:function(t){let n=(""+(t.email||"")).trim(),i=(""+(t.emailcc||"")).trim();e.data&&e.data.t&&e.data.t.text(n),e.data&&e.data.ccT&&e.data.ccT.text(i),"function"==typeof(e.data||{}).change&&e.data.change(n),"function"==typeof(e.data||{}).changeCc&&e.data.changeCc(i),$inv.d.syncField("invoiceemail",n),$inv.rd.syncField("invoiceemail",n),$inv.d.syncField("invoiceemailcc",i),$inv.rd.syncField("invoiceemailcc",i)}})},$inv.emailFrm=function(e,t,n,i){let a=$$.dc("inpfrm emailccfrm",e),r=$$.dc("content",a).rwText(i),s=$$.dc("inpfrm emailfrm",e),l=$$.dc("content",s).rwText(n);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT.invoiceemail}).append(gi("pencil")).click({t:l,ccT:r,nme:"invoiceemail",change:e=>{t.tbl.data("new").invoiceemail=e},changeCc:e=>{t.tbl.data("new").invoiceemailcc=e}},$inv.eHtml)),t.tbl.data("new").invoiceemail=n,t.tbl.data("new").invoiceemailcc=i},$inv.eHtml=function(e){if(e.data&&!(e.data instanceof jQuery)&&$inv.d&&"function"==typeof $inv.d.token&&""!==$inv.d.token()){if("invoiceaddress"===e.data.nme)return $inv.eAddress.call(this,e);if("provisionperiod"===e.data.nme)return $inv.eProvisionPeriod.call(this,e)}if(e.data&&!(e.data instanceof jQuery)&&"invoiceemail"===e.data.nme&&e.data.ccT)return $inv.eEmail.call(this,e);let t=$(this),n=e.data instanceof jQuery?e.data:e.data.t,i=["invoiceemail","invoiceemailcc","provisionperiod","invoicetitle"].includes(e.data.nme),a=i?[{name:"txt",label:"Text",type:"text",value:n.text()}]:[{name:"txt",label:"Text",type:"html",value:n.html(),tinymce:!0,attr:{style:"height: 300px"}}],r=e.data.change||null,s={title:t.data("dialog")||"",success:function(t){i?n.text(t.txt||""):n.html(t.txt),"function"==typeof r&&r(t.txt),$inv.d.syncField(e.data.nme,i?t.txt||"":t.txt),$inv.rd.syncField(e.data.nme,i?t.txt||"":t.txt)},tinymce:{valid_elements:"br",hidemenu:!0,hidetoolbar:!0}};if(Array.isArray(e.data.list)){let t=$$.dc("lstfrm");$.each(e.data.list,((n,i)=>{let a=$$.dc("li",t).append(""!==(e.data.lbl||"")?$$.dc("lbl").rwText(i[e.data.lbl]):null);$$.dc("adr",a).rwText(i[e.data.property]).data("val",i[e.data.property]).click((function(){let e=$(this),t=e.closest(".modal-body").find(':input[name="txt"]');t.is(".tinymce")?tinymce.get(t.attr("id")).setContent($$.s().rwText(e.data("val")).html()):"TEXTAREA"===t.prop("tagName")?t.val(e.data("val")).change():t.rwText(e.data("val"))}))})),s.addcontent=t}$ocms.dlgform(a,s)},$inv.setVat=function(e){$(this);let t=e.data,n=prompt($rct.rqV);n&&(n=parseFloat(n.replace("%","")),n>1&&(n*=.01),!1===isNaN(n)&&(t.siblings(".itm").each((function(){$(this).data().vat=fnum(n,{style:"percent"}).replace(" ","")})),$inv.t_fds_inv()))},$inv.inRow=function(e){let t=$(this),n=e.data,i={},a=$rcol.itm.clone(["SortOrder","NameOrNumber","Type","quantityhours","UnitString","net","svcnet_val","svcvat_val","net_val","vat_val","vat","Note"]),r="N"+(65536*(1+Math.random())||0).toString(16).substr(6),s=$$.tr({id:"itm_"+r.toString(),class:"itm"});$ocms.dlgform(a,{title:t.data("dialog")||"",success:function(e){s.data($.extend({Id:r},i,e)),$inv.rrw.call(s),s.insertAfter(n),$inv.t_fds_inv()},typedvalues:!0})},$inv.eRow=function(e){let t=$(this),n=e.data,i=n.data()||{},a=["SortOrder","NameOrNumber","Type","quantityhours","UnitString","net","svcnet_val","svcvat_val","net_val","vat_val","vat","Note"];i.id||""!==(i.Type||"")||a.unshift("Type");let r=$rcol.itm.clone(a).applyValues(i);r.set("Type","hidden","type"),$inv.eRw.call(t,n,i,r)},$inv.eRw=function(e,t,n){let i=$(this);$ocms.dlgform(n,{title:i.data("dialog")||"",success:function(n){let i={};""===(t.Id||"")&&(i.Id="N"+(65536*(1+Math.random())||0).toString(16).substr(6),e.attr("id","itm_"+i.Id.toString())),i.quantity=((n.quantityhours||"").toString()+" "+(n.UnitString||"").toString()).trimEnd(),e.data($.extend({},t,n,i)),console.debug("eRw success %o",e.data()),$inv.rrw.call(e),$inv.t_fds_inv()},typedvalues:!0})},$inv.bdysort=(e,t)=>{$(t).Sortable({dragItem:!1,dragHandleClass:"ico",parentident:"tr",onend:()=>{$inv.t_fds_inv()}})},$inv.rowCtxMenu=function(e){let t=$$[0]("nav").aC("rowctx");return t.ocmsmenu([{glyph:"glyphicon-option-vertical",aclass:"ctxbtn",attr:{title:$rct.ctxM},itm:e}]),t.find("li[title]").each((function(){let e=$(this);e.children("a").attr("title",e.attr("title"))})),t},$inv.rrw=function(){let e=$(this),t=e.data(),n={},i=e.is(".placeholder"),a=e.is(".hidenote"),r=e=>$$.d().append(e).html(),s=[{lbl:$rct.iRb,attr:{title:$rct.iRb},data:e,fnc:$inv.inRow}];!1===i&&(s.unshift({lbl:$rct.cP,attr:{title:$rct.cP},data:e,fnc:$inv.eRow}),s.push({lbl:$rct.dR,attr:{title:$rct.dR},fnc:function(t){confirm($rct.cD)&&(e.remove(),$inv.t_fds_inv())}}),"set"===(t.Type||"").toLowerCase()&&0===(t.net_val||0)&&s.push({lbl:$rct.toSetP,attr:{title:$rct.toSetP},data:e,fnc:$inv.toSetPrice}));let l=$$.dc("axf").append($inv.rowCtxMenu(s));!0===i?n={id:"",typ:"placeholder"}:!0===e.is(".itm.osum")?n={invrqid:t.InvRqId,id:"osum"+e.index(),typ:"osum",p:"",q:null,t:r(t.tbl.tbl),tt:null,v:null,vt:t.net_val,vs:t.svcnet_val,vat:t.vat,vv:t.vat_val,vsv:t.svcvat_val,det:!1}:(n={invrqid:t.InvRqId,id:t.Id||"",typ:t.Type||"other",p:"",q:null,t:"",tt:null,v:null,vt:t.net_val,vs:t.svcnet_val,vat:t.vat,vv:t.vat_val,vsv:t.svcvat_val,det:""!==(t.Note||"")&&!1===a,SetItmId:t.SetItmId||null,lvl:t.lvl||0},$$.dc("ibtn ico move",l,{title:$rct.mR}),n.p=null!=t.position?t.position:t.SortOrder||"",""===n.id?n.t="":["Text","Title"].includes(n.typ)&&0===(t.net_val||0)?n.t=t.htmltext||("#"!==(t.NameOrNumber||"").substr(0,1)?r($$[0]("p").text(t.NameOrNumber)):"")+(t.Note||""):(n.tt=n.det?"":$$.s(t.Note||"").text(),n.q=t.quantity||(0!==(t.quantityhours||0)?fnum(t.quantityhours)+" "+(t.UnitString||""):""),n.t=t.htmltext||(n.det?r($$.s(t.NameOrNumber||""))+r($$.dc("desc").html(t.Note)):r($$.s(t.NameOrNumber||""))),n.v=t.net,n.vt=t.net_val)),""!==(t.Note||"")&&$$.dc("ibtn add",l,{title:$rct.noteToggle}).append(gi("object-align-left")).click((function(t){$inv.rrw.call(e.tC("hidenote"))}));let d=[$$.tdc("aux").append(l),$$.tdc("keep").text(n.p)];if(""===n.id)d.push($$.td(e,{colspan:4}).append(n.t));else{Array.prototype.push.apply(d,n.q?[$$.tdc("keep").text(n.q)]:[]);let e=e=>null==e?"":fnum(e,$rct.cst);Array.prototype.push.apply(d,[$$.tdc("txt",{colspan:n.q?1:2,title:n.tt}).append(n.t),$$.tdc("currency").text(e(n.v)),$$.tdc("currency inetval").text(e(n.vt)).attr("title",$rct.svcPart+": "+e(n.vs))])}e.empty().attr("class",i?"placeholder":"itm").aC(n.Typ).tC("sethdr","set"===(n.typ||"").toString().toLowerCase()).aC((n.lvl||0)>0?"lvl"+Math.min(n.lvl,6):"").tC("hidenote",a).append(d),t.co=n},$inv.toSetPrice=function(e){let t=(e.data.data().Id||"").toString();""!==t&&!1!==confirm($rct.toSetPc)&&$.when($inv.t_fds_inv()).done((()=>{$inv.d.sync({Target:"item.setprice",Ref:t})}))},$inv.invSumUpdate=function(){let e=$(this),t=[],n=e.children("tbody"),i=[];n.each(((e,n)=>{let a=$(n),r=a.data()||{},s=[],l=[],d=a.find("tr.itm");a.tC("empty",d.length<1),d.each(((e,t)=>{let n=$(t).data()||{};s.push(n.co);let a=$inv.itemToContract(n),r=(n.SetItmId||"").toString();""!==r&&r!==a.id&&(a.setId=r),l.push(a);let d=!1===["text","title"].includes((n.Type||"other").toLowerCase());n.position=((e,t)=>{if(!e)return"";let n=Math.max(t||0,0);for(;i.length<=n;)i.push(0);return i.length=n+1,i[n]++,i.join(".")})(d,(n.co||{}).lvl||0),$inv.rrw.call(t)})),t.push({Id:r.Id,nme:r.Name,text:r.text,itm:s,items:l})}));let a=e.find("tbody:not(.empty)").length;n.find("tr.isum").tC("hidden",a<2),e.data("bai",t),""===(e.data("dtoken")||"")&&!1===bool(e.data("dseeding"),!1)&&null!=(e.data("admin")||{}).type&&(e.data("dseeding",!0),$inv.d.seed($.extend($inv.invcPayload(e.data()),{invid:e.data("invid")||""})))},$inv.worknotes=function(e){let t="";return e.steps.forEach(((e,n)=>{let i;try{i=JSON.parse(e.Data||{}).fields||[]}catch(e){console.debug(e),i=[]}!0!==Array.isArray(i||"")&&(i="object"==typeof i&&!0===Array.isArray(i.field||"")?i.field:[]),i.forEach(((e,n)=>{"Ausgeführte Arbeiten"===e.name&&(t=e.result||"")}))})),t},$inv.rendersrq=function(){let e=$(this).empty(),t=e.is(".onesum"),n=e.data(),i=$$.tr(e,{id:"srq"+n.Id}).aC("title nosort"),a=($rcol.itm.lbl(),$$.dc("axf").appendTo($$.tdc("aux",i)));$$.dc("ibtn osum",a,{title:$rct.combP}).append(gi("euro")).click((function(t){e.tC("onesum"),$inv.rendersrq.call(e),$inv.t_fds_inv()})),$$.dc("ibtn setvat",a,{title:$rct.sV}).append(gi("gbp")).click(i,$inv.setVat),$$.dc("ibtn insb",a,{title:$rct.iRb}).append(gi("indent-left")).click(i,$inv.inRow);let r,s=$$.sc("text",n.text),l=($$.td(i,{colspan:t?4:5}).append(s),["net_val","vat_val","svcnet_val","svcvat_val","net"]);if($$.dc("ibtn edit",a,{title:$rct.sectionTitleEditTT}).data("dialog",$rcol.req.lbl().Name).append(gi("pencil")).click({t:s,change:e=>{n.text=e,$inv.t_fds_inv()}},$inv.eHtml),t&&($$.tdc("currency isumval",i),r={Id:n.Id.toString()+"_osum",net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0},r.tbl=$$.tblset({class:"stbl"})),$.each(n.items||[],((n,i)=>{let a,s={Id:i.Id,net_val:i.net_val||0,vat_val:i.vat_val||0,svcnet_val:0,svcvat_val:0,net:i.net||0,Note:i.Note||""};if("service"===i.Type.toLowerCase())s.svcnet_val=i.net_val||0,s.svcvat_val=i.vat_val||0;t?(a=$$.tr(r.tbl.bdy,{id:"itm"+i.Id,class:"sitm"}).aC(i.Type),"Text"===i.Type||"Title"===i.Type?$$.td(a,{colspan:2}).html(i.htmltext||i.Note):($$.tdc("keep",a).text(i.quantity||((i.quantityhours||0)>0?fnum(i.quantityhours)+(i.UnitString||"").eine(" ",""):"")),i.htmltext?$$.tdc("txt",a).html(i.htmltext):$$.tdc("txt",a).text(i.NameOrNumber).attr("title",i.Note)),$.each(l,((e,t)=>{r[t]+=s[t]})),a.data(s)):($.extend(s,i),a=$$.tr(e,{id:"itm"+i.Id,class:"itm"}),a.data(s),$inv.rrw.call(a))})),t){let t=$$.tr(e,{id:"itmsq"+n.Id,class:"itm osum"}).data(r);$inv.rrw.call(t)}else{let t=$$.tr(e).aC("isum nosort");$$.tdc("aux",t),$$.td(t,{colspan:4}).text($rct.iSum),$$.tdc("currency isumval",t)}},$inv.t_fds_inv=()=>{let e=$("div.invoice_layout table.invi");if(e.trigger("fds.inv"),""!==(e.data("dtoken")||""))return $inv.d.syncChanged(e);let t=e.data("dseedpromise");return t?$.when(t).then((()=>$inv.d.syncChanged(e))):$.when()},$inv.sedit=()=>{$inv.sprev(!0)},$inv.jdisp=function(e){e.stopPropagation(),e.data.id&&$inv.disp(e.data.id,e.data.typ||"")},$inv.disp=(e,t)=>{let n="";switch(t){case"inv":n="inv/rdoc";break;case"rem":n="rem/rdoc"}""!==n&&$ocms.postXT({url:$ocms.url(n),data:{id:e||"",typ:"img"},timeout:$inv.pdfPreviewTimeout,success:e=>{let t=$$.dc("imagecollection pdfpreview"),n=Math.round(.88*vh());e.id;$.each(e.img||[],(function(e,i){$$.dc("pdfp",t).append($$.img(i).css("max-height",(n-rpx(6)).toString()+"px"))})),$ocms.dlg(t,{size:[n,Math.round(.88*vw())],zindex_min:50,form:!1,exclusive:!1})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete()})},$inv.jdbn=function(e){$ocms.postXT({url:$ocms.url("inv/rdocn"),data:{name:e.data.id||"",typ:"img"},timeout:$inv.pdfPreviewTimeout,success:e=>{let t=$$.dc("imagecollection pdfpreview"),n=Math.round(.88*vh());e.id;$.each(e.img||[],(function(e,i){$$.dc("pdfp",t).append($$.img(i).css("max-height",(n-rpx(6)).toString()+"px"))})),$ocms.dlg(t,{size:[n,Math.round(.88*vw())],zindex:50,form:!1})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete()})},$inv.sp13b=()=>{var e=$("div.invoice_layout").find("table.invi"),t=e.data();t.admin.p13b=!0,!1===(t.inv.InvoiceOptions||"").split(",").includes("§13b")&&(t.inv.InvoiceOptions+=",§13b"),e.trigger("fds.inv"),$inv.d.sync({Target:"p13b",Value:t.admin.p13b})},$inv.itemToContract=function(e){let t=((e=e||{}).Type||"").toString().toLowerCase(),n=e=>e??null,i={id:(e.Id||"").toString(),type:t,title:"",desc:"",qty:"",price_net:"",total_net:n(e.net_val),vat:e.vat||""};var a;return e.co&&"osum"===e.co.typ?(i.desc=e.co.t||"",i.total_net=e.net_val||0):["text","title"].includes(t)&&0===(e.net_val||0)?(i.desc=e.htmltext||("#"!==(e.NameOrNumber||"").substr(0,1)?(a=$$[0]("p").text(e.NameOrNumber||""),$$.d().append(a).html()):"")+(e.Note||""),i.total_net=""):(e.htmltext?i.desc=e.htmltext:(i.title=e.NameOrNumber||"",i.desc=e.Note||""),i.qty=e.quantity||(0!==(e.quantityhours||0)?fnum(e.quantityhours)+(e.UnitString?" "+e.UnitString:""):""),i.price_net=n(e.net),i.total_net=n(e.net_val)),i},$inv.hasSets=e=>((e||{}).req||[]).some((e=>{let t=((e||{}).itm||[]).filter((e=>e&&""!==(e.id||""))),n={};t.forEach((e=>{n[(e.id||"").toString()]=e}));return t.some((e=>{let t=(null==e.SetItmId?"":e.SetItmId).toString();return""!==t&&t!==(e.id||"").toString()&&n[t]&&(e=>"set"===(e.typ||"").toString().toLowerCase())(n[t])}))})),$inv.ssetmode=()=>{let e,t=$("div.invoice_layout").find("table.invi").data();if(t.dstate&&!1===$inv.hasSets(t.dstate))return void alert($rct.toSetMn);let n=t=>$$.dc("btn",$ict.setmo[t]).click((()=>{e.c.trigger("modal_close"),$inv.setSetmode(t)})),i=$$.dc("choicefrm").append([n("setprice"),n("setonly")]);e=$ocms.dlg(i,{width:800})},$inv.setSetmode=e=>{if(!1===confirm($rct.toSetMc||$rct.toSetPc))return;let t="setonly"===e?"block.setonly":"block.setprice";$.when($inv.t_fds_inv()).done((()=>{$inv.d.sync({Target:t})}))},$inv.sctp=()=>{let e=$invcol.ctp;$ocms.dlgform(e,{title:$ict.ctp,success:function(e){var t=$("div.invoice_layout"),n=t.find("table.invi").data();let i={};void 0!==n.new&&"{"===(n.new.CustomValues||"").substr(0,1)&&(i=JSON.parse(n.inv.CustomValues)),i.contactName=e.name,i.contactEmail=e.email,n.new.CustomValues=JSON.stringify(i),t.find(".ctpfrm").text(ne(e.name,e.email)),$inv.d.sync({Target:"contact",Value:{name:e.name,email:e.email}})},typedvalues:!0})},$inv.invcPayload=function(e){e=e||{};let t=$.extend({},e.new),n=$.extend({},e.admin);return t.title=null!=t.invoicetitle?t.invoicetitle:t.title||"",t.provisionlocation=null!=t.loc?t.loc:t.provisionlocation||"",t.paymentterm=null!=n.paymentterms?n.paymentterms:t.paymentterm||"",n.customerid=null!=n.customerid?n.customerid:n.CustomerId,{admin:n,req:e.bai,new:t}},$inv.ssave=()=>{$inv.d.save()},$inv.sprev=e=>{$inv.d.preview()},$inv.rReload=()=>{try{let e=$("#listframe ul.rql:first").data();$inv.cInv2({id:e.search})}catch(e){}},$inv.quantChange=function(e){},$inv.storno=function(e,t){let n,i=$$.dc("choicefrm").append([$$.dc("btn","Storno ohne Details").click({id:e,mode:"simple"},(e=>{n.c.trigger("modal_close"),$inv.cSt(e.data)})),$$.dc("btn","Storno mit neuer Rechnung").click({id:e},(e=>{n.c.trigger("modal_close"),$inv.ccStInv(e)})),$$.dc("btn","Storno mit best. Rechnung").tC("inactive",!1===bool(t,!1)).click({id:e,mode:"copy"},(e=>{!0===bool(t,!1)&&(n.c.trigger("modal_close"),$inv.cSt(e.data))}))]);n=$ocms.dlg(i,{width:1e3})},$inv.credit=function(e,t){let n,i=$$.dc("choicefrm").append([$$.dc("btn","Gutschrift").click({id:e,mode:"credit"},(e=>{n.c.trigger("modal_close"),$inv.cSt(e.data)}))]);n=$ocms.dlg(i,{width:1e3})},$inv.setPyd=function(e){confirm($ict.cpyd)&&$ocms.postXT({url:$ocms.url("inv/setpyd"),timeout:60,data:{id:e},success:e=>{alert($ict.relm)},error:()=>{alert($t.f1)}})},$inv.setUpd=function(e){confirm($ict.cupd)&&$ocms.postXT({url:$ocms.url("inv/setupd"),timeout:60,data:{id:e},success:e=>{alert($ict.relm)},error:()=>{alert($t.f1)}})},$inv.resendRem=function(e){e.stopPropagation(),e.data.id&&confirm(string($ict.remresc,[e.data.name]))&&$ocms.postXT({url:$ocms.url("rem/resend"),timeout:60,data:{id:e.data.id},success:t=>{alert(string($ict.remresr,[e.data.name]))},error:()=>{alert($t.f1)}})},$inv.dspRem=function(e){let t=$$.dc("rfrm").ldng(1),n=$ocms.dlg(t,{width:1e3});n.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("inv/getrem"),timeout:60,data:{id:e,drafts:!1},success:e=>{n.ft.empty();let i=$$.tblset({class:"invtbl"},t.empty()),a=$invcol.rem2,r=$$.tr(i.hd);$$.th(r);$.each(a.fields||[],((e,t)=>{$$.th(r).text(t.label)}));let s=!1;$.each(e,((e,t)=>{s=!s;let n=$$.tr(i.bdy).tC("alt",s),r=$$.td(n);n.click((function(){n.tC("selected").siblings().rC("selected")})),!0===bool(t.hasFile,!1)&&($$.dc("idl ilbtn",r,{title:$ict.dl+"\n"+t.DocumentName}).append(gi("save-file","ico")).click({id:t.Id},$inv.downloadrem),$$.dc("idl ilbtn",r,{title:$ict.remdsp+"\n"+t.DocumentName}).append(gi("eye-open","ico")).click({id:t.Id,typ:"rem"},$inv.jdisp),$$.dc("idl ilbtn",r,{title:$ict.remres+"\n"+t.DocumentName}).append(gi("refresh","ico")).click({id:t.Id,typ:"rem",name:t.DocumentName},$inv.resendRem)),$.each(a.fields||[],((e,i)=>{let a=$$.td(n).aC(i.dtype),r=t[i.name];if("function"==typeof i.dfnc)i.dfnc.call(a,r,t);else switch(i.type||""){case"date":a.text(fdt(t[i.name],"dd.MM.yy"));break;case"datetime":a.text(fdt(t[i.name]));break;case"html":a.append($$.dc("ctw").html(r)),a.append($$.dc("ttip").html(r));break;default:a.text(t[i.name])}if("InvoiceId"===(i.name||""))a.aC("keep");switch(typeof i.title){case"function":i.title.call(a,t);break;case"string":a.attr("title",cs.title)}}))}))},error:()=>{t.empty(),n.ft.rwText($t.f1)},complete:()=>{t.ldng(0)}})},$inv.ccRem=function(e,t){$(this);$ocms.postXT({url:$ocms.url("rem/lrem"),timeout:60,data:{id:e},success:n=>{let i=$invcol.rid.clone();i.applyValues(n.ov);let a=$$.dc("ac"),r=$$.tblset({class:"fullgrid fullwidth"},a);if((n.lst||[]).length>0){$$.d({style:"margin: 1.5rem 0 1rem 0;font-size: 110%;text-decoration: underline;"}).prependTo(a).text($ict.rovlh);let e=$$.tr(r.hd);$ict.rovl.forEach(((t,n)=>$$.th(e,t))),$.each(n.lst,((e,t)=>{$$.tr(r.bdy).append([$$.tdc("keep",t.subject),$$.tdc("currency",fnum(t.amount,$rct.cst)),$$.tdc("currency",fnum(t.amount_payed,$rct.cst)),$$.tdc("keep",fdt(t.DateFinalized,"dd.MM.yy"))])}))}else $$.td($$.tr(r.bdy),$ict.nd);$ocms.dlgform(i,{addcontent:a,title:string($ict.remdt,[t||"?"]),success:function(t){$inv.ccRem_s2(e,t)},typedvalues:!0})}})},$inv.rRemRw=function(e){let t=$(this),n=e.rm||{};t.empty().data({invoiceid:n.invoiceid,invoicedate:n.invoicedate,amount:n.amount,amount_payed:n.amount_payed});let i=[{lbl:$rct.cP,attr:{title:$rct.cP},data:t,fnc:$inv.eRowR}],a=$$.dc("axf").append($inv.rowCtxMenu(i));t.append([$$.tdc("aux").append(a),$$.tdc("keep",n.invoiceid),$$.tdc("keep",fdt(n.invoicedate,"dd.MM.yy")),$$.tdc("currency",fnum(n.amount,$rct.cst)),$$.tdc("currency",fnum(n.amount_payed,$rct.cst)),$$.tdc("currency",fnum(n.amount-n.amount_payed,$rct.cst))])},$inv.eRowR=function(e){let t=$(this),n=e.data,i=n.data()||{},a=$invcol.rem.clone().applyValues(i);$ocms.dlgform(a,{title:t.data("dialog")||"",success:function(e){let i=t.closest("table"),a=i.data();$.extend(a.rm,e),i.data(a),$inv.rRemRw.call(n,a),$inv.rd.syncAmount(a.rm.amount,a.rm.amount_payed)},typedvalues:!0})},$inv.ccRem_s2=function(e,t){$fis.lf(!1).rC("fix").aC("hd");let n=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.rprev));$inv.eM(!1,!0);$$.dc("rfrm").ldng(1);$ocms.postXT({url:$ocms.url("rem/get"),timeout:60,data:$.extend({id:e},t),success:e=>{let t=e.rm||{},i=$$.dc("srq",n),a=$$.tblset({class:"invi"},i);a.ft=$$[0]("tfoot"),a.tbl.data($.extend({invid:t.invid,new:{}},e));let r=$$.tr(a.hd).aC("shd").append([$$.th().aC("aux")]);$ict.remHR.forEach((e=>$$.th(r,e))),$inv.rRemRw.call($$.tr(a.bdy),a.tbl.data()),a.ft.appendTo(a.tbl);let s={invoiceemail:"Email-Adresse ändern",subject:"Betreff ändern"},l=(e,t,i,r,l)=>{let d=$$.dc("inpfrm",n).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),c=$$.dc("content",d).rwText(t);$$.dc("axf",d).append($$.dc("ibtn edit",{title:s[i]||$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:c,nme:i,change:e=>{a.tbl.data("new")[i]=e}},l),$inv.eHtml)),a.tbl.data("new")[i]=t};l("tfrm",t.subject,"subject",0,null),l("adrfrm",t.invoiceaddress,"invoiceaddress",0,null),l("emailfrm",t.invoiceemail,"invoiceemail",0,null),$$.dc("sndfrm",n).append($$.dc("content").text(t.sender)),a.tbl.children("tbody").each($inv.bdysort),a.tbl.trigger("fds.inv");let d=a.tbl.data("new");d.amount=t.amount,d.amount_payed=t.amount_payed,$inv.rd.seed({rem:{invid:t.invid,type:t.type,invoiceid:t.invoiceid,invoicedate:t.invoicedate},new:d})},complete:()=>{}})},$inv.rprev=()=>{$inv.rd.preview()},$inv.sis=e=>{confirm($ict.sisc)&&$ocms.postXT({url:$ocms.url("inv/sis"),data:{id:e||""},success:e=>{}})},$inv.srs=e=>{confirm($ict.srsc)&&$ocms.postXT({url:$ocms.url("rem/srs"),data:{id:e||""},success:e=>{}})},$inv.mfrrel=e=>{$("#contentframe").ldng(),$ocms.postXT({url:$ocms.url("inv/mfrrel"),data:{id:e||""},success:e=>{$inv.rerenderinv()},complete:()=>{$("#contentframe").ldng(0)}})},$inv.sets={o:null,c:null,drag:null,isOpen:()=>!!$inv.sets.o,open:function(){let e=$inv.d.tbl();if(e.length<1||$inv.sets.isOpen())return;if(""===$inv.d.token()&&!e.data("dstate"))return;let t=$$.dc("setstruct");$inv.sets.c=t,$inv.sets.o=$ocms.dlg(t,{title:$ict.setst,size:[-1,960],exclusive:!1,close:()=>{$inv.sets.o=null,$inv.sets.c=null,$inv.sets.drag=null}});let n=e.data("dstate");n?$inv.sets.render(n):$inv.d.refresh()},title:e=>{let t=$$.d().html(e.t||"").text().replace(/\s+/g," ").trim();return""!==t?t:$ict.setsNoTitle||""},typLbl:e=>{let t=(e.typ||"").toString().toLowerCase();return($ict.settyp||{})[t]||e.typ||""},isSet:e=>"set"===(e.typ||"").toString().toLowerCase(),parentOf:(e,t)=>{let n=(null==e.SetItmId?"":e.SetItmId).toString(),i=(e.id||"").toString();if(""===n||n===i)return"";let a=t[n];return a&&$inv.sets.isSet(a)?n:""},isDescendant:(e,t,n)=>{let i={},a=n[e];for(;a;){let e=$inv.sets.parentOf(a,n);if(""===e||i[e])return!1;if(e===t)return!0;i[e]=!0,a=n[e]}return!1},canDrop:(e,t,n,i)=>!!e&&e.bid===n&&e.id!==t&&!$inv.sets.isDescendant(t,e.id,i),sync:e=>($inv.sets.c&&$inv.sets.c.aC("busy"),$inv.d.sync(e)),render:function(e){let t=$inv.sets.c;if(!t)return;let n=t.closest(".modal-body"),i=n.length?n.scrollTop():0;t.empty().rC("busy"),$$.dc("shint",t).text($ict.setsHint||""),(e.req||[]).forEach((e=>{if(!e)return;let n=(e.Id||"").toString();if(""===n)return;let i=(e.itm||[]).filter((e=>e&&""!==(e.id||""))),a={};i.forEach((e=>{a[(e.id||"").toString()]=e}));let r=$$.dc("sblock",t).data({bid:n});$inv.sets.rootZone($$.dc("sbhd",r).append($$.sc("nme",e.text||e.nme||n)),n,a);let s=$$.tblset({class:"stbl"},r),l=$$.tr(s.hd);($ict.setsHR||[]).forEach((e=>$$.th(l,e))),i.forEach((e=>$inv.sets.row(s.bdy,e,n,i,a))),$inv.sets.rootZone($$.dc("sroot",r).text($ict.setsRoot||""),n,a),$inv.sets.createBar(r,n,i,a)})),n.length&&n.scrollTop(i)},collapsed:{},hiddenByCollapse:function(e,t){let n={},i=e;for(;i;){let e=$inv.sets.parentOf(i,t);if(""===e||n[e])return!1;if($inv.sets.collapsed[e])return!0;n[e]=!0,i=t[e]}return!1},zone:function(e,t,n){let i=e.originalEvent||e,a=t[0].getBoundingClientRect(),r=(i.clientY||0)-a.top,s=a.height||1;return r<.3*s?"before":r>.7*s||!n?"after":"into"},clearDrop:()=>{$(".setstruct .dropok, .setstruct .dropbefore, .setstruct .dropafter").rC("dropok dropbefore dropafter")},row:function(e,t,n,i,a){let r=(t.id||"").toString(),s=parseInt(t.lvl||0,10)||0,l=$inv.sets.isSet(t),d=$inv.sets.parentOf(t,a),c=l&&!!$inv.sets.collapsed[r],o=$$.tr(e,{draggable:"true"}).aC("srow lvl"+s).tC("isset",l).tC("folded",c).data({id:r,bid:n});$inv.sets.hiddenByCollapse(t,a)&&o.aC("hid"),$$.tdc("grip",o).append(gi("move")).attr("title",$rct.mR),$$.tdc("pos",o).text(null!=t.p?t.p:"");let u=$$.tdc("typ",o);l&&u.append($$.sc("fold").attr("title",c?$ict.setsExpand:$ict.setsCollapse).append(gi(c?"triangle-right":"triangle-bottom")).click((e=>{e.stopPropagation(),c?delete $inv.sets.collapsed[r]:$inv.sets.collapsed[r]=!0;let t=$inv.d.tbl().data("dstate");t&&$inv.sets.render(t)}))),u.append($$.s($inv.sets.typLbl(t))),$$.tdc("qty",o).text(t.q||"");let m=$$.tdc("ttl",o);if(""!==d&&m.append($$.sc("seti",$inv.sets.title(a[d]))),m.append($$.sc("txt",$inv.sets.title(t)).click((function(e){e.stopPropagation(),$(this).tC("exp")}))),l){let e=i.filter((e=>$inv.sets.parentOf(e,a)===r)).length;m.append($$.sc("cnt"," ("+e+")"))}let v=i.filter((e=>$inv.sets.parentOf(e,a)===d)),p=v.findIndex((e=>(e.id||"").toString()===r)),f=v.slice(0,p).some((e=>$inv.sets.isSet(e))),h=$$.tdc("act",o),g=(e,t,n,i,a)=>$$.dc("ibtn "+e,h,{title:n}).append(gi(t)).tC("disabled",!i).click((()=>{i&&$inv.sets.sync(a)}));g("up","arrow-up",$ict.setsUp,p>0,{Target:"set.move",Ref:r,Value:-1}),g("down","arrow-down",$ict.setsDown,p>=0&&p0,{Target:"set.level",Ref:r,Value:-1}),g("in","chevron-right",$ict.setsIn,f,{Target:"set.level",Ref:r,Value:1}),o.on("dragstart",(e=>{$inv.sets.drag={id:r,bid:n},o.aC("dragging");try{e.originalEvent.dataTransfer.setData("text/plain",r),e.originalEvent.dataTransfer.effectAllowed="move"}catch(e){}})).on("dragend",(()=>{o.rC("dragging"),$inv.sets.drag=null,$inv.sets.clearDrop()}));return o.on("dragover",(e=>{if(!$inv.sets.canDrop($inv.sets.drag,r,n,a))return;e.preventDefault();let t=$inv.sets.zone(e,o,l);o.rC("dropok dropbefore dropafter").aC("into"===t?"dropok":"before"===t?"dropbefore":"dropafter")})).on("dragleave",(()=>{o.rC("dropok dropbefore dropafter")})).on("drop",(e=>{e.preventDefault(),$inv.sets.clearDrop();let t=$inv.sets.drag;if($inv.sets.drag=null,!$inv.sets.canDrop(t,r,n,a))return;let i=$inv.sets.zone(e,o,l);"into"===i?$inv.sets.sync({Target:"set.assign",Ref:t.id,Value:{parent:r}}):$inv.sets.sync({Target:"set.move",Ref:t.id,Value:{anchor:r,where:i}})})),o},rootZone:function(e,t,n){return e.on("dragover",(i=>{(()=>{let e=$inv.sets.drag;return!!e&&e.bid===t&&!!n[e.id]&&""!==$inv.sets.parentOf(n[e.id],n)})()&&(i.preventDefault(),e.aC("dropok"))})).on("dragleave",(()=>{e.rC("dropok")})).on("drop",(i=>{i.preventDefault(),e.rC("dropok");let a=$inv.sets.drag;$inv.sets.drag=null,a&&a.bid===t&&n[a.id]&&""!==$inv.sets.parentOf(n[a.id],n)&&$inv.sets.sync({Target:"set.assign",Ref:a.id,Value:{parent:""}})})),e},createBar:function(e,t,n,i){let a=$$.dc("screate",e),r=$("").attr({name:"typ"}).append([$$.opt("set",$ict.settyp.set),$$.opt("text",$ict.settyp.text)]),s=$("").attr({name:"parent"}).append($$.opt("",$ict.setsTop));n.forEach((e=>{if(!$inv.sets.isSet(e))return;let t=parseInt(e.lvl||0,10)||0;s.append($$.opt((e.id||"").toString()," ".repeat(3*t)+$inv.sets.title(e)))}));let l=$('').attr({name:"title",placeholder:$ict.setsTitle,maxlength:250}),d=()=>{let e=(l.val()||"").toString().trim();""!==e?($inv.sets.sync({Target:"set.create",Ref:t,Value:{typ:r.val(),title:e,parent:s.val()||""}}),l.val("")):l.focus()};return l.on("keydown",(e=>{"Enter"===e.key&&(e.preventDefault(),d())})),a.append([$$.sc("lbl",$ict.setsNew),r,$$.sc("lbl",$ict.setsInto),s,l,$$.bbtn($ict.setsAdd,"sadd").click(d)]),a}};
\ No newline at end of file
+let $rct={mdl:"Aufträge",or:"offene Aufträge",orr:"offene Aufträge (4 W)",rn:"Auftragsnummer",iov:{all:"Auftragsübersicht (alle)","":"Auftragsübersicht"},wk:"Woche",nd:"Keine Daten gefunden.",h:"Uhr",rq1:"Auftragsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",rq2:"Auftragsdaten werden geladen",rq1f:"Die Auftragsdaten von MFR konnten nicht oder nicht schnell genug abgerufen werde.\nMöchten Sie mit den bestehenden Daten trotzdem weitermachen?",note1:"Im Bruttobetrag sind {0} Lohnkosten enthalten (netto {1}). Die darin enthaltene Umsatzsteuer beträgt {2}.",note2:"Bitte beachten Sie, nach §14 Abs. 1 Umsatzsteuergesetz ist diese Rechnung ein Zahlungsbeleg oder eine andere beweiskräftige Unterlage für 2 Jahre nach Ablauf des Kalenderjahres der Ausstellung dieser Rechnung aufzubewahren, soweit nicht aufgrund anderer gesetzlicher Regelungen andere ggf.längere Aufbewahrungsfristen gelten.",note3:"Privathaushalten erstattet das Finanzamt bis zu {0} des Arbeitslohns mit der nächsten Steuererklärung.",note4:"Für bereits erbrachte Arbeiten, Dienstleistungen, Materiallieferungen und getätigte Bestellvorgänge zum oben genannten Bauvorhaben, die sich aus dem mit Ihnen geschlossenen Vertrag ergeben, stellen wir Ihnen vertragsgemäß unsere Akontozahlung in Rechnung. Eine Endabrechnung erhalten Sie als Schlussrechnung nach Abschluss des gesamten Bauvorhabens. Das Ausführungsdatum entnehmen Sie bitte dem Schlusstext dieser Rechnung. Wir danken Ihnen herzlich für das entgegengebrachte Vertrauen und bitten Sie um kurzfristigen Ausgleich der Akontorechnung.",note13b:"Gem. §13b Umsatzsteuergesetz unterliegen Sie der Steuerschuldnerschaft des Leistungsempfängers zur Umsatzsteuer aus dieser Rechnung mit einem Steuersatz von 19%.",crI:"Rechnung erstellen",crII:"Abschlagsrechnung erstellen",dII:"Für eine Abschlagsrechnung darf nur ein Auftrag gewählt werden.",dnS:"Für eine Rechnung muss mindestens ein Auftrag gewählt werden.",inv:"Rechnung",invs:"Rechnungen",req:"Auftrag",provP:"Leistungszeitraum",provD:"Leistungsdatum",cP:"Position ändern",iRb:"Zeile darunter einfügen",dR:"Zeile löschen",sV:"USt festlegen",cD:"Löschen?",mR:"Zeile verschieben",ctxM:"Weitere Aktionen",noteToggle:"Notiz ein-/ausblenden",sectionTitleEditTT:"Auftragsbezeichnung ändern",svcPart:"Service-Anteil",vat:"Umsatzsteuer",combP:"Positionen zusammenfassen",toSetP:"Auf Setpreis umstellen (Positionen ohne Preis)",toSetPc:"Der Set-Preis wird auf die Summe seiner Positionen gesetzt und die Positionen selbst verlieren ihren Preis. Das ist nicht rückgängig zu machen (der Betrag kann danach nur noch manuell geändert werden). Fortfahren?",toSetMc:"Jedes Set erhält die Summe seiner Positionen als Set-Preis; die Positionen des Sets werden ohne Preis dargestellt bzw. ausgeblendet. Positionen ausserhalb eines Sets bleiben unverändert einzeln aufgeführt. Das ist nicht rückgängig zu machen (die Set-Preise können danach nur noch manuell geändert werden). Fortfahren?",toSetMn:'Diese Rechnung enthält kein Set. Legen Sie zuerst über "Set-Struktur bearbeiten" ein Set an bzw. ordnen Sie Positionen einem Set zu.',iSum:"Zwischensumme",dtRel:"Freigegeben am: ",dtCr:"Erstellt am: ",rqV:"USt des Auftrags?",cthd:"wirklich aus-/einblenden ?",cst:{style:"currency",currency:"EUR"},sts:{IsWorkDone:"Arbeiten erledigt",Closed:"Auftrag geschlossen",SubcontractorPendingConfirmation:"Warten auf Bestätigung (Unterauftrag)",Scheduled:"Geplant",OfferIsRejected:"Angebot abgelehnt",OfferIsSend:"Offen (Angebot versandt)",CollaborationWaitingConfirmation:"Warten auf Bestätigung (Zusammenarbeit)",Released:"Freigegeben",OfferIsConfirmed:"Bestätigt",InProgress:"In Bearbeitung",ReadyForScheduling:"Zur Planung",Created:"Erstellt",Rejected:"Abgebrochen",Invoiced:"Rechnung gestellt","-":"-"},invHR:["Pos.","Menge","Artikelbezeichnung","VK","Summe"],frm:{invoicetitle:"Titel",invoiceaddress:"Adresse",loc:"Leistungsort / Lieferadresse",invoiceemail:"Email",invoiceemailcc:"Zusatzempfänger (CC)",provisionperiod:"Leistungsdatum / -zeitraum"},frmTT:{invoicetitle:"Rechnungstitel ändern",invoiceaddress:"Rechnungsempfänger-Adresse ändern",loc:"Leistungsort oder Lieferadresse ändern",invoiceemail:"Email-Adresse ändern und zusätzliche Email-Empfänger festlegen",provisionperiod:"Leistungsdatum oder -zeitraum ändern"}},$rcol={req:new fields_definition("Auftrag","Aufträge",[{name:"tags",label:"",type:"string",dfnc:function(e,t){""!==(e||"")&&($(this).aC("tags"),e.split(",").forEach((e=>{""!==e&&$(this).append($$.sc("tag "+e.replace(" ","_").replace("/","_").toLowerCase(),e))})))}},{name:"DateOfCreation",label:"Datum",type:"date",title:function(e){$(this).attr("title",$rct.dtCr+fdt(e.DateOfCreation).ne("-")+" \n"+$rct.dtRel+fdt(e.DateReleased).ne("-"))}},{name:"CustomerName",label:"Kunde (Firma)",type:"string"},{name:"Name",label:"Auftragsname",type:"string"},{name:"ExternalId",label:"Auftragsnummer",type:"string"},{name:"ParentExtenalId",label:"PAuftrag",type:"string"},{name:"InvoiceId",label:"RNummer",type:"string",dfnc:function(e,t){$(this).rwText(e," ").find("span").each((function(){$(this).aC("cla").click({id:$(this).text()},$inv.jdbn)}))}},{name:"State",label:"Status",type:"string"},{name:"WorkDoneAt",label:"Erledigt am",type:"date"},{name:"Description",label:"Beschreibung",type:"html"}]),itm:new fields_definition("Auftragsposition","Auftragspositionen",[{name:"NameOrNumber",label:"Bezeichnung",type:"string"},{name:"Type",label:"Typ",type:"select",required:!0,value:"Text",url:[{value:"Text",label:"Text"},{value:"Equipment",label:"Ausrüstung"},{value:"Material",label:"Material"},{value:"Service",label:"Arbeitsleistung"}],change:function(e){$req.quantChange.call(this,e)}},{name:"quantityhours",label:"Anzahl / Menge",type:"number",precision:"0.01",value:1,change:function(e){$inv.quantChange.call(this,e)}},{name:"UnitString",label:"Einheit",type:"select",url:["LFDM","Stck","Std.","QM","AW","Pauschal"],change:function(e){$inv.quantChange.call(this,e)}},{name:"net",label:"EinzelPreis netto",type:"number",precision:"0.01",value:0,change:function(e){$inv.quantChange.call(this,e)}},{name:"net_val",label:"GesamtPreis netto",type:"number",precision:"0.01",value:0},{name:"vat_val",label:"GesamtPreis USt",type:"number",precision:"0.01",value:0},{name:"svcnet_val",label:"Arbeitslohn netto",type:"number",precision:"0.01",value:0},{name:"svcvat_val",label:"Arbeitslohn USt",type:"number",precision:"0.01",value:0},{name:"net_pos",label:"Netto",type:"string"},{name:"bo_pos",label:"Brutto",type:"string"},{name:"vat",label:"USt",type:"string",value:"19,0%",change:function(e){$inv.quantChange.call(this,e)}},{name:"Note",label:"Details",type:"html",tinymce:!0}])},$ict={mdl:"Rechnungen",iov:{all:"Rechnungen (alle)","":"Rechnungen (nur fertige)","#d":"Rechnungen (nur Entwürfe)","#u":"Rechnungen (nur unbezahlt)","#r":"Rechnungen (nur angemahnt)","#a":"Rechnungen (nur Akonto)","#c":"Rechnungen (nur Storno)","#ru":"Rechnungen (nur angemahnt + unbez.)"},uba:", gesamter Zeitraum)",req:"Auftrag",inv:"Rechnung",rem:"Mahnung",in:"Rechnungsnummer",cc:"Kunde",wk:"Woche",nd:"Keine Daten gefunden.",dl:"Herunterladen",ed:"Bearbeiten",ced:"Bearbeitung fortsetzen",sItm:"Einzelheiten anzeigen",sPay:"Zahlungen anzeigen",cdI:"Entwurf der Rechnung löschen?",rel:"Neu Laden",relm:"Bitte laden Sie Liste manuell neu, um die Änderungen zu sehen.",dsp:"Rechnung anzeigen",storno:"Storno-Rechnung erstellen",credit:"Gutschrift erstellen",remd:"Mahnung erstellen",remdt:"Mahnung erstellen zur Rechnung {0}",remlst:"Mahnungen anzeigen",remdsp:"Mahnung anzeigen",remres:"Mahnung erneut senden",remresc:"Mahnung {0} wirklich erneut senden?",remresr:"Mahnung {0} wurde erfolgreich versandt.",setpyd:"Bezahlt markieren",cpyd:"Rechnung wirklich als bezahlt markieren?",setupd:"Bezahlt-Markierung aufheben",cupd:"Bezahlt-Markierung wirklich aufheben?",ivE:"Die Email-Adresse ist vermutlich nicht gültig.",ivEc:"\nMöchten Sie fortfahren?",pna:"Diese Seite ist in der Vorschau nicht verfügbar",tpe:"Die Anzahl von {0} Seiten wird aktuell nicht unterstützt",eis:"Der Rechnungsentwurf konnte nicht gespeichert werden.",pvw:"Das Dokument wird abgerufen und für die Vorschau aufbereitet.\nDer Vorgang kann bis zu 2 Minuten dauern.",pvf:"Die PDF-Vorschau konnte nicht erstellt werden.",pvto:"Der Server hat nicht rechtzeitig geantwortet (Zeitüberschreitung). Bitte versuchen Sie es erneut.",pvgone:"Der Entwurf ist auf dem Server nicht mehr vorhanden (Sitzung abgelaufen). Bitte öffnen Sie den Entwurf erneut.",iss:"Zwischenstand speichern.",p13b:"USt -> §13b",setm:"Set-Preisanzeige",setmo:{setprice:"Set mit Preis – Positionen ohne Preis",setonly:"Nur Set mit Preis – Positionen ausgeblendet"},setst:"Set-Struktur bearbeiten",setsHint:'Reihenfolge: Zeile per Drag & Drop an den oberen/unteren Rand einer anderen Zeile ziehen (davor/danach) oder ▲▼ nutzen. Zuordnung: Zeile auf die Mitte eines Sets ziehen (hinein) bzw. auf die Auftragszeile oder "oberste Ebene" (aus dem Set lösen); ◀▶ ändert die Ebene. Sets lassen sich über das Dreieck zu-/aufklappen und auch zugeklappt verschieben – ihre Positionen wandern mit. Änderungen werden sofort übernommen.',setsUp:"Nach oben (innerhalb der Ebene)",setsDown:"Nach unten (innerhalb der Ebene)",setsCollapse:"Set zuklappen",setsExpand:"Set aufklappen",setsHR:["","Pos.","Typ","Menge","Bezeichnung","Reihenfolge / Ebene"],setsRoot:"Hierher ziehen = aus dem Set lösen (oberste Ebene)",setsOut:"Eine Ebene höher (aus dem Set lösen)",setsIn:"Eine Ebene tiefer (dem vorangehenden Set zuordnen)",setsNew:"Neu:",setsInto:"in",setsTop:"oberste Ebene",setsTitle:"Bezeichnung",setsAdd:"Hinzufügen",setsNoTitle:"(ohne Bezeichnung)",settyp:{set:"Set",text:"Text",title:"Text",material:"Material",service:"Arbeitsleistung",equipment:"Ausrüstung",other:"Position",osum:"Zusammenfassung",intinvoiceallocation:"Abschlag",intinvoiceallocationdiff:"Abschlag (offen)"},ctp:"Ansprechpartner festlegen",mfr:"Von MFR neu abrufen",rq1:"Auftragsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",rq2:"Auftragsdaten werden geladen",iq1:"Rechnungsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",iq2:"Rechnungsdaten werden geladen",sis:"Rechnung als versandt markieren",srs:"Mahnung als versandt markieren",sisc:"Rechnung wirklich als versandt markieren?",srsc:"Mahnung wirklich als versandt markieren?",iSt:{dft:"Entwurf",uns:"nicht versandt",pyd:"bezahlt",cc:"storniert",op:"offen",due:"fällig",ovd:"überfällig",rem:"angemahnt"},rSt:["","Überfällig","2. Mahnung","3. Stufe"],pSt:{a:"Vollst.",p:"Teilz."},ivT:{i:"AbschlagsR.",f:"SchlussR",r:"Rechnung",c:"StornoR."},rovlh:"Übersicht der bisherigen Mahnungen",rovl:["Betreff","Betrag","Betrag gezahlt","fertiggestellt am"],remHR:["Rechnung","vom","Rechnungsbetrag","bereits bezahlt","noch offen"],translatePaymentTerm:e=>(e||"").replace("wd"," Werktagen").replace("d"," Tagen").replace("wk"," Wochen")||"10 Tagen",payi:{account:"Konto",name:"Zahler",text:"Verw.Zweck",InvoiceID:"Rechnung",amount:"Betrag",date:"Datum",manual:"Typ"}},$invcol={datev:new fields_definition("Rechnung","Rechnungen",[{name:"Umsatz (ohne Soll/Haben-Kz)",label:"Umsatz (ohne Soll/Haben-Kz)",type:"string"},{name:"vf",label:"vf",type:"string"},{name:"Soll/Haben-Kennzeichen",label:"Soll/Haben-Kennzeichen",type:"string"},{name:"Konto",label:"Konto",type:"string"},{name:"Gegenkonto",label:"Gegenkonto",type:"string"},{name:"BU-Schlüssel",label:"BU-Schlüssel",type:"string"},{name:"Belegdatum",label:"Belegdatum",type:"string"},{name:"Belegfeld 1",label:"Belegfeld 1",type:"string"},{name:"Belegfeld 2",label:"Belegfeld 2",type:"string"},{name:"Buchungstext",label:"Buchungstext",type:"string"}]),inv:new fields_definition("Rechnung","Rechnungen",[{name:"invstatus",label:"Status",type:"select",url:$ict.iSt},{name:"balance",label:"Umsatz",type:"string",dtype:"currency"},{name:"CustomerName",label:"Kunde",type:"string"},{name:"InvoiceId",label:"RNummer",type:"string"},{name:"InvoiceType",label:"Typ",type:"select",url:$ict.ivT},{name:"request",label:"Auftrag",type:"string",dtype:"num"},{name:"vat",label:"MwSt",type:"string",dtype:"num"},{name:"deb_cred",label:"Soll/Haben",type:"string"},{name:"customer",label:"Konto",type:"string",dtype:"num"},{name:"contra_account",label:"Gegenkonto",type:"string",dtype:"num"},{name:"Belegdatum",label:"Belegdatum",type:"date"},{name:"reminderstatus",label:"MahnStatus",type:"select",url:$ict.rSt},{name:"reminder",label:"# Mahnungen",type:"integer"},{name:"Buchungstext",label:"Buchungstext",type:"string"},{name:"Payment",label:"Zahlung",type:"string"}]),rem:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"amount",label:"Rechnungsbetrag",type:"number",precision:"0.01",value:1},{name:"amount_payed",label:"bereits bezahlt",type:"number",precision:"0.01",value:1}]),rem2:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"DocumentName",label:"Name",type:"string"},{name:"subject",label:"Betreff",type:"string"},{name:"DateSent",label:"Versanddatum",type:"date"},{name:"status",label:"Status",type:"string"},{name:"amount_open",label:"offener Betrag",type:"number",precision:"0.01"},{name:"InvoiceId",label:"RNummer",type:"string"}]),rid:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"type",label:"Typ",type:"select",url:[["f","einfache Zahlungserinnerung"],["m","Mahnung"],["l","letzte Mahnung"]],required:!0},{name:"level",label:"Stufe",type:"select",url:[["1","Stufe 1"],["2","Stufe 2"],["3","Stufe 3"],["4","Stufe 4"],["5","Stufe 5"],["6","Stufe 6"]],required:!0}]),ctp:new fields_definition("Ansprechpartner","Ansprechpartner",[{name:"name",label:"Name",type:"string"},{name:"email",label:"Email",type:"string"}])},gi=(e,t)=>$$.sc("glyphicon glyphicon-"+e).aC(t),$inv={init2:function(e,t){e=e||"inv",t=t||{},$ocms.getScript([],(function(){$inv.init3(e,t)}))},init3:async function(e,t){$fis.cf(!0);let n=$fis.lf(!0);$("#topbar").ocmsmenu([]),$("#activemodule").text($ict.mdl);let i=[(async()=>{await $fis.getAuth("fds_inv")>0&&($inv.prepLst(""),n.aC("fix"))})(),new Promise(((e,t)=>{$fis.prepAuth(["fds_reminder"])}))];await Promise.all(i)},prepLst:function(e){let t=new Date,n=$fis.lf(!0).ldng(1),i=new Date("2021-01-01");$fis.frm_list().IN((function(){}));let a=[];$.each($ict.iov,((e,t)=>{a.push({lbl:t,fnc:()=>{$inv.prepLst(e),n.aC("fix")}})})),$fis.lfm().ocmsmenu([{lbl:"Filter",itm:a}]);$$.i({placeholder:$ict.in}).appendTo($$.dc("mth ivn",n)).enterKey((function(e){let t=$(this),n=t.val()||"";e.stopPropagation(),t.parent().siblings().rC("selected"),n.length>3&&(t.parent().aC("selected"),$inv.renderinv("i:"+n,"s","all"),t.val(""))})),$$.i({placeholder:$ict.cc}).appendTo($$.dc("mth ivc",n)).enterKey((function(e){let t=$(this),n=t.val()||"";e.stopPropagation(),t.parent().siblings().rC("selected"),n.length>=3&&(t.parent().aC("selected"),$inv.renderinv("c:"+n,"s","all"),t.val(""))}));"#"===e.substr(0,1)&&$$.dc("mth extra",n).text($ict.iov[e].replace(")",$ict.uba)).click((function(t){let n=$(this);if(t.stopPropagation(),n.siblings().rC("selected"),!0===n.is(".selected")){n.toggleClass("selected");let t=fdt(new Date,"yy-MM-dd");$inv.renderinv(t,"a",e)}n.aC("selected")})),n.append("");let r=$$.dc("mthl",n),l=t.getFullYear(),s=t.getMonth()+1;for(let t=i.getFullYear();t<=l;t++){let n=$$.dc("yr").prependTo(r).text($ict.iov[e]+" - "+t.toString()).toggleClass("selected",t===l);n.click({yr:t},(function(e){e.stopPropagation(),n.siblings().rC("selected"),n.aC("selected")}));let a=$$.dc("mfrm",n);for(let n=0;n<(t!==l?12:s);n++){i=new Date(t,n,1);let r=$$.dc("mth").prependTo(a).text($ict.iov[e]+" - "+fdt(i,"MMM yyyy"));if(r.click({yr:t,mt:n},(function(t){if(t.stopPropagation(),r.siblings().rC("selected"),!0===r.is(".selected")){r.toggleClass("selected");let n=fdt(new Date(t.data.yr,t.data.mt,1),"yy-MM-dd");$inv.renderinv(n,"m",e)}r.aC("selected")})),""===e){$$.dc("mthdl",r).append(gi("compressed","ico")).click({yr:t,mt:n},(function(e){e.stopPropagation();let t=fdt(new Date(e.data.yr,e.data.mt,1),"yy-MM-dd");$inv.downloadzip(t,"m")}))}let l=getMonday(i),s=new Date(i);s.setMonth(s.getMonth()+1),s.setDate(0),s=getMonday(s);let d=$$.dc("wfrm",r);for(;l<=s;){let t=$$.dc("wk",d).text(($ict.wk||"W")+" "+fdt(l,"dd.MM.yy"));t.click({rd:new Date(l)},(function(n){n.stopPropagation();let i=fdt(n.data.rd,"yy-MM-dd");$inv.renderinv(i,"w",e),r.siblings().rC("selected").find(".wk").rC("selected"),r.aC("selected").find(".wk").rC("selected"),t.aC("selected")})),$$.dc("wkdl",t).append(gi("compressed","ico")).click({rd:new Date(l)},(function(e){e.stopPropagation();let t=fdt(e.data.rd,"yy-MM-dd");$inv.downloadzip(t,"w")})),l.setDate(l.getDate()+7)}}}n.ldng(0)},rerenderinv:function(){let e=$("#contentframe .invfrm:first");if(e.length>0){let t=e.data("sets")||{};t.mode&&$inv.renderinv(t.tgt,t.mode,t.includes)}},renderinv:function(e,t,n){let i=$fis.frm_list(!0,!0).ldng(1),a=$$.dc("invfrm",i).aC("md"+t).data("sets",$.extend({},{tgt:e,mode:t,includes:n})),r=$fis.lf();$ocms.postXT({url:$ocms.url("inv/invl"),data:{mode:t,tgt:e,includes:n},success:i=>{r.rC("fix").aC("hd"),$$.dc("ovhd",a).text(i.admin.title);let l=$$.tblset({},a),s=$invcol.inv,d=$$.tr(l.hd);$$.th(d);$.each(s.fields||[],((e,t)=>{$$.th(d).text(t.label),"vat"===t.name&&$$.th(d)})),$.each(i.invoices||[],((d,c)=>{let o=$$.tr(l.bdy);o.click((function(){r.rC("fix").aC("hd"),o.toggleClass("selected").siblings().rC("selected").find("td.av").rC("av"),o.find("td.av").rC("av"),!0===o.is(".selected")?$inv.iMn(c):$inv.eM()}));let u=$$.td(o,{class:"raux"});c.hasFile?($$.dc("idl ilbtn",u,{title:$ict.dl+"\n"+c.DocumentName}).append(gi("save-file","ico")).click({id:c.Id},$inv.downloadinv),$$.dc("idl ilbtn",u,{title:$ict.dsp+"\n"+c.DocumentName}).append(gi("eye-open","ico")).click({id:c.Id,typ:"inv"},$inv.jdisp)):!1===c.isFinal&&!0===$fis.isAuth("fds_inv",2)&&$$.dc("idl ilbtn",u,{title:$ict.ed}).append(gi("edit","ico")).click({id:c.Id},$inv.doContInv),$$.dc("iitm ilbtn",u,{title:$ict.sItm}).append(gi("list","ico")).click({id:c.Id},$inv.showitm),$$.dc("iitm ilbtn",u,{title:$ict.sPay}).append(gi("euro","ico")).click({id:c.Id},$inv.showpay),$.each(s.fields||[],((r,l)=>{let s,d,u=$$.td(o).aC(l.dtype);switch("select"===(l.type||"")?u.text((l.url||{})[c[l.name]]||""):u.text(c[l.name]),l.name||""){case"vat":s=$$.sel().appendTo($$.td(o,{class:"vsel"})),d=(i.admin.ust_options||"19,0%;16,0%;0,0%").split(";"),$.each(d,((e,t)=>{$$.opt(t,t).appendTo(s)})),s.click((function(e){e.stopPropagation()})).val(c[l.name]).change().change({frm:a,tgt:e,mode:t,id:c.Id,td:u,includes:n},$inv.setvat),u.toggleClass("hl",c[l.name].substr(0,2)!==d[0].substr(0,2)).click((function(e){e.stopPropagation(),$(this).toggleClass("av")}));break;case"balance":u.aC("sh_"+(c.SollHaben||"").toLowerCase());break;case"invstatus":case"reminderstatus":u.aC(("invstatus"===l.name?"is_":"rs_")+c[l.name])}}))}))},complete:()=>{i.ldng(0)}})},setvat:function(e){let t=$(this),n=e.data||{};$ocms.postXT({url:$ocms.url("inv/setvat"),data:{id:n.id,val:t.val()},success:e=>{n.td.rC("av"),$inv.renderinv(n.tgt,n.mode,n.includes)}})},downloadzip:function(e,t){$(this).empty();window.open($ocms.url("inv/datevzip?mode="+t+"&tgt="+encodeURIComponent(e)),"_blank")},showitm:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&$ocms.postXT({url:$ocms.url("inv/rqi"),data:{id:e.data.id},success:e=>{let t=$$.dc("rfrm");(e.requests||[]).length<1?t.text($ict.nd):$.each(e.requests||[],(function(e,n){let i=$$.dc("srq",t);$$.dc("nme",i).text(n.name);let a=$$.tblset({class:"if"},i);$.each(n.items||[],((e,t)=>{let n=$$.tr({id:"itm"+t.Id}).appendTo(a.bdy);$$.td(n).text(t.NameOrNumber),$$.td(n).text(t.Type),$$.td(n).aC("currency").text(t.net_pos),$$.td(n).aC("currency").text(t.bo_pos),$$.td(n).aC("num").text(t.vat)}))})),$ocms.dlg(t,{width:1e3})}})},showpay:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&$ocms.postXT({url:$ocms.url("inv/pyi"),data:{id:e.data.id},success:e=>{let t=$$.dc("rfrm");if((e.payments||[]).length<1)t.text($ict.nd);else{let n=$$.tblset({class:"if"},t),i=$$.tr(n.hd);$.each(["date","account","name","text","InvoiceID","amount","manual"],((e,t)=>{$$.th(i,$ict.payi[t])})),$.each(e.payments,((e,t)=>{let i=$$.tr({id:"itm"+t.banking_uid}).appendTo(n.bdy);$$.td(i).aC("date").text(t.date),$$.td(i).text(t.account),$$.td(i).text(t.name),$$.td(i).text(t.text),$$.td(i).text(t.InvoiceID),$$.td(i).aC("currency").text(t.amount),$$.td(i).text(t.manual)}))}$ocms.dlg(t,{width:1e3,title:"Übersicht der Zahlungen"})}})},downloadinv:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&window.open($ocms.url("inv/rdoc?id="+e.data.id),"_blank")},doContInv:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&$inv.cntInv({id:e.data.id})}},$$inv={init2:$inv.init2,auth:{}};export default $$inv;$inv.cInv=function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&!1!==$fis.isAuth("fds_inv",2)&&$inv.cInv2({id:e.data.id})},$inv.rMn=e=>{let t=[{lbl:$ict.req,itm:[]}];return!0===bool(e,!1)&&!0===$fis.isAuth("fds_inv",2)&&Array.prototype.push.apply(t[0].itm,[{lbl:$rct.crI,fnc:$inv.ccInv,data:{typ:"r"}},{lbl:$rct.crII,fnc:$inv.ccInv,data:{typ:"i"}}]),t.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(t)},$inv.iMnr=e=>{let t=booln(e.isFinal,!0),n=e.Id,i=booln(e.fds,!1),a=[{glyph:"glyphicon-menu-left",fnc:()=>{$fis.frm_edit().remove()}},{lbl:$ict.inv,itm:[]},{lbl:$ict.rem,itm:[]}];return!1===t&&!0===$fis.isAuth("fds_inv",2)?a[1].itm.push({lbl:$ict.ced,fnc:$inv.clCntInv}):!0===$fis.isAuth("fds_inv",1)&&a[1].itm.push({lbl:$ict.dsp,fnc:()=>$inv.disp(n,"inv")}),!0===i&&!0===t&&!0===$fis.isAuth("fds_inv",2)&&(a[1].itm.push({lbl:$ict.storno,fnc:()=>$inv.storno(n,i)}),a[1].itm.push({lbl:$ict.credit,fnc:()=>$inv.credit(n,i)})),!0===t&&!0===$fis.isAuth("fds_reminder",2)&&(a[2].itm.push({lbl:$ict.remd,fnc:()=>$inv.ccRem(n,e.InvoiceId)}),a[2].itm.push({lbl:$ict.remlst,fnc:()=>$inv.dspRem(n)})),!0===t&&!0===$fis.isAuth("fds_reminder",2)&&!1===booln(e.IsSent,!1)&&a[2].itm.push({lbl:$ict.srs,fnc:()=>$inv.srs(n)}),a.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(a)},$inv.iMn=e=>{let t=booln(e.isFinal,!0),n=e.Id,i=booln(e.fds,!1),a=[{glyph:"glyphicon-menu-left",fnc:()=>{$fis.frm_edit().remove()}},{lbl:$ict.inv,itm:[]},{lbl:$ict.rem,itm:[]}];return!1===t&&!0===$fis.isAuth("fds_inv",2)?a[1].itm.push({lbl:$ict.ced,fnc:()=>{$inv.cntInv({id:n})}}):!0===$fis.isAuth("fds_inv",1)&&a[1].itm.push({lbl:$ict.dsp,fnc:()=>$inv.disp(n,"inv")}),!0===$fis.isAuth("fds_inv",2)&&(a[1].itm.push({lbl:$ict.storno,fnc:()=>$inv.storno(n,i)}),a[1].itm.push({lbl:$ict.credit,fnc:()=>$inv.credit(n,i)})),!0===t&&!1===booln(e.IsPayed,!1)?(!0===$fis.isAuth("fds_reminder",2)&&a[2].itm.push({lbl:$ict.remd,fnc:()=>$inv.ccRem(n,e.InvoiceId)}),!0===$fis.isAuth("fds_inv",2)&&a[1].itm.push({lbl:$ict.setpyd,fnc:()=>$inv.setPyd(n)})):!0===t&&!0===booln(e.IsPayed,!1)&&"m"===(e.PaymentStatus||"")&&!0===$fis.isAuth("fds_inv",2)&&a[1].itm.push({lbl:$ict.setupd,fnc:()=>$inv.setUpd(n)}),!0===$fis.isAuth("fds_reminder",2)&&a[2].itm.push({lbl:$ict.remlst,fnc:()=>$inv.dspRem(n)}),!0===t&&!0===$fis.isAuth("fds_inv",2)&&!1===booln(e.IsSent,!1)&&a[1].itm.push({lbl:$ict.sis,fnc:()=>$inv.sis(n)}),!1===i&&a[1].itm.push({lbl:$ict.mfr,fnc:()=>$inv.mfrrel(n)}),$("#topbar").ocmsmenu(a)},$inv.emOpt=()=>"iss,p13b,ctp,setst,setm",$inv.eM=(e,t,n)=>{let i=[];return!0!==booln(e,!1)&&!0!==booln(t,!1)||i.push({glyph:"glyphicon-menu-left",fnc:()=>{$fis.lf(!0),$fis.frm_edit().remove()}}),!0===(n||"").split(",").includes("iss")&&i.push({lbl:$ict.iss,fnc:$inv.ssave}),!0===(n||"").split(",").includes("ctp")&&i.push({lbl:$ict.ctp,fnc:$inv.sctp}),!0===(n||"").split(",").includes("p13b")&&i.push({lbl:$ict.p13b,fnc:$inv.sp13b}),!0===(n||"").split(",").includes("setm")&&i.push({lbl:$ict.setm,fnc:$inv.ssetmode}),!0===(n||"").split(",").includes("setst")&&i.push({lbl:$ict.setst,fnc:()=>$inv.sets.open()}),!0===(n||"").split(",").includes("iss")&&(i.push({lbl:"Änderungshistorie",fnc:()=>$inv.d.history()}),i.push({lbl:"Änderungen verwerfen",fnc:()=>$inv.d.discard()})),!0===booln(e,!1)&&i.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(i)},$inv.pdfPreviewTimeout=12e4,$inv.pdfPreviewFailed=function(e,t){if(11110===(e||{}).internalCode)return void $ocms.login.dlg();let n=((e||{}).internalText||"").trim();""===n&&"timeout"===t&&(n=$ict.pvto),""===n&&410===(e||{}).status&&(n=$ict.pvgone),alert(($ict.pvf||$t.f1)+(""!==n?"\n"+n:""))},$inv.pdfPreviewComplete=function(e,t){return(n,i)=>{t&&t.c.trigger("modal_close"),e&&e.rC("freeze"),"timeout"===i&&$inv.pdfPreviewFailed(n,i)}},$inv.pdfWaitDlg=function(){let e=$ocms.dlg($$.dc("rfrm").ldng(1),{exclusive:!1,zindex_min:50});return e&&e.ft.rwText($ict.pvw),e},$inv.d={tbl:()=>$("div.invoice_layout table.invi"),layout:()=>$("div.invoice_layout"),token:function(){return $inv.d.tbl().data("dtoken")||""},hashes:function(){let e=$inv.d.tbl().data("bai")||[],t={};return $.each(e,((e,n)=>{t[(n.Id||"").toString()]=JSON.stringify(n)})),t},seed:function(e){let t=$inv.d.layout();t.aC("freeze");let n=$ocms.postXT({url:$ocms.url("inv/dopen"),data:{payload:JSON.stringify(e)},success:e=>{$inv.d.tbl().data("dtoken",e.token).data("dver",e.version).data("dhashes",$inv.d.hashes()).data("dorder",$inv.d.order()),$fis.draft.bind(e.token,{onReady:()=>$inv.d.refresh(),onExpiring:e=>$inv.d.warnExpiry(e),onClosed:e=>$inv.d.closed(e)}),$inv.d.refresh()},error:()=>{t.rC("freeze")},complete:()=>{$inv.d.tbl().removeData("dseeding").removeData("dseedpromise")}});return $inv.d.tbl().data("dseedpromise",n),n},refresh:function(e){let t=$inv.d.token();""!==t&&$ocms.postXT({url:$ocms.url("inv/dstate"),data:{token:t},success:t=>{$inv.d.applyState(t),"function"==typeof e&&e(t)},error:e=>{e&&410===e.status&&$inv.d.closed("expired")},complete:()=>{$inv.d.layout().rC("freeze")}})},applyState:function(e){let t=$inv.d.tbl();if(t.length<1)return;let n=t.data("dver");"number"==typeof n&&"number"==typeof e.version&&e.version$$.dc("dnote").aC(e.style||"InvoiceNotes").text(e.text)))},applyItems:function(e,t){let n=e=>void 0===e?null:e;(t||[]).forEach((t=>{if(!t)return;let i=(t.Id||"").toString();if(""===i)return;let a=e.children("tbody").filter(((e,t)=>(($(t).data()||{}).Id||"").toString()===i)).first();if(a.length<1)return;let r=t.itm||[],l={},s=a.find("tr.title").first(),d=s.length?s:null;r.forEach((e=>{let t=(e.id||"").toString();if(""===t)return;l[t]=!0;let i=a.find("#itm"+t).first(),r=i.length<1;r&&(i=$$.tr(a,{id:"itm"+t,class:"itm"}));let s=i.data()||{},c=r||(s.Type||"")!==(e.typ||"")||s.net!==n(e.v)||s.net_val!==n(e.vt)||s.vat_val!==n(e.vv)||s.svcnet_val!==n(e.vs)||s.svcvat_val!==n(e.vsv)||(s.position||"")!==(null!=e.p?e.p:"")||(s.lvl||0)!==(e.lvl||0)||(s.SetItmId||null)!==(null!=e.SetItmId?e.SetItmId:null);$.extend(s,{Id:t,Type:e.typ,net:n(e.v),net_val:n(e.vt),vat_val:n(e.vv),svcnet_val:n(e.vs),svcvat_val:n(e.vsv),vat:e.vat,position:null!=e.p?e.p:"",SetItmId:null!=e.SetItmId?e.SetItmId:null,lvl:e.lvl||0}),r&&$.extend(s,{htmltext:e.t,quantity:e.q}),i.data(s),d?i.prev()[0]!==d[0]&&i.insertAfter(d):a.children().first()[0]!==i[0]&&a.prepend(i),d=i,c&&$inv.rrw.call(i)})),a.find("tr.itm").each(((e,t)=>{let n=(($(t).data()||{}).Id||"").toString();""===n||l[n]||$(t).remove()}))}))},applySetDisplay:function(e,t){e.find("tr.itm").each(((e,n)=>{let i=$(n),a=((i.data()||{}).Id||"").toString();if(""===a||!Object.prototype.hasOwnProperty.call(t,a))return;let r=t[a]||{};i.tC("sethdr",bool(r.h,!1)),!1===bool(r.p,!0)&&i.find("td.currency").text("")}))},sync:function(e){let t=$inv.d.token();if(""===t){let t=$inv.d.tbl().data("dseedpromise");return t?$.when(t).then((()=>$inv.d.sync(e))):$.when()}return $inv.d.layout().aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dpatch"),data:{token:t,delta:JSON.stringify(e)},success:()=>{$inv.d.refresh()},error:e=>{$inv.d.layout().rC("freeze"),e&&410===e.status&&$inv.d.closed("expired")}})},order:function(){return($inv.d.tbl().data("bai")||[]).map((e=>(e.Id||"").toString()))},syncChanged:function(e){let t=e.data("bai")||[],n=e.data("dhashes")||{},i={},a=[],r=[],l=[];$.each(t,((e,t)=>{let r=(t.Id||"").toString(),l=JSON.stringify(t);i[r]=l,n[r]!==l&&a.push(t)})),$.each(n,(e=>{void 0===i[e]&&r.push(e)}));let s=$inv.d.order(),d=e.data("dorder")||[];return e.data("dhashes",i).data("dorder",s),a.forEach((e=>l.push($inv.d.sync({Target:"block.replace",Ref:(e.Id||"").toString(),Value:e})))),r.forEach((e=>l.push($inv.d.sync({Target:"block.remove",Ref:e})))),d.length===s.length&&d.slice().sort().join(",")===s.slice().sort().join(",")&&d.join(",")!==s.join(",")&&l.push($inv.d.sync({Target:"block.order",Value:s})),$.when.apply($,l).promise()},syncField:function(e,t){let n={invoicetitle:"title",invoiceaddress:"address",invoiceemail:"email",invoiceemailcc:"emailcc",loc:"provisionlocation",provisionlocation:"provisionlocation",provisionperiod:"provisionperiod"}[e];n&&$inv.d.sync({Target:n,Value:t})},footer:function(e,t,n){let i=e.children("tfoot").empty();e.nextAll(".fnote").remove();let a=bool(n.p13b,!1),r=(e,t,n)=>$$.tdc("currency",$$.tr(i,{class:n||"tsum"}).append([$$.tdc("aux"),$$.td({colspan:4}).text(e)]),fnum(t,$rct.cst)),l=t=>$$.dc("fnote").insertAfter(e).rwText(t);r("Netto",t.total_net||0),!1===a&&$.each(t.vat||{},((e,t)=>r($rct.vat+" "+e+"%",t,"tvat"))),r("Summe",t.total_gross||0);let s=n.type||"";"i"===s?(l($rct.note2),l($rct.note4)):"c"===s?l($rct.note2):(l(string($rct.note3,[fnum(((t.service_net||0)+(t.service_vat||0))*(n.tax_servicerefund||0),$rct.cst)])).aC("ntax"),l($rct.note2),l(string($rct.note1,[fnum((t.service_net||0)+(t.service_vat||0),$rct.cst),fnum(t.service_net||0,$rct.cst),fnum(t.service_vat||0,$rct.cst)]))),!0===a&&l($rct.note13b)},validation:function(e){let t=$("div.invoice_layout");if(t.length<1)return;let n=t.children(".dvalidation");n.length<1&&(n=$$.dc("dvalidation"),t.prepend(n)),n.empty().tC("hidden",(e||[]).length<1),$.each(e||[],((e,t)=>$$.dc("dvmsg",n).aC(t.severity).text(t.message)))},preview:function(){let e=$inv.d.token();if(""===e)return;let t=$inv.d.layout(),n=($inv.d.tbl().data("new")||{}).invoiceemail||"";!1===$fis.ValidateEmail(n)&&!1===bool(confirm($ict.ivE+$ict.ivEc),!1)||(t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dpreview"),data:{token:e},timeout:$inv.pdfPreviewTimeout,success:n=>{t.rC("freeze");let i=$$.dc("imagecollection pdfpreview"),a=Math.round(.88*vh()),r=n.total;r>10&&$$.dc("note warn",i).text($ict.tpe),$.each(n.img||[],((e,t)=>{$$.dc("pdfp",i).append($$.img(t).css("max-height",(a-rpx(6)).toString()+"px"))}));for(let e=(n.img||[]).length+1;e<=r;e++)$$.dc("pdfp ph",i).append($$.dc("note",$ict.pna));$ocms.dlg(i,{size:[a,Math.round(.88*vw())],zindex:50,form:!1,button:$rct.crI,confirm:function(n){let i=$(this);t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dsave"),data:{token:e},success:e=>{$ocms.postXT({url:$ocms.url("req/sconf"),data:{id:e.invid},success:t=>{i.trigger("modal_close"),!0===t.hasFile&&window.open($ocms.url("req/idoc")+"?id="+e.invid,"_blank"),$inv.d.close(),$ocms.init("req"),$inv.rReload()},error:()=>{alert($t.f1),i.trigger("modal_close")},complete:()=>{t.rC("freeze")}})},error:()=>{t.rC("freeze"),alert($ict.eis)}})},cancel:function(e){confirm($ict.cdI)&&($inv.d.close(),$inv.rReload())}})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(t)}))},save:function(){let e=$inv.d.token();if(""===e)return;let t=$inv.d.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dsave"),data:{token:e},success:e=>{$inv.d.tbl().data("invid",e.invid)},error:()=>{alert($ict.eis)},complete:()=>{t.rC("freeze")}})},history:function(){let e=$inv.d.token();""!==e&&$ocms.postXT({url:$ocms.url("inv/dhistory"),data:{token:e},success:e=>{let t=$$.dc("dhist");if((e.history||[]).length<1)$$.dc("note",t).text("Noch keine Änderungen erfasst.");else{let n=$$.tblset({class:"invtbl fullwidth"},t);$$.tr(n.hd).append([$$.th().text("Zeit"),$$.th().text("Feld"),$$.th().text("Alt"),$$.th().text("Neu")]),$.each(e.history,((e,t)=>$$.tr(n.bdy).append([$$.tdc("keep",fdt(t.timestamp)),$$.td().text(t.target),$$.td().text(t.oldValue),$$.td().text(t.newValue)])))}$ocms.dlg(t,{width:800,form:!1})}})},discard:function(){let e=$inv.d.tbl().data("invid")||"";""!==e?!1!==confirm("Alle Änderungen verwerfen und den zuletzt gespeicherten Stand neu laden?")&&($inv.d.close(),$inv.cntInv({id:e})):alert("Es wurde noch kein Zwischenstand gespeichert, der wiederhergestellt werden könnte.")},warnExpiry:function(e){let t=Math.max(1,Math.round((e||0)/60));$fis.notifications.push({severity:"info",title:"Entwurf läuft ab",message:"Der Rechnungsentwurf läuft in etwa "+t+" Minute(n) ab. Bitte zwischenspeichern, sonst gehen die Änderungen verloren."})},closed:function(e){let t=$inv.d.token();$inv.d.tbl().removeData("dtoken"),""!==t&&$fis.draft.release(t),$fis.frm_edit().remove(),$fis.lf(!0),$fis.notifications.push({severity:"error",title:"Entwurf geschlossen",message:"expired"===e?"Der Rechnungsentwurf ist wegen Inaktivität abgelaufen. Nicht gespeicherte Änderungen sind verloren.":"Der Rechnungsentwurf wurde geschlossen."});try{$inv.rReload()}catch(e){}},close:function(){let e=$inv.d.token();""!==e&&($ocms.postXT({url:$ocms.url("inv/dclose"),data:{token:e}}),$fis.draft.release(e)),$inv.d.tbl().removeData("dtoken")}},$inv.rd={tbl:()=>$("div.invoice_layout table.invi"),layout:()=>$("div.invoice_layout"),token:function(){return $inv.rd.tbl().data("rdtoken")||""},seed:function(e){let t=$inv.rd.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dopen"),data:{payload:JSON.stringify(e)},success:e=>{$inv.rd.tbl().data("rdtoken",e.token).data("rdver",e.version),$fis.draft.bind(e.token,{onReady:()=>$inv.rd.refresh(),onExpiring:e=>$inv.rd.warnExpiry(e),onClosed:e=>$inv.rd.closed(e)}),$inv.rd.refresh()},error:()=>{t.rC("freeze")}})},refresh:function(e){let t=$inv.rd.token();""!==t&&$ocms.postXT({url:$ocms.url("rem/dstate"),data:{token:t},success:t=>{$inv.rd.applyState(t),"function"==typeof e&&e(t)},error:e=>{e&&410===e.status&&$inv.rd.closed("expired")},complete:()=>{$inv.rd.layout().rC("freeze")}})},applyState:function(e){let t=$inv.rd.tbl();if(t.length<1)return;let n=t.data("rdver");"number"==typeof n&&"number"==typeof e.version&&e.version{let t=$$[0]("p").aC("dnote intro").rwText(e);a.length?t.insertBefore(a):t.appendTo(n)})),((e||{}).closing||[]).forEach((e=>$$[0]("p").aC("dnote closing").rwText(e).appendTo(n)))},sync:function(e){let t=$inv.rd.token();""!==t&&($inv.rd.layout().aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dpatch"),data:{token:t,delta:JSON.stringify(e)},success:()=>{$inv.rd.refresh()},error:e=>{$inv.rd.layout().rC("freeze"),e&&410===e.status&&$inv.rd.closed("expired")}}))},syncField:function(e,t){if(""===$inv.rd.token())return;let n={subject:"subject",invoiceaddress:"address",invoiceemail:"email",text:"text"}[e];n&&$inv.rd.sync({Target:n,Value:t})},syncAmount:function(e,t){""!==$inv.rd.token()&&($inv.rd.sync({Target:"amount",Value:(null!=e?e:0).toString()}),$inv.rd.sync({Target:"amount_payed",Value:(null!=t?t:0).toString()}))},footer:function(e,t){let n=e.children("tfoot").empty(),i=$$.tr(n,{class:"tsum"}).append([$$.tdc("aux"),$$.td({colspan:4}).text("Offener Betrag")]);$$.tdc("currency",i,fnum(t.amount_open||0,$rct.cst))},validation:function(e){let t=$inv.rd.layout();if(t.length<1)return;let n=t.children(".dvalidation");n.length<1&&(n=$$.dc("dvalidation"),t.prepend(n)),n.empty().tC("hidden",(e||[]).length<1),$.each(e||[],((e,t)=>$$.dc("dvmsg",n).aC(t.severity).text(t.message)))},preview:function(){let e=$inv.rd.token();if(""===e)return;let t=$inv.rd.layout(),n=($inv.rd.tbl().data("new")||{}).invoiceemail||"";!1===$fis.ValidateEmail(n)&&!1===bool(confirm($ict.ivE+$ict.ivEc),!1)||(t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dpreview"),data:{token:e},timeout:$inv.pdfPreviewTimeout,success:n=>{t.rC("freeze");let i=$$.dc("imagecollection pdfpreview"),a=Math.round(.88*vh());$.each(n.img||[],((e,t)=>{$$.dc("pdfp",i).append($$.img(t).css("max-height",(a-rpx(6)).toString()+"px"))})),$ocms.dlg(i,{size:[a,Math.round(.88*vw())],zindex:50,form:!1,button:$ict.remd,confirm:function(n){let i=$(this);t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dsave"),data:{token:e},success:e=>{$ocms.postXT({url:$ocms.url("rem/conf"),data:{id:e.remid},success:()=>{i.trigger("modal_close"),window.open($ocms.url("rem/idoc")+"?id="+e.remid,"_blank"),$inv.rd.close(),$ocms.init("req"),$inv.rReload()},error:()=>{alert($t.f1),i.trigger("modal_close")},complete:()=>{t.rC("freeze")}})},error:()=>{t.rC("freeze"),alert($t.f1)}})},cancel:function(e){confirm($ict.cdI)&&($inv.rd.close(),$inv.rReload())}})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(t)}))},save:function(){let e=$inv.rd.token();if(""===e)return;let t=$inv.rd.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dsave"),data:{token:e},success:e=>{$inv.rd.tbl().data("remid",e.remid)},error:()=>{alert($t.f1)},complete:()=>{t.rC("freeze")}})},history:function(){let e=$inv.rd.token();""!==e&&$ocms.postXT({url:$ocms.url("rem/dhistory"),data:{token:e},success:e=>{let t=$$.dc("dhist");if((e.history||[]).length<1)$$.dc("note",t).text("Noch keine Änderungen erfasst.");else{let n=$$.tblset({class:"invtbl fullwidth"},t);$$.tr(n.hd).append([$$.th().text("Zeit"),$$.th().text("Feld"),$$.th().text("Alt"),$$.th().text("Neu")]),$.each(e.history,((e,t)=>$$.tr(n.bdy).append([$$.tdc("keep",fdt(t.timestamp)),$$.td().text(t.target),$$.td().text(t.oldValue),$$.td().text(t.newValue)])))}$ocms.dlg(t,{width:800,form:!1})}})},warnExpiry:function(e){let t=Math.max(1,Math.round((e||0)/60));$fis.notifications.push({severity:"info",title:"Entwurf läuft ab",message:"Der Mahnentwurf läuft in etwa "+t+" Minute(n) ab. Bitte zwischenspeichern, sonst gehen die Änderungen verloren."})},closed:function(e){let t=$inv.rd.token();$inv.rd.tbl().removeData("rdtoken"),""!==t&&$fis.draft.release(t),$fis.frm_edit().remove(),$fis.lf(!0),$fis.notifications.push({severity:"error",title:"Entwurf geschlossen",message:"expired"===e?"Der Mahnentwurf ist wegen Inaktivität abgelaufen. Nicht gespeicherte Änderungen sind verloren.":"Der Mahnentwurf wurde geschlossen."});try{$inv.rReload()}catch(e){}},close:function(){let e=$inv.rd.token();""!==e&&($ocms.postXT({url:$ocms.url("rem/dclose"),data:{token:e}}),$fis.draft.release(e)),$inv.rd.tbl().removeData("rdtoken")}},$inv.cInv2=function(e){let t=$$.dc("rfrm").ldng(1),n=$ocms.dlg(t,{width:1e3});n&&n.ft.rwText($rct.rq1);let i=()=>{$ocms.postXT({url:$ocms.url("req/get"),timeout:60,data:{id:e.id,mode:"r"},success:t=>{t.admin=t.admin||{};let n=$fis.lf(!0).aC("fix").rC("hd");if($fis.frm_edit().IN(),$inv.eM(!0,!0),(t.requests||[]).length<1)n.aC("fix").text($rct.nd);else{$$.dc("lh",n,$rct.mdl);let i=$$.d(),a=$$.ul({class:"rql"}).data({search:e.id,parent:t.admin.parent}).appendTo(n),r={},l=$rcol.req.lbl();$.each(t.requests||[],(function(e,t){let n=$$.li({class:"cli rli"}).data($.extend({},t)).appendTo(a),s=$$.dc("lihd",n).addClass(t.state);!0===booln(t.open,!1)&&s.append($$.sc("cbox").click((()=>{n.tC("checked"),i.find("li").rC("checked"),!0===n.is(".checked")?$inv.rMn(t.open):$inv.eM(!0)}))),s.append([$$.sc("eid",t.ExternalId),$$.sc("nme",t.Name)]),$$.dc("lidt",n).append([$$.dc("rqs").append([$$.s(l.State+": "),$$.s($rct.sts[t.State||"-"])]),$$.dc("ivn").append([$$.s(l.InvoiceId+": "),$$.s(t.InvoiceId||"- -")]),$$.dc("wda").append([$$.s(l.WorkDoneAt+": "),$$.s(fdt(t.WorkDoneAt,"dd.MM.yyyy"))])]),r[t.Id]=n})),(t.inv||[]).length>0&&($$.dc("lh",n,$rct.invs),i=$$.ul({class:"ivl"}).appendTo(n),$.each(t.inv||[],((e,t)=>{let n=$$.li({class:"cli ili"}).data($.extend({},t)).appendTo(i),r=$$.dc("lihd",n).addClass(t.invstatus);!1===booln(t.isFinal,!0)?r.append($$.sc("cbox").click((()=>{""!==(t.Id||"")&&(n.tC("checked").siblings().rC("checked"),a.find("li").rC("checked"),!0===n.is(".checked")?$inv.iMnr(t):$inv.eM(!0))}))):["","dft"].indexOf(t.invstatus)<0&&r.append($$.sc("dli").click((function(){$inv.disp(t.Id,"inv")}))),r.append($$.sc("nme",t.DocumentName||t.Id)),$$.dc("lidt",n).append([$$.dc("wda").append([$$.s(fdt(t.DateCreated,"dd.MM.yyyy"))]),$$.d().text($ict.iSt[t.invstatus]||t.invstatus)])})))}},complete:()=>{n&&n.c.trigger("modal_close")}})};$ocms.postXT({url:$ocms.url("req/pget"),timeout:90,data:{id:e.id},success:e=>{n&&n.ft.rwText($rct.rq2),i()},error:()=>{confirm($rct.rq1f)?(n&&n.ft.rwText($rct.rq2),i()):n&&n.c.trigger("modal_close")}})},$inv.ccInv=function(e){let t=(e.data||{}).typ||"r",n=$fis.lf(),i=n.children("ul.rql"),a=i.data("parent"),r=[];if(i.find("li.rli.checked").each((function(){r.push($(this).data("Id"))})),r.length<1)return void alert($rct.dnS);if("i"===t&&r.length>1)return void alert($rct.dII);let l=$fis.frm_edit(),s=$$.dc("invoice_layout",l).append($$.dc("btn sprev").click($inv.sprev)),d=$fis.cf().width()>s.width()+n.width()+20;n.tC("fix",d).tC("hd",!d),$inv.eM(!1,!0);let c=$$.dc("rfrm").ldng(1),o=$ocms.dlg(c,{width:1e3});o.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("req/iget"),timeout:60,data:{id:a,mode:"ful",typ:t,sel:r.join(",")},success:e=>{let t=$$.dc("srq",s),n=$$.tblset({class:"invi"},t);n.bdy.remove(),n.ft=$$[0]("tfoot"),e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b")),n.tbl.data($.extend({new:{},sms:{},itm:{}},{admin:e.admin,companies:e.companies,locations:e.locations}));let i=$$.tr(n.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(i,e))),n.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.requests||[],(function(t,i){if(0!==(i.Id||0)){let t=$inv.worknotes(i);i.text="i"===e.admin.type?$rct.req+jine([i.ExternalId,i.Name],": ").eine(" ",""):jine([jine([fdt(i.WorkDoneAt,"dd.MM.yy"),i.ExternalId]," - "+$rct.req+" "),t.ne(i.Name)],": \n");let a=$$.tbody(n.tbl).data($.extend({},i));$inv.rendersrq.call(a)}}));let a=$$.tr($$.tbody(n.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(a),n.ft.appendTo(n.tbl);let r,l,d=e.admin||{},c=(e,t,i,a,r)=>{let l=$$.dc("inpfrm",s).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(t);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{n.tbl.data("new")[i]=e}},r),$inv.eHtml)),n.tbl.data("new")[i]=t};c("tfrm",d.invoicetitle,"invoicetitle",0,null),c("adrfrm",d.invoiceaddress,"invoiceaddress",0,null),c("locfrm","","loc",1,{list:deepCopy(e.locations),lbl:"ref",property:"address"}),$inv.emailFrm(s,n,d.invoiceemail,d.invoiceemailcc),$$.dc("sndfrm",s).append($$.dc("content").text(d.sender)),d.provisionend&&(l=d.provisionstart?$rct.provP:$rct.provD,r=d.provisionstart?fdt(d.provisionstart,"dd.MM.yyyy")+" - "+fdt(d.provisionend,"dd.MM.yyyy"):fdt(d.provisionend,"dd.MM.yyyy")),c("admfrm",r,"provisionperiod",l,1),n.tbl.data("new").CustomValues=d.CustomValues||"",$$.dc("inpfrm ctpfrm",s).text(jObj(d.CustomValues,"contactName")),n.tbl.children("tbody").each($inv.bdysort),n.tbl.trigger("fds.inv"),$inv.eM(!1,!0,$inv.emOpt())},complete:()=>{o.c.trigger("modal_close")}})},$inv.ccStInv=function(e){let t=e.data||{},n=$fis.lf(),i=t.id,a=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sprev)),r=$fis.cf().width()>a.width()+n.width()+20;n.tC("fix",r).tC("hd",!r),$inv.eM(!1,!0);let l=$$.dc("rfrm").ldng(1),s=$ocms.dlg(l,{width:1e3});s.ft.rwText($ict.iq1),$ocms.postXT({url:$ocms.url("inv/pget"),timeout:90,data:{id:t.id},success:e=>{s&&s.ft.rwText($ict.iq2),$ocms.postXT({url:$ocms.url("inv/icget"),timeout:60,data:{id:i},success:e=>{let t=$$.dc("srq",a),n=$$.tblset({class:"invi"},t);n.bdy.remove(),n.ft=$$[0]("tfoot"),e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b")),n.tbl.data($.extend({new:{},sms:{},itm:{}},{admin:e.admin,companies:e.companies,locations:e.locations}));let i=$$.tr(n.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(i,e))),n.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.requests||[],(function(t,i){if(0!==(i.Id||0)){let t=$inv.worknotes(i);i.text="i"===e.admin.type?$rct.req+jine([i.ExternalId,i.Name],": ").eine(" ",""):jine([fdt(i.WorkDoneAt,"dd.MM.yy")+t.ne(i.Name)],": ");let a=$$.tbody(n.tbl).data($.extend({},i));$inv.rendersrq.call(a)}}));let r=$$.tr($$.tbody(n.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(r),n.ft.appendTo(n.tbl);let l,s,d=e.admin||{},c=(e,t,i,r,l)=>{let s=$$.dc("inpfrm",a).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",s).rwText(t);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{n.tbl.data("new")[i]=e}},l),$inv.eHtml)),n.tbl.data("new")[i]=t};c("tfrm",d.invoicetitle,"invoicetitle",0,null),c("adrfrm",d.invoiceaddress,"invoiceaddress",0,null),c("locfrm",d.provisionlocation,"loc",1,{list:deepCopy(e.locations),lbl:"ref",property:"address"}),$inv.emailFrm(a,n,d.invoiceemail,d.invoiceemailcc),$$.dc("sndfrm",a).append($$.dc("content").text(d.sender)),d.provisionend&&(s=d.provisionstart?$rct.provP:$rct.provD,l=d.provisionstart?fdt(d.provisionstart,"dd.MM.yyyy")+" - "+fdt(d.provisionend,"dd.MM.yyyy"):fdt(d.provisionend,"dd.MM.yyyy")),c("admfrm",l,"provisionperiod",s,1),n.tbl.data("new").CustomValues=d.CustomValues||"",$$.dc("inpfrm ctpfrm",a).text(jObj(d.CustomValues,"contactName")),n.tbl.children("tbody").each($inv.bdysort),n.tbl.trigger("fds.inv")},complete:()=>{s.c.trigger("modal_close")}})},error:()=>{s&&s.c.trigger("modal_close")}})},$inv.clCntInv=function(e){let t=$fis.lf(!1),n=[];t.find("li.ili.checked").each((function(){n.push($(this).data("Id"))})),1===n.length&&$inv.cntInv({id:n[0]})},$inv.cntInv=function(e){e=e||{};$fis.lf(!1).rC("fix").aC("hd");let t=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sedit));$inv.eM(!1,!0);let n=$$.dc("rfrm").ldng(1),i=$ocms.dlg(n,{width:1e3});i.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("inv/get"),timeout:60,data:{id:e.id},success:e=>{e.admin=e.admin||{};let n=e.inv||{},i=$$.dc("srq",t),a=$$.tblset({class:"invi"},i);a.bdy.remove(),a.ft=$$[0]("tfoot"),a.tbl.data($.extend({invid:n.Id,new:{},sms:{},itm:{},bai:[]},e));let r=$$.tr(a.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(r,e))),a.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.req||[],(function(e,t){let n=$$.tbody(a.tbl).data($.extend({},t));$inv.rendersrq.call(n)}));let l=$$.tr($$.tbody(a.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(l),a.ft.appendTo(a.tbl);let s=(e,n,i,r,l)=>{let s=$$.dc("inpfrm",t).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",s).rwText(n);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{a.tbl.data("new")[i]=e}},l),$inv.eHtml)),a.tbl.data("new")[i]=n};s("tfrm",n.InvoiceTitle,"invoicetitle",0,null),s("adrfrm",n.SendToAddress,"invoiceaddress",0,null),s("locfrm",n.ProvisionLocation,"loc",1,null),$inv.emailFrm(t,a,n.SendToEmail,n.SendToEmailCc),$$.dc("sndfrm",t).append($$.dc("content").text(e.admin.sender)),s("admfrm",n.ProvisionPeriod,"provisionperiod",!0===(n.ProvisionPeriod||"").includes("-")?$rct.provP:$rct.provD,1),a.tbl.data("new").CustomValues=n.CustomValues||"",$$.dc("inpfrm ctpfrm",t).text(jObj(n.CustomValues,"contactName")),a.tbl.children("tbody").each($inv.bdysort),a.tbl.trigger("fds.inv"),$inv.eM(!1,!0,$inv.emOpt())},complete:()=>{i.c.trigger("modal_close")}})},$inv.cSt=function(e){e=e||{};let t=$fis.lf(),n=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sedit)),i=$fis.cf().width()>n.width()+t.width()+20;t.tC("fix",i).tC("hd",!i),$inv.eM(!1,!0);let a=$$.dc("rfrm").ldng(1),r=$ocms.dlg(a,{width:1e3});r.ft.rwText($ict.iq1),$ocms.postXT({url:$ocms.url("inv/pget"),data:{id:e.id},success:t=>{r&&r.ft.rwText($ict.iq2),$ocms.postXT({url:$ocms.url("inv/storno"),data:{id:e.id,mode:e.mode},success:e=>{e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b"));let t=e.inv||{},i=$$.dc("srq",n),a=$$.tblset({class:"invi"},i);a.bdy.remove(),a.ft=$$[0]("tfoot"),a.tbl.data($.extend({invid:t.Id,new:{},sms:{},itm:{},bai:[]},e));let r=$$.tr(a.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(r,e))),a.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.req||[],(function(e,t){let n=$$.tbody(a.tbl).data($.extend({},t));$inv.rendersrq.call(n)}));let l=$$.tr($$.tbody(a.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(l),a.ft.appendTo(a.tbl);let s=(e,t,i,r,l)=>{let s=$$.dc("inpfrm",n).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",s).rwText(t);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{a.tbl.data("new")[i]=e}},l),$inv.eHtml)),a.tbl.data("new")[i]=t};s("tfrm",t.InvoiceTitle,"invoicetitle",0,null),s("adrfrm",t.SendToAddress,"invoiceaddress",0,null),s("locfrm",t.ProvisionLocation,"loc",1,null),$inv.emailFrm(n,a,t.SendToEmail,t.SendToEmailCc),$$.dc("sndfrm",n).append($$.dc("content").text(e.admin.sender)),s("admfrm",t.ProvisionPeriod,"provisionperiod",!0===(t.ProvisionPeriod||"").includes("-")?$rct.provP:$rct.provD,1),a.tbl.data("new").CustomValues=t.CustomValues||"",$$.dc("inpfrm ctpfrm",n).text(jObj(t.CustomValues,"contactName")),a.tbl.children("tbody").each($inv.bdysort),a.tbl.trigger("fds.inv")},complete:()=>{r.c.trigger("modal_close")}})},error:()=>{r&&r.c.trigger("modal_close")}})},$inv.adrCountries=[["DE","Deutschland"],["AT","Österreich"],["CH","Schweiz"],["FR","Frankreich"],["NL","Niederlande"],["BE","Belgien"],["LU","Luxemburg"],["IT","Italien"],["ES","Spanien"],["PL","Polen"],["DK","Dänemark"],["CZ","Tschechien"],["GB","Großbritannien"],["US","USA"]],$inv.composeAddress=function(e){let t=[],n=e=>{""!==(e=(""+(e||"")).trim())&&t.push(e)};n((e=e||{}).name),""!==(""+(e.contact||"")).trim()&&n("z.Hd. "+(""+e.contact).trim()),n(e.line2||e.addressLine2),n(e.street),n(((e.postalCode||"")+" "+(e.city||"")).trim());let i=(""+(e.countryCode||"")).toUpperCase();return""!==i&&"DE"!==i&&n(i),t.join("\n")},$inv.adrCurrent=function(e){let t=jObj((e.data("new")||{}).CustomValues,"sendToAddress");if("string"==typeof t&&"{"===t.trim().charAt(0))try{t=JSON.parse(t)}catch(e){t=null}if(t&&"object"==typeof t)return t;let n=(e.data("admin")||{}).invoiceaddressData;if("string"==typeof n&&"{"===n.trim().charAt(0))try{return JSON.parse(n)}catch(e){}else if(n&&"object"==typeof n)return n;return{}},$inv.eAddress=function(e){let t=$inv.d.tbl(),n=$inv.adrCurrent(t),i=[{name:"name",label:"Name / Firma",type:"text",value:n.name||"",required:!0},{name:"contact",label:"z.Hd. (optional)",type:"text",value:n.contact||""},{name:"street",label:"Straße + Nr.",type:"text",value:n.street||""},{name:"line2",label:"Adresszusatz (optional)",type:"text",value:n.line2||n.addressLine2||""},{name:"postalCode",label:"PLZ",type:"text",value:n.postalCode||""},{name:"city",label:"Ort",type:"text",value:n.city||""},{name:"countryCode",label:"Land",type:"select",url:$inv.adrCountries,value:n.countryCode||"DE"},{name:"vatId",label:"USt-IdNr. (nur bei Firmen)",type:"text",value:n.vatId||""},{name:"leitwegId",label:"Leitweg-ID (nur Behörden / B2G)",type:"text",value:n.leitwegId||""}],a=$$.dc("adr-conformity").append([$$.dc("hd").text("Hinweis zur DATEV-/eRechnungs-Konformität"),$$.dc("tx").text("Pflicht: Name, Straße, PLZ, Ort und Land. Die USt-IdNr. nur bei Firmen angeben — für eine Rechnung an eine Privatperson einfach leer lassen. Eine Leitweg-ID nur bei Behörden (B2G) — dann wird die Rechnung automatisch als XRechnung erzeugt.")]);$ocms.dlgform(i,{title:"Rechnungsempfänger",addcontent:a,success:function(t){let n={name:t.name||"",contact:t.contact||"",line2:t.line2||"",street:t.street||"",postalCode:t.postalCode||"",city:t.city||"",countryCode:t.countryCode||"DE",vatId:(""+(t.vatId||"")).trim(),leitwegId:(""+(t.leitwegId||"")).trim()},i=$inv.composeAddress(n);e.data&&e.data.t&&e.data.t.rwText(i),"function"==typeof(e.data||{}).change&&e.data.change(i),$inv.d.sync({Target:"address",Value:n})}})},$inv.provToIso=function(e){let t=(""+(e||"")).match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);return t?t[3]+"-"+("0"+t[2]).slice(-2)+"-"+("0"+t[1]).slice(-2):""},$inv.eProvisionPeriod=function(e){let t=(""+(e.data&&e.data.t?e.data.t.text():"")).trim().match(/\d{1,2}\.\d{1,2}\.\d{4}/g)||[],n=[{name:"von",label:"Leistungsdatum",type:"date",value:$inv.provToIso(t[0]||"")},{name:"bis",label:"Leistungszeitraum – bis (optional)",type:"date",value:$inv.provToIso(t[1]||"")}],i=$$.dc("adr-conformity").append([$$.dc("hd").text("Leistungsdatum / -zeitraum"),$$.dc("tx").text('Für ein einzelnes Datum nur „Leistungsdatum" ausfüllen; für einen Zeitraum zusätzlich das Bis-Datum. Nur strukturierte Datumsauswahl — für die E-Rechnung empfohlen.')]);$ocms.dlgform(n,{title:"Leistungsdatum / -zeitraum",addcontent:i,success:function(t){let n=(""+(t.von||"")).trim(),i=(""+(t.bis||"")).trim(),a=""===n?"":""===i||i===n?n:n+" - "+i;e.data&&e.data.t&&e.data.t.rwText(a),"function"==typeof(e.data||{}).change&&e.data.change(a),$inv.d.sync({Target:"provisionperiod",Value:a})}})},$inv.eEmail=function(e){let t=[{name:"email",label:$rct.frm.invoiceemail,type:"text",value:(e.data.t||$$.s()).text()},{name:"emailcc",label:$rct.frm.invoiceemailcc,type:"text",value:(e.data.ccT||$$.s()).text()}];$ocms.dlgform(t,{title:$rct.frm.invoiceemail,success:function(t){let n=(""+(t.email||"")).trim(),i=(""+(t.emailcc||"")).trim();e.data&&e.data.t&&e.data.t.text(n),e.data&&e.data.ccT&&e.data.ccT.text(i),"function"==typeof(e.data||{}).change&&e.data.change(n),"function"==typeof(e.data||{}).changeCc&&e.data.changeCc(i),$inv.d.syncField("invoiceemail",n),$inv.rd.syncField("invoiceemail",n),$inv.d.syncField("invoiceemailcc",i),$inv.rd.syncField("invoiceemailcc",i)}})},$inv.emailFrm=function(e,t,n,i){let a=$$.dc("inpfrm emailccfrm",e),r=$$.dc("content",a).rwText(i),l=$$.dc("inpfrm emailfrm",e),s=$$.dc("content",l).rwText(n);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT.invoiceemail}).append(gi("pencil")).click({t:s,ccT:r,nme:"invoiceemail",change:e=>{t.tbl.data("new").invoiceemail=e},changeCc:e=>{t.tbl.data("new").invoiceemailcc=e}},$inv.eHtml)),t.tbl.data("new").invoiceemail=n,t.tbl.data("new").invoiceemailcc=i},$inv.eHtml=function(e){if(e.data&&!(e.data instanceof jQuery)&&$inv.d&&"function"==typeof $inv.d.token&&""!==$inv.d.token()){if("invoiceaddress"===e.data.nme)return $inv.eAddress.call(this,e);if("provisionperiod"===e.data.nme)return $inv.eProvisionPeriod.call(this,e)}if(e.data&&!(e.data instanceof jQuery)&&"invoiceemail"===e.data.nme&&e.data.ccT)return $inv.eEmail.call(this,e);let t=$(this),n=e.data instanceof jQuery?e.data:e.data.t,i=["invoiceemail","invoiceemailcc","provisionperiod","invoicetitle"].includes(e.data.nme),a=i?[{name:"txt",label:"Text",type:"text",value:n.text()}]:[{name:"txt",label:"Text",type:"html",value:n.html(),tinymce:!0,attr:{style:"height: 300px"}}],r=e.data.change||null,l={title:t.data("dialog")||"",success:function(t){i?n.text(t.txt||""):n.html(t.txt),"function"==typeof r&&r(t.txt),$inv.d.syncField(e.data.nme,i?t.txt||"":t.txt),$inv.rd.syncField(e.data.nme,i?t.txt||"":t.txt)},tinymce:{valid_elements:"br",hidemenu:!0,hidetoolbar:!0}};if(Array.isArray(e.data.list)){let t=$$.dc("lstfrm");$.each(e.data.list,((n,i)=>{let a=$$.dc("li",t).append(""!==(e.data.lbl||"")?$$.dc("lbl").rwText(i[e.data.lbl]):null);$$.dc("adr",a).rwText(i[e.data.property]).data("val",i[e.data.property]).click((function(){let e=$(this),t=e.closest(".modal-body").find(':input[name="txt"]');t.is(".tinymce")?tinymce.get(t.attr("id")).setContent($$.s().rwText(e.data("val")).html()):"TEXTAREA"===t.prop("tagName")?t.val(e.data("val")).change():t.rwText(e.data("val"))}))})),l.addcontent=t}$ocms.dlgform(a,l)},$inv.setVat=function(e){$(this);let t=e.data,n=prompt($rct.rqV);n&&(n=parseFloat(n.replace("%","")),n>1&&(n*=.01),!1===isNaN(n)&&(t.siblings(".itm").each((function(){$(this).data().vat=fnum(n,{style:"percent"}).replace(" ","")})),$inv.t_fds_inv()))},$inv.inRow=function(e){let t=$(this),n=e.data,i={},a=$rcol.itm.clone(["SortOrder","NameOrNumber","Type","quantityhours","UnitString","net","svcnet_val","svcvat_val","net_val","vat_val","vat","Note"]),r="N"+(65536*(1+Math.random())||0).toString(16).substr(6),l=$$.tr({id:"itm_"+r.toString(),class:"itm"});$ocms.dlgform(a,{title:t.data("dialog")||"",success:function(e){l.data($.extend({Id:r},i,e)),$inv.rrw.call(l),l.insertAfter(n),$inv.t_fds_inv()},typedvalues:!0})},$inv.eRow=function(e){let t=$(this),n=e.data,i=n.data()||{},a=["SortOrder","NameOrNumber","Type","quantityhours","UnitString","net","svcnet_val","svcvat_val","net_val","vat_val","vat","Note"];i.id||""!==(i.Type||"")||a.unshift("Type");let r=$rcol.itm.clone(a).applyValues(i);r.set("Type","hidden","type"),$inv.eRw.call(t,n,i,r)},$inv.eRw=function(e,t,n){let i=$(this);$ocms.dlgform(n,{title:i.data("dialog")||"",success:function(n){let i={};""===(t.Id||"")&&(i.Id="N"+(65536*(1+Math.random())||0).toString(16).substr(6),e.attr("id","itm_"+i.Id.toString())),i.quantity=((n.quantityhours||"").toString()+" "+(n.UnitString||"").toString()).trimEnd(),e.data($.extend({},t,n,i)),console.debug("eRw success %o",e.data()),$inv.rrw.call(e),$inv.t_fds_inv()},typedvalues:!0})},$inv.bdysort=(e,t)=>{$(t).Sortable({dragItem:!1,dragHandleClass:"ico",parentident:"tr",onend:()=>{$inv.t_fds_inv()}})},$inv.rowCtxMenu=function(e){let t=$$[0]("nav").aC("rowctx");return t.ocmsmenu([{glyph:"glyphicon-option-vertical",aclass:"ctxbtn",attr:{title:$rct.ctxM},itm:e}]),t.find("li[title]").each((function(){let e=$(this);e.children("a").attr("title",e.attr("title"))})),t},$inv.rrw=function(){let e=$(this),t=e.data(),n={},i=e.is(".placeholder"),a=e.is(".hidenote"),r=e=>$$.d().append(e).html(),l=[{lbl:$rct.iRb,attr:{title:$rct.iRb},data:e,fnc:$inv.inRow}];!1===i&&(l.unshift({lbl:$rct.cP,attr:{title:$rct.cP},data:e,fnc:$inv.eRow}),l.push({lbl:$rct.dR,attr:{title:$rct.dR},fnc:function(t){confirm($rct.cD)&&(e.remove(),$inv.t_fds_inv())}}),"set"===(t.Type||"").toLowerCase()&&0===(t.net_val||0)&&l.push({lbl:$rct.toSetP,attr:{title:$rct.toSetP},data:e,fnc:$inv.toSetPrice}));let s=$$.dc("axf").append($inv.rowCtxMenu(l));!0===i?n={id:"",typ:"placeholder"}:!0===e.is(".itm.osum")?n={invrqid:t.InvRqId,id:"osum"+e.index(),typ:"osum",p:"",q:null,t:r(t.tbl.tbl),tt:null,v:null,vt:t.net_val,vs:t.svcnet_val,vat:t.vat,vv:t.vat_val,vsv:t.svcvat_val,det:!1}:(n={invrqid:t.InvRqId,id:t.Id||"",typ:t.Type||"other",p:"",q:null,t:"",tt:null,v:null,vt:t.net_val,vs:t.svcnet_val,vat:t.vat,vv:t.vat_val,vsv:t.svcvat_val,det:""!==(t.Note||"")&&!1===a,SetItmId:t.SetItmId||null,lvl:t.lvl||0},$$.dc("ibtn ico move",s,{title:$rct.mR}),n.p=null!=t.position?t.position:t.SortOrder||"",""===n.id?n.t="":["Text","Title"].includes(n.typ)&&0===(t.net_val||0)?n.t=t.htmltext||("#"!==(t.NameOrNumber||"").substr(0,1)?r($$[0]("p").text(t.NameOrNumber)):"")+(t.Note||""):(n.tt=n.det?"":$$.s(t.Note||"").text(),n.q=t.quantity||(0!==(t.quantityhours||0)?fnum(t.quantityhours)+" "+(t.UnitString||""):""),n.t=t.htmltext||(n.det?r($$.s(t.NameOrNumber||""))+r($$.dc("desc").html(t.Note)):r($$.s(t.NameOrNumber||""))),n.v=t.net,n.vt=t.net_val)),""!==(t.Note||"")&&$$.dc("ibtn add",s,{title:$rct.noteToggle}).append(gi("object-align-left")).click((function(t){$inv.rrw.call(e.tC("hidenote"))}));let d=[$$.tdc("aux").append(s),$$.tdc("keep").text(n.p)];if(""===n.id)d.push($$.td(e,{colspan:4}).append(n.t));else{Array.prototype.push.apply(d,n.q?[$$.tdc("keep").text(n.q)]:[]);let e=e=>null==e?"":fnum(e,$rct.cst);Array.prototype.push.apply(d,[$$.tdc("txt",{colspan:n.q?1:2,title:n.tt}).append(n.t),$$.tdc("currency").text(e(n.v)),$$.tdc("currency inetval").text(e(n.vt)).attr("title",$rct.svcPart+": "+e(n.vs))])}e.empty().attr("class",i?"placeholder":"itm").aC(n.Typ).tC("sethdr","set"===(n.typ||"").toString().toLowerCase()).aC((n.lvl||0)>0?"lvl"+Math.min(n.lvl,6):"").tC("hidenote",a).append(d),t.co=n},$inv.toSetPrice=function(e){let t=(e.data.data().Id||"").toString();""!==t&&!1!==confirm($rct.toSetPc)&&$.when($inv.t_fds_inv()).done((()=>{$inv.d.sync({Target:"item.setprice",Ref:t})}))},$inv.invSumUpdate=function(){let e=$(this),t=[],n=e.children("tbody"),i=[];n.each(((e,n)=>{let a=$(n),r=a.data()||{},l=[],s=[],d=a.find("tr.itm");a.tC("empty",d.length<1),d.each(((e,t)=>{let n=$(t).data()||{};l.push(n.co);let a=$inv.itemToContract(n),r=(n.SetItmId||"").toString();""!==r&&r!==a.id&&(a.setId=r),s.push(a);let d=!1===["text","title"].includes((n.Type||"other").toLowerCase());n.position=((e,t)=>{if(!e)return"";let n=Math.max(t||0,0);for(;i.length<=n;)i.push(0);return i.length=n+1,i[n]++,i.join(".")})(d,(n.co||{}).lvl||0),$inv.rrw.call(t)})),t.push({Id:r.Id,nme:r.Name,text:r.text,itm:l,items:s})}));let a=e.find("tbody:not(.empty)").length;n.find("tr.isum").tC("hidden",a<2),e.data("bai",t),""===(e.data("dtoken")||"")&&!1===bool(e.data("dseeding"),!1)&&null!=(e.data("admin")||{}).type&&(e.data("dseeding",!0),$inv.d.seed($.extend($inv.invcPayload(e.data()),{invid:e.data("invid")||""})))},$inv.worknotes=function(e){let t="";return e.steps.forEach(((e,n)=>{let i;try{i=JSON.parse(e.Data||{}).fields||[]}catch(e){console.debug(e),i=[]}!0!==Array.isArray(i||"")&&(i="object"==typeof i&&!0===Array.isArray(i.field||"")?i.field:[]),i.forEach(((e,n)=>{"Ausgeführte Arbeiten"===e.name&&(t=e.result||"")}))})),t},$inv.rendersrq=function(){let e=$(this).empty(),t=e.is(".onesum"),n=e.data(),i=$$.tr(e,{id:"srq"+n.Id}).aC("title nosort"),a=($rcol.itm.lbl(),$$.dc("axf").appendTo($$.tdc("aux",i)));$$.dc("ibtn osum",a,{title:$rct.combP}).append(gi("euro")).click((function(t){e.tC("onesum"),$inv.rendersrq.call(e),$inv.t_fds_inv()})),$$.dc("ibtn setvat",a,{title:$rct.sV}).append(gi("gbp")).click(i,$inv.setVat),$$.dc("ibtn insb",a,{title:$rct.iRb}).append(gi("indent-left")).click(i,$inv.inRow);let r,l=$$.sc("text",n.text),s=($$.td(i,{colspan:t?4:5}).append(l),["net_val","vat_val","svcnet_val","svcvat_val","net"]);if($$.dc("ibtn edit",a,{title:$rct.sectionTitleEditTT}).data("dialog",$rcol.req.lbl().Name).append(gi("pencil")).click({t:l,change:e=>{n.text=e,$inv.t_fds_inv()}},$inv.eHtml),t&&($$.tdc("currency isumval",i),r={Id:n.Id.toString()+"_osum",net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0},r.tbl=$$.tblset({class:"stbl"})),$.each(n.items||[],((n,i)=>{let a,l={Id:i.Id,net_val:i.net_val||0,vat_val:i.vat_val||0,svcnet_val:0,svcvat_val:0,net:i.net||0,Note:i.Note||""};if("service"===i.Type.toLowerCase())l.svcnet_val=i.net_val||0,l.svcvat_val=i.vat_val||0;t?(a=$$.tr(r.tbl.bdy,{id:"itm"+i.Id,class:"sitm"}).aC(i.Type),"Text"===i.Type||"Title"===i.Type?$$.td(a,{colspan:2}).html(i.htmltext||i.Note):($$.tdc("keep",a).text(i.quantity||((i.quantityhours||0)>0?fnum(i.quantityhours)+(i.UnitString||"").eine(" ",""):"")),i.htmltext?$$.tdc("txt",a).html(i.htmltext):$$.tdc("txt",a).text(i.NameOrNumber).attr("title",i.Note)),$.each(s,((e,t)=>{r[t]+=l[t]})),a.data(l)):($.extend(l,i),a=$$.tr(e,{id:"itm"+i.Id,class:"itm"}),a.data(l),$inv.rrw.call(a))})),t){let t=$$.tr(e,{id:"itmsq"+n.Id,class:"itm osum"}).data(r);$inv.rrw.call(t)}else{let t=$$.tr(e).aC("isum nosort");$$.tdc("aux",t),$$.td(t,{colspan:4}).text($rct.iSum),$$.tdc("currency isumval",t)}},$inv.t_fds_inv=()=>{let e=$("div.invoice_layout table.invi");if(e.trigger("fds.inv"),""!==(e.data("dtoken")||""))return $inv.d.syncChanged(e);let t=e.data("dseedpromise");return t?$.when(t).then((()=>$inv.d.syncChanged(e))):$.when()},$inv.sedit=()=>{$inv.sprev(!0)},$inv.jdisp=function(e){e.stopPropagation(),e.data.id&&$inv.disp(e.data.id,e.data.typ||"")},$inv.disp=(e,t)=>{let n="";switch(t){case"inv":n="inv/rdoc";break;case"rem":n="rem/rdoc"}if(""!==n){let t=$inv.pdfWaitDlg();$ocms.postXT({url:$ocms.url(n),data:{id:e||"",typ:"img"},timeout:$inv.pdfPreviewTimeout,success:e=>{let t=$$.dc("imagecollection pdfpreview"),n=Math.round(.88*vh());e.id;$.each(e.img||[],(function(e,i){$$.dc("pdfp",t).append($$.img(i).css("max-height",(n-rpx(6)).toString()+"px"))})),$ocms.dlg(t,{size:[n,Math.round(.88*vw())],zindex_min:50,form:!1,exclusive:!1})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(null,t)})}},$inv.jdbn=function(e){let t=$inv.pdfWaitDlg();$ocms.postXT({url:$ocms.url("inv/rdocn"),data:{name:e.data.id||"",typ:"img"},timeout:$inv.pdfPreviewTimeout,success:e=>{let t=$$.dc("imagecollection pdfpreview"),n=Math.round(.88*vh());e.id;$.each(e.img||[],(function(e,i){$$.dc("pdfp",t).append($$.img(i).css("max-height",(n-rpx(6)).toString()+"px"))})),$ocms.dlg(t,{size:[n,Math.round(.88*vw())],zindex:50,form:!1})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(null,t)})},$inv.sp13b=()=>{var e=$("div.invoice_layout").find("table.invi"),t=e.data();t.admin.p13b=!0,!1===(t.inv.InvoiceOptions||"").split(",").includes("§13b")&&(t.inv.InvoiceOptions+=",§13b"),e.trigger("fds.inv"),$inv.d.sync({Target:"p13b",Value:t.admin.p13b})},$inv.itemToContract=function(e){let t=((e=e||{}).Type||"").toString().toLowerCase(),n=e=>e??null,i={id:(e.Id||"").toString(),type:t,title:"",desc:"",qty:"",price_net:"",total_net:n(e.net_val),vat:e.vat||""};var a;return e.co&&"osum"===e.co.typ?(i.desc=e.co.t||"",i.total_net=e.net_val||0):["text","title"].includes(t)&&0===(e.net_val||0)?(i.desc=e.htmltext||("#"!==(e.NameOrNumber||"").substr(0,1)?(a=$$[0]("p").text(e.NameOrNumber||""),$$.d().append(a).html()):"")+(e.Note||""),i.total_net=""):(e.htmltext?i.desc=e.htmltext:(i.title=e.NameOrNumber||"",i.desc=e.Note||""),i.qty=e.quantity||(0!==(e.quantityhours||0)?fnum(e.quantityhours)+(e.UnitString?" "+e.UnitString:""):""),i.price_net=n(e.net),i.total_net=n(e.net_val)),i},$inv.hasSets=e=>((e||{}).req||[]).some((e=>{let t=((e||{}).itm||[]).filter((e=>e&&""!==(e.id||""))),n={};t.forEach((e=>{n[(e.id||"").toString()]=e}));return t.some((e=>{let t=(null==e.SetItmId?"":e.SetItmId).toString();return""!==t&&t!==(e.id||"").toString()&&n[t]&&(e=>"set"===(e.typ||"").toString().toLowerCase())(n[t])}))})),$inv.ssetmode=()=>{let e,t=$("div.invoice_layout").find("table.invi").data();if(t.dstate&&!1===$inv.hasSets(t.dstate))return void alert($rct.toSetMn);let n=t=>$$.dc("btn",$ict.setmo[t]).click((()=>{e.c.trigger("modal_close"),$inv.setSetmode(t)})),i=$$.dc("choicefrm").append([n("setprice"),n("setonly")]);e=$ocms.dlg(i,{width:800})},$inv.setSetmode=e=>{if(!1===confirm($rct.toSetMc||$rct.toSetPc))return;let t="setonly"===e?"block.setonly":"block.setprice";$.when($inv.t_fds_inv()).done((()=>{$inv.d.sync({Target:t})}))},$inv.sctp=()=>{let e=$invcol.ctp;$ocms.dlgform(e,{title:$ict.ctp,success:function(e){var t=$("div.invoice_layout"),n=t.find("table.invi").data();let i={};void 0!==n.new&&"{"===(n.new.CustomValues||"").substr(0,1)&&(i=JSON.parse(n.inv.CustomValues)),i.contactName=e.name,i.contactEmail=e.email,n.new.CustomValues=JSON.stringify(i),t.find(".ctpfrm").text(ne(e.name,e.email)),$inv.d.sync({Target:"contact",Value:{name:e.name,email:e.email}})},typedvalues:!0})},$inv.invcPayload=function(e){e=e||{};let t=$.extend({},e.new),n=$.extend({},e.admin);return t.title=null!=t.invoicetitle?t.invoicetitle:t.title||"",t.provisionlocation=null!=t.loc?t.loc:t.provisionlocation||"",t.paymentterm=null!=n.paymentterms?n.paymentterms:t.paymentterm||"",n.customerid=null!=n.customerid?n.customerid:n.CustomerId,{admin:n,req:e.bai,new:t}},$inv.ssave=()=>{$inv.d.save()},$inv.sprev=e=>{$inv.d.preview()},$inv.rReload=()=>{try{let e=$("#listframe ul.rql:first").data();$inv.cInv2({id:e.search})}catch(e){}},$inv.quantChange=function(e){},$inv.storno=function(e,t){let n,i=$$.dc("choicefrm").append([$$.dc("btn","Storno ohne Details").click({id:e,mode:"simple"},(e=>{n.c.trigger("modal_close"),$inv.cSt(e.data)})),$$.dc("btn","Storno mit neuer Rechnung").click({id:e},(e=>{n.c.trigger("modal_close"),$inv.ccStInv(e)})),$$.dc("btn","Storno mit best. Rechnung").tC("inactive",!1===bool(t,!1)).click({id:e,mode:"copy"},(e=>{!0===bool(t,!1)&&(n.c.trigger("modal_close"),$inv.cSt(e.data))}))]);n=$ocms.dlg(i,{width:1e3})},$inv.credit=function(e,t){let n,i=$$.dc("choicefrm").append([$$.dc("btn","Gutschrift").click({id:e,mode:"credit"},(e=>{n.c.trigger("modal_close"),$inv.cSt(e.data)}))]);n=$ocms.dlg(i,{width:1e3})},$inv.setPyd=function(e){confirm($ict.cpyd)&&$ocms.postXT({url:$ocms.url("inv/setpyd"),timeout:60,data:{id:e},success:e=>{alert($ict.relm)},error:()=>{alert($t.f1)}})},$inv.setUpd=function(e){confirm($ict.cupd)&&$ocms.postXT({url:$ocms.url("inv/setupd"),timeout:60,data:{id:e},success:e=>{alert($ict.relm)},error:()=>{alert($t.f1)}})},$inv.resendRem=function(e){e.stopPropagation(),e.data.id&&confirm(string($ict.remresc,[e.data.name]))&&$ocms.postXT({url:$ocms.url("rem/resend"),timeout:60,data:{id:e.data.id},success:t=>{alert(string($ict.remresr,[e.data.name]))},error:()=>{alert($t.f1)}})},$inv.dspRem=function(e){let t=$$.dc("rfrm").ldng(1),n=$ocms.dlg(t,{width:1e3});n.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("inv/getrem"),timeout:60,data:{id:e,drafts:!1},success:e=>{n.ft.empty();let i=$$.tblset({class:"invtbl"},t.empty()),a=$invcol.rem2,r=$$.tr(i.hd);$$.th(r);$.each(a.fields||[],((e,t)=>{$$.th(r).text(t.label)}));let l=!1;$.each(e,((e,t)=>{l=!l;let n=$$.tr(i.bdy).tC("alt",l),r=$$.td(n);n.click((function(){n.tC("selected").siblings().rC("selected")})),!0===bool(t.hasFile,!1)&&($$.dc("idl ilbtn",r,{title:$ict.dl+"\n"+t.DocumentName}).append(gi("save-file","ico")).click({id:t.Id},$inv.downloadrem),$$.dc("idl ilbtn",r,{title:$ict.remdsp+"\n"+t.DocumentName}).append(gi("eye-open","ico")).click({id:t.Id,typ:"rem"},$inv.jdisp),$$.dc("idl ilbtn",r,{title:$ict.remres+"\n"+t.DocumentName}).append(gi("refresh","ico")).click({id:t.Id,typ:"rem",name:t.DocumentName},$inv.resendRem)),$.each(a.fields||[],((e,i)=>{let a=$$.td(n).aC(i.dtype),r=t[i.name];if("function"==typeof i.dfnc)i.dfnc.call(a,r,t);else switch(i.type||""){case"date":a.text(fdt(t[i.name],"dd.MM.yy"));break;case"datetime":a.text(fdt(t[i.name]));break;case"html":a.append($$.dc("ctw").html(r)),a.append($$.dc("ttip").html(r));break;default:a.text(t[i.name])}if("InvoiceId"===(i.name||""))a.aC("keep");switch(typeof i.title){case"function":i.title.call(a,t);break;case"string":a.attr("title",cs.title)}}))}))},error:()=>{t.empty(),n.ft.rwText($t.f1)},complete:()=>{t.ldng(0)}})},$inv.ccRem=function(e,t){$(this);$ocms.postXT({url:$ocms.url("rem/lrem"),timeout:60,data:{id:e},success:n=>{let i=$invcol.rid.clone();i.applyValues(n.ov);let a=$$.dc("ac"),r=$$.tblset({class:"fullgrid fullwidth"},a);if((n.lst||[]).length>0){$$.d({style:"margin: 1.5rem 0 1rem 0;font-size: 110%;text-decoration: underline;"}).prependTo(a).text($ict.rovlh);let e=$$.tr(r.hd);$ict.rovl.forEach(((t,n)=>$$.th(e,t))),$.each(n.lst,((e,t)=>{$$.tr(r.bdy).append([$$.tdc("keep",t.subject),$$.tdc("currency",fnum(t.amount,$rct.cst)),$$.tdc("currency",fnum(t.amount_payed,$rct.cst)),$$.tdc("keep",fdt(t.DateFinalized,"dd.MM.yy"))])}))}else $$.td($$.tr(r.bdy),$ict.nd);$ocms.dlgform(i,{addcontent:a,title:string($ict.remdt,[t||"?"]),success:function(t){$inv.ccRem_s2(e,t)},typedvalues:!0})}})},$inv.rRemRw=function(e){let t=$(this),n=e.rm||{};t.empty().data({invoiceid:n.invoiceid,invoicedate:n.invoicedate,amount:n.amount,amount_payed:n.amount_payed});let i=[{lbl:$rct.cP,attr:{title:$rct.cP},data:t,fnc:$inv.eRowR}],a=$$.dc("axf").append($inv.rowCtxMenu(i));t.append([$$.tdc("aux").append(a),$$.tdc("keep",n.invoiceid),$$.tdc("keep",fdt(n.invoicedate,"dd.MM.yy")),$$.tdc("currency",fnum(n.amount,$rct.cst)),$$.tdc("currency",fnum(n.amount_payed,$rct.cst)),$$.tdc("currency",fnum(n.amount-n.amount_payed,$rct.cst))])},$inv.eRowR=function(e){let t=$(this),n=e.data,i=n.data()||{},a=$invcol.rem.clone().applyValues(i);$ocms.dlgform(a,{title:t.data("dialog")||"",success:function(e){let i=t.closest("table"),a=i.data();$.extend(a.rm,e),i.data(a),$inv.rRemRw.call(n,a),$inv.rd.syncAmount(a.rm.amount,a.rm.amount_payed)},typedvalues:!0})},$inv.ccRem_s2=function(e,t){$fis.lf(!1).rC("fix").aC("hd");let n=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.rprev));$inv.eM(!1,!0);$$.dc("rfrm").ldng(1);$ocms.postXT({url:$ocms.url("rem/get"),timeout:60,data:$.extend({id:e},t),success:e=>{let t=e.rm||{},i=$$.dc("srq",n),a=$$.tblset({class:"invi"},i);a.ft=$$[0]("tfoot"),a.tbl.data($.extend({invid:t.invid,new:{}},e));let r=$$.tr(a.hd).aC("shd").append([$$.th().aC("aux")]);$ict.remHR.forEach((e=>$$.th(r,e))),$inv.rRemRw.call($$.tr(a.bdy),a.tbl.data()),a.ft.appendTo(a.tbl);let l={invoiceemail:"Email-Adresse ändern",subject:"Betreff ändern"},s=(e,t,i,r,s)=>{let d=$$.dc("inpfrm",n).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),c=$$.dc("content",d).rwText(t);$$.dc("axf",d).append($$.dc("ibtn edit",{title:l[i]||$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:c,nme:i,change:e=>{a.tbl.data("new")[i]=e}},s),$inv.eHtml)),a.tbl.data("new")[i]=t};s("tfrm",t.subject,"subject",0,null),s("adrfrm",t.invoiceaddress,"invoiceaddress",0,null),s("emailfrm",t.invoiceemail,"invoiceemail",0,null),$$.dc("sndfrm",n).append($$.dc("content").text(t.sender)),a.tbl.children("tbody").each($inv.bdysort),a.tbl.trigger("fds.inv");let d=a.tbl.data("new");d.amount=t.amount,d.amount_payed=t.amount_payed,$inv.rd.seed({rem:{invid:t.invid,type:t.type,invoiceid:t.invoiceid,invoicedate:t.invoicedate},new:d})},complete:()=>{}})},$inv.rprev=()=>{$inv.rd.preview()},$inv.sis=e=>{confirm($ict.sisc)&&$ocms.postXT({url:$ocms.url("inv/sis"),data:{id:e||""},success:e=>{}})},$inv.srs=e=>{confirm($ict.srsc)&&$ocms.postXT({url:$ocms.url("rem/srs"),data:{id:e||""},success:e=>{}})},$inv.mfrrel=e=>{$("#contentframe").ldng(),$ocms.postXT({url:$ocms.url("inv/mfrrel"),data:{id:e||""},success:e=>{$inv.rerenderinv()},complete:()=>{$("#contentframe").ldng(0)}})},$inv.sets={o:null,c:null,drag:null,isOpen:()=>!!$inv.sets.o,open:function(){let e=$inv.d.tbl();if(e.length<1||$inv.sets.isOpen())return;if(""===$inv.d.token()&&!e.data("dstate"))return;let t=$$.dc("setstruct");$inv.sets.c=t,$inv.sets.o=$ocms.dlg(t,{title:$ict.setst,size:[-1,960],exclusive:!1,close:()=>{$inv.sets.o=null,$inv.sets.c=null,$inv.sets.drag=null}});let n=e.data("dstate");n?$inv.sets.render(n):$inv.d.refresh()},title:e=>{let t=$$.d().html(e.t||"").text().replace(/\s+/g," ").trim();return""!==t?t:$ict.setsNoTitle||""},typLbl:e=>{let t=(e.typ||"").toString().toLowerCase();return($ict.settyp||{})[t]||e.typ||""},isSet:e=>"set"===(e.typ||"").toString().toLowerCase(),parentOf:(e,t)=>{let n=(null==e.SetItmId?"":e.SetItmId).toString(),i=(e.id||"").toString();if(""===n||n===i)return"";let a=t[n];return a&&$inv.sets.isSet(a)?n:""},isDescendant:(e,t,n)=>{let i={},a=n[e];for(;a;){let e=$inv.sets.parentOf(a,n);if(""===e||i[e])return!1;if(e===t)return!0;i[e]=!0,a=n[e]}return!1},canDrop:(e,t,n,i)=>!!e&&e.bid===n&&e.id!==t&&!$inv.sets.isDescendant(t,e.id,i),sync:e=>($inv.sets.c&&$inv.sets.c.aC("busy"),$inv.d.sync(e)),render:function(e){let t=$inv.sets.c;if(!t)return;let n=t.closest(".modal-body"),i=n.length?n.scrollTop():0;t.empty().rC("busy"),$$.dc("shint",t).text($ict.setsHint||""),(e.req||[]).forEach((e=>{if(!e)return;let n=(e.Id||"").toString();if(""===n)return;let i=(e.itm||[]).filter((e=>e&&""!==(e.id||""))),a={};i.forEach((e=>{a[(e.id||"").toString()]=e}));let r=$$.dc("sblock",t).data({bid:n});$inv.sets.rootZone($$.dc("sbhd",r).append($$.sc("nme",e.text||e.nme||n)),n,a);let l=$$.tblset({class:"stbl"},r),s=$$.tr(l.hd);($ict.setsHR||[]).forEach((e=>$$.th(s,e))),i.forEach((e=>$inv.sets.row(l.bdy,e,n,i,a))),$inv.sets.rootZone($$.dc("sroot",r).text($ict.setsRoot||""),n,a),$inv.sets.createBar(r,n,i,a)})),n.length&&n.scrollTop(i)},collapsed:{},hiddenByCollapse:function(e,t){let n={},i=e;for(;i;){let e=$inv.sets.parentOf(i,t);if(""===e||n[e])return!1;if($inv.sets.collapsed[e])return!0;n[e]=!0,i=t[e]}return!1},zone:function(e,t,n){let i=e.originalEvent||e,a=t[0].getBoundingClientRect(),r=(i.clientY||0)-a.top,l=a.height||1;return r<.3*l?"before":r>.7*l||!n?"after":"into"},clearDrop:()=>{$(".setstruct .dropok, .setstruct .dropbefore, .setstruct .dropafter").rC("dropok dropbefore dropafter")},row:function(e,t,n,i,a){let r=(t.id||"").toString(),l=parseInt(t.lvl||0,10)||0,s=$inv.sets.isSet(t),d=$inv.sets.parentOf(t,a),c=s&&!!$inv.sets.collapsed[r],o=$$.tr(e,{draggable:"true"}).aC("srow lvl"+l).tC("isset",s).tC("folded",c).data({id:r,bid:n});$inv.sets.hiddenByCollapse(t,a)&&o.aC("hid"),$$.tdc("grip",o).append(gi("move")).attr("title",$rct.mR),$$.tdc("pos",o).text(null!=t.p?t.p:"");let u=$$.tdc("typ",o);s&&u.append($$.sc("fold").attr("title",c?$ict.setsExpand:$ict.setsCollapse).append(gi(c?"triangle-right":"triangle-bottom")).click((e=>{e.stopPropagation(),c?delete $inv.sets.collapsed[r]:$inv.sets.collapsed[r]=!0;let t=$inv.d.tbl().data("dstate");t&&$inv.sets.render(t)}))),u.append($$.s($inv.sets.typLbl(t))),$$.tdc("qty",o).text(t.q||"");let m=$$.tdc("ttl",o);if(""!==d&&m.append($$.sc("seti",$inv.sets.title(a[d]))),m.append($$.sc("txt",$inv.sets.title(t)).click((function(e){e.stopPropagation(),$(this).tC("exp")}))),s){let e=i.filter((e=>$inv.sets.parentOf(e,a)===r)).length;m.append($$.sc("cnt"," ("+e+")"))}let v=i.filter((e=>$inv.sets.parentOf(e,a)===d)),p=v.findIndex((e=>(e.id||"").toString()===r)),f=v.slice(0,p).some((e=>$inv.sets.isSet(e))),h=$$.tdc("act",o),g=(e,t,n,i,a)=>$$.dc("ibtn "+e,h,{title:n}).append(gi(t)).tC("disabled",!i).click((()=>{i&&$inv.sets.sync(a)}));g("up","arrow-up",$ict.setsUp,p>0,{Target:"set.move",Ref:r,Value:-1}),g("down","arrow-down",$ict.setsDown,p>=0&&p0,{Target:"set.level",Ref:r,Value:-1}),g("in","chevron-right",$ict.setsIn,f,{Target:"set.level",Ref:r,Value:1}),o.on("dragstart",(e=>{$inv.sets.drag={id:r,bid:n},o.aC("dragging");try{e.originalEvent.dataTransfer.setData("text/plain",r),e.originalEvent.dataTransfer.effectAllowed="move"}catch(e){}})).on("dragend",(()=>{o.rC("dragging"),$inv.sets.drag=null,$inv.sets.clearDrop()}));return o.on("dragover",(e=>{if(!$inv.sets.canDrop($inv.sets.drag,r,n,a))return;e.preventDefault();let t=$inv.sets.zone(e,o,s);o.rC("dropok dropbefore dropafter").aC("into"===t?"dropok":"before"===t?"dropbefore":"dropafter")})).on("dragleave",(()=>{o.rC("dropok dropbefore dropafter")})).on("drop",(e=>{e.preventDefault(),$inv.sets.clearDrop();let t=$inv.sets.drag;if($inv.sets.drag=null,!$inv.sets.canDrop(t,r,n,a))return;let i=$inv.sets.zone(e,o,s);"into"===i?$inv.sets.sync({Target:"set.assign",Ref:t.id,Value:{parent:r}}):$inv.sets.sync({Target:"set.move",Ref:t.id,Value:{anchor:r,where:i}})})),o},rootZone:function(e,t,n){return e.on("dragover",(i=>{(()=>{let e=$inv.sets.drag;return!!e&&e.bid===t&&!!n[e.id]&&""!==$inv.sets.parentOf(n[e.id],n)})()&&(i.preventDefault(),e.aC("dropok"))})).on("dragleave",(()=>{e.rC("dropok")})).on("drop",(i=>{i.preventDefault(),e.rC("dropok");let a=$inv.sets.drag;$inv.sets.drag=null,a&&a.bid===t&&n[a.id]&&""!==$inv.sets.parentOf(n[a.id],n)&&$inv.sets.sync({Target:"set.assign",Ref:a.id,Value:{parent:""}})})),e},createBar:function(e,t,n,i){let a=$$.dc("screate",e),r=$("").attr({name:"typ"}).append([$$.opt("set",$ict.settyp.set),$$.opt("text",$ict.settyp.text)]),l=$("").attr({name:"parent"}).append($$.opt("",$ict.setsTop));n.forEach((e=>{if(!$inv.sets.isSet(e))return;let t=parseInt(e.lvl||0,10)||0;l.append($$.opt((e.id||"").toString()," ".repeat(3*t)+$inv.sets.title(e)))}));let s=$('').attr({name:"title",placeholder:$ict.setsTitle,maxlength:250}),d=()=>{let e=(s.val()||"").toString().trim();""!==e?($inv.sets.sync({Target:"set.create",Ref:t,Value:{typ:r.val(),title:e,parent:l.val()||""}}),s.val("")):s.focus()};return s.on("keydown",(e=>{"Enter"===e.key&&(e.preventDefault(),d())})),a.append([$$.sc("lbl",$ict.setsNew),r,$$.sc("lbl",$ict.setsInto),l,s,$$.bbtn($ict.setsAdd,"sadd").click(d)]),a}};
\ No newline at end of file
diff --git a/Fuchs/wwwroot/web/fis.req.de.js b/Fuchs/wwwroot/web/fis.req.de.js
index 275d083..0eca6e4 100644
--- a/Fuchs/wwwroot/web/fis.req.de.js
+++ b/Fuchs/wwwroot/web/fis.req.de.js
@@ -162,6 +162,7 @@ let $ict = {
pna: 'Diese Seite ist in der Vorschau nicht verfügbar',
tpe: 'Die Anzahl von {0} Seiten wird aktuell nicht unterstützt',
eis: 'Der Rechnungsentwurf konnte nicht gespeichert werden.',
+ pvw: 'Das Dokument wird abgerufen und für die Vorschau aufbereitet.\nDer Vorgang kann bis zu 2 Minuten dauern.',
pvf: 'Die PDF-Vorschau konnte nicht erstellt werden.',
pvto: 'Der Server hat nicht rechtzeitig geantwortet (Zeitüberschreitung). Bitte versuchen Sie es erneut.',
pvgone: 'Der Entwurf ist auf dem Server nicht mehr vorhanden (Sitzung abgelaufen). Bitte öffnen Sie den Entwurf erneut.',
@@ -693,13 +694,27 @@ $inv.pdfPreviewFailed = function (jqXHR, textStatus) {
alert(($ict.pvf || $t.f1) + (desc !== '' ? '\n' + desc : ''));
};
/* postXT never calls `error` for a timeout (it returns early), so the timeout is only
- observable from `complete`; this builds the complete handler for a preview call. */
-$inv.pdfPreviewComplete = function (layout) {
+ observable from `complete`; this builds the complete handler for a preview call.
+ `wait`, if given, is the "please wait" popup from `$inv.pdfWaitDlg` — it must close on
+ every outcome (success, error, timeout), so `complete` is the only place that reliably
+ covers all three. */
+$inv.pdfPreviewComplete = function (layout, wait) {
return (jqXHR, textStatus) => {
+ if (wait) { wait.c.trigger('modal_close'); }
if (layout) { layout.rC('freeze'); }
if (textStatus === 'timeout') { $inv.pdfPreviewFailed(jqXHR, textStatus); }
};
};
+/* A preview render can take anywhere from a couple of seconds to the full 120s timeout (a
+ cold miss regenerates + stores the PDF before rasterising it, ADR 0025); postXT's generic
+ `body.ldng` class has no CSS behind it, so nothing tells the user the click was received.
+ Same popup the MFR data fetch shows (see $inv.cInv2): spinner frame in a modal with the
+ explanation in the footer. Non-exclusive so it can sit on top of an open editor. */
+$inv.pdfWaitDlg = function () {
+ let o = $ocms.dlg($$.dc('rfrm').ldng(1), { exclusive: false, zindex_min: 50 });
+ if (o) { o.ft.rwText($ict.pvw); }
+ return o;
+};
/* ── Backend-authoritative draft editing controller (ADR 0006/0007) ───────────
The server holds the truth for an invoice draft in an in-memory session; this
object seeds it, sends single edits as deltas, and renders the totals footer +
@@ -2123,6 +2138,7 @@ $inv.disp = (id, typ) => {
break;
}
if (u !== '') {
+ let wait = $inv.pdfWaitDlg();
$ocms.postXT({
url: $ocms.url(u), data: { id: id || '', typ: 'img' }, timeout: $inv.pdfPreviewTimeout, success: (response) => {
let c = $$.dc('imagecollection pdfpreview'), vhr = Math.round(vh() * 0.88), invid = response.id;
@@ -2132,11 +2148,12 @@ $inv.disp = (id, typ) => {
$ocms.dlg(c, {
size: [vhr, Math.round(vw() * 0.88)], zindex_min: 50, form: false, exclusive:false
});
- }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete()
+ }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete(null, wait)
});
}
};
$inv.jdbn = function (ev) {
+ let wait = $inv.pdfWaitDlg();
$ocms.postXT({
url: $ocms.url('inv/rdocn'), data: { name: ev.data.id || '', typ: 'img' }, timeout: $inv.pdfPreviewTimeout, success: (response) => {
let c = $$.dc('imagecollection pdfpreview'), vhr = Math.round(vh() * 0.88), invid = response.id;
@@ -2146,7 +2163,7 @@ $inv.jdbn = function (ev) {
$ocms.dlg(c, {
size: [vhr, Math.round(vw() * 0.88)], zindex: 50, form: false
});
- }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete()
+ }, error: $inv.pdfPreviewFailed, complete: $inv.pdfPreviewComplete(null, wait)
});
};
$inv.sp13b = () => {
diff --git a/Fuchs/wwwroot/web/fis.req.de.min.js b/Fuchs/wwwroot/web/fis.req.de.min.js
index fdb7fc5..6e684b6 100644
--- a/Fuchs/wwwroot/web/fis.req.de.min.js
+++ b/Fuchs/wwwroot/web/fis.req.de.min.js
@@ -1 +1 @@
-let $rct={mdl:"Aufträge",or:"offene Aufträge",orr:"offene Aufträge (4 W)",rn:"Auftragsnummer",iov:{all:"Auftragsübersicht (alle)","":"Auftragsübersicht"},wk:"Woche",nd:"Keine Daten gefunden.",h:"Uhr",rq1:"Auftragsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",rq2:"Auftragsdaten werden geladen",rq1f:"Die Auftragsdaten von MFR konnten nicht oder nicht schnell genug abgerufen werde.\nMöchten Sie mit den bestehenden Daten trotzdem weitermachen?",note1:"Im Bruttobetrag sind {0} Lohnkosten enthalten (netto {1}). Die darin enthaltene Umsatzsteuer beträgt {2}.",note2:"Bitte beachten Sie, nach §14 Abs. 1 Umsatzsteuergesetz ist diese Rechnung ein Zahlungsbeleg oder eine andere beweiskräftige Unterlage für 2 Jahre nach Ablauf des Kalenderjahres der Ausstellung dieser Rechnung aufzubewahren, soweit nicht aufgrund anderer gesetzlicher Regelungen andere ggf.längere Aufbewahrungsfristen gelten.",note3:"Privathaushalten erstattet das Finanzamt bis zu {0} des Arbeitslohns mit der nächsten Steuererklärung.",note4:"Für bereits erbrachte Arbeiten, Dienstleistungen, Materiallieferungen und getätigte Bestellvorgänge zum oben genannten Bauvorhaben, die sich aus dem mit Ihnen geschlossenen Vertrag ergeben, stellen wir Ihnen vertragsgemäß unsere Akontozahlung in Rechnung. Eine Endabrechnung erhalten Sie als Schlussrechnung nach Abschluss des gesamten Bauvorhabens. Das Ausführungsdatum entnehmen Sie bitte dem Schlusstext dieser Rechnung. Wir danken Ihnen herzlich für das entgegengebrachte Vertrauen und bitten Sie um kurzfristigen Ausgleich der Akontorechnung.",note13b:"Gem. §13b Umsatzsteuergesetz unterliegen Sie der Steuerschuldnerschaft des Leistungsempfängers zur Umsatzsteuer aus dieser Rechnung mit einem Steuersatz von 19%.",crI:"Rechnung erstellen",crII:"Abschlagsrechnung erstellen",dII:"Für eine Abschlagsrechnung darf nur ein Auftrag gewählt werden.",dnS:"Für eine Rechnung muss mindestens ein Auftrag gewählt werden.",inv:"Rechnung",invs:"Rechnungen",req:"Auftrag",provP:"Leistungszeitraum",provD:"Leistungsdatum",cP:"Position ändern",iRb:"Zeile darunter einfügen",dR:"Zeile löschen",sV:"USt festlegen",cD:"Löschen?",mR:"Zeile verschieben",ctxM:"Weitere Aktionen",noteToggle:"Notiz ein-/ausblenden",sectionTitleEditTT:"Auftragsbezeichnung ändern",svcPart:"Service-Anteil",vat:"Umsatzsteuer",combP:"Positionen zusammenfassen",toSetP:"Auf Setpreis umstellen (Positionen ohne Preis)",toSetPc:"Der Set-Preis wird auf die Summe seiner Positionen gesetzt und die Positionen selbst verlieren ihren Preis. Das ist nicht rückgängig zu machen (der Betrag kann danach nur noch manuell geändert werden). Fortfahren?",toSetMc:"Jedes Set erhält die Summe seiner Positionen als Set-Preis; die Positionen des Sets werden ohne Preis dargestellt bzw. ausgeblendet. Positionen ausserhalb eines Sets bleiben unverändert einzeln aufgeführt. Das ist nicht rückgängig zu machen (die Set-Preise können danach nur noch manuell geändert werden). Fortfahren?",toSetMn:'Diese Rechnung enthält kein Set. Legen Sie zuerst über "Set-Struktur bearbeiten" ein Set an bzw. ordnen Sie Positionen einem Set zu.',iSum:"Zwischensumme",dtRel:"Freigegeben am: ",dtCr:"Erstellt am: ",rqV:"USt des Auftrags?",cthd:"wirklich aus-/einblenden ?",cst:{style:"currency",currency:"EUR"},sts:{IsWorkDone:"Arbeiten erledigt",Closed:"Auftrag geschlossen",SubcontractorPendingConfirmation:"Warten auf Bestätigung (Unterauftrag)",Scheduled:"Geplant",OfferIsRejected:"Angebot abgelehnt",OfferIsSend:"Offen (Angebot versandt)",CollaborationWaitingConfirmation:"Warten auf Bestätigung (Zusammenarbeit)",Released:"Freigegeben",OfferIsConfirmed:"Bestätigt",InProgress:"In Bearbeitung",ReadyForScheduling:"Zur Planung",Created:"Erstellt",Rejected:"Abgebrochen",Invoiced:"Rechnung gestellt","-":"-"},invHR:["Pos.","Menge","Artikelbezeichnung","VK","Summe"],frm:{invoicetitle:"Titel",invoiceaddress:"Adresse",loc:"Leistungsort / Lieferadresse",invoiceemail:"Email",invoiceemailcc:"Zusatzempfänger (CC)",provisionperiod:"Leistungsdatum / -zeitraum"},frmTT:{invoicetitle:"Rechnungstitel ändern",invoiceaddress:"Rechnungsempfänger-Adresse ändern",loc:"Leistungsort oder Lieferadresse ändern",invoiceemail:"Email-Adresse ändern und zusätzliche Email-Empfänger festlegen",provisionperiod:"Leistungsdatum oder -zeitraum ändern"}},$rcol={req:new fields_definition("Auftrag","Aufträge",[{name:"tags",label:"",type:"string",dfnc:function(e,t){""!==(e||"")&&($(this).aC("tags"),e.split(",").forEach((e=>{""!==e&&$(this).append($$.sc("tag "+e.replace(" ","_").replace("/","_").toLowerCase(),e))})))}},{name:"DateOfCreation",label:"Datum",type:"date",title:function(e){$(this).attr("title",$rct.dtCr+fdt(e.DateOfCreation).ne("-")+" \n"+$rct.dtRel+fdt(e.DateReleased).ne("-"))}},{name:"CustomerName",label:"Kunde (Firma)",type:"string"},{name:"Name",label:"Auftragsname",type:"string"},{name:"ExternalId",label:"Auftragsnummer",type:"string"},{name:"ParentExtenalId",label:"PAuftrag",type:"string"},{name:"InvoiceId",label:"RNummer",type:"string",dfnc:function(e,t){$(this).rwText(e," ").find("span").each((function(){$(this).aC("cla").click({id:$(this).text()},$inv.jdbn)}))}},{name:"State",label:"Status",type:"string"},{name:"WorkDoneAt",label:"Erledigt am",type:"date"},{name:"Description",label:"Beschreibung",type:"html"}]),itm:new fields_definition("Auftragsposition","Auftragspositionen",[{name:"NameOrNumber",label:"Bezeichnung",type:"string"},{name:"Type",label:"Typ",type:"select",required:!0,value:"Text",url:[{value:"Text",label:"Text"},{value:"Equipment",label:"Ausrüstung"},{value:"Material",label:"Material"},{value:"Service",label:"Arbeitsleistung"}],change:function(e){$req.quantChange.call(this,e)}},{name:"quantityhours",label:"Anzahl / Menge",type:"number",precision:"0.01",value:1,change:function(e){$inv.quantChange.call(this,e)}},{name:"UnitString",label:"Einheit",type:"select",url:["LFDM","Stck","Std.","QM","AW","Pauschal"],change:function(e){$inv.quantChange.call(this,e)}},{name:"net",label:"EinzelPreis netto",type:"number",precision:"0.01",value:0,change:function(e){$inv.quantChange.call(this,e)}},{name:"net_val",label:"GesamtPreis netto",type:"number",precision:"0.01",value:0},{name:"vat_val",label:"GesamtPreis USt",type:"number",precision:"0.01",value:0},{name:"svcnet_val",label:"Arbeitslohn netto",type:"number",precision:"0.01",value:0},{name:"svcvat_val",label:"Arbeitslohn USt",type:"number",precision:"0.01",value:0},{name:"net_pos",label:"Netto",type:"string"},{name:"bo_pos",label:"Brutto",type:"string"},{name:"vat",label:"USt",type:"string",value:"19,0%",change:function(e){$inv.quantChange.call(this,e)}},{name:"Note",label:"Details",type:"html",tinymce:!0}])},$ict={mdl:"Rechnungen",iov:{all:"Rechnungen (alle)","":"Rechnungen (nur fertige)","#d":"Rechnungen (nur Entwürfe)","#u":"Rechnungen (nur unbezahlt)","#r":"Rechnungen (nur angemahnt)","#a":"Rechnungen (nur Akonto)","#c":"Rechnungen (nur Storno)","#ru":"Rechnungen (nur angemahnt + unbez.)"},uba:", gesamter Zeitraum)",req:"Auftrag",inv:"Rechnung",rem:"Mahnung",in:"Rechnungsnummer",cc:"Kunde",wk:"Woche",nd:"Keine Daten gefunden.",dl:"Herunterladen",ed:"Bearbeiten",ced:"Bearbeitung fortsetzen",sItm:"Einzelheiten anzeigen",sPay:"Zahlungen anzeigen",cdI:"Entwurf der Rechnung löschen?",rel:"Neu Laden",relm:"Bitte laden Sie Liste manuell neu, um die Änderungen zu sehen.",dsp:"Rechnung anzeigen",storno:"Storno-Rechnung erstellen",credit:"Gutschrift erstellen",remd:"Mahnung erstellen",remdt:"Mahnung erstellen zur Rechnung {0}",remlst:"Mahnungen anzeigen",remdsp:"Mahnung anzeigen",remres:"Mahnung erneut senden",remresc:"Mahnung {0} wirklich erneut senden?",remresr:"Mahnung {0} wurde erfolgreich versandt.",setpyd:"Bezahlt markieren",cpyd:"Rechnung wirklich als bezahlt markieren?",setupd:"Bezahlt-Markierung aufheben",cupd:"Bezahlt-Markierung wirklich aufheben?",ivE:"Die Email-Adresse ist vermutlich nicht gültig.",ivEc:"\nMöchten Sie fortfahren?",pna:"Diese Seite ist in der Vorschau nicht verfügbar",tpe:"Die Anzahl von {0} Seiten wird aktuell nicht unterstützt",eis:"Der Rechnungsentwurf konnte nicht gespeichert werden.",pvf:"Die PDF-Vorschau konnte nicht erstellt werden.",pvto:"Der Server hat nicht rechtzeitig geantwortet (Zeitüberschreitung). Bitte versuchen Sie es erneut.",pvgone:"Der Entwurf ist auf dem Server nicht mehr vorhanden (Sitzung abgelaufen). Bitte öffnen Sie den Entwurf erneut.",iss:"Zwischenstand speichern.",p13b:"USt -> §13b",setm:"Set-Preisanzeige",setmo:{setprice:"Set mit Preis – Positionen ohne Preis",setonly:"Nur Set mit Preis – Positionen ausgeblendet"},setst:"Set-Struktur bearbeiten",setsHint:'Reihenfolge: Zeile per Drag & Drop an den oberen/unteren Rand einer anderen Zeile ziehen (davor/danach) oder ▲▼ nutzen. Zuordnung: Zeile auf die Mitte eines Sets ziehen (hinein) bzw. auf die Auftragszeile oder "oberste Ebene" (aus dem Set lösen); ◀▶ ändert die Ebene. Sets lassen sich über das Dreieck zu-/aufklappen und auch zugeklappt verschieben – ihre Positionen wandern mit. Änderungen werden sofort übernommen.',setsUp:"Nach oben (innerhalb der Ebene)",setsDown:"Nach unten (innerhalb der Ebene)",setsCollapse:"Set zuklappen",setsExpand:"Set aufklappen",setsHR:["","Pos.","Typ","Menge","Bezeichnung","Reihenfolge / Ebene"],setsRoot:"Hierher ziehen = aus dem Set lösen (oberste Ebene)",setsOut:"Eine Ebene höher (aus dem Set lösen)",setsIn:"Eine Ebene tiefer (dem vorangehenden Set zuordnen)",setsNew:"Neu:",setsInto:"in",setsTop:"oberste Ebene",setsTitle:"Bezeichnung",setsAdd:"Hinzufügen",setsNoTitle:"(ohne Bezeichnung)",settyp:{set:"Set",text:"Text",title:"Text",material:"Material",service:"Arbeitsleistung",equipment:"Ausrüstung",other:"Position",osum:"Zusammenfassung",intinvoiceallocation:"Abschlag",intinvoiceallocationdiff:"Abschlag (offen)"},ctp:"Ansprechpartner festlegen",mfr:"Von MFR neu abrufen",rq1:"Auftragsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",rq2:"Auftragsdaten werden geladen",iq1:"Rechnungsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",iq2:"Rechnungsdaten werden geladen",sis:"Rechnung als versandt markieren",srs:"Mahnung als versandt markieren",sisc:"Rechnung wirklich als versandt markieren?",srsc:"Mahnung wirklich als versandt markieren?",iSt:{dft:"Entwurf",uns:"nicht versandt",pyd:"bezahlt",cc:"storniert",op:"offen",due:"fällig",ovd:"überfällig",rem:"angemahnt"},rSt:["","Überfällig","2. Mahnung","3. Stufe"],pSt:{a:"Vollst.",p:"Teilz."},ivT:{i:"AbschlagsR.",f:"SchlussR",r:"Rechnung",c:"StornoR."},rovlh:"Übersicht der bisherigen Mahnungen",rovl:["Betreff","Betrag","Betrag gezahlt","fertiggestellt am"],remHR:["Rechnung","vom","Rechnungsbetrag","bereits bezahlt","noch offen"],translatePaymentTerm:e=>(e||"").replace("wd"," Werktagen").replace("d"," Tagen").replace("wk"," Wochen")||"10 Tagen",payi:{account:"Konto",name:"Zahler",text:"Verw.Zweck",InvoiceID:"Rechnung",amount:"Betrag",date:"Datum",manual:"Typ"}},$invcol={datev:new fields_definition("Rechnung","Rechnungen",[{name:"Umsatz (ohne Soll/Haben-Kz)",label:"Umsatz (ohne Soll/Haben-Kz)",type:"string"},{name:"vf",label:"vf",type:"string"},{name:"Soll/Haben-Kennzeichen",label:"Soll/Haben-Kennzeichen",type:"string"},{name:"Konto",label:"Konto",type:"string"},{name:"Gegenkonto",label:"Gegenkonto",type:"string"},{name:"BU-Schlüssel",label:"BU-Schlüssel",type:"string"},{name:"Belegdatum",label:"Belegdatum",type:"string"},{name:"Belegfeld 1",label:"Belegfeld 1",type:"string"},{name:"Belegfeld 2",label:"Belegfeld 2",type:"string"},{name:"Buchungstext",label:"Buchungstext",type:"string"}]),inv:new fields_definition("Rechnung","Rechnungen",[{name:"invstatus",label:"Status",type:"select",url:$ict.iSt},{name:"balance",label:"Umsatz",type:"string",dtype:"currency"},{name:"CustomerName",label:"Kunde",type:"string"},{name:"InvoiceId",label:"RNummer",type:"string"},{name:"InvoiceType",label:"Typ",type:"select",url:$ict.ivT},{name:"request",label:"Auftrag",type:"string",dtype:"num"},{name:"vat",label:"MwSt",type:"string",dtype:"num"},{name:"deb_cred",label:"Soll/Haben",type:"string"},{name:"customer",label:"Konto",type:"string",dtype:"num"},{name:"contra_account",label:"Gegenkonto",type:"string",dtype:"num"},{name:"Belegdatum",label:"Belegdatum",type:"date"},{name:"reminderstatus",label:"MahnStatus",type:"select",url:$ict.rSt},{name:"reminder",label:"# Mahnungen",type:"integer"},{name:"Buchungstext",label:"Buchungstext",type:"string"},{name:"Payment",label:"Zahlung",type:"string"}]),rem:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"amount",label:"Rechnungsbetrag",type:"number",precision:"0.01",value:1},{name:"amount_payed",label:"bereits bezahlt",type:"number",precision:"0.01",value:1}]),rem2:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"DocumentName",label:"Name",type:"string"},{name:"subject",label:"Betreff",type:"string"},{name:"DateSent",label:"Versanddatum",type:"date"},{name:"status",label:"Status",type:"string"},{name:"amount_open",label:"offener Betrag",type:"number",precision:"0.01"},{name:"InvoiceId",label:"RNummer",type:"string"}]),rid:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"type",label:"Typ",type:"select",url:[["f","einfache Zahlungserinnerung"],["m","Mahnung"],["l","letzte Mahnung"]],required:!0},{name:"level",label:"Stufe",type:"select",url:[["1","Stufe 1"],["2","Stufe 2"],["3","Stufe 3"],["4","Stufe 4"],["5","Stufe 5"],["6","Stufe 6"]],required:!0}]),ctp:new fields_definition("Ansprechpartner","Ansprechpartner",[{name:"name",label:"Name",type:"string"},{name:"email",label:"Email",type:"string"}])},gi=(e,t)=>$$.sc("glyphicon glyphicon-"+e).aC(t),$inv={},$req={init2:function(e,t){e=e||"inv",t=t||{},$ocms.getScript([],(function(){$req.init3(e,t)}))},init3:async function(e,t){$fis.cf(!0);let n=$fis.lf(!0);$("#topbar").ocmsmenu([]),$("#activemodule").text($rct.mdl),await $fis.prepAuth("fds_req,fds_inv,fds_reminder");let i=[(async()=>{!0===$fis.isAuth("fds_req",1)&&($req.prepLst(""),n.aC("fix"))})(),new Promise(((e,t)=>{n.find("div.oreq2").aC("selected"),$req.renderreq(fdt(new Date,"yy-MM-dd"),"r"),e()}))];await Promise.all(i)},prepLst:function(e){let t=new Date,n=$fis.lf(!0).ldng(1),i=new Date("2021-01-01");$fis.frm_list().IN((function(){}));$$.dc("mth oreq",n).text($rct.or).click((function(e){let t=$(this);e.stopPropagation(),t.siblings().rC("selected"),!0===t.is(".selected")&&(t.tC("selected"),$req.renderreq(fdt(new Date,"yy-MM-dd"),"o")),t.aC("selected")})),$$.dc("mth oreq2",n).text($rct.orr).click((function(e){let t=$(this);e.stopPropagation(),t.siblings().rC("selected"),!0===t.is(".selected")&&(t.tC("selected"),$req.renderreq(fdt(new Date,"yy-MM-dd"),"r")),t.aC("selected")})),$$.i({placeholder:$rct.rn}).appendTo($$.dc("mth oreqn",n)).enterKey((function(e){let t=$(this),n=t.val()||"";e.stopPropagation(),t.parent().siblings().rC("selected"),n.length>3&&(t.parent().aC("selected"),$req.renderreq("n:"+n,"s"),t.val(""))}));n.append("");let r=$$.dc("mthl",n),a=t.getFullYear(),s=t.getMonth()+1;for(let t=i.getFullYear();t<=a;t++){let n=$$.dc("yr").prependTo(r).text($rct.iov[e]+" - "+t.toString()).toggleClass("selected",t===a);n.click({yr:t},(function(e){e.stopPropagation(),n.siblings().rC("selected"),n.aC("selected")}));let l=$$.dc("mfrm",n);for(let n=0;n<(t!==a?12:s);n++){i=new Date(t,n,1);let r=$$.dc("mth").prependTo(l).text($rct.iov[e]+" - "+fdt(i,"MMM yyyy"));r.click({yr:t,mt:n},(function(e){if(e.stopPropagation(),r.siblings().rC("selected"),!0===r.is(".selected")){r.tC("selected");let t=fdt(new Date(e.data.yr,e.data.mt,1),"yy-MM-dd");$req.renderreq(t,"m")}r.aC("selected")}));let a=getMonday(i),s=new Date(i);s.setMonth(s.getMonth()+1),s.setDate(0),s=getMonday(s);let d=$$.dc("wfrm",r);for(;a<=s;){let e=$$.dc("wk",d).text(($rct.wk||"W")+" "+fdt(a,"dd.MM.yy"));e.click({rd:new Date(a)},(function(t){t.stopPropagation();let n=fdt(t.data.rd,"yy-MM-dd");$req.renderreq(n,"w"),r.siblings().rC("selected").find(".wk").rC("selected"),r.aC("selected").find(".wk").rC("selected"),e.aC("selected")}));let t=$$.dc("wkdl",e).append($$.sc("ico glyphicon glyphicon-compressed"));!0===$fis.isAuth("fds_inv",2)&&t.click({rd:new Date(a)},(function(e){e.stopPropagation();let t=fdt(e.data.rd,"yy-MM-dd");$req.downloadzip.call(t,"w")})),a.setDate(a.getDate()+7)}}}n.ldng(0)},renderreq:function(e,t){let n=$fis.frm_list().ldng(1),i=$$.dc("invfrm",n).aC("md"+t),r=$fis.lf();$ocms.postXT({url:$ocms.url("req/reql"),data:{mode:t,tgt:e},success:n=>{r.rC("fix").aC("hd"),$$.dc("ovhd",i).append($$.s(n.admin.title)).appendIf($$.sc("note",n.admin.note),""!==ne(n.admin.note,""));let a=$$.tblset({},i),s=$rcol.req,l=$$.tr(a.hd);$$.th(l);$.each(s.fields||[],((e,t)=>{$$.th(l).text(t.label),"vat"===t.name&&$$.th(l)}));let d=0,c=!1;$.each(n.requests||[],((n,l)=>{d>0&&d!==l.ParentServiceRequestId&&(c=!c);let o=$$.tr(a.bdy).tC("alt",c);d=l.ParentServiceRequestId,o.click((function(){r.rC("fix").aC("hd"),o.tC("selected").siblings().rC("selected").find("td.av").rC("av"),o.find("td.av").rC("av")})),o.tC("child",l.isChild);let u=$$.td(o,{class:"raux"});!0===bool(l.open,!1)&&$$.dc("ihd ilbtn",u).append(gi("eye-close","ico")).click({id:l.Id},$req.tHd),$$.dc("iitm ilbtn",u).append(gi("list","ico")).click({id:l.Id},$req.showitm),!0===$fis.isAuth("fds_inv",2)&&$$.dc("invc ilbtn",u).append(gi("edit","ico")).click({id:l.Id},$inv.cInv),$.each(s.fields||[],((n,r)=>{let a=$$.td(o).aC(r.dtype),s=l[r.name];if("function"==typeof r.dfnc)r.dfnc.call(a,s,l);else switch(r.type||""){case"date":a.text(fdt(l[r.name],"dd.MM.yy"));break;case"datetime":a.text(fdt(l[r.name]));break;case"html":a.append($$.dc("ctw").html(s)),a.append($$.dc("ttip").html(s));break;default:a.text(l[r.name])}switch(r.name||""){case"State":a.text($rct.sts[s||"-"]);break;case"Name":a.aC(r.name.toLowerCase());break;case"vat":$$.sel().appendTo($$.td(o,{class:"vsel"})).click((function(e){e.stopPropagation()})).append([$$.opt("19,0 %","19,0 %"),$$.opt("16,0 %","16,0 %"),$$.opt("0,0 %","0,0 %")]).val(l[r.name]).change().change({frm:i,tgt:e,mode:t,id:l.Id,td:a},$req.setvat),a.tC("hl","19"!==l[r.name].substr(0,2)).click((function(e){e.stopPropagation(),$(this).tC("av")}));break;case"balance":a.aC("sh_"+(l.SollHaben||"").toLowerCase());break;case"InvoiceId":a.aC("keep")}switch(typeof r.title){case"function":r.title.call(a,l);break;case"string":a.attr("title",cs.title)}}))}))},complete:()=>{n.ldng(0)}})},tHd:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&confirm($rct.cthd)&&$ocms.postXT({url:$ocms.url("req/rthd"),data:{id:e.data.id},success:n=>{n.id===e.data.id&&!1===bool(n.visible,!0)?(!1===t.is(".tbhd")&&setTimeout((()=>{t.filter(".tbhd").remove()}),15e3),t.aC("tbhd")):n.id===e.data.id&&t.rC("tbhd")}})},showitm:function(e){let t=$(this).closest("tr");if(e.stopPropagation(),!1===t.is(".selected"))return;let n=$$.dc("rfrm").ldng(1);$ocms.postXT({url:$ocms.url("req/pget"),data:{id:e.data.id},success:t=>{$ocms.postXT({url:$ocms.url("req/get"),data:{id:e.data.id,mode:"ful"},success:e=>{if((e.requests||[]).length<1)n.text($rct.nd);else{let t=$$.dc("srq",n),i=$$.tblset({class:"if"},t);$.each(e.requests||[],(function(e,t){e>0&&$$.tr(i.bdy).aC("sep").append($$.td({colspan:6}));let n=$$.tr(i.bdy).aC("title"),r=$rcol.itm.lbl(),a=$inv.worknotes(t);$$.td(n,{colspan:6}).append([$$.s($rcol.req.label_sng),$$.sc("eid",t.ExternalId),$$.sc("nme",fdt(t.WorkDoneAt,"dd.MM.yy")+": "+a.ne(t.Name))]);$$.tr(i.bdy).aC("shd").append([$$.td(),$$.td(r.NameOrNumber),$$.td(r.Type),$$.td(r.net_pos),$$.td(r.bo_pos),$$.td(r.vat)]);$.each(t.items||[],((e,t)=>{t.ServiceRequestId;let n=$$.tr(i.bdy,{id:"itm"+t.Id}).aC(t.Type);$$.td(n).aC("ico"),$$.td(n).text(t.NameOrNumber),$$.td(n).text(t.Type),$$.td(n).aC("currency").text(t.net_pos),$$.td(n).aC("currency").text(t.bo_pos),$$.td(n).aC("num").text(t.vat)}))}))}},error:()=>{n.text($t.t12)},complete:()=>{n.ldng(0)}})},error:()=>{n.text($t.t12),n.ldng(0)}}),$ocms.dlg(n,{width:1e3})}},$$req={init2:$req.init2,auth:{}};export default $$req;$inv.cInv=function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&!1!==$fis.isAuth("fds_inv",2)&&$inv.cInv2({id:e.data.id})},$inv.rMn=e=>{let t=[{lbl:$ict.req,itm:[]}];return!0===bool(e,!1)&&!0===$fis.isAuth("fds_inv",2)&&Array.prototype.push.apply(t[0].itm,[{lbl:$rct.crI,fnc:$inv.ccInv,data:{typ:"r"}},{lbl:$rct.crII,fnc:$inv.ccInv,data:{typ:"i"}}]),t.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(t)},$inv.iMnr=e=>{let t=booln(e.isFinal,!0),n=e.Id,i=booln(e.fds,!1),r=[{glyph:"glyphicon-menu-left",fnc:()=>{$fis.frm_edit().remove()}},{lbl:$ict.inv,itm:[]},{lbl:$ict.rem,itm:[]}];return!1===t&&!0===$fis.isAuth("fds_inv",2)?r[1].itm.push({lbl:$ict.ced,fnc:$inv.clCntInv}):!0===$fis.isAuth("fds_inv",1)&&r[1].itm.push({lbl:$ict.dsp,fnc:()=>$inv.disp(n,"inv")}),!0===i&&!0===t&&!0===$fis.isAuth("fds_inv",2)&&(r[1].itm.push({lbl:$ict.storno,fnc:()=>$inv.storno(n,i)}),r[1].itm.push({lbl:$ict.credit,fnc:()=>$inv.credit(n,i)})),!0===t&&!0===$fis.isAuth("fds_reminder",2)&&(r[2].itm.push({lbl:$ict.remd,fnc:()=>$inv.ccRem(n,e.InvoiceId)}),r[2].itm.push({lbl:$ict.remlst,fnc:()=>$inv.dspRem(n)})),!0===t&&!0===$fis.isAuth("fds_reminder",2)&&!1===booln(e.IsSent,!1)&&r[2].itm.push({lbl:$ict.srs,fnc:()=>$inv.srs(n)}),r.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(r)},$inv.iMn=e=>{let t=booln(e.isFinal,!0),n=e.Id,i=booln(e.fds,!1),r=[{glyph:"glyphicon-menu-left",fnc:()=>{$fis.frm_edit().remove()}},{lbl:$ict.inv,itm:[]},{lbl:$ict.rem,itm:[]}];return!1===t&&!0===$fis.isAuth("fds_inv",2)?r[1].itm.push({lbl:$ict.ced,fnc:()=>{$inv.cntInv({id:n})}}):!0===$fis.isAuth("fds_inv",1)&&r[1].itm.push({lbl:$ict.dsp,fnc:()=>$inv.disp(n,"inv")}),!0===$fis.isAuth("fds_inv",2)&&(r[1].itm.push({lbl:$ict.storno,fnc:()=>$inv.storno(n,i)}),r[1].itm.push({lbl:$ict.credit,fnc:()=>$inv.credit(n,i)})),!0===t&&!1===booln(e.IsPayed,!1)?(!0===$fis.isAuth("fds_reminder",2)&&r[2].itm.push({lbl:$ict.remd,fnc:()=>$inv.ccRem(n,e.InvoiceId)}),!0===$fis.isAuth("fds_inv",2)&&r[1].itm.push({lbl:$ict.setpyd,fnc:()=>$inv.setPyd(n)})):!0===t&&!0===booln(e.IsPayed,!1)&&"m"===(e.PaymentStatus||"")&&!0===$fis.isAuth("fds_inv",2)&&r[1].itm.push({lbl:$ict.setupd,fnc:()=>$inv.setUpd(n)}),!0===$fis.isAuth("fds_reminder",2)&&r[2].itm.push({lbl:$ict.remlst,fnc:()=>$inv.dspRem(n)}),!0===t&&!0===$fis.isAuth("fds_inv",2)&&!1===booln(e.IsSent,!1)&&r[1].itm.push({lbl:$ict.sis,fnc:()=>$inv.sis(n)}),!1===i&&r[1].itm.push({lbl:$ict.mfr,fnc:()=>$inv.mfrrel(n)}),$("#topbar").ocmsmenu(r)},$inv.emOpt=()=>"iss,p13b,ctp,setst,setm",$inv.eM=(e,t,n)=>{let i=[];return!0!==booln(e,!1)&&!0!==booln(t,!1)||i.push({glyph:"glyphicon-menu-left",fnc:()=>{$fis.lf(!0),$fis.frm_edit().remove()}}),!0===(n||"").split(",").includes("iss")&&i.push({lbl:$ict.iss,fnc:$inv.ssave}),!0===(n||"").split(",").includes("ctp")&&i.push({lbl:$ict.ctp,fnc:$inv.sctp}),!0===(n||"").split(",").includes("p13b")&&i.push({lbl:$ict.p13b,fnc:$inv.sp13b}),!0===(n||"").split(",").includes("setm")&&i.push({lbl:$ict.setm,fnc:$inv.ssetmode}),!0===(n||"").split(",").includes("setst")&&i.push({lbl:$ict.setst,fnc:()=>$inv.sets.open()}),!0===(n||"").split(",").includes("iss")&&(i.push({lbl:"Änderungshistorie",fnc:()=>$inv.d.history()}),i.push({lbl:"Änderungen verwerfen",fnc:()=>$inv.d.discard()})),!0===booln(e,!1)&&i.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(i)},$inv.pdfPreviewTimeout=12e4,$inv.pdfPreviewFailed=function(e,t){if(11110===(e||{}).internalCode)return void $ocms.login.dlg();let n=((e||{}).internalText||"").trim();""===n&&"timeout"===t&&(n=$ict.pvto),""===n&&410===(e||{}).status&&(n=$ict.pvgone),alert(($ict.pvf||$t.f1)+(""!==n?"\n"+n:""))},$inv.pdfPreviewComplete=function(e){return(t,n)=>{e&&e.rC("freeze"),"timeout"===n&&$inv.pdfPreviewFailed(t,n)}},$inv.d={tbl:()=>$("div.invoice_layout table.invi"),layout:()=>$("div.invoice_layout"),token:function(){return $inv.d.tbl().data("dtoken")||""},hashes:function(){let e=$inv.d.tbl().data("bai")||[],t={};return $.each(e,((e,n)=>{t[(n.Id||"").toString()]=JSON.stringify(n)})),t},seed:function(e){let t=$inv.d.layout();t.aC("freeze");let n=$ocms.postXT({url:$ocms.url("inv/dopen"),data:{payload:JSON.stringify(e)},success:e=>{$inv.d.tbl().data("dtoken",e.token).data("dver",e.version).data("dhashes",$inv.d.hashes()).data("dorder",$inv.d.order()),$fis.draft.bind(e.token,{onReady:()=>$inv.d.refresh(),onExpiring:e=>$inv.d.warnExpiry(e),onClosed:e=>$inv.d.closed(e)}),$inv.d.refresh()},error:()=>{t.rC("freeze")},complete:()=>{$inv.d.tbl().removeData("dseeding").removeData("dseedpromise")}});return $inv.d.tbl().data("dseedpromise",n),n},refresh:function(e){let t=$inv.d.token();""!==t&&$ocms.postXT({url:$ocms.url("inv/dstate"),data:{token:t},success:t=>{$inv.d.applyState(t),"function"==typeof e&&e(t)},error:e=>{e&&410===e.status&&$inv.d.closed("expired")},complete:()=>{$inv.d.layout().rC("freeze")}})},applyState:function(e){let t=$inv.d.tbl();if(t.length<1)return;let n=t.data("dver");"number"==typeof n&&"number"==typeof e.version&&e.version$$.dc("dnote").aC(e.style||"InvoiceNotes").text(e.text)))},applyItems:function(e,t){let n=e=>void 0===e?null:e;(t||[]).forEach((t=>{if(!t)return;let i=(t.Id||"").toString();if(""===i)return;let r=e.children("tbody").filter(((e,t)=>(($(t).data()||{}).Id||"").toString()===i)).first();if(r.length<1)return;let a=t.itm||[],s={},l=r.find("tr.title").first(),d=l.length?l:null;a.forEach((e=>{let t=(e.id||"").toString();if(""===t)return;s[t]=!0;let i=r.find("#itm"+t).first(),a=i.length<1;a&&(i=$$.tr(r,{id:"itm"+t,class:"itm"}));let l=i.data()||{},c=a||(l.Type||"")!==(e.typ||"")||l.net!==n(e.v)||l.net_val!==n(e.vt)||l.vat_val!==n(e.vv)||l.svcnet_val!==n(e.vs)||l.svcvat_val!==n(e.vsv)||(l.position||"")!==(null!=e.p?e.p:"")||(l.lvl||0)!==(e.lvl||0)||(l.SetItmId||null)!==(null!=e.SetItmId?e.SetItmId:null);$.extend(l,{Id:t,Type:e.typ,net:n(e.v),net_val:n(e.vt),vat_val:n(e.vv),svcnet_val:n(e.vs),svcvat_val:n(e.vsv),vat:e.vat,position:null!=e.p?e.p:"",SetItmId:null!=e.SetItmId?e.SetItmId:null,lvl:e.lvl||0}),a&&$.extend(l,{htmltext:e.t,quantity:e.q}),i.data(l),d?i.prev()[0]!==d[0]&&i.insertAfter(d):r.children().first()[0]!==i[0]&&r.prepend(i),d=i,c&&$inv.rrw.call(i)})),r.find("tr.itm").each(((e,t)=>{let n=(($(t).data()||{}).Id||"").toString();""===n||s[n]||$(t).remove()}))}))},applySetDisplay:function(e,t){e.find("tr.itm").each(((e,n)=>{let i=$(n),r=((i.data()||{}).Id||"").toString();if(""===r||!Object.prototype.hasOwnProperty.call(t,r))return;let a=t[r]||{};i.tC("sethdr",bool(a.h,!1)),!1===bool(a.p,!0)&&i.find("td.currency").text("")}))},sync:function(e){let t=$inv.d.token();if(""===t){let t=$inv.d.tbl().data("dseedpromise");return t?$.when(t).then((()=>$inv.d.sync(e))):$.when()}return $inv.d.layout().aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dpatch"),data:{token:t,delta:JSON.stringify(e)},success:()=>{$inv.d.refresh()},error:e=>{$inv.d.layout().rC("freeze"),e&&410===e.status&&$inv.d.closed("expired")}})},order:function(){return($inv.d.tbl().data("bai")||[]).map((e=>(e.Id||"").toString()))},syncChanged:function(e){let t=e.data("bai")||[],n=e.data("dhashes")||{},i={},r=[],a=[],s=[];$.each(t,((e,t)=>{let a=(t.Id||"").toString(),s=JSON.stringify(t);i[a]=s,n[a]!==s&&r.push(t)})),$.each(n,(e=>{void 0===i[e]&&a.push(e)}));let l=$inv.d.order(),d=e.data("dorder")||[];return e.data("dhashes",i).data("dorder",l),r.forEach((e=>s.push($inv.d.sync({Target:"block.replace",Ref:(e.Id||"").toString(),Value:e})))),a.forEach((e=>s.push($inv.d.sync({Target:"block.remove",Ref:e})))),d.length===l.length&&d.slice().sort().join(",")===l.slice().sort().join(",")&&d.join(",")!==l.join(",")&&s.push($inv.d.sync({Target:"block.order",Value:l})),$.when.apply($,s).promise()},syncField:function(e,t){let n={invoicetitle:"title",invoiceaddress:"address",invoiceemail:"email",invoiceemailcc:"emailcc",loc:"provisionlocation",provisionlocation:"provisionlocation",provisionperiod:"provisionperiod"}[e];n&&$inv.d.sync({Target:n,Value:t})},footer:function(e,t,n){let i=e.children("tfoot").empty();e.nextAll(".fnote").remove();let r=bool(n.p13b,!1),a=(e,t,n)=>$$.tdc("currency",$$.tr(i,{class:n||"tsum"}).append([$$.tdc("aux"),$$.td({colspan:4}).text(e)]),fnum(t,$rct.cst)),s=t=>$$.dc("fnote").insertAfter(e).rwText(t);a("Netto",t.total_net||0),!1===r&&$.each(t.vat||{},((e,t)=>a($rct.vat+" "+e+"%",t,"tvat"))),a("Summe",t.total_gross||0);let l=n.type||"";"i"===l?(s($rct.note2),s($rct.note4)):"c"===l?s($rct.note2):(s(string($rct.note3,[fnum(((t.service_net||0)+(t.service_vat||0))*(n.tax_servicerefund||0),$rct.cst)])).aC("ntax"),s($rct.note2),s(string($rct.note1,[fnum((t.service_net||0)+(t.service_vat||0),$rct.cst),fnum(t.service_net||0,$rct.cst),fnum(t.service_vat||0,$rct.cst)]))),!0===r&&s($rct.note13b)},validation:function(e){let t=$("div.invoice_layout");if(t.length<1)return;let n=t.children(".dvalidation");n.length<1&&(n=$$.dc("dvalidation"),t.prepend(n)),n.empty().tC("hidden",(e||[]).length<1),$.each(e||[],((e,t)=>$$.dc("dvmsg",n).aC(t.severity).text(t.message)))},preview:function(){let e=$inv.d.token();if(""===e)return;let t=$inv.d.layout(),n=($inv.d.tbl().data("new")||{}).invoiceemail||"";!1===$fis.ValidateEmail(n)&&!1===bool(confirm($ict.ivE+$ict.ivEc),!1)||(t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dpreview"),data:{token:e},timeout:$inv.pdfPreviewTimeout,success:n=>{t.rC("freeze");let i=$$.dc("imagecollection pdfpreview"),r=Math.round(.88*vh()),a=n.total;a>10&&$$.dc("note warn",i).text($ict.tpe),$.each(n.img||[],((e,t)=>{$$.dc("pdfp",i).append($$.img(t).css("max-height",(r-rpx(6)).toString()+"px"))}));for(let e=(n.img||[]).length+1;e<=a;e++)$$.dc("pdfp ph",i).append($$.dc("note",$ict.pna));$ocms.dlg(i,{size:[r,Math.round(.88*vw())],zindex:50,form:!1,button:$rct.crI,confirm:function(n){let i=$(this);t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dsave"),data:{token:e},success:e=>{$ocms.postXT({url:$ocms.url("req/sconf"),data:{id:e.invid},success:t=>{i.trigger("modal_close"),!0===t.hasFile&&window.open($ocms.url("req/idoc")+"?id="+e.invid,"_blank"),$inv.d.close(),$ocms.init("req"),$inv.rReload()},error:()=>{alert($t.f1),i.trigger("modal_close")},complete:()=>{t.rC("freeze")}})},error:()=>{t.rC("freeze"),alert($ict.eis)}})},cancel:function(e){confirm($ict.cdI)&&($inv.d.close(),$inv.rReload())}})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(t)}))},save:function(){let e=$inv.d.token();if(""===e)return;let t=$inv.d.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dsave"),data:{token:e},success:e=>{$inv.d.tbl().data("invid",e.invid)},error:()=>{alert($ict.eis)},complete:()=>{t.rC("freeze")}})},history:function(){let e=$inv.d.token();""!==e&&$ocms.postXT({url:$ocms.url("inv/dhistory"),data:{token:e},success:e=>{let t=$$.dc("dhist");if((e.history||[]).length<1)$$.dc("note",t).text("Noch keine Änderungen erfasst.");else{let n=$$.tblset({class:"invtbl fullwidth"},t);$$.tr(n.hd).append([$$.th().text("Zeit"),$$.th().text("Feld"),$$.th().text("Alt"),$$.th().text("Neu")]),$.each(e.history,((e,t)=>$$.tr(n.bdy).append([$$.tdc("keep",fdt(t.timestamp)),$$.td().text(t.target),$$.td().text(t.oldValue),$$.td().text(t.newValue)])))}$ocms.dlg(t,{width:800,form:!1})}})},discard:function(){let e=$inv.d.tbl().data("invid")||"";""!==e?!1!==confirm("Alle Änderungen verwerfen und den zuletzt gespeicherten Stand neu laden?")&&($inv.d.close(),$inv.cntInv({id:e})):alert("Es wurde noch kein Zwischenstand gespeichert, der wiederhergestellt werden könnte.")},warnExpiry:function(e){let t=Math.max(1,Math.round((e||0)/60));$fis.notifications.push({severity:"info",title:"Entwurf läuft ab",message:"Der Rechnungsentwurf läuft in etwa "+t+" Minute(n) ab. Bitte zwischenspeichern, sonst gehen die Änderungen verloren."})},closed:function(e){let t=$inv.d.token();$inv.d.tbl().removeData("dtoken"),""!==t&&$fis.draft.release(t),$fis.frm_edit().remove(),$fis.lf(!0),$fis.notifications.push({severity:"error",title:"Entwurf geschlossen",message:"expired"===e?"Der Rechnungsentwurf ist wegen Inaktivität abgelaufen. Nicht gespeicherte Änderungen sind verloren.":"Der Rechnungsentwurf wurde geschlossen."});try{$inv.rReload()}catch(e){}},close:function(){let e=$inv.d.token();""!==e&&($ocms.postXT({url:$ocms.url("inv/dclose"),data:{token:e}}),$fis.draft.release(e)),$inv.d.tbl().removeData("dtoken")}},$inv.rd={tbl:()=>$("div.invoice_layout table.invi"),layout:()=>$("div.invoice_layout"),token:function(){return $inv.rd.tbl().data("rdtoken")||""},seed:function(e){let t=$inv.rd.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dopen"),data:{payload:JSON.stringify(e)},success:e=>{$inv.rd.tbl().data("rdtoken",e.token).data("rdver",e.version),$fis.draft.bind(e.token,{onReady:()=>$inv.rd.refresh(),onExpiring:e=>$inv.rd.warnExpiry(e),onClosed:e=>$inv.rd.closed(e)}),$inv.rd.refresh()},error:()=>{t.rC("freeze")}})},refresh:function(e){let t=$inv.rd.token();""!==t&&$ocms.postXT({url:$ocms.url("rem/dstate"),data:{token:t},success:t=>{$inv.rd.applyState(t),"function"==typeof e&&e(t)},error:e=>{e&&410===e.status&&$inv.rd.closed("expired")},complete:()=>{$inv.rd.layout().rC("freeze")}})},applyState:function(e){let t=$inv.rd.tbl();if(t.length<1)return;let n=t.data("rdver");"number"==typeof n&&"number"==typeof e.version&&e.version{let t=$$[0]("p").aC("dnote intro").rwText(e);r.length?t.insertBefore(r):t.appendTo(n)})),((e||{}).closing||[]).forEach((e=>$$[0]("p").aC("dnote closing").rwText(e).appendTo(n)))},sync:function(e){let t=$inv.rd.token();""!==t&&($inv.rd.layout().aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dpatch"),data:{token:t,delta:JSON.stringify(e)},success:()=>{$inv.rd.refresh()},error:e=>{$inv.rd.layout().rC("freeze"),e&&410===e.status&&$inv.rd.closed("expired")}}))},syncField:function(e,t){if(""===$inv.rd.token())return;let n={subject:"subject",invoiceaddress:"address",invoiceemail:"email",text:"text"}[e];n&&$inv.rd.sync({Target:n,Value:t})},syncAmount:function(e,t){""!==$inv.rd.token()&&($inv.rd.sync({Target:"amount",Value:(null!=e?e:0).toString()}),$inv.rd.sync({Target:"amount_payed",Value:(null!=t?t:0).toString()}))},footer:function(e,t){let n=e.children("tfoot").empty(),i=$$.tr(n,{class:"tsum"}).append([$$.tdc("aux"),$$.td({colspan:4}).text("Offener Betrag")]);$$.tdc("currency",i,fnum(t.amount_open||0,$rct.cst))},validation:function(e){let t=$inv.rd.layout();if(t.length<1)return;let n=t.children(".dvalidation");n.length<1&&(n=$$.dc("dvalidation"),t.prepend(n)),n.empty().tC("hidden",(e||[]).length<1),$.each(e||[],((e,t)=>$$.dc("dvmsg",n).aC(t.severity).text(t.message)))},preview:function(){let e=$inv.rd.token();if(""===e)return;let t=$inv.rd.layout(),n=($inv.rd.tbl().data("new")||{}).invoiceemail||"";!1===$fis.ValidateEmail(n)&&!1===bool(confirm($ict.ivE+$ict.ivEc),!1)||(t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dpreview"),data:{token:e},timeout:$inv.pdfPreviewTimeout,success:n=>{t.rC("freeze");let i=$$.dc("imagecollection pdfpreview"),r=Math.round(.88*vh());$.each(n.img||[],((e,t)=>{$$.dc("pdfp",i).append($$.img(t).css("max-height",(r-rpx(6)).toString()+"px"))})),$ocms.dlg(i,{size:[r,Math.round(.88*vw())],zindex:50,form:!1,button:$ict.remd,confirm:function(n){let i=$(this);t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dsave"),data:{token:e},success:e=>{$ocms.postXT({url:$ocms.url("rem/conf"),data:{id:e.remid},success:()=>{i.trigger("modal_close"),window.open($ocms.url("rem/idoc")+"?id="+e.remid,"_blank"),$inv.rd.close(),$ocms.init("req"),$inv.rReload()},error:()=>{alert($t.f1),i.trigger("modal_close")},complete:()=>{t.rC("freeze")}})},error:()=>{t.rC("freeze"),alert($t.f1)}})},cancel:function(e){confirm($ict.cdI)&&($inv.rd.close(),$inv.rReload())}})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(t)}))},save:function(){let e=$inv.rd.token();if(""===e)return;let t=$inv.rd.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dsave"),data:{token:e},success:e=>{$inv.rd.tbl().data("remid",e.remid)},error:()=>{alert($t.f1)},complete:()=>{t.rC("freeze")}})},history:function(){let e=$inv.rd.token();""!==e&&$ocms.postXT({url:$ocms.url("rem/dhistory"),data:{token:e},success:e=>{let t=$$.dc("dhist");if((e.history||[]).length<1)$$.dc("note",t).text("Noch keine Änderungen erfasst.");else{let n=$$.tblset({class:"invtbl fullwidth"},t);$$.tr(n.hd).append([$$.th().text("Zeit"),$$.th().text("Feld"),$$.th().text("Alt"),$$.th().text("Neu")]),$.each(e.history,((e,t)=>$$.tr(n.bdy).append([$$.tdc("keep",fdt(t.timestamp)),$$.td().text(t.target),$$.td().text(t.oldValue),$$.td().text(t.newValue)])))}$ocms.dlg(t,{width:800,form:!1})}})},warnExpiry:function(e){let t=Math.max(1,Math.round((e||0)/60));$fis.notifications.push({severity:"info",title:"Entwurf läuft ab",message:"Der Mahnentwurf läuft in etwa "+t+" Minute(n) ab. Bitte zwischenspeichern, sonst gehen die Änderungen verloren."})},closed:function(e){let t=$inv.rd.token();$inv.rd.tbl().removeData("rdtoken"),""!==t&&$fis.draft.release(t),$fis.frm_edit().remove(),$fis.lf(!0),$fis.notifications.push({severity:"error",title:"Entwurf geschlossen",message:"expired"===e?"Der Mahnentwurf ist wegen Inaktivität abgelaufen. Nicht gespeicherte Änderungen sind verloren.":"Der Mahnentwurf wurde geschlossen."});try{$inv.rReload()}catch(e){}},close:function(){let e=$inv.rd.token();""!==e&&($ocms.postXT({url:$ocms.url("rem/dclose"),data:{token:e}}),$fis.draft.release(e)),$inv.rd.tbl().removeData("rdtoken")}},$inv.cInv2=function(e){let t=$$.dc("rfrm").ldng(1),n=$ocms.dlg(t,{width:1e3});n&&n.ft.rwText($rct.rq1);let i=()=>{$ocms.postXT({url:$ocms.url("req/get"),timeout:60,data:{id:e.id,mode:"r"},success:t=>{t.admin=t.admin||{};let n=$fis.lf(!0).aC("fix").rC("hd");if($fis.frm_edit().IN(),$inv.eM(!0,!0),(t.requests||[]).length<1)n.aC("fix").text($rct.nd);else{$$.dc("lh",n,$rct.mdl);let i=$$.d(),r=$$.ul({class:"rql"}).data({search:e.id,parent:t.admin.parent}).appendTo(n),a={},s=$rcol.req.lbl();$.each(t.requests||[],(function(e,t){let n=$$.li({class:"cli rli"}).data($.extend({},t)).appendTo(r),l=$$.dc("lihd",n).addClass(t.state);!0===booln(t.open,!1)&&l.append($$.sc("cbox").click((()=>{n.tC("checked"),i.find("li").rC("checked"),!0===n.is(".checked")?$inv.rMn(t.open):$inv.eM(!0)}))),l.append([$$.sc("eid",t.ExternalId),$$.sc("nme",t.Name)]),$$.dc("lidt",n).append([$$.dc("rqs").append([$$.s(s.State+": "),$$.s($rct.sts[t.State||"-"])]),$$.dc("ivn").append([$$.s(s.InvoiceId+": "),$$.s(t.InvoiceId||"- -")]),$$.dc("wda").append([$$.s(s.WorkDoneAt+": "),$$.s(fdt(t.WorkDoneAt,"dd.MM.yyyy"))])]),a[t.Id]=n})),(t.inv||[]).length>0&&($$.dc("lh",n,$rct.invs),i=$$.ul({class:"ivl"}).appendTo(n),$.each(t.inv||[],((e,t)=>{let n=$$.li({class:"cli ili"}).data($.extend({},t)).appendTo(i),a=$$.dc("lihd",n).addClass(t.invstatus);!1===booln(t.isFinal,!0)?a.append($$.sc("cbox").click((()=>{""!==(t.Id||"")&&(n.tC("checked").siblings().rC("checked"),r.find("li").rC("checked"),!0===n.is(".checked")?$inv.iMnr(t):$inv.eM(!0))}))):["","dft"].indexOf(t.invstatus)<0&&a.append($$.sc("dli").click((function(){$inv.disp(t.Id,"inv")}))),a.append($$.sc("nme",t.DocumentName||t.Id)),$$.dc("lidt",n).append([$$.dc("wda").append([$$.s(fdt(t.DateCreated,"dd.MM.yyyy"))]),$$.d().text($ict.iSt[t.invstatus]||t.invstatus)])})))}},complete:()=>{n&&n.c.trigger("modal_close")}})};$ocms.postXT({url:$ocms.url("req/pget"),timeout:90,data:{id:e.id},success:e=>{n&&n.ft.rwText($rct.rq2),i()},error:()=>{confirm($rct.rq1f)?(n&&n.ft.rwText($rct.rq2),i()):n&&n.c.trigger("modal_close")}})},$inv.ccInv=function(e){let t=(e.data||{}).typ||"r",n=$fis.lf(),i=n.children("ul.rql"),r=i.data("parent"),a=[];if(i.find("li.rli.checked").each((function(){a.push($(this).data("Id"))})),a.length<1)return void alert($rct.dnS);if("i"===t&&a.length>1)return void alert($rct.dII);let s=$fis.frm_edit(),l=$$.dc("invoice_layout",s).append($$.dc("btn sprev").click($inv.sprev)),d=$fis.cf().width()>l.width()+n.width()+20;n.tC("fix",d).tC("hd",!d),$inv.eM(!1,!0);let c=$$.dc("rfrm").ldng(1),o=$ocms.dlg(c,{width:1e3});o.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("req/iget"),timeout:60,data:{id:r,mode:"ful",typ:t,sel:a.join(",")},success:e=>{let t=$$.dc("srq",l),n=$$.tblset({class:"invi"},t);n.bdy.remove(),n.ft=$$[0]("tfoot"),e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b")),n.tbl.data($.extend({new:{},sms:{},itm:{}},{admin:e.admin,companies:e.companies,locations:e.locations}));let i=$$.tr(n.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(i,e))),n.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.requests||[],(function(t,i){if(0!==(i.Id||0)){let t=$inv.worknotes(i);i.text="i"===e.admin.type?$rct.req+jine([i.ExternalId,i.Name],": ").eine(" ",""):jine([jine([fdt(i.WorkDoneAt,"dd.MM.yy"),i.ExternalId]," - "+$rct.req+" "),t.ne(i.Name)],": \n");let r=$$.tbody(n.tbl).data($.extend({},i));$inv.rendersrq.call(r)}}));let r=$$.tr($$.tbody(n.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(r),n.ft.appendTo(n.tbl);let a,s,d=e.admin||{},c=(e,t,i,r,a)=>{let s=$$.dc("inpfrm",l).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",s).rwText(t);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{n.tbl.data("new")[i]=e}},a),$inv.eHtml)),n.tbl.data("new")[i]=t};c("tfrm",d.invoicetitle,"invoicetitle",0,null),c("adrfrm",d.invoiceaddress,"invoiceaddress",0,null),c("locfrm","","loc",1,{list:deepCopy(e.locations),lbl:"ref",property:"address"}),$inv.emailFrm(l,n,d.invoiceemail,d.invoiceemailcc),$$.dc("sndfrm",l).append($$.dc("content").text(d.sender)),d.provisionend&&(s=d.provisionstart?$rct.provP:$rct.provD,a=d.provisionstart?fdt(d.provisionstart,"dd.MM.yyyy")+" - "+fdt(d.provisionend,"dd.MM.yyyy"):fdt(d.provisionend,"dd.MM.yyyy")),c("admfrm",a,"provisionperiod",s,1),n.tbl.data("new").CustomValues=d.CustomValues||"",$$.dc("inpfrm ctpfrm",l).text(jObj(d.CustomValues,"contactName")),n.tbl.children("tbody").each($inv.bdysort),n.tbl.trigger("fds.inv"),$inv.eM(!1,!0,$inv.emOpt())},complete:()=>{o.c.trigger("modal_close")}})},$inv.ccStInv=function(e){let t=e.data||{},n=$fis.lf(),i=t.id,r=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sprev)),a=$fis.cf().width()>r.width()+n.width()+20;n.tC("fix",a).tC("hd",!a),$inv.eM(!1,!0);let s=$$.dc("rfrm").ldng(1),l=$ocms.dlg(s,{width:1e3});l.ft.rwText($ict.iq1),$ocms.postXT({url:$ocms.url("inv/pget"),timeout:90,data:{id:t.id},success:e=>{l&&l.ft.rwText($ict.iq2),$ocms.postXT({url:$ocms.url("inv/icget"),timeout:60,data:{id:i},success:e=>{let t=$$.dc("srq",r),n=$$.tblset({class:"invi"},t);n.bdy.remove(),n.ft=$$[0]("tfoot"),e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b")),n.tbl.data($.extend({new:{},sms:{},itm:{}},{admin:e.admin,companies:e.companies,locations:e.locations}));let i=$$.tr(n.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(i,e))),n.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.requests||[],(function(t,i){if(0!==(i.Id||0)){let t=$inv.worknotes(i);i.text="i"===e.admin.type?$rct.req+jine([i.ExternalId,i.Name],": ").eine(" ",""):jine([fdt(i.WorkDoneAt,"dd.MM.yy")+t.ne(i.Name)],": ");let r=$$.tbody(n.tbl).data($.extend({},i));$inv.rendersrq.call(r)}}));let a=$$.tr($$.tbody(n.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(a),n.ft.appendTo(n.tbl);let s,l,d=e.admin||{},c=(e,t,i,a,s)=>{let l=$$.dc("inpfrm",r).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(t);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{n.tbl.data("new")[i]=e}},s),$inv.eHtml)),n.tbl.data("new")[i]=t};c("tfrm",d.invoicetitle,"invoicetitle",0,null),c("adrfrm",d.invoiceaddress,"invoiceaddress",0,null),c("locfrm",d.provisionlocation,"loc",1,{list:deepCopy(e.locations),lbl:"ref",property:"address"}),$inv.emailFrm(r,n,d.invoiceemail,d.invoiceemailcc),$$.dc("sndfrm",r).append($$.dc("content").text(d.sender)),d.provisionend&&(l=d.provisionstart?$rct.provP:$rct.provD,s=d.provisionstart?fdt(d.provisionstart,"dd.MM.yyyy")+" - "+fdt(d.provisionend,"dd.MM.yyyy"):fdt(d.provisionend,"dd.MM.yyyy")),c("admfrm",s,"provisionperiod",l,1),n.tbl.data("new").CustomValues=d.CustomValues||"",$$.dc("inpfrm ctpfrm",r).text(jObj(d.CustomValues,"contactName")),n.tbl.children("tbody").each($inv.bdysort),n.tbl.trigger("fds.inv")},complete:()=>{l.c.trigger("modal_close")}})},error:()=>{l&&l.c.trigger("modal_close")}})},$inv.clCntInv=function(e){let t=$fis.lf(!1),n=[];t.find("li.ili.checked").each((function(){n.push($(this).data("Id"))})),1===n.length&&$inv.cntInv({id:n[0]})},$inv.cntInv=function(e){e=e||{};$fis.lf(!1).rC("fix").aC("hd");let t=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sedit));$inv.eM(!1,!0);let n=$$.dc("rfrm").ldng(1),i=$ocms.dlg(n,{width:1e3});i.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("inv/get"),timeout:60,data:{id:e.id},success:e=>{e.admin=e.admin||{};let n=e.inv||{},i=$$.dc("srq",t),r=$$.tblset({class:"invi"},i);r.bdy.remove(),r.ft=$$[0]("tfoot"),r.tbl.data($.extend({invid:n.Id,new:{},sms:{},itm:{},bai:[]},e));let a=$$.tr(r.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(a,e))),r.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.req||[],(function(e,t){let n=$$.tbody(r.tbl).data($.extend({},t));$inv.rendersrq.call(n)}));let s=$$.tr($$.tbody(r.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(s),r.ft.appendTo(r.tbl);let l=(e,n,i,a,s)=>{let l=$$.dc("inpfrm",t).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(n);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{r.tbl.data("new")[i]=e}},s),$inv.eHtml)),r.tbl.data("new")[i]=n};l("tfrm",n.InvoiceTitle,"invoicetitle",0,null),l("adrfrm",n.SendToAddress,"invoiceaddress",0,null),l("locfrm",n.ProvisionLocation,"loc",1,null),$inv.emailFrm(t,r,n.SendToEmail,n.SendToEmailCc),$$.dc("sndfrm",t).append($$.dc("content").text(e.admin.sender)),l("admfrm",n.ProvisionPeriod,"provisionperiod",!0===(n.ProvisionPeriod||"").includes("-")?$rct.provP:$rct.provD,1),r.tbl.data("new").CustomValues=n.CustomValues||"",$$.dc("inpfrm ctpfrm",t).text(jObj(n.CustomValues,"contactName")),r.tbl.children("tbody").each($inv.bdysort),r.tbl.trigger("fds.inv"),$inv.eM(!1,!0,$inv.emOpt())},complete:()=>{i.c.trigger("modal_close")}})},$inv.cSt=function(e){e=e||{};let t=$fis.lf(),n=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sedit)),i=$fis.cf().width()>n.width()+t.width()+20;t.tC("fix",i).tC("hd",!i),$inv.eM(!1,!0);let r=$$.dc("rfrm").ldng(1),a=$ocms.dlg(r,{width:1e3});a.ft.rwText($ict.iq1),$ocms.postXT({url:$ocms.url("inv/pget"),data:{id:e.id},success:t=>{a&&a.ft.rwText($ict.iq2),$ocms.postXT({url:$ocms.url("inv/storno"),data:{id:e.id,mode:e.mode},success:e=>{e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b"));let t=e.inv||{},i=$$.dc("srq",n),r=$$.tblset({class:"invi"},i);r.bdy.remove(),r.ft=$$[0]("tfoot"),r.tbl.data($.extend({invid:t.Id,new:{},sms:{},itm:{},bai:[]},e));let a=$$.tr(r.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(a,e))),r.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.req||[],(function(e,t){let n=$$.tbody(r.tbl).data($.extend({},t));$inv.rendersrq.call(n)}));let s=$$.tr($$.tbody(r.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(s),r.ft.appendTo(r.tbl);let l=(e,t,i,a,s)=>{let l=$$.dc("inpfrm",n).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(t);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{r.tbl.data("new")[i]=e}},s),$inv.eHtml)),r.tbl.data("new")[i]=t};l("tfrm",t.InvoiceTitle,"invoicetitle",0,null),l("adrfrm",t.SendToAddress,"invoiceaddress",0,null),l("locfrm",t.ProvisionLocation,"loc",1,null),$inv.emailFrm(n,r,t.SendToEmail,t.SendToEmailCc),$$.dc("sndfrm",n).append($$.dc("content").text(e.admin.sender)),l("admfrm",t.ProvisionPeriod,"provisionperiod",!0===(t.ProvisionPeriod||"").includes("-")?$rct.provP:$rct.provD,1),r.tbl.data("new").CustomValues=t.CustomValues||"",$$.dc("inpfrm ctpfrm",n).text(jObj(t.CustomValues,"contactName")),r.tbl.children("tbody").each($inv.bdysort),r.tbl.trigger("fds.inv")},complete:()=>{a.c.trigger("modal_close")}})},error:()=>{a&&a.c.trigger("modal_close")}})},$inv.adrCountries=[["DE","Deutschland"],["AT","Österreich"],["CH","Schweiz"],["FR","Frankreich"],["NL","Niederlande"],["BE","Belgien"],["LU","Luxemburg"],["IT","Italien"],["ES","Spanien"],["PL","Polen"],["DK","Dänemark"],["CZ","Tschechien"],["GB","Großbritannien"],["US","USA"]],$inv.composeAddress=function(e){let t=[],n=e=>{""!==(e=(""+(e||"")).trim())&&t.push(e)};n((e=e||{}).name),""!==(""+(e.contact||"")).trim()&&n("z.Hd. "+(""+e.contact).trim()),n(e.line2||e.addressLine2),n(e.street),n(((e.postalCode||"")+" "+(e.city||"")).trim());let i=(""+(e.countryCode||"")).toUpperCase();return""!==i&&"DE"!==i&&n(i),t.join("\n")},$inv.adrCurrent=function(e){let t=jObj((e.data("new")||{}).CustomValues,"sendToAddress");if("string"==typeof t&&"{"===t.trim().charAt(0))try{t=JSON.parse(t)}catch(e){t=null}if(t&&"object"==typeof t)return t;let n=(e.data("admin")||{}).invoiceaddressData;if("string"==typeof n&&"{"===n.trim().charAt(0))try{return JSON.parse(n)}catch(e){}else if(n&&"object"==typeof n)return n;return{}},$inv.eAddress=function(e){let t=$inv.d.tbl(),n=$inv.adrCurrent(t),i=[{name:"name",label:"Name / Firma",type:"text",value:n.name||"",required:!0},{name:"contact",label:"z.Hd. (optional)",type:"text",value:n.contact||""},{name:"street",label:"Straße + Nr.",type:"text",value:n.street||""},{name:"line2",label:"Adresszusatz (optional)",type:"text",value:n.line2||n.addressLine2||""},{name:"postalCode",label:"PLZ",type:"text",value:n.postalCode||""},{name:"city",label:"Ort",type:"text",value:n.city||""},{name:"countryCode",label:"Land",type:"select",url:$inv.adrCountries,value:n.countryCode||"DE"},{name:"vatId",label:"USt-IdNr. (nur bei Firmen)",type:"text",value:n.vatId||""},{name:"leitwegId",label:"Leitweg-ID (nur Behörden / B2G)",type:"text",value:n.leitwegId||""}],r=$$.dc("adr-conformity").append([$$.dc("hd").text("Hinweis zur DATEV-/eRechnungs-Konformität"),$$.dc("tx").text("Pflicht: Name, Straße, PLZ, Ort und Land. Die USt-IdNr. nur bei Firmen angeben — für eine Rechnung an eine Privatperson einfach leer lassen. Eine Leitweg-ID nur bei Behörden (B2G) — dann wird die Rechnung automatisch als XRechnung erzeugt.")]);$ocms.dlgform(i,{title:"Rechnungsempfänger",addcontent:r,success:function(t){let n={name:t.name||"",contact:t.contact||"",line2:t.line2||"",street:t.street||"",postalCode:t.postalCode||"",city:t.city||"",countryCode:t.countryCode||"DE",vatId:(""+(t.vatId||"")).trim(),leitwegId:(""+(t.leitwegId||"")).trim()},i=$inv.composeAddress(n);e.data&&e.data.t&&e.data.t.rwText(i),"function"==typeof(e.data||{}).change&&e.data.change(i),$inv.d.sync({Target:"address",Value:n})}})},$inv.provToIso=function(e){let t=(""+(e||"")).match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);return t?t[3]+"-"+("0"+t[2]).slice(-2)+"-"+("0"+t[1]).slice(-2):""},$inv.eProvisionPeriod=function(e){let t=(""+(e.data&&e.data.t?e.data.t.text():"")).trim().match(/\d{1,2}\.\d{1,2}\.\d{4}/g)||[],n=[{name:"von",label:"Leistungsdatum",type:"date",value:$inv.provToIso(t[0]||"")},{name:"bis",label:"Leistungszeitraum – bis (optional)",type:"date",value:$inv.provToIso(t[1]||"")}],i=$$.dc("adr-conformity").append([$$.dc("hd").text("Leistungsdatum / -zeitraum"),$$.dc("tx").text('Für ein einzelnes Datum nur „Leistungsdatum" ausfüllen; für einen Zeitraum zusätzlich das Bis-Datum. Nur strukturierte Datumsauswahl — für die E-Rechnung empfohlen.')]);$ocms.dlgform(n,{title:"Leistungsdatum / -zeitraum",addcontent:i,success:function(t){let n=(""+(t.von||"")).trim(),i=(""+(t.bis||"")).trim(),r=""===n?"":""===i||i===n?n:n+" - "+i;e.data&&e.data.t&&e.data.t.rwText(r),"function"==typeof(e.data||{}).change&&e.data.change(r),$inv.d.sync({Target:"provisionperiod",Value:r})}})},$inv.eEmail=function(e){let t=[{name:"email",label:$rct.frm.invoiceemail,type:"text",value:(e.data.t||$$.s()).text()},{name:"emailcc",label:$rct.frm.invoiceemailcc,type:"text",value:(e.data.ccT||$$.s()).text()}];$ocms.dlgform(t,{title:$rct.frm.invoiceemail,success:function(t){let n=(""+(t.email||"")).trim(),i=(""+(t.emailcc||"")).trim();e.data&&e.data.t&&e.data.t.text(n),e.data&&e.data.ccT&&e.data.ccT.text(i),"function"==typeof(e.data||{}).change&&e.data.change(n),"function"==typeof(e.data||{}).changeCc&&e.data.changeCc(i),$inv.d.syncField("invoiceemail",n),$inv.rd.syncField("invoiceemail",n),$inv.d.syncField("invoiceemailcc",i),$inv.rd.syncField("invoiceemailcc",i)}})},$inv.emailFrm=function(e,t,n,i){let r=$$.dc("inpfrm emailccfrm",e),a=$$.dc("content",r).rwText(i),s=$$.dc("inpfrm emailfrm",e),l=$$.dc("content",s).rwText(n);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT.invoiceemail}).append(gi("pencil")).click({t:l,ccT:a,nme:"invoiceemail",change:e=>{t.tbl.data("new").invoiceemail=e},changeCc:e=>{t.tbl.data("new").invoiceemailcc=e}},$inv.eHtml)),t.tbl.data("new").invoiceemail=n,t.tbl.data("new").invoiceemailcc=i},$inv.eHtml=function(e){if(e.data&&!(e.data instanceof jQuery)&&$inv.d&&"function"==typeof $inv.d.token&&""!==$inv.d.token()){if("invoiceaddress"===e.data.nme)return $inv.eAddress.call(this,e);if("provisionperiod"===e.data.nme)return $inv.eProvisionPeriod.call(this,e)}if(e.data&&!(e.data instanceof jQuery)&&"invoiceemail"===e.data.nme&&e.data.ccT)return $inv.eEmail.call(this,e);let t=$(this),n=e.data instanceof jQuery?e.data:e.data.t,i=["invoiceemail","invoiceemailcc","provisionperiod","invoicetitle"].includes(e.data.nme),r=i?[{name:"txt",label:"Text",type:"text",value:n.text()}]:[{name:"txt",label:"Text",type:"html",value:n.html(),tinymce:!0,attr:{style:"height: 300px"}}],a=e.data.change||null,s={title:t.data("dialog")||"",success:function(t){i?n.text(t.txt||""):n.html(t.txt),"function"==typeof a&&a(t.txt),$inv.d.syncField(e.data.nme,i?t.txt||"":t.txt),$inv.rd.syncField(e.data.nme,i?t.txt||"":t.txt)},tinymce:{valid_elements:"br",hidemenu:!0,hidetoolbar:!0}};if(Array.isArray(e.data.list)){let t=$$.dc("lstfrm");$.each(e.data.list,((n,i)=>{let r=$$.dc("li",t).append(""!==(e.data.lbl||"")?$$.dc("lbl").rwText(i[e.data.lbl]):null);$$.dc("adr",r).rwText(i[e.data.property]).data("val",i[e.data.property]).click((function(){let e=$(this),t=e.closest(".modal-body").find(':input[name="txt"]');t.is(".tinymce")?tinymce.get(t.attr("id")).setContent($$.s().rwText(e.data("val")).html()):"TEXTAREA"===t.prop("tagName")?t.val(e.data("val")).change():t.rwText(e.data("val"))}))})),s.addcontent=t}$ocms.dlgform(r,s)},$inv.setVat=function(e){$(this);let t=e.data,n=prompt($rct.rqV);n&&(n=parseFloat(n.replace("%","")),n>1&&(n*=.01),!1===isNaN(n)&&(t.siblings(".itm").each((function(){$(this).data().vat=fnum(n,{style:"percent"}).replace(" ","")})),$inv.t_fds_inv()))},$inv.inRow=function(e){let t=$(this),n=e.data,i={},r=$rcol.itm.clone(["SortOrder","NameOrNumber","Type","quantityhours","UnitString","net","svcnet_val","svcvat_val","net_val","vat_val","vat","Note"]),a="N"+(65536*(1+Math.random())||0).toString(16).substr(6),s=$$.tr({id:"itm_"+a.toString(),class:"itm"});$ocms.dlgform(r,{title:t.data("dialog")||"",success:function(e){s.data($.extend({Id:a},i,e)),$inv.rrw.call(s),s.insertAfter(n),$inv.t_fds_inv()},typedvalues:!0})},$inv.eRow=function(e){let t=$(this),n=e.data,i=n.data()||{},r=["SortOrder","NameOrNumber","Type","quantityhours","UnitString","net","svcnet_val","svcvat_val","net_val","vat_val","vat","Note"];i.id||""!==(i.Type||"")||r.unshift("Type");let a=$rcol.itm.clone(r).applyValues(i);a.set("Type","hidden","type"),$inv.eRw.call(t,n,i,a)},$inv.eRw=function(e,t,n){let i=$(this);$ocms.dlgform(n,{title:i.data("dialog")||"",success:function(n){let i={};""===(t.Id||"")&&(i.Id="N"+(65536*(1+Math.random())||0).toString(16).substr(6),e.attr("id","itm_"+i.Id.toString())),i.quantity=((n.quantityhours||"").toString()+" "+(n.UnitString||"").toString()).trimEnd(),e.data($.extend({},t,n,i)),console.debug("eRw success %o",e.data()),$inv.rrw.call(e),$inv.t_fds_inv()},typedvalues:!0})},$inv.bdysort=(e,t)=>{$(t).Sortable({dragItem:!1,dragHandleClass:"ico",parentident:"tr",onend:()=>{$inv.t_fds_inv()}})},$inv.rowCtxMenu=function(e){let t=$$[0]("nav").aC("rowctx");return t.ocmsmenu([{glyph:"glyphicon-option-vertical",aclass:"ctxbtn",attr:{title:$rct.ctxM},itm:e}]),t.find("li[title]").each((function(){let e=$(this);e.children("a").attr("title",e.attr("title"))})),t},$inv.rrw=function(){let e=$(this),t=e.data(),n={},i=e.is(".placeholder"),r=e.is(".hidenote"),a=e=>$$.d().append(e).html(),s=[{lbl:$rct.iRb,attr:{title:$rct.iRb},data:e,fnc:$inv.inRow}];!1===i&&(s.unshift({lbl:$rct.cP,attr:{title:$rct.cP},data:e,fnc:$inv.eRow}),s.push({lbl:$rct.dR,attr:{title:$rct.dR},fnc:function(t){confirm($rct.cD)&&(e.remove(),$inv.t_fds_inv())}}),"set"===(t.Type||"").toLowerCase()&&0===(t.net_val||0)&&s.push({lbl:$rct.toSetP,attr:{title:$rct.toSetP},data:e,fnc:$inv.toSetPrice}));let l=$$.dc("axf").append($inv.rowCtxMenu(s));!0===i?n={id:"",typ:"placeholder"}:!0===e.is(".itm.osum")?n={invrqid:t.InvRqId,id:"osum"+e.index(),typ:"osum",p:"",q:null,t:a(t.tbl.tbl),tt:null,v:null,vt:t.net_val,vs:t.svcnet_val,vat:t.vat,vv:t.vat_val,vsv:t.svcvat_val,det:!1}:(n={invrqid:t.InvRqId,id:t.Id||"",typ:t.Type||"other",p:"",q:null,t:"",tt:null,v:null,vt:t.net_val,vs:t.svcnet_val,vat:t.vat,vv:t.vat_val,vsv:t.svcvat_val,det:""!==(t.Note||"")&&!1===r,SetItmId:t.SetItmId||null,lvl:t.lvl||0},$$.dc("ibtn ico move",l,{title:$rct.mR}),n.p=null!=t.position?t.position:t.SortOrder||"",""===n.id?n.t="":["Text","Title"].includes(n.typ)&&0===(t.net_val||0)?n.t=t.htmltext||("#"!==(t.NameOrNumber||"").substr(0,1)?a($$[0]("p").text(t.NameOrNumber)):"")+(t.Note||""):(n.tt=n.det?"":$$.s(t.Note||"").text(),n.q=t.quantity||(0!==(t.quantityhours||0)?fnum(t.quantityhours)+" "+(t.UnitString||""):""),n.t=t.htmltext||(n.det?a($$.s(t.NameOrNumber||""))+a($$.dc("desc").html(t.Note)):a($$.s(t.NameOrNumber||""))),n.v=t.net,n.vt=t.net_val)),""!==(t.Note||"")&&$$.dc("ibtn add",l,{title:$rct.noteToggle}).append(gi("object-align-left")).click((function(t){$inv.rrw.call(e.tC("hidenote"))}));let d=[$$.tdc("aux").append(l),$$.tdc("keep").text(n.p)];if(""===n.id)d.push($$.td(e,{colspan:4}).append(n.t));else{Array.prototype.push.apply(d,n.q?[$$.tdc("keep").text(n.q)]:[]);let e=e=>null==e?"":fnum(e,$rct.cst);Array.prototype.push.apply(d,[$$.tdc("txt",{colspan:n.q?1:2,title:n.tt}).append(n.t),$$.tdc("currency").text(e(n.v)),$$.tdc("currency inetval").text(e(n.vt)).attr("title",$rct.svcPart+": "+e(n.vs))])}e.empty().attr("class",i?"placeholder":"itm").aC(n.Typ).tC("sethdr","set"===(n.typ||"").toString().toLowerCase()).aC((n.lvl||0)>0?"lvl"+Math.min(n.lvl,6):"").tC("hidenote",r).append(d),t.co=n},$inv.toSetPrice=function(e){let t=(e.data.data().Id||"").toString();""!==t&&!1!==confirm($rct.toSetPc)&&$.when($inv.t_fds_inv()).done((()=>{$inv.d.sync({Target:"item.setprice",Ref:t})}))},$inv.invSumUpdate=function(){let e=$(this),t=[],n=e.children("tbody"),i=[];n.each(((e,n)=>{let r=$(n),a=r.data()||{},s=[],l=[],d=r.find("tr.itm");r.tC("empty",d.length<1),d.each(((e,t)=>{let n=$(t).data()||{};s.push(n.co);let r=$inv.itemToContract(n),a=(n.SetItmId||"").toString();""!==a&&a!==r.id&&(r.setId=a),l.push(r);let d=!1===["text","title"].includes((n.Type||"other").toLowerCase());n.position=((e,t)=>{if(!e)return"";let n=Math.max(t||0,0);for(;i.length<=n;)i.push(0);return i.length=n+1,i[n]++,i.join(".")})(d,(n.co||{}).lvl||0),$inv.rrw.call(t)})),t.push({Id:a.Id,nme:a.Name,text:a.text,itm:s,items:l})}));let r=e.find("tbody:not(.empty)").length;n.find("tr.isum").tC("hidden",r<2),e.data("bai",t),""===(e.data("dtoken")||"")&&!1===bool(e.data("dseeding"),!1)&&null!=(e.data("admin")||{}).type&&(e.data("dseeding",!0),$inv.d.seed($.extend($inv.invcPayload(e.data()),{invid:e.data("invid")||""})))},$inv.worknotes=function(e){let t="";return e.steps.forEach(((e,n)=>{let i;try{i=JSON.parse(e.Data||{}).fields||[]}catch(e){console.debug(e),i=[]}!0!==Array.isArray(i||"")&&(i="object"==typeof i&&!0===Array.isArray(i.field||"")?i.field:[]),i.forEach(((e,n)=>{"Ausgeführte Arbeiten"===e.name&&(t=e.result||"")}))})),t},$inv.rendersrq=function(){let e=$(this).empty(),t=e.is(".onesum"),n=e.data(),i=$$.tr(e,{id:"srq"+n.Id}).aC("title nosort"),r=($rcol.itm.lbl(),$$.dc("axf").appendTo($$.tdc("aux",i)));$$.dc("ibtn osum",r,{title:$rct.combP}).append(gi("euro")).click((function(t){e.tC("onesum"),$inv.rendersrq.call(e),$inv.t_fds_inv()})),$$.dc("ibtn setvat",r,{title:$rct.sV}).append(gi("gbp")).click(i,$inv.setVat),$$.dc("ibtn insb",r,{title:$rct.iRb}).append(gi("indent-left")).click(i,$inv.inRow);let a,s=$$.sc("text",n.text),l=($$.td(i,{colspan:t?4:5}).append(s),["net_val","vat_val","svcnet_val","svcvat_val","net"]);if($$.dc("ibtn edit",r,{title:$rct.sectionTitleEditTT}).data("dialog",$rcol.req.lbl().Name).append(gi("pencil")).click({t:s,change:e=>{n.text=e,$inv.t_fds_inv()}},$inv.eHtml),t&&($$.tdc("currency isumval",i),a={Id:n.Id.toString()+"_osum",net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0},a.tbl=$$.tblset({class:"stbl"})),$.each(n.items||[],((n,i)=>{let r,s={Id:i.Id,net_val:i.net_val||0,vat_val:i.vat_val||0,svcnet_val:0,svcvat_val:0,net:i.net||0,Note:i.Note||""};if("service"===i.Type.toLowerCase())s.svcnet_val=i.net_val||0,s.svcvat_val=i.vat_val||0;t?(r=$$.tr(a.tbl.bdy,{id:"itm"+i.Id,class:"sitm"}).aC(i.Type),"Text"===i.Type||"Title"===i.Type?$$.td(r,{colspan:2}).html(i.htmltext||i.Note):($$.tdc("keep",r).text(i.quantity||((i.quantityhours||0)>0?fnum(i.quantityhours)+(i.UnitString||"").eine(" ",""):"")),i.htmltext?$$.tdc("txt",r).html(i.htmltext):$$.tdc("txt",r).text(i.NameOrNumber).attr("title",i.Note)),$.each(l,((e,t)=>{a[t]+=s[t]})),r.data(s)):($.extend(s,i),r=$$.tr(e,{id:"itm"+i.Id,class:"itm"}),r.data(s),$inv.rrw.call(r))})),t){let t=$$.tr(e,{id:"itmsq"+n.Id,class:"itm osum"}).data(a);$inv.rrw.call(t)}else{let t=$$.tr(e).aC("isum nosort");$$.tdc("aux",t),$$.td(t,{colspan:4}).text($rct.iSum),$$.tdc("currency isumval",t)}},$inv.t_fds_inv=()=>{let e=$("div.invoice_layout table.invi");if(e.trigger("fds.inv"),""!==(e.data("dtoken")||""))return $inv.d.syncChanged(e);let t=e.data("dseedpromise");return t?$.when(t).then((()=>$inv.d.syncChanged(e))):$.when()},$inv.sedit=()=>{$inv.sprev(!0)},$inv.jdisp=function(e){e.stopPropagation(),e.data.id&&$inv.disp(e.data.id,e.data.typ||"")},$inv.disp=(e,t)=>{let n="";switch(t){case"inv":n="inv/rdoc";break;case"rem":n="rem/rdoc"}""!==n&&$ocms.postXT({url:$ocms.url(n),data:{id:e||"",typ:"img"},timeout:$inv.pdfPreviewTimeout,success:e=>{let t=$$.dc("imagecollection pdfpreview"),n=Math.round(.88*vh());e.id;$.each(e.img||[],(function(e,i){$$.dc("pdfp",t).append($$.img(i).css("max-height",(n-rpx(6)).toString()+"px"))})),$ocms.dlg(t,{size:[n,Math.round(.88*vw())],zindex_min:50,form:!1,exclusive:!1})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete()})},$inv.jdbn=function(e){$ocms.postXT({url:$ocms.url("inv/rdocn"),data:{name:e.data.id||"",typ:"img"},timeout:$inv.pdfPreviewTimeout,success:e=>{let t=$$.dc("imagecollection pdfpreview"),n=Math.round(.88*vh());e.id;$.each(e.img||[],(function(e,i){$$.dc("pdfp",t).append($$.img(i).css("max-height",(n-rpx(6)).toString()+"px"))})),$ocms.dlg(t,{size:[n,Math.round(.88*vw())],zindex:50,form:!1})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete()})},$inv.sp13b=()=>{var e=$("div.invoice_layout").find("table.invi"),t=e.data();t.admin.p13b=!0,!1===(t.inv.InvoiceOptions||"").split(",").includes("§13b")&&(t.inv.InvoiceOptions+=",§13b"),e.trigger("fds.inv"),$inv.d.sync({Target:"p13b",Value:t.admin.p13b})},$inv.itemToContract=function(e){let t=((e=e||{}).Type||"").toString().toLowerCase(),n=e=>e??null,i={id:(e.Id||"").toString(),type:t,title:"",desc:"",qty:"",price_net:"",total_net:n(e.net_val),vat:e.vat||""};var r;return e.co&&"osum"===e.co.typ?(i.desc=e.co.t||"",i.total_net=e.net_val||0):["text","title"].includes(t)&&0===(e.net_val||0)?(i.desc=e.htmltext||("#"!==(e.NameOrNumber||"").substr(0,1)?(r=$$[0]("p").text(e.NameOrNumber||""),$$.d().append(r).html()):"")+(e.Note||""),i.total_net=""):(e.htmltext?i.desc=e.htmltext:(i.title=e.NameOrNumber||"",i.desc=e.Note||""),i.qty=e.quantity||(0!==(e.quantityhours||0)?fnum(e.quantityhours)+(e.UnitString?" "+e.UnitString:""):""),i.price_net=n(e.net),i.total_net=n(e.net_val)),i},$inv.hasSets=e=>((e||{}).req||[]).some((e=>{let t=((e||{}).itm||[]).filter((e=>e&&""!==(e.id||""))),n={};t.forEach((e=>{n[(e.id||"").toString()]=e}));return t.some((e=>{let t=(null==e.SetItmId?"":e.SetItmId).toString();return""!==t&&t!==(e.id||"").toString()&&n[t]&&(e=>"set"===(e.typ||"").toString().toLowerCase())(n[t])}))})),$inv.ssetmode=()=>{let e,t=$("div.invoice_layout").find("table.invi").data();if(t.dstate&&!1===$inv.hasSets(t.dstate))return void alert($rct.toSetMn);let n=t=>$$.dc("btn",$ict.setmo[t]).click((()=>{e.c.trigger("modal_close"),$inv.setSetmode(t)})),i=$$.dc("choicefrm").append([n("setprice"),n("setonly")]);e=$ocms.dlg(i,{width:800})},$inv.setSetmode=e=>{if(!1===confirm($rct.toSetMc||$rct.toSetPc))return;let t="setonly"===e?"block.setonly":"block.setprice";$.when($inv.t_fds_inv()).done((()=>{$inv.d.sync({Target:t})}))},$inv.sctp=()=>{let e=$invcol.ctp;$ocms.dlgform(e,{title:$ict.ctp,success:function(e){var t=$("div.invoice_layout"),n=t.find("table.invi").data();let i={};void 0!==n.new&&"{"===(n.new.CustomValues||"").substr(0,1)&&(i=JSON.parse(n.inv.CustomValues)),i.contactName=e.name,i.contactEmail=e.email,n.new.CustomValues=JSON.stringify(i),t.find(".ctpfrm").text(ne(e.name,e.email)),$inv.d.sync({Target:"contact",Value:{name:e.name,email:e.email}})},typedvalues:!0})},$inv.invcPayload=function(e){e=e||{};let t=$.extend({},e.new),n=$.extend({},e.admin);return t.title=null!=t.invoicetitle?t.invoicetitle:t.title||"",t.provisionlocation=null!=t.loc?t.loc:t.provisionlocation||"",t.paymentterm=null!=n.paymentterms?n.paymentterms:t.paymentterm||"",n.customerid=null!=n.customerid?n.customerid:n.CustomerId,{admin:n,req:e.bai,new:t}},$inv.ssave=()=>{$inv.d.save()},$inv.sprev=e=>{$inv.d.preview()},$inv.rReload=()=>{try{let e=$("#listframe ul.rql:first").data();$inv.cInv2({id:e.search})}catch(e){}},$inv.quantChange=function(e){},$inv.storno=function(e,t){let n,i=$$.dc("choicefrm").append([$$.dc("btn","Storno ohne Details").click({id:e,mode:"simple"},(e=>{n.c.trigger("modal_close"),$inv.cSt(e.data)})),$$.dc("btn","Storno mit neuer Rechnung").click({id:e},(e=>{n.c.trigger("modal_close"),$inv.ccStInv(e)})),$$.dc("btn","Storno mit best. Rechnung").tC("inactive",!1===bool(t,!1)).click({id:e,mode:"copy"},(e=>{!0===bool(t,!1)&&(n.c.trigger("modal_close"),$inv.cSt(e.data))}))]);n=$ocms.dlg(i,{width:1e3})},$inv.credit=function(e,t){let n,i=$$.dc("choicefrm").append([$$.dc("btn","Gutschrift").click({id:e,mode:"credit"},(e=>{n.c.trigger("modal_close"),$inv.cSt(e.data)}))]);n=$ocms.dlg(i,{width:1e3})},$inv.setPyd=function(e){confirm($ict.cpyd)&&$ocms.postXT({url:$ocms.url("inv/setpyd"),timeout:60,data:{id:e},success:e=>{alert($ict.relm)},error:()=>{alert($t.f1)}})},$inv.setUpd=function(e){confirm($ict.cupd)&&$ocms.postXT({url:$ocms.url("inv/setupd"),timeout:60,data:{id:e},success:e=>{alert($ict.relm)},error:()=>{alert($t.f1)}})},$inv.resendRem=function(e){e.stopPropagation(),e.data.id&&confirm(string($ict.remresc,[e.data.name]))&&$ocms.postXT({url:$ocms.url("rem/resend"),timeout:60,data:{id:e.data.id},success:t=>{alert(string($ict.remresr,[e.data.name]))},error:()=>{alert($t.f1)}})},$inv.dspRem=function(e){let t=$$.dc("rfrm").ldng(1),n=$ocms.dlg(t,{width:1e3});n.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("inv/getrem"),timeout:60,data:{id:e,drafts:!1},success:e=>{n.ft.empty();let i=$$.tblset({class:"invtbl"},t.empty()),r=$invcol.rem2,a=$$.tr(i.hd);$$.th(a);$.each(r.fields||[],((e,t)=>{$$.th(a).text(t.label)}));let s=!1;$.each(e,((e,t)=>{s=!s;let n=$$.tr(i.bdy).tC("alt",s),a=$$.td(n);n.click((function(){n.tC("selected").siblings().rC("selected")})),!0===bool(t.hasFile,!1)&&($$.dc("idl ilbtn",a,{title:$ict.dl+"\n"+t.DocumentName}).append(gi("save-file","ico")).click({id:t.Id},$inv.downloadrem),$$.dc("idl ilbtn",a,{title:$ict.remdsp+"\n"+t.DocumentName}).append(gi("eye-open","ico")).click({id:t.Id,typ:"rem"},$inv.jdisp),$$.dc("idl ilbtn",a,{title:$ict.remres+"\n"+t.DocumentName}).append(gi("refresh","ico")).click({id:t.Id,typ:"rem",name:t.DocumentName},$inv.resendRem)),$.each(r.fields||[],((e,i)=>{let r=$$.td(n).aC(i.dtype),a=t[i.name];if("function"==typeof i.dfnc)i.dfnc.call(r,a,t);else switch(i.type||""){case"date":r.text(fdt(t[i.name],"dd.MM.yy"));break;case"datetime":r.text(fdt(t[i.name]));break;case"html":r.append($$.dc("ctw").html(a)),r.append($$.dc("ttip").html(a));break;default:r.text(t[i.name])}if("InvoiceId"===(i.name||""))r.aC("keep");switch(typeof i.title){case"function":i.title.call(r,t);break;case"string":r.attr("title",cs.title)}}))}))},error:()=>{t.empty(),n.ft.rwText($t.f1)},complete:()=>{t.ldng(0)}})},$inv.ccRem=function(e,t){$(this);$ocms.postXT({url:$ocms.url("rem/lrem"),timeout:60,data:{id:e},success:n=>{let i=$invcol.rid.clone();i.applyValues(n.ov);let r=$$.dc("ac"),a=$$.tblset({class:"fullgrid fullwidth"},r);if((n.lst||[]).length>0){$$.d({style:"margin: 1.5rem 0 1rem 0;font-size: 110%;text-decoration: underline;"}).prependTo(r).text($ict.rovlh);let e=$$.tr(a.hd);$ict.rovl.forEach(((t,n)=>$$.th(e,t))),$.each(n.lst,((e,t)=>{$$.tr(a.bdy).append([$$.tdc("keep",t.subject),$$.tdc("currency",fnum(t.amount,$rct.cst)),$$.tdc("currency",fnum(t.amount_payed,$rct.cst)),$$.tdc("keep",fdt(t.DateFinalized,"dd.MM.yy"))])}))}else $$.td($$.tr(a.bdy),$ict.nd);$ocms.dlgform(i,{addcontent:r,title:string($ict.remdt,[t||"?"]),success:function(t){$inv.ccRem_s2(e,t)},typedvalues:!0})}})},$inv.rRemRw=function(e){let t=$(this),n=e.rm||{};t.empty().data({invoiceid:n.invoiceid,invoicedate:n.invoicedate,amount:n.amount,amount_payed:n.amount_payed});let i=[{lbl:$rct.cP,attr:{title:$rct.cP},data:t,fnc:$inv.eRowR}],r=$$.dc("axf").append($inv.rowCtxMenu(i));t.append([$$.tdc("aux").append(r),$$.tdc("keep",n.invoiceid),$$.tdc("keep",fdt(n.invoicedate,"dd.MM.yy")),$$.tdc("currency",fnum(n.amount,$rct.cst)),$$.tdc("currency",fnum(n.amount_payed,$rct.cst)),$$.tdc("currency",fnum(n.amount-n.amount_payed,$rct.cst))])},$inv.eRowR=function(e){let t=$(this),n=e.data,i=n.data()||{},r=$invcol.rem.clone().applyValues(i);$ocms.dlgform(r,{title:t.data("dialog")||"",success:function(e){let i=t.closest("table"),r=i.data();$.extend(r.rm,e),i.data(r),$inv.rRemRw.call(n,r),$inv.rd.syncAmount(r.rm.amount,r.rm.amount_payed)},typedvalues:!0})},$inv.ccRem_s2=function(e,t){$fis.lf(!1).rC("fix").aC("hd");let n=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.rprev));$inv.eM(!1,!0);$$.dc("rfrm").ldng(1);$ocms.postXT({url:$ocms.url("rem/get"),timeout:60,data:$.extend({id:e},t),success:e=>{let t=e.rm||{},i=$$.dc("srq",n),r=$$.tblset({class:"invi"},i);r.ft=$$[0]("tfoot"),r.tbl.data($.extend({invid:t.invid,new:{}},e));let a=$$.tr(r.hd).aC("shd").append([$$.th().aC("aux")]);$ict.remHR.forEach((e=>$$.th(a,e))),$inv.rRemRw.call($$.tr(r.bdy),r.tbl.data()),r.ft.appendTo(r.tbl);let s={invoiceemail:"Email-Adresse ändern",subject:"Betreff ändern"},l=(e,t,i,a,l)=>{let d=$$.dc("inpfrm",n).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),c=$$.dc("content",d).rwText(t);$$.dc("axf",d).append($$.dc("ibtn edit",{title:s[i]||$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:c,nme:i,change:e=>{r.tbl.data("new")[i]=e}},l),$inv.eHtml)),r.tbl.data("new")[i]=t};l("tfrm",t.subject,"subject",0,null),l("adrfrm",t.invoiceaddress,"invoiceaddress",0,null),l("emailfrm",t.invoiceemail,"invoiceemail",0,null),$$.dc("sndfrm",n).append($$.dc("content").text(t.sender)),r.tbl.children("tbody").each($inv.bdysort),r.tbl.trigger("fds.inv");let d=r.tbl.data("new");d.amount=t.amount,d.amount_payed=t.amount_payed,$inv.rd.seed({rem:{invid:t.invid,type:t.type,invoiceid:t.invoiceid,invoicedate:t.invoicedate},new:d})},complete:()=>{}})},$inv.rprev=()=>{$inv.rd.preview()},$inv.sis=e=>{confirm($ict.sisc)&&$ocms.postXT({url:$ocms.url("inv/sis"),data:{id:e||""},success:e=>{}})},$inv.srs=e=>{confirm($ict.srsc)&&$ocms.postXT({url:$ocms.url("rem/srs"),data:{id:e||""},success:e=>{}})},$inv.mfrrel=e=>{$("#contentframe").ldng(),$ocms.postXT({url:$ocms.url("inv/mfrrel"),data:{id:e||""},success:e=>{$inv.rerenderinv()},complete:()=>{$("#contentframe").ldng(0)}})},$inv.sets={o:null,c:null,drag:null,isOpen:()=>!!$inv.sets.o,open:function(){let e=$inv.d.tbl();if(e.length<1||$inv.sets.isOpen())return;if(""===$inv.d.token()&&!e.data("dstate"))return;let t=$$.dc("setstruct");$inv.sets.c=t,$inv.sets.o=$ocms.dlg(t,{title:$ict.setst,size:[-1,960],exclusive:!1,close:()=>{$inv.sets.o=null,$inv.sets.c=null,$inv.sets.drag=null}});let n=e.data("dstate");n?$inv.sets.render(n):$inv.d.refresh()},title:e=>{let t=$$.d().html(e.t||"").text().replace(/\s+/g," ").trim();return""!==t?t:$ict.setsNoTitle||""},typLbl:e=>{let t=(e.typ||"").toString().toLowerCase();return($ict.settyp||{})[t]||e.typ||""},isSet:e=>"set"===(e.typ||"").toString().toLowerCase(),parentOf:(e,t)=>{let n=(null==e.SetItmId?"":e.SetItmId).toString(),i=(e.id||"").toString();if(""===n||n===i)return"";let r=t[n];return r&&$inv.sets.isSet(r)?n:""},isDescendant:(e,t,n)=>{let i={},r=n[e];for(;r;){let e=$inv.sets.parentOf(r,n);if(""===e||i[e])return!1;if(e===t)return!0;i[e]=!0,r=n[e]}return!1},canDrop:(e,t,n,i)=>!!e&&e.bid===n&&e.id!==t&&!$inv.sets.isDescendant(t,e.id,i),sync:e=>($inv.sets.c&&$inv.sets.c.aC("busy"),$inv.d.sync(e)),render:function(e){let t=$inv.sets.c;if(!t)return;let n=t.closest(".modal-body"),i=n.length?n.scrollTop():0;t.empty().rC("busy"),$$.dc("shint",t).text($ict.setsHint||""),(e.req||[]).forEach((e=>{if(!e)return;let n=(e.Id||"").toString();if(""===n)return;let i=(e.itm||[]).filter((e=>e&&""!==(e.id||""))),r={};i.forEach((e=>{r[(e.id||"").toString()]=e}));let a=$$.dc("sblock",t).data({bid:n});$inv.sets.rootZone($$.dc("sbhd",a).append($$.sc("nme",e.text||e.nme||n)),n,r);let s=$$.tblset({class:"stbl"},a),l=$$.tr(s.hd);($ict.setsHR||[]).forEach((e=>$$.th(l,e))),i.forEach((e=>$inv.sets.row(s.bdy,e,n,i,r))),$inv.sets.rootZone($$.dc("sroot",a).text($ict.setsRoot||""),n,r),$inv.sets.createBar(a,n,i,r)})),n.length&&n.scrollTop(i)},collapsed:{},hiddenByCollapse:function(e,t){let n={},i=e;for(;i;){let e=$inv.sets.parentOf(i,t);if(""===e||n[e])return!1;if($inv.sets.collapsed[e])return!0;n[e]=!0,i=t[e]}return!1},zone:function(e,t,n){let i=e.originalEvent||e,r=t[0].getBoundingClientRect(),a=(i.clientY||0)-r.top,s=r.height||1;return a<.3*s?"before":a>.7*s||!n?"after":"into"},clearDrop:()=>{$(".setstruct .dropok, .setstruct .dropbefore, .setstruct .dropafter").rC("dropok dropbefore dropafter")},row:function(e,t,n,i,r){let a=(t.id||"").toString(),s=parseInt(t.lvl||0,10)||0,l=$inv.sets.isSet(t),d=$inv.sets.parentOf(t,r),c=l&&!!$inv.sets.collapsed[a],o=$$.tr(e,{draggable:"true"}).aC("srow lvl"+s).tC("isset",l).tC("folded",c).data({id:a,bid:n});$inv.sets.hiddenByCollapse(t,r)&&o.aC("hid"),$$.tdc("grip",o).append(gi("move")).attr("title",$rct.mR),$$.tdc("pos",o).text(null!=t.p?t.p:"");let u=$$.tdc("typ",o);l&&u.append($$.sc("fold").attr("title",c?$ict.setsExpand:$ict.setsCollapse).append(gi(c?"triangle-right":"triangle-bottom")).click((e=>{e.stopPropagation(),c?delete $inv.sets.collapsed[a]:$inv.sets.collapsed[a]=!0;let t=$inv.d.tbl().data("dstate");t&&$inv.sets.render(t)}))),u.append($$.s($inv.sets.typLbl(t))),$$.tdc("qty",o).text(t.q||"");let m=$$.tdc("ttl",o);if(""!==d&&m.append($$.sc("seti",$inv.sets.title(r[d]))),m.append($$.sc("txt",$inv.sets.title(t)).click((function(e){e.stopPropagation(),$(this).tC("exp")}))),l){let e=i.filter((e=>$inv.sets.parentOf(e,r)===a)).length;m.append($$.sc("cnt"," ("+e+")"))}let v=i.filter((e=>$inv.sets.parentOf(e,r)===d)),p=v.findIndex((e=>(e.id||"").toString()===a)),f=v.slice(0,p).some((e=>$inv.sets.isSet(e))),h=$$.tdc("act",o),g=(e,t,n,i,r)=>$$.dc("ibtn "+e,h,{title:n}).append(gi(t)).tC("disabled",!i).click((()=>{i&&$inv.sets.sync(r)}));g("up","arrow-up",$ict.setsUp,p>0,{Target:"set.move",Ref:a,Value:-1}),g("down","arrow-down",$ict.setsDown,p>=0&&p0,{Target:"set.level",Ref:a,Value:-1}),g("in","chevron-right",$ict.setsIn,f,{Target:"set.level",Ref:a,Value:1}),o.on("dragstart",(e=>{$inv.sets.drag={id:a,bid:n},o.aC("dragging");try{e.originalEvent.dataTransfer.setData("text/plain",a),e.originalEvent.dataTransfer.effectAllowed="move"}catch(e){}})).on("dragend",(()=>{o.rC("dragging"),$inv.sets.drag=null,$inv.sets.clearDrop()}));return o.on("dragover",(e=>{if(!$inv.sets.canDrop($inv.sets.drag,a,n,r))return;e.preventDefault();let t=$inv.sets.zone(e,o,l);o.rC("dropok dropbefore dropafter").aC("into"===t?"dropok":"before"===t?"dropbefore":"dropafter")})).on("dragleave",(()=>{o.rC("dropok dropbefore dropafter")})).on("drop",(e=>{e.preventDefault(),$inv.sets.clearDrop();let t=$inv.sets.drag;if($inv.sets.drag=null,!$inv.sets.canDrop(t,a,n,r))return;let i=$inv.sets.zone(e,o,l);"into"===i?$inv.sets.sync({Target:"set.assign",Ref:t.id,Value:{parent:a}}):$inv.sets.sync({Target:"set.move",Ref:t.id,Value:{anchor:a,where:i}})})),o},rootZone:function(e,t,n){return e.on("dragover",(i=>{(()=>{let e=$inv.sets.drag;return!!e&&e.bid===t&&!!n[e.id]&&""!==$inv.sets.parentOf(n[e.id],n)})()&&(i.preventDefault(),e.aC("dropok"))})).on("dragleave",(()=>{e.rC("dropok")})).on("drop",(i=>{i.preventDefault(),e.rC("dropok");let r=$inv.sets.drag;$inv.sets.drag=null,r&&r.bid===t&&n[r.id]&&""!==$inv.sets.parentOf(n[r.id],n)&&$inv.sets.sync({Target:"set.assign",Ref:r.id,Value:{parent:""}})})),e},createBar:function(e,t,n,i){let r=$$.dc("screate",e),a=$("").attr({name:"typ"}).append([$$.opt("set",$ict.settyp.set),$$.opt("text",$ict.settyp.text)]),s=$("").attr({name:"parent"}).append($$.opt("",$ict.setsTop));n.forEach((e=>{if(!$inv.sets.isSet(e))return;let t=parseInt(e.lvl||0,10)||0;s.append($$.opt((e.id||"").toString()," ".repeat(3*t)+$inv.sets.title(e)))}));let l=$('').attr({name:"title",placeholder:$ict.setsTitle,maxlength:250}),d=()=>{let e=(l.val()||"").toString().trim();""!==e?($inv.sets.sync({Target:"set.create",Ref:t,Value:{typ:a.val(),title:e,parent:s.val()||""}}),l.val("")):l.focus()};return l.on("keydown",(e=>{"Enter"===e.key&&(e.preventDefault(),d())})),r.append([$$.sc("lbl",$ict.setsNew),a,$$.sc("lbl",$ict.setsInto),s,l,$$.bbtn($ict.setsAdd,"sadd").click(d)]),r}};
\ No newline at end of file
+let $rct={mdl:"Aufträge",or:"offene Aufträge",orr:"offene Aufträge (4 W)",rn:"Auftragsnummer",iov:{all:"Auftragsübersicht (alle)","":"Auftragsübersicht"},wk:"Woche",nd:"Keine Daten gefunden.",h:"Uhr",rq1:"Auftragsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",rq2:"Auftragsdaten werden geladen",rq1f:"Die Auftragsdaten von MFR konnten nicht oder nicht schnell genug abgerufen werde.\nMöchten Sie mit den bestehenden Daten trotzdem weitermachen?",note1:"Im Bruttobetrag sind {0} Lohnkosten enthalten (netto {1}). Die darin enthaltene Umsatzsteuer beträgt {2}.",note2:"Bitte beachten Sie, nach §14 Abs. 1 Umsatzsteuergesetz ist diese Rechnung ein Zahlungsbeleg oder eine andere beweiskräftige Unterlage für 2 Jahre nach Ablauf des Kalenderjahres der Ausstellung dieser Rechnung aufzubewahren, soweit nicht aufgrund anderer gesetzlicher Regelungen andere ggf.längere Aufbewahrungsfristen gelten.",note3:"Privathaushalten erstattet das Finanzamt bis zu {0} des Arbeitslohns mit der nächsten Steuererklärung.",note4:"Für bereits erbrachte Arbeiten, Dienstleistungen, Materiallieferungen und getätigte Bestellvorgänge zum oben genannten Bauvorhaben, die sich aus dem mit Ihnen geschlossenen Vertrag ergeben, stellen wir Ihnen vertragsgemäß unsere Akontozahlung in Rechnung. Eine Endabrechnung erhalten Sie als Schlussrechnung nach Abschluss des gesamten Bauvorhabens. Das Ausführungsdatum entnehmen Sie bitte dem Schlusstext dieser Rechnung. Wir danken Ihnen herzlich für das entgegengebrachte Vertrauen und bitten Sie um kurzfristigen Ausgleich der Akontorechnung.",note13b:"Gem. §13b Umsatzsteuergesetz unterliegen Sie der Steuerschuldnerschaft des Leistungsempfängers zur Umsatzsteuer aus dieser Rechnung mit einem Steuersatz von 19%.",crI:"Rechnung erstellen",crII:"Abschlagsrechnung erstellen",dII:"Für eine Abschlagsrechnung darf nur ein Auftrag gewählt werden.",dnS:"Für eine Rechnung muss mindestens ein Auftrag gewählt werden.",inv:"Rechnung",invs:"Rechnungen",req:"Auftrag",provP:"Leistungszeitraum",provD:"Leistungsdatum",cP:"Position ändern",iRb:"Zeile darunter einfügen",dR:"Zeile löschen",sV:"USt festlegen",cD:"Löschen?",mR:"Zeile verschieben",ctxM:"Weitere Aktionen",noteToggle:"Notiz ein-/ausblenden",sectionTitleEditTT:"Auftragsbezeichnung ändern",svcPart:"Service-Anteil",vat:"Umsatzsteuer",combP:"Positionen zusammenfassen",toSetP:"Auf Setpreis umstellen (Positionen ohne Preis)",toSetPc:"Der Set-Preis wird auf die Summe seiner Positionen gesetzt und die Positionen selbst verlieren ihren Preis. Das ist nicht rückgängig zu machen (der Betrag kann danach nur noch manuell geändert werden). Fortfahren?",toSetMc:"Jedes Set erhält die Summe seiner Positionen als Set-Preis; die Positionen des Sets werden ohne Preis dargestellt bzw. ausgeblendet. Positionen ausserhalb eines Sets bleiben unverändert einzeln aufgeführt. Das ist nicht rückgängig zu machen (die Set-Preise können danach nur noch manuell geändert werden). Fortfahren?",toSetMn:'Diese Rechnung enthält kein Set. Legen Sie zuerst über "Set-Struktur bearbeiten" ein Set an bzw. ordnen Sie Positionen einem Set zu.',iSum:"Zwischensumme",dtRel:"Freigegeben am: ",dtCr:"Erstellt am: ",rqV:"USt des Auftrags?",cthd:"wirklich aus-/einblenden ?",cst:{style:"currency",currency:"EUR"},sts:{IsWorkDone:"Arbeiten erledigt",Closed:"Auftrag geschlossen",SubcontractorPendingConfirmation:"Warten auf Bestätigung (Unterauftrag)",Scheduled:"Geplant",OfferIsRejected:"Angebot abgelehnt",OfferIsSend:"Offen (Angebot versandt)",CollaborationWaitingConfirmation:"Warten auf Bestätigung (Zusammenarbeit)",Released:"Freigegeben",OfferIsConfirmed:"Bestätigt",InProgress:"In Bearbeitung",ReadyForScheduling:"Zur Planung",Created:"Erstellt",Rejected:"Abgebrochen",Invoiced:"Rechnung gestellt","-":"-"},invHR:["Pos.","Menge","Artikelbezeichnung","VK","Summe"],frm:{invoicetitle:"Titel",invoiceaddress:"Adresse",loc:"Leistungsort / Lieferadresse",invoiceemail:"Email",invoiceemailcc:"Zusatzempfänger (CC)",provisionperiod:"Leistungsdatum / -zeitraum"},frmTT:{invoicetitle:"Rechnungstitel ändern",invoiceaddress:"Rechnungsempfänger-Adresse ändern",loc:"Leistungsort oder Lieferadresse ändern",invoiceemail:"Email-Adresse ändern und zusätzliche Email-Empfänger festlegen",provisionperiod:"Leistungsdatum oder -zeitraum ändern"}},$rcol={req:new fields_definition("Auftrag","Aufträge",[{name:"tags",label:"",type:"string",dfnc:function(e,t){""!==(e||"")&&($(this).aC("tags"),e.split(",").forEach((e=>{""!==e&&$(this).append($$.sc("tag "+e.replace(" ","_").replace("/","_").toLowerCase(),e))})))}},{name:"DateOfCreation",label:"Datum",type:"date",title:function(e){$(this).attr("title",$rct.dtCr+fdt(e.DateOfCreation).ne("-")+" \n"+$rct.dtRel+fdt(e.DateReleased).ne("-"))}},{name:"CustomerName",label:"Kunde (Firma)",type:"string"},{name:"Name",label:"Auftragsname",type:"string"},{name:"ExternalId",label:"Auftragsnummer",type:"string"},{name:"ParentExtenalId",label:"PAuftrag",type:"string"},{name:"InvoiceId",label:"RNummer",type:"string",dfnc:function(e,t){$(this).rwText(e," ").find("span").each((function(){$(this).aC("cla").click({id:$(this).text()},$inv.jdbn)}))}},{name:"State",label:"Status",type:"string"},{name:"WorkDoneAt",label:"Erledigt am",type:"date"},{name:"Description",label:"Beschreibung",type:"html"}]),itm:new fields_definition("Auftragsposition","Auftragspositionen",[{name:"NameOrNumber",label:"Bezeichnung",type:"string"},{name:"Type",label:"Typ",type:"select",required:!0,value:"Text",url:[{value:"Text",label:"Text"},{value:"Equipment",label:"Ausrüstung"},{value:"Material",label:"Material"},{value:"Service",label:"Arbeitsleistung"}],change:function(e){$req.quantChange.call(this,e)}},{name:"quantityhours",label:"Anzahl / Menge",type:"number",precision:"0.01",value:1,change:function(e){$inv.quantChange.call(this,e)}},{name:"UnitString",label:"Einheit",type:"select",url:["LFDM","Stck","Std.","QM","AW","Pauschal"],change:function(e){$inv.quantChange.call(this,e)}},{name:"net",label:"EinzelPreis netto",type:"number",precision:"0.01",value:0,change:function(e){$inv.quantChange.call(this,e)}},{name:"net_val",label:"GesamtPreis netto",type:"number",precision:"0.01",value:0},{name:"vat_val",label:"GesamtPreis USt",type:"number",precision:"0.01",value:0},{name:"svcnet_val",label:"Arbeitslohn netto",type:"number",precision:"0.01",value:0},{name:"svcvat_val",label:"Arbeitslohn USt",type:"number",precision:"0.01",value:0},{name:"net_pos",label:"Netto",type:"string"},{name:"bo_pos",label:"Brutto",type:"string"},{name:"vat",label:"USt",type:"string",value:"19,0%",change:function(e){$inv.quantChange.call(this,e)}},{name:"Note",label:"Details",type:"html",tinymce:!0}])},$ict={mdl:"Rechnungen",iov:{all:"Rechnungen (alle)","":"Rechnungen (nur fertige)","#d":"Rechnungen (nur Entwürfe)","#u":"Rechnungen (nur unbezahlt)","#r":"Rechnungen (nur angemahnt)","#a":"Rechnungen (nur Akonto)","#c":"Rechnungen (nur Storno)","#ru":"Rechnungen (nur angemahnt + unbez.)"},uba:", gesamter Zeitraum)",req:"Auftrag",inv:"Rechnung",rem:"Mahnung",in:"Rechnungsnummer",cc:"Kunde",wk:"Woche",nd:"Keine Daten gefunden.",dl:"Herunterladen",ed:"Bearbeiten",ced:"Bearbeitung fortsetzen",sItm:"Einzelheiten anzeigen",sPay:"Zahlungen anzeigen",cdI:"Entwurf der Rechnung löschen?",rel:"Neu Laden",relm:"Bitte laden Sie Liste manuell neu, um die Änderungen zu sehen.",dsp:"Rechnung anzeigen",storno:"Storno-Rechnung erstellen",credit:"Gutschrift erstellen",remd:"Mahnung erstellen",remdt:"Mahnung erstellen zur Rechnung {0}",remlst:"Mahnungen anzeigen",remdsp:"Mahnung anzeigen",remres:"Mahnung erneut senden",remresc:"Mahnung {0} wirklich erneut senden?",remresr:"Mahnung {0} wurde erfolgreich versandt.",setpyd:"Bezahlt markieren",cpyd:"Rechnung wirklich als bezahlt markieren?",setupd:"Bezahlt-Markierung aufheben",cupd:"Bezahlt-Markierung wirklich aufheben?",ivE:"Die Email-Adresse ist vermutlich nicht gültig.",ivEc:"\nMöchten Sie fortfahren?",pna:"Diese Seite ist in der Vorschau nicht verfügbar",tpe:"Die Anzahl von {0} Seiten wird aktuell nicht unterstützt",eis:"Der Rechnungsentwurf konnte nicht gespeichert werden.",pvw:"Das Dokument wird abgerufen und für die Vorschau aufbereitet.\nDer Vorgang kann bis zu 2 Minuten dauern.",pvf:"Die PDF-Vorschau konnte nicht erstellt werden.",pvto:"Der Server hat nicht rechtzeitig geantwortet (Zeitüberschreitung). Bitte versuchen Sie es erneut.",pvgone:"Der Entwurf ist auf dem Server nicht mehr vorhanden (Sitzung abgelaufen). Bitte öffnen Sie den Entwurf erneut.",iss:"Zwischenstand speichern.",p13b:"USt -> §13b",setm:"Set-Preisanzeige",setmo:{setprice:"Set mit Preis – Positionen ohne Preis",setonly:"Nur Set mit Preis – Positionen ausgeblendet"},setst:"Set-Struktur bearbeiten",setsHint:'Reihenfolge: Zeile per Drag & Drop an den oberen/unteren Rand einer anderen Zeile ziehen (davor/danach) oder ▲▼ nutzen. Zuordnung: Zeile auf die Mitte eines Sets ziehen (hinein) bzw. auf die Auftragszeile oder "oberste Ebene" (aus dem Set lösen); ◀▶ ändert die Ebene. Sets lassen sich über das Dreieck zu-/aufklappen und auch zugeklappt verschieben – ihre Positionen wandern mit. Änderungen werden sofort übernommen.',setsUp:"Nach oben (innerhalb der Ebene)",setsDown:"Nach unten (innerhalb der Ebene)",setsCollapse:"Set zuklappen",setsExpand:"Set aufklappen",setsHR:["","Pos.","Typ","Menge","Bezeichnung","Reihenfolge / Ebene"],setsRoot:"Hierher ziehen = aus dem Set lösen (oberste Ebene)",setsOut:"Eine Ebene höher (aus dem Set lösen)",setsIn:"Eine Ebene tiefer (dem vorangehenden Set zuordnen)",setsNew:"Neu:",setsInto:"in",setsTop:"oberste Ebene",setsTitle:"Bezeichnung",setsAdd:"Hinzufügen",setsNoTitle:"(ohne Bezeichnung)",settyp:{set:"Set",text:"Text",title:"Text",material:"Material",service:"Arbeitsleistung",equipment:"Ausrüstung",other:"Position",osum:"Zusammenfassung",intinvoiceallocation:"Abschlag",intinvoiceallocationdiff:"Abschlag (offen)"},ctp:"Ansprechpartner festlegen",mfr:"Von MFR neu abrufen",rq1:"Auftragsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",rq2:"Auftragsdaten werden geladen",iq1:"Rechnungsdaten werden von MFR abgerufen.\nDer Vorgang kann bis zu 90Sek dauern.",iq2:"Rechnungsdaten werden geladen",sis:"Rechnung als versandt markieren",srs:"Mahnung als versandt markieren",sisc:"Rechnung wirklich als versandt markieren?",srsc:"Mahnung wirklich als versandt markieren?",iSt:{dft:"Entwurf",uns:"nicht versandt",pyd:"bezahlt",cc:"storniert",op:"offen",due:"fällig",ovd:"überfällig",rem:"angemahnt"},rSt:["","Überfällig","2. Mahnung","3. Stufe"],pSt:{a:"Vollst.",p:"Teilz."},ivT:{i:"AbschlagsR.",f:"SchlussR",r:"Rechnung",c:"StornoR."},rovlh:"Übersicht der bisherigen Mahnungen",rovl:["Betreff","Betrag","Betrag gezahlt","fertiggestellt am"],remHR:["Rechnung","vom","Rechnungsbetrag","bereits bezahlt","noch offen"],translatePaymentTerm:e=>(e||"").replace("wd"," Werktagen").replace("d"," Tagen").replace("wk"," Wochen")||"10 Tagen",payi:{account:"Konto",name:"Zahler",text:"Verw.Zweck",InvoiceID:"Rechnung",amount:"Betrag",date:"Datum",manual:"Typ"}},$invcol={datev:new fields_definition("Rechnung","Rechnungen",[{name:"Umsatz (ohne Soll/Haben-Kz)",label:"Umsatz (ohne Soll/Haben-Kz)",type:"string"},{name:"vf",label:"vf",type:"string"},{name:"Soll/Haben-Kennzeichen",label:"Soll/Haben-Kennzeichen",type:"string"},{name:"Konto",label:"Konto",type:"string"},{name:"Gegenkonto",label:"Gegenkonto",type:"string"},{name:"BU-Schlüssel",label:"BU-Schlüssel",type:"string"},{name:"Belegdatum",label:"Belegdatum",type:"string"},{name:"Belegfeld 1",label:"Belegfeld 1",type:"string"},{name:"Belegfeld 2",label:"Belegfeld 2",type:"string"},{name:"Buchungstext",label:"Buchungstext",type:"string"}]),inv:new fields_definition("Rechnung","Rechnungen",[{name:"invstatus",label:"Status",type:"select",url:$ict.iSt},{name:"balance",label:"Umsatz",type:"string",dtype:"currency"},{name:"CustomerName",label:"Kunde",type:"string"},{name:"InvoiceId",label:"RNummer",type:"string"},{name:"InvoiceType",label:"Typ",type:"select",url:$ict.ivT},{name:"request",label:"Auftrag",type:"string",dtype:"num"},{name:"vat",label:"MwSt",type:"string",dtype:"num"},{name:"deb_cred",label:"Soll/Haben",type:"string"},{name:"customer",label:"Konto",type:"string",dtype:"num"},{name:"contra_account",label:"Gegenkonto",type:"string",dtype:"num"},{name:"Belegdatum",label:"Belegdatum",type:"date"},{name:"reminderstatus",label:"MahnStatus",type:"select",url:$ict.rSt},{name:"reminder",label:"# Mahnungen",type:"integer"},{name:"Buchungstext",label:"Buchungstext",type:"string"},{name:"Payment",label:"Zahlung",type:"string"}]),rem:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"amount",label:"Rechnungsbetrag",type:"number",precision:"0.01",value:1},{name:"amount_payed",label:"bereits bezahlt",type:"number",precision:"0.01",value:1}]),rem2:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"DocumentName",label:"Name",type:"string"},{name:"subject",label:"Betreff",type:"string"},{name:"DateSent",label:"Versanddatum",type:"date"},{name:"status",label:"Status",type:"string"},{name:"amount_open",label:"offener Betrag",type:"number",precision:"0.01"},{name:"InvoiceId",label:"RNummer",type:"string"}]),rid:new fields_definition("Zahlungserinnerung","Zahlungserinnerung",[{name:"type",label:"Typ",type:"select",url:[["f","einfache Zahlungserinnerung"],["m","Mahnung"],["l","letzte Mahnung"]],required:!0},{name:"level",label:"Stufe",type:"select",url:[["1","Stufe 1"],["2","Stufe 2"],["3","Stufe 3"],["4","Stufe 4"],["5","Stufe 5"],["6","Stufe 6"]],required:!0}]),ctp:new fields_definition("Ansprechpartner","Ansprechpartner",[{name:"name",label:"Name",type:"string"},{name:"email",label:"Email",type:"string"}])},gi=(e,t)=>$$.sc("glyphicon glyphicon-"+e).aC(t),$inv={},$req={init2:function(e,t){e=e||"inv",t=t||{},$ocms.getScript([],(function(){$req.init3(e,t)}))},init3:async function(e,t){$fis.cf(!0);let n=$fis.lf(!0);$("#topbar").ocmsmenu([]),$("#activemodule").text($rct.mdl),await $fis.prepAuth("fds_req,fds_inv,fds_reminder");let i=[(async()=>{!0===$fis.isAuth("fds_req",1)&&($req.prepLst(""),n.aC("fix"))})(),new Promise(((e,t)=>{n.find("div.oreq2").aC("selected"),$req.renderreq(fdt(new Date,"yy-MM-dd"),"r"),e()}))];await Promise.all(i)},prepLst:function(e){let t=new Date,n=$fis.lf(!0).ldng(1),i=new Date("2021-01-01");$fis.frm_list().IN((function(){}));$$.dc("mth oreq",n).text($rct.or).click((function(e){let t=$(this);e.stopPropagation(),t.siblings().rC("selected"),!0===t.is(".selected")&&(t.tC("selected"),$req.renderreq(fdt(new Date,"yy-MM-dd"),"o")),t.aC("selected")})),$$.dc("mth oreq2",n).text($rct.orr).click((function(e){let t=$(this);e.stopPropagation(),t.siblings().rC("selected"),!0===t.is(".selected")&&(t.tC("selected"),$req.renderreq(fdt(new Date,"yy-MM-dd"),"r")),t.aC("selected")})),$$.i({placeholder:$rct.rn}).appendTo($$.dc("mth oreqn",n)).enterKey((function(e){let t=$(this),n=t.val()||"";e.stopPropagation(),t.parent().siblings().rC("selected"),n.length>3&&(t.parent().aC("selected"),$req.renderreq("n:"+n,"s"),t.val(""))}));n.append("");let r=$$.dc("mthl",n),a=t.getFullYear(),s=t.getMonth()+1;for(let t=i.getFullYear();t<=a;t++){let n=$$.dc("yr").prependTo(r).text($rct.iov[e]+" - "+t.toString()).toggleClass("selected",t===a);n.click({yr:t},(function(e){e.stopPropagation(),n.siblings().rC("selected"),n.aC("selected")}));let l=$$.dc("mfrm",n);for(let n=0;n<(t!==a?12:s);n++){i=new Date(t,n,1);let r=$$.dc("mth").prependTo(l).text($rct.iov[e]+" - "+fdt(i,"MMM yyyy"));r.click({yr:t,mt:n},(function(e){if(e.stopPropagation(),r.siblings().rC("selected"),!0===r.is(".selected")){r.tC("selected");let t=fdt(new Date(e.data.yr,e.data.mt,1),"yy-MM-dd");$req.renderreq(t,"m")}r.aC("selected")}));let a=getMonday(i),s=new Date(i);s.setMonth(s.getMonth()+1),s.setDate(0),s=getMonday(s);let d=$$.dc("wfrm",r);for(;a<=s;){let e=$$.dc("wk",d).text(($rct.wk||"W")+" "+fdt(a,"dd.MM.yy"));e.click({rd:new Date(a)},(function(t){t.stopPropagation();let n=fdt(t.data.rd,"yy-MM-dd");$req.renderreq(n,"w"),r.siblings().rC("selected").find(".wk").rC("selected"),r.aC("selected").find(".wk").rC("selected"),e.aC("selected")}));let t=$$.dc("wkdl",e).append($$.sc("ico glyphicon glyphicon-compressed"));!0===$fis.isAuth("fds_inv",2)&&t.click({rd:new Date(a)},(function(e){e.stopPropagation();let t=fdt(e.data.rd,"yy-MM-dd");$req.downloadzip.call(t,"w")})),a.setDate(a.getDate()+7)}}}n.ldng(0)},renderreq:function(e,t){let n=$fis.frm_list().ldng(1),i=$$.dc("invfrm",n).aC("md"+t),r=$fis.lf();$ocms.postXT({url:$ocms.url("req/reql"),data:{mode:t,tgt:e},success:n=>{r.rC("fix").aC("hd"),$$.dc("ovhd",i).append($$.s(n.admin.title)).appendIf($$.sc("note",n.admin.note),""!==ne(n.admin.note,""));let a=$$.tblset({},i),s=$rcol.req,l=$$.tr(a.hd);$$.th(l);$.each(s.fields||[],((e,t)=>{$$.th(l).text(t.label),"vat"===t.name&&$$.th(l)}));let d=0,c=!1;$.each(n.requests||[],((n,l)=>{d>0&&d!==l.ParentServiceRequestId&&(c=!c);let o=$$.tr(a.bdy).tC("alt",c);d=l.ParentServiceRequestId,o.click((function(){r.rC("fix").aC("hd"),o.tC("selected").siblings().rC("selected").find("td.av").rC("av"),o.find("td.av").rC("av")})),o.tC("child",l.isChild);let u=$$.td(o,{class:"raux"});!0===bool(l.open,!1)&&$$.dc("ihd ilbtn",u).append(gi("eye-close","ico")).click({id:l.Id},$req.tHd),$$.dc("iitm ilbtn",u).append(gi("list","ico")).click({id:l.Id},$req.showitm),!0===$fis.isAuth("fds_inv",2)&&$$.dc("invc ilbtn",u).append(gi("edit","ico")).click({id:l.Id},$inv.cInv),$.each(s.fields||[],((n,r)=>{let a=$$.td(o).aC(r.dtype),s=l[r.name];if("function"==typeof r.dfnc)r.dfnc.call(a,s,l);else switch(r.type||""){case"date":a.text(fdt(l[r.name],"dd.MM.yy"));break;case"datetime":a.text(fdt(l[r.name]));break;case"html":a.append($$.dc("ctw").html(s)),a.append($$.dc("ttip").html(s));break;default:a.text(l[r.name])}switch(r.name||""){case"State":a.text($rct.sts[s||"-"]);break;case"Name":a.aC(r.name.toLowerCase());break;case"vat":$$.sel().appendTo($$.td(o,{class:"vsel"})).click((function(e){e.stopPropagation()})).append([$$.opt("19,0 %","19,0 %"),$$.opt("16,0 %","16,0 %"),$$.opt("0,0 %","0,0 %")]).val(l[r.name]).change().change({frm:i,tgt:e,mode:t,id:l.Id,td:a},$req.setvat),a.tC("hl","19"!==l[r.name].substr(0,2)).click((function(e){e.stopPropagation(),$(this).tC("av")}));break;case"balance":a.aC("sh_"+(l.SollHaben||"").toLowerCase());break;case"InvoiceId":a.aC("keep")}switch(typeof r.title){case"function":r.title.call(a,l);break;case"string":a.attr("title",cs.title)}}))}))},complete:()=>{n.ldng(0)}})},tHd:function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&confirm($rct.cthd)&&$ocms.postXT({url:$ocms.url("req/rthd"),data:{id:e.data.id},success:n=>{n.id===e.data.id&&!1===bool(n.visible,!0)?(!1===t.is(".tbhd")&&setTimeout((()=>{t.filter(".tbhd").remove()}),15e3),t.aC("tbhd")):n.id===e.data.id&&t.rC("tbhd")}})},showitm:function(e){let t=$(this).closest("tr");if(e.stopPropagation(),!1===t.is(".selected"))return;let n=$$.dc("rfrm").ldng(1);$ocms.postXT({url:$ocms.url("req/pget"),data:{id:e.data.id},success:t=>{$ocms.postXT({url:$ocms.url("req/get"),data:{id:e.data.id,mode:"ful"},success:e=>{if((e.requests||[]).length<1)n.text($rct.nd);else{let t=$$.dc("srq",n),i=$$.tblset({class:"if"},t);$.each(e.requests||[],(function(e,t){e>0&&$$.tr(i.bdy).aC("sep").append($$.td({colspan:6}));let n=$$.tr(i.bdy).aC("title"),r=$rcol.itm.lbl(),a=$inv.worknotes(t);$$.td(n,{colspan:6}).append([$$.s($rcol.req.label_sng),$$.sc("eid",t.ExternalId),$$.sc("nme",fdt(t.WorkDoneAt,"dd.MM.yy")+": "+a.ne(t.Name))]);$$.tr(i.bdy).aC("shd").append([$$.td(),$$.td(r.NameOrNumber),$$.td(r.Type),$$.td(r.net_pos),$$.td(r.bo_pos),$$.td(r.vat)]);$.each(t.items||[],((e,t)=>{t.ServiceRequestId;let n=$$.tr(i.bdy,{id:"itm"+t.Id}).aC(t.Type);$$.td(n).aC("ico"),$$.td(n).text(t.NameOrNumber),$$.td(n).text(t.Type),$$.td(n).aC("currency").text(t.net_pos),$$.td(n).aC("currency").text(t.bo_pos),$$.td(n).aC("num").text(t.vat)}))}))}},error:()=>{n.text($t.t12)},complete:()=>{n.ldng(0)}})},error:()=>{n.text($t.t12),n.ldng(0)}}),$ocms.dlg(n,{width:1e3})}},$$req={init2:$req.init2,auth:{}};export default $$req;$inv.cInv=function(e){let t=$(this).closest("tr");e.stopPropagation(),!1!==t.is(".selected")&&!1!==$fis.isAuth("fds_inv",2)&&$inv.cInv2({id:e.data.id})},$inv.rMn=e=>{let t=[{lbl:$ict.req,itm:[]}];return!0===bool(e,!1)&&!0===$fis.isAuth("fds_inv",2)&&Array.prototype.push.apply(t[0].itm,[{lbl:$rct.crI,fnc:$inv.ccInv,data:{typ:"r"}},{lbl:$rct.crII,fnc:$inv.ccInv,data:{typ:"i"}}]),t.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(t)},$inv.iMnr=e=>{let t=booln(e.isFinal,!0),n=e.Id,i=booln(e.fds,!1),r=[{glyph:"glyphicon-menu-left",fnc:()=>{$fis.frm_edit().remove()}},{lbl:$ict.inv,itm:[]},{lbl:$ict.rem,itm:[]}];return!1===t&&!0===$fis.isAuth("fds_inv",2)?r[1].itm.push({lbl:$ict.ced,fnc:$inv.clCntInv}):!0===$fis.isAuth("fds_inv",1)&&r[1].itm.push({lbl:$ict.dsp,fnc:()=>$inv.disp(n,"inv")}),!0===i&&!0===t&&!0===$fis.isAuth("fds_inv",2)&&(r[1].itm.push({lbl:$ict.storno,fnc:()=>$inv.storno(n,i)}),r[1].itm.push({lbl:$ict.credit,fnc:()=>$inv.credit(n,i)})),!0===t&&!0===$fis.isAuth("fds_reminder",2)&&(r[2].itm.push({lbl:$ict.remd,fnc:()=>$inv.ccRem(n,e.InvoiceId)}),r[2].itm.push({lbl:$ict.remlst,fnc:()=>$inv.dspRem(n)})),!0===t&&!0===$fis.isAuth("fds_reminder",2)&&!1===booln(e.IsSent,!1)&&r[2].itm.push({lbl:$ict.srs,fnc:()=>$inv.srs(n)}),r.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(r)},$inv.iMn=e=>{let t=booln(e.isFinal,!0),n=e.Id,i=booln(e.fds,!1),r=[{glyph:"glyphicon-menu-left",fnc:()=>{$fis.frm_edit().remove()}},{lbl:$ict.inv,itm:[]},{lbl:$ict.rem,itm:[]}];return!1===t&&!0===$fis.isAuth("fds_inv",2)?r[1].itm.push({lbl:$ict.ced,fnc:()=>{$inv.cntInv({id:n})}}):!0===$fis.isAuth("fds_inv",1)&&r[1].itm.push({lbl:$ict.dsp,fnc:()=>$inv.disp(n,"inv")}),!0===$fis.isAuth("fds_inv",2)&&(r[1].itm.push({lbl:$ict.storno,fnc:()=>$inv.storno(n,i)}),r[1].itm.push({lbl:$ict.credit,fnc:()=>$inv.credit(n,i)})),!0===t&&!1===booln(e.IsPayed,!1)?(!0===$fis.isAuth("fds_reminder",2)&&r[2].itm.push({lbl:$ict.remd,fnc:()=>$inv.ccRem(n,e.InvoiceId)}),!0===$fis.isAuth("fds_inv",2)&&r[1].itm.push({lbl:$ict.setpyd,fnc:()=>$inv.setPyd(n)})):!0===t&&!0===booln(e.IsPayed,!1)&&"m"===(e.PaymentStatus||"")&&!0===$fis.isAuth("fds_inv",2)&&r[1].itm.push({lbl:$ict.setupd,fnc:()=>$inv.setUpd(n)}),!0===$fis.isAuth("fds_reminder",2)&&r[2].itm.push({lbl:$ict.remlst,fnc:()=>$inv.dspRem(n)}),!0===t&&!0===$fis.isAuth("fds_inv",2)&&!1===booln(e.IsSent,!1)&&r[1].itm.push({lbl:$ict.sis,fnc:()=>$inv.sis(n)}),!1===i&&r[1].itm.push({lbl:$ict.mfr,fnc:()=>$inv.mfrrel(n)}),$("#topbar").ocmsmenu(r)},$inv.emOpt=()=>"iss,p13b,ctp,setst,setm",$inv.eM=(e,t,n)=>{let i=[];return!0!==booln(e,!1)&&!0!==booln(t,!1)||i.push({glyph:"glyphicon-menu-left",fnc:()=>{$fis.lf(!0),$fis.frm_edit().remove()}}),!0===(n||"").split(",").includes("iss")&&i.push({lbl:$ict.iss,fnc:$inv.ssave}),!0===(n||"").split(",").includes("ctp")&&i.push({lbl:$ict.ctp,fnc:$inv.sctp}),!0===(n||"").split(",").includes("p13b")&&i.push({lbl:$ict.p13b,fnc:$inv.sp13b}),!0===(n||"").split(",").includes("setm")&&i.push({lbl:$ict.setm,fnc:$inv.ssetmode}),!0===(n||"").split(",").includes("setst")&&i.push({lbl:$ict.setst,fnc:()=>$inv.sets.open()}),!0===(n||"").split(",").includes("iss")&&(i.push({lbl:"Änderungshistorie",fnc:()=>$inv.d.history()}),i.push({lbl:"Änderungen verwerfen",fnc:()=>$inv.d.discard()})),!0===booln(e,!1)&&i.push({lbl:$ict.rel,fnc:$inv.rReload}),$("#topbar").ocmsmenu(i)},$inv.pdfPreviewTimeout=12e4,$inv.pdfPreviewFailed=function(e,t){if(11110===(e||{}).internalCode)return void $ocms.login.dlg();let n=((e||{}).internalText||"").trim();""===n&&"timeout"===t&&(n=$ict.pvto),""===n&&410===(e||{}).status&&(n=$ict.pvgone),alert(($ict.pvf||$t.f1)+(""!==n?"\n"+n:""))},$inv.pdfPreviewComplete=function(e,t){return(n,i)=>{t&&t.c.trigger("modal_close"),e&&e.rC("freeze"),"timeout"===i&&$inv.pdfPreviewFailed(n,i)}},$inv.pdfWaitDlg=function(){let e=$ocms.dlg($$.dc("rfrm").ldng(1),{exclusive:!1,zindex_min:50});return e&&e.ft.rwText($ict.pvw),e},$inv.d={tbl:()=>$("div.invoice_layout table.invi"),layout:()=>$("div.invoice_layout"),token:function(){return $inv.d.tbl().data("dtoken")||""},hashes:function(){let e=$inv.d.tbl().data("bai")||[],t={};return $.each(e,((e,n)=>{t[(n.Id||"").toString()]=JSON.stringify(n)})),t},seed:function(e){let t=$inv.d.layout();t.aC("freeze");let n=$ocms.postXT({url:$ocms.url("inv/dopen"),data:{payload:JSON.stringify(e)},success:e=>{$inv.d.tbl().data("dtoken",e.token).data("dver",e.version).data("dhashes",$inv.d.hashes()).data("dorder",$inv.d.order()),$fis.draft.bind(e.token,{onReady:()=>$inv.d.refresh(),onExpiring:e=>$inv.d.warnExpiry(e),onClosed:e=>$inv.d.closed(e)}),$inv.d.refresh()},error:()=>{t.rC("freeze")},complete:()=>{$inv.d.tbl().removeData("dseeding").removeData("dseedpromise")}});return $inv.d.tbl().data("dseedpromise",n),n},refresh:function(e){let t=$inv.d.token();""!==t&&$ocms.postXT({url:$ocms.url("inv/dstate"),data:{token:t},success:t=>{$inv.d.applyState(t),"function"==typeof e&&e(t)},error:e=>{e&&410===e.status&&$inv.d.closed("expired")},complete:()=>{$inv.d.layout().rC("freeze")}})},applyState:function(e){let t=$inv.d.tbl();if(t.length<1)return;let n=t.data("dver");"number"==typeof n&&"number"==typeof e.version&&e.version$$.dc("dnote").aC(e.style||"InvoiceNotes").text(e.text)))},applyItems:function(e,t){let n=e=>void 0===e?null:e;(t||[]).forEach((t=>{if(!t)return;let i=(t.Id||"").toString();if(""===i)return;let r=e.children("tbody").filter(((e,t)=>(($(t).data()||{}).Id||"").toString()===i)).first();if(r.length<1)return;let a=t.itm||[],s={},l=r.find("tr.title").first(),d=l.length?l:null;a.forEach((e=>{let t=(e.id||"").toString();if(""===t)return;s[t]=!0;let i=r.find("#itm"+t).first(),a=i.length<1;a&&(i=$$.tr(r,{id:"itm"+t,class:"itm"}));let l=i.data()||{},c=a||(l.Type||"")!==(e.typ||"")||l.net!==n(e.v)||l.net_val!==n(e.vt)||l.vat_val!==n(e.vv)||l.svcnet_val!==n(e.vs)||l.svcvat_val!==n(e.vsv)||(l.position||"")!==(null!=e.p?e.p:"")||(l.lvl||0)!==(e.lvl||0)||(l.SetItmId||null)!==(null!=e.SetItmId?e.SetItmId:null);$.extend(l,{Id:t,Type:e.typ,net:n(e.v),net_val:n(e.vt),vat_val:n(e.vv),svcnet_val:n(e.vs),svcvat_val:n(e.vsv),vat:e.vat,position:null!=e.p?e.p:"",SetItmId:null!=e.SetItmId?e.SetItmId:null,lvl:e.lvl||0}),a&&$.extend(l,{htmltext:e.t,quantity:e.q}),i.data(l),d?i.prev()[0]!==d[0]&&i.insertAfter(d):r.children().first()[0]!==i[0]&&r.prepend(i),d=i,c&&$inv.rrw.call(i)})),r.find("tr.itm").each(((e,t)=>{let n=(($(t).data()||{}).Id||"").toString();""===n||s[n]||$(t).remove()}))}))},applySetDisplay:function(e,t){e.find("tr.itm").each(((e,n)=>{let i=$(n),r=((i.data()||{}).Id||"").toString();if(""===r||!Object.prototype.hasOwnProperty.call(t,r))return;let a=t[r]||{};i.tC("sethdr",bool(a.h,!1)),!1===bool(a.p,!0)&&i.find("td.currency").text("")}))},sync:function(e){let t=$inv.d.token();if(""===t){let t=$inv.d.tbl().data("dseedpromise");return t?$.when(t).then((()=>$inv.d.sync(e))):$.when()}return $inv.d.layout().aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dpatch"),data:{token:t,delta:JSON.stringify(e)},success:()=>{$inv.d.refresh()},error:e=>{$inv.d.layout().rC("freeze"),e&&410===e.status&&$inv.d.closed("expired")}})},order:function(){return($inv.d.tbl().data("bai")||[]).map((e=>(e.Id||"").toString()))},syncChanged:function(e){let t=e.data("bai")||[],n=e.data("dhashes")||{},i={},r=[],a=[],s=[];$.each(t,((e,t)=>{let a=(t.Id||"").toString(),s=JSON.stringify(t);i[a]=s,n[a]!==s&&r.push(t)})),$.each(n,(e=>{void 0===i[e]&&a.push(e)}));let l=$inv.d.order(),d=e.data("dorder")||[];return e.data("dhashes",i).data("dorder",l),r.forEach((e=>s.push($inv.d.sync({Target:"block.replace",Ref:(e.Id||"").toString(),Value:e})))),a.forEach((e=>s.push($inv.d.sync({Target:"block.remove",Ref:e})))),d.length===l.length&&d.slice().sort().join(",")===l.slice().sort().join(",")&&d.join(",")!==l.join(",")&&s.push($inv.d.sync({Target:"block.order",Value:l})),$.when.apply($,s).promise()},syncField:function(e,t){let n={invoicetitle:"title",invoiceaddress:"address",invoiceemail:"email",invoiceemailcc:"emailcc",loc:"provisionlocation",provisionlocation:"provisionlocation",provisionperiod:"provisionperiod"}[e];n&&$inv.d.sync({Target:n,Value:t})},footer:function(e,t,n){let i=e.children("tfoot").empty();e.nextAll(".fnote").remove();let r=bool(n.p13b,!1),a=(e,t,n)=>$$.tdc("currency",$$.tr(i,{class:n||"tsum"}).append([$$.tdc("aux"),$$.td({colspan:4}).text(e)]),fnum(t,$rct.cst)),s=t=>$$.dc("fnote").insertAfter(e).rwText(t);a("Netto",t.total_net||0),!1===r&&$.each(t.vat||{},((e,t)=>a($rct.vat+" "+e+"%",t,"tvat"))),a("Summe",t.total_gross||0);let l=n.type||"";"i"===l?(s($rct.note2),s($rct.note4)):"c"===l?s($rct.note2):(s(string($rct.note3,[fnum(((t.service_net||0)+(t.service_vat||0))*(n.tax_servicerefund||0),$rct.cst)])).aC("ntax"),s($rct.note2),s(string($rct.note1,[fnum((t.service_net||0)+(t.service_vat||0),$rct.cst),fnum(t.service_net||0,$rct.cst),fnum(t.service_vat||0,$rct.cst)]))),!0===r&&s($rct.note13b)},validation:function(e){let t=$("div.invoice_layout");if(t.length<1)return;let n=t.children(".dvalidation");n.length<1&&(n=$$.dc("dvalidation"),t.prepend(n)),n.empty().tC("hidden",(e||[]).length<1),$.each(e||[],((e,t)=>$$.dc("dvmsg",n).aC(t.severity).text(t.message)))},preview:function(){let e=$inv.d.token();if(""===e)return;let t=$inv.d.layout(),n=($inv.d.tbl().data("new")||{}).invoiceemail||"";!1===$fis.ValidateEmail(n)&&!1===bool(confirm($ict.ivE+$ict.ivEc),!1)||(t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dpreview"),data:{token:e},timeout:$inv.pdfPreviewTimeout,success:n=>{t.rC("freeze");let i=$$.dc("imagecollection pdfpreview"),r=Math.round(.88*vh()),a=n.total;a>10&&$$.dc("note warn",i).text($ict.tpe),$.each(n.img||[],((e,t)=>{$$.dc("pdfp",i).append($$.img(t).css("max-height",(r-rpx(6)).toString()+"px"))}));for(let e=(n.img||[]).length+1;e<=a;e++)$$.dc("pdfp ph",i).append($$.dc("note",$ict.pna));$ocms.dlg(i,{size:[r,Math.round(.88*vw())],zindex:50,form:!1,button:$rct.crI,confirm:function(n){let i=$(this);t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dsave"),data:{token:e},success:e=>{$ocms.postXT({url:$ocms.url("req/sconf"),data:{id:e.invid},success:t=>{i.trigger("modal_close"),!0===t.hasFile&&window.open($ocms.url("req/idoc")+"?id="+e.invid,"_blank"),$inv.d.close(),$ocms.init("req"),$inv.rReload()},error:()=>{alert($t.f1),i.trigger("modal_close")},complete:()=>{t.rC("freeze")}})},error:()=>{t.rC("freeze"),alert($ict.eis)}})},cancel:function(e){confirm($ict.cdI)&&($inv.d.close(),$inv.rReload())}})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(t)}))},save:function(){let e=$inv.d.token();if(""===e)return;let t=$inv.d.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("inv/dsave"),data:{token:e},success:e=>{$inv.d.tbl().data("invid",e.invid)},error:()=>{alert($ict.eis)},complete:()=>{t.rC("freeze")}})},history:function(){let e=$inv.d.token();""!==e&&$ocms.postXT({url:$ocms.url("inv/dhistory"),data:{token:e},success:e=>{let t=$$.dc("dhist");if((e.history||[]).length<1)$$.dc("note",t).text("Noch keine Änderungen erfasst.");else{let n=$$.tblset({class:"invtbl fullwidth"},t);$$.tr(n.hd).append([$$.th().text("Zeit"),$$.th().text("Feld"),$$.th().text("Alt"),$$.th().text("Neu")]),$.each(e.history,((e,t)=>$$.tr(n.bdy).append([$$.tdc("keep",fdt(t.timestamp)),$$.td().text(t.target),$$.td().text(t.oldValue),$$.td().text(t.newValue)])))}$ocms.dlg(t,{width:800,form:!1})}})},discard:function(){let e=$inv.d.tbl().data("invid")||"";""!==e?!1!==confirm("Alle Änderungen verwerfen und den zuletzt gespeicherten Stand neu laden?")&&($inv.d.close(),$inv.cntInv({id:e})):alert("Es wurde noch kein Zwischenstand gespeichert, der wiederhergestellt werden könnte.")},warnExpiry:function(e){let t=Math.max(1,Math.round((e||0)/60));$fis.notifications.push({severity:"info",title:"Entwurf läuft ab",message:"Der Rechnungsentwurf läuft in etwa "+t+" Minute(n) ab. Bitte zwischenspeichern, sonst gehen die Änderungen verloren."})},closed:function(e){let t=$inv.d.token();$inv.d.tbl().removeData("dtoken"),""!==t&&$fis.draft.release(t),$fis.frm_edit().remove(),$fis.lf(!0),$fis.notifications.push({severity:"error",title:"Entwurf geschlossen",message:"expired"===e?"Der Rechnungsentwurf ist wegen Inaktivität abgelaufen. Nicht gespeicherte Änderungen sind verloren.":"Der Rechnungsentwurf wurde geschlossen."});try{$inv.rReload()}catch(e){}},close:function(){let e=$inv.d.token();""!==e&&($ocms.postXT({url:$ocms.url("inv/dclose"),data:{token:e}}),$fis.draft.release(e)),$inv.d.tbl().removeData("dtoken")}},$inv.rd={tbl:()=>$("div.invoice_layout table.invi"),layout:()=>$("div.invoice_layout"),token:function(){return $inv.rd.tbl().data("rdtoken")||""},seed:function(e){let t=$inv.rd.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dopen"),data:{payload:JSON.stringify(e)},success:e=>{$inv.rd.tbl().data("rdtoken",e.token).data("rdver",e.version),$fis.draft.bind(e.token,{onReady:()=>$inv.rd.refresh(),onExpiring:e=>$inv.rd.warnExpiry(e),onClosed:e=>$inv.rd.closed(e)}),$inv.rd.refresh()},error:()=>{t.rC("freeze")}})},refresh:function(e){let t=$inv.rd.token();""!==t&&$ocms.postXT({url:$ocms.url("rem/dstate"),data:{token:t},success:t=>{$inv.rd.applyState(t),"function"==typeof e&&e(t)},error:e=>{e&&410===e.status&&$inv.rd.closed("expired")},complete:()=>{$inv.rd.layout().rC("freeze")}})},applyState:function(e){let t=$inv.rd.tbl();if(t.length<1)return;let n=t.data("rdver");"number"==typeof n&&"number"==typeof e.version&&e.version{let t=$$[0]("p").aC("dnote intro").rwText(e);r.length?t.insertBefore(r):t.appendTo(n)})),((e||{}).closing||[]).forEach((e=>$$[0]("p").aC("dnote closing").rwText(e).appendTo(n)))},sync:function(e){let t=$inv.rd.token();""!==t&&($inv.rd.layout().aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dpatch"),data:{token:t,delta:JSON.stringify(e)},success:()=>{$inv.rd.refresh()},error:e=>{$inv.rd.layout().rC("freeze"),e&&410===e.status&&$inv.rd.closed("expired")}}))},syncField:function(e,t){if(""===$inv.rd.token())return;let n={subject:"subject",invoiceaddress:"address",invoiceemail:"email",text:"text"}[e];n&&$inv.rd.sync({Target:n,Value:t})},syncAmount:function(e,t){""!==$inv.rd.token()&&($inv.rd.sync({Target:"amount",Value:(null!=e?e:0).toString()}),$inv.rd.sync({Target:"amount_payed",Value:(null!=t?t:0).toString()}))},footer:function(e,t){let n=e.children("tfoot").empty(),i=$$.tr(n,{class:"tsum"}).append([$$.tdc("aux"),$$.td({colspan:4}).text("Offener Betrag")]);$$.tdc("currency",i,fnum(t.amount_open||0,$rct.cst))},validation:function(e){let t=$inv.rd.layout();if(t.length<1)return;let n=t.children(".dvalidation");n.length<1&&(n=$$.dc("dvalidation"),t.prepend(n)),n.empty().tC("hidden",(e||[]).length<1),$.each(e||[],((e,t)=>$$.dc("dvmsg",n).aC(t.severity).text(t.message)))},preview:function(){let e=$inv.rd.token();if(""===e)return;let t=$inv.rd.layout(),n=($inv.rd.tbl().data("new")||{}).invoiceemail||"";!1===$fis.ValidateEmail(n)&&!1===bool(confirm($ict.ivE+$ict.ivEc),!1)||(t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dpreview"),data:{token:e},timeout:$inv.pdfPreviewTimeout,success:n=>{t.rC("freeze");let i=$$.dc("imagecollection pdfpreview"),r=Math.round(.88*vh());$.each(n.img||[],((e,t)=>{$$.dc("pdfp",i).append($$.img(t).css("max-height",(r-rpx(6)).toString()+"px"))})),$ocms.dlg(i,{size:[r,Math.round(.88*vw())],zindex:50,form:!1,button:$ict.remd,confirm:function(n){let i=$(this);t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dsave"),data:{token:e},success:e=>{$ocms.postXT({url:$ocms.url("rem/conf"),data:{id:e.remid},success:()=>{i.trigger("modal_close"),window.open($ocms.url("rem/idoc")+"?id="+e.remid,"_blank"),$inv.rd.close(),$ocms.init("req"),$inv.rReload()},error:()=>{alert($t.f1),i.trigger("modal_close")},complete:()=>{t.rC("freeze")}})},error:()=>{t.rC("freeze"),alert($t.f1)}})},cancel:function(e){confirm($ict.cdI)&&($inv.rd.close(),$inv.rReload())}})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(t)}))},save:function(){let e=$inv.rd.token();if(""===e)return;let t=$inv.rd.layout();t.aC("freeze"),$ocms.postXT({url:$ocms.url("rem/dsave"),data:{token:e},success:e=>{$inv.rd.tbl().data("remid",e.remid)},error:()=>{alert($t.f1)},complete:()=>{t.rC("freeze")}})},history:function(){let e=$inv.rd.token();""!==e&&$ocms.postXT({url:$ocms.url("rem/dhistory"),data:{token:e},success:e=>{let t=$$.dc("dhist");if((e.history||[]).length<1)$$.dc("note",t).text("Noch keine Änderungen erfasst.");else{let n=$$.tblset({class:"invtbl fullwidth"},t);$$.tr(n.hd).append([$$.th().text("Zeit"),$$.th().text("Feld"),$$.th().text("Alt"),$$.th().text("Neu")]),$.each(e.history,((e,t)=>$$.tr(n.bdy).append([$$.tdc("keep",fdt(t.timestamp)),$$.td().text(t.target),$$.td().text(t.oldValue),$$.td().text(t.newValue)])))}$ocms.dlg(t,{width:800,form:!1})}})},warnExpiry:function(e){let t=Math.max(1,Math.round((e||0)/60));$fis.notifications.push({severity:"info",title:"Entwurf läuft ab",message:"Der Mahnentwurf läuft in etwa "+t+" Minute(n) ab. Bitte zwischenspeichern, sonst gehen die Änderungen verloren."})},closed:function(e){let t=$inv.rd.token();$inv.rd.tbl().removeData("rdtoken"),""!==t&&$fis.draft.release(t),$fis.frm_edit().remove(),$fis.lf(!0),$fis.notifications.push({severity:"error",title:"Entwurf geschlossen",message:"expired"===e?"Der Mahnentwurf ist wegen Inaktivität abgelaufen. Nicht gespeicherte Änderungen sind verloren.":"Der Mahnentwurf wurde geschlossen."});try{$inv.rReload()}catch(e){}},close:function(){let e=$inv.rd.token();""!==e&&($ocms.postXT({url:$ocms.url("rem/dclose"),data:{token:e}}),$fis.draft.release(e)),$inv.rd.tbl().removeData("rdtoken")}},$inv.cInv2=function(e){let t=$$.dc("rfrm").ldng(1),n=$ocms.dlg(t,{width:1e3});n&&n.ft.rwText($rct.rq1);let i=()=>{$ocms.postXT({url:$ocms.url("req/get"),timeout:60,data:{id:e.id,mode:"r"},success:t=>{t.admin=t.admin||{};let n=$fis.lf(!0).aC("fix").rC("hd");if($fis.frm_edit().IN(),$inv.eM(!0,!0),(t.requests||[]).length<1)n.aC("fix").text($rct.nd);else{$$.dc("lh",n,$rct.mdl);let i=$$.d(),r=$$.ul({class:"rql"}).data({search:e.id,parent:t.admin.parent}).appendTo(n),a={},s=$rcol.req.lbl();$.each(t.requests||[],(function(e,t){let n=$$.li({class:"cli rli"}).data($.extend({},t)).appendTo(r),l=$$.dc("lihd",n).addClass(t.state);!0===booln(t.open,!1)&&l.append($$.sc("cbox").click((()=>{n.tC("checked"),i.find("li").rC("checked"),!0===n.is(".checked")?$inv.rMn(t.open):$inv.eM(!0)}))),l.append([$$.sc("eid",t.ExternalId),$$.sc("nme",t.Name)]),$$.dc("lidt",n).append([$$.dc("rqs").append([$$.s(s.State+": "),$$.s($rct.sts[t.State||"-"])]),$$.dc("ivn").append([$$.s(s.InvoiceId+": "),$$.s(t.InvoiceId||"- -")]),$$.dc("wda").append([$$.s(s.WorkDoneAt+": "),$$.s(fdt(t.WorkDoneAt,"dd.MM.yyyy"))])]),a[t.Id]=n})),(t.inv||[]).length>0&&($$.dc("lh",n,$rct.invs),i=$$.ul({class:"ivl"}).appendTo(n),$.each(t.inv||[],((e,t)=>{let n=$$.li({class:"cli ili"}).data($.extend({},t)).appendTo(i),a=$$.dc("lihd",n).addClass(t.invstatus);!1===booln(t.isFinal,!0)?a.append($$.sc("cbox").click((()=>{""!==(t.Id||"")&&(n.tC("checked").siblings().rC("checked"),r.find("li").rC("checked"),!0===n.is(".checked")?$inv.iMnr(t):$inv.eM(!0))}))):["","dft"].indexOf(t.invstatus)<0&&a.append($$.sc("dli").click((function(){$inv.disp(t.Id,"inv")}))),a.append($$.sc("nme",t.DocumentName||t.Id)),$$.dc("lidt",n).append([$$.dc("wda").append([$$.s(fdt(t.DateCreated,"dd.MM.yyyy"))]),$$.d().text($ict.iSt[t.invstatus]||t.invstatus)])})))}},complete:()=>{n&&n.c.trigger("modal_close")}})};$ocms.postXT({url:$ocms.url("req/pget"),timeout:90,data:{id:e.id},success:e=>{n&&n.ft.rwText($rct.rq2),i()},error:()=>{confirm($rct.rq1f)?(n&&n.ft.rwText($rct.rq2),i()):n&&n.c.trigger("modal_close")}})},$inv.ccInv=function(e){let t=(e.data||{}).typ||"r",n=$fis.lf(),i=n.children("ul.rql"),r=i.data("parent"),a=[];if(i.find("li.rli.checked").each((function(){a.push($(this).data("Id"))})),a.length<1)return void alert($rct.dnS);if("i"===t&&a.length>1)return void alert($rct.dII);let s=$fis.frm_edit(),l=$$.dc("invoice_layout",s).append($$.dc("btn sprev").click($inv.sprev)),d=$fis.cf().width()>l.width()+n.width()+20;n.tC("fix",d).tC("hd",!d),$inv.eM(!1,!0);let c=$$.dc("rfrm").ldng(1),o=$ocms.dlg(c,{width:1e3});o.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("req/iget"),timeout:60,data:{id:r,mode:"ful",typ:t,sel:a.join(",")},success:e=>{let t=$$.dc("srq",l),n=$$.tblset({class:"invi"},t);n.bdy.remove(),n.ft=$$[0]("tfoot"),e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b")),n.tbl.data($.extend({new:{},sms:{},itm:{}},{admin:e.admin,companies:e.companies,locations:e.locations}));let i=$$.tr(n.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(i,e))),n.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.requests||[],(function(t,i){if(0!==(i.Id||0)){let t=$inv.worknotes(i);i.text="i"===e.admin.type?$rct.req+jine([i.ExternalId,i.Name],": ").eine(" ",""):jine([jine([fdt(i.WorkDoneAt,"dd.MM.yy"),i.ExternalId]," - "+$rct.req+" "),t.ne(i.Name)],": \n");let r=$$.tbody(n.tbl).data($.extend({},i));$inv.rendersrq.call(r)}}));let r=$$.tr($$.tbody(n.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(r),n.ft.appendTo(n.tbl);let a,s,d=e.admin||{},c=(e,t,i,r,a)=>{let s=$$.dc("inpfrm",l).aC(e).append("string"==typeof r?$$.dc("ahd",r):r>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",s).rwText(t);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{n.tbl.data("new")[i]=e}},a),$inv.eHtml)),n.tbl.data("new")[i]=t};c("tfrm",d.invoicetitle,"invoicetitle",0,null),c("adrfrm",d.invoiceaddress,"invoiceaddress",0,null),c("locfrm","","loc",1,{list:deepCopy(e.locations),lbl:"ref",property:"address"}),$inv.emailFrm(l,n,d.invoiceemail,d.invoiceemailcc),$$.dc("sndfrm",l).append($$.dc("content").text(d.sender)),d.provisionend&&(s=d.provisionstart?$rct.provP:$rct.provD,a=d.provisionstart?fdt(d.provisionstart,"dd.MM.yyyy")+" - "+fdt(d.provisionend,"dd.MM.yyyy"):fdt(d.provisionend,"dd.MM.yyyy")),c("admfrm",a,"provisionperiod",s,1),n.tbl.data("new").CustomValues=d.CustomValues||"",$$.dc("inpfrm ctpfrm",l).text(jObj(d.CustomValues,"contactName")),n.tbl.children("tbody").each($inv.bdysort),n.tbl.trigger("fds.inv"),$inv.eM(!1,!0,$inv.emOpt())},complete:()=>{o.c.trigger("modal_close")}})},$inv.ccStInv=function(e){let t=e.data||{},n=$fis.lf(),i=t.id,r=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sprev)),a=$fis.cf().width()>r.width()+n.width()+20;n.tC("fix",a).tC("hd",!a),$inv.eM(!1,!0);let s=$$.dc("rfrm").ldng(1),l=$ocms.dlg(s,{width:1e3});l.ft.rwText($ict.iq1),$ocms.postXT({url:$ocms.url("inv/pget"),timeout:90,data:{id:t.id},success:e=>{l&&l.ft.rwText($ict.iq2),$ocms.postXT({url:$ocms.url("inv/icget"),timeout:60,data:{id:i},success:e=>{let t=$$.dc("srq",r),n=$$.tblset({class:"invi"},t);n.bdy.remove(),n.ft=$$[0]("tfoot"),e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b")),n.tbl.data($.extend({new:{},sms:{},itm:{}},{admin:e.admin,companies:e.companies,locations:e.locations}));let i=$$.tr(n.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(i,e))),n.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.requests||[],(function(t,i){if(0!==(i.Id||0)){let t=$inv.worknotes(i);i.text="i"===e.admin.type?$rct.req+jine([i.ExternalId,i.Name],": ").eine(" ",""):jine([fdt(i.WorkDoneAt,"dd.MM.yy")+t.ne(i.Name)],": ");let r=$$.tbody(n.tbl).data($.extend({},i));$inv.rendersrq.call(r)}}));let a=$$.tr($$.tbody(n.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(a),n.ft.appendTo(n.tbl);let s,l,d=e.admin||{},c=(e,t,i,a,s)=>{let l=$$.dc("inpfrm",r).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(t);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{n.tbl.data("new")[i]=e}},s),$inv.eHtml)),n.tbl.data("new")[i]=t};c("tfrm",d.invoicetitle,"invoicetitle",0,null),c("adrfrm",d.invoiceaddress,"invoiceaddress",0,null),c("locfrm",d.provisionlocation,"loc",1,{list:deepCopy(e.locations),lbl:"ref",property:"address"}),$inv.emailFrm(r,n,d.invoiceemail,d.invoiceemailcc),$$.dc("sndfrm",r).append($$.dc("content").text(d.sender)),d.provisionend&&(l=d.provisionstart?$rct.provP:$rct.provD,s=d.provisionstart?fdt(d.provisionstart,"dd.MM.yyyy")+" - "+fdt(d.provisionend,"dd.MM.yyyy"):fdt(d.provisionend,"dd.MM.yyyy")),c("admfrm",s,"provisionperiod",l,1),n.tbl.data("new").CustomValues=d.CustomValues||"",$$.dc("inpfrm ctpfrm",r).text(jObj(d.CustomValues,"contactName")),n.tbl.children("tbody").each($inv.bdysort),n.tbl.trigger("fds.inv")},complete:()=>{l.c.trigger("modal_close")}})},error:()=>{l&&l.c.trigger("modal_close")}})},$inv.clCntInv=function(e){let t=$fis.lf(!1),n=[];t.find("li.ili.checked").each((function(){n.push($(this).data("Id"))})),1===n.length&&$inv.cntInv({id:n[0]})},$inv.cntInv=function(e){e=e||{};$fis.lf(!1).rC("fix").aC("hd");let t=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sedit));$inv.eM(!1,!0);let n=$$.dc("rfrm").ldng(1),i=$ocms.dlg(n,{width:1e3});i.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("inv/get"),timeout:60,data:{id:e.id},success:e=>{e.admin=e.admin||{};let n=e.inv||{},i=$$.dc("srq",t),r=$$.tblset({class:"invi"},i);r.bdy.remove(),r.ft=$$[0]("tfoot"),r.tbl.data($.extend({invid:n.Id,new:{},sms:{},itm:{},bai:[]},e));let a=$$.tr(r.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(a,e))),r.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.req||[],(function(e,t){let n=$$.tbody(r.tbl).data($.extend({},t));$inv.rendersrq.call(n)}));let s=$$.tr($$.tbody(r.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(s),r.ft.appendTo(r.tbl);let l=(e,n,i,a,s)=>{let l=$$.dc("inpfrm",t).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(n);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{r.tbl.data("new")[i]=e}},s),$inv.eHtml)),r.tbl.data("new")[i]=n};l("tfrm",n.InvoiceTitle,"invoicetitle",0,null),l("adrfrm",n.SendToAddress,"invoiceaddress",0,null),l("locfrm",n.ProvisionLocation,"loc",1,null),$inv.emailFrm(t,r,n.SendToEmail,n.SendToEmailCc),$$.dc("sndfrm",t).append($$.dc("content").text(e.admin.sender)),l("admfrm",n.ProvisionPeriod,"provisionperiod",!0===(n.ProvisionPeriod||"").includes("-")?$rct.provP:$rct.provD,1),r.tbl.data("new").CustomValues=n.CustomValues||"",$$.dc("inpfrm ctpfrm",t).text(jObj(n.CustomValues,"contactName")),r.tbl.children("tbody").each($inv.bdysort),r.tbl.trigger("fds.inv"),$inv.eM(!1,!0,$inv.emOpt())},complete:()=>{i.c.trigger("modal_close")}})},$inv.cSt=function(e){e=e||{};let t=$fis.lf(),n=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.sedit)),i=$fis.cf().width()>n.width()+t.width()+20;t.tC("fix",i).tC("hd",!i),$inv.eM(!1,!0);let r=$$.dc("rfrm").ldng(1),a=$ocms.dlg(r,{width:1e3});a.ft.rwText($ict.iq1),$ocms.postXT({url:$ocms.url("inv/pget"),data:{id:e.id},success:t=>{a&&a.ft.rwText($ict.iq2),$ocms.postXT({url:$ocms.url("inv/storno"),data:{id:e.id,mode:e.mode},success:e=>{e.admin=e.admin||{},e.admin.p13b=bool(e.admin.p13b||"",!0===((e.inv||{}).InvoiceOptions||"").split(",").includes("§13b"));let t=e.inv||{},i=$$.dc("srq",n),r=$$.tblset({class:"invi"},i);r.bdy.remove(),r.ft=$$[0]("tfoot"),r.tbl.data($.extend({invid:t.Id,new:{},sms:{},itm:{},bai:[]},e));let a=$$.tr(r.hd).aC("shd").append([$$.th().aC("aux")]);$rct.invHR.forEach((e=>$$.th(a,e))),r.tbl.on("fds.inv",$inv.invSumUpdate),$.each(e.req||[],(function(e,t){let n=$$.tbody(r.tbl).data($.extend({},t));$inv.rendersrq.call(n)}));let s=$$.tr($$.tbody(r.tbl),{class:"placeholder"}).data({net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0});$inv.rrw.call(s),r.ft.appendTo(r.tbl);let l=(e,t,i,a,s)=>{let l=$$.dc("inpfrm",n).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),d=$$.dc("content",l).rwText(t);$$.dc("axf",l).append($$.dc("ibtn edit",{title:$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:d,nme:i,change:e=>{r.tbl.data("new")[i]=e}},s),$inv.eHtml)),r.tbl.data("new")[i]=t};l("tfrm",t.InvoiceTitle,"invoicetitle",0,null),l("adrfrm",t.SendToAddress,"invoiceaddress",0,null),l("locfrm",t.ProvisionLocation,"loc",1,null),$inv.emailFrm(n,r,t.SendToEmail,t.SendToEmailCc),$$.dc("sndfrm",n).append($$.dc("content").text(e.admin.sender)),l("admfrm",t.ProvisionPeriod,"provisionperiod",!0===(t.ProvisionPeriod||"").includes("-")?$rct.provP:$rct.provD,1),r.tbl.data("new").CustomValues=t.CustomValues||"",$$.dc("inpfrm ctpfrm",n).text(jObj(t.CustomValues,"contactName")),r.tbl.children("tbody").each($inv.bdysort),r.tbl.trigger("fds.inv")},complete:()=>{a.c.trigger("modal_close")}})},error:()=>{a&&a.c.trigger("modal_close")}})},$inv.adrCountries=[["DE","Deutschland"],["AT","Österreich"],["CH","Schweiz"],["FR","Frankreich"],["NL","Niederlande"],["BE","Belgien"],["LU","Luxemburg"],["IT","Italien"],["ES","Spanien"],["PL","Polen"],["DK","Dänemark"],["CZ","Tschechien"],["GB","Großbritannien"],["US","USA"]],$inv.composeAddress=function(e){let t=[],n=e=>{""!==(e=(""+(e||"")).trim())&&t.push(e)};n((e=e||{}).name),""!==(""+(e.contact||"")).trim()&&n("z.Hd. "+(""+e.contact).trim()),n(e.line2||e.addressLine2),n(e.street),n(((e.postalCode||"")+" "+(e.city||"")).trim());let i=(""+(e.countryCode||"")).toUpperCase();return""!==i&&"DE"!==i&&n(i),t.join("\n")},$inv.adrCurrent=function(e){let t=jObj((e.data("new")||{}).CustomValues,"sendToAddress");if("string"==typeof t&&"{"===t.trim().charAt(0))try{t=JSON.parse(t)}catch(e){t=null}if(t&&"object"==typeof t)return t;let n=(e.data("admin")||{}).invoiceaddressData;if("string"==typeof n&&"{"===n.trim().charAt(0))try{return JSON.parse(n)}catch(e){}else if(n&&"object"==typeof n)return n;return{}},$inv.eAddress=function(e){let t=$inv.d.tbl(),n=$inv.adrCurrent(t),i=[{name:"name",label:"Name / Firma",type:"text",value:n.name||"",required:!0},{name:"contact",label:"z.Hd. (optional)",type:"text",value:n.contact||""},{name:"street",label:"Straße + Nr.",type:"text",value:n.street||""},{name:"line2",label:"Adresszusatz (optional)",type:"text",value:n.line2||n.addressLine2||""},{name:"postalCode",label:"PLZ",type:"text",value:n.postalCode||""},{name:"city",label:"Ort",type:"text",value:n.city||""},{name:"countryCode",label:"Land",type:"select",url:$inv.adrCountries,value:n.countryCode||"DE"},{name:"vatId",label:"USt-IdNr. (nur bei Firmen)",type:"text",value:n.vatId||""},{name:"leitwegId",label:"Leitweg-ID (nur Behörden / B2G)",type:"text",value:n.leitwegId||""}],r=$$.dc("adr-conformity").append([$$.dc("hd").text("Hinweis zur DATEV-/eRechnungs-Konformität"),$$.dc("tx").text("Pflicht: Name, Straße, PLZ, Ort und Land. Die USt-IdNr. nur bei Firmen angeben — für eine Rechnung an eine Privatperson einfach leer lassen. Eine Leitweg-ID nur bei Behörden (B2G) — dann wird die Rechnung automatisch als XRechnung erzeugt.")]);$ocms.dlgform(i,{title:"Rechnungsempfänger",addcontent:r,success:function(t){let n={name:t.name||"",contact:t.contact||"",line2:t.line2||"",street:t.street||"",postalCode:t.postalCode||"",city:t.city||"",countryCode:t.countryCode||"DE",vatId:(""+(t.vatId||"")).trim(),leitwegId:(""+(t.leitwegId||"")).trim()},i=$inv.composeAddress(n);e.data&&e.data.t&&e.data.t.rwText(i),"function"==typeof(e.data||{}).change&&e.data.change(i),$inv.d.sync({Target:"address",Value:n})}})},$inv.provToIso=function(e){let t=(""+(e||"")).match(/(\d{1,2})\.(\d{1,2})\.(\d{4})/);return t?t[3]+"-"+("0"+t[2]).slice(-2)+"-"+("0"+t[1]).slice(-2):""},$inv.eProvisionPeriod=function(e){let t=(""+(e.data&&e.data.t?e.data.t.text():"")).trim().match(/\d{1,2}\.\d{1,2}\.\d{4}/g)||[],n=[{name:"von",label:"Leistungsdatum",type:"date",value:$inv.provToIso(t[0]||"")},{name:"bis",label:"Leistungszeitraum – bis (optional)",type:"date",value:$inv.provToIso(t[1]||"")}],i=$$.dc("adr-conformity").append([$$.dc("hd").text("Leistungsdatum / -zeitraum"),$$.dc("tx").text('Für ein einzelnes Datum nur „Leistungsdatum" ausfüllen; für einen Zeitraum zusätzlich das Bis-Datum. Nur strukturierte Datumsauswahl — für die E-Rechnung empfohlen.')]);$ocms.dlgform(n,{title:"Leistungsdatum / -zeitraum",addcontent:i,success:function(t){let n=(""+(t.von||"")).trim(),i=(""+(t.bis||"")).trim(),r=""===n?"":""===i||i===n?n:n+" - "+i;e.data&&e.data.t&&e.data.t.rwText(r),"function"==typeof(e.data||{}).change&&e.data.change(r),$inv.d.sync({Target:"provisionperiod",Value:r})}})},$inv.eEmail=function(e){let t=[{name:"email",label:$rct.frm.invoiceemail,type:"text",value:(e.data.t||$$.s()).text()},{name:"emailcc",label:$rct.frm.invoiceemailcc,type:"text",value:(e.data.ccT||$$.s()).text()}];$ocms.dlgform(t,{title:$rct.frm.invoiceemail,success:function(t){let n=(""+(t.email||"")).trim(),i=(""+(t.emailcc||"")).trim();e.data&&e.data.t&&e.data.t.text(n),e.data&&e.data.ccT&&e.data.ccT.text(i),"function"==typeof(e.data||{}).change&&e.data.change(n),"function"==typeof(e.data||{}).changeCc&&e.data.changeCc(i),$inv.d.syncField("invoiceemail",n),$inv.rd.syncField("invoiceemail",n),$inv.d.syncField("invoiceemailcc",i),$inv.rd.syncField("invoiceemailcc",i)}})},$inv.emailFrm=function(e,t,n,i){let r=$$.dc("inpfrm emailccfrm",e),a=$$.dc("content",r).rwText(i),s=$$.dc("inpfrm emailfrm",e),l=$$.dc("content",s).rwText(n);$$.dc("axf",s).append($$.dc("ibtn edit",{title:$rct.frmTT.invoiceemail}).append(gi("pencil")).click({t:l,ccT:a,nme:"invoiceemail",change:e=>{t.tbl.data("new").invoiceemail=e},changeCc:e=>{t.tbl.data("new").invoiceemailcc=e}},$inv.eHtml)),t.tbl.data("new").invoiceemail=n,t.tbl.data("new").invoiceemailcc=i},$inv.eHtml=function(e){if(e.data&&!(e.data instanceof jQuery)&&$inv.d&&"function"==typeof $inv.d.token&&""!==$inv.d.token()){if("invoiceaddress"===e.data.nme)return $inv.eAddress.call(this,e);if("provisionperiod"===e.data.nme)return $inv.eProvisionPeriod.call(this,e)}if(e.data&&!(e.data instanceof jQuery)&&"invoiceemail"===e.data.nme&&e.data.ccT)return $inv.eEmail.call(this,e);let t=$(this),n=e.data instanceof jQuery?e.data:e.data.t,i=["invoiceemail","invoiceemailcc","provisionperiod","invoicetitle"].includes(e.data.nme),r=i?[{name:"txt",label:"Text",type:"text",value:n.text()}]:[{name:"txt",label:"Text",type:"html",value:n.html(),tinymce:!0,attr:{style:"height: 300px"}}],a=e.data.change||null,s={title:t.data("dialog")||"",success:function(t){i?n.text(t.txt||""):n.html(t.txt),"function"==typeof a&&a(t.txt),$inv.d.syncField(e.data.nme,i?t.txt||"":t.txt),$inv.rd.syncField(e.data.nme,i?t.txt||"":t.txt)},tinymce:{valid_elements:"br",hidemenu:!0,hidetoolbar:!0}};if(Array.isArray(e.data.list)){let t=$$.dc("lstfrm");$.each(e.data.list,((n,i)=>{let r=$$.dc("li",t).append(""!==(e.data.lbl||"")?$$.dc("lbl").rwText(i[e.data.lbl]):null);$$.dc("adr",r).rwText(i[e.data.property]).data("val",i[e.data.property]).click((function(){let e=$(this),t=e.closest(".modal-body").find(':input[name="txt"]');t.is(".tinymce")?tinymce.get(t.attr("id")).setContent($$.s().rwText(e.data("val")).html()):"TEXTAREA"===t.prop("tagName")?t.val(e.data("val")).change():t.rwText(e.data("val"))}))})),s.addcontent=t}$ocms.dlgform(r,s)},$inv.setVat=function(e){$(this);let t=e.data,n=prompt($rct.rqV);n&&(n=parseFloat(n.replace("%","")),n>1&&(n*=.01),!1===isNaN(n)&&(t.siblings(".itm").each((function(){$(this).data().vat=fnum(n,{style:"percent"}).replace(" ","")})),$inv.t_fds_inv()))},$inv.inRow=function(e){let t=$(this),n=e.data,i={},r=$rcol.itm.clone(["SortOrder","NameOrNumber","Type","quantityhours","UnitString","net","svcnet_val","svcvat_val","net_val","vat_val","vat","Note"]),a="N"+(65536*(1+Math.random())||0).toString(16).substr(6),s=$$.tr({id:"itm_"+a.toString(),class:"itm"});$ocms.dlgform(r,{title:t.data("dialog")||"",success:function(e){s.data($.extend({Id:a},i,e)),$inv.rrw.call(s),s.insertAfter(n),$inv.t_fds_inv()},typedvalues:!0})},$inv.eRow=function(e){let t=$(this),n=e.data,i=n.data()||{},r=["SortOrder","NameOrNumber","Type","quantityhours","UnitString","net","svcnet_val","svcvat_val","net_val","vat_val","vat","Note"];i.id||""!==(i.Type||"")||r.unshift("Type");let a=$rcol.itm.clone(r).applyValues(i);a.set("Type","hidden","type"),$inv.eRw.call(t,n,i,a)},$inv.eRw=function(e,t,n){let i=$(this);$ocms.dlgform(n,{title:i.data("dialog")||"",success:function(n){let i={};""===(t.Id||"")&&(i.Id="N"+(65536*(1+Math.random())||0).toString(16).substr(6),e.attr("id","itm_"+i.Id.toString())),i.quantity=((n.quantityhours||"").toString()+" "+(n.UnitString||"").toString()).trimEnd(),e.data($.extend({},t,n,i)),console.debug("eRw success %o",e.data()),$inv.rrw.call(e),$inv.t_fds_inv()},typedvalues:!0})},$inv.bdysort=(e,t)=>{$(t).Sortable({dragItem:!1,dragHandleClass:"ico",parentident:"tr",onend:()=>{$inv.t_fds_inv()}})},$inv.rowCtxMenu=function(e){let t=$$[0]("nav").aC("rowctx");return t.ocmsmenu([{glyph:"glyphicon-option-vertical",aclass:"ctxbtn",attr:{title:$rct.ctxM},itm:e}]),t.find("li[title]").each((function(){let e=$(this);e.children("a").attr("title",e.attr("title"))})),t},$inv.rrw=function(){let e=$(this),t=e.data(),n={},i=e.is(".placeholder"),r=e.is(".hidenote"),a=e=>$$.d().append(e).html(),s=[{lbl:$rct.iRb,attr:{title:$rct.iRb},data:e,fnc:$inv.inRow}];!1===i&&(s.unshift({lbl:$rct.cP,attr:{title:$rct.cP},data:e,fnc:$inv.eRow}),s.push({lbl:$rct.dR,attr:{title:$rct.dR},fnc:function(t){confirm($rct.cD)&&(e.remove(),$inv.t_fds_inv())}}),"set"===(t.Type||"").toLowerCase()&&0===(t.net_val||0)&&s.push({lbl:$rct.toSetP,attr:{title:$rct.toSetP},data:e,fnc:$inv.toSetPrice}));let l=$$.dc("axf").append($inv.rowCtxMenu(s));!0===i?n={id:"",typ:"placeholder"}:!0===e.is(".itm.osum")?n={invrqid:t.InvRqId,id:"osum"+e.index(),typ:"osum",p:"",q:null,t:a(t.tbl.tbl),tt:null,v:null,vt:t.net_val,vs:t.svcnet_val,vat:t.vat,vv:t.vat_val,vsv:t.svcvat_val,det:!1}:(n={invrqid:t.InvRqId,id:t.Id||"",typ:t.Type||"other",p:"",q:null,t:"",tt:null,v:null,vt:t.net_val,vs:t.svcnet_val,vat:t.vat,vv:t.vat_val,vsv:t.svcvat_val,det:""!==(t.Note||"")&&!1===r,SetItmId:t.SetItmId||null,lvl:t.lvl||0},$$.dc("ibtn ico move",l,{title:$rct.mR}),n.p=null!=t.position?t.position:t.SortOrder||"",""===n.id?n.t="":["Text","Title"].includes(n.typ)&&0===(t.net_val||0)?n.t=t.htmltext||("#"!==(t.NameOrNumber||"").substr(0,1)?a($$[0]("p").text(t.NameOrNumber)):"")+(t.Note||""):(n.tt=n.det?"":$$.s(t.Note||"").text(),n.q=t.quantity||(0!==(t.quantityhours||0)?fnum(t.quantityhours)+" "+(t.UnitString||""):""),n.t=t.htmltext||(n.det?a($$.s(t.NameOrNumber||""))+a($$.dc("desc").html(t.Note)):a($$.s(t.NameOrNumber||""))),n.v=t.net,n.vt=t.net_val)),""!==(t.Note||"")&&$$.dc("ibtn add",l,{title:$rct.noteToggle}).append(gi("object-align-left")).click((function(t){$inv.rrw.call(e.tC("hidenote"))}));let d=[$$.tdc("aux").append(l),$$.tdc("keep").text(n.p)];if(""===n.id)d.push($$.td(e,{colspan:4}).append(n.t));else{Array.prototype.push.apply(d,n.q?[$$.tdc("keep").text(n.q)]:[]);let e=e=>null==e?"":fnum(e,$rct.cst);Array.prototype.push.apply(d,[$$.tdc("txt",{colspan:n.q?1:2,title:n.tt}).append(n.t),$$.tdc("currency").text(e(n.v)),$$.tdc("currency inetval").text(e(n.vt)).attr("title",$rct.svcPart+": "+e(n.vs))])}e.empty().attr("class",i?"placeholder":"itm").aC(n.Typ).tC("sethdr","set"===(n.typ||"").toString().toLowerCase()).aC((n.lvl||0)>0?"lvl"+Math.min(n.lvl,6):"").tC("hidenote",r).append(d),t.co=n},$inv.toSetPrice=function(e){let t=(e.data.data().Id||"").toString();""!==t&&!1!==confirm($rct.toSetPc)&&$.when($inv.t_fds_inv()).done((()=>{$inv.d.sync({Target:"item.setprice",Ref:t})}))},$inv.invSumUpdate=function(){let e=$(this),t=[],n=e.children("tbody"),i=[];n.each(((e,n)=>{let r=$(n),a=r.data()||{},s=[],l=[],d=r.find("tr.itm");r.tC("empty",d.length<1),d.each(((e,t)=>{let n=$(t).data()||{};s.push(n.co);let r=$inv.itemToContract(n),a=(n.SetItmId||"").toString();""!==a&&a!==r.id&&(r.setId=a),l.push(r);let d=!1===["text","title"].includes((n.Type||"other").toLowerCase());n.position=((e,t)=>{if(!e)return"";let n=Math.max(t||0,0);for(;i.length<=n;)i.push(0);return i.length=n+1,i[n]++,i.join(".")})(d,(n.co||{}).lvl||0),$inv.rrw.call(t)})),t.push({Id:a.Id,nme:a.Name,text:a.text,itm:s,items:l})}));let r=e.find("tbody:not(.empty)").length;n.find("tr.isum").tC("hidden",r<2),e.data("bai",t),""===(e.data("dtoken")||"")&&!1===bool(e.data("dseeding"),!1)&&null!=(e.data("admin")||{}).type&&(e.data("dseeding",!0),$inv.d.seed($.extend($inv.invcPayload(e.data()),{invid:e.data("invid")||""})))},$inv.worknotes=function(e){let t="";return e.steps.forEach(((e,n)=>{let i;try{i=JSON.parse(e.Data||{}).fields||[]}catch(e){console.debug(e),i=[]}!0!==Array.isArray(i||"")&&(i="object"==typeof i&&!0===Array.isArray(i.field||"")?i.field:[]),i.forEach(((e,n)=>{"Ausgeführte Arbeiten"===e.name&&(t=e.result||"")}))})),t},$inv.rendersrq=function(){let e=$(this).empty(),t=e.is(".onesum"),n=e.data(),i=$$.tr(e,{id:"srq"+n.Id}).aC("title nosort"),r=($rcol.itm.lbl(),$$.dc("axf").appendTo($$.tdc("aux",i)));$$.dc("ibtn osum",r,{title:$rct.combP}).append(gi("euro")).click((function(t){e.tC("onesum"),$inv.rendersrq.call(e),$inv.t_fds_inv()})),$$.dc("ibtn setvat",r,{title:$rct.sV}).append(gi("gbp")).click(i,$inv.setVat),$$.dc("ibtn insb",r,{title:$rct.iRb}).append(gi("indent-left")).click(i,$inv.inRow);let a,s=$$.sc("text",n.text),l=($$.td(i,{colspan:t?4:5}).append(s),["net_val","vat_val","svcnet_val","svcvat_val","net"]);if($$.dc("ibtn edit",r,{title:$rct.sectionTitleEditTT}).data("dialog",$rcol.req.lbl().Name).append(gi("pencil")).click({t:s,change:e=>{n.text=e,$inv.t_fds_inv()}},$inv.eHtml),t&&($$.tdc("currency isumval",i),a={Id:n.Id.toString()+"_osum",net_val:0,vat_val:0,svcnet_val:0,svcvat_val:0,net:0},a.tbl=$$.tblset({class:"stbl"})),$.each(n.items||[],((n,i)=>{let r,s={Id:i.Id,net_val:i.net_val||0,vat_val:i.vat_val||0,svcnet_val:0,svcvat_val:0,net:i.net||0,Note:i.Note||""};if("service"===i.Type.toLowerCase())s.svcnet_val=i.net_val||0,s.svcvat_val=i.vat_val||0;t?(r=$$.tr(a.tbl.bdy,{id:"itm"+i.Id,class:"sitm"}).aC(i.Type),"Text"===i.Type||"Title"===i.Type?$$.td(r,{colspan:2}).html(i.htmltext||i.Note):($$.tdc("keep",r).text(i.quantity||((i.quantityhours||0)>0?fnum(i.quantityhours)+(i.UnitString||"").eine(" ",""):"")),i.htmltext?$$.tdc("txt",r).html(i.htmltext):$$.tdc("txt",r).text(i.NameOrNumber).attr("title",i.Note)),$.each(l,((e,t)=>{a[t]+=s[t]})),r.data(s)):($.extend(s,i),r=$$.tr(e,{id:"itm"+i.Id,class:"itm"}),r.data(s),$inv.rrw.call(r))})),t){let t=$$.tr(e,{id:"itmsq"+n.Id,class:"itm osum"}).data(a);$inv.rrw.call(t)}else{let t=$$.tr(e).aC("isum nosort");$$.tdc("aux",t),$$.td(t,{colspan:4}).text($rct.iSum),$$.tdc("currency isumval",t)}},$inv.t_fds_inv=()=>{let e=$("div.invoice_layout table.invi");if(e.trigger("fds.inv"),""!==(e.data("dtoken")||""))return $inv.d.syncChanged(e);let t=e.data("dseedpromise");return t?$.when(t).then((()=>$inv.d.syncChanged(e))):$.when()},$inv.sedit=()=>{$inv.sprev(!0)},$inv.jdisp=function(e){e.stopPropagation(),e.data.id&&$inv.disp(e.data.id,e.data.typ||"")},$inv.disp=(e,t)=>{let n="";switch(t){case"inv":n="inv/rdoc";break;case"rem":n="rem/rdoc"}if(""!==n){let t=$inv.pdfWaitDlg();$ocms.postXT({url:$ocms.url(n),data:{id:e||"",typ:"img"},timeout:$inv.pdfPreviewTimeout,success:e=>{let t=$$.dc("imagecollection pdfpreview"),n=Math.round(.88*vh());e.id;$.each(e.img||[],(function(e,i){$$.dc("pdfp",t).append($$.img(i).css("max-height",(n-rpx(6)).toString()+"px"))})),$ocms.dlg(t,{size:[n,Math.round(.88*vw())],zindex_min:50,form:!1,exclusive:!1})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(null,t)})}},$inv.jdbn=function(e){let t=$inv.pdfWaitDlg();$ocms.postXT({url:$ocms.url("inv/rdocn"),data:{name:e.data.id||"",typ:"img"},timeout:$inv.pdfPreviewTimeout,success:e=>{let t=$$.dc("imagecollection pdfpreview"),n=Math.round(.88*vh());e.id;$.each(e.img||[],(function(e,i){$$.dc("pdfp",t).append($$.img(i).css("max-height",(n-rpx(6)).toString()+"px"))})),$ocms.dlg(t,{size:[n,Math.round(.88*vw())],zindex:50,form:!1})},error:$inv.pdfPreviewFailed,complete:$inv.pdfPreviewComplete(null,t)})},$inv.sp13b=()=>{var e=$("div.invoice_layout").find("table.invi"),t=e.data();t.admin.p13b=!0,!1===(t.inv.InvoiceOptions||"").split(",").includes("§13b")&&(t.inv.InvoiceOptions+=",§13b"),e.trigger("fds.inv"),$inv.d.sync({Target:"p13b",Value:t.admin.p13b})},$inv.itemToContract=function(e){let t=((e=e||{}).Type||"").toString().toLowerCase(),n=e=>e??null,i={id:(e.Id||"").toString(),type:t,title:"",desc:"",qty:"",price_net:"",total_net:n(e.net_val),vat:e.vat||""};var r;return e.co&&"osum"===e.co.typ?(i.desc=e.co.t||"",i.total_net=e.net_val||0):["text","title"].includes(t)&&0===(e.net_val||0)?(i.desc=e.htmltext||("#"!==(e.NameOrNumber||"").substr(0,1)?(r=$$[0]("p").text(e.NameOrNumber||""),$$.d().append(r).html()):"")+(e.Note||""),i.total_net=""):(e.htmltext?i.desc=e.htmltext:(i.title=e.NameOrNumber||"",i.desc=e.Note||""),i.qty=e.quantity||(0!==(e.quantityhours||0)?fnum(e.quantityhours)+(e.UnitString?" "+e.UnitString:""):""),i.price_net=n(e.net),i.total_net=n(e.net_val)),i},$inv.hasSets=e=>((e||{}).req||[]).some((e=>{let t=((e||{}).itm||[]).filter((e=>e&&""!==(e.id||""))),n={};t.forEach((e=>{n[(e.id||"").toString()]=e}));return t.some((e=>{let t=(null==e.SetItmId?"":e.SetItmId).toString();return""!==t&&t!==(e.id||"").toString()&&n[t]&&(e=>"set"===(e.typ||"").toString().toLowerCase())(n[t])}))})),$inv.ssetmode=()=>{let e,t=$("div.invoice_layout").find("table.invi").data();if(t.dstate&&!1===$inv.hasSets(t.dstate))return void alert($rct.toSetMn);let n=t=>$$.dc("btn",$ict.setmo[t]).click((()=>{e.c.trigger("modal_close"),$inv.setSetmode(t)})),i=$$.dc("choicefrm").append([n("setprice"),n("setonly")]);e=$ocms.dlg(i,{width:800})},$inv.setSetmode=e=>{if(!1===confirm($rct.toSetMc||$rct.toSetPc))return;let t="setonly"===e?"block.setonly":"block.setprice";$.when($inv.t_fds_inv()).done((()=>{$inv.d.sync({Target:t})}))},$inv.sctp=()=>{let e=$invcol.ctp;$ocms.dlgform(e,{title:$ict.ctp,success:function(e){var t=$("div.invoice_layout"),n=t.find("table.invi").data();let i={};void 0!==n.new&&"{"===(n.new.CustomValues||"").substr(0,1)&&(i=JSON.parse(n.inv.CustomValues)),i.contactName=e.name,i.contactEmail=e.email,n.new.CustomValues=JSON.stringify(i),t.find(".ctpfrm").text(ne(e.name,e.email)),$inv.d.sync({Target:"contact",Value:{name:e.name,email:e.email}})},typedvalues:!0})},$inv.invcPayload=function(e){e=e||{};let t=$.extend({},e.new),n=$.extend({},e.admin);return t.title=null!=t.invoicetitle?t.invoicetitle:t.title||"",t.provisionlocation=null!=t.loc?t.loc:t.provisionlocation||"",t.paymentterm=null!=n.paymentterms?n.paymentterms:t.paymentterm||"",n.customerid=null!=n.customerid?n.customerid:n.CustomerId,{admin:n,req:e.bai,new:t}},$inv.ssave=()=>{$inv.d.save()},$inv.sprev=e=>{$inv.d.preview()},$inv.rReload=()=>{try{let e=$("#listframe ul.rql:first").data();$inv.cInv2({id:e.search})}catch(e){}},$inv.quantChange=function(e){},$inv.storno=function(e,t){let n,i=$$.dc("choicefrm").append([$$.dc("btn","Storno ohne Details").click({id:e,mode:"simple"},(e=>{n.c.trigger("modal_close"),$inv.cSt(e.data)})),$$.dc("btn","Storno mit neuer Rechnung").click({id:e},(e=>{n.c.trigger("modal_close"),$inv.ccStInv(e)})),$$.dc("btn","Storno mit best. Rechnung").tC("inactive",!1===bool(t,!1)).click({id:e,mode:"copy"},(e=>{!0===bool(t,!1)&&(n.c.trigger("modal_close"),$inv.cSt(e.data))}))]);n=$ocms.dlg(i,{width:1e3})},$inv.credit=function(e,t){let n,i=$$.dc("choicefrm").append([$$.dc("btn","Gutschrift").click({id:e,mode:"credit"},(e=>{n.c.trigger("modal_close"),$inv.cSt(e.data)}))]);n=$ocms.dlg(i,{width:1e3})},$inv.setPyd=function(e){confirm($ict.cpyd)&&$ocms.postXT({url:$ocms.url("inv/setpyd"),timeout:60,data:{id:e},success:e=>{alert($ict.relm)},error:()=>{alert($t.f1)}})},$inv.setUpd=function(e){confirm($ict.cupd)&&$ocms.postXT({url:$ocms.url("inv/setupd"),timeout:60,data:{id:e},success:e=>{alert($ict.relm)},error:()=>{alert($t.f1)}})},$inv.resendRem=function(e){e.stopPropagation(),e.data.id&&confirm(string($ict.remresc,[e.data.name]))&&$ocms.postXT({url:$ocms.url("rem/resend"),timeout:60,data:{id:e.data.id},success:t=>{alert(string($ict.remresr,[e.data.name]))},error:()=>{alert($t.f1)}})},$inv.dspRem=function(e){let t=$$.dc("rfrm").ldng(1),n=$ocms.dlg(t,{width:1e3});n.ft.rwText($rct.rq2),$ocms.postXT({url:$ocms.url("inv/getrem"),timeout:60,data:{id:e,drafts:!1},success:e=>{n.ft.empty();let i=$$.tblset({class:"invtbl"},t.empty()),r=$invcol.rem2,a=$$.tr(i.hd);$$.th(a);$.each(r.fields||[],((e,t)=>{$$.th(a).text(t.label)}));let s=!1;$.each(e,((e,t)=>{s=!s;let n=$$.tr(i.bdy).tC("alt",s),a=$$.td(n);n.click((function(){n.tC("selected").siblings().rC("selected")})),!0===bool(t.hasFile,!1)&&($$.dc("idl ilbtn",a,{title:$ict.dl+"\n"+t.DocumentName}).append(gi("save-file","ico")).click({id:t.Id},$inv.downloadrem),$$.dc("idl ilbtn",a,{title:$ict.remdsp+"\n"+t.DocumentName}).append(gi("eye-open","ico")).click({id:t.Id,typ:"rem"},$inv.jdisp),$$.dc("idl ilbtn",a,{title:$ict.remres+"\n"+t.DocumentName}).append(gi("refresh","ico")).click({id:t.Id,typ:"rem",name:t.DocumentName},$inv.resendRem)),$.each(r.fields||[],((e,i)=>{let r=$$.td(n).aC(i.dtype),a=t[i.name];if("function"==typeof i.dfnc)i.dfnc.call(r,a,t);else switch(i.type||""){case"date":r.text(fdt(t[i.name],"dd.MM.yy"));break;case"datetime":r.text(fdt(t[i.name]));break;case"html":r.append($$.dc("ctw").html(a)),r.append($$.dc("ttip").html(a));break;default:r.text(t[i.name])}if("InvoiceId"===(i.name||""))r.aC("keep");switch(typeof i.title){case"function":i.title.call(r,t);break;case"string":r.attr("title",cs.title)}}))}))},error:()=>{t.empty(),n.ft.rwText($t.f1)},complete:()=>{t.ldng(0)}})},$inv.ccRem=function(e,t){$(this);$ocms.postXT({url:$ocms.url("rem/lrem"),timeout:60,data:{id:e},success:n=>{let i=$invcol.rid.clone();i.applyValues(n.ov);let r=$$.dc("ac"),a=$$.tblset({class:"fullgrid fullwidth"},r);if((n.lst||[]).length>0){$$.d({style:"margin: 1.5rem 0 1rem 0;font-size: 110%;text-decoration: underline;"}).prependTo(r).text($ict.rovlh);let e=$$.tr(a.hd);$ict.rovl.forEach(((t,n)=>$$.th(e,t))),$.each(n.lst,((e,t)=>{$$.tr(a.bdy).append([$$.tdc("keep",t.subject),$$.tdc("currency",fnum(t.amount,$rct.cst)),$$.tdc("currency",fnum(t.amount_payed,$rct.cst)),$$.tdc("keep",fdt(t.DateFinalized,"dd.MM.yy"))])}))}else $$.td($$.tr(a.bdy),$ict.nd);$ocms.dlgform(i,{addcontent:r,title:string($ict.remdt,[t||"?"]),success:function(t){$inv.ccRem_s2(e,t)},typedvalues:!0})}})},$inv.rRemRw=function(e){let t=$(this),n=e.rm||{};t.empty().data({invoiceid:n.invoiceid,invoicedate:n.invoicedate,amount:n.amount,amount_payed:n.amount_payed});let i=[{lbl:$rct.cP,attr:{title:$rct.cP},data:t,fnc:$inv.eRowR}],r=$$.dc("axf").append($inv.rowCtxMenu(i));t.append([$$.tdc("aux").append(r),$$.tdc("keep",n.invoiceid),$$.tdc("keep",fdt(n.invoicedate,"dd.MM.yy")),$$.tdc("currency",fnum(n.amount,$rct.cst)),$$.tdc("currency",fnum(n.amount_payed,$rct.cst)),$$.tdc("currency",fnum(n.amount-n.amount_payed,$rct.cst))])},$inv.eRowR=function(e){let t=$(this),n=e.data,i=n.data()||{},r=$invcol.rem.clone().applyValues(i);$ocms.dlgform(r,{title:t.data("dialog")||"",success:function(e){let i=t.closest("table"),r=i.data();$.extend(r.rm,e),i.data(r),$inv.rRemRw.call(n,r),$inv.rd.syncAmount(r.rm.amount,r.rm.amount_payed)},typedvalues:!0})},$inv.ccRem_s2=function(e,t){$fis.lf(!1).rC("fix").aC("hd");let n=$$.dc("invoice_layout",$fis.frm_edit()).append($$.dc("btn sprev").click($inv.rprev));$inv.eM(!1,!0);$$.dc("rfrm").ldng(1);$ocms.postXT({url:$ocms.url("rem/get"),timeout:60,data:$.extend({id:e},t),success:e=>{let t=e.rm||{},i=$$.dc("srq",n),r=$$.tblset({class:"invi"},i);r.ft=$$[0]("tfoot"),r.tbl.data($.extend({invid:t.invid,new:{}},e));let a=$$.tr(r.hd).aC("shd").append([$$.th().aC("aux")]);$ict.remHR.forEach((e=>$$.th(a,e))),$inv.rRemRw.call($$.tr(r.bdy),r.tbl.data()),r.ft.appendTo(r.tbl);let s={invoiceemail:"Email-Adresse ändern",subject:"Betreff ändern"},l=(e,t,i,a,l)=>{let d=$$.dc("inpfrm",n).aC(e).append("string"==typeof a?$$.dc("ahd",a):a>0?$$.dc("ahd",$rct.frm[i]):null),c=$$.dc("content",d).rwText(t);$$.dc("axf",d).append($$.dc("ibtn edit",{title:s[i]||$rct.frmTT[i]||$rct.frm[i]}).data("dialog",$rct.frm[i]).append(gi("pencil")).click($.extend({t:c,nme:i,change:e=>{r.tbl.data("new")[i]=e}},l),$inv.eHtml)),r.tbl.data("new")[i]=t};l("tfrm",t.subject,"subject",0,null),l("adrfrm",t.invoiceaddress,"invoiceaddress",0,null),l("emailfrm",t.invoiceemail,"invoiceemail",0,null),$$.dc("sndfrm",n).append($$.dc("content").text(t.sender)),r.tbl.children("tbody").each($inv.bdysort),r.tbl.trigger("fds.inv");let d=r.tbl.data("new");d.amount=t.amount,d.amount_payed=t.amount_payed,$inv.rd.seed({rem:{invid:t.invid,type:t.type,invoiceid:t.invoiceid,invoicedate:t.invoicedate},new:d})},complete:()=>{}})},$inv.rprev=()=>{$inv.rd.preview()},$inv.sis=e=>{confirm($ict.sisc)&&$ocms.postXT({url:$ocms.url("inv/sis"),data:{id:e||""},success:e=>{}})},$inv.srs=e=>{confirm($ict.srsc)&&$ocms.postXT({url:$ocms.url("rem/srs"),data:{id:e||""},success:e=>{}})},$inv.mfrrel=e=>{$("#contentframe").ldng(),$ocms.postXT({url:$ocms.url("inv/mfrrel"),data:{id:e||""},success:e=>{$inv.rerenderinv()},complete:()=>{$("#contentframe").ldng(0)}})},$inv.sets={o:null,c:null,drag:null,isOpen:()=>!!$inv.sets.o,open:function(){let e=$inv.d.tbl();if(e.length<1||$inv.sets.isOpen())return;if(""===$inv.d.token()&&!e.data("dstate"))return;let t=$$.dc("setstruct");$inv.sets.c=t,$inv.sets.o=$ocms.dlg(t,{title:$ict.setst,size:[-1,960],exclusive:!1,close:()=>{$inv.sets.o=null,$inv.sets.c=null,$inv.sets.drag=null}});let n=e.data("dstate");n?$inv.sets.render(n):$inv.d.refresh()},title:e=>{let t=$$.d().html(e.t||"").text().replace(/\s+/g," ").trim();return""!==t?t:$ict.setsNoTitle||""},typLbl:e=>{let t=(e.typ||"").toString().toLowerCase();return($ict.settyp||{})[t]||e.typ||""},isSet:e=>"set"===(e.typ||"").toString().toLowerCase(),parentOf:(e,t)=>{let n=(null==e.SetItmId?"":e.SetItmId).toString(),i=(e.id||"").toString();if(""===n||n===i)return"";let r=t[n];return r&&$inv.sets.isSet(r)?n:""},isDescendant:(e,t,n)=>{let i={},r=n[e];for(;r;){let e=$inv.sets.parentOf(r,n);if(""===e||i[e])return!1;if(e===t)return!0;i[e]=!0,r=n[e]}return!1},canDrop:(e,t,n,i)=>!!e&&e.bid===n&&e.id!==t&&!$inv.sets.isDescendant(t,e.id,i),sync:e=>($inv.sets.c&&$inv.sets.c.aC("busy"),$inv.d.sync(e)),render:function(e){let t=$inv.sets.c;if(!t)return;let n=t.closest(".modal-body"),i=n.length?n.scrollTop():0;t.empty().rC("busy"),$$.dc("shint",t).text($ict.setsHint||""),(e.req||[]).forEach((e=>{if(!e)return;let n=(e.Id||"").toString();if(""===n)return;let i=(e.itm||[]).filter((e=>e&&""!==(e.id||""))),r={};i.forEach((e=>{r[(e.id||"").toString()]=e}));let a=$$.dc("sblock",t).data({bid:n});$inv.sets.rootZone($$.dc("sbhd",a).append($$.sc("nme",e.text||e.nme||n)),n,r);let s=$$.tblset({class:"stbl"},a),l=$$.tr(s.hd);($ict.setsHR||[]).forEach((e=>$$.th(l,e))),i.forEach((e=>$inv.sets.row(s.bdy,e,n,i,r))),$inv.sets.rootZone($$.dc("sroot",a).text($ict.setsRoot||""),n,r),$inv.sets.createBar(a,n,i,r)})),n.length&&n.scrollTop(i)},collapsed:{},hiddenByCollapse:function(e,t){let n={},i=e;for(;i;){let e=$inv.sets.parentOf(i,t);if(""===e||n[e])return!1;if($inv.sets.collapsed[e])return!0;n[e]=!0,i=t[e]}return!1},zone:function(e,t,n){let i=e.originalEvent||e,r=t[0].getBoundingClientRect(),a=(i.clientY||0)-r.top,s=r.height||1;return a<.3*s?"before":a>.7*s||!n?"after":"into"},clearDrop:()=>{$(".setstruct .dropok, .setstruct .dropbefore, .setstruct .dropafter").rC("dropok dropbefore dropafter")},row:function(e,t,n,i,r){let a=(t.id||"").toString(),s=parseInt(t.lvl||0,10)||0,l=$inv.sets.isSet(t),d=$inv.sets.parentOf(t,r),c=l&&!!$inv.sets.collapsed[a],o=$$.tr(e,{draggable:"true"}).aC("srow lvl"+s).tC("isset",l).tC("folded",c).data({id:a,bid:n});$inv.sets.hiddenByCollapse(t,r)&&o.aC("hid"),$$.tdc("grip",o).append(gi("move")).attr("title",$rct.mR),$$.tdc("pos",o).text(null!=t.p?t.p:"");let u=$$.tdc("typ",o);l&&u.append($$.sc("fold").attr("title",c?$ict.setsExpand:$ict.setsCollapse).append(gi(c?"triangle-right":"triangle-bottom")).click((e=>{e.stopPropagation(),c?delete $inv.sets.collapsed[a]:$inv.sets.collapsed[a]=!0;let t=$inv.d.tbl().data("dstate");t&&$inv.sets.render(t)}))),u.append($$.s($inv.sets.typLbl(t))),$$.tdc("qty",o).text(t.q||"");let m=$$.tdc("ttl",o);if(""!==d&&m.append($$.sc("seti",$inv.sets.title(r[d]))),m.append($$.sc("txt",$inv.sets.title(t)).click((function(e){e.stopPropagation(),$(this).tC("exp")}))),l){let e=i.filter((e=>$inv.sets.parentOf(e,r)===a)).length;m.append($$.sc("cnt"," ("+e+")"))}let v=i.filter((e=>$inv.sets.parentOf(e,r)===d)),p=v.findIndex((e=>(e.id||"").toString()===a)),f=v.slice(0,p).some((e=>$inv.sets.isSet(e))),h=$$.tdc("act",o),g=(e,t,n,i,r)=>$$.dc("ibtn "+e,h,{title:n}).append(gi(t)).tC("disabled",!i).click((()=>{i&&$inv.sets.sync(r)}));g("up","arrow-up",$ict.setsUp,p>0,{Target:"set.move",Ref:a,Value:-1}),g("down","arrow-down",$ict.setsDown,p>=0&&p0,{Target:"set.level",Ref:a,Value:-1}),g("in","chevron-right",$ict.setsIn,f,{Target:"set.level",Ref:a,Value:1}),o.on("dragstart",(e=>{$inv.sets.drag={id:a,bid:n},o.aC("dragging");try{e.originalEvent.dataTransfer.setData("text/plain",a),e.originalEvent.dataTransfer.effectAllowed="move"}catch(e){}})).on("dragend",(()=>{o.rC("dragging"),$inv.sets.drag=null,$inv.sets.clearDrop()}));return o.on("dragover",(e=>{if(!$inv.sets.canDrop($inv.sets.drag,a,n,r))return;e.preventDefault();let t=$inv.sets.zone(e,o,l);o.rC("dropok dropbefore dropafter").aC("into"===t?"dropok":"before"===t?"dropbefore":"dropafter")})).on("dragleave",(()=>{o.rC("dropok dropbefore dropafter")})).on("drop",(e=>{e.preventDefault(),$inv.sets.clearDrop();let t=$inv.sets.drag;if($inv.sets.drag=null,!$inv.sets.canDrop(t,a,n,r))return;let i=$inv.sets.zone(e,o,l);"into"===i?$inv.sets.sync({Target:"set.assign",Ref:t.id,Value:{parent:a}}):$inv.sets.sync({Target:"set.move",Ref:t.id,Value:{anchor:a,where:i}})})),o},rootZone:function(e,t,n){return e.on("dragover",(i=>{(()=>{let e=$inv.sets.drag;return!!e&&e.bid===t&&!!n[e.id]&&""!==$inv.sets.parentOf(n[e.id],n)})()&&(i.preventDefault(),e.aC("dropok"))})).on("dragleave",(()=>{e.rC("dropok")})).on("drop",(i=>{i.preventDefault(),e.rC("dropok");let r=$inv.sets.drag;$inv.sets.drag=null,r&&r.bid===t&&n[r.id]&&""!==$inv.sets.parentOf(n[r.id],n)&&$inv.sets.sync({Target:"set.assign",Ref:r.id,Value:{parent:""}})})),e},createBar:function(e,t,n,i){let r=$$.dc("screate",e),a=$("").attr({name:"typ"}).append([$$.opt("set",$ict.settyp.set),$$.opt("text",$ict.settyp.text)]),s=$("").attr({name:"parent"}).append($$.opt("",$ict.setsTop));n.forEach((e=>{if(!$inv.sets.isSet(e))return;let t=parseInt(e.lvl||0,10)||0;s.append($$.opt((e.id||"").toString()," ".repeat(3*t)+$inv.sets.title(e)))}));let l=$('').attr({name:"title",placeholder:$ict.setsTitle,maxlength:250}),d=()=>{let e=(l.val()||"").toString().trim();""!==e?($inv.sets.sync({Target:"set.create",Ref:t,Value:{typ:a.val(),title:e,parent:s.val()||""}}),l.val("")):l.focus()};return l.on("keydown",(e=>{"Enter"===e.key&&(e.preventDefault(),d())})),r.append([$$.sc("lbl",$ict.setsNew),a,$$.sc("lbl",$ict.setsInto),s,l,$$.bbtn($ict.setsAdd,"sadd").click(d)]),r}};
\ No newline at end of file
diff --git a/Fuchs/wwwroot/web/tools.js b/Fuchs/wwwroot/web/tools.js
index f36c9c0..ceb47a5 100644
--- a/Fuchs/wwwroot/web/tools.js
+++ b/Fuchs/wwwroot/web/tools.js
@@ -1,5 +1,4 @@
+/*! js-cookie v3.0.1 | MIT */
+!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,function(){var n=e.Cookies,o=e.Cookies=t();o.noConflict=function(){return e.Cookies=n,o}}())}(this,(function(){"use strict";function e(e){for(var t=1;t+~]|"+ge+")"+ge+"*"),x=new RegExp(ge+"|>"),j=new RegExp(g),A=new RegExp("^"+t+"$"),D={ID:new RegExp("^#("+t+")"),CLASS:new RegExp("^\\.("+t+")"),TAG:new RegExp("^("+t+"|[*])"),ATTR:new RegExp("^"+p),PSEUDO:new RegExp("^"+g),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+ge+"*(even|odd|(([+-]|)(\\d*)n|)"+ge+"*(?:([+-]|)"+ge+"*(\\d+)|))"+ge+"*\\)|)","i"),bool:new RegExp("^(?:"+f+")$","i"),needsContext:new RegExp("^"+ge+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+ge+"*((?:-\\d)?\\d*)"+ge+"*\\)|)(?=[^-]|$)","i")},N=/^(?:input|select|textarea|button)$/i,q=/^h\d$/i,L=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,H=/[+~]/,O=new RegExp("\\\\[\\da-fA-F]{1,6}"+ge+"?|\\\\([^\\r\\n\\f])","g"),P=function(e,t){var n="0x"+e.slice(1)-65536;return t||(n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320))},M=function(){V()},R=J(function(e){return!0===e.disabled&&fe(e,"fieldset")},{dir:"parentNode",next:"legend"});try{k.apply(oe=ae.call(ye.childNodes),ye.childNodes),oe[ye.childNodes.length].nodeType}catch(e){k={apply:function(e,t){me.apply(e,ae.call(t))},call:function(e){me.apply(e,ae.call(arguments,1))}}}function I(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&(V(e),e=e||T,C)){if(11!==p&&(u=L.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return k.call(n,a),n}else if(f&&(a=f.getElementById(i))&&I.contains(e,a)&&a.id===i)return k.call(n,a),n}else{if(u[2])return k.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&e.getElementsByClassName)return k.apply(n,e.getElementsByClassName(i)),n}if(!(h[t+" "]||d&&d.test(t))){if(c=t,f=e,1===p&&(x.test(t)||m.test(t))){(f=H.test(t)&&U(e.parentNode)||e)==e&&le.scope||((s=e.getAttribute("id"))?s=ce.escapeSelector(s):e.setAttribute("id",s=S)),o=(l=Y(t)).length;while(o--)l[o]=(s?"#"+s:":scope")+" "+Q(l[o]);c=l.join(",")}try{return k.apply(n,f.querySelectorAll(c)),n}catch(e){h(t,!0)}finally{s===S&&e.removeAttribute("id")}}}return re(t.replace(ve,"$1"),e,n,r)}function W(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function F(e){return e[S]=!0,e}function $(e){var t=T.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function B(t){return function(e){return fe(e,"input")&&e.type===t}}function _(t){return function(e){return(fe(e,"input")||fe(e,"button"))&&e.type===t}}function z(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&R(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function X(a){return F(function(o){return o=+o,F(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function U(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}function V(e){var t,n=e?e.ownerDocument||e:ye;return n!=T&&9===n.nodeType&&n.documentElement&&(r=(T=n).documentElement,C=!ce.isXMLDoc(T),i=r.matches||r.webkitMatchesSelector||r.msMatchesSelector,r.msMatchesSelector&&ye!=T&&(t=T.defaultView)&&t.top!==t&&t.addEventListener("unload",M),le.getById=$(function(e){return r.appendChild(e).id=ce.expando,!T.getElementsByName||!T.getElementsByName(ce.expando).length}),le.disconnectedMatch=$(function(e){return i.call(e,"*")}),le.scope=$(function(){return T.querySelectorAll(":scope")}),le.cssHas=$(function(){try{return T.querySelector(":has(*,:jqfake)"),!1}catch(e){return!0}}),le.getById?(b.filter.ID=function(e){var t=e.replace(O,P);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&C){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(O,P);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&C){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):t.querySelectorAll(e)},b.find.CLASS=function(e,t){if("undefined"!=typeof t.getElementsByClassName&&C)return t.getElementsByClassName(e)},d=[],$(function(e){var t;r.appendChild(e).innerHTML="",e.querySelectorAll("[selected]").length||d.push("\\["+ge+"*(?:value|"+f+")"),e.querySelectorAll("[id~="+S+"-]").length||d.push("~="),e.querySelectorAll("a#"+S+"+*").length||d.push(".#.+[+~]"),e.querySelectorAll(":checked").length||d.push(":checked"),(t=T.createElement("input")).setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),r.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&d.push(":enabled",":disabled"),(t=T.createElement("input")).setAttribute("name",""),e.appendChild(t),e.querySelectorAll("[name='']").length||d.push("\\["+ge+"*name"+ge+"*="+ge+"*(?:''|\"\")")}),le.cssHas||d.push(":has"),d=d.length&&new RegExp(d.join("|")),l=function(e,t){if(e===t)return a=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)==(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!le.sortDetached&&t.compareDocumentPosition(e)===n?e===T||e.ownerDocument==ye&&I.contains(ye,e)?-1:t===T||t.ownerDocument==ye&&I.contains(ye,t)?1:o?se.call(o,e)-se.call(o,t):0:4&n?-1:1)}),T}for(e in I.matches=function(e,t){return I(e,null,null,t)},I.matchesSelector=function(e,t){if(V(e),C&&!h[t+" "]&&(!d||!d.test(t)))try{var n=i.call(e,t);if(n||le.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){h(t,!0)}return 0":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(O,P),e[3]=(e[3]||e[4]||e[5]||"").replace(O,P),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||I.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&I.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return D.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&j.test(n)&&(t=Y(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(O,P).toLowerCase();return"*"===e?function(){return!0}:function(e){return fe(e,t)}},CLASS:function(e){var t=s[e+" "];return t||(t=new RegExp("(^|"+ge+")"+e+"("+ge+"|$)"))&&s(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=I.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function T(e,n,r){return v(n)?ce.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?ce.grep(e,function(e){return e===n!==r}):"string"!=typeof n?ce.grep(e,function(e){return-1)[^>]*|#([\w-]+))$/;(ce.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||k,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:S.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof ce?t[0]:t,ce.merge(this,ce.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:C,!0)),w.test(r[1])&&ce.isPlainObject(t))for(r in t)v(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=C.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):v(e)?void 0!==n.ready?n.ready(e):e(ce):ce.makeArray(e,this)}).prototype=ce.fn,k=ce(C);var E=/^(?:parents|prev(?:Until|All))/,j={children:!0,contents:!0,next:!0,prev:!0};function A(e,t){while((e=e[t])&&1!==e.nodeType);return e}ce.fn.extend({has:function(e){var t=ce(e,this),n=t.length;return this.filter(function(){for(var e=0;e\x20\t\r\n\f]*)/i,Ce=/^$|^module$|\/(?:java|ecma)script/i;xe=C.createDocumentFragment().appendChild(C.createElement("div")),(be=C.createElement("input")).setAttribute("type","radio"),be.setAttribute("checked","checked"),be.setAttribute("name","t"),xe.appendChild(be),le.checkClone=xe.cloneNode(!0).cloneNode(!0).lastChild.checked,xe.innerHTML="",le.noCloneChecked=!!xe.cloneNode(!0).lastChild.defaultValue,xe.innerHTML="",le.option=!!xe.lastChild;var ke={thead:[1,"
","
"],col:[2,"
","
"],tr:[2,"
","
"],td:[3,"
","
"],_default:[0,"",""]};function Se(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&fe(e,t)?ce.merge([e],n):n}function Ee(e,t){for(var n=0,r=e.length;n",""]);var je=/<|?\w+;/;function Ae(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),p=[],d=0,h=e.length;d\s*$/g;function Re(e,t){return fe(e,"table")&&fe(11!==t.nodeType?t:t.firstChild,"tr")&&ce(e).children("tbody")[0]||e}function Ie(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function We(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Fe(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(_.hasData(e)&&(s=_.get(e).events))for(i in _.remove(t,"handle events"),s)for(n=0,r=s[i].length;n").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),C.head.appendChild(r[0])},abort:function(){i&&i()}}});var Jt,Kt=[],Zt=/(=)\?(?=&|$)|\?\?/;ce.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Kt.pop()||ce.expando+"_"+jt.guid++;return this[e]=!0,e}}),ce.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Zt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Zt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=v(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Zt,"$1"+r):!1!==e.jsonp&&(e.url+=(At.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||ce.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=ie[r],ie[r]=function(){o=arguments},n.always(function(){void 0===i?ce(ie).removeProp(r):ie[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Kt.push(r)),o&&v(i)&&i(o[0]),o=i=void 0}),"script"}),le.createHTMLDocument=((Jt=C.implementation.createHTMLDocument("").body).innerHTML="",2===Jt.childNodes.length),ce.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(le.createHTMLDocument?((r=(t=C.implementation.createHTMLDocument("")).createElement("base")).href=C.location.href,t.head.appendChild(r)):t=C),o=!n&&[],(i=w.exec(e))?[t.createElement(i[1])]:(i=Ae([e],t,o),o&&o.length&&ce(o).remove(),ce.merge([],i.childNodes)));var r,i,o},ce.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1").append(ce.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},ce.expr.pseudos.animated=function(t){return ce.grep(ce.timers,function(e){return t===e.elem}).length},ce.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=ce.css(e,"position"),c=ce(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=ce.css(e,"top"),u=ce.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),v(t)&&(t=t.call(e,n,ce.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):c.css(f)}},ce.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){ce.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===ce.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===ce.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=ce(e).offset()).top+=ce.css(e,"borderTopWidth",!0),i.left+=ce.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-ce.css(r,"marginTop",!0),left:t.left-i.left-ce.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===ce.css(e,"position"))e=e.offsetParent;return e||J})}}),ce.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;ce.fn[t]=function(e){return M(this,function(e,t,n){var r;if(y(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),ce.each(["top","left"],function(e,n){ce.cssHooks[n]=Ye(le.pixelPosition,function(e,t){if(t)return t=Ge(e,n),_e.test(t)?ce(e).position()[n]+"px":t})}),ce.each({Height:"height",Width:"width"},function(a,s){ce.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){ce.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return M(this,function(e,t,n){var r;return y(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?ce.css(e,t,i):ce.style(e,t,n,i)},s,n?e:void 0,n)}})}),ce.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){ce.fn[t]=function(e){return this.on(t,e)}}),ce.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},hover:function(e,t){return this.on("mouseenter",e).on("mouseleave",t||e)}}),ce.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){ce.fn[n]=function(e,t){return 0", "").Replace("", "").Replace("=", "_")
- .Replace(">", "_").Replace("|", "_").Replace("!", "_").Replace("<", "_").Replace("/", "_");
- return new FileInfo(Path.GetTempPath() + safeName);
+ // Same sanitiser as the regenerate-on-miss path (ADR 0025) so a stored and a
+ // regenerated document with the same DocumentName download under the same name.
+ // Fallback to the report id: an empty DocumentName used to yield the temp-dir
+ // segment ("Temp") as the download name.
+ string safeName = FdsDocumentNames.SafeFileName(fln, reportid);
+ return new FileInfo(Path.Combine(Path.GetTempPath(), safeName));
}
}
return null;
diff --git a/Fuchs_DataService/FdsShared.cs b/Fuchs_DataService/FdsShared.cs
index 4d8c095..567af10 100644
--- a/Fuchs_DataService/FdsShared.cs
+++ b/Fuchs_DataService/FdsShared.cs
@@ -40,6 +40,33 @@ public static class FdsConfig
Current["Fds:MFR_host"] ?? "";
}
+///
+/// Download-filename sanitising shared by every path that hands a document to the browser —
+/// stored documents () and documents regenerated on a miss
+/// (IntranetController.HandleReportDoc, ADR 0025) — so both produce the same name for the
+/// same DocumentName. DocumentName is derived from the user-typed invoice title, so it can carry
+/// path separators ("Wartung 2025/26"), stray editor markup and characters Windows rejects.
+///
+public static class FdsDocumentNames
+{
+ // '=' and '!' are legal filename characters, but the stored-document path replaced them
+ // long before the regenerate path existed; kept so unifying the two never loosens either.
+ private static readonly char[] Replaced =
+ [.. Path.GetInvalidFileNameChars(), '=', '!'];
+
+ /// Raw DocumentName (may be null, empty, or wrapped in <p>).
+ /// Used when nothing usable remains after cleanup.
+ public static string SafeFileName(string? documentName, string fallback)
+ {
+ string name = (documentName ?? "").Replace("
", "").Replace("
", "").Trim();
+ if (name.Length == 0) return fallback;
+ foreach (char c in Replaced)
+ name = name.Replace(c, '_');
+ name = name.Trim();
+ return name.Length == 0 ? fallback : name;
+ }
+}
+
internal static class FdsShared
{
internal static string FDSConnectionString() => FdsConfig.FDSConnectionString();
diff --git a/Fuchs_DataService/Fuchs_DataService.xml b/Fuchs_DataService/Fuchs_DataService.xml
index e22f5eb..21a3f9d 100644
--- a/Fuchs_DataService/Fuchs_DataService.xml
+++ b/Fuchs_DataService/Fuchs_DataService.xml
@@ -37,5 +37,18 @@
which Program.cs calls once at startup before any use.
+
+
+ Download-filename sanitising shared by every path that hands a document to the browser —
+ stored documents () and documents regenerated on a miss
+ (IntranetController.HandleReportDoc, ADR 0025) — so both produce the same name for the
+ same DocumentName. DocumentName is derived from the user-typed invoice title, so it can carry
+ path separators ("Wartung 2025/26"), stray editor markup and characters Windows rejects.
+
+
+
+ Raw DocumentName (may be null, empty, or wrapped in <p>).
+ Used when nothing usable remains after cleanup.
+
diff --git a/global.json b/global.json
new file mode 100644
index 0000000..3140116
--- /dev/null
+++ b/global.json
@@ -0,0 +1,5 @@
+{
+ "test": {
+ "runner": "Microsoft.Testing.Platform"
+ }
+}