Beispiel #1
0
        public ActionResult ListItems(decimal todayCode)
        {
            var lst = _da.GetSummaryProductsByToDayCode(todayCode);

            //lay nha cung cap theo categoryid
            var suppliersupports = _supplierDa.GetSupplierByProductIds(lst.Select(n => n.CateID.Value).ToList());


            var model = new List <DNRequestWareTotalItem>();


            //lay so luong da goi nha cung cap
            var products = _productToDayDa.GetListByToDay(todayCode);

            products = products.GroupBy(m => new { m.SupplierId, m.ProductId, m.SupplierName, m.SupplierPhone, m.Price }).Select(m => new TotalProductToDayItem()
            {
                SupplierName  = m.Key.SupplierName,
                ProductId     = m.Key.ProductId,
                SupplierId    = m.Key.SupplierId,
                SupplierPhone = m.Key.SupplierPhone,
                Price         = m.Key.Price,
                Quantity      = m.Sum(n => n.Quantity)
            }).ToList();

            foreach (var dnRequestWareItem in lst)
            {
                var item = new DNRequestWareTotalItem()
                {
                    CateID      = dnRequestWareItem.CateID,
                    Quantity    = dnRequestWareItem.Quantity,
                    ProductName = dnRequestWareItem.ProductName
                };

                item.Details = new List <TotalProductToDayItem>();

                var notConfirm = _da.GetTotalProductNotConfirm(todayCode);

                //lay so luong nha cung cap co
                var suppliers = _amountProductDa.GetAmount(dnRequestWareItem.CateID.Value, todayCode);

                foreach (var supplierAmountProductItem in suppliers)
                {
                    var detail = new TotalProductToDayItem()
                    {
                        SupplierName   = supplierAmountProductItem.SupplierName,
                        ProductId      = supplierAmountProductItem.ProductID.Value,
                        SupplierId     = supplierAmountProductItem.SupplierId,
                        QuantityActive = supplierAmountProductItem.AmountEstimate - supplierAmountProductItem.AmountPayed
                    };

                    var tmp = products.FirstOrDefault(m => m.ProductId == supplierAmountProductItem.ProductID && m.SupplierId == supplierAmountProductItem.SupplierId);
                    if (tmp != null)
                    {
                        detail.Quantity = tmp.Quantity;
                        detail.Price    = tmp.Price;
                    }
                    item.Details.Add(detail);
                    var supplier = suppliersupports
                                   .FirstOrDefault(m => m.ID == supplierAmountProductItem.SupplierId);
                    if (supplier != null)
                    {
                        detail.SupplierPhone = supplier.Mobile;
                    }
                }

                var itemConfirm = notConfirm.FirstOrDefault(m => m.CateID == item.CateID);
                if (itemConfirm != null)
                {
                    item.QuantityNotConfirm = itemConfirm.Quantity;
                }

                item.Details = item.Details.OrderByDescending(m => m.Quantity).ToList();

                //calculate so luong da nhap
                item.QuantityActive = item.Details.Sum(m => m.Quantity);
                model.Add(item);
            }

            return(Json(model));
        }