Пример #1
0
        //取得全部采购单
        public IList <PurchaseHeaderViewModel> GetAllPurchaseViewModels(RequestCategoriesEnum category)
        {
            var listOfPurchases      = _purchaseHeaderRepository.GetPurchaseHeaders(category).ToList();
            var listOfStocks         = _inStockRepository.GetAll().ToList();
            var listRequesterHeaders = _requestHeaderRepository.GetAll().Include(x => x.Contract);
            var models = _mapper.Map <PurchaseHeaderViewModel[]>(listOfPurchases);
            var listOfPurchasedViewModels = new List <PurchaseViewModel>();

            foreach (var item in models)
            {
                int numerator           = 0;
                int denominator         = item.PurchaseViewModels.Count();
                var purchaseApplication = listOfPurchases.FirstOrDefault(x => x.PurchaseNumber == item.PurchaseNumber)?.Purchases.FirstOrDefault()?.PurchaseApplication;
                if (purchaseApplication != null)
                {
                    var requestHeaderNumber = purchaseApplication.PurchaseApplicationHeader.RequestNumber;
                    var requestHeader       = listRequesterHeaders.FirstOrDefault(x => x.RequestHeaderNumber == requestHeaderNumber);
                    if (category == RequestCategoriesEnum.采购退货)
                    {
                        item.PoNumber = purchaseApplication.SelectedPONumber;
                        numerator     = item.PurchaseViewModels.Count(x => x.Status == ProcessStatusEnum.退货申请完成) +
                                        item.PurchaseViewModels.Count(x => x.Status == ProcessStatusEnum.退货出库);
                    }
                    else
                    {
                        var poNumber = requestHeader?.Contract.PoModel.PoNumber;
                        item.PoNumber = poNumber;
                        numerator     = item.PurchaseViewModels.Count(x => x.Status == ProcessStatusEnum.采购完成) +
                                        item.PurchaseViewModels.Count(x => x.Status == ProcessStatusEnum.采购入库) +
                                        item.PurchaseViewModels.Count(x => x.Status == ProcessStatusEnum.已出库);
                    }
                    item.PurchaseViewModels.ToList().ForEach(x => x.PoNumber = item.PoNumber);
                    item.Priority = purchaseApplication.Priority;
                    if (requestHeader != null)
                    {
                        item.PurchaseType = requestHeader.RequestCategory;
                    }
                }
                item.TotalPrice         = item.PurchaseViewModels.Sum(x => x.TotalPrice);
                item.CompletePercentage = (decimal)numerator / denominator;
                listOfPurchasedViewModels.AddRange(item.PurchaseViewModels);
                //item.PurchaseViewModels.ToList()
                //    .ForEach(x => x.AlreadyInStock = listOfStocks.Where(l => l.PurchaseId == x.PurchaseId).ToArray().Any() ?
                //    listOfStocks.Where(l => l.PurchaseId == x.PurchaseId).Sum(z => z.Total) :
                //    0);
            }
            foreach (var item in listOfPurchasedViewModels)
            {
                item.AlreadyInStock = listOfStocks.Where(l => l.PurchaseId == item.PurchaseId).ToArray().Any() ?
                                      listOfStocks.Where(l => l.PurchaseId == item.PurchaseId).Sum(z => z.Total) :
                                      0;
            }
            foreach (var item in models)
            {
                item.PurchaseViewModels = new BindingList <PurchaseViewModel>(listOfPurchasedViewModels.Where(x => x.PurchaseNumber == item.PurchaseNumber).ToList());
            }
            return(models);
        }
Пример #2
0
        public IList <InStockHeaderViewModel> GetAllInStockHeaderViewModel()
        {
            var listOfInStockHeader = _inStockHeaderRepository.GetAllInStockHeaders();
            var requestHeaders      = _requestHeaderRepository.GetAll().ToList();
            var purchaseHeaders     = _purchaseHeaderRepository.GetAll().ToList();
            var requests            = _requestRepository.GetAll().ToList();
            var purchases           = _purchaseRepository.GetAll().ToList();
            IList <InStockHeaderViewModel> listOfInStockHeaderViewModels = _mapper.Map <InStockHeaderViewModel[]>(listOfInStockHeader);

            foreach (var inStockHeader in listOfInStockHeaderViewModels)
            {
                var requestHeader = requestHeaders.Where(x => x.RequestHeaderNumber == inStockHeader.RequestNumber).FirstOrDefault();

                switch (inStockHeader.InStockCategory)
                {
                case RequestCategoriesEnum.工具维修:
                    inStockHeader.ContractNumber = requestHeader?.Contract?.ContractNumber;
                    break;

                case RequestCategoriesEnum.工程车维修:
                {
                    inStockHeader.ContractNumber = requestHeader?.Contract?.ContractNumber;
                    foreach (var inStock in inStockHeader.InStockViewModels)
                    {
                        var request = requests.FirstOrDefault(x => x.RequestId == inStock.RequestId);
                        if (request != null)
                        {
                            inStock.Price = request.Item.Price;
                        }
                        inStock.TotalPrice = inStock.Price * inStock.Total;
                    }
                    break;
                }

                case RequestCategoriesEnum.工具借出:
                {
                    inStockHeader.ContractNumber = requestHeader?.Contract?.ContractNumber;
                    foreach (var inStock in inStockHeader.InStockViewModels)
                    {
                        inStock.TotalPrice = 0;
                        inStock.Price      = 0;
                    }

                    break;
                }

                case RequestCategoriesEnum.物品退回:
                    inStockHeader.ContractNumber = requestHeader?.Contract?.ContractNumber;
                    break;

                default:
                {
                    var purchaseHeader = purchaseHeaders.Where(x => x.PurchaseNumber == inStockHeader.PurchaseNumber).FirstOrDefault();
                    inStockHeader.PoNumber     = requestHeader?.Contract?.PoModel?.PoNumber;
                    inStockHeader.SupplierName = purchaseHeader?.SupplierId;
                    foreach (var instock in inStockHeader.InStockViewModels)
                    {
                        if (!instock.PurchaseId.HasValue)
                        {
                            continue;
                        }
                        var purchase = purchases.FirstOrDefault(x => x.PurchaseId == instock.PurchaseId);
                        if (purchase == null)
                        {
                            continue;
                        }
                        instock.Price      = purchase.CurrentPurchasePrice;
                        instock.TotalPrice = instock.Price * instock.Total;
                    }

                    break;
                }
                }
            }
            return(listOfInStockHeaderViewModels);
        }