Exemplo n.º 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);
        }
        public IList <PurchaseHeader> GetPurchaseHeaders(RequestCategoriesEnum category)
        {
            IList <PurchaseHeader> listOfPurchaseHeader;

            if (category == RequestCategoriesEnum.采购退货)
            {
                listOfPurchaseHeader = FindBy(x => x.RequestCategory == category).Include(x => x.Purchases.Select(s => s.PurchaseApplication.Item.Positions))
                                       .ToList();
            }
            else
            {
                listOfPurchaseHeader = FindBy(x => x.RequestCategory != RequestCategoriesEnum.采购退货).Include(x => x.Purchases.Select(s => s.PurchaseApplication.Item.Positions))
                                       .ToList();
            }

            return(listOfPurchaseHeader);
        }
        public static void SetCategoryColor(RequestCategoriesEnum requestCategoriesEnum, RowCellStyleEventArgs e)
        {
            switch (requestCategoriesEnum)
            {
            case RequestCategoriesEnum.材料需求:
                e.Appearance.BackColor = Color.AntiqueWhite;
                break;

            case RequestCategoriesEnum.工程车维修:
                e.Appearance.BackColor = Color.Cornsilk;
                break;

            case RequestCategoriesEnum.工具维修:
                e.Appearance.BackColor = Color.LightSlateGray;
                break;

            case RequestCategoriesEnum.工程车补给:
                e.Appearance.BackColor = Color.LemonChiffon;
                break;

            case RequestCategoriesEnum.员工补给:
                e.Appearance.BackColor = Color.LavenderBlush;
                break;

            case RequestCategoriesEnum.物品退回:
                e.Appearance.BackColor = Color.MintCream;
                break;

            case RequestCategoriesEnum.采购退货:
                e.Appearance.BackColor = Color.MistyRose;
                break;

            case RequestCategoriesEnum.工具借出:
                e.Appearance.BackColor = Color.Honeydew;
                break;
            }
        }
 public void SetCurrentRequestCategory(RequestCategoriesEnum requestCategory)
 {
     _currentRequestCategory = requestCategory;
 }
        public IList <RequestHeader> GetRequestHeadersByCategory(RequestCategoriesEnum requestCategory)
        {
            var result = FindBy(x => x.RequestCategory == requestCategory).Include(c => c.Contract).Include(x => x.Requests.Select(i => i.Item.Positions)).ToArray();

            return(result);
        }
Exemplo n.º 6
0
        public IList <PurchaseApplicationHeaderViewModel> GetAllPurchaseApplicationHeaderViewModels(RequestCategoriesEnum category)
        {
            var listOfPurchaseApplications = _purchaseApplicationHeaderRepository.GetAllPurchaseApplicationHeaders();

            PurchaseApplicationHeaderViewModel[] models = _mapper.Map <PurchaseApplicationHeaderViewModel[]>(listOfPurchaseApplications);
            models = category == RequestCategoriesEnum.采购退货 ? models.Where(x => x.RequestCategory == category).ToArray() : models.Where(x => x.RequestCategory != RequestCategoriesEnum.采购退货).ToArray();

            if (category == RequestCategoriesEnum.材料需求)
            {
                foreach (var item in models)
                {
                    if (item.PurchaseApplicationViewModels.Count() == 0)
                    {
                        item.CompletePercentage = 0;
                    }
                    else
                    {
                        item.CompletePercentage = (decimal)
                                                  item.PurchaseApplicationViewModels.Count(x => x.ProcessStatus >= ProcessStatusEnum.采购中) /
                                                  item.PurchaseApplicationViewModels.Count();
                    }
                }
            }
            else
            {
                foreach (var item in models)
                {
                    item.CompletePercentage = (decimal)
                                              item.PurchaseApplicationViewModels.Count(x => x.ProcessStatus >= ProcessStatusEnum.退货中) /
                                              item.PurchaseApplicationViewModels.Count();
                }
            }
            return(models);
        }