示例#1
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
            });
        }
示例#2
0
        public async Task <ActionResult> GetProductInfoByCode(string code, string warehouseId, GoodsDeliveryNoteType type, DateTime deliveryDate)
        {
            var result = await _goodsReceiptNoteDetailService.GetProductInfoByCode(CurrentUser.TenantId, CurrentUser.Id, code, warehouseId,
                                                                                   type, deliveryDate);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }