MailWindow: Allow user to change document date
All checks were successful
Test / Run tests (push) Successful in 1m55s

This commit is contained in:
2024-06-17 19:28:21 +02:00
parent 763f0197ca
commit 7ce8c3cabf
3 changed files with 24 additions and 13 deletions

View File

@ -30,7 +30,7 @@ namespace Elwig.Documents {
public string Author;
public string Header;
public string Footer;
public DateTime Date;
public DateOnly Date;
public Document(string title) {
var c = App.Client;
@ -47,7 +47,7 @@ namespace Elwig.Documents {
.Item("Betriebs-Nr.", c.LfbisNr).Item("UID", c.UstIdNr).NextLine()
.Item("BIC", c.Bic).Item("IBAN", c.Iban)
.ToString();
Date = DateTime.Today;
Date = DateOnly.FromDateTime(Utils.Today);
}
~Document() {

View File

@ -94,9 +94,10 @@
<TextBox x:Name="PostalLocation" Grid.Column="1"
Margin="10,30,10,10" Width="120" HorizontalAlignment="Left"/>
<Label Margin="130,30,10,10" FontSize="14" Grid.Column="1">
<TextBlock>, am <Run x:Name="PostalDate">01.01.2020</Run></TextBlock>
</Label>
<Label Content=", am" Margin="130,30,10,10" FontSize="14" Grid.Column="1"/>
<TextBox x:Name="PostalDate" Grid.Column="1" Text="01.01.2020"
Margin="162,30,10,10" Width="78" HorizontalAlignment="Left"
TextChanged="Date_TextChanged" LostFocus="Date_LostFocus"/>
<GroupBox Header="Adressaten" Margin="10,70,10,47" Grid.Column="1">
<Grid>

View File

@ -303,6 +303,15 @@ namespace Elwig.Windows {
await UpdateRecipients(ctx);
}
private void Date_TextChanged(object sender, RoutedEventArgs evt) {
Validator.CheckDate((TextBox)sender, true);
}
private void Date_LostFocus(object sender, RoutedEventArgs evt) {
var res = Validator.CheckDate((TextBox)sender, true);
if (!res.IsValid) ((TextBox)sender).Text = $"{Utils.Today:dd.MM.yyyy}";
}
private async Task UpdateRecipients(AppDbContext ctx) {
if (RecipientsCustomInput.IsChecked == true) {
Recipients = MemberCustomInput.SelectedItems.Cast<Member>().ToList();
@ -493,6 +502,7 @@ namespace Elwig.Windows {
}
}
var postalDate = DateOnly.ParseExact(PostalDate.Text, "dd.MM.yyyy");
var memberDocs = recipients.Select(m => new {
Member = m,
Docs = docs.SelectMany<SelectedDoc, GeneratedDoc>(doc => {
@ -500,7 +510,7 @@ namespace Elwig.Windows {
if (doc.Type == DocType.Custom) {
return [new GeneratedDoc((string)doc.Details!)];
} else if (doc.Type == DocType.MemberDataSheet) {
return [new GeneratedDoc(new MemberDataSheet(m, ctx))];
return [new GeneratedDoc(new MemberDataSheet(m, ctx) { Date = postalDate })];
} else if (doc.Type == DocType.DeliveryConfirmation) {
var details = ((int, bool))doc.Details!;
var year = details.Item1;
@ -513,7 +523,7 @@ namespace Elwig.Windows {
} else {
return [];
}
return [new GeneratedDoc(new DeliveryConfirmation(ctx, year, m, data))];
return [new GeneratedDoc(new DeliveryConfirmation(ctx, year, m, data) { Date = postalDate })];
} else if (doc.Type == DocType.CreditNote) {
var details = ((int, int))doc.Details!;
var year = details.Item1;
@ -526,7 +536,7 @@ namespace Elwig.Windows {
data.Item3.ConsiderTotalPenalty,
data.Item3.ConsiderAutoBusinessShares,
ctx.GetMemberUnderDelivery(year, m.MgNr).GetAwaiter().GetResult()
))];
) { Date = postalDate })];
} catch (Exception) {
return [];
}