private void RefreschData()
        {
            CanSave_CounterOrdersSelected = 0;
            //package uit db halen
            ProductsForStockManagementPackageDTO _ProductsForStockManagement =
                _appDbRespository.Product.GetAllForStockManagement();


            ProductsAll = _ProductsForStockManagement.ProductForStockDTO.DistinctBy(p => p.EAN).Select(x => x).ToList();
            AvailableTempOrdersOutdependentOfSelectedProduct = null;
            OrdersInSelected = null;

            //werkLijst maken van TemporyOrderedOuts objecten
            _workingTempOrdersOut = _ProductsForStockManagement.ProductForStockDTO
                                    //.Where(x => x.EAN == SelectedProduct.EAN)
                                    .Select(p => new TemporyOrderedOuts
            {
                EAN             = p.EAN,
                ProductName     = p.ProductTittle,
                CalculatedCount = Math.Max(p.MaxCountInStock - p.CountInStock - p.CountInProgress, 1),
                SettedCount     = Math.Max(p.MaxCountInStock - p.CountInStock - p.CountInProgress, 1),
                UnitPrice       = p.UnitPrice,
                ID_supplier     = p.ID_Supplier,
                Name_supplier   = p.SuplierName,
                IsChecked       = false,
            })
                                    .OrderBy(x => x.UnitPrice)
                                    .ToList();
        }
Exemplo n.º 2
0
        public ProductsForStockManagementPackageDTO GetAllForStockManagement()
        {
            ProductsForStockManagementPackageDTO terug = new ProductsForStockManagementPackageDTO();

            List <ProductForStockDTO> opgehaald;
            List <SupplierMinDTO>     opgehaaldSupplierMin;

            List <int> tmp = new List <int>();

            using (KfsContext ctx = new KfsContext(_constring))
            {
                //ophalen van data
                //gegroepeerd per EAN en employeeId en hieruit enkel het laatste id nemen, datum ontbrak :-(
                opgehaald = ctx.Products.Join(ctx.Supplier_Product_Prices,
                                              p => p.EAN,
                                              spp => spp.EAN_Product,
                                              (p, ssp) => new ProductForStockDTO()
                {
                    EAN               = p.EAN,
                    ProductTittle     = p.ProductTitle,
                    CountInStock      = p.CountInStock,
                    MinCountInStock   = p.MinCountInStock,
                    MaxCountInStock   = p.MaxCountInStock,
                    WareHouseLocation = p.WareHouseLocation,
                    UnitPrice         = ssp.UnitPrice,
                    ID_Supplier       = ssp.Id_Supplier,
                    OploopNummer      = ssp.Id,
                })
                            .GroupBy(x => new { x.ID_Supplier, x.EAN }).Select(g => g.OrderByDescending(y => y.OploopNummer).FirstOrDefault())
                            //.OrderByDescending(x => x).Take(100)
                            .ToList();

                Console.WriteLine("===================================================================");
                foreach (var item in opgehaald)
                {
                    int xxx = 0;
                    try
                    {
                        xxx = ctx.OrderIns.Join(ctx.OrderLineIns,
                                                o => o.Id,
                                                ol => ol.Id_OrderIn,
                                                (o, ol) => new
                        {
                            idAfgehandeld = o.Id_HandledBy,
                            EAN           = ol.EAN_Product,
                            NumOfProducts = ol.NumberOfProducts,
                        })
                              .Where(x => x.EAN == item.EAN && x.idAfgehandeld == null).Select(x => x.NumOfProducts).Sum();
                    }
                    catch { }

                    item.CountInProgress = xxx;
                }
                Console.WriteLine("===================================================================");



                //id's van de suppliers die betrekking hebben op de gevonden lijst distincten
                tmp = opgehaald.Select(x => x.ID_Supplier).Distinct().ToList();


                opgehaaldSupplierMin = ctx.Suppliers
                                       .Where(t => tmp.Contains(t.Id))
                                       .Select(s => new SupplierMinDTO()
                {
                    Name = s.Name,
                    Id   = s.Id
                })
                                       .ToList();
            }

            foreach (var item in opgehaald)
            {
                item.SuplierName = opgehaaldSupplierMin.Where(x => x.Id == item.ID_Supplier).Select(x => x.Name).FirstOrDefault();
                //1 als bijbestellen nodig is
                item.IsOrderNeeded = (item.CountInStock + item.CountInProgress) < item.MinCountInStock;
            }

            //Console.WriteLine("===================================================");

            //foreach (var item in opgehaaldSupplierMin)
            //{
            //    //Console.WriteLine(item.EAN +"," + item.ID_Supplier + "," + item.UnitPrice);
            //    //Console.WriteLine(item);
            //    Console.WriteLine(item.Id + ":" + item.Name);
            //}

            //Console.WriteLine("===================================================");

            terug.ProductForStockDTO = opgehaald;
            terug.SupplierMinkDTO    = opgehaaldSupplierMin;

            return(terug);
        }