Fixed loading of old billings by making

* tenant bank account values optional
 * landlord mail address optional
This commit is contained in:
Tobias Erbshäußer
2021-01-01 17:06:31 +01:00
parent dac8f59523
commit 7efdc01919
5 changed files with 42 additions and 22 deletions
+15 -10
View File
@@ -71,11 +71,11 @@ namespace UCalc.Data
public static class BillingLoader
{
private static string AsString(JObject parent, string name, bool optional = false)
private static string AsString(JObject parent, string name, string defaultValue = null)
{
if (optional && (parent[name]?.Type ?? JTokenType.Null) == JTokenType.Null)
if (defaultValue != null && (parent[name]?.Type ?? JTokenType.Null) == JTokenType.Null)
{
return "";
return defaultValue;
}
return parent[name]?.Value<string>() ??
@@ -89,7 +89,7 @@ namespace UCalc.Data
private static DateTime? AsDateOptional(JObject parent, string name)
{
var str = AsString(parent, name, true);
var str = AsString(parent, name, "");
if (string.IsNullOrEmpty(str))
{
return null;
@@ -104,8 +104,13 @@ namespace UCalc.Data
throw new JsonException($"Cannot read {parent.Path}.{name} as integer");
}
private static bool AsBool(JObject parent, string name)
private static bool AsBool(JObject parent, string name, bool? defaultValue = null)
{
if (defaultValue != null && (parent[name]?.Type ?? JTokenType.Null) == JTokenType.Null)
{
return defaultValue.Value;
}
return parent[name]?.Value<bool>() ??
throw new JsonException($"Cannot read {parent.Path}.{name} as bool");
}
@@ -118,7 +123,7 @@ namespace UCalc.Data
private static decimal? AsDecimalOptional(JObject parent, string name)
{
var str = AsString(parent, name, true);
var str = AsString(parent, name, "");
if (string.IsNullOrEmpty(str))
{
return null;
@@ -187,7 +192,7 @@ namespace UCalc.Data
billing.Landlord.Salutation = (Salutation) AsInt(landlord, "salutation");
billing.Landlord.Name = AsString(landlord, "name");
billing.Landlord.Phone = AsString(landlord, "phone");
billing.Landlord.MailAddress = AsString(landlord, "mail");
billing.Landlord.MailAddress = AsString(landlord, "mail", "");
LoadAddress(landlord, "address", billing.Landlord.Address);
LoadBankAccount(landlord, "account", billing.Landlord.BankAccount);
@@ -207,8 +212,8 @@ namespace UCalc.Data
EntryDate = AsDateOptional(tenant, "entry_date"),
DepartureDate = AsDateOptional(tenant, "departure_date"),
PaidRent = AsDecimal(tenant, "paid_rent"),
CustomMessage1 = AsString(tenant, "message1", true),
CustomMessage2 = AsString(tenant, "message2", true)
CustomMessage1 = AsString(tenant, "message1", ""),
CustomMessage2 = AsString(tenant, "message2", "")
};
LoadBankAccount(tenant, "account", targetTenant.BankAccount);
@@ -266,7 +271,7 @@ namespace UCalc.Data
Details = details
};
}).ToList(),
DisplayInBill = AsBool(cost, "display")
DisplayInBill = AsBool(cost, "display", false)
};
billing.Costs.Add(targetCost);
+14 -4
View File
@@ -4,15 +4,25 @@ namespace UCalc.Models
{
public class BankAccountProperty : NestedProperty
{
public NotEmptyStringProperty Iban { get; }
public NotEmptyStringProperty Bic { get; }
public NotEmptyStringProperty BankName { get; }
public ValueProperty<string> Iban { get; }
public ValueProperty<string> Bic { get; }
public ValueProperty<string> BankName { get; }
public BankAccountProperty(Model model, Property parent, BankAccount data) : base(model, parent)
public BankAccountProperty(Model model, Property parent, BankAccount data, bool belongsToTenant) : base(model,
parent)
{
if (belongsToTenant)
{
Iban = Add(new AlwaysValidProperty<string>(model, this, "IBAN", data.Iban));
Bic = Add(new AlwaysValidProperty<string>(model, this, "BIC", data.Bic));
BankName = Add(new AlwaysValidProperty<string>(model, this, "Name der Bank", data.BankName));
}
else
{
Iban = Add(new NotEmptyStringProperty(model, this, "IBAN", data.Iban));
Bic = Add(new NotEmptyStringProperty(model, this, "BIC", data.Bic));
BankName = Add(new NotEmptyStringProperty(model, this, "Name der Bank", data.BankName));
}
}
}
}
+3 -3
View File
@@ -6,7 +6,7 @@ namespace UCalc.Models
{
public SalutationProperty Salutation { get; }
public NotEmptyStringProperty Name { get; }
public NotEmptyStringProperty MailAddress { get; }
public AlwaysValidProperty<string> MailAddress { get; }
public NotEmptyStringProperty Phone { get; }
public AddressProperty Address { get; }
public BankAccountProperty BankAccount { get; }
@@ -15,10 +15,10 @@ namespace UCalc.Models
{
Salutation = Add(new SalutationProperty(model, this, "Anrede", data.Salutation));
Name = Add(new NotEmptyStringProperty(model, this, "Name", data.Name));
MailAddress = Add(new NotEmptyStringProperty(model, this, "Email Adresse", data.MailAddress));
MailAddress = Add(new AlwaysValidProperty<string>(model, this, "Email Adresse", data.MailAddress));
Phone = Add(new NotEmptyStringProperty(model, this, "Telefonnummer", data.Phone));
Address = Add(new AddressProperty(model, this, data.Address));
BankAccount = Add(new BankAccountProperty(model, this, data.BankAccount));
BankAccount = Add(new BankAccountProperty(model, this, data.BankAccount, false));
}
}
}
+1 -1
View File
@@ -212,7 +212,7 @@ namespace UCalc.Models
Salutation = Add(new SalutationProperty(model, this, "Anrede", data.Salutation));
Name = Add(new NotEmptyStringProperty(model, this, "Name", data.Name));
PersonCount = Add(new NaturalNumberProperty(model, this, "Personenanzahl", data.PersonCount));
BankAccount = Add(new BankAccountProperty(model, this, data.BankAccount));
BankAccount = Add(new BankAccountProperty(model, this, data.BankAccount, true));
EntryDate = Add(new EntryDateProperty(model, this, "Einzugsdatum", data.EntryDate));
DepartureDate = Add(new DepatureDateProperty(model, this, "Auszugsdatum", data.DepartureDate));
RentedFlats = Add(new RentedFlatsProperty(model, this, data.RentedFlats, flatToProperty));
+6 -1
View File
@@ -188,7 +188,12 @@ namespace UCalc
}
AddText(
$"{Billing.Landlord.Salutation.AsString()} {Billing.Landlord.Name}\n{DateTime.Now.ToString(Constants.DateFormat)}\n\n{Billing.Landlord.Address.Street} {Billing.Landlord.Address.HouseNumber}\n{Billing.Landlord.Address.Postcode} {Billing.Landlord.Address.City}\nTelefon: {Billing.Landlord.Phone}\nEmail: {Billing.Landlord.MailAddress}");
$"{Billing.Landlord.Salutation.AsString()} {Billing.Landlord.Name}\n{DateTime.Now.ToString(Constants.DateFormat)}\n\n{Billing.Landlord.Address.Street} {Billing.Landlord.Address.HouseNumber}\n{Billing.Landlord.Address.Postcode} {Billing.Landlord.Address.City}\nTelefon: {Billing.Landlord.Phone}");
if (!string.IsNullOrEmpty(Billing.Landlord.MailAddress))
{
AddText($"Email: {Billing.Landlord.MailAddress}");
}
AddLineBreaks(2);