public void CreateDraftStockAdjustment(List <ViewModelFromNew> list) { userService = new UserService(Context); stockAdjustmentService = new StockAdjustmentService(Context); itemService = new ItemService(Context); notificationService = new NotificationService(Context); List <StockAdjustmentDetail> detaillist = new List <StockAdjustmentDetail>(); StockAdjustment s = new StockAdjustment(); s.StockAdjustmentId = IdService.GetNewStockAdjustmentId(Context); s.CreatedBy = userService.FindUserByEmail(CurrentUserName); s.CreatedDateTime = DateTime.Now; foreach (ViewModelFromNew v in list) { StockAdjustmentDetail sd = new StockAdjustmentDetail(); string itemcode = v.Itemcode; Item item = itemService.FindItemByItemCode(itemcode); sd.ItemCode = itemcode; sd.Reason = (v.Reason == null) ? "" : v.Reason; sd.StockAdjustmentId = s.StockAdjustmentId; sd.OriginalQuantity = item.Inventory.Quantity; sd.AfterQuantity = v.Adjustment + sd.OriginalQuantity; detaillist.Add(sd); // stockAdjustmentDetailRepository.Save(sd); } s.StockAdjustmentDetails = detaillist; stockAdjustmentService.CreateDraftStockAdjustment(s); }
public void GetNewStockAdjustmentId_ExistingId_Valid() { // Arrange string expectedPrefix = $"ADJ-{DateTime.Now.Year}{DateTime.Now.Month:00}"; var previous = IdService.GetNewStockAdjustmentId(context); new StockAdjustmentRepository(context).Save(new StockAdjustment() { StockAdjustmentId = previous, Remarks = "IDSERVICETEST", CreatedDateTime = DateTime.Now.AddDays(1 - DateTime.Today.Day), }); // Act var current = IdService.GetNewStockAdjustmentId(context); new StockAdjustmentRepository(context).Save(new StockAdjustment() { StockAdjustmentId = current, Remarks = "IDSERVICETEST", CreatedDateTime = DateTime.Now, }); var previousSerialNoParseResult = Int32.TryParse(previous.Substring(previous.Length - 3), out int previousSerialNo); var resultSerialNoParseResult = Int32.TryParse(current.Substring(current.Length - 3), out int resultSerialNo); // Assert Assert.AreEqual(1, resultSerialNo - previousSerialNo); }
public void GetNewStockAdjustmentIdTest() { // Arrange string expectedPrefix = $"ADJ-{DateTime.Now.Year}{DateTime.Now.Month:00}"; // Act var result = IdService.GetNewStockAdjustmentId(context); var serialNoParseResult = Int32.TryParse(result.Substring(result.Length - 3), out int serialNo); // Assert Assert.AreEqual(expectedPrefix, result.Substring(0, 10)); Assert.IsTrue(serialNoParseResult); }
public void GetStockAdjustmentsForSupervisor_ContainsResult() { // Arrange var expectedId = IdService.GetNewStockAdjustmentId(context); saRepository.Save(new StockAdjustment() { StockAdjustmentId = expectedId, CreatedBy = new UserService(context).FindUserByEmail("*****@*****.**"), CreatedDateTime = DateTime.Now, Remarks = "THIS IS A TEST", Status = new StatusService(context).FindStatusByStatusId(4), StockAdjustmentDetails = new List <StockAdjustmentDetail>() { new StockAdjustmentDetail() { StockAdjustmentId = expectedId, Item = new ItemService(context).FindItemByItemCode("E030"), OriginalQuantity = 20, AfterQuantity = 30, } } }); var controller = new StockAdjustmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; // Act IHttpActionResult actionResult = controller.GetStockAdjustmentsForSupervisor(new EmailViewModel() { Email = "*****@*****.**", }); var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <StockAdjustmentRequestViewModel> >; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.IsTrue(contentResult.Content.Select(s => s.StockAdjustmentId).Contains(expectedId)); Assert.IsTrue(contentResult.Content .SelectMany(s => s.StockAdjustmentRequestDetails.Where(x => x.ItemCode == "E030").Select(sd => sd.OriginalQuantity)) .FirstOrDefault().Contains(20.ToString())); }
public void FindStockMovementByStockAdjustmentIdTest() { //Arrange StockMovement a = new StockMovement(); a.CreatedDateTime = DateTime.Now; a.StockAdjustmentId = IdService.GetNewStockAdjustmentId(context); a.Item = context.Item.First(); stockmovementService.Save(a); int expected = context.StockMovement.Where(x => x.StockAdjustmentId == a.StockAdjustmentId).ToList().Count; //Act var result = stockmovementService.FindStockMovementByStockAdjustmentId(a.StockAdjustmentId).Count; stockmovementRepository.Delete(a); //Assert Assert.AreEqual(expected, result); }
public string CreatePendingStockAdjustment(List <ViewModelFromNew> list) { userService = new UserService(Context); stockAdjustmentService = new StockAdjustmentService(Context); itemService = new ItemService(Context); notificationService = new NotificationService(Context); List <StockAdjustmentDetail> detaillist = new List <StockAdjustmentDetail>(); StockAdjustment s = new StockAdjustment(); s.StockAdjustmentId = IdService.GetNewStockAdjustmentId(Context); s.CreatedBy = userService.FindUserByEmail(CurrentUserName); s.CreatedDateTime = DateTime.Now; foreach (ViewModelFromNew v in list) { StockAdjustmentDetail sd = new StockAdjustmentDetail(); string itemcode = v.Itemcode; Item item = itemService.FindItemByItemCode(itemcode); sd.ItemCode = itemcode; sd.Reason = (v.Reason == null) ? "" : v.Reason; sd.StockAdjustmentId = s.StockAdjustmentId; sd.OriginalQuantity = item.Inventory.Quantity; sd.AfterQuantity = v.Adjustment + sd.OriginalQuantity; detaillist.Add(sd); // stockAdjustmentDetailRepository.Save(sd); } s.StockAdjustmentDetails = detaillist; stockAdjustmentService.CreatePendingStockAdjustment(s); int flag = 0; foreach (ViewModelFromNew v in list) { if (v.Unitprice.CompareTo("250") == 1) { flag = 1; break; } } Department d = userService.FindUserByEmail(CurrentUserName).Department; ApplicationUser Supervisor = userService.FindSupervisorsByDepartment(d).First(); ApplicationUser Manager = d.Head; if (flag == 1) { Notification n = notificationService.CreateNotification(s, Manager); //send email and android notifications new NotificationApiController().SendNotification(n.NotificationId.ToString()); new NotificationApiController().SendEmail(n.NotificationId.ToString()); } if (flag == 0) { Notification n = notificationService.CreateNotification(s, Supervisor); //send email and android notifications new NotificationApiController().SendNotification(n.NotificationId.ToString()); new NotificationApiController().SendEmail(n.NotificationId.ToString()); } return(s.StockAdjustmentId); }
public IHttpActionResult Save(List <MobileSADViewModel> models) { stockAdjustmentService = new StockAdjustmentService(Context); userService = new UserService(Context); itemService = new ItemService(Context); notificationService = new NotificationService(Context); StockAdjustment SA; try { //create new StockAdjustment object SA = new StockAdjustment() { StockAdjustmentId = IdService.GetNewStockAdjustmentId(Context), StockAdjustmentDetails = new List <StockAdjustmentDetail>(), CreatedDateTime = DateTime.Now, CreatedBy = userService.FindUserByEmail(models.First().UserName) }; //convert viewmodels to StockAdmustmentDetails list and link to stockadjustment object foreach (MobileSADViewModel m in models) { Item item = itemService.FindItemByItemCode(m.ItemCode); SA.StockAdjustmentDetails.Add(new StockAdjustmentDetail() { StockAdjustment = SA, ItemCode = m.ItemCode, Item = item, OriginalQuantity = Int32.Parse(m.OriginalQuantity), AfterQuantity = Int32.Parse(m.AfterQuantity), Reason = m.Reason }); } bool flag = false; foreach (StockAdjustmentDetail detail in SA.StockAdjustmentDetails) { foreach (ItemPrice p in detail.Item.ItemPrices) { if (p.Price >= 250) { flag = true; break; } } } ApplicationUser supervisor = userService.FindUserByEmail(models.First().UserName).Supervisor; ApplicationUser manager = supervisor.Supervisor; if (flag == true) { Notification n = notificationService.CreateNotification(SA, manager); new NotificationApiController().SendNotification(n.NotificationId.ToString()); new NotificationApiController().SendEmail(n.NotificationId.ToString()); } if (flag == false) { Notification n = notificationService.CreateNotification(SA, supervisor); new NotificationApiController().SendNotification(n.NotificationId.ToString()); new NotificationApiController().SendEmail(n.NotificationId.ToString()); } //save SA object into database stockAdjustmentService.updateToPendingStockAdjustment(SA); } catch (ArgumentException) { return(BadRequest("Unable to save Stock Adjustments!")); } return(Ok(SA.StockAdjustmentId)); }