public List <ItemViewModel> Shortfall() { //FindInventoryShortfallItems return(purchaseOrderService.FindInventoryShortfallItems().Select(item => new ItemViewModel() { ItemCode = item.ItemCode, Description = item.Description, Quantity = item.Inventory.Quantity, ReorderLevel = item.ReorderLevel, ReorderQuantity = item.ReorderQuantity, Uom = item.Uom, UnfulfilledQuantity = requisitionService.FindUnfulfilledQuantityRequested(item), AmountToReorder = (item.Inventory.Quantity - requisitionService.FindUnfulfilledQuantityRequested(item) < item.ReorderLevel) ? Math.Max(requisitionService.FindUnfulfilledQuantityRequested(item) + item.ReorderQuantity, item.ReorderLevel - item.Inventory.Quantity + requisitionService.FindUnfulfilledQuantityRequested(item)) : 0 }).ToList()); }
public void FindUnfulfilledQuantityRequestedTest() { //arrange Requisition r1 = new Requisition(); r1.RequisitionId = "RANIAH1"; r1.Department = context.Department.Where(x => x.DepartmentCode == "COMM").ToList().First(); r1.CollectionPoint = context.CollectionPoint.Where(x => x.CollectionPointId == 1).ToList().First(); r1.RequisitionDetails = new List <RequisitionDetail>(); r1.Retrieval = null; r1.EmployeeRemarks = "Test by Gabriel"; r1.HeadRemarks = "Test by Gabriel Boss"; r1.Status = context.Status.Where(x => x.StatusId == 6).ToList().First();; // Approved r1.CreatedBy = null; r1.CreatedDateTime = DateTime.Now; Item i = new Item(); i.ItemCode = "IT1"; i.ReorderLevel = 100; i.ReorderQuantity = 500; i.CreatedDateTime = DateTime.Now; itemRepository.Save(i); RequisitionDetail rd1 = new RequisitionDetail(); rd1.Item = context.Item.Where(x => x.ItemCode == "IT1").ToList().First(); rd1.Quantity = 10; r1.RequisitionDetails.Add(rd1); requisitionRepository.Save(r1); Requisition r2 = new Requisition(); r2.RequisitionId = "RANIAH2"; r2.Department = context.Department.Where(x => x.DepartmentCode == "CPSC").ToList().First(); r2.CollectionPoint = context.CollectionPoint.Where(x => x.CollectionPointId == 1).ToList().First(); r2.RequisitionDetails = new List <RequisitionDetail>(); r2.Retrieval = null; r2.EmployeeRemarks = "Test by Gabriel"; r2.HeadRemarks = "Test by Gabriel Boss"; r2.Status = context.Status.Where(x => x.StatusId == 7).ToList().First();; // Req Processed r2.CreatedBy = null; r2.CreatedDateTime = DateTime.Now; RequisitionDetail rd2 = new RequisitionDetail(); rd2.Item = context.Item.Where(x => x.ItemCode == "IT1").ToList().First(); rd2.Quantity = 15; r2.RequisitionDetails.Add(rd2); requisitionRepository.Save(r2); //Act var result = requisitionService.FindUnfulfilledQuantityRequested(itemRepository.FindById("IT1")); //Assert Assert.AreEqual(result, 25); }