Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the GroceryCo Shopping App:");

            ShowOptions();

            string selection = Console.ReadLine().ToUpper();

            while (!selection.Equals("Q"))
            {
                switch (selection)
                {
                case "L":
                    IProductReport productReport = new ProductReport();
                    productReport.DisplayProducts();
                    break;

                case "C":
                    IShoppingCartHandler shoppingCartHandler = new ShoppingCartHandler();
                    shoppingCartHandler.CheckoutShoppingCart();
                    break;

                case "Q":
                    break;

                default:
                    Console.WriteLine("Invalid option selected");
                    break;
                }

                ShowOptions();

                selection = Console.ReadLine().ToUpper();
            }
        }
        private void dgvProductList_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1 || e.ColumnIndex == -1)
            {
                return;
            }
            ProductReport selectedProduct = (ProductReport)dgvProductList.Rows[e.RowIndex].DataBoundItem;

            if (GetSelectedCellText(dgvProductList, e) == "Details")
            {
                ProductForm productForm = new ProductForm(selectedProduct.Id);
                ShowFormAsFixedDialog(this, productForm);
            }
            else if (GetSelectedCellText(dgvProductList, e) == "Select")
            {
                if (CallerForm == null && CallerForm.Name == null)
                {
                    return;
                }
                else if (selectedProduct != null && CallerForm.Name == "DealerBillBreakupForm")
                {
                    ((DealerBillBreakupForm)CallerForm).OnProductSelect(selectedProduct.Id, selectedProduct.ProductName);
                }
                Close(); // close form and on closing call BillBreakupForm method to set product Id and Name
            }
        }
        public StatisticProductReportWindow(List <RecordProducts> records, StatisticModel Model)
        {
            this.Model = Model;

            InitializeComponent();

            this.Text = Model.Title;


            Assembly asm = Assembly.LoadFrom(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Res.dll"));

            this.Icon = new Icon(asm.GetManifestResourceStream(@"Oybab.Res.Resources.Images.PC.Statistic.ico"));


            Model.DataSource = records;


            ProductReport report = new ProductReport(Model.Parameters["PriceSymbol"].ToString());



            webBrowser1.Refresh();
            string htmlContent = report.ProcessHTMLContent(Model);

            webBrowser1.DocumentText = htmlContent;



            //File.WriteAllText("y:\\test1111.html", htmlContent);
        }
Beispiel #4
0
        public override object WindowLoaded(params object[] parameters)
        {
            ProductReport productReport = new ProductReport();

            productReport.SetParameterValue("@Product_ID", mProductID.ToString());
            return(productReport);
        }
        private void PopulateReportsList()
        {
            foreach (var ship in this.Spaceships)
            {
                var quantity = this.Sales
                               .Where(s => s.ProductName == ship.Model)
                               .Sum(s => s.Quantity);

                var totalSum = this.Sales
                               .Where(s => s.ProductName == ship.Model)
                               .Sum(s => s.Sum);

                var jsonReportEntry = new ProductReport()
                {
                    Id          = ship.Id,
                    Model       = ship.Model,
                    Category    = ship.Category.Name,
                    Price       = ship.Price,
                    QuanitySold = quantity,
                    TotalIncome = totalSum
                };

                this.Reports.Add(jsonReportEntry);
            }
        }
Beispiel #6
0
        public List <string> CreateJsonReports(Dictionary <DateTime, Dictionary <int, DBManager.MongoEntry> > reports)
        {
            string pathString = "../../../Product-Reports/";

            if (!Directory.Exists(pathString))
            {
                Directory.CreateDirectory(pathString);
            }

            var reportsAsStringsList = new List <string>();

            foreach (var report in reports)
            {
                foreach (var entry in report.Value)
                {
                    var productReport = new ProductReport(entry.Key, entry.Value.ProductName, entry.Value.VendorName,
                                                          entry.Value.QuantitySold, entry.Value.TotatIncome);
                    var serializeProductReport = new JavaScriptSerializer().Serialize(productReport);
                    reportsAsStringsList.Add(serializeProductReport);

                    SaveJsonIntoFile(serializeProductReport, pathString, entry.Key);
                }
            }

            return(reportsAsStringsList);
        }
        private static List<ProductReport> getAllReports(SupermarketContext db)
        {
            var reports = new List<ProductReport>();

            foreach (var product in db.Products)
            {
                int totalQuantitySold = 0;
                var foundProduct = db.SalesReports.FirstOrDefault(x => x.ProductID == product.ProductID);
                if(foundProduct!=null)
                {
                    totalQuantitySold = db.SalesReports.Where(x => x.ProductID == product.ProductID)
                                        .Sum(x => x.Quantity);
                }

                ProductReport report = new ProductReport()
                {
                    productId = product.ProductID,
                    productName = product.ProductName,
                    vendorName = product.Vendor.VendorName,
                    totalQuantitySold = totalQuantitySold,
                    totalIncomes = product.BasePrice * totalQuantitySold
                };

                reports.Add(report);
            }

            return reports;
        }
Beispiel #8
0
        private void btnProd_Click(object sender, EventArgs e)
        {
            ProductReport objPro  = new ProductReport();
            rptViewer     objView = new rptViewer();

            if (!String.IsNullOrEmpty(txtSearch.Text))
            {
                objPro.SetParameterValue("@ProductID", txtSearch.Text);

                ProductBL obj = new ProductBL()
                {
                    ProductID = Convert.ToInt32(txtSearch.Text)
                };
                var dt = obj.SearchByPRod();
                if (dt != null)
                {
                    objPro.SetDataSource(dt);
                    objView.crptViewer.ReportSource = objPro;
                    objView.WindowState             = FormWindowState.Maximized;
                    objView.ShowDialog();
                    //crptViewerProd.ReportSource = objPro;
                    txtSearch.Clear();
                }
                else
                {
                    MessageBox.Show("No Record Found");
                }
            }
            else
            {
                MessageBox.Show("Please Enter Product ID");
            }
        }
Beispiel #9
0
 private static void PrintProductReport(string header, ProductReport <ProductPrice> productReport)
 {
     Console.WriteLine($"Report - {header}");
     foreach (var reportLine in productReport.Products)
     {
         Console.WriteLine("{0}, {1}", reportLine.Name, reportLine.Price);
     }
 }
Beispiel #10
0
        public void Will_be_able_to_save_and_retrieve_a_product_dto()
        {
            var productReport = new ProductReport(Guid.NewGuid(), "Test Product");

            _repository.Save(productReport);
            ProductReport sut = _repository.GetByExample <ProductReport>(new { Name = "Test Product" }).FirstOrDefault();

            Assert.That(sut.Id, Is.EqualTo(productReport.Id));
            Assert.That(sut.Name, Is.EqualTo(productReport.Name));
        }
Beispiel #11
0
        private void productReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form c in this.MdiChildren)
            {
                c.Close();
            }
            ProductReport pr = new ProductReport();

            pr.MdiParent = this;
            pr.Show();
            groupBox1.Hide();
        }
Beispiel #12
0
        internal void Initial(List <RecordProducts> records, StatisticModel statisticModel)
        {
            statisticModel.DataSource = records;


            ProductReport report = new ProductReport(statisticModel.Parameters["PriceSymbol"].ToString());


            string htmlContent = report.ProcessHTMLContent(statisticModel);

            var htmlSource = new HtmlWebViewSource();

            htmlSource.Html = htmlContent;

            _browser.Source = htmlSource;
        }
        private static ProductReport GetReportObject(string itemId, BusinessDbContext bDb)
        {
            ProductDetail productDetail = bDb.ProductDetails.Where(x => x.Id == itemId).Include(x => x.ProductCategory)
                                          .Include(x => x.ProductCategory.ProductGroup).First();

            var report = new ProductReport
            {
                ProductDetailId     = itemId,
                ProductDetailName   = productDetail.Name,
                ProductCategoryId   = productDetail.ProductCategoryId,
                ProductCategoryName = productDetail.ProductCategory.Name,
                ProductGroupId      = productDetail.ProductCategory.ProductGroupId,
                ProductGroupName    = productDetail.ProductCategory.ProductGroup.Name,
            };

            return(report);
        }
Beispiel #14
0
        public Boolean insertProductReport(string productName, int quantity, int totalPay)
        {
            Boolean ret = false; // return variable

            try {
                MongoClient     mc            = new MongoClient("mongodb://*****:*****@ds139428.mlab.com:39428/info_aplicada_ucr");
                MongoServer     ms            = mc.GetServer();
                MongoDatabase   db            = ms.GetDatabase("info_aplicada_ucr");
                var             productReport = new ProductReport(productName, quantity, totalPay);
                MongoCollection collection    = db.GetCollection <ProductReport>("ProductReport");
                collection.Insert <ProductReport>(productReport);
                ret = true;
            }//try
            catch (Exception error) {
                ret = false;
            } //catch
            return(ret);
        }     //insertProductReport
        public async Task <List <ProductReport> > GetProductReport()
        {
            var models = new List <ProductReport>();
            var reader = await SqlHelperExtension.ExecuteReader(_connectionString, SqlConstant.ProcGetProductReport, System.Data.CommandType.StoredProcedure, null);

            while (reader.Read())
            {
                ProductReport model = new ProductReport();
                model.Code           = reader.DefaultIfNull <string>("Code");
                model.Name           = reader.DefaultIfNull <string>("Name");
                model.PeUnitCost     = reader.DefaultIfNull <decimal>("PerUnitCost");
                model.Quantity       = reader.DefaultIfNull <int>("Quantity");
                model.ThresholdValue = reader.DefaultIfNull <int>("ThresholdValue");
                model.Unit           = reader.DefaultIfNull <string>("Unit");
                models.Add(model);
            }

            return(models);
        }
 private void dgvProductList_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.ColumnIndex == ColAvailableQuantity.Index)
     {
         ProductReport productReport = (ProductReport)dgvProductList.Rows[e.RowIndex].DataBoundItem;
         if (productReport.AvailableQuantity <= productReport.LowerLimit)
         {
             e.CellStyle.BackColor = RAG_Red;
         }
         else if (productReport.AvailableQuantity >= productReport.UpperLimit)
         {
             e.CellStyle.BackColor = RAG_Green;
         }
         else
         {
             e.CellStyle.BackColor = RAG_Amber;
         }
     }
     DataGridView_Selected_Cell_CellFormatting(sender, e);
 }
Beispiel #17
0
        private void btnAllRecord_Click(object sender, EventArgs e)
        {
            ProductReport objPro  = new ProductReport();
            rptViewer     objView = new rptViewer();

            ProductBL obj = new ProductBL();
            var       dt  = obj.SearchByPRodCom();

            if (dt != null)
            {
                objPro.SetDataSource(dt);
                objView.crptViewer.ReportSource = objPro;
                objView.WindowState             = FormWindowState.Maximized;
                objView.ShowDialog();
                //crptViewerProd.ReportSource = objPro;
            }
            else
            {
                MessageBox.Show("No Record Found");
            }
        }
        private static void GenerateMongoReportsFromMSSql(MongoCollection<BsonDocument> productReports)
        {
            using (var supermarketEntities = new SupermarketEntities())
            {
                var reportsOrederedByProductId = supermarketEntities.Reports
                                                                    .Include("Product.Vendor")
                                                                    .OrderBy(p => p.ProductId);
                var firstProduct = reportsOrederedByProductId.First();
                int currentProductId = firstProduct.ProductId;
                int totalQuantitySold = 0;
                decimal totalIncome = 0;
                ProductReport productReport;
                Report lastReport = new Report();

                foreach (var report in reportsOrederedByProductId)
                {
                    if (currentProductId != report.ProductId)
                    {
                        productReport = new ProductReport(currentProductId,
                            report.Product.ProductName.ToString(),
                            report.Product.Vendor.VendorName.ToString().Trim(),
                            totalQuantitySold, totalIncome);
                        totalIncome = 0;
                        totalQuantitySold = 0;
                        currentProductId = report.ProductId;
                        productReports.Insert(productReport);
                    }

                    totalIncome += report.Sum;
                    totalQuantitySold += report.Quantity;
                    lastReport = report;
                }

                productReport = new ProductReport(currentProductId,
                            lastReport.Product.ProductName.ToString(),
                            lastReport.Product.Vendor.VendorName.ToString().Trim(),
                            totalQuantitySold, totalIncome);
                productReports.Insert(productReport);
            }
        }
        public async Task <Unit> Handle(CreateProductReportCommand request, CancellationToken cancellationToken)
        {
            var product = await _dbContext.Products.FindAsync(request.ProductId);

            if (product == null)
            {
                throw new NotFoundException("Product was not found");
            }

            var entity = new ProductReport
            {
                ProductId = request.ProductId,
                Reason    = request.Reason,
                Resolved  = false
            };

            await _dbContext.ProductReports.AddAsync(entity, cancellationToken);

            await _dbContext.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Beispiel #20
0
        private void MinStockReport_Load(object sender, EventArgs e)
        {
            ICollection <Product> products;
            List <ProductReport>  productReport = new List <ProductReport>();

            using (MFSContext context = new MFSContext())
            {
                products = context.Products.ToList();
                foreach (var p in products)
                {
                    ProductReport report;


                    report = new ProductReport()
                    {
                        Id   = p.ProductId,
                        Name = p.Name,
                        Cost = (context.OrderDetails
                                .Where(o => o.Product.ProductId == p.ProductId).Count() == 0) ? 0 : context.OrderDetails
                               .Where(o => o.Product.ProductId == p.ProductId).Average(o => o.Cost),
                        Image     = Company.Image,
                        SellPrice = p.SellPrice,
                        Stock     = (context.OrderDetails.Where(o => o.Product.ProductId == p.ProductId).Count() > 0) ?
                                    context.OrderDetails.Where(o => o.Product.ProductId == p.ProductId && o.Remove != 1).Sum(o => o.Quantity) -
                                    context.SaleDetails.Where(s => s.Product.ProductId == p.ProductId && s.Remove != 1).Sum(s => s.Quantity) : 0,
                        CompanyName = Company.Name,
                        MinStock    = p.MinStock,
                        Title       = "Listado de todos los productos."
                    };
                    if (report.MinStock >= report.Stock)
                    {
                        productReport.Add(report);
                    }

                    ProductReportBindingSource.DataSource = productReport;
                    this.reportViewer1.RefreshReport();
                }
            }
        }
        public IActionResult Pdf(Product product)
        {
            ProductCategoryVM productCategoryVM = new ProductCategoryVM();

            productCategoryVM.Products = productService.GetActive();


            ProductReport productReport = new ProductReport(_hostingEnvironment);

            return(File(productReport.Report(productCategoryVM.Products), "application/pdf"));


            //HtmlToPdfConverter converter = new HtmlToPdfConverter();
            //WebKitConverterSettings settings = new WebKitConverterSettings();
            //settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesWindows");
            //converter.ConverterSettings = settings;
            //PdfDocument document = converter.Convert("http://localhost:44347/ManagerPanel/Product/product");
            //MemoryStream memory = new MemoryStream();
            //document.Save(memory);

            //return File(memory.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Output.pdf");
        }
Beispiel #22
0
        private void SaveReport(ProductReport report)
        {
            var db = BusinessDbContext.Create();

            //M dbReport = db.ProductReports.FirstOrDefault(
            //    x => x.ShopId == report.ShopId
            //         && x.ReportTimeType == report.ReportTimeType
            //         && x.Date == report.Date
            //         && x.ProductReportType == report.ProductReportType
            //         && x.ProductDetailId == report.ProductDetailId);

            //if (dbReport == null)
            //{
            //    db.ProductReports.Add(report);
            //}
            //else
            //{
            //    dbReport.PurchaseTotal = report.PurchaseTotal;
            //    dbReport.PurchaseQuantity = report.PurchaseQuantity;
            //    dbReport.PurchasePricePerUnitAverage =
            //        report.PurchaseQuantity == 0 ? 0 : report.PurchaseTotal / report.PurchaseQuantity;

            //    dbReport.SaleTotal = report.SaleTotal;
            //    dbReport.SaleCostTotal = report.SaleCostTotal;
            //    dbReport.SalePriceTotal = report.SalePriceTotal;
            //    dbReport.SaleDiscountTotal = report.SaleDiscountTotal;
            //    dbReport.SaleQuantity = report.SaleQuantity;
            //    dbReport.SaleCostPricePerUnitAverage = report.SaleCostPricePerUnitAverage;
            //    dbReport.SalePricePerUnitAverage = report.SalePricePerUnitAverage;

            //    dbReport.StartingQuantity = report.StartingQuantity;
            //    dbReport.EndingQuantity = report.EndingQuantity;
            //}

            db.SaveChanges();
        }
        public bool DayStartAll(string shopId, DateTime startDate)
        {
            startDate = startDate.Date;
            DateTime yesterday = startDate.AddDays(-1).Date;

            DayEndUpdateAll(shopId, yesterday);

            ReportDbContext   rDb = new ReportDbContext();
            BusinessDbContext bDb = new BusinessDbContext();
            List <string>     ids = bDb.ProductDetails.Where(x => x.ShopId == shopId).Select(x => x.Id).ToList();

            foreach (string pId in ids)
            {
                ProductReport report = GetReportObject(pId, bDb);
                this.SetDefaults(report, shopId, startDate);

                ProductReport yesterdayReport = rDb.ProductReports.Where(x => x.ShopId == shopId && x.ProductDetailId == pId).FirstOrDefault(x => DbFunctions.TruncateTime(x.Date) == yesterday);
                if (yesterdayReport != null)
                {
                    report.QuantityStartingToday = yesterdayReport.QuantityEndingToday;
                }
                var todayExists = rDb.ProductReports.Any(
                    x => x.ShopId == shopId && x.ProductDetailId == pId && DbFunctions.TruncateTime(x.Date) == startDate);
                if (todayExists)
                {
                    this.QuickUpdate(shopId, pId, startDate);
                }
                else
                {
                    rDb.ProductReports.Add(report);
                    rDb.SaveChanges();
                }
            }

            return(true);
        }
Beispiel #24
0
        public ActionResult BarcodeGenerate(int productId, int quantity)
        {
            //{
            //    Document doc = new Document(new iTextSharp.text.Rectangle(24, 12), 5, 5, 1, 1);
            //    try
            //    {

            //        PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(
            //          Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/codes.pdf", FileMode.Create));
            //        doc.Open();

            //        DataTable dt = new DataTable();
            //        dt.Columns.Add("ID");
            //        dt.Columns.Add("Price");
            //        for (int i = 0; i < 20; i++)
            //        {
            //            DataRow row = dt.NewRow();
            //            row["ID"] = "ZS00000000000000" + i.ToString();
            //            row["Price"] = "100," + i.ToString();
            //            dt.Rows.Add(row);
            //        }
            //        System.Drawing.Image img1 = null;
            //        for (int i = 0; i < dt.Rows.Count; i++)
            //        {
            //            if (i != 0)
            //                doc.NewPage();
            //            PdfContentByte cb1 = writer.DirectContent;
            //            BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_BOLDITALIC, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            //            cb1.SetFontAndSize(bf, 2.0f);
            //            cb1.BeginText();
            //            cb1.SetTextMatrix(1.2f, 9.5f);
            //            cb1.ShowText("Safi Garments");
            //            cb1.EndText();

            //            PdfContentByte cb2 = writer.DirectContent;
            //            BaseFont bf1 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            //            cb2.SetFontAndSize(bf1, 1.3f);
            //            cb2.BeginText();
            //            cb2.SetTextMatrix(17.5f, 1.0f);
            //            cb2.ShowText(dt.Rows[i]["Price"].ToString());
            //            cb2.EndText();

            //            iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
            //            iTextSharp.text.pdf.Barcode128 bc = new Barcode128();
            //            bc.TextAlignment = Element.ALIGN_LEFT;
            //            bc.Code = dt.Rows[i]["ID"].ToString();
            //            bc.StartStopText = false;
            //            bc.CodeType = iTextSharp.text.pdf.Barcode128.EAN13;
            //            bc.Extended = true;

            //            //System.Drawing.Image bimg =
            //            //  bc.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
            //            //img1 = bimg;

            //            iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
            //              iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

            //            cb.SetTextMatrix(1.5f, 3.0f);
            //            img.ScaleToFit(60, 5);
            //            img.SetAbsolutePosition(1.5f, 1);
            //            cb.AddImage(img);
            //        }
            //    }
            //    catch
            //    {
            //    }
            //    finally
            //    {
            //        doc.Close();
            //    }

            if (ModelState.IsValid)
            {
                ProductReport paymentReport = new ProductReport();
                byte[]        bytes         = paymentReport.CreateReport();
                return(File(bytes, "application/pdf"));
            }
            return(RedirectToAction("BarcodeGenerate"));
        }
Beispiel #25
0
 public AddReport(ProductReport productReport)
 {
     this.productReport = productReport;
 }
Beispiel #26
0
        public async Task <Tuple <Vm, List <ProductReportViewModel>, int> > GetHistoryByDate(Rm rm)
        {
            var productDetailService = new BaseService <ProductDetail, ProductDetailRequestModel, ProductDetailViewModel>(new BaseRepository <ProductDetail>(Repository.Db));
            var productDetail        = productDetailService.GetById(rm.ParentId);

            var productDetailViewModel = new Vm(productDetail);

            var saleDetailService      = new BaseService <SaleDetail, SaleDetailRequestModel, SaleDetailViewModel>(new BaseRepository <SaleDetail>(Repository.Db));
            var saleDetailRequestModel = new SaleDetailRequestModel("")
            {
                ShopId           = rm.ShopId,
                ProductDetailId  = rm.ParentId,
                Page             = -1,
                IsIncludeParents = true,
                WarehouseId      = rm.WarehouseId,
                StartDate        = rm.StartDate,
                EndDate          = rm.EndDate,
            };
            // this will pull all data

            Tuple <List <SaleDetailViewModel>, int> saleDetailResult = await saleDetailService.SearchAsync(saleDetailRequestModel);

            List <HistoryViewModel> saleDetailHistoryViewModels = saleDetailResult.Item1.ConvertAll(x => new HistoryViewModel(x, productDetail.Name, productDetail.SalePrice)).ToList();

            var purchaseDetailService      = new BaseService <PurchaseDetail, PurchaseDetailRequestModel, PurchaseDetailViewModel>(new BaseRepository <PurchaseDetail>(Repository.Db));
            var purchaseDetailRequestModel = new PurchaseDetailRequestModel("")
            {
                ShopId           = rm.ShopId,
                ProductDetailId  = rm.ParentId,
                Page             = -1,
                PerPageCount     = rm.PerPageCount,
                IsIncludeParents = true,
                WarehouseId      = rm.WarehouseId,
                StartDate        = rm.StartDate,
                EndDate          = rm.EndDate,
            };

            Tuple <List <PurchaseDetailViewModel>, int> purchaseDetailResult = await purchaseDetailService.SearchAsync(purchaseDetailRequestModel);

            List <HistoryViewModel> purchaseDetailHistoryViewModels = purchaseDetailResult.Item1.ConvertAll(x => new HistoryViewModel(x, productDetail.Name, productDetail.CostPrice)).ToList();

            saleDetailHistoryViewModels.AddRange(purchaseDetailHistoryViewModels);
            List <HistoryViewModel> merged = saleDetailHistoryViewModels.OrderByDescending(x => x.Date).ToList();

            List <IGrouping <DateTime, HistoryViewModel> > list = merged.GroupBy(x => x.Date.Date).ToList();

            List <ProductReportViewModel> reportModels = new List <ProductReportViewModel>();

            foreach (IGrouping <DateTime, HistoryViewModel> groupModels in list)
            {
                double purchasedToday = groupModels.Where(x => x.Type == "Purchase").Sum(x => x.Quantity);
                double soldToday      = groupModels.Where(x => x.Type == "Sale").Sum(x => x.Quantity);

                double soldPendingToday = groupModels.Where(x => x.Type == "Sale" && x.OrderState == OrderState.Pending)
                                          .Sum(x => x.Quantity);

                double soldProcessingToday = groupModels.Where(x => x.Type == "Sale" && x.OrderState > OrderState.Pending && x.OrderState < OrderState.Delivered)
                                             .Sum(x => x.Quantity);

                double soldDoneToday = groupModels.Where(x => x.Type == "Sale" && x.OrderState != OrderState.Cancel && x.OrderState >= OrderState.Delivered)
                                       .Sum(x => x.Quantity);

                double purchasedAmount = groupModels.Where(x => x.Type == "Purchase").Sum(x => x.Total);
                double soldAmount      = groupModels.Where(x => x.Type == "Sale").Sum(x => x.Total);

                ProductReport reportModel = new ProductReport()
                {
                    Id                          = productDetail.Id,
                    Date                        = groupModels.Key,
                    ProductDetailId             = productDetail.Id,
                    IsActive                    = productDetail.IsActive,
                    ShopId                      = productDetail.ShopId,
                    ProductCategoryId           = productDetail.ProductCategoryId,
                    QuantityPurchaseToday       = purchasedToday,
                    QuantitySaleToday           = soldToday,
                    QuantitySalePendingToday    = soldPendingToday,
                    QuantitySaleProcessingToday = soldProcessingToday,
                    QuantitySaleDoneToday       = soldDoneToday,
                    AmountPurchaseToday         = purchasedAmount,
                    AmountSaleToday             = soldAmount,
                };

                reportModels.Add(new ProductReportViewModel(reportModel));
            }

            return(new Tuple <Vm, List <ProductReportViewModel>, int>(productDetailViewModel, reportModels, reportModels.Count));
        }
 protected override void SetupDependencies()
 {
     OnDependency <IReportingRepository>()
     .Setup(x => x.Save(It.IsAny <ProductReport>()))
     .Callback <ProductReport>(a => SavedProductObject = a);
 }
        public string QuickUpdate(string shopId, string itemId, DateTime date)
        {
            date = date.Date;
            ReportDbContext   rDb = new ReportDbContext();
            BusinessDbContext bDb = new BusinessDbContext();

            ProductReport report = rDb.ProductReports.FirstOrDefault(
                x => x.ShopId == shopId && x.ProductDetailId == itemId && x.Date == date);

            if (report == null)
            {
                report = GetReportObject(itemId, bDb);

                this.SetDefaults(report, shopId, date);
                rDb.ProductReports.Add(report);
                rDb.SaveChanges();
                report = rDb.ProductReports.First(x => x.Id == report.Id);
            }

            var saleDetails =
                bDb.SaleDetails
                .Where(x => x.ShopId == shopId &&
                       DbFunctions.TruncateTime(x.Created) == date)
                .Where(x => x.ProductDetailId == itemId).AsQueryable();
            var purchaseDetails =
                bDb.PurchaseDetails
                .Where(x => x.ShopId == shopId &&
                       DbFunctions.TruncateTime(x.Created) == date)
                .Where(x => x.ProductDetailId == itemId).AsQueryable();

            var saleListToday     = saleDetails.ToList();
            var purchaseListToday = purchaseDetails.ToList();

            // quantities
            report.QuantityPurchaseToday = purchaseListToday.Sum(x => x.Quantity);
            report.QuantitySaleToday     = saleListToday.Sum(x => x.Quantity);
            report.QuantityEndingToday   =
                report.QuantityStartingToday + report.QuantityPurchaseToday - report.QuantitySaleToday;

            // sale amounts
            report.AmountSaleToday        = saleListToday.Sum(x => x.Total);
            report.AmountCostForSaleToday = saleListToday.Sum(x => x.CostTotal);
            report.AmountReceivedToday    = saleListToday.Sum(x => x.PaidAmount);
            report.AmountReceivableToday  = saleListToday.Sum(x => x.DueAmount);
            if (report.QuantitySaleToday > 0)
            {
                report.AmountAverageSalePriceToday = report.AmountSaleToday / report.QuantitySaleToday;
            }

            report.AmountProfitToday = report.AmountSaleToday - report.AmountCostForSaleToday;

            if (report.AmountCostForSaleToday > 0)
            {
                report.AmountProfitPercentToday = report.AmountProfitToday * 100 / report.AmountCostForSaleToday;
            }

            // purchase amounts
            report.AmountPurchaseToday = purchaseListToday.Sum(x => x.CostTotal);
            report.AmountPaidToday     = purchaseListToday.Sum(x => x.Paid);
            report.AmountPayableToday  = purchaseListToday.Sum(x => x.Payable);

            if (report.QuantityPurchaseToday > 0)
            {
                report.AmountAveragePurchasePricePerUnitToday = report.AmountPurchaseToday / report.QuantityPurchaseToday;
            }

            report.Modified = DateTime.Now;
            int i = rDb.SaveChanges();

            return(report.Id);
        }
Beispiel #29
0
        private void LoadTable()
        {
            if (!String.IsNullOrEmpty(Table))
            {
                switch (Table)
                {
                case "Product":
                    List <ProductModel> productModels = new List <ProductModel>();
                    ProductReport       rpt           = new ProductReport();
                    var data = from p in db.Products
                               select new ProductModel
                    {
                        Sku           = p.Sku,
                        DisplayName   = p.DisplayName,
                        Quantity      = (int)p.Quantity,
                        PurcharePrice = p.PurchasePrice,
                        Price         = (double)p.Price,
                        Unit          = p.Unit.DisplayName,
                        Brand         = p.Brand.DisplayName,
                        Category      = p.Category.DisplayName,
                        Supplier      = p.Suplier.DisplayName,
                        Status        = p.Quantity == 0 ?"Hết hàng":"Còn hàng"
                    };
                    rpt.SetDataSource(data);

                    crvReport.ReportSource = rpt;
                    crvReport.Show();
                    break;

                case "Categories":
                    List <CategoriesModel> categoriesModels = new List <CategoriesModel>();
                    CategoriesReport       rpc = new CategoriesReport();
                    var datac = from c in db.Categories
                                select new CategoriesModel
                    {
                        Id          = c.Id,
                        DisplayName = c.DisplayName,
                        Status      = c.Status ? "Kích hoạt" : "Ẩn"
                    };
                    rpc.SetDataSource(datac);

                    crvReport.ReportSource = rpc;
                    crvReport.Show();
                    break;

                case "Brand":
                    List <BrandModel> brandModels = new List <BrandModel>();
                    BrandReport       rpb         = new BrandReport();
                    var datab = from b in db.Brands
                                select new BrandModel
                    {
                        Id          = b.Id,
                        DisplayName = b.DisplayName,
                        Status      = b.Status ? "Kích hoạt" : "Ẩn"
                    };
                    rpb.SetDataSource(datab);

                    crvReport.ReportSource = rpb;
                    crvReport.Show();
                    break;

                case "Supplier":
                    List <SuplierModel> suplierModels = new List <SuplierModel>();
                    SuplierReport       rps           = new SuplierReport();
                    var datas = from s in db.Supliers
                                select new SuplierModel
                    {
                        DisplayName   = s.DisplayName,
                        TaxCode       = s.TaxCode,
                        AccountNumber = s.AcountNumber,
                        Phone         = s.Phone,
                        Email         = s.Email,
                        Adress        = s.Adress,
                        ContractDate  = s.ContractDate,
                        Status        = s.Status ? "Kích hoạt" : "Ẩn"
                    };
                    rps.SetDataSource(datas);

                    crvReport.ReportSource = rps;
                    crvReport.Show();
                    break;

                case "Customer":
                    List <CustomerModel> customerModels = new List <CustomerModel>();
                    CustomerReport       rpcu           = new CustomerReport();
                    var datacu = from cu in db.Customers
                                 select new CustomerModel
                    {
                        DisplayName  = cu.DisplayName,
                        Phone        = cu.Phone,
                        Email        = cu.Email,
                        Adress       = cu.Adress,
                        ContractDate = (DateTime)cu.ContractDate,
                        Status       = cu.Status ? "Kích hoạt" : "Ẩn"
                    };
                    rpcu.SetDataSource(datacu);

                    crvReport.ReportSource = rpcu;
                    crvReport.Show();
                    break;

                case "Input":
                    InputReport rpi   = new InputReport();
                    var         datai = from i in db.InputDetails
                                        select new
                    {
                        Id          = i.Input.Id,
                        DisplayName = i.Input.DisplayName,
                        InputDate   = i.Input.InputDate,
                        Status      = i.Input.Status ? "Đã nhập" : "Chờ duyệt",
                        ProductId1  = i.ProductId,
                        Quantity1   = i.Quantity,
                        Price1      = i.Price
                    };
                    rpi.SetDataSource(datai);

                    crvReport.ReportSource = rpi;
                    crvReport.Show();
                    break;

                case "Output":
                    break;

                default:
                    MessageBox.Show("Vui lòng chọn 1 bảng");
                    break;
                }
            }
            else
            {
                MessageBox.Show("Lỗi thao tác", "Vui lòng chọn 1 bảng để in !", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        // GET: Producers/Reports
        public async Task <IActionResult> Reports(ProducerReportViewModel report)
        {
            report.Producers    = Add0Dropdown(new SelectList(_context.Set <Producer>(), "ProducerId", "BusinessName"), "producer");
            report.ProductTypes = Add0Dropdown(new SelectList(_context.Set <ProductType>(), "ProductTypeId", "Description"), "product type");


            var OrderProducts = await _context.OrderProduct
                                .Include(op => op.Product)
                                .ThenInclude(p => p.ProductType)
                                .Include(op => op.Order)
                                .ToListAsync();


            if (report.selectedProducer != null)
            {
                var ProductsThisProducer = await _context.Products.Where(p => p.ProducerId == report.selectedProducer.ProducerId).ToListAsync();

                var PTheseDates = ProductsThisProducer.Where(p => p.Added <= report.EndDate && p.Added >= report.StartDate);

                var OPThisProducer = OrderProducts.Where(op => op.Product.ProducerId == report.selectedProducer.ProducerId);
                var OPTheseDates   = OPThisProducer.Where(op => op.Order.OrderDate <= report.EndDate && op.Order.OrderDate >= report.StartDate);


                //ICollection<ProductReport> soldProducts = new ICollection<ProductReport>();

                foreach (OrderProduct op in OPTheseDates)
                {
                    //Calculate the time to expire for this product

                    TimeSpan expirationTime = TimeSpan.FromDays(Convert.ToDouble(op.Product.ProductType.TimeToExpire));
                    op.Product.ExpirationDate = op.Product.Added.Add(expirationTime);



                    if (report.soldProducts != null && report.soldProducts.Any(pr => pr.Product.ProductId == op.ProductId))
                    {
                        ProductReport thisProductReport = report.soldProducts
                                                          .FirstOrDefault(pr => pr.Product.ProductId == op.ProductId);
                        report.soldProducts.Remove(thisProductReport);
                        thisProductReport.Sold += 1;



                        //thisProductReport.Product.ExpirationDate = thisProductReport.Product.Added.Add(expirationTime);
                        if (thisProductReport.Product.ExpirationDate < report.EndDate)
                        {
                            //TODO if expiration date has passed, add expiration quantity
                            thisProductReport.Expired = thisProductReport.Product.Quantity - thisProductReport.Sold;
                        }
                        else
                        {
                            thisProductReport.Expired = 0;
                        }

                        report.soldProducts.Add(thisProductReport);
                        var count = report.soldProducts.Count();
                    }
                    else
                    {
                        ProductReport ProductReport = new ProductReport();
                        ProductReport.Product = op.Product;
                        ProductReport.Sold    = 1;

                        if (ProductReport.Product.ExpirationDate < report.EndDate)
                        {
                            //TODO if expiration date has passed, add expiration quantity
                            ProductReport.Expired = ProductReport.Product.Quantity - ProductReport.Sold;
                        }
                        else
                        {
                            ProductReport.Expired = 0;
                        }

                        report.soldProducts.Add(ProductReport);
                    }

                    report.TotalSales += op.Product.Price;
                }
                int countPopular = 0;
                foreach (ProductReport pr in report.soldProducts)
                {
                    report.TotalLosses += pr.Expired * pr.Product.Price;
                    int productCount = pr.Sold;
                    if (productCount > countPopular)
                    {
                        report.MostPopular = pr.Product;
                    }
                }
            }


            return(View(report));
        }
Beispiel #31
0
 void Application_Start(object sender, EventArgs e)
 {
     ProductReport prod = new ProductReport();
 }
        public void Execute(ProductCreatedEvent e)
        {
            var productReport = new ProductReport(e.ProductId, e.Name);

            _reportingRepository.Save(productReport);
        }