/// <summary>
        /// Generate a pdf report with the data retrieved
        /// </summary>
        /// <param name="data">Data source</param>
        /// <returns>Message for successful document generation</returns>
        /// <exception cref="InvalidOperationException">
        /// Throws exeption when no command arguments are available
        /// to process the command</exception>
        public string Execute(IProductsSystemData data)
        {
            var commandOutput = "";

            if (this.Arguments.Count == CommandArgumentsCount)
            {
                //var aggregatedSalesData = this.RetrieveAggregateSalesInformation(
                //    data, (DateTime)Arguments[0], (DateTime)Arguments[1]);
                //if (aggregatedSalesData.Count == 0)
                //{
                //    commandOutput = EngineConstants.NoResultDataMessage;
                //}
                //else
                //{
                //xmlExporter.Data = aggregatedSalesData;
                this.xmlExporter.Export();
                //    commandOutput = EngineConstants.XmlReportSuccessfullyExportedMessage;
                //}

                this.Arguments.Clear();
                return(commandOutput);
            }

            throw new SupermarketsChainException(EngineConstants.CommandArgumentsMissmatchMessage);
        }
        private IList <SalesForDateInterval> RetrieveAggregateSalesInformation(
            IProductsSystemData data, DateTime startDate, DateTime endDate)
        {
            var dataFiltered = data.Sales
                               .Find(s => s.Date >= startDate && s.Date <= endDate)
                               .GroupBy(s => s.Date)
                               .ToDictionary(group => group.Key, group => group.ToList());

            var aggregatedSalesData = new List <SalesForDateInterval>();

            foreach (var group in dataFiltered)
            {
                var sales = group.Value;

                aggregatedSalesData.Add(
                    new SalesForDateInterval
                {
                    Date  = group.Key,
                    Sales = group.Value.Select(sale =>
                                               new
                    {
                        Product   = sale.Product.Name,
                        Quantity  = sale.Quantity + " " + sale.Product.Measure.Name,
                        UnitPrice = sale.Product.Price,
                        Location  = sale.Supermarket.Location,
                        Sum       = sale.Quantity * sale.Product.Price
                    }).ToList(),
                    TotaSum = group.Value.Sum(s => (s.Quantity * s.Product.Price))
                });
            }

            return(aggregatedSalesData);
        }
        /// <summary>
        /// Generate a xml report with the data retrieved
        /// </summary>
        /// <param name="data">Data source</param>
        /// <returns>Message for successful document generation</returns>
        /// <exception cref="InvalidOperationException">
        /// Throws exeption when no command arguments are available
        /// to process the command</exception>
        public string Execute(IProductsSystemData data)
        {
            var commandOutput = "";

            if (this.Arguments.Count == CommandArgumentsCount)
            {
                IList <SalesAggregated> aggregatedSalesData;
                aggregatedSalesData = this.RetrieveAggregateSalesInformation(
                    data, (DateTime)this.Arguments[0], (DateTime)this.Arguments[1]);
                if (aggregatedSalesData.Count == 0)
                {
                    commandOutput = EngineConstants.NoResultDataMessage;
                }
                else
                {
                    this.xmlExporter.Data = aggregatedSalesData;
                    this.xmlExporter.Export(aggregatedSalesData);
                    commandOutput = EngineConstants.XmlReportSuccessfullyExportedMessage;
                }

                this.Arguments.Clear();
                return(commandOutput);
            }

            throw new SupermarketsChainException(EngineConstants.InvalidCommandMessage);
        }
Beispiel #4
0
        public string Execute(IProductsSystemData data)
        {
            var dataToBeImported = this.LoadDataToBeImported();

            xmlImporter.DataToBeImported = dataToBeImported;
            xmlImporter.Import(data);
            return(EngineConstants.XmlReportSuccessfullyImportedMessage);
        }
        public string Execute(IProductsSystemData data)
        {
            var dataToBeImported = this.LoadOracleData();

            oracleImporter.DataToBeImported = dataToBeImported;
            oracleImporter.Import(data);
            return(EngineConstants.OracleDataSuccessfullyImported);
        }
        public static Engine GetInstance(IUserInterface userInterface, IProductsSystemData data)
        {
            if (instance == null)
            {
                instance = new Engine(userInterface, data);
            }

            return(instance);
        }
Beispiel #7
0
        public string Execute(IProductsSystemData data)
        {
            var sales = this.LoadSales(data);

            excelImporter.SalesToBeImported = sales;
            excelImporter.Import(data);

            return(EngineConstants.ExcelDataSuccessfullyImported);
        }
Beispiel #8
0
        public void Import(IProductsSystemData data)
        {
            var sqlSereverProductsNames = data.Products.All().Select(p => p.Name);

            this.DataToBeImported.RemoveAll(p => sqlSereverProductsNames.Contains(p.Name));
            if (this.DataToBeImported.Any())
            {
                data.Products.AddRange(this.DataToBeImported);
                data.SaveChanges();
            }
        }
        private IList <SalesAggregated> RetrieveAggregateSalesInformation(
            IProductsSystemData data, DateTime startDate, DateTime endDate)
        {
            var salesAggregated = data.Sales.All()
                                  .Where(s => s.Date >= startDate && s.Date <= endDate)
                                  .GroupBy(s => s.Product.Vendor)
                                  .Select(sgv => new SalesAggregated
            {
                VendorName   = sgv.Key.Name,
                RawSummaries = sgv.GroupBy(s => s.Date).Select(sgd => new SalesSummary {
                    Date = sgd.Key, TotalSum = sgd.Sum(s => s.Product.Price * s.Quantity)
                })
            }).ToList();

            return(salesAggregated);
        }
Beispiel #10
0
        private IList <SalesByProduct> RetrieveAggregateSalesInformation(
            IProductsSystemData data, DateTime startDate, DateTime endDate)
        {
            var product = data.Sales.All()
                          .GroupBy(s => s.Product)
                          .Select(sp => new SalesByProduct
            {
                ProductId         = sp.Key.Id,
                ProductName       = sp.Key.Name,
                VendorName        = sp.Key.Vendor.Name,
                TotalQuantitySold = sp.Sum(s => s.Quantity),
                TotalIncomes      = sp.Sum(s => s.Quantity * s.Product.Price),
            }).ToList();

            return(product);
        }
Beispiel #11
0
        private IList <Sale> LoadSales(IProductsSystemData data)
        {
            ZipFile.ExtractToDirectory(DefaultZipPath, DefaultExtractPath);
            var salesReportsDirectories = Directory.GetDirectories(DefaultExtractPath);
            var sales = new List <Sale>();

            foreach (var directory in salesReportsDirectories)
            {
                var salesDate    = Path.GetFileName(directory);
                var date         = DateTime.ParseExact(salesDate, StringDateFormat, CultureInfo.InvariantCulture);
                var salesReports = Directory.GetFiles(directory);
                foreach (var salesReport in salesReports)
                {
                    sales.AddRange(this.ExtractSales(salesReport, date, data));
                }
            }

            return(sales);
        }
        /// <summary>
        /// Generate a pdf report with the data retrieved
        /// </summary>
        /// <param name="data">Data source</param>
        /// <returns>Message for successful document generation</returns>
        /// <exception cref="InvalidOperationException">
        /// Throws exeption when no command arguments are available
        /// to process the command</exception>
        public string Execute(IProductsSystemData data)
        {
            var commandOutput = "";

            var aggregatedSalesData = this.RetrieveAggregateSalesInformation(
                data, (DateTime)this.Arguments[0], (DateTime)this.Arguments[1]);

            if (aggregatedSalesData.Count == 0)
            {
                commandOutput = EngineConstants.NoResultDataMessage;
            }
            else
            {
                this.pdfExporter.Data = aggregatedSalesData;
                this.pdfExporter.Export();
                commandOutput = EngineConstants.PdfReportSuccessfullyExportedMessage;
            }

            this.Arguments.Clear();
            return(commandOutput);
        }
        public void Import(IProductsSystemData data)
        {
            foreach (var vendor in DataToBeImported)
            {
                var vendorEntity = data.Vendors.Find(v => v.Name == vendor.Key);
                if (vendorEntity != null)
                {
                    int vendorId = vendorEntity.First().Id;
                    foreach (var vendorExpense in vendor.Value)
                    {
                        data.Expenses.Add(new Expense
                        {
                            VendorID = vendorId,
                            Amount   = vendorExpense.Value,
                            Period   = vendorExpense.Key
                        });
                    }
                }
            }

            data.SaveChanges();
        }
Beispiel #14
0
        private IList <Sale> ExtractSales(string file, DateTime date, IProductsSystemData data)
        {
            IList <Sale> sales  = new List <Sale>();
            var          report = new Spreadsheet();

            using (report)
            {
                report.LoadFromFile(file);
                Worksheet worksheet       = report.Workbook.Worksheets.ByName("Sales");
                var       supermarketName = worksheet.Cell(WorksheetSettings.StartRow, WorksheetSettings.StartCell).Value;
                int       supermarketId   = data.Supermarkets.Find(s => s.Location == supermarketName).Select(s => s.Id).First();
                string    productName;
                Product   product;
                int       quantity;
                int       currentRow   = WorksheetSettings.FirstContentRow;
                string    checkContent = worksheet.Cell(currentRow, WorksheetSettings.ProductCell).ValueAsString;
                while (checkContent != WorksheetSettings.EndRowContent)
                {
                    productName = worksheet.Cell(currentRow, WorksheetSettings.ProductCell).ValueAsString;
                    product     = data.Products.Find(p => p.Name == productName).First();
                    this.AddNewPrices(product, supermarketId, worksheet, currentRow);
                    quantity = worksheet.Cell(currentRow, WorksheetSettings.QuantityCell).ValueAsInteger;
                    var sale = new Sale
                    {
                        Product       = product,
                        SupermarketId = supermarketId,
                        Quantity      = quantity,
                        Date          = date
                    };

                    sales.Add(sale);
                    currentRow++;
                    checkContent = worksheet.Cell(currentRow, WorksheetSettings.ProductCell).ValueAsString;
                }
            }

            return(sales);
        }
 private Engine(IUserInterface userInterface, IProductsSystemData data)
 {
     this.userInterface = userInterface;
     this.data          = data;
     this.commands      = new Dictionary <Type, IEngineCommand>();
 }
Beispiel #16
0
 public void Import(IProductsSystemData data)
 {
     data.Sales.AddRange(this.SalesToBeImported);
     data.SaveChanges();
 }