Beispiel #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.Sale:
                itemQty.QuantityOnHand = itemQty.QuantityOnHand + line.Unit;
                itemQty.QuantitySold   = itemQty.QuantitySold - line.Unit;
                break;

            case TransactionTypes.Purchase:
                //if (itemQty.QuantityOnHand < line.Unit)
                //return null;
                itemQty.QuantityOnHand    = itemQty.QuantityOnHand - line.Unit;
                itemQty.QuantityPurchased = itemQty.QuantityPurchased - line.Unit;
                break;
            }
            return(itemQty);
        }
Beispiel #2
0
        public string UnPost(PhysicalInventoryHeaderDTO piHeader)
        {
            try
            {
                var itemsQuantityRepository = new Repository <ItemQuantityDTO>(_iDbContext);
                if (piHeader.PhysicalInventoryLines.Count == 0)
                {
                    return("No Items To Post, Add Item First....");
                }

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

                foreach (var line in piHeader.PhysicalInventoryLines.Where(p => p.Enabled))
                {
                    var itQty = new ItemQuantityService(_iDbContext).GetByCriteria(piHeader.WarehouseId, line.ItemId);
                    if (line.CountedQty >= itQty.QuantityOnHand)
                    {
                        //donothing
                    }
                    if (line.CountedQty < itQty.QuantityOnHand)
                    {
                        itemsQuantityRepository = new Repository <ItemQuantityDTO>(_iDbContext);
                        return("Can't Unpost");
                    }

                    itQty.QuantityOnHand = line.ExpectedQty;
                    itemsQuantityRepository.InsertUpdate(itQty);
                }


                piHeader.Status = PhysicalInventoryStatus.Draft;
                _piHeaderRepository.Update(piHeader);

                _unitOfWork.Commit();

                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Beispiel #3
0
        public PhysicalInventoryLineDTO GetNewPiLine(int warehouseId, int itemId,
                                                     decimal countedQty, PhysicalInventoryLineTypes lineType)
        {
            var line = new PhysicalInventoryLineDTO();

            try
            {
                var selectedItemQuantity = new ItemQuantityService(false).GetByCriteria(warehouseId, itemId);

                //var selectedPhysicalInventory = GetListOf(false)
                //.FirstOrDefault(pi => pi.WarehouseId == warehouseId &&
                //                      pi.PhysicalInventoryDate.Date == DateTime.Now.Date) ??
                var selectedPhysicalInventory = new PhysicalInventoryHeaderDTO
                {
                    PhysicalInventoryDate = DateTime.Now,
                    Status                  = PhysicalInventoryStatus.Posted,
                    WarehouseId             = warehouseId,
                    PhysicalInventoryNumber = GetNewPhysicalInventoryNumber(warehouseId, false)
                };

                line.PhysicalInventory         = selectedPhysicalInventory;
                line.ItemId                    = itemId;
                line.CountedQty                = countedQty;
                line.ExpectedQty               = selectedItemQuantity != null ? selectedItemQuantity.QuantityOnHand : 0;
                line.PhysicalInventoryLineType = lineType;
            }
            catch
            {
                MessageBox.Show("Problem getting new pi, try again...");
                return(null);
            }
            finally
            {
                //_unitOfWork.Dispose();
            }

            return(line);
        }
        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);
            }
        }
Beispiel #5
0
        public string PostPayments(TransactionHeaderDTO transaction2, PaymentDTO payment2, PaymentModel paymentModel, CheckDTO selectedCheck)
        {
            string stat = string.Empty;

            try
            {
                var transaction =
                    _transactionRepository
                    .Query()
                    .Include(t => t.Warehouse, t => t.BusinessPartner, t => t.TransactionLines, t => t.Payments)
                    .Filter(t => t.Id == transaction2.Id)
                    .Get()
                    .FirstOrDefault();

                if (transaction == null)
                {
                    return("Empty transaction");
                }

                var bp = _businessPartnerRepository
                         .Query()
                         .Filter(b => b.Id == transaction.BusinessPartnerId)
                         .Get()
                         .FirstOrDefault();
                if (bp == null)
                {
                    return("No Business Partner");
                }

                PaymentDTO cashPayment = null;
                if (paymentModel.Amount > 0) //always cash payment
                {
                    #region Cash Payment

                    cashPayment = GetNewPayment(transaction, paymentModel.PaymentDate);
                    if (cashPayment != null)
                    {
                        cashPayment.PaymentMethod = PaymentMethods.Cash;
                        cashPayment.Status        = PaymentStatus.NotDeposited;
                        cashPayment.Amount        = paymentModel.Amount - paymentModel.Change;
                        if (!Singleton.Setting.HandleBankTransaction)
                        {
                            cashPayment.Status = PaymentStatus.Cleared;
                        }

                        _paymentRepository.Insert(cashPayment);

                        if (payment2 != null)
                        {
                            bp.TotalCredits = bp.TotalCredits - cashPayment.Amount;
                            if (payment2.Amount - cashPayment.Amount == 0)
                            {
                                bp.TotalNoOfCreditTransactions = bp.TotalNoOfCreditTransactions - 1;
                            }
                            _businessPartnerRepository.InsertUpdate(bp);
                        }
                    }

                    #endregion
                }

                //Commented because is always cash payment
                if (paymentModel.Amount < paymentModel.AmountRequired)
                {
                    if (selectedCheck != null && selectedCheck.CheckNumber.Length > 0)
                    {
                        #region Check Payment

                        var checkPayment = GetNewPayment(transaction, paymentModel.PaymentDate);
                        if (checkPayment != null)
                        {
                            checkPayment.Check         = selectedCheck;
                            checkPayment.PaymentMethod = PaymentMethods.Check;
                            checkPayment.Amount        = paymentModel.AmountRequired - paymentModel.Amount;
                            //piList.Add(checkPayment);
                            _paymentRepository.Insert(checkPayment);

                            if (payment2 == null)
                            {
                                bp.TotalCredits = bp.TotalCredits + checkPayment.Amount;
                                bp.TotalNoOfCreditTransactions = bp.TotalNoOfCreditTransactions + 1;
                                _businessPartnerRepository.InsertUpdate(bp);
                            }
                        }

                        #endregion
                    }
                    else if (transaction.BusinessPartner.AllowCreditsWithoutCheck)
                    {
                        #region Credit Payment

                        var creditPayment = GetNewPayment(transaction, paymentModel.PaymentDate);
                        if (creditPayment != null)
                        {
                            creditPayment.PaymentMethod = PaymentMethods.Credit;
                            creditPayment.DueDate       = DateTime.Now.AddDays(transaction.BusinessPartner.PaymentTerm);
                            creditPayment.Amount        = paymentModel.AmountRequired - paymentModel.Amount;
                            _paymentRepository.Insert(creditPayment);

                            if (payment2 == null)
                            {
                                bp.TotalCredits = bp.TotalCredits + creditPayment.Amount;
                                bp.TotalNoOfCreditTransactions = bp.TotalNoOfCreditTransactions + 1;
                                _businessPartnerRepository.InsertUpdate(bp);
                            }
                        }

                        #endregion
                    }
                    else
                    {
                        stat = "Got problem while getting check detail, Can't take credit or problem on check ..";
                        if (cashPayment != null)
                        {
                            _paymentRepository.Delete(cashPayment);
                        }
                    }
                }
                if (string.IsNullOrEmpty(stat))
                {
                    if (payment2 == null)
                    {
                        // Update Inventory
                        var iqList = new ItemQuantityService(_iDbContext).UpdateInventoryByTransaction(transaction);
                        foreach (var itemQuantityDTO in iqList)
                        {
                            _itemsQuantityRepository.InsertUpdate(itemQuantityDTO);
                        }

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

                        _unitOfWork.Commit();
                    }
                    else
                    {
                        var payment = _paymentRepository.FindById(payment2.Id);

                        payment.Enabled = false;
                        _paymentRepository.Update(payment);

                        _unitOfWork.Commit();
                    }
                }
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                _iDbContext.Dispose();
            }
            return(stat);
        }