diff --git a/Elwig/Documents/Document.cs b/Elwig/Documents/Document.cs index 755286e..26a0e29 100644 --- a/Elwig/Documents/Document.cs +++ b/Elwig/Documents/Document.cs @@ -44,8 +44,8 @@ namespace Elwig.Documents { .Item(c.Address).Item($"{c.Plz} {c.Ort}").Item("Österreich").Item("Tel.", c.PhoneNr).Item("Fax", c.FaxNr).NextLine() .Item(c.EmailAddress != null ? $"\">{c.EmailAddress}" : null) .Item(c.Website != null ? $"{c.Website}" : null) - .Item("Betriebs-Nr.", c.LfbisNr).Item("UID", c.UstIdNr).NextLine() - .Item("BIC", c.Bic).Item("IBAN", c.Iban) + .Item("Betriebs-Nr.", c.LfbisNr).Item("Bio-KSt.", c.OrganicAuthority).NextLine() + .Item("UID", c.UstIdNr).Item("BIC", c.Bic).Item("IBAN", c.Iban) .ToString(); Date = DateOnly.FromDateTime(Utils.Today); } diff --git a/Elwig/Helpers/ClientParameters.cs b/Elwig/Helpers/ClientParameters.cs index f6d5d7b..57371c8 100644 --- a/Elwig/Helpers/ClientParameters.cs +++ b/Elwig/Helpers/ClientParameters.cs @@ -55,6 +55,7 @@ namespace Elwig.Helpers { public string? Bic; public string? UstIdNr; public string? LfbisNr; + public string? OrganicAuthority; public string? PhoneNr; public string? FaxNr; @@ -113,6 +114,7 @@ namespace Elwig.Helpers { UstIdNr = parameters.GetValueOrDefault("CLIENT_USTIDNR"); Bic = parameters.GetValueOrDefault("CLIENT_BIC"); Iban = parameters.GetValueOrDefault("CLIENT_IBAN"); + OrganicAuthority = parameters.GetValueOrDefault("CLIENT_ORGANIC_AUTHORITY"); switch (parameters.GetValueOrDefault("MODE_DELIVERYNOTE_STATS", "SHORT")?.ToUpper()) { case "NONE": ModeDeliveryNoteStats = 0; break; @@ -257,6 +259,7 @@ namespace Elwig.Helpers { ("CLIENT_USTIDNR", UstIdNr), ("CLIENT_BIC", Bic), ("CLIENT_IBAN", Iban), + ("CLIENT_ORGANIC_AUTHORITY", OrganicAuthority), ("MODE_DELIVERYNOTE_STATS", deliveryNoteStats), ("MODE_WINEQUALITYSTATISTICS", modeWineQualityStatistics), ("ORDERING_MEMBERLIST", orderingMemberList), diff --git a/Elwig/Helpers/Validator.cs b/Elwig/Helpers/Validator.cs index 53b50b3..b0b76e0 100644 --- a/Elwig/Helpers/Validator.cs +++ b/Elwig/Helpers/Validator.cs @@ -628,5 +628,55 @@ namespace Elwig.Helpers { return new(true, null); } + + public static ValidationResult CheckOrganicAuthorityCode(TextBox input, bool required) { + string text = ""; + int pos = input.CaretIndex; + for (int i = 0, v = 0; i < input.Text.Length; i++) { + char ch = char.ToUpper(input.Text[i]); + if (v < 2 && char.IsAsciiLetter(ch)) { + v++; + text += ch; + } else if ((v == 2 || v == 6) && ch == '-') { + v++; + text += ch; + } else if (v >= 2 && char.IsLetterOrDigit(ch)) { + if (text.StartsWith("AT")) { + if (v == 3 && ch == 'B' || v == 4 && ch == 'I' || v == 5 && ch == 'O') { + v++; + text += ch; + } else if (v > 6 && char.IsAsciiDigit(ch)) { + v++; + text += ch; + } + } else { + v++; + text += ch; + } + } + + if (i == input.CaretIndex - 1) { + pos = text.Length; + } else if (text.StartsWith("AT") && v >= 10) { + break; + } + } + + input.Text = text; + input.CaretIndex = pos; + + if (text.Length == 0) + return required ? new(false, "Bio-Kontrollstellen-Code ist nicht optional") : new(true, null); + + if (text.StartsWith("AT")) { + if (text.Length != 10) { + return new(false, "Bio-Kontrollstellen-Code ist ungültig"); + } + } else { + return new(false, "Not implemented yet"); + } + + return new(true, null); + } } } diff --git a/Elwig/Windows/AdministrationWindow.cs b/Elwig/Windows/AdministrationWindow.cs index e17ba3b..0c4b1a3 100644 --- a/Elwig/Windows/AdministrationWindow.cs +++ b/Elwig/Windows/AdministrationWindow.cs @@ -570,6 +570,14 @@ namespace Elwig.Windows { InputLostFocus((TextBox)sender, Validator.CheckLfbisNr); } + protected void OrganicAuthorityCodeInput_TextChanged(object sender, TextChangedEventArgs? evt) { + InputTextChanged((TextBox)sender, Validator.CheckOrganicAuthorityCode); + } + + protected void OrganicAuthorityCodeInput_LostFocus(object sender, RoutedEventArgs? evt) { + InputLostFocus((TextBox)sender, Validator.CheckOrganicAuthorityCode); + } + protected void UpperCaseInput_TextChanged(object sender, TextChangedEventArgs? evt) { InputTextChanged((TextBox)sender, Validator.CheckUpperCase); } diff --git a/Elwig/Windows/BaseDataWindow.xaml b/Elwig/Windows/BaseDataWindow.xaml index 9dc045d..28623c7 100644 --- a/Elwig/Windows/BaseDataWindow.xaml +++ b/Elwig/Windows/BaseDataWindow.xaml @@ -122,6 +122,12 @@ VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="3" Margin="0,130,10,10" Width="64" TextChanged="LfbisNrInput_TextChanged" LostFocus="LfbisNrInput_LostFocus"/> +