Skip to content

Commit

Permalink
Sum amounts are null by default
Browse files Browse the repository at this point in the history
closes #563
editorconfig naming fixes
  • Loading branch information
stephanstapel committed Jan 10, 2025
1 parent e9aa607 commit 516e7ea
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 59 deletions.
64 changes: 32 additions & 32 deletions ZUGFeRD/InvoiceDescriptor20Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public override InvoiceDescriptor Load(Stream stream)
foreach (XmlNode node in doc.SelectNodes("//rsm:ExchangedDocument/ram:IncludedNote", nsmgr))
{
string content = XmlUtils.NodeAsString(node, ".//ram:Content", nsmgr);
string _subjectCode = XmlUtils.NodeAsString(node, ".//ram:SubjectCode", nsmgr);
SubjectCodes subjectCode = default(SubjectCodes).FromString(_subjectCode);
string _contentCode = XmlUtils.NodeAsString(node, ".//ram:ContentCode", nsmgr);
ContentCodes contentCode = default(ContentCodes).FromString(_contentCode);
string subjectCodeAsString = XmlUtils.NodeAsString(node, ".//ram:SubjectCode", nsmgr);
SubjectCodes subjectCode = default(SubjectCodes).FromString(subjectCodeAsString);
string contentCodeAsString = XmlUtils.NodeAsString(node, ".//ram:ContentCode", nsmgr);
ContentCodes contentCode = default(ContentCodes).FromString(contentCodeAsString);
retval.AddNote(content, subjectCode, contentCode);
}

Expand Down Expand Up @@ -122,20 +122,20 @@ public override InvoiceDescriptor Load(Stream stream)
retval.ShipFrom = _nodeAsParty(doc.DocumentElement, "//ram:ApplicableHeaderTradeDelivery/ram:ShipFromTradeParty", nsmgr);
retval.ActualDeliveryDate = XmlUtils.NodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeDelivery/ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString", nsmgr);

string _deliveryNoteNo = XmlUtils.NodeAsString(doc.DocumentElement, "//ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:ID", nsmgr);
DateTime? _deliveryNoteDate = XmlUtils.NodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssueDateTime/udt:DateTimeString", nsmgr);
string deliveryNoteNo = XmlUtils.NodeAsString(doc.DocumentElement, "//ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:ID", nsmgr);
DateTime? deliveryNoteDate = XmlUtils.NodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssueDateTime/udt:DateTimeString", nsmgr);

if (!_deliveryNoteDate.HasValue)
if (!deliveryNoteDate.HasValue)
{
_deliveryNoteDate = XmlUtils.NodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssueDateTime", nsmgr);
deliveryNoteDate = XmlUtils.NodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssueDateTime", nsmgr);
}

if (_deliveryNoteDate.HasValue || !String.IsNullOrWhiteSpace(_deliveryNoteNo))
if (deliveryNoteDate.HasValue || !String.IsNullOrWhiteSpace(deliveryNoteNo))
{
retval.DeliveryNoteReferencedDocument = new DeliveryNoteReferencedDocument()
{
ID = _deliveryNoteNo,
IssueDateTime = _deliveryNoteDate
ID = deliveryNoteNo,
IssueDateTime = deliveryNoteDate
};
}

Expand All @@ -147,7 +147,7 @@ public override InvoiceDescriptor Load(Stream stream)
retval.SellerReferenceNo = XmlUtils.NodeAsString(doc.DocumentElement, "//ram:ApplicableHeaderTradeSettlement/ram:InvoiceIssuerReference", nsmgr);

// TODO: Multiple SpecifiedTradeSettlementPaymentMeans can exist for each account/institution (with different SEPA?)
PaymentMeans _tempPaymentMeans = new PaymentMeans()
PaymentMeans tempPaymentMeans = new PaymentMeans()
{
TypeCode = default(PaymentMeansTypeCodes).FromString(XmlUtils.NodeAsString(doc.DocumentElement, "//ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:TypeCode", nsmgr)),
Information = XmlUtils.NodeAsString(doc.DocumentElement, "//ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:Information", nsmgr),
Expand All @@ -159,14 +159,14 @@ public override InvoiceDescriptor Load(Stream stream)

if (!string.IsNullOrWhiteSpace(financialCardId) || !string.IsNullOrWhiteSpace(financialCardCardholderName))
{
_tempPaymentMeans.FinancialCard = new FinancialCard()
tempPaymentMeans.FinancialCard = new FinancialCard()
{
Id = financialCardId,
CardholderName = financialCardCardholderName
};
}

retval.PaymentMeans = _tempPaymentMeans;
retval.PaymentMeans = tempPaymentMeans;

retval.BillingPeriodStart = XmlUtils.NodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeSettlement/ram:BillingSpecifiedPeriod/ram:StartDateTime", nsmgr);
retval.BillingPeriodEnd = XmlUtils.NodeAsDateTime(doc.DocumentElement, "//ram:ApplicableHeaderTradeSettlement/ram:BillingSpecifiedPeriod/ram:EndDateTime", nsmgr);
Expand All @@ -178,7 +178,7 @@ public override InvoiceDescriptor Load(Stream stream)
{
for (int i = 0; i < creditorFinancialAccountNodes.Count; i++)
{
BankAccount _account = new BankAccount()
BankAccount account = new BankAccount()
{
ID = XmlUtils.NodeAsString(creditorFinancialAccountNodes[0], ".//ram:ProprietaryID", nsmgr),
IBAN = XmlUtils.NodeAsString(creditorFinancialAccountNodes[0], ".//ram:IBANID", nsmgr),
Expand All @@ -188,7 +188,7 @@ public override InvoiceDescriptor Load(Stream stream)
BankName = XmlUtils.NodeAsString(creditorFinancialInstitutions[0], ".//ram:Name", nsmgr),
};

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

Expand All @@ -203,7 +203,7 @@ public override InvoiceDescriptor Load(Stream stream)
continue;
}

var _account = new BankAccount()
var account = new BankAccount()
{
ID = XmlUtils.NodeAsString(payerPartyDebtorFinancialAccountNode, ".//ram:ProprietaryID", nsmgr),
IBAN = XmlUtils.NodeAsString(payerPartyDebtorFinancialAccountNode, ".//ram:IBANID", nsmgr),
Expand All @@ -213,9 +213,9 @@ public override InvoiceDescriptor Load(Stream stream)

var payerSpecifiedDebtorFinancialInstitutionNode = specifiedTradeSettlementPaymentMeansNode.SelectSingleNode("ram:PayerSpecifiedDebtorFinancialInstitution", nsmgr);
if (payerSpecifiedDebtorFinancialInstitutionNode != null)
_account.BIC = XmlUtils.NodeAsString(payerPartyDebtorFinancialAccountNode, ".//ram:BICID", nsmgr);
account.BIC = XmlUtils.NodeAsString(payerPartyDebtorFinancialAccountNode, ".//ram:BICID", nsmgr);

retval.DebitorBankAccounts.Add(_account);
retval.DebitorBankAccounts.Add(account);
}

//XmlNodeList debitorFinancialAccountNodes = doc.SelectNodes("//ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeSettlementPaymentMeans/ram:PayerPartyDebtorFinancialAccount", nsmgr);
Expand All @@ -225,7 +225,7 @@ public override InvoiceDescriptor Load(Stream stream)
//{
// for (int i = 0; i < debitorFinancialAccountNodes.Count; i++)
// {
// BankAccount _account = new BankAccount()
// BankAccount account = new BankAccount()
// {
// ID = XmlUtils.NodeAsString(debitorFinancialAccountNodes[0], ".//ram:ProprietaryID", nsmgr),
// IBAN = XmlUtils.NodeAsString(debitorFinancialAccountNodes[0], ".//ram:IBANID", nsmgr),
Expand All @@ -234,7 +234,7 @@ public override InvoiceDescriptor Load(Stream stream)
// BankName = XmlUtils.NodeAsString(debitorFinancialInstitutions[0], ".//ram:Name", nsmgr),
// };

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

Expand Down Expand Up @@ -292,15 +292,15 @@ public override InvoiceDescriptor Load(Stream stream)
discountAmount ?? penaltyAmount);
}

retval.LineTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:LineTotalAmount", nsmgr, 0).Value;
retval.LineTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:LineTotalAmount", nsmgr, null).Value;
retval.ChargeTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:ChargeTotalAmount", nsmgr, null);
retval.AllowanceTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:AllowanceTotalAmount", nsmgr, null);
retval.TaxBasisAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxBasisTotalAmount", nsmgr, null);
retval.TaxTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount", nsmgr, 0).Value;
retval.GrandTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:GrandTotalAmount", nsmgr, 0).Value;
retval.RoundingAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:RoundingAmount", nsmgr, 0).Value;
retval.TaxTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TaxTotalAmount", nsmgr, null).Value;
retval.GrandTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:GrandTotalAmount", nsmgr, null).Value;
retval.RoundingAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:RoundingAmount", nsmgr, null).Value;
retval.TotalPrepaidAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:TotalPrepaidAmount", nsmgr, null);
retval.DuePayableAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:DuePayableAmount", nsmgr, 0).Value;
retval.DuePayableAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementHeaderMonetarySummation/ram:DuePayableAmount", nsmgr, null).Value;

// in this version we should only have on invoice referenced document but nevertheless...
foreach (XmlNode invoiceReferencedDocumentNodes in doc.DocumentElement.SelectNodes("//ram:ApplicableHeaderTradeSettlement/ram:InvoiceReferencedDocument", nsmgr))
Expand Down Expand Up @@ -366,12 +366,12 @@ private static TradeLineItem _parseTradeLineItem(XmlNode tradeLineItem, XmlNames
return null;
}

string _lineId = XmlUtils.NodeAsString(tradeLineItem, ".//ram:AssociatedDocumentLineDocument/ram:LineID", nsmgr, String.Empty);
string lineId = XmlUtils.NodeAsString(tradeLineItem, ".//ram:AssociatedDocumentLineDocument/ram:LineID", nsmgr, String.Empty);

LineStatusCodes? _lineStatusCode = default(LineStatusCodes).FromString(XmlUtils.NodeAsString(tradeLineItem, ".//ram:AssociatedDocumentLineDocument/ram:LineStatusCode", nsmgr, null));
LineStatusReasonCodes? _lineStatusReasonCode = default(LineStatusReasonCodes).FromString(XmlUtils.NodeAsString(tradeLineItem, ".//ram:AssociatedDocumentLineDocument/ram:LineStatusReasonCode", nsmgr, null));
LineStatusCodes? lineStatusCode = default(LineStatusCodes).FromString(XmlUtils.NodeAsString(tradeLineItem, ".//ram:AssociatedDocumentLineDocument/ram:LineStatusCode", nsmgr, null));
LineStatusReasonCodes? lineStatusReasonCode = default(LineStatusReasonCodes).FromString(XmlUtils.NodeAsString(tradeLineItem, ".//ram:AssociatedDocumentLineDocument/ram:LineStatusReasonCode", nsmgr, null));

TradeLineItem item = new TradeLineItem(_lineId)
TradeLineItem item = new TradeLineItem(lineId)
{
GlobalID = new GlobalID(default(GlobalIDSchemeIdentifiers).FromString(XmlUtils.NodeAsString(tradeLineItem, ".//ram:SpecifiedTradeProduct/ram:GlobalID/@schemeID", nsmgr)),
XmlUtils.NodeAsString(tradeLineItem, ".//ram:SpecifiedTradeProduct/ram:GlobalID", nsmgr)),
Expand All @@ -392,9 +392,9 @@ private static TradeLineItem _parseTradeLineItem(XmlNode tradeLineItem, XmlNames
BillingPeriodEnd = XmlUtils.NodeAsDateTime(tradeLineItem, ".//ram:BillingSpecifiedPeriod/ram:EndDateTime/udt:DateTimeString", nsmgr),
};

if (_lineStatusCode.HasValue && _lineStatusReasonCode.HasValue)
if (lineStatusCode.HasValue && lineStatusReasonCode.HasValue)
{
item.SetLineStatus(_lineStatusCode.Value, _lineStatusReasonCode.Value);
item.SetLineStatus(lineStatusCode.Value, lineStatusReasonCode.Value);
}

if (tradeLineItem.SelectNodes(".//ram:SpecifiedTradeProduct/ram:ApplicableProductCharacteristic", nsmgr) != null)
Expand Down
Loading

0 comments on commit 516e7ea

Please sign in to comment.