public async Task<IbisFileGeneratorResult<TransactionFile>> CreateAsync(ulong fileID, InvoiceRun invoiceRun)
        {
            TransactionFile transactionFile = new TransactionFile("WEE", fileID);

            var errors = new List<Exception>();
            var groups = invoiceRun.MemberUploads.GroupBy(mu => mu.Scheme);

            foreach (var group in groups)
            {
                List<InvoiceLineItem> lineItems = new List<InvoiceLineItem>();
                var lineItemErrors = new List<Exception>();

                foreach (MemberUpload memberUpload in group)
                {
                    DateTime submittedDate = memberUpload.SubmittedDate.Value;

                    string description = string.Format("Charge for producer registration submission made on {0:dd MMM yyyy}.",
                        submittedDate);

                    try
                    {
                        InvoiceLineItem lineItem = new InvoiceLineItem(
                            memberUpload.TotalCharges,
                            description);

                        lineItems.Add(lineItem);
                    }
                    catch (Exception ex)
                    {
                        lineItemErrors.Add(new SchemeFieldException(group.Key, ex));
                    }
                }

                errors.AddRange(lineItemErrors);

                string transactionReference = await transactionReferenceGenerator.GetNextTransactionReferenceAsync();

                if (lineItemErrors.Count == 0)
                {
                    try
                    {
                        Invoice invoice = new Invoice(
                            group.Key.IbisCustomerReference,
                            invoiceRun.IssuedDate,
                            TransactionType.Invoice,
                            transactionReference,
                            lineItems);

                        transactionFile.AddInvoice(invoice);
                    }
                    catch (Exception ex)
                    {
                        errors.Add(new SchemeFieldException(group.Key, ex));
                    }
                }
            }

            return new IbisFileGeneratorResult<TransactionFile>(errors.Count == 0 ? transactionFile : null, errors);
        }
        public async Task<IbisFileGeneratorResult<TransactionFile>> CreateAsync(ulong fileID, InvoiceRun invoiceRun)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

            var errors = new List<Exception>();
            TransactionFile transactionFile = new TransactionFile("WEE", fileID);

            foreach (MemberUpload memberUpload in invoiceRun.MemberUploads)
            {
                List<InvoiceLineItem> lineItems = new List<InvoiceLineItem>();

                var lineItemGroups = memberUpload.ProducerSubmissions
                    .Where(ps => ps.ChargeThisUpdate != 0)
                    .Where(ps => ps.Invoiced)
                    .GroupBy(ps => ps.ChargeThisUpdate)
                    .OrderBy(g => g.Key)
                    .Select(g => new { Charge = g.Key, Quantity = g.Count() })
                    .ToList();

                if (lineItemGroups.Count > 0)
                {
                    var lineItemErrors = new List<Exception>();

                    foreach (var lineItemGroup in lineItemGroups)
                    {
                        decimal amount = lineItemGroup.Charge * lineItemGroup.Quantity;

                        string description = string.Format("{0} producer registration charge{1} at {2:C}.",
                            lineItemGroup.Quantity,
                            lineItemGroup.Quantity != 1 ? "s" : string.Empty,
                            lineItemGroup.Charge);

                        InvoiceLineItem lineItem;
                        try
                        {
                            lineItem = new InvoiceLineItem(
                                amount,
                                description);

                            lineItems.Add(lineItem);
                        }
                        catch (Exception ex)
                        {
                            lineItemErrors.Add(ex);
                        }
                    }

                    errors.AddRange(lineItemErrors);

                    if (lineItemErrors.Count == 0)
                    {
                        string transactionReference = await transactionReferenceGenerator.GetNextTransactionReferenceAsync();

                        try
                        {
                            Invoice invoice = new Invoice(
                                memberUpload.Scheme.IbisCustomerReference,
                                invoiceRun.IssuedDate,
                                TransactionType.Invoice,
                                transactionReference,
                                lineItems);

                            transactionFile.AddInvoice(invoice);
                        }
                        catch (Exception ex)
                        {
                            errors.Add(ex);
                        }
                    }
                }
            }

            return new IbisFileGeneratorResult<TransactionFile>(errors.Count == 0 ? transactionFile : null, errors);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a list of data items related to the invoice line item.
        /// </summary>
        public IEnumerable <string> GetDataItems()
        {
            yield return(Invoice.CustomerReference);

            yield return(Invoice.TransactionDate.ToString("dd-MMM-yyyy").ToUpperInvariant());

            yield return(ConvertTransactionTypeToString(Invoice.TransactionType));

            yield return(Invoice.TransactionReference);

            yield return(Invoice.RelatedTransactionReference);

            yield return(ConvertCurrencyCodeToString(Invoice.CurrencyCode));

            yield return(Invoice.TransactionHeaderNarrative);

            yield return(Invoice.TransactionDate.ToString("dd-MMM-yyyy").ToUpperInvariant()); // Header Attribute 1

            yield return(string.Empty);                                                       // Header Attribute 2

            yield return(string.Empty);                                                       // Header Attribute 3

            yield return(string.Empty);                                                       // Header Attribute 4

            yield return(string.Empty);                                                       // Header Attribute 5

            yield return(string.Empty);                                                       // Header Attribute 6

            yield return(string.Empty);                                                       // Header Attribute 7

            yield return(string.Empty);                                                       // Header Attribute 8

            yield return(string.Empty);                                                       // Header Attribute 9

            yield return(string.Empty);                                                       // Header Attribute 10

            yield return(TransactionFile.FormatCurrencyInPence(InvoiceLineItem.AmountExcludingVAT));

            yield return(InvoiceLineItem.VatCode);

            yield return(InvoiceLineItem.AreaCode);

            yield return(InvoiceLineItem.Description);

            yield return(InvoiceLineItem.IncomeStreamCode);

            yield return(InvoiceLineItem.ContextCode);

            yield return(string.Empty); // Line Attribute 1

            yield return(string.Empty); // Line Attribute 2

            yield return(string.Empty); // Line Attribute 3

            yield return(string.Empty); // Line Attribute 4

            yield return(string.Empty); // Line Attribute 5

            yield return(string.Empty); // Line Attribute 6

            yield return(string.Empty); // Line Attribute 7

            yield return(string.Empty); // Line Attribute 8

            yield return(string.Empty); // Line Attribute 9

            yield return(string.Empty); // Line Attribute 10

            yield return(string.Empty); // Line Attribute 11

            yield return(string.Empty); // Line Attribute 12

            yield return(string.Empty); // Line Attribute 13

            yield return(string.Empty); // Line Attribute 14

            yield return(string.Empty); // Line Attribute 15

            yield return(InvoiceLineItem.Quantity.ToString());

            yield return(ConvertUnitOfMeasureToString(InvoiceLineItem.UnitOfMeasure));

            yield return(TransactionFile.FormatCurrencyInPence(InvoiceLineItem.AmountExcludingVAT)); // UOM selling price
        }