public Stream CreateZugFerdXML()
        {
            //Create ZugFerd Invoice
            ZugFerdInvoice invoice = new ZugFerdInvoice("2058557939", new DateTime(2013, 6, 5), CurrencyCodes.USD);

            //Set ZugFerdProfile to ZugFerdInvoice
            invoice.Profile = ZugFerdProfile.Basic;

            //Add buyer details
            invoice.Buyer = new UserDetails
            {
                ID          = "Abraham_12",
                Name        = "Abraham Swearegin",
                ContactName = "Swearegin",
                City        = "United States, California",
                Postcode    = "9920",
                Country     = CountryCodes.US,
                Street      = "9920 BridgePointe Parkway"
            };

            //Add seller details
            invoice.Seller = new UserDetails
            {
                ID          = "Adventure_123",
                Name        = "AdventureWorks",
                ContactName = "Adventure support",
                City        = "Austin,TX",
                Postcode    = "",
                Country     = CountryCodes.US,
                Street      = "800 Interchange Blvd"
            };


            IEnumerable <Product> products = GetProductReport();

            float total = 0;

            foreach (var product in products)
            {
                invoice.AddProduct(product);
                total += product.Total;
            }

            invoice.TotalAmount = total;

            MemoryStream ms = new MemoryStream();

            //Save ZugFerd Xml
            return(invoice.Save(ms));
        }
Exemple #2
0
        public Stream CreateZugFerdXML()
        {
            //Create ZugFerd Invoice
            ZugFerdInvoice invoice = new ZugFerdInvoice("2058557939", new DateTime(2013, 6, 5), CurrencyCodes.USD);

            //Set ZugFerdProfile to ZugFerdInvoice
            invoice.Profile = ZugFerdProfile.Basic;

            //Add buyer details
            invoice.Buyer = new UserDetails
            {
                ID          = "Abraham_12",
                Name        = "Abraham Swearegin",
                ContactName = "Swearegin",
                City        = "United States, California",
                Postcode    = "9920",
                Country     = CountryCodes.US,
                Street      = "9920 BridgePointe Parkway"
            };

            //Add seller details
            invoice.Seller = new UserDetails
            {
                ID          = "Adventure_123",
                Name        = "AdventureWorks",
                ContactName = "Adventure support",
                City        = "Austin,TX",
                Postcode    = "",
                Country     = CountryCodes.US,
                Street      = "800 Interchange Blvd"
            };
            Stream xmlStream = typeof(ZugFerd).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.InvoiceProductList.xml");
            float  total     = 0;

            using (XmlReader reader = XmlReader.Create(xmlStream))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        reader.Name.ToString();

                        Product product = new Product();


                        switch (reader.Name.ToString())
                        {
                        case "Productid":
                            product.ProductID = reader.ReadString();
                            break;

                        case "Product":
                            product.productName = reader.ReadString();
                            break;

                        case "Price":
                            product.Price = float.Parse(reader.ReadString(), System.Globalization.CultureInfo.InvariantCulture);
                            break;

                        case "Quantity":
                            product.Quantity = float.Parse(reader.ReadString(), System.Globalization.CultureInfo.InvariantCulture);
                            break;

                        case "Total":
                            product.Total = float.Parse(reader.ReadString(), System.Globalization.CultureInfo.InvariantCulture);
                            total        += product.Total;
                            invoice.AddProduct(product.ProductID, product.productName, product.Price, product.Quantity, product.Total);
                            break;
                        }
                    }
                }
            }

            invoice.TotalAmount = total;

            MemoryStream ms = new MemoryStream();

            //Save ZugFerd Xml
            return(invoice.Save(ms));
        }