Beispiel #1
0
        public bool ObjectExists(TransactionHeaderDTO transaction)
        {
            var objectExists = false;
            var iDbContext   = DbContextUtil.GetDbContextInstance();

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

            return(objectExists);
        }
Beispiel #2
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);
                }

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

                _unitOfWork.Commit();

                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Beispiel #3
0
        public string InsertOrUpdate(TransactionHeaderDTO transaction)
        {
            try
            {
                //InsertOrUpdateChild(transaction.TransactionLines.FirstOrDefault());
                //return "";
                var validate = Validate(transaction);
                if (!string.IsNullOrEmpty(validate))
                {
                    return(validate);
                }

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

                _transactionRepository.InsertUpdate(transaction);
                _unitOfWork.Commit();

                //Generate New TransactionNumber
                if (string.IsNullOrEmpty(transaction.TransactionNumber))
                {
                    return(GetNewTransactionNumber(transaction));
                }

                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Beispiel #4
0
        public IEnumerable <ItemQuantityDTO> UpdateInventoryByTransaction(TransactionHeaderDTO transaction)
        {
            var itemsQuantityRepository = new List <ItemQuantityDTO>();

            try
            {
                foreach (var line in transaction.TransactionLines.Where(t => t.Enabled))
                {
                    //var itemQty = new ItemQuantityDTO
                    //{
                    //    WarehouseId = transaction.WarehouseId,
                    //    ItemId = line.ItemId,
                    //    QuantityOnHand = 0
                    //};
                    var iQty = GetByCriteria(transaction.WarehouseId, line.ItemId);
                    if (iQty == null)
                    {
                        iQty = new ItemQuantityDTO()
                        {
                            ItemId      = line.ItemId,
                            WarehouseId = transaction.WarehouseId
                        };
                    }
                    if (transaction.TransactionType == TransactionTypes.Sale)
                    {
                        //if (iQty == null) //if item not found in stock //make sure it should never become null
                        //{
                        //    return null; // "Item not found in store";
                        //}

                        //if (iQty.QuantityOnHand < line.Unit) //If PostWithLessStock is not allowed
                        //{
                        //    return null;
                        //    // "The Store has less than " + itemQty.QuantityOnHand.ToString() + "  '" + line.Item.DisplayName + "'";
                        //}
                        iQty.QuantityOnHand = iQty.QuantityOnHand - line.Unit;
                        iQty.QuantitySold   = iQty.QuantitySold + line.Unit;
                    }
                    else if (transaction.TransactionType == TransactionTypes.Purchase)
                    {
                        iQty.QuantityOnHand    = iQty.QuantityOnHand + line.Unit;
                        iQty.QuantityPurchased = iQty.QuantityPurchased + line.Unit;
                    }

                    itemsQuantityRepository.Add(iQty);
                }
            }
            catch (Exception exception)
            {
                return(null);
            }
            finally
            {
                //Dispose(true);
            }

            return(itemsQuantityRepository);
        }
Beispiel #5
0
        private void AddNewTransactionHeader()
        {
            if (SelectedWarehouse == null || SelectedWarehouse.Id == -1)
            {
                return;
            }

            SelectedTransactionHeader = new TransactionHeaderDTO
            {
                TransactionType = TransactionType,
                Status          = TransactionStatus.Posted,
                TransactionDate = DateTime.Now,
                WarehouseId     = SelectedWarehouse.Id
            };
        }
Beispiel #6
0
        public string GetNewTransactionNumber(TransactionHeaderDTO transaction)
        {
            var tranNumber = "";

            try
            {
                //like
            }
            catch (Exception exception)
            {
                tranNumber = "Problem getting transaction number, try again..." + Environment.NewLine +
                             exception.Message;
            }
            return(tranNumber);
        }
Beispiel #7
0
        public string Disable(TransactionHeaderDTO transaction2)
        {
            if (transaction2 == null)
            {
                return(GenericMessages.ObjectIsNull);
            }

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

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

                if (transaction != null)
                {
                    foreach (var transactionLine in transaction.TransactionLines.Where(t => t.Enabled))
                    {
                        transactionLine.Enabled = false;
                        transactionLineRepository2.Update(transactionLine);
                    }
                    transaction.Enabled = false;
                    transactionRepository2.Update(transaction);
                }
                unitOfWorkTemp.Commit();
                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                iDbContextTemp.Dispose();
            }
            return(stat);
        }
Beispiel #8
0
        public string Validate(TransactionHeaderDTO transaction)
        {
            if (null == transaction)
            {
                return(GenericMessages.ObjectIsNull);
            }

            if (transaction.WarehouseId == 0)
            {
                return("Warehouse " + GenericMessages.ObjectIsNull);
            }

            //if (String.IsNullOrEmpty(transaction.TransactionNumber))
            //    return transaction.TransactionNumber + " " + GenericMessages.StringIsNullOrEmpty;

            //if (transaction.TransactionNumber.Length > 50)
            //    return transaction.TransactionNumber + " can not be more than 50 characters ";

            return(string.Empty);
        }
Beispiel #9
0
        public PaymentDTO GetNewPayment(TransactionHeaderDTO selectedTransaction, DateTime paymentDate)
        {
            if (selectedTransaction != null)
            {
                return(new PaymentDTO
                {
                    //PaymentMethod = PaymentMethods.Check,
                    Status = PaymentStatus.NotCleared,
                    PaymentDate = paymentDate,

                    TransactionId = selectedTransaction.Id,
                    WarehouseId = selectedTransaction.WarehouseId,
                    PersonName = selectedTransaction.BusinessPartnerId.ToString(),

                    PaymentType = selectedTransaction.TransactionType == TransactionTypes.Sale ? PaymentTypes.Sale : PaymentTypes.Purchase,
                    Reason = selectedTransaction.TransactionType.ToString() + "-" +
                             selectedTransaction.TransactionNumber + "-" +
                             selectedTransaction.TransactionDateString
                });
            }
            return(null);
        }
        private void AddNewTransactionHeader()
        {
            if (SelectedWarehouse == null || SelectedWarehouse.Id == -1)
            {
                return;
            }

            SelectedTransactionHeader = new TransactionHeaderDTO
            {
                TransactionType = TransactionType,
                Status          = TransactionStatus.New,
                TransactionDate = DateTime.Now,
                WarehouseId     = SelectedWarehouse.Id
            };

            StockReceiveDate = DateTime.Now;
            TransactionLines = new ObservableCollection <TransactionLineDTO>();

            if (TransactionType == TransactionTypes.TransferStock)
            {
                SelectedToWarehouse = ToWarehouses.FirstOrDefault();
            }
        }
Beispiel #11
0
        public string GetNewTransactionNumber(TransactionHeaderDTO transaction)
        {
            var tranNumber = "";

            try
            {
                var selectedWarehouse = new WarehouseService(true)
                                        .Find(transaction.WarehouseId.ToString());
                var prefix = transaction.TransactionType.ToString().Substring(0, 1);
                var clDto  = new ClientService(true).GetClient();

                if (clDto != null && clDto.HasOnlineAccess)
                {
                    prefix = Singleton.Edition == AMStockEdition.OnlineEdition ? prefix + "S" : prefix + "L";
                }

                var lastNum = transaction.Id + 1000000;

                var subLength = 1;
                if (clDto != null && clDto.Organizations.Count > 1)
                {
                    subLength = 0;
                }

                transaction.TransactionNumber = prefix +
                                                selectedWarehouse.WarehouseNumber.ToString().Substring(subLength) +
                                                lastNum.ToString().Substring(1);
                _transactionRepository.InsertUpdate(transaction);
                _unitOfWork.Commit();
            }
            catch (Exception exception)
            {
                tranNumber = "Problem getting transaction number, try again..." + Environment.NewLine + exception.Message;
            }
            return(tranNumber);
        }
Beispiel #12
0
        public ItemDetail(ObservableCollection <TransactionLineDTO> transactionLines, TransactionHeaderDTO transactionHeader)
        {
            ItemDetailViewModel.Errors = 0;
            InitializeComponent();

            Messenger.Default.Send <ObservableCollection <TransactionLineDTO> >(transactionLines);
            Messenger.Default.Send <TransactionHeaderDTO>(transactionHeader);

            Messenger.Reset();
        }
Beispiel #13
0
        public IEnumerable <ItemQuantityDTO> UpdateInventoryByTransaction(TransactionHeaderDTO transaction)
        {
            var itemsQuantityRepository = new List <ItemQuantityDTO>();

            try
            {
                foreach (var line in transaction.TransactionLines.Where(t => t.Enabled))
                {
                    var iQty = GetByCriteria(transaction.WarehouseId, line.ItemId);
                    if (transaction.TransactionType == TransactionTypes.SellStock || transaction.TransactionType == TransactionTypes.UseStock)
                    {
                        if (iQty == null) //if item not found in stock //make sure it should never become null
                        {
                            return(null); // "Item not found in store";
                        }

                        if (iQty.QuantityOnHand < line.Unit) //If PostWithLessStock is not allowed
                        {
                            return(null);
                            // "The Store has less than " + itemQty.QuantityOnHand.ToString() + "  '" + line.Item.DisplayName + "'";
                        }
                        iQty.QuantityOnHand = iQty.QuantityOnHand - line.Unit;
                        itemsQuantityRepository.Add(iQty);
                    }
                    else if (transaction.TransactionType == TransactionTypes.RecieveStock)
                    {
                        if (iQty == null)
                        {
                            iQty = new ItemQuantityDTO()
                            {
                                ItemId         = line.ItemId,
                                WarehouseId    = transaction.WarehouseId,
                                QuantityOnHand = 0
                            };
                        }
                        iQty.QuantityOnHand = iQty.QuantityOnHand + line.Unit;
                        itemsQuantityRepository.Add(iQty);
                    }
                    else if (transaction.TransactionType == TransactionTypes.TransferStock)
                    {
                        if (transaction.ToWarehouseId == null)
                        {
                            return(null);
                        }

                        if (transaction.Status == TransactionStatus.Requested)
                        {
                            if (iQty == null)
                            {
                                iQty = new ItemQuantityDTO()
                                {
                                    ItemId         = line.ItemId,
                                    WarehouseId    = transaction.WarehouseId,
                                    QuantityOnHand = 0
                                };
                            }
                            if (iQty.QuantityOnHand < line.Unit) //If PostWithLessStock is not allowed
                            {
                                return(null);
                            }
                            iQty.QuantityOnHand = iQty.QuantityOnHand - line.Unit;
                            itemsQuantityRepository.Add(iQty);
                        }
                        else if (transaction.Status == TransactionStatus.Sent)
                        {
                            var destWarehouse = (int)transaction.ToWarehouseId;
                            var iQtyDest      = GetByCriteria(destWarehouse, line.ItemId);
                            if (iQtyDest == null)
                            {
                                iQtyDest = new ItemQuantityDTO()
                                {
                                    ItemId         = line.ItemId,
                                    WarehouseId    = destWarehouse,
                                    QuantityOnHand = 0
                                };
                            }
                            iQtyDest.QuantityOnHand = iQtyDest.QuantityOnHand + line.Unit;
                            itemsQuantityRepository.Add(iQtyDest);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                return(null);
            }
            finally
            {
                //Dispose(true);
            }

            return(itemsQuantityRepository);
        }
Beispiel #14
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);
        }
Beispiel #15
0
 public AttachmentEntry(TransactionHeaderDTO transaction)
 {
     AttachmentEntryViewModel.Errors = 0;
     InitializeComponent();
     Messenger.Default.Send <TransactionHeaderDTO>(transaction);
 }
Beispiel #16
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);
        }
Beispiel #17
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);
            }
        }
Beispiel #18
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, t => t.Payments)
                                  .Filter(t => t.Id == transaction2.Id)
                                  .Get()
                                  .FirstOrDefault();
                var piLineRepository       = unitOfWorkTemp.Repository <PhysicalInventoryLineDTO>();
                var paymentRepository      = unitOfWorkTemp.Repository <PaymentDTO>();
                var itemQtyRepository      = unitOfWorkTemp.Repository <ItemQuantityDTO>();
                var piHeaderRepository2    = new PiHeaderService(iDbContextTemp);
                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);

                        var piLineNew = piHeaderRepository2.GetNewPiLine(transactionLine.Transaction.WarehouseId,
                                                                         transactionLine.ItemId,
                                                                         itemQty.QuantityOnHand, PhysicalInventoryLineTypes.UnpostSales);

                        piLineRepository.Insert(piLineNew);
                    }
                    if (string.IsNullOrEmpty(stat))
                    {
                        foreach (var transactionPayment in transaction.Payments)
                        {
                            transactionPayment.Enabled = false;
                            paymentRepository.Update(transactionPayment);
                        }

                        transaction.Status = TransactionStatus.Order;
                        transactionRepository2.Update(transaction);
                        unitOfWorkTemp.Commit();
                    }
                }

                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                iDbContextTemp.Dispose();
            }
            return(stat);
        }
Beispiel #19
0
 public AddPayment(TransactionHeaderDTO transaction)
 {
     AddPaymentViewModel.Errors = 0;
     InitializeComponent();
     Messenger.Default.Send <TransactionHeaderDTO>(transaction);
 }