public async Task <Tuple <WarehouseViewModel, List <HistoryViewModel>, int> > GetHistory(WarehouseRequestModel request)
        {
            var wareService = new BaseService <Warehouse, WarehouseRequestModel, WarehouseViewModel>(new BaseRepository <Warehouse>(Repository.Db));

            var warehouse = wareService.GetById(request.ParentId);

            var warehouseViewModel = new WarehouseViewModel(warehouse);

            var saleService = new BaseService <SaleDetail, SaleDetailRequestModel, SaleDetailViewModel>(new BaseRepository <SaleDetail>(Repository.Db));

            var saleDetailRequestModel = new SaleDetailRequestModel("")
            {
                ShopId           = request.ShopId,
                WarehouseId      = request.ParentId,
                Page             = -1,
                IsIncludeParents = true
            };

            Tuple <List <SaleDetailViewModel>, int> result = await saleService.SearchAsync(saleDetailRequestModel);

            List <HistoryViewModel> viewModels = result.Item1.ConvertAll(x => new HistoryViewModel(x, x.ProductDetailName, x.SalePricePerUnit)).ToList();

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

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

            List <HistoryViewModel> models = purchaseDetailResult.Item1.ConvertAll(x => new HistoryViewModel(x, x.ProductDetailName, x.CostPricePerUnit)).ToList();

            viewModels.AddRange(models);
            List <HistoryViewModel> merged = viewModels.OrderByDescending(x => x.Date).ToList();

            return(new Tuple <WarehouseViewModel, List <HistoryViewModel>, int>(warehouseViewModel, viewModels, viewModels.Count));
        }
示例#2
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));
        }
示例#3
0
        public async Task <Tuple <Vm, List <HistoryViewModel>, int> > GetHistory(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 service1 = new BaseService <SaleDetail, SaleDetailRequestModel, SaleDetailViewModel>(new BaseRepository <SaleDetail>(Repository.Db));
            var saleDetailRequestModel = new SaleDetailRequestModel("")
            {
                ShopId           = rm.ShopId,
                ProductDetailId  = rm.ParentId,
                Page             = rm.Page,
                IsIncludeParents = true,
                WarehouseId      = rm.WarehouseId,
                PerPageCount     = rm.PerPageCount,
                StartDate        = rm.StartDate,
                EndDate          = rm.EndDate
            };
            // this will pull all data

            Tuple <List <SaleDetailViewModel>, int> result = await service1.SearchAsync(saleDetailRequestModel);

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

            var stockTransferService =
                new BaseService <StockTransferDetail, StockTransferDetailRequestModel, StockTransferDetailViewModel>(
                    new BaseRepository <StockTransferDetail>(Repository.Db));
            var stockTransferDetailInRequestModel = new StockTransferDetailRequestModel("")
            {
                ShopId                 = rm.ShopId,
                ProductDetailId        = rm.ParentId,
                Page                   = rm.Page,
                IsIncludeParents       = true,
                DestinationWarehouseId = rm.WarehouseId,
                PerPageCount           = rm.PerPageCount,
                StartDate              = rm.StartDate,
                EndDate                = rm.EndDate
            };
            var stockInResult = await stockTransferService.SearchAsync(stockTransferDetailInRequestModel);

            var stockInViewModels = stockInResult.Item1.ConvertAll(x => new HistoryViewModel(x, productDetail.Name, "StockIn")).ToList();

            var stockTransferDetailOutRequestModel = new StockTransferDetailRequestModel("")
            {
                ShopId            = rm.ShopId,
                ProductDetailId   = rm.ParentId,
                Page              = rm.Page,
                IsIncludeParents  = true,
                SourceWarehouseId = rm.WarehouseId,
                PerPageCount      = rm.PerPageCount,
                StartDate         = rm.StartDate,
                EndDate           = rm.EndDate
            };
            var stockOutResult = await stockTransferService.SearchAsync(stockTransferDetailOutRequestModel);

            var stockOutViewModels = stockOutResult.Item1.ConvertAll(x => new HistoryViewModel(x, productDetail.Name, "StockOut")).ToList();

            var purchaseDetailService      = new BaseService <PurchaseDetail, PurchaseDetailRequestModel, PurchaseDetailViewModel>(new BaseRepository <PurchaseDetail>(Repository.Db));
            var purchaseDetailRequestModel = new PurchaseDetailRequestModel("")
            {
                ShopId           = rm.ShopId,
                ProductDetailId  = rm.ParentId,
                Page             = rm.Page,
                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> models = purchaseDetailResult.Item1.ConvertAll(x => new HistoryViewModel(x, productDetail.Name, productDetail.CostPrice)).ToList();


            viewModels.AddRange(models);
            viewModels.AddRange(stockInViewModels);
            viewModels.AddRange(stockOutViewModels);
            List <HistoryViewModel> merged = viewModels.OrderByDescending(x => x.Date.Date).ToList();

            double purchased = merged.Where(x => x.Type == "Purchase").Sum(x => x.Quantity);
            double sold      = merged
                               .Where(x => x.Type == "Sale" && x.OrderState > OrderState.Pending && x.OrderState < OrderState.Cancel)
                               .Sum(x => x.Quantity);
            double stockInQuantity = merged
                                     .Where(x => x.Type == "StockIn" && x.TransferState == StockTransferState.Approved.ToString())
                                     .Sum(x => x.Quantity);
            double stockOutQuantity = merged
                                      .Where(x => x.Type == "StockOut" && x.TransferState == StockTransferState.Approved.ToString())
                                      .Sum(x => x.Quantity);

            productDetailViewModel.Purchased = purchased;
            productDetailViewModel.Sold      = sold;
            productDetailViewModel.StockIn   = stockInQuantity;
            productDetailViewModel.StockOut  = stockOutQuantity;
            productDetailViewModel.OnHand    = purchased
                                               + stockInQuantity
                                               - sold
                                               - stockOutQuantity;

            return(new Tuple <Vm, List <HistoryViewModel>, int>(productDetailViewModel, merged, viewModels.Count));
        }