Exemplo n.º 1
0
        public ClientOrderStatisticalDTO GetClientOrdersStatistics(OrderCommand cmd, int userId, ref int pagesCount)
        {
            var user    = new UserDalFacade().GetAccountUser(userId);
            var isAdmin = user.isSunnat || user.PositionRole == 1;

            return(new OrderDalFacade().GetClientOrdersStats(cmd, user.WorkPlace.Id.Value, isAdmin, ref pagesCount));
        }
Exemplo n.º 2
0
        public void Update(ReturnedSaleDTO dto, int userId)
        {
            //var sale = new SaleDalFacade().GetSale(dto.SaleId);
            var workPlaceId          = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id.Value;
            var existingReturnedSale = GetReturnedSale(dto.Id);
            var dasd = existingReturnedSale.Quantity - existingReturnedSale.DefectedQuantity;
            var diff = (dto.Quantity - dto.DefectedQuantity) - dasd; // quantity - deffectedQuantity !!!(So quantity is general for both)

            var productInStockFrom = new ProductStockDalFacade().GetProductStockByPlaceAndProduct(workPlaceId, dto.ProductId);

            productInStockFrom.Quantity += diff;

            new ProductStockDalFacade().Update(productInStockFrom);

            new ReturnedSaleDalFacade().Update(dto);
            //

            var existingReturnSale  = new ReturnedSaleBL().GetReturnedSale(dto.Id);
            var lostInMoneyInInsert = existingReturnSale.ReturnedPrice * existingReturnSale.Quantity;
            var lostInMoneyInUpdate = dto.ReturnedPrice * dto.Quantity;
            var lostInMoney         = lostInMoneyInInsert - lostInMoneyInUpdate;
            var quantity            = existingReturnSale.Quantity - dto.Quantity;
            //var sale2 = new SaleDalFacade().GetSale(dto.SaleId);
            //sale2.SalesPrice -= lostInMoney;
            //sale2.Quantity -= quantity;
            //new SaleDalFacade().Update(sale2);

            //var order = new OrderDalFacade().GetClientOrder(sale.OrderId);
            //order.OverallPrice -= lostInMoney;
            //order.PaymentByCash -= lostInMoney;
            //new OrderDalFacade().Update(order);
        }
Exemplo n.º 3
0
        public List <ReturnedSaleDTO> GetReturnedSales(PaginationDTO cmd, int userId, ref int pagesCount)
        {
            var workPlaceId = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id.Value;
            var isAdmin     = new UserBL().GetAccountUser(userId)?.PositionRole == 1;

            return(new ReturnedSaleDalFacade().GetReturnedSales(cmd, workPlaceId, isAdmin, ref pagesCount));
        }
Exemplo n.º 4
0
        public void UpdateProductStocks(SaleDTO sale, int userId)
        {
            var errorMessage = string.Empty;
            var workplaceId  = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id.Value;
            var productStock =
                new ProductStockDalFacade().GetProductStockByPlaceAndProduct(workplaceId, sale.ProductId);

            if (sale.Quantity > productStock.Quantity)
            {
                errorMessage +=
                    $"Not Enough Product ({productStock.ProductId}-{productStock.ProductName}) in ProductStock to complete transaction.";
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                errorMessage += Environment.NewLine;
            }

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new ArgumentOutOfRangeException(errorMessage);
            }

            var productInStockMinus =
                new ProductStockDalFacade().GetProductStockByPlaceAndProduct(workplaceId, sale.ProductId);

            productInStockMinus.Quantity -= sale.Quantity;
            new ProductStockDalFacade().Update(productInStockMinus);
        }
Exemplo n.º 5
0
        public void Add(ProductStockDTO stock, int userId)
        {
            var workPlaceId = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id;

            var income = CreateLogIncome(userId, stock.ProductId, stock.Quantity, workPlaceId);

            new IncomeDalFacade().AddIncome(income);
            new ProductStockDalFacade().Add(stock);
        }
Exemplo n.º 6
0
        public void Delete(int?id, int userId)
        {
            var workPlaceId  = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id;
            var existedStock = new ProductStockDalFacade().GetProductStock(id);
            var quantity     = existedStock.Quantity * -1;
            var income       = CreateLogIncome(userId, existedStock.ProductId, quantity, workPlaceId);

            new IncomeDalFacade().AddIncome(income);
            new ProductStockDalFacade().Delete(id);
        }
Exemplo n.º 7
0
        public void Update(ProductStockDTO stock, int userId)
        {
            var workPlaceId  = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id;
            var existedStock = new ProductStockDalFacade().GetProductStock(stock.Id);
            var quantity     = stock.Quantity - existedStock.Quantity;
            var income       = CreateLogIncome(userId, existedStock.ProductId, quantity, workPlaceId);

            new IncomeDalFacade().AddIncome(income);
            new ProductStockDalFacade().Update(stock);
        }
Exemplo n.º 8
0
        public void Delete(int id, int userId)
        {
            var workPlaceId        = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id.Value;
            var existing           = GetReturnedSale(id);
            var existingDiff       = existing.Quantity - existing.DefectedQuantity;
            var productInStockFrom = new ProductStockDalFacade().GetProductStockByPlaceAndProduct(workPlaceId, existing.ProductId);

            productInStockFrom.Quantity -= existingDiff;

            new ProductStockDalFacade().Update(productInStockFrom);

            new ReturnedSaleDalFacade().Delete(id);
        }
Exemplo n.º 9
0
        public void UpdateProductStock(ReturnedSaleDTO dto, int userId)
        {
            var workplaceId = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id.Value;

            var productInStockAdd =
                new ProductStockDalFacade().GetProductStockByPlaceAndProduct(workplaceId, dto.ProductId, true);

            if (productInStockAdd == null)
            {
                AddProductStock(workplaceId, dto.ProductId, dto.Quantity - dto.DefectedQuantity);
            }
            else
            {
                productInStockAdd.Quantity += dto.Quantity - dto.DefectedQuantity;
                new ProductStockDalFacade().Update(productInStockAdd);
            }
        }
Exemplo n.º 10
0
        public void Add(ReturnedSaleDTO dto, int userId)
        {
            var workPlaceId = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id.Value;

            if (dto.SaleId == 0)
            {
                dto.SaleId = null;
            }
            new ProductStockBL().UpdateProductStock(dto, userId);
            new ReturnedSaleDalFacade().Add(dto, workPlaceId);

            var lostInMoney = dto.ReturnedPrice * dto.Quantity;
            //var sale = new SaleDalFacade().GetSale(dto.SaleId);
            //sale.Quantity -= dto.Quantity;
            //sale.SalesPrice -= lostInMoney;
            //new SaleDalFacade().Update(sale);

            //var order = new OrderDalFacade().GetClientOrder(sale.OrderId);
            //order.OverallPrice -= lostInMoney;
            //order.PaymentByCash -= lostInMoney;
            //new OrderDalFacade().Update(order);
        }
Exemplo n.º 11
0
        public void Update(SaleDTO sale, int userId)
        {
            var saleOld            = new SaleDalFacade().GetSale(sale.Id);
            var workPlaceId        = new UserDalFacade().GetAccountUser(userId).WorkPlace.Id.Value;
            var diff               = sale.Quantity - saleOld.Quantity; // should-Be - was
            var productInStockFrom = new ProductStockDalFacade().GetProductStockByPlaceAndProduct(workPlaceId, sale.ProductId);

            if (productInStockFrom.Quantity > diff)
            {
                productInStockFrom.Quantity -= diff;// dto.Quantity - inMovement.Quantity;
                new ProductStockDalFacade().Update(productInStockFrom);
            }
            else if (diff == 0)
            {
                //do nothing
            }
            else
            {
                throw new ArgumentOutOfRangeException($"Not Enough Product ({saleOld.ProductId}-{saleOld.ProductName}) in ProductStock to complete transaction.");
            }
            new SaleDalFacade().Update(saleOld);
        }
Exemplo n.º 12
0
        public User GetUserByCredentials(string name, string password)
        {
            var user = new UserDalFacade().GetAccountByName(name, password);

            return(user);
        }