Beispiel #1
0
        public async Task <SearchResult <InventoryDailyReportViewModel> > Search(string tenantId, string userId, string warehouseId, string keyword,
                                                                                 DateTime?fromDate, DateTime?toDate, int page, int pageSize)
        {
            if (string.IsNullOrEmpty(warehouseId))
            {
                return(new SearchResult <InventoryDailyReportViewModel>(-1,
                                                                        _sharedResourceService.GetString(ValidatorMessage.PleaseSelect, _resourceService.GetString("warehouse"))));
            }

            if (!fromDate.HasValue)
            {
                fromDate = DateTime.Today;
            }

            toDate = toDate?.AddDays(1).AddMilliseconds(-1) ?? fromDate.Value.AddDays(1).AddMilliseconds(-1);

            // Check current user is warehouse manager.
            var isWarehouseManager = await _warehouseManagerConfigRepository.CheckExists(warehouseId, userId, tenantId);

            if (!isWarehouseManager)
            {
                return(new SearchResult <InventoryDailyReportViewModel>(-403, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            var inventoryDailyReports = await _inventoryDailyReportRepository.SearchInventoryOpningStock(tenantId, keyword, warehouseId, fromDate.Value,
                                                                                                         page, pageSize, out int totalRows);

            // Lấy về danh sách nhập trong kỳ.
            if (!inventoryDailyReports.Any())
            {
                return(new SearchResult <InventoryDailyReportViewModel>(inventoryDailyReports, totalRows));
            }

            foreach (var inventoryDailyReport in inventoryDailyReports)
            {
                // Lấy về tổng nhập trong kỳ.
                var receivingInPeriod = _goodsReceiptNoteDetailRepository.GetReceivingInPeriod(tenantId, warehouseId,
                                                                                               inventoryDailyReport.ProductId, fromDate.Value, toDate.Value);

                // Lấy về tổng xuất trong kỳ.
                var deliveringInPeriod = _goodsDeliveryNoteDetailRepository.GetDeliveringInPeriod(tenantId, warehouseId,
                                                                                                  inventoryDailyReport.ProductId, fromDate.Value, toDate.Value);

                inventoryDailyReport.ReceivingQuantity    = receivingInPeriod.Quantity;
                inventoryDailyReport.ReceivingValue       = receivingInPeriod.Value;
                inventoryDailyReport.DeliveringQuantity   = deliveringInPeriod.Quantity;
                inventoryDailyReport.DeliveringValue      = deliveringInPeriod.Value;
                inventoryDailyReport.ClosingStockQuantity = inventoryDailyReport.OpeningStockQuantity + receivingInPeriod.Quantity - deliveringInPeriod.Quantity;
                inventoryDailyReport.ClosingStockValue    = inventoryDailyReport.OpeningStockValue + receivingInPeriod.Value - deliveringInPeriod.Value;
            }

            return(new SearchResult <InventoryDailyReportViewModel>(inventoryDailyReports, totalRows));
        }
Beispiel #2
0
        public async Task <SearchResult <InventoryViewModel> > Search(string tenantId, string warehouseId, string userId, DateTime?fromDate,
                                                                      DateTime?toDate, InventoryStatus?status, int page, int pageSize)
        {
            if (!string.IsNullOrEmpty(warehouseId))
            {
                var isWarehouseManagement = await _warehouseManagerConfigRepository.CheckExists(
                    warehouseId, userId, tenantId);

                if (!isWarehouseManagement)
                {
                    return(new SearchResult <InventoryViewModel>(-403, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
                }
            }

            var items = await _inventoryRepository.Search(tenantId, warehouseId, fromDate, toDate, status, page, pageSize, out var totalRows);

            return(new SearchResult <InventoryViewModel>
            {
                TotalRows = totalRows,
                Items = items
            });
        }
Beispiel #3
0
        public async Task <ActionResultResponse <ProductInfoViewModel> > GetProductInfoByCode(string tenantId, string userId, string code,
                                                                                              string warehouseId, GoodsDeliveryNoteType type, DateTime deliveryDate)
        {
            // Kiểm tra người dùng có quyền trên kho hiện tại hay không.
            var isWarehouseManagement = await _warehouseManagerConfigRepository.CheckExists(
                warehouseId, userId, tenantId);

            if (!isWarehouseManagement)
            {
                return(new ActionResultResponse <ProductInfoViewModel>(-403, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            var productInfo = await _goodsReceiptNoteDetailRepository.GetProductInfoByCode(tenantId, warehouseId, code);

            if (productInfo == null)
            {
                return(new ActionResultResponse <ProductInfoViewModel>(-1, _resourceService.GetString("Product you are looking for does not exits.",
                                                                                                      _sharedResourceService.GetString(ErrorMessage.Sorry))));
            }

            // Lấy về số lượng tồn kho của sản phẩm.
            var openingStock = !string.IsNullOrEmpty(productInfo.LotId)
                ? await _inventoryReportRepository.GetOpeningStockByLot(tenantId, warehouseId, productInfo.ProductId, productInfo.LotId,
                                                                        deliveryDate)
                    : await _inventoryReportRepository.GetOpeningStock(tenantId, warehouseId, productInfo.ProductId,
                                                                       deliveryDate);

            if (openingStock == null || openingStock.ClosingStockValue <= 0)
            {
                return(new ActionResultResponse <ProductInfoViewModel>(-2, _resourceService.GetString("Out of stock.",
                                                                                                      _sharedResourceService.GetString(ErrorMessage.Sorry))));
            }

            productInfo.InventoryQuantity = openingStock.ClosingStockQuantity;
            productInfo.Price             = openingStock.ExWarehousePrice;

            productInfo.Price = !string.IsNullOrEmpty(productInfo.LotId)
                ? await _inventoryReportRepository.GetExWarehousePriceByCode(tenantId, warehouseId, code)
                : openingStock.ExWarehousePrice;

            productInfo.InventoryQuantity = openingStock.ClosingStockQuantity;
            productInfo.Units             = await _productUnitRepository.GetByProductId(tenantId, productInfo.ProductId);

            var conversionUnit = productInfo.Units.FirstOrDefault(x => x.UnitId == productInfo.UnitId);

            if (conversionUnit == null)
            {
                return(new ActionResultResponse <ProductInfoViewModel>(-4, _resourceService.GetString("Product unit does not exists. Please contact with administrator.")));
            }

            // Lấy về tổng sản phẩm theo phiếu nhập.
            var receivedQuantities = await _goodsReceiptNoteDetailRepository.GetQuantitiesByCode(tenantId,
                                                                                                 warehouseId, code);

            // Tổng xuất theo mã sản phẩm thuộc phiếu nhập.
            var deliveryQuantities = await _goodsDeliveryNoteDetailsRepository.GetQuantiesByCode(tenantId,
                                                                                                 warehouseId, code, string.Empty);

            productInfo.RealInventoryQuantity = receivedQuantities - deliveryQuantities;
            return(new ActionResultResponse <ProductInfoViewModel>
            {
                Data = productInfo
            });
        }