public void Execute(AddInventoryAdjustmentNoteLineItemCommand command) { _log.InfoFormat("Execute {1} - Command Id {0} ", command.CommandId, command.GetType()); try { if (!DocumentExists(command.DocumentId)) { _log.InfoFormat("Cannot add line item. Document does not exist Execute {1} - Command Id {0} ", command.CommandId, command.GetType()); return; } if (DocumentLineItemExists(command.CommandId)) { _log.InfoFormat("Cannot add line item {0}. Line item already exists", command.CommandId); return; } tblDocument document = ExistingDocument(command.DocumentId); tblLineItems lineItem = NewLineItem(command.CommandId, command.DocumentId, command.ProductId, command.Reason, command.Expected, command.LineItemSequence); lineItem.IAN_Actual = command.Actual; document.tblLineItems.Add(lineItem); _cokeDataContext.SaveChanges(); } catch (Exception ex) { _log.ErrorFormat("Error Execute {1} - Command Id {0} ", command.CommandId, command.GetType().ToString()); _log.Error("AddInventoryAdjustmentNoteLineItemCommandHandler exception", ex); throw ; } }
public void Handle(AddInventoryAdjustmentNoteLineItemCommand command) { inventoryRepository.AdjustInventoryForProduct(command.ProductId, command.Actual - command.Expected); }
public void BreakBulk(Guid productId, Guid costcentreId, decimal qty, BasicConfig config) { Product product = _productService.GetById(productId); if (!(product is ConsolidatedProduct)) return; ConsolidatedProduct consolidatedProduct = product as ConsolidatedProduct; //create inventory adjustment Guid documentId = Guid.NewGuid(); //TODO AJM resolve current user id Guid currentUserId = Guid.Empty; CreateInventoryAdjustmentNoteCommand cianc = new CreateInventoryAdjustmentNoteCommand( Guid.NewGuid(), documentId, currentUserId, config.CostCentreId, 0, config.CostCentreApplicationId, config.CostCentreId, currentUserId, (int)InventoryAdjustmentNoteType.Available, "", DateTime.Now ); _commandRouter.RouteDocumentCommand(cianc); _auditLogWFManager.AuditLogEntry("Break Bulk", string.Format("Created Break Bulk document: {0}; for consolidated product: {1}; and Quantity: {2};", documentId, consolidatedProduct.Description, qty)); //create line items //-- adjust down consolidated product AddInventoryAdjustmentNoteLineItemCommand li = new AddInventoryAdjustmentNoteLineItemCommand( Guid.NewGuid(), documentId, currentUserId, config.CostCentreId, 0, config.CostCentreApplicationId, productId, -qty, 0, 1, "break bulk"); _commandRouter.RouteDocumentCommand(li); int count = 1; //-- adjust up items foreach (var item in consolidatedProduct.ProductDetails) { count++; var li1 = new AddInventoryAdjustmentNoteLineItemCommand(Guid.NewGuid(), documentId, currentUserId, config.CostCentreId, 0, config.CostCentreApplicationId, item.Product.Id, item.QuantityPerConsolidatedProduct * qty, 0, count, "break bulk" ); _commandRouter.RouteDocumentCommand(li1); _auditLogWFManager.AuditLogEntry("Break Bulk", string.Format("Adjusted Product: {0}; to Quantity: {1}; for consolidated product: {2};", item.Product.Description, item.QuantityPerConsolidatedProduct * qty, consolidatedProduct.Description)); } //confirm var confirmIA = new ConfirmInventoryAdjustmentNoteCommand(Guid.NewGuid(), documentId, currentUserId, config.CostCentreId, 0, config.CostCentreApplicationId); _commandRouter.RouteDocumentCommand(confirmIA); _auditLogWFManager.AuditLogEntry("Break Bulk", string.Format("confirmed Break Bulk document: {0}; for consolidated product: {1}; and Quantity: {2};", documentId, consolidatedProduct.Description, qty)); }
private static void CheckInventoryAdjustmentNoteLineCommand(ProductLineItem item, AddInventoryAdjustmentNoteLineItemCommand command, decimal availableStock) { Assert.AreEqual(item.Product.Id, command.ProductId, "Line item Product ID"); Assert.AreEqual(availableStock, command.Expected, "Line item available value"); Assert.AreEqual(availableStock - item.Quantity, command.Actual, "Line item expected value"); }