Skip to content

Commit

Permalink
SEPA addition
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanstapel committed Apr 11, 2017
1 parent fc7e507 commit d400afe
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
1 change: 1 addition & 0 deletions ZUGFeRD/InvoiceDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class InvoiceDescriptor
public List<TradeAllowanceCharge> TradeAllowanceCharges { get; set; }
public PaymentTerms PaymentTerms { get; set; }
public List<BankAccount> CreditorBankAccounts { get; set; }
public List<BankAccount> DebitorBankAccounts { get; set; }
public PaymentMeans PaymentMeans { get; set; }


Expand Down
42 changes: 32 additions & 10 deletions ZUGFeRD/InvoiceDescriptorReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,52 @@ public static InvoiceDescriptor Load(Stream stream)
PaymentMeans _tempPaymentMeans = new PaymentMeans()
{
TypeCode = default(PaymentMeansTypeCodes).FromString(_nodeAsString(doc.DocumentElement, "//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:TypeCode", nsmgr)),
Information = _nodeAsString(doc.DocumentElement, "//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:Information", nsmgr)
Information = _nodeAsString(doc.DocumentElement, "//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:Information", nsmgr),
SEPACreditorIdentifier = _nodeAsString(doc.DocumentElement, "//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:ID", nsmgr),
SEPAMandateReference = _nodeAsString(doc.DocumentElement, "//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:ID/@schemaAgencyID", nsmgr)
};
retval.PaymentMeans = _tempPaymentMeans;

XmlNodeList financialAccountNodes = doc.SelectNodes("//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeePartyCreditorFinancialAccount", nsmgr);
XmlNodeList financialInstitutions = doc.SelectNodes("//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeeSpecifiedCreditorFinancialInstitution", nsmgr);
XmlNodeList creditorFinancialAccountNodes = doc.SelectNodes("//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeePartyCreditorFinancialAccount", nsmgr);
XmlNodeList creditorFinancialInstitutions = doc.SelectNodes("//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayeeSpecifiedCreditorFinancialInstitution", nsmgr);

if (financialAccountNodes.Count == financialInstitutions.Count)
if (creditorFinancialAccountNodes.Count == creditorFinancialInstitutions.Count)
{
for (int i = 0; i < financialAccountNodes.Count; i++)
for (int i = 0; i < creditorFinancialAccountNodes.Count; i++)
{
BankAccount _account = new BankAccount()
{
ID = _nodeAsString(financialAccountNodes[0], ".//ram:ProprietaryID", nsmgr),
IBAN = _nodeAsString(financialAccountNodes[0], ".//ram:IBANID", nsmgr),
BIC = _nodeAsString(financialInstitutions[0], ".//ram:BICID", nsmgr),
Bankleitzahl = _nodeAsString(financialInstitutions[0], ".//ram:GermanBankleitzahlID", nsmgr),
BankName = _nodeAsString(financialInstitutions[0], ".//ram:Name", nsmgr),
ID = _nodeAsString(creditorFinancialAccountNodes[0], ".//ram:ProprietaryID", nsmgr),
IBAN = _nodeAsString(creditorFinancialAccountNodes[0], ".//ram:IBANID", nsmgr),
BIC = _nodeAsString(creditorFinancialInstitutions[0], ".//ram:BICID", nsmgr),
Bankleitzahl = _nodeAsString(creditorFinancialInstitutions[0], ".//ram:GermanBankleitzahlID", nsmgr),
BankName = _nodeAsString(creditorFinancialInstitutions[0], ".//ram:AccountName", nsmgr),
};

retval.CreditorBankAccounts.Add(_account);
} // !for(i)
}

XmlNodeList debitorFinancialAccountNodes = doc.SelectNodes("//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayerPartyDebtorFinancialAccount", nsmgr);
XmlNodeList debitorFinancialInstitutions = doc.SelectNodes("//ram:ApplicableSupplyChainTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayerSpecifiedDebtorFinancialInstitution", nsmgr);

if (debitorFinancialAccountNodes.Count == debitorFinancialInstitutions.Count)
{
for (int i = 0; i < debitorFinancialAccountNodes.Count; i++)
{
BankAccount _account = new BankAccount()
{
ID = _nodeAsString(debitorFinancialAccountNodes[0], ".//ram:ProprietaryID", nsmgr),
IBAN = _nodeAsString(debitorFinancialAccountNodes[0], ".//ram:IBANID", nsmgr),
BIC = _nodeAsString(debitorFinancialInstitutions[0], ".//ram:BICID", nsmgr),
Bankleitzahl = _nodeAsString(debitorFinancialInstitutions[0], ".//ram:GermanBankleitzahlID", nsmgr),
BankName = _nodeAsString(debitorFinancialInstitutions[0], ".//ram:Name", nsmgr),
};

retval.DebitorBankAccounts.Add(_account);
} // !for(i)
}

foreach (XmlNode node in doc.SelectNodes("//ram:ApplicableSupplyChainTradeSettlement/ram:ApplicableTradeTax", nsmgr))
{
retval.AddApplicableTradeTax(_nodeAsDecimal(node, ".//ram:BasisAmount", nsmgr, 0).Value,
Expand Down
35 changes: 34 additions & 1 deletion ZUGFeRD/InvoiceDescriptorWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ public void Save(InvoiceDescriptor descriptor, Stream stream)
{
Writer.WriteElementString("ram:TypeCode", this.Descriptor.PaymentMeans.TypeCode.EnumToString());
Writer.WriteElementString("ram:Information", this.Descriptor.PaymentMeans.Information);

if (!String.IsNullOrEmpty(this.Descriptor.PaymentMeans.SEPACreditorIdentifier) && !String.IsNullOrEmpty(this.Descriptor.PaymentMeans.SEPAMandateReference))
{
Writer.WriteStartElement("ram:ID");
Writer.WriteAttributeString("schemaAgencyID", this.Descriptor.PaymentMeans.SEPACreditorIdentifier);
Writer.WriteValue(this.Descriptor.PaymentMeans.SEPAMandateReference);
Writer.WriteEndElement(); // !ram:ID
}
}

foreach (BankAccount account in this.Descriptor.CreditorBankAccounts)
Expand All @@ -202,11 +210,36 @@ public void Save(InvoiceDescriptor descriptor, Stream stream)

if (!String.IsNullOrEmpty(account.BankName))
{
Writer.WriteElementString("ram:Name", account.BankName);
Writer.WriteElementString("ram:AccountName", account.BankName);
}
Writer.WriteEndElement(); // !PayeeSpecifiedCreditorFinancialInstitution
}

foreach (BankAccount account in this.Descriptor.DebitorBankAccounts)
{
Writer.WriteStartElement("ram:PayerPartyDebtorFinancialAccount");
Writer.WriteElementString("ram:IBANID", account.IBAN);
if (!String.IsNullOrEmpty(account.ID))
{
Writer.WriteElementString("ram:ProprietaryID", account.ID);
}
Writer.WriteEndElement(); // !PayerPartyDebtorFinancialAccount

Writer.WriteStartElement("ram:PayerSpecifiedDebtorFinancialInstitution");
Writer.WriteElementString("ram:BICID", account.BIC);

if (!String.IsNullOrEmpty(account.Bankleitzahl))
{
Writer.WriteElementString("ram:GermanBankleitzahlID", account.Bankleitzahl);
}

if (!String.IsNullOrEmpty(account.BankName))
{
Writer.WriteElementString("ram:Name", account.BankName);
}
Writer.WriteEndElement(); // !PayerSpecifiedDebtorFinancialInstitution
}

Writer.WriteEndElement(); // !SpecifiedTradeSettlementPaymentMeans
}

Expand Down
16 changes: 14 additions & 2 deletions ZUGFeRD/PaymentMeans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ public class PaymentMeans
{
public PaymentMeansTypeCodes TypeCode { get; set; }
public string Information { get; set; }
public string ID { get; set; }
public string schemeAgencyID { get; set; }

/// <summary>
/// Gläubiger-Identifikationsnummer
///
/// https://de.wikipedia.org/wiki/Gl%C3%A4ubiger-Identifikationsnummer
/// </summary>
public string SEPACreditorIdentifier { get; set; }

/// <summary>
/// Mandatsreferenz
///
/// https://de.wikipedia.org/wiki/Mandatsreferenz
/// </summary>
public string SEPAMandateReference { get; set; }
}
}

0 comments on commit d400afe

Please sign in to comment.