public void Execute(ConfirmInventoryAdjustmentNoteCommand command) { _log.InfoFormat("Execute {1} - Command Id {0} ", command.CommandId, command.GetType().ToString()); try { if (!DocumentExists(command.DocumentId)) { _log.InfoFormat("Failed to Execute {1} - Command Id {0} ", command.CommandId, command.GetType().ToString()); return; } if (DocumentIsConfirmed(command.DocumentId)) { _log.InfoFormat("Failed to Execute {1} - Command Id {0} Document is already confirmed", command.CommandId, command.GetType().ToString()); return; } ConfirmDocument(command.DocumentId); InventoryAdjustmentNote adjustmentNote = _documentRepository.GetById(command.DocumentId); var nonInventoryDoc = new List<InventoryAdjustmentNoteType> { InventoryAdjustmentNoteType.StockTake, InventoryAdjustmentNoteType.OutletStockTake }; if (!nonInventoryDoc.Contains(adjustmentNote.InventoryAdjustmentNoteType)) { List<Guid> aid =_cokeDataContext.tblLineItems .Where(s => s.DocumentID == command.DocumentId) .Select(s => s.ProductID.Value).Distinct().ToList(); int count =_cokeDataContext.tblProduct.Count(s => aid.Contains(s.id)); if(aid.Count!=count) { string liguilds = string.Join(",", aid.ToString()); int licount = aid.Count(); string message = string.Format("The document contain invalid product ids {0} # line item count {1} - product count {2} ",liguilds, licount, count ); throw new Exception(message); } _log.InfoFormat("Document Id {0} no of lineItem count {1} ", command.DocumentId, adjustmentNote.LineItem.Count); foreach (var item in adjustmentNote.LineItem) { //adjust Distributor stock _inventoryWorkflow.InventoryAdjust(adjustmentNote.DocumentIssuerCostCentre.Id, item.Product.Id, (item.Actual - item.Qty), DocumentType.InventoryAdjustmentNote, adjustmentNote.Id, adjustmentNote.DocumentDateIssued, adjustmentNote.InventoryAdjustmentNoteType); } } } catch (Exception ex) { _log.ErrorFormat("Error Execute {1} - Command Id {0} ", command.CommandId, command.GetType().ToString()); _log.Error("ConfirmInventoryAdjustmentNoteCommandHandler exception", ex); throw ex; } }
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)); }