Beispiel #1
0
 public async Task <Tuple <List <InvoiceViewModel>, int> > Search(InvoiceQuery req)
 {
     return(await(_dbContext as Model.PunnelContext).msp_Invoice_Search(req));
 }
        static void Main(string[] args)
        {
            var run = true;

            while (run)
            {
                ConsoleKeyInfo userInput = MainMenu();

                switch (userInput.KeyChar)
                {
                case '0':
                    run = false;
                    break;

                case '1':
                    Console.Clear();
                    var invoiceQuery = new InvoiceQuery();

                    var invoices       = invoiceQuery.GetInvoicesBySalesRep();
                    var invoiceDetails = invoiceQuery.GetInvoiceDetails();

                    Console.WriteLine("Here are all of the invoice IDs associated with their sales reps");

                    foreach (var invoice in invoices)
                    {
                        Console.WriteLine($"Sales Rep: {invoice.Name}, Invoice ID: {invoice.InvoiceId}");
                    }
                    Console.WriteLine("press enter to continue.");
                    Console.ReadLine();
                    break;

                case '2':
                    Console.Clear();
                    Console.WriteLine("Here are all of the invoices with their totals, and some other shit");

                    invoiceQuery   = new InvoiceQuery();
                    invoices       = invoiceQuery.GetInvoicesBySalesRep();
                    invoiceDetails = invoiceQuery.GetInvoiceDetails();

                    foreach (var detail in invoiceDetails)
                    {
                        Console.WriteLine($"Total: {detail.Total}, Sales Rep: {detail.SalesAgent}, Billing Country: {detail.BillingCountry}, Customer Name: {detail.CustomerName}");
                    }
                    Console.WriteLine("press enter to continue.");
                    Console.ReadLine();
                    break;

                case '3':
                    Console.Clear();
                    Console.WriteLine("Please enter in an invoice ID to see the total number of line items for that invoice.");
                    var invoiceInput = Console.ReadLine();
                    invoiceQuery = new InvoiceQuery();
                    var lineItems = invoiceQuery.GetInvoiceLineItems(int.Parse(invoiceInput));
                    Console.WriteLine($"There are {lineItems} line items for invoice ID {invoiceInput}");
                    Console.WriteLine("press enter to continue.");
                    Console.ReadLine();
                    break;

                case '4':
                    Console.Clear();
                    Console.WriteLine("Please enter your address to create a new invoice.");
                    var userAddress = Console.ReadLine();
                    Console.WriteLine("What is the customerID for this invoice?");
                    var customerID      = Console.ReadLine();
                    var invoiceModifier = new InvoiceModifier();
                    var createInvoice   = invoiceModifier.AddNewInvoice(userAddress, int.Parse(customerID));
                    if (createInvoice)
                    {
                        Console.WriteLine("Congratulations, you created a new invoice!");
                    }
                    Console.WriteLine("press enter to continue.");
                    Console.ReadLine();
                    break;

                case '5':
                    Console.Clear();
                    Console.WriteLine("Please enter the Employee ID whose name you would like to change.");
                    var employeeId = Console.ReadLine();
                    Console.WriteLine("What would you like to change their name to?");
                    var newName          = Console.ReadLine();
                    var employeeModifier = new EmployeeModifier();
                    var changeName       = employeeModifier.UpdateEmployee(int.Parse(employeeId), newName);
                    if (changeName)
                    {
                        Console.WriteLine($"Congratulations, you updated the name of employee ID {employeeId} to {newName}!");
                    }
                    Console.WriteLine("press enter to continue.");
                    Console.ReadLine();
                    break;
                }
            }

            ConsoleKeyInfo MainMenu()
            {
                View mainMenu = new View()
                                .AddMenuOption("Show invoices associated with each sales agent.")
                                .AddMenuOption("See invoice data for all invoices.")
                                .AddMenuOption("See number of invoice line items for each invoice.")
                                .AddMenuOption("Add anew invoice.")
                                .AddMenuOption("Update an employee name.")
                                .AddMenuText("Press 0 to exit.");

                Console.Write(mainMenu.GetFullMenu());
                ConsoleKeyInfo userOption = Console.ReadKey();

                return(userOption);
            }
        }
Beispiel #3
0
 public Invoice GetById(int id)
 {
     return(_invoice.One(InvoiceQuery.WithById(id)));
 }
        private async Task MigratedInvoiceTextSearchToDb(int startFromPage)
        {
            // deleting legacy DBriize database if present
            var dbpath = Path.Combine(_datadirs.DataDir, "InvoiceDB");

            if (Directory.Exists(dbpath))
            {
                Directory.Delete(dbpath, true);
            }

            // migrate data to new table using invoices from database
            using var ctx = _dbContextFactory.CreateContext();

            var invoiceQuery = new InvoiceQuery {
                IncludeArchived = true
            };
            var totalCount = await _invoiceRepository.GetInvoicesTotal(invoiceQuery);

            const int PAGE_SIZE  = 1000;
            var       totalPages = Math.Ceiling(totalCount * 1.0m / PAGE_SIZE);

            for (int i = startFromPage; i < totalPages && !CancellationToken.IsCancellationRequested; i++)
            {
                invoiceQuery.Skip = i * PAGE_SIZE;
                invoiceQuery.Take = PAGE_SIZE;
                var invoices = await _invoiceRepository.GetInvoices(invoiceQuery);

                foreach (var invoice in invoices)
                {
                    var textSearch = new List <string>();

                    // recreating different textSearch.Adds that were previously in DBriize
                    foreach (var paymentMethod in invoice.GetPaymentMethods())
                    {
                        if (paymentMethod.Network != null)
                        {
                            var paymentDestination = paymentMethod.GetPaymentMethodDetails().GetPaymentDestination();
                            textSearch.Add(paymentDestination);
                            textSearch.Add(paymentMethod.Calculate().TotalDue.ToString());
                        }
                    }
                    //
                    textSearch.Add(invoice.Id);
                    textSearch.Add(invoice.InvoiceTime.ToString(CultureInfo.InvariantCulture));
                    textSearch.Add(invoice.Price.ToString(CultureInfo.InvariantCulture));
                    textSearch.Add(invoice.Metadata.OrderId);
                    textSearch.Add(InvoiceRepository.ToJsonString(invoice.Metadata, null));
                    textSearch.Add(invoice.StoreId);
                    textSearch.Add(invoice.Metadata.BuyerEmail);
                    //
                    textSearch.Add(invoice.RefundMail);
                    // TODO: Are there more things to cache? PaymentData?

                    InvoiceRepository.AddToTextSearch(ctx,
                                                      new InvoiceData {
                        Id = invoice.Id, InvoiceSearchData = new List <InvoiceSearchData>()
                    },
                                                      textSearch.ToArray());
                }

                var settings = await _settingsRepository.GetSettingAsync <MigrationSettings>();

                if (i + 1 < totalPages)
                {
                    settings.MigratedInvoiceTextSearchPages = i;
                }
                else
                {
                    // during final pass we set int.MaxValue so migration doesn't run again
                    settings.MigratedInvoiceTextSearchPages = int.MaxValue;
                }

                // this call triggers update; we're sure that MigrationSettings is already initialized in db
                // because of logic executed in MigrationStartupTask.cs
                _settingsRepository.UpdateSettingInContext(ctx, settings);
                await ctx.SaveChangesAsync();
            }
        }
Beispiel #5
0
 /// <summary>
 /// Returns All Invoices
 ///
 /// GET /umbraco/Merchello/InvoiceApi/GetFilteredInvoices
 /// </summary>
 /// <param name="term"></param>
 public IEnumerable <InvoiceDisplay> GetFilteredInvoices(string term)
 {
     return(InvoiceQuery.Search(term));
 }
Beispiel #6
0
 /// <summary>
 /// Returns All Products
 ///
 /// GET /umbraco/Merchello/ProductApi/GetProducts
 /// </summary>
 public IEnumerable <InvoiceDisplay> GetAllInvoices(int page, int perPage)
 {
     return(InvoiceQuery.GetAllInvoices().Skip((page - 1) * perPage).Take(perPage));
 }
Beispiel #7
0
 /// <summary>
 /// Returns All Invoices
 ///
 /// GET /umbraco/Merchello/InvoiceApi/GetInvoices
 /// </summary>
 public IEnumerable <InvoiceDisplay> GetAllInvoices()
 {
     return(InvoiceQuery.GetAllInvoices());
 }
Beispiel #8
0
 /// <summary>
 /// Returns All Products
 ///
 /// GET /umbraco/Merchello/InvoicesApi/GetFilteredInvoices
 /// </summary>
 public IEnumerable <InvoiceDisplay> GetFilteredInvoices(string term, int page, int perPage)
 {
     return(InvoiceQuery.Search(term).Skip((page - 1) * perPage).Take(perPage));
 }