/// <summary> /// This method is used for cancel supplier purchase order in database. - JJ /// </summary> /// <param name="Comment">Comment of the person who cancels</param> /// <param name="RecordId">Id of Parent Record</param> /// <param name="userName"> Currently logged in user's username </param> /// <returns>null</returns> public string CancelSupplierPO(string Comment, int RecordId, string userName) { var currentUser = _userDetailContext.First(x => x.UserName == userName && x.IsDelete == false); var spo = new SupplierPurchaseOrder(); if (_supplierPOContext.Fetch(x => x.RecordId == RecordId).Any()) { spo = _supplierPOContext.First(x => x.RecordId == RecordId); } if (spo != null) { var log = _workFlowLogContext.Fetch(x => x.RecordId == RecordId).ToList().Last(); if (log.WorkFlowDetail.AssignedId == currentUser.RoleId) { if (_workFlowContext.Fetch(x => x.Activity.Name == StringConstants.Review && x.ParentActivityId == log.WorkFlowId).Any()) { var activityWorkFlow = _workFlowContext.FirstOrDefault(x => x.Activity.Name == StringConstants.Review && x.ParentActivityId == log.WorkFlowId); Comment = Comment == "." ? "" : Comment; var workFlowLog = new WorkFlowLog { Comments = Comment, CreatedDateTime = DateTime.UtcNow, RecordId = RecordId, RoleId = currentUser.RoleId, UserId = currentUser.UserId, WorkFlowId = activityWorkFlow.Id, Action = "Canceled", Stage = "" + currentUser.RoleName + " " + activityWorkFlow.Activity.Name }; _workFlowLogContext.Add(workFlowLog); _workFlowLogContext.SaveChanges(); SaveSupplierPurchaseOrderLog("Cancelled", Comment, spo.Id, workFlowLog.RecordId, currentUser.RoleName, "" + currentUser.RoleName + " " + activityWorkFlow.Activity.Name, currentUser.UserName); spo.IsCanceled = true; spo.IsCancelApproved = false; spo.ModifiedDateTime = DateTime.UtcNow; _supplierPOContext.Update(spo); _supplierPOContext.SaveChanges(); return("ok"); } else { return(StringConstants.WorkFlowNotCreated); } } else { return(StringConstants.WorkFlowNotCreated); } } else { return(StringConstants.PONotFound); } }
/// <summary> /// Update the Item Profiles as per Purchase Order Items - JJ /// </summary> /// <param name="spoId"></param> private void UpdateItem(int spoId) { SupplierPurchaseOrder spo = _supplierPOContext.Find(spoId); List <PurchaseOrderBranch> spoBranches = _purchaseOrderBranchContext.Fetch(x => x.PurchaseOrderId == spoId).ToList(); List <PurchaseOrderItem> poItems = _purchaseOrderItemContext.Fetch(x => x.PurchaseOrderId == spoId).ToList(); foreach (PurchaseOrderItem item in poItems) { ItemProfile itemProfile = _itemProfileContext.Find(item.ItemId); itemProfile.PreviousCostPrice = itemProfile.CostPrice; itemProfile.CostPrice = GetItemPrice(item, itemProfile, spoBranches); var icr = _icrDetailContext.FirstOrDefault(x => x.SPOItemId == item.Id && !x.IsDeleted); if (icr != null) { var icrPrice = _icrPriceContext.FirstOrDefault(x => x.IcrId == icr.Id); if (icrPrice != null) { itemProfile.SellPrice = icrPrice.ModifyingSellPrice; itemProfile.SellPriceA = icrPrice.ModifyingSellPriceA; itemProfile.SellPriceB = icrPrice.ModifyingSellPriceB; itemProfile.SellPriceC = icrPrice.ModifyingSellPriceC; itemProfile.SellPriceD = icrPrice.ModifyingSellPriceD; } } _itemProfileContext.Update(itemProfile); _itemProfileContext.SaveChanges(); foreach (PurchaseOrderBranch branch in spoBranches) { var itemQuantity = _itemQuantityContext.FirstOrDefault(x => x.ItemId == item.ItemId && x.BranchId == branch.BranchId); if (itemQuantity != null) { itemQuantity.ActualQuantity += item.ReceivingQuantity; _itemQuantityContext.Update(itemQuantity); _itemQuantityContext.SaveChanges(); } else { var newItemQuantity = new ItemQuantity { ActualQuantity = item.ReceivingQuantity, BranchId = branch.BranchId, CreatedDateTime = DateTime.UtcNow, ItemId = item.ItemId, //client asked to keep test data for the time being MaxQuantity = item.ReceivingQuantity, MinQuantity = item.ReceivingQuantity }; _itemQuantityContext.Add(newItemQuantity); _itemQuantityContext.SaveChanges(); } } } }
/// <summary> /// This method is used for reject supplier purchase order in database. - JJ /// </summary> /// <param name="Comment">Comment of the rejector</param> /// <param name="RecordId">Id of Parent Record</param> /// <param name="userName"> Currently logged in user's username </param> /// <returns>status</returns> public string RejectSupplierPO(string Comment, int RecordId, string userName) { try { var spo = new SupplierPurchaseOrder(); if (_supplierPOContext.Fetch(x => x.RecordId == RecordId).Any()) { spo = _supplierPOContext.First(x => x.RecordId == RecordId); } if (spo != null) { var currentUser = _userDetailContext.First(x => x.UserName == userName && x.IsDelete == false); var log = _workFlowLogContext.Fetch(x => x.RecordId == RecordId).ToList().Last(); if (log.WorkFlowDetail.AssignedId == currentUser.RoleId) { if (Comment == ".") { Comment = ""; } var loger = _iWorkFlowDetailsRepository.GetApprovalActionWorkFLow(RecordId, StringConstants.ApprovAction, Comment, currentUser, false); if (loger != null) { log = _workFlowLogContext.Fetch(x => x.RecordId == RecordId).ToList().Last(); SaveSupplierPurchaseOrderLog("Rejected", Comment, spo.Id, RecordId, currentUser.RoleName, "" + currentUser.RoleName + " " + log.WorkFlowDetail.Activity.Name, userName); spo.IsApproved = false; spo.IsRejected = true; spo.ModifiedDateTime = DateTime.UtcNow; _supplierPOContext.Update(spo); _supplierPOContext.SaveChanges(); return("ok"); } else { return(StringConstants.WorkFlowNotCreated); } } else { return(StringConstants.WorkFlowNotCreated); } } else { return(StringConstants.PONotFound); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// This method is used for review supplier purchase order in database. - JJ /// </summary> /// <param name="Comment">Comment of the approver</param> /// <param name="RecordId">Id of Parent Record</param> /// <param name="userName"> Currently logged in user's username </param> /// <returns>status</returns> public string ReviewSupplierPO(string Comment, int RecordId, UserDetail user) { try { var spo = new SupplierPurchaseOrder(); if (_supplierPOContext.Fetch(x => x.RecordId == RecordId).Any()) { spo = _supplierPOContext.First(x => x.RecordId == RecordId); } if (spo != null) { var log = _workFlowLogContext.Fetch(x => x.RecordId == RecordId).ToList().Last(); var prevActivity = log.WorkFlowDetail.NextActivity.AcceptPermission; if (log.WorkFlowDetail.AssignedId == user.RoleId) { if (Comment == ".") { Comment = null; } var loger = _iWorkFlowDetailsRepository.GetReviewActionWorkFlow(RecordId, spo, spo, StringConstants.ReviewAction, Comment, user); if (loger != null) { SaveSupplierPurchaseOrderLog("Reviewed", Comment, spo.Id, loger.RecordId, user.RoleName, loger.Stage, user.UserName); return(CheckApproved(RecordId, true, prevActivity)); } else { return(StringConstants.WorkFlowNotCreated); } } else { return(StringConstants.WorkFlowNotCreated); } } else { return(StringConstants.PONotFound); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// This method used for get list of purchase order item by purchase order item id. /// </summary> /// <param name="purchaseOrderItemId"></param> /// <returns></returns> public ReceivingPurchaseOrderAC GetListOfPurchaseOrderItem(int purchaseOrderId) { try { ReceivingPurchaseOrderAC receivingPurchaseOrderAC = new ReceivingPurchaseOrderAC(); List <RecevingPurchaseOrderList> listOfReceivingPurchaseOrder = new List <RecevingPurchaseOrderList>(); List <PurchaseOrderItem> listOfPurchaseOrderItem = _purchaseOrderItemContext.Fetch(x => x.PurchaseOrderId == purchaseOrderId).ToList(); foreach (var item in listOfPurchaseOrderItem) { RecevingPurchaseOrderList recevingPurchaseOrderList = new RecevingPurchaseOrderList(); recevingPurchaseOrderList.Barcode = item.ItemProfile.Barcode; recevingPurchaseOrderList.Code = item.ItemProfile.Code; recevingPurchaseOrderList.Discount = item.PercentageDiscount; recevingPurchaseOrderList.FreeQuantity = item.FreeQuantity; recevingPurchaseOrderList.ItemName = item.ItemProfile.ItemNameEn; recevingPurchaseOrderList.ReceivingQuantity = item.ReceivingQuantity; recevingPurchaseOrderList.ReceivnigCostPrice = item.ReceivingCostPrice; recevingPurchaseOrderList.SPOReceivingStatus = item.SPOReceivingStatus.ToString(); recevingPurchaseOrderList.Unit = item.ItemProfile.SystemParameter.ValueEn; listOfReceivingPurchaseOrder.Add(recevingPurchaseOrderList); } receivingPurchaseOrderAC.RecevingPurchaseOrderList = listOfReceivingPurchaseOrder; SupplierPurchaseOrder supplierPurchaseOrder = new SupplierPurchaseOrder(); supplierPurchaseOrder = _supplierPOContext.FirstOrDefault(x => x.Id == purchaseOrderId); if (supplierPurchaseOrder.IsReceived || supplierPurchaseOrder.IsVerified) { receivingPurchaseOrderAC.IsReceived = true; } return(receivingPurchaseOrderAC); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// This method is used for approving cancel supplier purchase order in database. - JJ /// </summary> /// <param name="Comment">Comment of the person who approves cancel</param> /// <param name="RecordId">Id of Parent Record</param> /// <param name="userName"> Currently logged in user's username </param> /// <returns>null</returns> public void ApproveCancelSupplierPO(string Comment, int RecordId, string userName, int Status) { var spo = new SupplierPurchaseOrder(); if (_supplierPOContext.Fetch(x => x.RecordId == RecordId).Any()) { spo = _supplierPOContext.First(x => x.RecordId == RecordId); } if (spo != null) { bool isCancelApproved; bool approve = Status == 1 ? true : false; var currentUser = _userDetailContext.First(x => x.UserName == userName && x.IsDelete == false); var log = _workFlowLogContext.Fetch(x => x.RecordId == RecordId).ToList().Last(); if (log.WorkFlowDetail.AssignedId == currentUser.RoleId && _workFlowContext.Fetch(x => x.Activity.Name == StringConstants.Review && x.ParentActivityId == log.WorkFlowId).Any()) { _workFlowContext.Fetch(x => x.Activity.Name == StringConstants.Review && x.ParentActivityId == log.WorkFlowId).ToList(); if (approve) { var activityWorkFlow = _workFlowContext.FirstOrDefault(x => x.Activity.Name == StringConstants.Review && x.ParentActivityId == log.WorkFlowId && x.IsApprovePanel); if (Comment == ".") { Comment = ""; } var workFlowLog = new WorkFlowLog { Comments = Comment, CreatedDateTime = DateTime.UtcNow, RecordId = RecordId, RoleId = currentUser.RoleId, UserId = currentUser.UserId, WorkFlowId = activityWorkFlow.Id, Action = "Cancel Approved", Stage = "" + currentUser.RoleName + " " + activityWorkFlow.Activity.Name }; _workFlowLogContext.Add(workFlowLog); _workFlowLogContext.SaveChanges(); SaveSupplierPurchaseOrderLog("Cancel Approved", Comment, spo.Id, workFlowLog.RecordId, currentUser.RoleName, "" + currentUser.RoleName + " " + activityWorkFlow.Activity.Name, currentUser.UserName); isCancelApproved = (activityWorkFlow.IsApproval || activityWorkFlow.IsReview) ? false : true; spo.IsCanceled = true; spo.IsCancelApproved = isCancelApproved; spo.ModifiedDateTime = DateTime.UtcNow; _supplierPOContext.Update(spo); _supplierPOContext.SaveChanges(); } else { var activityWorkFlow = _workFlowContext.FirstOrDefault(x => x.Activity.Name == StringConstants.Review && x.ParentActivityId == log.WorkFlowId && x.IsRejectPanel); Comment = (Comment == ".") ? "" : Comment; var workFlowLog = new WorkFlowLog { Comments = Comment, CreatedDateTime = DateTime.UtcNow, RecordId = RecordId, RoleId = currentUser.RoleId, UserId = currentUser.UserId, WorkFlowId = activityWorkFlow.Id, Action = "Rejected Cancel", Stage = "" + currentUser.RoleName + " " + activityWorkFlow.Activity.Name }; _workFlowLogContext.Add(workFlowLog); _workFlowLogContext.SaveChanges(); SaveSupplierPurchaseOrderLog("Rejected Cancel", Comment, spo.Id, workFlowLog.RecordId, currentUser.RoleName, "" + currentUser.RoleName + " " + activityWorkFlow.Activity.Name, currentUser.UserName); spo.IsCanceled = false; spo.IsCancelApproved = false; spo.ModifiedDateTime = DateTime.UtcNow; _supplierPOContext.Update(spo); _supplierPOContext.SaveChanges(); } } } }
/// <summary> /// This method is used for insert new supplier purchase order in database. - JJ /// </summary> /// <param name="supplierPO"> object of SupplierPOAC</param> /// <param name="company">object of Company</param> /// <param name="userName">current user's username</param> /// <returns>status</returns> public string SaveSupplierPO(SupplierPOAC supplierPO, string userName, CompanyDetail company) { try { var log = new WorkFlowLog(); var currentUser = _userDetailContext.First(x => x.UserName == userName && x.IsDelete == false); var companyConfig = _companyConfigurationContext.First(x => x.CompanyId == company.Id); var sponumber = companyConfig.SPOInvoiceNo; bool IsApproved = false; bool IsConfirmed = false; bool IsCanceled = false; bool IsRejected = false; bool IsPartiallyReceived = false; string ponumber = PurchaseOrderNumberGenerator(sponumber, 4); if (supplierPO.IsSubmitted) { var workFlowLog = _IWorkFlowDetailsRepository.GetInitiationActionWorkFlow(StringConstants.SupplierPurchaseOrder, StringConstants.CreateSupplierPurchaseOrder, currentUser, company, supplierPO, supplierPO.InitiationComment, supplierPO); if (workFlowLog != null) { log = (WorkFlowLog)workFlowLog.Item1; supplierPO.ParentRecordId = log.RecordId; } else { return(StringConstants.WorkFlowNotCreated); } var activityWorkFlow = _workFlowContext.FirstOrDefault(x => x.Id == log.WorkFlowId); if (!activityWorkFlow.NextActivity.IsClosed) { IsApproved = false; } else { IsApproved = true; } } var supplierType = _paramTypeContext.Fetch(x => x.Param.Key == StringConstants.SupplierType); bool isCredit = false; foreach (var type in supplierType) { if (type.Id == supplierPO.SupplierTypeId && type.ValueEn == StringConstants.Credit) { isCredit = true; } else { isCredit = false; } } var supplierPurchaseOrder = new SupplierPurchaseOrder { UserId = currentUser.Id, RecordId = supplierPO.ParentRecordId, SupplierId = supplierPO.SupplierId, InitiationBranchId = supplierPO.InitiationBranchId, IsApproved = IsApproved, IsConfirmed = IsConfirmed, IsNotProcessed = true, IsRejected = IsRejected, IsCanceled = IsCanceled, IsPartiallyReceived = IsPartiallyReceived, IsSend = false, IsSubmitted = supplierPO.IsSubmitted, DueDate = supplierPO.DueDate, CreatedDateTime = DateTime.UtcNow, CreditDaysLimit = supplierPO.SupplierDaysLimit, IsCreditPayment = isCredit, UpdatedDate = DateTime.UtcNow, PurchaseOrderNumber = ponumber }; _supplierPOContext.Add(supplierPurchaseOrder); _supplierPOContext.SaveChanges(); if (supplierPO.IsSubmitted) { _supplierPOWorkListContext.SaveSupplierPurchaseOrderLog(log.Action, supplierPO.InitiationComment, supplierPurchaseOrder.Id, log.RecordId, currentUser.RoleName, log.Stage, currentUser.UserName); } foreach (var branch in supplierPO.SPOBranch) { var spoBranch = new PurchaseOrderBranch { CreatedDateTime = DateTime.UtcNow, BranchId = branch.Id, PurchaseOrderId = supplierPurchaseOrder.Id }; _purchaseOrderBranchContext.Add(spoBranch); _purchaseOrderBranchContext.SaveChanges(); } foreach (var item in supplierPO.SupplierItem) { var poItem = new PurchaseOrderItem { CreatedDateTime = DateTime.UtcNow, FreeQuantity = item.FreeQuantity, ItemId = item.ItemId, OrderCostPrice = item.OrderCostPrice, OrderQuantity = item.OrderQuantity, ReceivingCostPrice = item.OrderCostPrice, BillCostPrice = item.OrderCostPrice, ReceivingQuantity = item.OrderQuantity, SystemParameterId = item.UnitParamTypeId, PercentageDiscount = item.PercentageDiscount, IsPercentageDiscount = true, PurchaseOrderId = supplierPurchaseOrder.Id, ReceivingDate = supplierPO.DueDate, UpdatedDate = DateTime.UtcNow, SPOReceivingStatus = SPOReceivingStatus.NotReceived }; _purchaseOrderItemContext.Add(poItem); _purchaseOrderItemContext.SaveChanges(); } return(StringConstants.SPOCreated); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// This method used for insert into account entroes table.- JJ /// </summary> /// <param name="destruction"></param> /// <param name="totalCostPrice"></param> private void InsertIntoAccountEntries(SupplierPurchaseOrder supplierPO, SPOPaymentAC supplierPOPayment, decimal?discount) { try { List <DoubleEntry> listOfDoubleEntry = new List <DoubleEntry>(); var spoBranches = _purchaseOrderBranchContext.Fetch(x => x.PurchaseOrderId == supplierPO.Id).ToList(); foreach (var branch in spoBranches) { if (supplierPO.SupplierProfile.SupplierType.ValueEn == StringConstants.Cash)//check whether cash po. { var ledgersForCash = _iAccountingRepository.GetAccountLedgerByName(StringConstants.CashInHand, Convert.ToInt32(branch.BranchId)); var ledgersForStockInHand = _iAccountingRepository.GetAccountLedgerByName(StringConstants.StockInHand, Convert.ToInt32(branch.BranchId)); var cash = 0M; cash = supplierPOPayment.Cash; if (discount > 0) { cash += (decimal)discount; } if (ledgersForCash != null && ledgersForStockInHand != null) { listOfDoubleEntry.Add(new DoubleEntry { LedgerId = ledgersForCash.Id, TransactionDate = DateTime.UtcNow, Credit = cash, Debit = 0, ActivityName = StringConstants.SPOPayment, CreatedDateTime = DateTime.UtcNow, Description = "Entry for SPO no. " + supplierPO.PurchaseOrderNumber }); listOfDoubleEntry.Add(new DoubleEntry { LedgerId = ledgersForStockInHand.Id, TransactionDate = DateTime.UtcNow, Credit = 0, Debit = cash, ActivityName = StringConstants.SPOPayment, CreatedDateTime = DateTime.UtcNow, Description = "Entry for SPO no. " + supplierPO.PurchaseOrderNumber }); } } else { var ledgersForSupplier = _iAccountingRepository.GetAccountLedgerBySupplier(supplierPO.SupplierId); var ledgersForStockInHand = _iAccountingRepository.GetAccountLedgerByName(StringConstants.StockInHand, Convert.ToInt32(branch.BranchId)); var cheque = 0M; cheque = supplierPOPayment.Cheque; if (discount > 0) { cheque += (decimal)discount; } if (ledgersForSupplier != null && ledgersForStockInHand != null) { listOfDoubleEntry.Add(new DoubleEntry { LedgerId = ledgersForSupplier.Id, TransactionDate = DateTime.UtcNow, Credit = cheque, Debit = 0, ActivityName = StringConstants.SPOPayment, CreatedDateTime = DateTime.UtcNow, Description = "Entry for SPO no. " + supplierPO.PurchaseOrderNumber }); listOfDoubleEntry.Add(new DoubleEntry { LedgerId = ledgersForStockInHand.Id, TransactionDate = DateTime.UtcNow, Credit = 0, Debit = cheque, ActivityName = StringConstants.SPOPayment, CreatedDateTime = DateTime.UtcNow, Description = "Entry for SPO no. " + supplierPO.PurchaseOrderNumber }); } } if (discount > 0) { var ledgersForIncome = _iAccountingRepository.GetAccountLedgerByName(StringConstants.Income, Convert.ToInt32(branch.BranchId)); if (ledgersForIncome != null) { listOfDoubleEntry.Add(new DoubleEntry { LedgerId = ledgersForIncome.Id, TransactionDate = DateTime.UtcNow, Credit = (decimal)discount, Debit = 0, ActivityName = StringConstants.SPOPayment, CreatedDateTime = DateTime.UtcNow, Description = "Entry for SPO no. " + supplierPO.PurchaseOrderNumber }); } } if (supplierPOPayment.Credit > 0) { var ledgersForSupplier = _iAccountingRepository.GetAccountLedgerBySupplier(supplierPO.SupplierId); var ledgersForCreditNote = _iAccountingRepository.GetAccountLedgerByName(StringConstants.CRNote, Convert.ToInt32(branch.BranchId)); if (ledgersForSupplier != null && ledgersForCreditNote != null) { listOfDoubleEntry.Add(new DoubleEntry { LedgerId = ledgersForCreditNote.Id, TransactionDate = DateTime.UtcNow, Credit = supplierPOPayment.Credit, Debit = 0, ActivityName = StringConstants.SPOPayment, CreatedDateTime = DateTime.UtcNow, Description = "Entry for SPO no. " + supplierPO.PurchaseOrderNumber }); listOfDoubleEntry.Add(new DoubleEntry { LedgerId = ledgersForSupplier.Id, TransactionDate = DateTime.UtcNow, Credit = 0, Debit = supplierPOPayment.Credit, ActivityName = StringConstants.SPOPayment, CreatedDateTime = DateTime.UtcNow, Description = "Entry for SPO no. " + supplierPO.PurchaseOrderNumber }); } } } if (listOfDoubleEntry.Any()) { _iAccountingRepository.AddAccountingEntries(listOfDoubleEntry); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// This method is used for receive an item of SPO - JJ /// </summary> /// <param name="SupplierItemAC">object of SupplierItemAC</param> /// <param name="currentUser">object of UserDetail</param> /// <param name="company">object of CompanyDetail</param> /// <returns>receiving status id</returns> public int ReceiveSPOItem(SupplierItemAC SupplierItemAC, UserDetail currentUser, CompanyDetail company) { try { SupplierPurchaseOrder purchaseOrder = _supplierPOContext.Find(SupplierItemAC.PurchaseOrderId); purchaseOrder.IsVerified = false; purchaseOrder.IsReceived = false; purchaseOrder.ModifiedDateTime = DateTime.UtcNow; _supplierPOContext.Update(purchaseOrder); _supplierPOContext.SaveChanges(); PurchaseOrderItem poItem = _purchaseOrderItemContext.Fetch(x => x.ItemId == SupplierItemAC.ItemId && x.PurchaseOrderId == SupplierItemAC.PurchaseOrderId && x.SupplierPurchaseOrder.IsApproved && x.SupplierPurchaseOrder.IsSend).Include(x => x.ItemProfile).FirstOrDefault(); if (poItem != null) { IcrDetail icrDetail = poItem.ICRDetailId != null?_icrDetailContext.FirstOrDefault(x => !x.IsDeleted && x.Id == (int)poItem.ICRDetailId) : null; List <int> spoBranchIds = _purchaseOrderBranchContext.Fetch(x => x.PurchaseOrderId == purchaseOrder.Id).Select(x => x.BranchId).ToList(); //bit indicates whether an ICR is generated for item if it is generated then is it for this POItem. bool IsIcrForPOItem = true; List <ItemQuantity> itemQuantities = _itemQuantityContext.Fetch(x => x.ItemId == poItem.ItemId && spoBranchIds.Contains(x.BranchId)).ToList(); if (itemQuantities?.Count > 0) { IsIcrForPOItem = !(itemQuantities.Any(x => x.IsICRGenerated)); } if (IsIcrForPOItem && poItem.ItemProfile.IsItemChangeRequestGenerated) { IsIcrForPOItem = false; if (poItem.Id == icrDetail?.SPOItemId) { IsIcrForPOItem = true; } } if (IsIcrForPOItem) { if (poItem.ICRDetailId != null) { var icrPrice = _icrPriceContext.Fetch(x => x.IcrId == poItem.ICRDetailId).ToList().LastOrDefault(); if (icrPrice != null && icrPrice.ModifyingCostPrice == SupplierItemAC.ReceiveCostPrice) { var icr = _icrDetailContext.FirstOrDefault(x => x.Id == icrPrice.IcrId && !x.IsDeleted); if (icr != null && icr.IsApproved) { if (poItem.OrderQuantity > SupplierItemAC.ReceiveQuantity) { poItem.SPOReceivingStatus = SPOReceivingStatus.PartiallyReceived; } else { poItem.SPOReceivingStatus = SPOReceivingStatus.Received; } } else { poItem.SPOReceivingStatus = SPOReceivingStatus.NotReceived; } poItem.ModifiedDateTime = DateTime.UtcNow; _purchaseOrderItemContext.Update(poItem); _purchaseOrderItemContext.SaveChanges(); return((int)poItem.SPOReceivingStatus); } return(Receive(SupplierItemAC, currentUser, company)); } return(Receive(SupplierItemAC, currentUser, company)); } return(401); } return(404); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }