Skip to content

Commit

Permalink
More optional value clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanstapel committed Mar 8, 2021
1 parent c1fac9d commit ba65461
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
14 changes: 7 additions & 7 deletions ZUGFeRD/InvoiceDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,12 @@ public TradeLineItem AddTradeLineItem(string name,
string description = null,
QuantityCodes unitCode = QuantityCodes.Unknown,
decimal? unitQuantity = null,
decimal grossUnitPrice = Decimal.MinValue,
decimal netUnitPrice = Decimal.MinValue,
decimal billedQuantity = Decimal.MinValue,
decimal? grossUnitPrice = null,
decimal? netUnitPrice = null,
decimal billedQuantity = 0,
TaxTypes taxType = TaxTypes.Unknown,
TaxCategoryCodes categoryCode = TaxCategoryCodes.Unknown,
decimal taxPercent = Decimal.MinValue,
decimal taxPercent = 0,
string comment = null,
GlobalID id = null,
string sellerAssignedID = "", string buyerAssignedID = "",
Expand Down Expand Up @@ -777,12 +777,12 @@ public TradeLineItem AddTradeLineItem(string lineID,
string description = null,
QuantityCodes unitCode = QuantityCodes.Unknown,
decimal? unitQuantity = null,
decimal grossUnitPrice = 0,
decimal netUnitPrice = 0,
decimal? grossUnitPrice = null,
decimal? netUnitPrice = null,
decimal billedQuantity = 0,
TaxTypes taxType = TaxTypes.Unknown,
TaxCategoryCodes categoryCode = TaxCategoryCodes.Unknown,
decimal taxPercent = Decimal.MinValue,
decimal taxPercent = 0,
string comment = null,
GlobalID id = null,
string sellerAssignedID = "", string buyerAssignedID = "",
Expand Down
4 changes: 2 additions & 2 deletions ZUGFeRD/InvoiceDescriptor1Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream)
{
_total = tradeLineItem.LineTotalAmount.Value;
}
else
else if (tradeLineItem.NetUnitPrice.HasValue)
{
_total = tradeLineItem.NetUnitPrice * tradeLineItem.BilledQuantity;
_total = tradeLineItem.NetUnitPrice.Value * tradeLineItem.BilledQuantity;
}

_writeElementWithAttribute(Writer, "ram:LineTotalAmount", "currencyID", this.Descriptor.Currency.EnumToString(), _formatDecimal(_total));
Expand Down
4 changes: 2 additions & 2 deletions ZUGFeRD/InvoiceDescriptor20Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream)
{
_total = tradeLineItem.LineTotalAmount.Value;
}
else
else if (tradeLineItem.NetUnitPrice.HasValue)
{
_total = tradeLineItem.NetUnitPrice * tradeLineItem.BilledQuantity;
_total = tradeLineItem.NetUnitPrice.Value * tradeLineItem.BilledQuantity;
}

_writeElementWithAttribute(Writer, "ram:LineTotalAmount", "currencyID", this.Descriptor.Currency.EnumToString(), _formatDecimal(_total));
Expand Down
4 changes: 2 additions & 2 deletions ZUGFeRD/InvoiceDescriptor21Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ public override void Save(InvoiceDescriptor descriptor, Stream stream)
{
_total = tradeLineItem.LineTotalAmount.Value;
}
else
else if (tradeLineItem.NetUnitPrice.HasValue)
{
_total = tradeLineItem.NetUnitPrice * tradeLineItem.BilledQuantity;
_total = tradeLineItem.NetUnitPrice.Value * tradeLineItem.BilledQuantity;
}

Writer.WriteStartElement("ram:LineTotalAmount", Profile.Basic | Profile.Comfort | Profile.Extended | Profile.XRechnung1 | Profile.XRechnung);
Expand Down
8 changes: 6 additions & 2 deletions ZUGFeRD/InvoiceValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ public static List<string> Validate(InvoiceDescriptor descriptor)
Dictionary<decimal, decimal> lineTotalPerTax = new Dictionary<decimal, decimal>();
foreach(TradeLineItem item in descriptor.TradeLineItems)
{
decimal _total = decimal.Multiply(item.NetUnitPrice, item.BilledQuantity);
lineTotal += _total;
decimal _total = 0m;
if (item.NetUnitPrice.HasValue)
{
_total = decimal.Multiply(item.NetUnitPrice.Value, item.BilledQuantity);
lineTotal += _total;
}

if (!lineTotalPerTax.ContainsKey(item.TaxPercent))
{
Expand Down
4 changes: 2 additions & 2 deletions ZUGFeRD/TradeLineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ public class TradeLineItem
/// <summary>
/// Netto Einzelpreis
/// </summary>
public decimal NetUnitPrice { get; set; }
public decimal? NetUnitPrice { get; set; }
/// <summary>
/// Brutto Einzelpreis
/// </summary>
public decimal GrossUnitPrice { get; set; }
public decimal? GrossUnitPrice { get; set; }
/// <summary>
/// Einheit der Preisbasismenge
/// </summary>
Expand Down

0 comments on commit ba65461

Please sign in to comment.