From 516ca587401d9349e63718c170d81c535b5bfddc Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Thu, 4 Jun 2026 07:52:08 +0200 Subject: [PATCH] [fix:] plz/pplz was not normalized during address creation --- Tasks/AddressCreation.cs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Tasks/AddressCreation.cs b/Tasks/AddressCreation.cs index 0c937ec..b543a3b 100644 --- a/Tasks/AddressCreation.cs +++ b/Tasks/AddressCreation.cs @@ -104,8 +104,9 @@ public static class AddressCreator // Alternative A: pplz valid and city existing if (!string.IsNullOrEmpty(address.ort) && CheckPLZ(address.pplz, address.land)) { - KasPerson.SetUsedPLZ(id, address.pplz); - string_address = address.pplz + " " + address.ort + "\n" + string_address; + string pplz = NormalizeGermanPLZ(address.pplz); + KasPerson.SetUsedPLZ(id, pplz); + string_address = pplz + " " + address.ort + "\n" + string_address; address_line_count++; if (!string.IsNullOrWhiteSpace(address.postfach)) { @@ -151,8 +152,9 @@ public static class AddressCreator } // Alternative B: plz valid and city existing else if (!string.IsNullOrEmpty(address.ort) && CheckPLZ(address.plz, address.land)) { - KasPerson.SetUsedPLZ(id, address.plz); - string_address = address.plz + " " + address.ort + "\n" + string_address; + string plz = NormalizeGermanPLZ(address.plz); + KasPerson.SetUsedPLZ(id, plz); + string_address = plz + " " + address.ort + "\n" + string_address; address_line_count++; if (!string.IsNullOrWhiteSpace(address.strasse)) { @@ -251,4 +253,23 @@ public static class AddressCreator // For non-German countries, accept any non-empty postal code return true; } + + public static string NormalizeGermanPLZ(string plz) + { + if(plz.Length == 5) return plz; + if(plz.Length > 5) + { + return plz.Substring(0, 5); + } + + if (plz.Length < 5) + { + int toadd = 5 - plz.Length; + for (int i = 0; i < toadd; i++) + { + plz = "0" + plz; + } + } + return plz; + } } \ No newline at end of file