Fixed loading of old billings by making
* tenant bank account values optional * landlord mail address optional
This commit is contained in:
+15
-10
@@ -71,11 +71,11 @@ namespace UCalc.Data
|
|||||||
|
|
||||||
public static class BillingLoader
|
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>() ??
|
return parent[name]?.Value<string>() ??
|
||||||
@@ -89,7 +89,7 @@ namespace UCalc.Data
|
|||||||
|
|
||||||
private static DateTime? AsDateOptional(JObject parent, string name)
|
private static DateTime? AsDateOptional(JObject parent, string name)
|
||||||
{
|
{
|
||||||
var str = AsString(parent, name, true);
|
var str = AsString(parent, name, "");
|
||||||
if (string.IsNullOrEmpty(str))
|
if (string.IsNullOrEmpty(str))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -104,8 +104,13 @@ namespace UCalc.Data
|
|||||||
throw new JsonException($"Cannot read {parent.Path}.{name} as integer");
|
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>() ??
|
return parent[name]?.Value<bool>() ??
|
||||||
throw new JsonException($"Cannot read {parent.Path}.{name} as 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)
|
private static decimal? AsDecimalOptional(JObject parent, string name)
|
||||||
{
|
{
|
||||||
var str = AsString(parent, name, true);
|
var str = AsString(parent, name, "");
|
||||||
if (string.IsNullOrEmpty(str))
|
if (string.IsNullOrEmpty(str))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -187,7 +192,7 @@ namespace UCalc.Data
|
|||||||
billing.Landlord.Salutation = (Salutation) AsInt(landlord, "salutation");
|
billing.Landlord.Salutation = (Salutation) AsInt(landlord, "salutation");
|
||||||
billing.Landlord.Name = AsString(landlord, "name");
|
billing.Landlord.Name = AsString(landlord, "name");
|
||||||
billing.Landlord.Phone = AsString(landlord, "phone");
|
billing.Landlord.Phone = AsString(landlord, "phone");
|
||||||
billing.Landlord.MailAddress = AsString(landlord, "mail");
|
billing.Landlord.MailAddress = AsString(landlord, "mail", "");
|
||||||
LoadAddress(landlord, "address", billing.Landlord.Address);
|
LoadAddress(landlord, "address", billing.Landlord.Address);
|
||||||
LoadBankAccount(landlord, "account", billing.Landlord.BankAccount);
|
LoadBankAccount(landlord, "account", billing.Landlord.BankAccount);
|
||||||
|
|
||||||
@@ -207,8 +212,8 @@ namespace UCalc.Data
|
|||||||
EntryDate = AsDateOptional(tenant, "entry_date"),
|
EntryDate = AsDateOptional(tenant, "entry_date"),
|
||||||
DepartureDate = AsDateOptional(tenant, "departure_date"),
|
DepartureDate = AsDateOptional(tenant, "departure_date"),
|
||||||
PaidRent = AsDecimal(tenant, "paid_rent"),
|
PaidRent = AsDecimal(tenant, "paid_rent"),
|
||||||
CustomMessage1 = AsString(tenant, "message1", true),
|
CustomMessage1 = AsString(tenant, "message1", ""),
|
||||||
CustomMessage2 = AsString(tenant, "message2", true)
|
CustomMessage2 = AsString(tenant, "message2", "")
|
||||||
};
|
};
|
||||||
LoadBankAccount(tenant, "account", targetTenant.BankAccount);
|
LoadBankAccount(tenant, "account", targetTenant.BankAccount);
|
||||||
|
|
||||||
@@ -266,7 +271,7 @@ namespace UCalc.Data
|
|||||||
Details = details
|
Details = details
|
||||||
};
|
};
|
||||||
}).ToList(),
|
}).ToList(),
|
||||||
DisplayInBill = AsBool(cost, "display")
|
DisplayInBill = AsBool(cost, "display", false)
|
||||||
};
|
};
|
||||||
|
|
||||||
billing.Costs.Add(targetCost);
|
billing.Costs.Add(targetCost);
|
||||||
|
|||||||
@@ -4,15 +4,25 @@ namespace UCalc.Models
|
|||||||
{
|
{
|
||||||
public class BankAccountProperty : NestedProperty
|
public class BankAccountProperty : NestedProperty
|
||||||
{
|
{
|
||||||
public NotEmptyStringProperty Iban { get; }
|
public ValueProperty<string> Iban { get; }
|
||||||
public NotEmptyStringProperty Bic { get; }
|
public ValueProperty<string> Bic { get; }
|
||||||
public NotEmptyStringProperty BankName { 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));
|
Iban = Add(new NotEmptyStringProperty(model, this, "IBAN", data.Iban));
|
||||||
Bic = Add(new NotEmptyStringProperty(model, this, "BIC", data.Bic));
|
Bic = Add(new NotEmptyStringProperty(model, this, "BIC", data.Bic));
|
||||||
BankName = Add(new NotEmptyStringProperty(model, this, "Name der Bank", data.BankName));
|
BankName = Add(new NotEmptyStringProperty(model, this, "Name der Bank", data.BankName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ namespace UCalc.Models
|
|||||||
{
|
{
|
||||||
public SalutationProperty Salutation { get; }
|
public SalutationProperty Salutation { get; }
|
||||||
public NotEmptyStringProperty Name { get; }
|
public NotEmptyStringProperty Name { get; }
|
||||||
public NotEmptyStringProperty MailAddress { get; }
|
public AlwaysValidProperty<string> MailAddress { get; }
|
||||||
public NotEmptyStringProperty Phone { get; }
|
public NotEmptyStringProperty Phone { get; }
|
||||||
public AddressProperty Address { get; }
|
public AddressProperty Address { get; }
|
||||||
public BankAccountProperty BankAccount { get; }
|
public BankAccountProperty BankAccount { get; }
|
||||||
@@ -15,10 +15,10 @@ namespace UCalc.Models
|
|||||||
{
|
{
|
||||||
Salutation = Add(new SalutationProperty(model, this, "Anrede", data.Salutation));
|
Salutation = Add(new SalutationProperty(model, this, "Anrede", data.Salutation));
|
||||||
Name = Add(new NotEmptyStringProperty(model, this, "Name", data.Name));
|
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));
|
Phone = Add(new NotEmptyStringProperty(model, this, "Telefonnummer", data.Phone));
|
||||||
Address = Add(new AddressProperty(model, this, data.Address));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ namespace UCalc.Models
|
|||||||
Salutation = Add(new SalutationProperty(model, this, "Anrede", data.Salutation));
|
Salutation = Add(new SalutationProperty(model, this, "Anrede", data.Salutation));
|
||||||
Name = Add(new NotEmptyStringProperty(model, this, "Name", data.Name));
|
Name = Add(new NotEmptyStringProperty(model, this, "Name", data.Name));
|
||||||
PersonCount = Add(new NaturalNumberProperty(model, this, "Personenanzahl", data.PersonCount));
|
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));
|
EntryDate = Add(new EntryDateProperty(model, this, "Einzugsdatum", data.EntryDate));
|
||||||
DepartureDate = Add(new DepatureDateProperty(model, this, "Auszugsdatum", data.DepartureDate));
|
DepartureDate = Add(new DepatureDateProperty(model, this, "Auszugsdatum", data.DepartureDate));
|
||||||
RentedFlats = Add(new RentedFlatsProperty(model, this, data.RentedFlats, flatToProperty));
|
RentedFlats = Add(new RentedFlatsProperty(model, this, data.RentedFlats, flatToProperty));
|
||||||
|
|||||||
@@ -188,7 +188,12 @@ namespace UCalc
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddText(
|
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);
|
AddLineBreaks(2);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user