Exemplo n.º 1
0
 private void AddToInvoiceFile(bool addDelimiter, InvoiceFileDto fileDto, params string[] rows)
 {
     foreach (var row in rows)
         fileDto.FileRows.Add(row);
     // section delimiter
     if (addDelimiter)
         fileDto.FileRows.Add(string.Empty);
 }
Exemplo n.º 2
0
        /// <summary>
        /// This method is not good at all, since it contains hard-coded strings.
        /// If there will be need to localize(translate) the file, this code should be rewritten.
        /// </summary>
        /// <param name="invoice"></param>
        /// <param name="fees"></param>
        /// <returns></returns>
        private InvoiceFileDto PrepareInvoiceFile(Invoice invoice, IDictionary<FeeType, Fee> fees)
        {
            var fileDto = new InvoiceFileDto
            {
                InvoiceNumber = invoice.Number,
                FileRows = new List<string>()
            };

            const string invoiceHeader = "Invoice";
            var number = string.Format("Number,{0}", invoice.Number);
            var date = string.Format("Date,{0}", invoice.Date.ToString("dd.MM.yyyy HH:mm:ss"));
            var customer = string.Format("Customer,{0}", invoice.Customer);
            AddToInvoiceFile(true, fileDto, invoiceHeader, number, date, customer);

            const string rowsHeader = "Rows";
            const string rowsDescription = "Equipments,Days rented,Price";
            AddToInvoiceFile(false, fileDto, rowsHeader, rowsDescription);

            // using invariant culture renders decimals with '.' - useful distinction in .csv files
            var rowStrs = invoice.Rows.Select(row =>
                string.Format("{0},{1},{2}", row.Equipment.Name, row.RentedDays,
                    row.GetRowPrice(fees).ToString(CultureInfo.InvariantCulture))).ToArray();
            AddToInvoiceFile(true, fileDto, rowStrs);

            const string bottomHeader = "Total";
            var totalPrice = string.Format("Price,{0}",
                invoice.GetInvoicePrice().ToString(CultureInfo.InvariantCulture));
            var points = string.Format("Loyalty points,{0}", invoice.GetInvoiceLoyaltyPoints());
            AddToInvoiceFile(false, fileDto, bottomHeader, totalPrice, points);

            return fileDto;
        }