From 3bd2a3f3859cfad6a20262168d89cf3b8cbb1a97 Mon Sep 17 00:00:00 2001 From: Avatarsia Date: Thu, 30 Apr 2026 14:42:50 +0200 Subject: [PATCH] feat(mahnwesen): expose {FRIST}, {DATUMRECHNUNG}, {MAHNDATUM}, {TAGE} placeholders The mahnwesen template engine previously only exposed {DATUM}, {BELEGNR}, {OFFEN}, {MAHNGEBUEHR}, {HEUTE}, {RECHNUNG} via the ParseVars mapping. The legacy block computing {DATUM*}/{TAGE}/{MAHNDATUM} is commented out, so dunning templates referencing a calendar-bound deadline ("bis zum X") had no working placeholder for the deadline date. This adds: - {FRIST} = mahnwesen_datum + mahn_tage (mahnwesen.tage from system settings), formatted dd.mm.yyyy - {DATUMRECHNUNG} = invoice date (alias to {DATUM} for clarity) - {MAHNDATUM} = current dunning issue date in dd.mm.yyyy - {TAGE} = configured grace days for the current dunning level Also fixes a use-before-define on $tage at line 678 by replacing the no-op `if($tage<=0)$tage=0;` with a single `max(0,(int)mahn_tage)` assignment that pulls from the mahnwesen table (system settings). Guards 0000-00-00 mahnwesen_datum to avoid bogus future-date arithmetic. Co-Authored-By: Claude Opus 4.7 (1M context) --- www/pages/mahnwesen.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/www/pages/mahnwesen.php b/www/pages/mahnwesen.php index 61d48e449..9b1b56d5b 100644 --- a/www/pages/mahnwesen.php +++ b/www/pages/mahnwesen.php @@ -675,7 +675,12 @@ function MahnwesenMessage($rechnung_id) { $offen = $this->app->erp->GetSaldoDokument($rechnung_id, 'rechnung'); - if($tage <=0) $tage = 0; + $tage = max(0, (int)$rechnungarr['mahn_tage']); + + $mahnwesen_datum_valid = !empty($mahnwesen_datum) && $mahnwesen_datum !== '0000-00-00'; + $frist_de = $mahnwesen_datum_valid + ? date('d.m.Y', strtotime($mahnwesen_datum.' +'.$tage.' days')) + : ''; /* $datummahnung= $this->app->DB->Select("SELECT DATE_FORMAT(DATE_ADD('$mahnwesen_datum', INTERVAL $tage DAY),'%d.%m.%Y')"); $datumrechnungzahlungsziel= $this->app->DB->Select("SELECT DATE_FORMAT(DATE_ADD('$datum_sql', INTERVAL $zahlungszieltage DAY),'%d.%m.%Y')"); @@ -726,6 +731,10 @@ function MahnwesenMessage($rechnung_id) { 'rechnung' => $belegnr, 'belegnr' => $belegnr, 'datum' => $datum_sql, + 'datumrechnung' => $datum_sql, + 'frist' => $frist_de, + 'mahndatum' => $mahnwesen_datum_deutsch, + 'tage' => $tage, 'offen' => $this->app->erp->EUR(-$offen['betrag'])." ".$offen['waehrung'], 'mahngebuehr' => $this->app->erp->EUR($rechnungarr['mahn_gebuehr']), 'heute' => $rechnungarr['heute']