Beispiel #1
0
 /// <summary>
 /// Method to set invoice items of the invoice options.
 /// </summary>
 /// <param name="items">
 /// List of items which should be added to the invoice options.
 /// </param>
 public void SetInvoiceItems(IList <InvoiceItem> items)
 {
     CsvLineItems = InvoiceItem.GetHeaders() + "\n" + string.Join("\n", items.Select(ii => ii.ToString()));
 }
Beispiel #2
0
        /// <summary>
        /// List of invoice items.
        /// This is used for free-form invoices.
        /// </summary>
        /// <returns>The list of invoices.</returns>
        public IList<InvoiceItem> ListLineItems()
        {
            if (_listLineItems == null)
            {
                _listLineItems = new List<InvoiceItem>();

                // Null check
                if (string.IsNullOrEmpty(CsvLineItems)) return _listLineItems;

                // Get memory stream of data
                System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(CsvLineItems));

                // Use the inbuildt .NET CSV parser
                Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(stream);
                parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
                parser.SetDelimiters(",");

                List<string> headers = new List<string>();
                int lineindex = 0;
                while (!parser.EndOfData)
                {
                    string[] fields = parser.ReadFields();
                    int fieldindex = 0;
                    InvoiceItem invocieitem = null;
                    foreach (string field in fields)
                    {
                        // Header, or content?
                        if (lineindex == 0)
                        {
                            headers.Add(field);
                        }
                        else
                        {
                            if (invocieitem == null) invocieitem = new InvoiceItem();

                            // Parse by header name
                            switch (headers[fieldindex])
                            {
                                case "kind": invocieitem.Kind = field; break;
                                case "description": invocieitem.Description = field; break;
                                case "quantity": invocieitem.Quantity = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;
                                case "unit_price": invocieitem.UnitPrice = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;
                                case "amount": invocieitem.Amount  = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;
                                case "taxed": invocieitem.Taxed = bool.Parse(field); break;
                                case "taxed2": invocieitem.Taxed2 = bool.Parse(field); break;
                                case "project_id": invocieitem.ProjectId = string.IsNullOrEmpty(field) ? 0 : long.Parse(field); break;
                            }
                        }

                        fieldindex++;
                    }

                    lineindex++;
                    if (invocieitem != null) _listLineItems.Add(invocieitem);
                }

                parser.Close();
            }

            return _listLineItems;
        }
Beispiel #3
0
        /// <summary>
        /// List of invoice items.
        /// This is used for free-form invoices.
        /// </summary>
        /// <returns>The list of invoices.</returns>
        public IList <InvoiceItem> ListLineItems()
        {
            if (_listLineItems == null)
            {
                _listLineItems = new List <InvoiceItem>();

                // Null check
                if (string.IsNullOrEmpty(CsvLineItems))
                {
                    return(_listLineItems);
                }

                // Get memory stream of data
                System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(CsvLineItems));

                // Use the inbuildt .NET CSV parser
                var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(stream)
                {
                    TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
                };

                parser.SetDelimiters(",");

                List <string> headers   = new List <string>();
                int           lineindex = 0;
                while (!parser.EndOfData)
                {
                    string[]    fields      = parser.ReadFields();
                    int         fieldindex  = 0;
                    InvoiceItem invocieitem = null;
                    foreach (string field in fields)
                    {
                        // Header, or content?
                        if (lineindex == 0)
                        {
                            headers.Add(field);
                        }
                        else
                        {
                            if (invocieitem == null)
                            {
                                invocieitem = new InvoiceItem();
                            }

                            // Parse by header name
                            switch (headers[fieldindex])
                            {
                            case "kind": invocieitem.Kind = field; break;

                            case "description": invocieitem.Description = field; break;

                            case "quantity": invocieitem.Quantity = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;

                            case "unit_price": invocieitem.UnitPrice = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;

                            case "amount": invocieitem.Amount = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;

                            case "taxed": invocieitem.Taxed = bool.Parse(field); break;

                            case "taxed2": invocieitem.Taxed2 = bool.Parse(field); break;

                            case "project_id": invocieitem.ProjectId = string.IsNullOrEmpty(field) ? 0 : long.Parse(field); break;
                            }
                        }

                        fieldindex++;
                    }

                    lineindex++;
                    if (invocieitem != null)
                    {
                        _listLineItems.Add(invocieitem);
                    }
                }

                parser.Close();
            }

            return(_listLineItems);
        }
Beispiel #4
0
        /// <summary>
        /// List of invoice items.
        /// This is used for free-form invoices.
        /// </summary>
        /// <returns>The list of invoices.</returns>
        public IList <InvoiceItem> ListLineItems()
        {
            if (_listLineItems == null)
            {
                _listLineItems = new List <InvoiceItem>();

                // Null check
                if (string.IsNullOrEmpty(CsvLineItems))
                {
                    return(_listLineItems);
                }

                // Get memory stream of data
                using (System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(CsvLineItems)))
                    using (var streamReader = new StreamReader(stream))
                        using (var parser = new CsvHelper.CsvReader(streamReader)) {
                            List <string> headers   = new List <string>();
                            int           lineindex = 0;
                            while (parser.Read())
                            {
                                string[]    fields      = GetFields(parser);
                                int         fieldindex  = 0;
                                InvoiceItem invocieitem = null;
                                foreach (string field in fields)
                                {
                                    // Header, or content?
                                    if (lineindex == 0)
                                    {
                                        headers.Add(field);
                                    }
                                    else
                                    {
                                        if (invocieitem == null)
                                        {
                                            invocieitem = new InvoiceItem();
                                        }

                                        // Parse by header name
                                        switch (headers[fieldindex])
                                        {
                                        case "kind": invocieitem.Kind = field; break;

                                        case "description": invocieitem.Description = field; break;

                                        case "quantity": invocieitem.Quantity = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;

                                        case "unit_price": invocieitem.UnitPrice = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;

                                        case "amount": invocieitem.Amount = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break;

                                        case "taxed": invocieitem.Taxed = bool.Parse(field); break;

                                        case "taxed2": invocieitem.Taxed2 = bool.Parse(field); break;

                                        case "project_id": invocieitem.ProjectId = string.IsNullOrEmpty(field) ? 0 : long.Parse(field); break;
                                        }
                                    }

                                    fieldindex++;
                                }

                                lineindex++;
                                if (invocieitem != null)
                                {
                                    _listLineItems.Add(invocieitem);
                                }
                            }
                        }
            }

            return(_listLineItems);
        }