Exemplo n.º 1
0
        public ItemQuantityDTO UnPostUpdateInventory(TransactionLineDTO line, IDbContext idbDbContext)
        {
            var itemQty = new ItemQuantityService(idbDbContext).GetByCriteria(line.Transaction.WarehouseId, line.ItemId);

            if (itemQty == null)
            {
                MessageBox.Show("Can't get item to do the Un-post, Please try again!!");
                return(null);
            }

            switch (line.Transaction.TransactionType)
            {
            case TransactionTypes.SellStock:
                itemQty.QuantityOnHand = itemQty.QuantityOnHand + line.Unit;
                break;

            case TransactionTypes.RecieveStock:
                if (itemQty.QuantityOnHand < line.Unit)
                {
                    return(null);
                }
                itemQty.QuantityOnHand = itemQty.QuantityOnHand - line.Unit;
                break;

            case TransactionTypes.TransferStock:
                itemQty.QuantityOnHand = itemQty.QuantityOnHand + line.Unit;
                break;
            }
            return(itemQty);
        }
Exemplo n.º 2
0
        public string UnPost(TransactionHeaderDTO transaction2)
        {
            if (transaction2 == null)
            {
                return(GenericMessages.ObjectIsNull);
            }

            var iDbContextTemp = DbContextUtil.GetDbContextInstance();
            var unitOfWorkTemp = new UnitOfWork(iDbContextTemp);
            var stat           = "";

            try
            {
                var transaction = unitOfWorkTemp.Repository <TransactionHeaderDTO>().Query()
                                  .Include(t => t.TransactionLines)
                                  .Filter(t => t.Id == transaction2.Id)
                                  .Get()
                                  .FirstOrDefault();

                var itemQtyRepository      = unitOfWorkTemp.Repository <ItemQuantityDTO>();
                var transactionRepository2 = unitOfWorkTemp.Repository <TransactionHeaderDTO>();

                if (transaction != null)
                {
                    foreach (var transactionLine in transaction.TransactionLines.Where(t => t.Enabled))
                    {
                        var itemQty = UnPostUpdateInventory(transactionLine, iDbContextTemp);

                        if (itemQty == null)
                        {
                            stat = "Got problem while updating inventory data, please try agan later...";
                            stat = stat + Environment.NewLine + " may be, The Store has less quantity for the item '" +
                                   transactionLine.Item.DisplayName + "'";
                            break;
                        }
                        itemQtyRepository.InsertUpdate(itemQty);

                        if (transactionLine.Transaction.TransactionType == TransactionTypes.TransferStock &&
                            transactionLine.Transaction.Status == TransactionStatus.Received)
                        {
                            if (transactionLine.Transaction.ToWarehouseId != null)
                            {
                                var toWareId  = (int)transactionLine.Transaction.ToWarehouseId;
                                var itemQtyTo = new ItemQuantityService(iDbContextTemp).GetByCriteria(toWareId,
                                                                                                      transactionLine.ItemId);

                                if (itemQtyTo != null)
                                {
                                    if (itemQtyTo.QuantityOnHand < transactionLine.Unit)
                                    {
                                        return(null);
                                    }
                                    itemQtyTo.QuantityOnHand = itemQtyTo.QuantityOnHand - transactionLine.Unit;
                                }
                                else
                                {
                                    stat = "Got problem while updating inventory data, please try agan later...";
                                    stat = stat + Environment.NewLine +
                                           " may be, The Store has less quantity for the item '" +
                                           transactionLine.Item.DisplayName + "'";
                                    break;
                                }
                                itemQtyRepository.InsertUpdate(itemQtyTo);
                            }
                        }
                    }
                    if (string.IsNullOrEmpty(stat))
                    {
                        if (transaction.TransactionType == TransactionTypes.SellStock)
                        {
                            transaction.Status  = TransactionStatus.New;
                            transaction.Enabled = false;
                            transactionRepository2.Update(transaction);
                        }
                        else
                        {
                            transaction.Status        = TransactionStatus.New;
                            transaction.RequestedBy   = "";
                            transaction.RequestedDate = null;
                            transaction.SentBy        = "";
                            transaction.SentDate      = null;
                            transaction.ReceivedBy    = "";
                            transaction.ReceivedDate  = null;
                            transactionRepository2.Update(transaction);
                        }
                        unitOfWorkTemp.Commit();
                    }
                }

                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                iDbContextTemp.Dispose();
            }
            return(stat);
        }
Exemplo n.º 3
0
        public string Post(TransactionHeaderDTO transaction)
        {
            try
            {
                if (transaction.TransactionLines.Count == 0)
                {
                    return("No Items To Post, Add Item First....");
                }

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

                if (transaction.TransactionType == TransactionTypes.RecieveStock ||
                    transaction.TransactionType == TransactionTypes.SellStock ||
                    transaction.TransactionType == TransactionTypes.UseStock)
                {
                    var iqList = new ItemQuantityService(_iDbContext).UpdateInventoryByTransaction(transaction);
                    foreach (var itemQuantityDto in iqList)
                    {
                        _itemsQuantityRepository.InsertUpdate(itemQuantityDto);
                    }

                    //Update transaction
                    transaction.Status = TransactionStatus.Received;
                    _transactionRepository.InsertUpdate(transaction);

                    _unitOfWork.Commit();
                }
                else if (transaction.TransactionType == TransactionTypes.TransferStock)
                {
                    var stat = TransactionStatus.New;
                    if (transaction.Status == TransactionStatus.New)
                    {
                        stat = TransactionStatus.Requested;
                        transaction.RequestedBy   = Singleton.User.FullName;
                        transaction.RequestedDate = DateTime.Now;
                    }
                    else if (transaction.Status == TransactionStatus.Requested)
                    {
                        stat = TransactionStatus.Sent;
                        transaction.SentBy   = Singleton.User.FullName;
                        transaction.SentDate = DateTime.Now;
                        var iqList = new ItemQuantityService(_iDbContext).UpdateInventoryByTransaction(transaction);
                        foreach (var itemQuantityDto in iqList)
                        {
                            _itemsQuantityRepository.InsertUpdate(itemQuantityDto);
                        }
                    }
                    else if (transaction.Status == TransactionStatus.Sent)
                    {
                        stat = TransactionStatus.Received;
                        transaction.ReceivedBy   = Singleton.User.FullName;
                        transaction.ReceivedDate = DateTime.Now;
                        var iqList = new ItemQuantityService(_iDbContext).UpdateInventoryByTransaction(transaction);
                        foreach (var itemQuantityDto in iqList)
                        {
                            _itemsQuantityRepository.InsertUpdate(itemQuantityDto);
                        }
                    }

                    transaction.Status = stat;
                    _transactionRepository.InsertUpdate(transaction);

                    _unitOfWork.Commit();
                }
                //transaction.Status = TransactionStatus.Posted;
                //_transactionRepository.Update(transaction);

                //_unitOfWork.Commit();

                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }