Ejemplo n.º 1
0
        public string Validate(ItemsMovementHeaderDTO imHeader)
        {
            if (null == imHeader)
            {
                return(GenericMessages.ObjectIsNull);
            }

            if (imHeader.FromWarehouseId == -1)
            {
                return("From Warehouse " + GenericMessages.ObjectIsNull);
            }

            if (imHeader.ToWarehouseId == -1)
            {
                return("To Warehouse " + GenericMessages.ObjectIsNull);
            }

            if (String.IsNullOrEmpty(imHeader.MovementNumber))
            {
                return(imHeader.MovementNumber + " " + GenericMessages.StringIsNullOrEmpty);
            }

            if (imHeader.MovementNumber.Length > 50)
            {
                return(imHeader.MovementNumber + " can not be more than 50 characters ");
            }

            return(string.Empty);
        }
Ejemplo n.º 2
0
        private void AddNewItemsMovementHeader()
        {
            SelectedFromWarehouse = Warehouses.FirstOrDefault();
            SelectedToWarehouse   = Warehouses.FirstOrDefault();

            SelectedItemsMovement = new ItemsMovementHeaderDTO
            {
                MovementDate    = DateTime.Now,
                Status          = TransactionStatus.Draft,
                FromWarehouseId = -1,
                ToWarehouseId   = -1,
                MovementNumber  = _imHeaderService.GetNewMovementNumber(1, false)
            };

            ItemsMovementLines = new ObservableCollection <ItemsMovementLineDTO>();
        }
Ejemplo n.º 3
0
        public string Disable(ItemsMovementHeaderDTO imHeader)
        {
            if (imHeader == null)
            {
                return(GenericMessages.ObjectIsNull);
            }

            string stat;

            try
            {
                _imHeaderRepository.Update(imHeader);
                _unitOfWork.Commit();
                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            return(stat);
        }
Ejemplo n.º 4
0
        public bool ObjectExists(ItemsMovementHeaderDTO imHeader)
        {
            var objectExists = false;
            var iDbContext   = DbContextUtil.GetDbContextInstance();

            try
            {
                var catRepository = new Repository <ItemsMovementHeaderDTO>(iDbContext);
                var catExists     = catRepository.Query()
                                    .Filter(bp => bp.MovementNumber == imHeader.MovementNumber && bp.Id != imHeader.Id)
                                    .Get()
                                    .FirstOrDefault();
                if (catExists != null)
                {
                    objectExists = true;
                }
            }
            finally
            {
                iDbContext.Dispose();
            }

            return(objectExists);
        }
Ejemplo n.º 5
0
        public string InsertOrUpdate(ItemsMovementHeaderDTO imHeader)
        {
            try
            {
                var validate = Validate(imHeader);
                if (!string.IsNullOrEmpty(validate))
                {
                    return(validate);
                }

                if (ObjectExists(imHeader))
                {
                    return(GenericMessages.DatabaseErrorRecordAlreadyExists);
                }

                _imHeaderRepository.InsertUpdate(imHeader);
                _unitOfWork.Commit();
                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Ejemplo n.º 6
0
        public string UnPost(ItemsMovementHeaderDTO iMHeader)
        {
            try
            {
                var imHeader = this.Get().Filter(im => im.Id == iMHeader.Id).Get().FirstOrDefault();
                //For Eager Loading
                var items =
                    _imLineRepository.Query()
                    .Include(l => l.Item)
                    .Filter(l => l.ItemsMovementHeaderId == imHeader.Id)
                    .Get();

                if (imHeader != null)
                {
                    if (imHeader.ItemsMovementLines.Count == 0)
                    {
                        return("No Items To UnPost, Add Item First....");
                    }

                    var itemsQuantityRepository = new Repository <ItemQuantityDTO>(_iDbContext);

                    var validate = Validate(imHeader);
                    if (!string.IsNullOrEmpty(validate))
                    {
                        return(validate);
                    }

                    foreach (var line in imHeader.ItemsMovementLines.Where(p => p.Enabled))
                    {
                        var itFrQty = new ItemQuantityService(_iDbContext)
                                      .GetByCriteria(imHeader.FromWarehouseId, line.ItemId);

                        itFrQty.QuantityOnHand = itFrQty.QuantityOnHand + (int)line.MovedQuantity;

                        itemsQuantityRepository.InsertUpdate(itFrQty);

                        var itToQty = new ItemQuantityService(_iDbContext)
                                      .GetByCriteria(imHeader.ToWarehouseId, line.ItemId);

                        itToQty.QuantityOnHand = itToQty.QuantityOnHand - (int)line.MovedQuantity;
                        if (itFrQty.QuantityOnHand < 0)
                        {
                            return("Less than 0 stock level found for item " + line.Item.DisplayName);
                        }
                        itemsQuantityRepository.InsertUpdate(itToQty);
                    }


                    imHeader.Status = TransactionStatus.Draft;
                    _imHeaderRepository.Update(imHeader);

                    _unitOfWork.Commit();

                    return(string.Empty);
                }
                return("can't Find Items Movement...");
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }