Пример #1
0
        public void InventoryAdjust(Guid costCentreId, Guid productId, decimal qty, DocumentType docType, Guid documentId, DateTime date, InventoryAdjustmentNoteType inventoryAdjustmentNoteType)
        {
           // _log.InfoFormat("Inventory Adjust costcentreid : {0} - productid : {1} - qty : {2} - doctype : {3} - docid : {4}", costCentreId, productId, qty, docType, documentId);
            try
            {
                Product p = _productRepository.GetById(productId);
                CostCentre cc = _costCentreRepository.GetById(costCentreId);
                if (!(cc is Warehouse))
                    throw new Exception("Can only have inventory in a cost centre that is a warehouse");
                //does inventory item exist for costcentre
                if (!_inventoryRepository.GetByProductId(productId).Any(n => n.Warehouse.Id == costCentreId))
                {
                    var inv = new Inventory(Guid.NewGuid())
                    {
                        Balance = 0,
                        Value = 0,
                        Product = p,
                        Warehouse = (Warehouse)cc
                    };
                    _inventoryRepository.AddInventory(inv);
                }

                Inventory inv1 = _inventoryRepository.GetByProductId(productId).First(n => n.Warehouse.Id == costCentreId);
                var it = new InventoryTransaction(Guid.NewGuid())
                {
                    DateInserted = DateTime.Now,
                    DocumentId = documentId,
                    DocumentType = docType,
                    Inventory = inv1,
                    NoItems = qty,

                };
                _inventoryTransactionRepository.Add(it);

                _inventoryRepository.AdjustInventoryBalance(inv1.Id, qty, (int)inventoryAdjustmentNoteType);

            }
            catch (Exception)
            {
                //_log.Error(ex);
            }
        }
        public InventoryTransaction Map(tblInventoryTransaction tblInvTr)
        {
            var inv = _inventoryRepository.GetById(tblInvTr.InventoryId);
            InventoryTransaction accTr = new InventoryTransaction(tblInvTr.Id)
            {
                 CostCentreId = inv.Warehouse.Id, 
                Inventory = inv,
                NoItems = tblInvTr.NoItems.Value,
                NetValue = (decimal)tblInvTr.NetValue,
                GrossValue = (decimal)tblInvTr.GrossValue,
                DocumentType = (DocumentType)tblInvTr.DocumentType,
                DocumentId = tblInvTr.DocumentId,
                DateInserted = tblInvTr.DateInserted
            };
            accTr._SetDateCreated(tblInvTr.IM_DateCreated);
            accTr._SetDateLastUpdated(tblInvTr.IM_DateLastUpdated);
            accTr._SetStatus((EntityStatus)tblInvTr.IM_Status);

            return accTr;

        }
        public Guid Add(InventoryTransaction inventoryTransaction)
        {
            ValidationResultInfo vri = Validate(inventoryTransaction);
            if (!vri.IsValid)
            {
                throw new DomainValidationException(vri, "Failed To Validate InventoryTransaction");
            }
            tblInventoryTransaction tblInvTr = _ctx.tblInventoryTransaction.FirstOrDefault(n => n.Id == inventoryTransaction.Id); ;
            DateTime dt = DateTime.Now;
            if (tblInvTr == null)
            {
                tblInvTr = new tblInventoryTransaction();
                tblInvTr.Id = inventoryTransaction.Id;
                tblInvTr.IM_DateCreated = dt;
                tblInvTr.IM_Status = (int)EntityStatus.Active; //true;
                _ctx.tblInventoryTransaction.AddObject(tblInvTr);
                _log.DebugFormat("inventoryTransaction.Id == 0");
            }
            var entityStatus = (inventoryTransaction._Status == EntityStatus.New) ? EntityStatus.Active : inventoryTransaction._Status;
            if (tblInvTr.IM_Status != (int)entityStatus)
                tblInvTr.IM_Status = (int)inventoryTransaction._Status;
              


            tblInvTr.InventoryId = inventoryTransaction.Inventory.Id;
            tblInvTr.NoItems = inventoryTransaction.NoItems;
            tblInvTr.NetValue = inventoryTransaction.NetValue;
            tblInvTr.GrossValue = inventoryTransaction.GrossValue;
            tblInvTr.DocumentType = (int)inventoryTransaction.DocumentType;
            tblInvTr.DocumentId = inventoryTransaction.DocumentId;
            tblInvTr.DateInserted = inventoryTransaction.DateInserted;
            tblInvTr.IM_DateLastUpdated = dt;
            _log.DebugFormat("Saving/Updating InventoryTransaction");

            _ctx.SaveChanges();
            return tblInvTr.Id;
        }
 public ValidationResultInfo Validate(InventoryTransaction itemToValidate)
 {
     ValidationResultInfo vri = itemToValidate.BasicValidation();
     if (itemToValidate._Status == EntityStatus.Inactive || itemToValidate._Status == EntityStatus.Deleted)
         return vri;
     if (itemToValidate.Id == Guid.Empty)
         vri.Results.Add(new ValidationResult("Enter Valid  Guid ID"));
     return vri;
 }