예제 #1
0
        public ActionResult Detail(int?Id)
        {
            var model = new RequestInboundViewModel();
            var modelproductInbound  = new ProductInboundViewModel();
            var modelproductOutbound = new ProductOutboundViewModel();
            var requestInbound       = new vwRequestInbound();
            var productInbound       = new vwProductInbound();
            var productOutbound      = new vwProductOutbound();

            if (Id != null && Id.Value > 0)
            {
                requestInbound = RequestInboundRepository.GetvwRequestInboundById(Id.Value);
                if (requestInbound.InboundId != null && requestInbound.InboundId.Value > 0)
                {
                    productInbound = productInboundRepository.GetvwProductInboundFullById(requestInbound.InboundId.Value);
                    AutoMapper.Mapper.Map(productInbound, modelproductInbound);
                    modelproductInbound.CreatedUserName = userRepository.GetUserById(modelproductInbound.CreatedUserId.Value).FullName;
                }
                if (requestInbound.OutboundId != null && requestInbound.OutboundId.Value > 0)
                {
                    productOutbound = productOutboundRepository.GetvwProductOutboundFullById(requestInbound.OutboundId.Value);
                    AutoMapper.Mapper.Map(productOutbound, modelproductOutbound);
                    modelproductOutbound.CreatedUserName = userRepository.GetUserById(modelproductOutbound.CreatedUserId.Value).FullName;
                }
            }
            ViewBag.productInbound  = modelproductInbound;
            ViewBag.productOutbound = modelproductOutbound;
            AutoMapper.Mapper.Map(requestInbound, model);
            model.CreatedUserName = userRepository.GetUserById(requestInbound.CreatedUserId.Value).FullName;
            model.DetailList      = RequestInboundRepository.GetAllvwRequestInboundDetailsByInvoiceId(requestInbound.Id).AsEnumerable().Select(x =>
                                                                                                                                               new RequestInboundDetailViewModel
            {
                Id                = x.Id,
                Price             = x.Price,
                ProductId         = x.ProductId,
                Quantity          = x.Quantity,
                Unit              = x.Unit,
                CategoryCode      = x.CategoryCode,
                ProductName       = x.ProductName,
                ProductCode       = x.ProductCode,
                ProductGroup      = x.ProductGroup,
                Manufacturer      = x.Manufacturer,
                ProductBarCode    = x.ProductBarCode,
                RequestInboundId  = x.RequestInboundId,
                QuantityRemaining = x.QuantityRemaining,
                ProductGroupName  = x.ProductGroupName,
                Image_Name        = x.Image_Name
            }).OrderBy(x => x.Id).ToList();
            var warehouse = WarehouseRepository.GetAllWarehouse().Where(x => x.IsSale == true && x.BranchId == null).ToList();

            if (warehouse.Count() > 0)
            {
                // var wh = warehouse.FirstOrDefault().Id;
                var productList = Domain.Helper.SqlHelper.QuerySP <InventoryViewModel>("spSale_Get_Inventory", new { WarehouseId = "", HasQuantity = "1", ProductCode = "", ProductName = "", CategoryCode = "", ProductGroup = "", BranchId = "", LoCode = "", ProductId = "", ExpiryDate = "" });
                productList = productList.Where(id1 => warehouse.Any(id2 => id2.Id == id1.WarehouseId)).ToList();
                foreach (var item in model.DetailList)
                {
                    var quantity = productList.Where(x => x.ProductId == item.ProductId).Sum(x => x.Quantity);
                    item.QuantityInventoryKT  = quantity == null ? 0 : quantity;
                    item.QuantityNotCondition = item.QuantityInventoryKT <= 0 ? 1 : 0;
                }
            }
            var ProductInvoiceList = SqlHelper.QuerySP <ProductInvoiceViewModel>("spSale_LiabilitiesDrugStore", new
            {
                StartDate  = "",
                EndDate    = "",
                branchId   = model.BranchId,
                CityId     = "",
                DistrictId = ""
            }).ToList();

            //var inbound = productInboundRepository.GetAllProductInbound().Where(x => x.BranchId == model.BranchId&&x.IsArchive==true).Sum(x => x.TotalAmount);
            model.Liabilities = 0;
            var invoice = ProductInvoiceList.Where(x => x.AccountancyUserId == null).Sum(x => x.TotalAmount);

            model.Liabilities    = invoice;
            model.MaxDebitAmount = branchRepository.GetBranchById(model.BranchId.Value).MaxDebitAmount;
            var tonkho = Domain.Helper.SqlHelper.QuerySP <InventoryViewModel>("spSale_Get_Inventory", new { WarehouseId = model.WarehouseDestinationId, HasQuantity = "1", ProductCode = "", ProductName = "", CategoryCode = "", ProductGroup = "", BranchId = "", LoCode = "", ProductId = "", ExpiryDate = "" }).ToList();

            model.DinhMucKho = tonkho.Sum(x => x.Quantity * x.ProductPriceOutbound) + invoice;
            //var user = userRepository.GetUserById(WebSecurity.CurrentUserId);
            //ViewBag.User = user;
            return(View(model));
        }
        public ActionResult Detail(int?Id)
        {
            var model = new RequestInboundViewModel();
            var modelproductInbound  = new ProductInboundViewModel();
            var modelproductOutbound = new ProductOutboundViewModel();
            var requestInbound       = new vwRequestInbound();
            var productInbound       = new vwProductInbound();
            var productOutbound      = new vwProductOutbound();

            if (Id != null && Id.Value > 0)
            {
                requestInbound = RequestInboundRepository.GetvwRequestInboundById(Id.Value);
                if (requestInbound.InboundId != null && requestInbound.InboundId.Value > 0)
                {
                    productInbound = productInboundRepository.GetvwProductInboundById(requestInbound.InboundId.Value);
                    AutoMapper.Mapper.Map(productInbound, modelproductInbound);
                    modelproductInbound.CreatedUserName = userRepository.GetUserById(modelproductInbound.CreatedUserId.Value).FullName;
                }
                if (requestInbound.OutboundId != null && requestInbound.OutboundId.Value > 0)
                {
                    productOutbound = productOutboundRepository.GetvwProductOutboundById(requestInbound.OutboundId.Value);
                    AutoMapper.Mapper.Map(productOutbound, modelproductOutbound);
                    modelproductOutbound.CreatedUserName = userRepository.GetUserById(modelproductOutbound.CreatedUserId.Value).FullName;
                }
            }
            ViewBag.productInbound  = modelproductInbound;
            ViewBag.productOutbound = modelproductOutbound;
            AutoMapper.Mapper.Map(requestInbound, model);
            model.CreatedUserName = userRepository.GetUserById(requestInbound.CreatedUserId.Value).FullName;
            model.DetailList      = RequestInboundRepository.GetAllvwRequestInboundDetailsByInvoiceId(requestInbound.Id).AsEnumerable().Select(x =>
                                                                                                                                               new RequestInboundDetailViewModel
            {
                Id                = x.Id,
                Price             = x.Price,
                ProductId         = x.ProductId,
                Quantity          = x.Quantity,
                Unit              = x.Unit,
                CategoryCode      = x.CategoryCode,
                ProductName       = x.ProductName,
                ProductCode       = x.ProductCode,
                ProductGroup      = x.ProductGroup,
                Manufacturer      = x.Manufacturer,
                ProductBarCode    = x.ProductBarCode,
                RequestInboundId  = x.RequestInboundId,
                QuantityRemaining = x.QuantityRemaining,
                Image_Name        = Erp.BackOffice.Helpers.Common.KiemTraTonTaiHinhAnh(x.Image_Name, "product-image-folder", "product")
            }).ToList();

            model.GroupProduct = model.DetailList.GroupBy(x => new { x.ProductGroup }, (key, group) => new RequestInboundDetailViewModel
            {
                ProductGroup = key.ProductGroup,
                ProductId    = group.FirstOrDefault().ProductId,
                Id           = group.FirstOrDefault().Id
            }).ToList();

            foreach (var item in model.GroupProduct)
            {
                if (!string.IsNullOrEmpty(item.ProductGroup))
                {
                    var ProductGroupName = categoryRepository.GetCategoryByCode("Categories_product").Where(x => x.Value == item.ProductGroup).FirstOrDefault();
                    item.ProductGroupName = ProductGroupName.Name;
                }
            }
            var user = userRepository.GetUserById(WebSecurity.CurrentUserId);

            ViewBag.User = user;
            return(View(model));
        }