Esempio n. 1
0
        public string InsertOrUpdate(ItemQuantityDTO itemQuantity, bool insertPiLine)
        {
            try
            {
                var itemQty = GetByIq(itemQuantity);

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

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

                _itemQuantityRepository.InsertUpdate(itemQty);


                if (insertPiLine)
                {
                    var line = new PiHeaderService().GetNewPiLine(itemQty.WarehouseId, itemQty.ItemId,
                                                                  itemQty.QuantityOnHand, PhysicalInventoryLineTypes.ItemEntry);

                    _piRepository.InsertUpdate(line);
                }

                _unitOfWork.Commit();
                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Esempio 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, 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);
        }