Skip to content

Commit

Permalink
better readability for profile awareness in party and specified legal…
Browse files Browse the repository at this point in the history
… organizations
  • Loading branch information
stephanstapel committed Nov 23, 2023
1 parent a781a41 commit 7c1a56c
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 60 deletions.
1 change: 1 addition & 0 deletions ZUGFeRD-Test/ZUGFeRD21Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ public void TestAdditionalReferencedDocument()
Assert.AreEqual(issueDateTime, loadedInvoice.AdditionalReferencedDocuments[0].IssueDateTime);
} // !TestAdditionalReferencedDocument()


[TestMethod]
public void TestPartyExtensions()
{
Expand Down
190 changes: 134 additions & 56 deletions ZUGFeRD/InvoiceDescriptor21Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,54 +1161,137 @@ private void _writeNotes(ProfileAwareXmlTextWriter writer, List<Note> notes)
}
} // !_writeNotes()


private void _writeOptionalLegalOrganization(ProfileAwareXmlTextWriter writer, string legalOrganizationTag, LegalOrganization legalOrganization, PartyTypes partyType = PartyTypes.Unknown)
{
if (legalOrganization != null)
if (legalOrganization == null)
{
return;
}

switch (partyType)
{
case PartyTypes.SellerTradeParty:
// all profiles
break;
case PartyTypes.BuyerTradeParty:
// all profiles
break;
case PartyTypes.ShipToTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.UltimateShipToTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.ShipFromTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.InvoiceeTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.PayeeTradeParty:
// all profiles
break;
case PartyTypes.SalesAgentTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.BuyerTaxRepresentativeTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.ProductEndUserTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.BuyerAgentTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.InvoicerTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
case PartyTypes.PayerTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; } // extended profile only
break;
default:
return;
}

writer.WriteStartElement(legalOrganizationTag, this.Descriptor.Profile);
if (legalOrganization.ID != null)
{
writer.WriteStartElement(legalOrganizationTag, this.Descriptor.Profile);
if (legalOrganization.ID != null)
if (!String.IsNullOrEmpty(legalOrganization.ID.ID) && !String.IsNullOrEmpty(legalOrganization.ID.SchemeID.EnumToString()))
{
if (!String.IsNullOrEmpty(legalOrganization.ID.ID) && !String.IsNullOrEmpty(legalOrganization.ID.SchemeID.EnumToString()))
{
writer.WriteStartElement("ram:ID");
writer.WriteAttributeString("schemeID", legalOrganization.ID.SchemeID.EnumToString());
writer.WriteValue(legalOrganization.ID.ID);
writer.WriteEndElement();
}
else
{
writer.WriteElementString("ram:ID", legalOrganization.ID.ID);
}
if (!String.IsNullOrEmpty(legalOrganization.TradingBusinessName))
writer.WriteStartElement("ram:ID");
writer.WriteAttributeString("schemeID", legalOrganization.ID.SchemeID.EnumToString());
writer.WriteValue(legalOrganization.ID.ID);
writer.WriteEndElement();
}
else
{
writer.WriteElementString("ram:ID", legalOrganization.ID.ID);
}
if (!String.IsNullOrEmpty(legalOrganization.TradingBusinessName))
{
// filter according to https://github.com/stephanstapel/ZUGFeRD-csharp/pull/221
if (((partyType == PartyTypes.SellerTradeParty) && (this.Descriptor.Profile != Profile.Minimum)) ||
((partyType == PartyTypes.PayeeTradeParty) && (this.Descriptor.Profile != Profile.Minimum)) ||
((partyType == PartyTypes.BuyerTradeParty) && (this.Descriptor.Profile == Profile.Comfort)) ||
((partyType == PartyTypes.BuyerTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
(this.Descriptor.Profile == Profile.Extended) /* remaining party types */
)
{
// filter according to https://github.com/stephanstapel/ZUGFeRD-csharp/pull/221
if (((partyType == PartyTypes.SellerTradeParty) && (this.Descriptor.Profile != Profile.Minimum)) ||
((partyType == PartyTypes.PayeeTradeParty) && (this.Descriptor.Profile != Profile.Minimum)) ||
((partyType == PartyTypes.BuyerTradeParty) && (this.Descriptor.Profile == Profile.Comfort)) ||
((partyType == PartyTypes.BuyerTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
(this.Descriptor.Profile == Profile.Extended) /* remaining party types */
)
{
writer.WriteElementString("ram:TradingBusinessName", legalOrganization.TradingBusinessName, this.Descriptor.Profile);
}
writer.WriteElementString("ram:TradingBusinessName", legalOrganization.TradingBusinessName, this.Descriptor.Profile);
}
}
writer.WriteEndElement();
}
}
writer.WriteEndElement();
} // !_writeOptionalLegalOrganization()


private void _writeOptionalParty(ProfileAwareXmlTextWriter writer, PartyTypes partyType, Party party, Contact contact = null, ElectronicAddress ElectronicAddress = null, List<TaxRegistration> taxRegistrations = null)
{
// filter according to https://github.com/stephanstapel/ZUGFeRD-csharp/pull/221
if ( ((partyType == PartyTypes.UltimateShipToTradeParty) && (this.Descriptor.Profile != Profile.Extended)) ||
((partyType == PartyTypes.ShipToTradeParty) && (this.Descriptor.Profile != Profile.Extended)) ||
((partyType == PartyTypes.ShipFromTradeParty) && (this.Descriptor.Profile != Profile.Extended)) ||
((partyType == PartyTypes.InvoiceeTradeParty) && (this.Descriptor.Profile != Profile.Extended)) ||
((partyType == PartyTypes.PayeeTradeParty) && (this.Descriptor.Profile == Profile.Minimum)) ||
((partyType == PartyTypes.PayerTradeParty) && (this.Descriptor.Profile != Profile.Extended))
)
switch (partyType)
{
return;
case PartyTypes.Unknown:
return;
case PartyTypes.SellerTradeParty:
break;
case PartyTypes.BuyerTradeParty:
break;
case PartyTypes.ShipToTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.UltimateShipToTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.ShipFromTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.InvoiceeTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.PayeeTradeParty:
if (this.Descriptor.Profile == Profile.Minimum) { return; } // party is written for all profiles but minimum
break;
case PartyTypes.SalesAgentTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.BuyerTaxRepresentativeTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.ProductEndUserTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.BuyerAgentTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.InvoicerTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
case PartyTypes.PayerTradeParty:
if (this.Descriptor.Profile != Profile.Extended) { return; }
break;
default:
return;
}

if (party != null)
Expand Down Expand Up @@ -1239,6 +1322,21 @@ private void _writeOptionalParty(ProfileAwareXmlTextWriter writer, PartyTypes pa
case PartyTypes.PayerTradeParty:
writer.WriteStartElement("ram:PayerTradeParty", this.Descriptor.Profile);
break;
case PartyTypes.SalesAgentTradeParty:
writer.WriteStartElement("ram:SalesAgentTradeParty", this.Descriptor.Profile);
break;
case PartyTypes.BuyerTaxRepresentativeTradeParty:
writer.WriteStartElement("ram:BuyerTaxRepresentativeTradeParty", this.Descriptor.Profile);
break;
case PartyTypes.ProductEndUserTradeParty:
writer.WriteStartElement("ram:ProductEndUserTradeParty", this.Descriptor.Profile);
break;
case PartyTypes.BuyerAgentTradeParty:
writer.WriteStartElement("ram:BuyerAgentTradeParty", this.Descriptor.Profile);
break;
case PartyTypes.InvoicerTradeParty:
writer.WriteStartElement("ram:InvoicerTradeParty", this.Descriptor.Profile);
break;
}

if (party.ID != null)
Expand Down Expand Up @@ -1269,27 +1367,7 @@ private void _writeOptionalParty(ProfileAwareXmlTextWriter writer, PartyTypes pa
writer.WriteElementString("ram:Name", party.Name);
}

if (party.SpecifiedLegalOrganization != null)
{
// filter according to https://github.com/stephanstapel/ZUGFeRD-csharp/pull/221
if (((partyType == PartyTypes.ShipToTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.ShipFromTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.SalesAgentTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.UltimateShipToTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.BuyerTaxRepresentativeTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.ProductEndUserTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.BuyerAgentTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.InvoicerTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.InvoiceeTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.PayerTradeParty) && (this.Descriptor.Profile == Profile.Extended)) ||
((partyType == PartyTypes.SellerTradeParty) /* all profiles */ ) ||
((partyType == PartyTypes.BuyerTradeParty) /* all profiles */ ) ||
((partyType == PartyTypes.PayeeTradeParty) /* all profiles */ )
)
{
_writeOptionalLegalOrganization(writer, "ram:SpecifiedLegalOrganization", party.SpecifiedLegalOrganization, partyType);
}
}
_writeOptionalLegalOrganization(writer, "ram:SpecifiedLegalOrganization", party.SpecifiedLegalOrganization, partyType);

if (contact != null)
{
Expand Down
8 changes: 4 additions & 4 deletions ZUGFeRD/ZUGFeRD.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;net480</TargetFrameworks>
<Version>12.2.0</Version>
<Version>12.3.0</Version>
<Authors>Stephan Stapel</Authors>
<Company>s2 industries</Company>
<Description>ZUGFeRD and it's successor Factur-X/ XRechnung are initiatives from German (respectively European) government to foster electronic invoices.
Expand All @@ -22,15 +22,15 @@ https://github.com/stephanstapel/ZUGFeRD-csharp</Description>
<PackageProjectUrl>https://github.com/stephanstapel/ZUGFeRD-csharp/</PackageProjectUrl>
<PackageTags>zugferd xml</PackageTags>
<Copyright>Stephan Stapel, s2 industries, 2023</Copyright>
<AssemblyVersion>12.2.0</AssemblyVersion>
<AssemblyVersion>12.3.0</AssemblyVersion>
<AssemblyTrademark>http://www.s2-industries.com</AssemblyTrademark>
<FileVersion>12.2.0.0</FileVersion>
<FileVersion>12.3.0.0</FileVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<AssemblyName>s2industries.ZUGFeRD</AssemblyName>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>ZUGFeRD.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageReleaseNotes>12.3.0: enhanced standard conformance for all party types</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>ZUGFeRD-csharp</PackageId>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down

0 comments on commit 7c1a56c

Please sign in to comment.