Пример #1
0
        } // !AddTradeLineCommentItem()

        /// <summary>
        /// Adds a new comment as a dedicated line of the invoice.
        ///
        /// The line id is passed as a parameter
        /// </summary>
        /// <param name="lineID"></param>
        /// <param name="comment"></param>
        public void AddTradeLineCommentItem(string lineID, string comment)
        {
            if (String.IsNullOrEmpty(lineID))
            {
                throw new ArgumentException("LineID cannot be Null or Empty");
            }
            else
            {
                if (this.TradeLineItems.Any(p => p.AssociatedDocument.LineID.ToLower() == lineID.ToLower()))
                {
                    throw new ArgumentException("LineID must be unique");
                }
            }

            TradeLineItem item = new TradeLineItem()
            {
                LineID             = lineID,
                AssociatedDocument = new ZUGFeRD.AssociatedDocument(lineID),
                GrossUnitPrice     = 0m,
                NetUnitPrice       = 0m,
                BilledQuantity     = 0m,
                TaxCategoryCode    = TaxCategoryCodes.O
            };

            item.AssociatedDocument.Notes.Add(new Note(
                                                  content: comment,
                                                  subjectCode: SubjectCodes.Unknown,
                                                  contentCode: ContentCodes.Unknown
                                                  ));

            this.TradeLineItems.Add(item);
        } // !AddTradeLineCommentItem()
        } // !Save()

        public void addTradeLineCommentItem(string comment)
        {
            TradeLineItem item = new TradeLineItem()
            {
                AssociatedDocument = new ZUGFeRD.AssociatedDocument()
            };

            item.AssociatedDocument.Notes.Add(new Note(
                                                  content: comment,
                                                  subjectCode: SubjectCodes.Unknown,
                                                  contentCode: ContentCodes.Unknown
                                                  ));

            this.TradeLineItems.Add(item);
        } // !addTradeLineCommentItem()
Пример #3
0
        } // !Save()

        public void addTradeLineCommentItem(string comment)
        {
            TradeLineItem item = new TradeLineItem()
            {
                AssociatedDocument = new ZUGFeRD.AssociatedDocument(),
                GrossUnitPrice     = 0m,
                NetUnitPrice       = 0m,
                BilledQuantity     = 0m
            };

            item.AssociatedDocument.Notes.Add(new Note(
                                                  content: comment,
                                                  subjectCode: SubjectCodes.Unknown,
                                                  contentCode: ContentCodes.Unknown
                                                  ));

            this.TradeLineItems.Add(item);
        } // !addTradeLineCommentItem()
Пример #4
0
        } // !Save()

        public void addTradeLineCommentItem(string comment)
        {
            TradeLineItem item = new TradeLineItem()
            {
                AssociatedDocument = new ZUGFeRD.AssociatedDocument(),
                GrossUnitPrice     = 0m,
                NetUnitPrice       = 0m,
                BilledQuantity     = 0m,
                TaxCategoryCode    = TaxCategoryCodes.O
            };

            int?_lineID = null;

            if (this.TradeLineItems.Count > 0)
            {
                _lineID = this.TradeLineItems.Last().AssociatedDocument.LineID;
            }

            if (_lineID.HasValue)
            {
                _lineID = _lineID.Value + 1;
            }
            else
            {
                _lineID = 1;
            }

            item.AssociatedDocument = new ZUGFeRD.AssociatedDocument(_lineID);

            item.AssociatedDocument.Notes.Add(new Note(
                                                  content: comment,
                                                  subjectCode: SubjectCodes.Unknown,
                                                  contentCode: ContentCodes.Unknown
                                                  ));

            this.TradeLineItems.Add(item);
        } // !addTradeLineCommentItem()
Пример #5
0
        } // !addTradeLineCommentItem()

        /// <summary>
        /// @todo Rabatt ergänzen:
        /// <ram:AppliedTradeAllowanceCharge>
        ///                 <ram:ChargeIndicator><udt:Indicator>false</udt:Indicator></ram:ChargeIndicator>
        ///                 <ram:CalculationPercent>2.00</ram:CalculationPercent>
        ///                 <ram:BasisAmount currencyID = "EUR" > 1.5000 </ ram:BasisAmount>
        ///                 <ram:ActualAmount currencyID = "EUR" > 0.0300 </ ram:ActualAmount>
        ///                 <ram:Reason>Artikelrabatt 1</ram:Reason>
        ///             </ram:AppliedTradeAllowanceCharge>
        /// </summary>
        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,
                                              TaxTypes taxType              = TaxTypes.Unknown,
                                              TaxCategoryCodes categoryCode = TaxCategoryCodes.Unknown,
                                              decimal taxPercent            = Decimal.MinValue,
                                              string comment          = null,
                                              GlobalID id             = null,
                                              string sellerAssignedID = "", string buyerAssignedID    = "",
                                              string deliveryNoteID   = "", DateTime?deliveryNoteDate = null,
                                              string buyerOrderID     = "", DateTime?buyerOrderDate   = null)
        {
            TradeLineItem newItem = new TradeLineItem()
            {
                GlobalID         = id,
                SellerAssignedID = sellerAssignedID,
                BuyerAssignedID  = buyerAssignedID,
                Name             = name,
                Description      = description,
                UnitCode         = unitCode,
                UnitQuantity     = unitQuantity,
                GrossUnitPrice   = grossUnitPrice,
                NetUnitPrice     = netUnitPrice,
                BilledQuantity   = billedQuantity,
                TaxType          = taxType,
                TaxCategoryCode  = categoryCode,
                TaxPercent       = taxPercent,
                LineTotalAmount  = netUnitPrice * billedQuantity
            };

            int?_lineID = null;

            if (this.TradeLineItems.Count > 0)
            {
                _lineID = this.TradeLineItems.Last().AssociatedDocument.LineID;
            }

            if (_lineID.HasValue)
            {
                _lineID = _lineID.Value + 1;
            }
            else
            {
                _lineID = 1;
            }

            newItem.AssociatedDocument = new ZUGFeRD.AssociatedDocument(_lineID);
            if (!String.IsNullOrEmpty(comment))
            {
                newItem.AssociatedDocument.Notes.Add(new Note(comment, SubjectCodes.Unknown, ContentCodes.Unknown));
            }

            if (!String.IsNullOrEmpty(deliveryNoteID) || deliveryNoteDate.HasValue)
            {
                newItem.setDeliveryNoteReferencedDocument(deliveryNoteID, deliveryNoteDate);
            }

            if (!String.IsNullOrEmpty(buyerOrderID) || buyerOrderDate.HasValue)
            {
                newItem.setOrderReferencedDocument(buyerOrderID, buyerOrderDate);
            }

            this.TradeLineItems.Add(newItem);
            return(newItem);
        } // !addTradeLineItem()
Пример #6
0
        } // !IsReadableByThisReaderVersion()

        private static TradeLineItem _parseTradeLineItem(XmlNode tradeLineItem, XmlNamespaceManager nsmgr = null)
        {
            if (tradeLineItem == null)
            {
                return(null);
            }

            TradeLineItem item = new TradeLineItem()
            {
                GlobalID = new GlobalID(_nodeAsString(tradeLineItem, ".//ram:SpecifiedTradeProduct/ram:GlobalID/@schemeID", nsmgr),
                                        _nodeAsString(tradeLineItem, ".//ram:SpecifiedTradeProduct/ram:GlobalID", nsmgr)),
                SellerAssignedID = _nodeAsString(tradeLineItem, ".//ram:SpecifiedTradeProduct/ram:SellerAssignedID", nsmgr),
                BuyerAssignedID  = _nodeAsString(tradeLineItem, ".//ram:SpecifiedTradeProduct/ram:BuyerAssignedID", nsmgr),
                Name             = _nodeAsString(tradeLineItem, ".//ram:SpecifiedTradeProduct/ram:Name", nsmgr),
                Description      = _nodeAsString(tradeLineItem, ".//ram:SpecifiedTradeProduct/ram:Description", nsmgr),
                UnitQuantity     = _nodeAsDecimal(tradeLineItem, ".//ram:BasisQuantity", nsmgr, 1),
                BilledQuantity   = _nodeAsDecimal(tradeLineItem, ".//ram:BilledQuantity", nsmgr, 0).Value,
                LineTotalAmount  = _nodeAsDecimal(tradeLineItem, ".//ram:LineTotalAmount", nsmgr, 0),
                TaxCategoryCode  = default(TaxCategoryCodes).FromString(_nodeAsString(tradeLineItem, ".//ram:ApplicableTradeTax/ram:CategoryCode", nsmgr)),
                TaxType          = default(TaxTypes).FromString(_nodeAsString(tradeLineItem, ".//ram:ApplicableTradeTax/ram:TypeCode", nsmgr)),
                TaxPercent       = _nodeAsDecimal(tradeLineItem, ".//ram:ApplicableTradeTax/ram:RateApplicablePercent", nsmgr, 0).Value,
                NetUnitPrice     = _nodeAsDecimal(tradeLineItem, ".//ram:NetPriceProductTradePrice/ram:ChargeAmount", nsmgr, 0).Value,
                GrossUnitPrice   = _nodeAsDecimal(tradeLineItem, ".//ram:GrossPriceProductTradePrice/ram:ChargeAmount", nsmgr, 0).Value,
                UnitCode         = default(QuantityCodes).FromString(_nodeAsString(tradeLineItem, ".//ram:BasisQuantity/@unitCode", nsmgr))
            };


            if (tradeLineItem.SelectSingleNode(".//ram:SpecifiedLineTradeAgreement/ram:BuyerOrderReferencedDocument", nsmgr) != null)
            {
                item.BuyerOrderReferencedDocument = new BuyerOrderReferencedDocument()
                {
                    ID            = _nodeAsString(tradeLineItem, ".//ram:SpecifiedLineTradeAgreement/ram:BuyerOrderReferencedDocument/ram:IssuerAssignedID", nsmgr),
                    IssueDateTime = _nodeAsDateTime(tradeLineItem, ".//ram:SpecifiedLineTradeAgreement/ram:BuyerOrderReferencedDocument/ram:IssueDateTime/qdt:DateTimeString", nsmgr)
                };
            }

            if (tradeLineItem.SelectSingleNode(".//ram:SpecifiedLineTradeAgreement/ram:ContractReferencedDocument", nsmgr) != null)
            {
                item.ContractReferencedDocument = new ContractReferencedDocument()
                {
                    ID            = _nodeAsString(tradeLineItem, ".//ram:SpecifiedLineTradeAgreement/ram:ContractReferencedDocument/ram:IssuerAssignedID", nsmgr),
                    IssueDateTime = _nodeAsDateTime(tradeLineItem, ".//ram:SpecifiedLineTradeAgreement/ram:ContractReferencedDocument/ram:IssueDateTime/qdt:DateTimeString", nsmgr)
                };
            }


            if (tradeLineItem.SelectSingleNode(".//ram:AssociatedDocumentLineDocument", nsmgr) != null)
            {
                item.AssociatedDocument = new AssociatedDocument()
                {
                    LineID = _nodeAsInt(tradeLineItem, ".//ram:AssociatedDocumentLineDocument/ram:LineID", nsmgr, Int32.MaxValue)
                };

                XmlNodeList noteNodes = tradeLineItem.SelectNodes(".//ram:AssociatedDocumentLineDocument/ram:IncludedNote", nsmgr);
                foreach (XmlNode noteNode in noteNodes)
                {
                    item.AssociatedDocument.Notes.Add(new Note(
                                                          content: _nodeAsString(noteNode, ".//ram:Content", nsmgr),
                                                          subjectCode: default(SubjectCodes).FromString(_nodeAsString(noteNode, ".//ram:SubjectCode", nsmgr)),
                                                          contentCode: ContentCodes.Unknown
                                                          ));
                }

                if (item.AssociatedDocument.LineID == Int32.MaxValue) // a bit dirty, but works for now
                {
                    item.AssociatedDocument.LineID = null;
                }
            }

            XmlNodeList appliedTradeAllowanceChargeNodes = tradeLineItem.SelectNodes(".//ram:SpecifiedSupplyChainTradeAgreement/ram:GrossPriceProductTradePrice/ram:AppliedTradeAllowanceCharge", nsmgr);

            foreach (XmlNode appliedTradeAllowanceChargeNode in appliedTradeAllowanceChargeNodes)
            {
                bool    chargeIndicator      = _nodeAsBool(appliedTradeAllowanceChargeNode, "./ram:ChargeIndicator/udt:Indicator", nsmgr);
                decimal basisAmount          = _nodeAsDecimal(appliedTradeAllowanceChargeNode, "./ram:BasisAmount", nsmgr, 0).Value;
                string  basisAmountCurrency  = _nodeAsString(appliedTradeAllowanceChargeNode, "./ram:BasisAmount/@currencyID", nsmgr);
                decimal actualAmount         = _nodeAsDecimal(appliedTradeAllowanceChargeNode, "./ram:ActualAmount", nsmgr, 0).Value;
                string  actualAmountCurrency = _nodeAsString(appliedTradeAllowanceChargeNode, "./ram:ActualAmount/@currencyID", nsmgr);
                string  reason = _nodeAsString(appliedTradeAllowanceChargeNode, "./ram:Reason", nsmgr);

                item.AddTradeAllowanceCharge(!chargeIndicator, // wichtig: das not (!) beachten
                                             default(CurrencyCodes).FromString(basisAmountCurrency),
                                             basisAmount,
                                             actualAmount,
                                             reason);
            }

            if (item.UnitCode == QuantityCodes.Unknown)
            {
                // UnitCode alternativ aus BilledQuantity extrahieren
                item.UnitCode = default(QuantityCodes).FromString(_nodeAsString(tradeLineItem, ".//ram:BilledQuantity/@unitCode", nsmgr));
            }

            if (tradeLineItem.SelectSingleNode(".//ram:SpecifiedSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:ID", nsmgr) != null)
            {
                item.BuyerOrderReferencedDocument = new BuyerOrderReferencedDocument()
                {
                    ID            = _nodeAsString(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:ID", nsmgr),
                    IssueDateTime = _nodeAsDateTime(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeAgreement/ram:BuyerOrderReferencedDocument/ram:IssueDateTime", nsmgr),
                };
            }

            if (tradeLineItem.SelectSingleNode(".//ram:SpecifiedSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssuerAssignedID", nsmgr) != null)
            {
                item.DeliveryNoteReferencedDocument = new DeliveryNoteReferencedDocument()
                {
                    ID            = _nodeAsString(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssuerAssignedID", nsmgr),
                    IssueDateTime = _nodeAsDateTime(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeDelivery/ram:DeliveryNoteReferencedDocument/ram:IssueDateTime/udt:DateTimeString", nsmgr),
                };
            }

            if (tradeLineItem.SelectSingleNode(".//ram:SpecifiedSupplyChainTradeDelivery/ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime", nsmgr) != null)
            {
                item.ActualDeliveryDate = _nodeAsDateTime(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeDelivery/ram:ActualDeliverySupplyChainEvent/ram:OccurrenceDateTime/udt:DateTimeString", nsmgr);
            }

            if (tradeLineItem.SelectSingleNode(".//ram:SpecifiedSupplyChainTradeAgreement/ram:ContractReferencedDocument/ram:IssuerAssignedID", nsmgr) != null)
            {
                item.ContractReferencedDocument = new ContractReferencedDocument()
                {
                    ID            = _nodeAsString(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeAgreement/ram:ContractReferencedDocument/ram:IssuerAssignedID", nsmgr),
                    IssueDateTime = _nodeAsDateTime(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeAgreement/ram:ContractReferencedDocument/ram:IssueDateTime/udt:DateTimeString", nsmgr),
                };
            }

            XmlNodeList referenceNodes = tradeLineItem.SelectNodes(".//ram:SpecifiedSupplyChainTradeAgreement/ram:AdditionalReferencedDocument", nsmgr);

            foreach (XmlNode referenceNode in referenceNodes)
            {
                string _code = _nodeAsString(referenceNode, "ram:ReferenceTypeCode", nsmgr);

                item.AddAdditionalReferencedDocument(
                    id: _nodeAsString(referenceNode, "ram:IssuerAssignedID", nsmgr),
                    date: _nodeAsDateTime(referenceNode, "ram:IssueDateTime/udt:DateTimeString", nsmgr),
                    code: default(ReferenceTypeCodes).FromString(_code)
                    );
            }

            if (tradeLineItem.SelectSingleNode(".//ram:SpecifiedSupplyChainTradeAgreement/ram:ContractReferencedDocument/ram:IssuerAssignedID", nsmgr) != null)
            {
                item.ContractReferencedDocument = new ContractReferencedDocument()
                {
                    ID            = _nodeAsString(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeAgreement/ram:ContractReferencedDocument/ram:IssuerAssignedID", nsmgr),
                    IssueDateTime = _nodeAsDateTime(tradeLineItem, ".//ram:SpecifiedSupplyChainTradeAgreement/ram:ContractReferencedDocument/ram:IssueDateTime/udt:DateTimeString", nsmgr),
                };
            }

            return(item);
        } // !_parseTradeLineItem()
Пример #7
0
        } // !AddTradeLineItem()

        /// <summary>
        /// Adds a new line to the invoice. The line id is passed as a parameter.
        /// </summary>
        public TradeLineItem AddTradeLineItem(string lineID,
                                              string name,
                                              string description            = null,
                                              QuantityCodes unitCode        = QuantityCodes.Unknown,
                                              decimal?unitQuantity          = null,
                                              decimal?grossUnitPrice        = null,
                                              decimal?netUnitPrice          = null,
                                              decimal billedQuantity        = 0,
                                              TaxTypes taxType              = TaxTypes.Unknown,
                                              TaxCategoryCodes categoryCode = TaxCategoryCodes.Unknown,
                                              decimal taxPercent            = 0,
                                              string comment              = null,
                                              GlobalID id                 = null,
                                              string sellerAssignedID     = "", string buyerAssignedID      = "",
                                              string deliveryNoteID       = "", DateTime?deliveryNoteDate   = null,
                                              string buyerOrderID         = "", DateTime?buyerOrderDate     = null,
                                              DateTime?billingPeriodStart = null, DateTime?billingPeriodEnd = null)
        {
            TradeLineItem newItem = new TradeLineItem()
            {
                LineID             = lineID,
                GlobalID           = id,
                SellerAssignedID   = sellerAssignedID,
                BuyerAssignedID    = buyerAssignedID,
                Name               = name,
                Description        = description,
                UnitCode           = unitCode,
                UnitQuantity       = unitQuantity,
                GrossUnitPrice     = grossUnitPrice,
                NetUnitPrice       = netUnitPrice,
                BilledQuantity     = billedQuantity,
                TaxType            = taxType,
                TaxCategoryCode    = categoryCode,
                TaxPercent         = taxPercent,
                BillingPeriodStart = billingPeriodStart,
                BillingPeriodEnd   = billingPeriodEnd
            };

            if (String.IsNullOrEmpty(lineID))
            {
                throw new ArgumentException("LineID cannot be Null or Empty");
            }
            else
            {
                if (this.TradeLineItems.Any(p => p.AssociatedDocument.LineID.ToLower() == lineID.ToLower()))
                {
                    throw new ArgumentException("LineID must be unique");
                }
            }

            newItem.AssociatedDocument = new ZUGFeRD.AssociatedDocument(lineID);
            if (!String.IsNullOrEmpty(comment))
            {
                newItem.AssociatedDocument.Notes.Add(new Note(comment, SubjectCodes.Unknown, ContentCodes.Unknown));
            }

            if (!String.IsNullOrEmpty(deliveryNoteID) || deliveryNoteDate.HasValue)
            {
                newItem.SetDeliveryNoteReferencedDocument(deliveryNoteID, deliveryNoteDate);
            }

            if (!String.IsNullOrEmpty(buyerOrderID) || buyerOrderDate.HasValue)
            {
                newItem.SetOrderReferencedDocument(buyerOrderID, buyerOrderDate);
            }

            this.TradeLineItems.Add(newItem);
            return(newItem);
        } // !AddTradeLineItem()