private List <ReceivingDetailModel> getPendingReceivingDetail(long poId) { List <ReceivingDetailModel> pendingReceivings = new List <ReceivingDetailModel>(); List <PurchaseOrderDetail> poDetails = poService.GetAllPODetail(poId).ToList(); List <Receiving> receivings = service.GetAllByPOId(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, poId).ToList(); List <ReceivingDetail> receivingDetails = new List <ReceivingDetail>(); foreach (var poDetail in poDetails) { receivingDetails.AddRange(service.GetAllByPODetailId(poDetail.Id).ToList()); List <ReceivingDetail> currentPODetailReceiving = receivingDetails.Where(rec => rec.PODetailId == poDetail.Id).ToList(); if (currentPODetailReceiving.Sum(rec => rec.Quantity) >= poDetail.Quantity) { continue; } else { pendingReceivings.Add(new ReceivingDetailModel { BalanceQty = poDetail.Quantity - currentPODetailReceiving.Sum(rec => rec.Quantity), Id = -poDetail.Id, ItemId = poDetail.ItemId, ItemName = itemService.GetSingle(poDetail.ItemId.ToString(), AuthenticationHelper.CompanyId.Value).ItemName, OrderQty = poDetail.Quantity, PODetailId = poDetail.Id, PurchaseQty = currentPODetailReceiving.Sum(rec => rec.Quantity), ThisPurchaseQty = poDetail.Quantity - currentPODetailReceiving.Sum(rec => rec.Quantity) }); } } return(pendingReceivings); }