Skip to content

Commit

Permalink
starting to obsolete properties and go for methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanstapel committed Jan 20, 2025
1 parent 363ebf2 commit 76ef08a
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 131 deletions.
4 changes: 2 additions & 2 deletions ZUGFeRD.Test/ZUGFeRD22Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2782,8 +2782,8 @@ public void TestBuyerOrderReferenceLineId()
InvoiceDescriptor desc = InvoiceDescriptor.Load(s);
s.Close();

Assert.AreEqual(desc.TradeLineItems[0].BuyerOrderReferencedDocument.LineID, "1");
Assert.AreEqual(desc.TradeLineItems[0].BuyerOrderReferencedDocument.ID, "ORDER84359");
Assert.AreEqual(desc.GetTradeLineItems().First().BuyerOrderReferencedDocument.LineID, "1");
Assert.AreEqual(desc.GetTradeLineItems().First().BuyerOrderReferencedDocument.ID, "ORDER84359");
}

[TestMethod]
Expand Down
109 changes: 103 additions & 6 deletions ZUGFeRD/InvoiceDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public class InvoiceDescriptor
/// <summary>
/// An aggregation of business terms containing information about individual invoice positions
/// </summary>
[Obsolete("This property will not be available any more with version 18.0. Please use GetTradeLineItems() instead")]
public List<TradeLineItem> TradeLineItems { get; internal set; } = new List<TradeLineItem>();

/// <summary>
Expand Down Expand Up @@ -310,11 +311,13 @@ public class InvoiceDescriptor
/// <summary>
/// A group of business terms providing information about VAT breakdown by different categories, rates and exemption reasons
/// </summary>
public List<Tax> Taxes { get; internal set; } = new List<Tax>();
[Obsolete("This property will be removed in version 18.0. Please use GetApplicableTradeTaxes() instead")]
public List<Tax> Taxes { get; internal set; } = new List<Tax>();

/// <summary>
/// Transport and packaging costs
/// </summary>
[Obsolete("This property will be removed in version 18.0. Please use GetLogisticsServiceCharges() instead")]
public List<ServiceCharge> ServiceCharges { get; internal set; } = new List<ServiceCharge>();

/// <summary>
Expand Down Expand Up @@ -342,19 +345,22 @@ public class InvoiceDescriptor
/// <summary>
/// Detailed information about the accounting reference
/// </summary>
public List<ReceivableSpecifiedTradeAccountingAccount> ReceivableSpecifiedTradeAccountingAccounts { get; internal set; } = new List<ReceivableSpecifiedTradeAccountingAccount>();
[Obsolete("This property will be removed in version 18.0. Please use GetReceivableSpecifiedTradeAccountingAccounts() instead")]
public List<ReceivableSpecifiedTradeAccountingAccount> _ReceivableSpecifiedTradeAccountingAccounts { get; internal set; } = new List<ReceivableSpecifiedTradeAccountingAccount>();

/// <summary>
/// Credit Transfer
///
/// A group of business terms to specify credit transfer payments
/// </summary>
public List<BankAccount> CreditorBankAccounts { get; set; } = new List<BankAccount>();
[Obsolete("This property will be removed in version 18.0. Please use GetCreditorFinancialAccounts() instead")]
public List<BankAccount> CreditorBankAccounts { get; internal set; } = new List<BankAccount>();

/// <summary>
/// Buyer bank information
/// </summary>
public List<BankAccount> DebitorBankAccounts { get; set; } = new List<BankAccount>();
[Obsolete("This property will be removed in version 18.0. Please use GetDebitorFinancialAccounts() instead")]
public List<BankAccount> DebitorBankAccounts { get; internal set; } = new List<BankAccount>();

/// <summary>
/// Payment instructions
Expand Down Expand Up @@ -808,6 +814,12 @@ public void AddLogisticsServiceCharge(decimal amount, string description, TaxTyp
} // !AddLogisticsServiceCharge()


public List<ServiceCharge> GetLogisticsServiceCharges()
{
return this.ServiceCharges;

Check warning on line 819 in ZUGFeRD/InvoiceDescriptor.cs

View workflow job for this annotation

GitHub Actions / build

'InvoiceDescriptor.ServiceCharges' is obsolete: 'This property will be removed in version 18.0. Please use GetLogisticsServiceCharges() instead'

Check warning on line 819 in ZUGFeRD/InvoiceDescriptor.cs

View workflow job for this annotation

GitHub Actions / build

'InvoiceDescriptor.ServiceCharges' is obsolete: 'This property will be removed in version 18.0. Please use GetLogisticsServiceCharges() instead'
} // !GetLogisticsServiceCharges()


/// <summary>
/// Adds an allowance or charge on document level.
///
Expand Down Expand Up @@ -1039,6 +1051,18 @@ public void AddApplicableTradeTax(decimal basisAmount,
} // !AddApplicableTradeTax()


public List<Tax> GetApplicableTradeTaxes()
{
return this.Taxes;

Check warning on line 1056 in ZUGFeRD/InvoiceDescriptor.cs

View workflow job for this annotation

GitHub Actions / build

'InvoiceDescriptor.Taxes' is obsolete: 'This property will be removed in version 18.0. Please use GetApplicableTradeTaxes() instead'

Check warning on line 1056 in ZUGFeRD/InvoiceDescriptor.cs

View workflow job for this annotation

GitHub Actions / build

'InvoiceDescriptor.Taxes' is obsolete: 'This property will be removed in version 18.0. Please use GetApplicableTradeTaxes() instead'
} // !GetApplicableTradeTaxes()


public bool AnyApplicableTradeTaxes()
{
return this.Taxes.Any();

Check warning on line 1062 in ZUGFeRD/InvoiceDescriptor.cs

View workflow job for this annotation

GitHub Actions / build

'InvoiceDescriptor.Taxes' is obsolete: 'This property will be removed in version 18.0. Please use GetApplicableTradeTaxes() instead'

Check warning on line 1062 in ZUGFeRD/InvoiceDescriptor.cs

View workflow job for this annotation

GitHub Actions / build

'InvoiceDescriptor.Taxes' is obsolete: 'This property will be removed in version 18.0. Please use GetApplicableTradeTaxes() instead'
} // !AnyApplicableTradeTaxes()


private IInvoiceDescriptorWriter _selectInvoiceDescriptorWriter(ZUGFeRDVersion version)
{
switch (version)
Expand Down Expand Up @@ -1304,6 +1328,30 @@ public TradeLineItem AddTradeLineItem(string lineID,
} // !AddTradeLineItem()


internal void _AddTradeLineItem(TradeLineItem item)
{
this.TradeLineItems.Add(item);

Check warning on line 1333 in ZUGFeRD/InvoiceDescriptor.cs

View workflow job for this annotation

GitHub Actions / build

'InvoiceDescriptor.TradeLineItems' is obsolete: 'This property will not be available any more with version 18.0. Please use GetTradeLineItems() instead'

Check warning on line 1333 in ZUGFeRD/InvoiceDescriptor.cs

View workflow job for this annotation

GitHub Actions / build

'InvoiceDescriptor.TradeLineItems' is obsolete: 'This property will not be available any more with version 18.0. Please use GetTradeLineItems() instead'
} // !_AddTradeLineItem()


internal void _AddTradeLineItems(IEnumerable<TradeLineItem> items)
{
this.TradeLineItems.AddRange(items);
} // !_AddTradeLineItems()


public List<TradeLineItem> GetTradeLineItems()
{
return this.TradeLineItems;
} // !GetTradeLineItems()


public bool AnyTradeLineItems()
{
return this.TradeLineItems.Any();
} // !AnyTradeLineItems()


/// <summary>
/// Sets up the payment means.
/// </summary>
Expand Down Expand Up @@ -1379,6 +1427,24 @@ public void AddCreditorFinancialAccount(string iban, string bic, string id = nul
} // !AddCreditorFinancialAccount()


internal void _AddCreditorFinancialAccount(BankAccount bankAccount)
{
this.CreditorBankAccounts.Add(bankAccount);
} // !_AddCreditorFinancialAccount()


public List<BankAccount> GetCreditorFinancialAccounts()
{
return this.CreditorBankAccounts;
} // !GetCreditorFinancialAccounts()


public bool AnyCreditorFinancialAccount()
{
return this.CreditorBankAccounts.Any();
} // !AnyCreditorFinancialAccount()


public void AddDebitorFinancialAccount(string iban, string bic, string id = null, string bankleitzahl = null, string bankName = null)
{
this.DebitorBankAccounts.Add(new BankAccount()
Expand All @@ -1392,6 +1458,24 @@ public void AddDebitorFinancialAccount(string iban, string bic, string id = null
} // !AddDebitorFinancialAccount()


internal void _AddDebitorFinancialAccount(BankAccount bankAccount)
{
this.DebitorBankAccounts.Add(bankAccount);
} // !_AddDebitorFinancialAccount()


public List<BankAccount> GetDebitorFinancialAccounts()
{
return this.DebitorBankAccounts;
} // !GetDebitorFinancialAccounts()


public bool AnyDebitorFinancialAccount()
{
return this.DebitorBankAccounts.Any();
} // !AnyDebitorFinancialAccount()


public void AddReceivableSpecifiedTradeAccountingAccount(string AccountID)
{
AddReceivableSpecifiedTradeAccountingAccount(AccountID, AccountingAccountTypeCodes.Unknown);
Expand All @@ -1400,12 +1484,25 @@ public void AddReceivableSpecifiedTradeAccountingAccount(string AccountID)

public void AddReceivableSpecifiedTradeAccountingAccount(string AccountID, AccountingAccountTypeCodes AccountTypeCode)
{
this.ReceivableSpecifiedTradeAccountingAccounts.Add(new ReceivableSpecifiedTradeAccountingAccount()
this._ReceivableSpecifiedTradeAccountingAccounts.Add(new ReceivableSpecifiedTradeAccountingAccount()
{
TradeAccountID = AccountID,
TradeAccountTypeCode = AccountTypeCode
});
}
} // !AddReceivableSpecifiedTradeAccountingAccount()


public List<ReceivableSpecifiedTradeAccountingAccount> GetReceivableSpecifiedTradeAccountingAccounts()
{
return this._ReceivableSpecifiedTradeAccountingAccounts;
} // !GetReceivableSpecifiedTradeAccountingAccounts()


public bool AnyReceivableSpecifiedTradeAccountingAccounts()
{
return this._ReceivableSpecifiedTradeAccountingAccounts.Any();
} // !AnyReceivableSpecifiedTradeAccountingAccounts()


private string _getNextLineId()
{
Expand Down
34 changes: 12 additions & 22 deletions ZUGFeRD/InvoiceDescriptor1Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,12 @@ public override InvoiceDescriptor Load(Stream stream)
{
for (int i = 0; i < creditorFinancialAccountNodes.Count; i++)
{
BankAccount account = new BankAccount()
{
ID = XmlUtils.NodeAsString(creditorFinancialAccountNodes[0], ".//ram:ProprietaryID", nsmgr),
IBAN = XmlUtils.NodeAsString(creditorFinancialAccountNodes[0], ".//ram:IBANID", nsmgr),
BIC = XmlUtils.NodeAsString(creditorFinancialInstitutions[0], ".//ram:BICID", nsmgr),
Bankleitzahl = XmlUtils.NodeAsString(creditorFinancialInstitutions[0], ".//ram:GermanBankleitzahlID", nsmgr),
BankName = XmlUtils.NodeAsString(creditorFinancialInstitutions[0], ".//ram:Name", nsmgr),
Name = XmlUtils.NodeAsString(creditorFinancialInstitutions[0], ".//ram:AccountName", nsmgr),
};

retval.CreditorBankAccounts.Add(account);
retval.AddCreditorFinancialAccount(iban: XmlUtils.NodeAsString(creditorFinancialAccountNodes[i], ".//ram:IBANID", nsmgr),
bic: XmlUtils.NodeAsString(creditorFinancialInstitutions[i], ".//ram:BICID", nsmgr),
id: XmlUtils.NodeAsString(creditorFinancialAccountNodes[i], ".//ram:ProprietaryID", nsmgr),
bankleitzahl: XmlUtils.NodeAsString(creditorFinancialInstitutions[i], ".//ram:GermanBankleitzahlID", nsmgr),
bankName: XmlUtils.NodeAsString(creditorFinancialInstitutions[i], ".//ram:Name", nsmgr),
name: XmlUtils.NodeAsString(creditorFinancialAccountNodes[i], ".//ram:AccountName", nsmgr));
} // !for(i)
}

Expand All @@ -177,16 +172,11 @@ public override InvoiceDescriptor Load(Stream stream)
{
for (int i = 0; i < debitorFinancialAccountNodes.Count; i++)
{
BankAccount account = new BankAccount()
{
ID = XmlUtils.NodeAsString(debitorFinancialAccountNodes[0], ".//ram:ProprietaryID", nsmgr),
IBAN = XmlUtils.NodeAsString(debitorFinancialAccountNodes[0], ".//ram:IBANID", nsmgr),
BIC = XmlUtils.NodeAsString(debitorFinancialInstitutions[0], ".//ram:BICID", nsmgr),
Bankleitzahl = XmlUtils.NodeAsString(debitorFinancialInstitutions[0], ".//ram:GermanBankleitzahlID", nsmgr),
BankName = XmlUtils.NodeAsString(debitorFinancialInstitutions[0], ".//ram:Name", nsmgr),
};

retval.DebitorBankAccounts.Add(account);
retval.AddDebitorFinancialAccount(iban: XmlUtils.NodeAsString(creditorFinancialAccountNodes[i], ".//ram:IBANID", nsmgr),
bic: XmlUtils.NodeAsString(creditorFinancialInstitutions[i], ".//ram:BICID", nsmgr),
id: XmlUtils.NodeAsString(creditorFinancialAccountNodes[i], ".//ram:ProprietaryID", nsmgr),
bankleitzahl: XmlUtils.NodeAsString(creditorFinancialInstitutions[i], ".//ram:GermanBankleitzahlID", nsmgr),
bankName: XmlUtils.NodeAsString(creditorFinancialInstitutions[i], ".//ram:Name", nsmgr));
} // !for(i)
}

Expand Down Expand Up @@ -265,7 +255,7 @@ public override InvoiceDescriptor Load(Stream stream)

foreach (XmlNode node in doc.SelectNodes("//ram:IncludedSupplyChainTradeLineItem", nsmgr))
{
retval.TradeLineItems.Add(_parseTradeLineItem(node, nsmgr));
retval._AddTradeLineItem(_parseTradeLineItem(node, nsmgr));
}
return retval;
} // !Load()
Expand Down
38 changes: 19 additions & 19 deletions ZUGFeRD/InvoiceDescriptor1Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFo

Writer.WriteOptionalElementString("ram", "PaymentReference", this.Descriptor.PaymentReference);

if (this.Descriptor.CreditorBankAccounts.Count == 0 && this.Descriptor.DebitorBankAccounts.Count == 0)
if (!this.Descriptor.AnyCreditorFinancialAccount() && ! this.Descriptor.AnyDebitorFinancialAccount())
{
if (this.Descriptor.PaymentMeans != null)
{
Expand All @@ -247,7 +247,7 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFo
}
else
{
foreach (BankAccount account in this.Descriptor.CreditorBankAccounts)
foreach (BankAccount creditorBankAccount in this.Descriptor.GetCreditorFinancialAccounts())
{
Writer.WriteStartElement("ram", "SpecifiedTradeSettlementPaymentMeans");

Expand All @@ -266,23 +266,23 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFo
}

Writer.WriteStartElement("ram", "PayeePartyCreditorFinancialAccount");
Writer.WriteElementString("ram", "IBANID", account.IBAN);
if (!String.IsNullOrWhiteSpace(account.Name))
Writer.WriteElementString("ram", "IBANID", creditorBankAccount.IBAN);
if (!String.IsNullOrWhiteSpace(creditorBankAccount.Name))
{
Writer.WriteOptionalElementString("ram", "AccountName", account.Name);
Writer.WriteOptionalElementString("ram", "AccountName", creditorBankAccount.Name);
}
Writer.WriteOptionalElementString("ram", "ProprietaryID", account.ID);
Writer.WriteOptionalElementString("ram", "ProprietaryID", creditorBankAccount.ID);
Writer.WriteEndElement(); // !PayeePartyCreditorFinancialAccount

Writer.WriteStartElement("ram", "PayeeSpecifiedCreditorFinancialInstitution");
Writer.WriteElementString("ram", "BICID", account.BIC);
Writer.WriteOptionalElementString("ram", "GermanBankleitzahlID", account.Bankleitzahl);
Writer.WriteOptionalElementString("ram", "Name", account.BankName);
Writer.WriteElementString("ram", "BICID", creditorBankAccount.BIC);
Writer.WriteOptionalElementString("ram", "GermanBankleitzahlID", creditorBankAccount.Bankleitzahl);
Writer.WriteOptionalElementString("ram", "Name", creditorBankAccount.BankName);
Writer.WriteEndElement(); // !PayeeSpecifiedCreditorFinancialInstitution
Writer.WriteEndElement(); // !SpecifiedTradeSettlementPaymentMeans
}

foreach (BankAccount account in this.Descriptor.DebitorBankAccounts)
foreach (BankAccount debitorBankAccount in this.Descriptor.GetDebitorFinancialAccounts())
{
Writer.WriteStartElement("ram", "SpecifiedTradeSettlementPaymentMeans");

Expand All @@ -301,14 +301,14 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFo
}

Writer.WriteStartElement("ram", "PayerPartyDebtorFinancialAccount");
Writer.WriteElementString("ram", "IBANID", account.IBAN);
Writer.WriteOptionalElementString("ram", "ProprietaryID", account.ID);
Writer.WriteElementString("ram", "IBANID", debitorBankAccount.IBAN);
Writer.WriteOptionalElementString("ram", "ProprietaryID", debitorBankAccount.ID);
Writer.WriteEndElement(); // !PayerPartyDebtorFinancialAccount

Writer.WriteStartElement("ram", "PayerSpecifiedDebtorFinancialInstitution");
Writer.WriteElementString("ram", "BICID", account.BIC);
Writer.WriteOptionalElementString("ram", "GermanBankleitzahlID", account.Bankleitzahl);
Writer.WriteOptionalElementString("ram", "Name", account.BankName);
Writer.WriteElementString("ram", "BICID", debitorBankAccount.BIC);
Writer.WriteOptionalElementString("ram", "GermanBankleitzahlID", debitorBankAccount.Bankleitzahl);
Writer.WriteOptionalElementString("ram", "Name", debitorBankAccount.BankName);
Writer.WriteEndElement(); // !PayerSpecifiedDebtorFinancialInstitution
Writer.WriteEndElement(); // !SpecifiedTradeSettlementPaymentMeans
}
Expand Down Expand Up @@ -352,7 +352,7 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFo
Writer.WriteEndElement();
}

foreach (ServiceCharge serviceCharge in this.Descriptor.ServiceCharges)
foreach (ServiceCharge serviceCharge in this.Descriptor.GetLogisticsServiceCharges())
{
Writer.WriteStartElement("ram", "SpecifiedLogisticsServiceCharge");
Writer.WriteOptionalElementString("ram", "Description", serviceCharge.Description, Profile.Comfort | Profile.Extended);
Expand Down Expand Up @@ -451,7 +451,7 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream, ZUGFeRDFo

Writer.WriteEndElement(); // !ram:ApplicableSupplyChainTradeSettlement

foreach (TradeLineItem tradeLineItem in this.Descriptor.TradeLineItems)
foreach (TradeLineItem tradeLineItem in this.Descriptor.GetTradeLineItems())
{
Writer.WriteStartElement("ram", "IncludedSupplyChainTradeLineItem");

Expand Down Expand Up @@ -693,7 +693,7 @@ internal override bool Validate(InvoiceDescriptor descriptor, bool throwExceptio

if (descriptor.Profile != Profile.Extended) // check tax types, only extended profile allows tax types other than vat
{
if (!descriptor.TradeLineItems.All(l => l.TaxType.Equals(TaxTypes.VAT) || l.TaxType.Equals(TaxTypes.Unknown)))
if (!descriptor.GetTradeLineItems().All(l => l.TaxType.Equals(TaxTypes.VAT) || l.TaxType.Equals(TaxTypes.Unknown)))
{
if (throwExceptions) { throw new UnsupportedException("Tax types other than VAT only possible with extended profile."); }
return false;
Expand Down Expand Up @@ -727,7 +727,7 @@ private void _writeElementWithAttribute(ProfileAwareXmlTextWriter writer, string

private void _writeOptionalTaxes(ProfileAwareXmlTextWriter writer)
{
foreach (Tax tax in this.Descriptor.Taxes)
foreach (Tax tax in this.Descriptor.GetApplicableTradeTaxes())
{
writer.WriteStartElement("ram", "ApplicableTradeTax");

Expand Down
Loading

0 comments on commit 76ef08a

Please sign in to comment.