public InventoryAdjustmentNote Create(CostCentre documentIssuerCostCentre, Guid documentIssueCostCentreApplicationId, CostCentre documentRecipientCC, User documentIssuerUser, string documentReference, InventoryAdjustmentNoteType inventoryAdjustmentNoteType, Guid documentParentId , double? longitude = null, double? latitude = null) { Guid id = Guid.NewGuid(); InventoryAdjustmentNote doc = DocumentPrivateConstruct<InventoryAdjustmentNote>(id); // new InventoryAdjustmentNote(id); doc.InventoryAdjustmentNoteType = inventoryAdjustmentNoteType; doc.DocumentType = DocumentType.InventoryAdjustmentNote; if (documentParentId == null || documentParentId == Guid.Empty) doc.DocumentParentId = id; else doc.DocumentParentId = documentParentId; Map(doc, documentIssuerCostCentre, documentIssueCostCentreApplicationId, documentRecipientCC, documentIssuerUser, documentReference, latitude, longitude); SetDefaultDates(doc); doc.EnableAddCommands(); return doc; }
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); } }