/// <summary> /// This method is used for fetching supplier purchase order from database. - JJ /// </summary> /// <param name="POUD">ID OF PO</param> /// <returns>object of SupplierPOAC</returns> public SupplierPOAC GetSupplierPO(int POId) { if (_supplierPOContext.Fetch(x => x.Id == POId).Any()) { var supplierPurchaseOrder = _supplierPOContext.FirstOrDefault(x => x.Id == POId); var workLog = new List <WorkFlowLogAC>(); var lastLog = new WorkFlowLogAC(); if (supplierPurchaseOrder.RecordId != null && supplierPurchaseOrder.RecordId > 0) { workLog = GetSPOWorkFlowLog((int)supplierPurchaseOrder.RecordId); lastLog = GetSPOLog((int)supplierPurchaseOrder.RecordId); } var itemList = GetSupplierPOItemList(supplierPurchaseOrder.Id, supplierPurchaseOrder.PurchaseOrderNumber); var branchList = GetSPOBranchList(supplierPurchaseOrder.Id); SupplierPOAC supplierPO = new SupplierPOAC(); supplierPO.Id = supplierPurchaseOrder.Id; supplierPO.DueDate = supplierPurchaseOrder.DueDate; supplierPO.IsApproved = supplierPurchaseOrder.IsApproved; supplierPO.IsConfirmed = supplierPurchaseOrder.IsConfirmed; supplierPO.IsRejected = supplierPurchaseOrder.IsRejected; supplierPO.IsCanceled = supplierPurchaseOrder.IsCanceled; supplierPO.IsReceived = supplierPurchaseOrder.IsReceived; supplierPO.IsSend = supplierPurchaseOrder.IsSend; supplierPO.IsSubmitted = supplierPurchaseOrder.IsSubmitted; supplierPO.UserId = supplierPurchaseOrder.UserId; supplierPO.IsCancelApproved = supplierPurchaseOrder.IsCancelApproved; supplierPO.IsPartiallyReceived = supplierPurchaseOrder.IsPartiallyReceived; supplierPO.IsCancelApproved = supplierPurchaseOrder.IsCancelApproved; supplierPO.PurchaseOrderNumber = supplierPurchaseOrder.PurchaseOrderNumber; supplierPO.InitiationBranchId = supplierPurchaseOrder.InitiationBranchId; supplierPO.InitiationBranchName = supplierPurchaseOrder.InitiatorBranch.Name; supplierPO.IssueDate = supplierPurchaseOrder.CreatedDateTime; supplierPO.SupplierId = supplierPurchaseOrder.SupplierId; supplierPO.SupplierName = supplierPurchaseOrder.SupplierProfile.NameEn; supplierPO.IsVerified = supplierPurchaseOrder.IsVerified; supplierPO.SupplierCode = supplierPurchaseOrder.SupplierProfile.Code; supplierPO.WorkFlowLog = workLog; supplierPO.SupplierItem = itemList; supplierPO.SPOBranch = branchList; supplierPO.ParentRecordId = supplierPurchaseOrder.RecordId; supplierPO.LastLog = lastLog; return(supplierPO); } else { return(null); } }
/// <summary> /// This method is used for fetch supplier purchase order in database. - JJ /// </summary> /// <param name="id">id of spo</param> /// <returns>object of SupplierPOAC</returns> public SupplierPOAC GetSupplierPO(int id) { try { if (_supplierPOContext.Fetch(x => x.Id == id).Any()) { var spo = _supplierPOContext.Find(id); SupplierPOAC supplierPOAC = new SupplierPOAC(); supplierPOAC.PurchaseOrderNumber = spo.PurchaseOrderNumber; supplierPOAC.Id = spo.Id; supplierPOAC.UserId = spo.UserId; supplierPOAC.SupplierId = spo.SupplierId; supplierPOAC.DueDate = spo.DueDate; supplierPOAC.ReceivingDate = spo.DueDate; supplierPOAC.CreatedDateTime = spo.CreatedDateTime; supplierPOAC.ParentRecordId = spo.RecordId; supplierPOAC.SupplierName = spo.SupplierProfile.NameEn; supplierPOAC.SupplierProfile = spo.SupplierProfile; supplierPOAC.SupplierTypeId = spo.SupplierProfile.SupplierTypeId; supplierPOAC.IsApproved = spo.IsApproved; supplierPOAC.IsCanceled = spo.IsCanceled; supplierPOAC.IsConfirmed = spo.IsConfirmed; supplierPOAC.InitiationBranchId = spo.InitiationBranchId; supplierPOAC.InitiationBranchName = spo.InitiatorBranch.Name; supplierPOAC.IsRejected = spo.IsRejected; supplierPOAC.IsPartiallyReceived = spo.IsPartiallyReceived; supplierPOAC.IsSend = spo.IsSend; supplierPOAC.SPOBranch = _supplierPOWorkListContext.GetSPOBranchList(id); return(supplierPOAC); } else { return(null); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// This method is used to edit spo and delete item of spo - JJ /// </summary> /// <param name="supplierPO">object of SupplierPOAC</param> /// <returns>status</returns> public string EditSPO(SupplierPOAC supplierPO) { try { var supplierPurchaseOrder = _supplierPOContext.First(x => x.Id == supplierPO.Id); if (supplierPurchaseOrder.DueDate == supplierPO.DueDate) { supplierPurchaseOrder.IsNotProcessed = true; } else { supplierPurchaseOrder.IsNotProcessed = false; } supplierPurchaseOrder.DueDate = supplierPO.DueDate; supplierPurchaseOrder.IsRejected = false; supplierPurchaseOrder.ModifiedDateTime = DateTime.UtcNow; var oldItems = _purchaseOrderItemContext.Fetch(x => x.PurchaseOrderId == supplierPO.Id).ToList(); var firstCollection = from item in supplierPO.SupplierItem select new { FreeQuantity = item.FreeQuantity, ItemId = item.ItemId, OrderCostPrice = item.OrderCostPrice, OrderQuantity = item.OrderQuantity, ReceivingCostPrice = item.OrderCostPrice, ReceivingQuantity = item.OrderQuantity, PurchaseOrderId = supplierPurchaseOrder.Id, PercentageDiscount = item.PercentageDiscount }; var secCollection = from item in oldItems select new { FreeQuantity = item.FreeQuantity, ItemId = item.ItemId, OrderCostPrice = item.OrderCostPrice, OrderQuantity = item.OrderQuantity, ReceivingCostPrice = item.OrderCostPrice, ReceivingQuantity = item.OrderQuantity, PurchaseOrderId = supplierPurchaseOrder.Id, PercentageDiscount = item.PercentageDiscount }; var except = firstCollection.Except(secCollection); var length = except.ToList().Count; var except2 = secCollection.Except(firstCollection); var length2 = except2.ToList().Count; if (length > 0 || length2 > 0) { supplierPurchaseOrder.IsNotProcessed = false; DeleteItems(supplierPO.Id); 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, PurchaseOrderId = supplierPurchaseOrder.Id, PercentageDiscount = item.PercentageDiscount, IsPercentageDiscount = true, ReceivingDate = supplierPO.DueDate, UpdatedDate = DateTime.UtcNow, SPOReceivingStatus = SPOReceivingStatus.NotReceived }; _purchaseOrderItemContext.Add(poItem); _purchaseOrderItemContext.SaveChanges(); } } else { supplierPurchaseOrder.IsNotProcessed = true; } var oldBranches = _purchaseOrderBranchContext.Fetch(x => x.PurchaseOrderId == supplierPurchaseOrder.Id).ToList(); var oldBranchList = from branch in oldBranches select new { BranchId = branch.BranchId, }; var newBranchList = from branch in supplierPO.SPOBranch select new { BranchId = branch.Id, }; var exceptBranch = oldBranchList.Except(newBranchList); var blenghth = exceptBranch.ToList().Count; var exceptBranch2 = newBranchList.Except(oldBranchList); var blength2 = exceptBranch2.ToList().Count; if (blenghth > 0 || blength2 > 0) { supplierPurchaseOrder.IsNotProcessed = false; DeleteBranches(supplierPO.Id); foreach (var branch in supplierPO.SPOBranch) { var spoBranch = new PurchaseOrderBranch { CreatedDateTime = DateTime.UtcNow, BranchId = branch.Id, PurchaseOrderId = supplierPurchaseOrder.Id }; _purchaseOrderBranchContext.Add(spoBranch); _purchaseOrderBranchContext.SaveChanges(); } } else { if (supplierPurchaseOrder.IsNotProcessed) { supplierPurchaseOrder.IsNotProcessed = true; } } _supplierPOContext.Update(supplierPurchaseOrder); _supplierPOContext.SaveChanges(); return("ok"); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// This method is used to update supplierPO - JJ /// </summary> /// <param name="supplierPO">object of SupplierPOAC</param> /// <param name="userName">currently logged in user's user name</param> /// <returns>status</returns> public string UpdateSPO(SupplierPOAC supplierPO, string userName) { if (supplierPO.DueDate == DateTime.MinValue) { supplierPO.DueDate = DateTime.UtcNow.AddDays(2); } try { var currentUser = _userDetailContext.FirstOrDefault(x => x.UserName == userName); // u will have to change it as there are 2 with these conditions // check when edit is called //i.e. after getting rejected or before approving if (_supplierPOContext.Fetch(x => x.Id == supplierPO.Id).Any()) { var spo = _supplierPOContext.Find(supplierPO.Id); if (spo.IsSubmitted) { if (supplierPO.IsRejected) { var log = _workFlowLogContext.Fetch(x => x.RecordId == supplierPO.ParentRecordId).ToList().LastOrDefault(); if (log.WorkFlowDetail.AssignedId == currentUser.RoleId) { var workFlowLog = _IWorkFlowDetailsRepository.GetResubmitActionWorkFlow((int)supplierPO.ParentRecordId, supplierPO, supplierPO, "Updated", supplierPO.InitiationComment, currentUser); if (workFlowLog != null) { var workFlowDeatail = _workFlowContext.Find(workFlowLog.WorkFlowId); _supplierPOWorkListContext.SaveSupplierPurchaseOrderLog(StringConstants.ReSubmitedAction, supplierPO.InitiationComment, supplierPO.Id, workFlowLog.RecordId, currentUser.RoleName, workFlowLog.Stage, userName); if (workFlowDeatail.IsApproval || workFlowDeatail.IsReview || workFlowDeatail.NextActivity.AcceptPermission == StringConstants.FurtherApproval) { supplierPO.IsApproved = false; } else { supplierPO.IsApproved = true; } return(EditSPO(supplierPO)); } else { return(StringConstants.WorkFlowNotCreated); } } else { return(StringConstants.WorkFlowNotCreated); } } else { return(EditSPO(supplierPO)); } } else { return(EditSPO(supplierPO)); } } else { return(StringConstants.PONotFound); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <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 is used for fetching supplier purchase order from database. - JJ /// </summary> /// <param name="POID">ID OF PO</param> /// <returns>object of SPOReceivingAC</returns> public SPOReceivingAC GetSupplierPO(int POId) { try { if (_supplierPOContext.Fetch(x => x.Id == POId).Any()) { var supplierPurchaseOrder = _supplierPOContext.Find(POId); var isCashPO = false; var SupplierDaysLimit = new List <DiscountDaysAC>(); if (supplierPurchaseOrder.SupplierProfile.SupplierType.ValueEn == "Cash") { isCashPO = true; } else { var daysLimit = _supplierDaysLimitContext.Fetch(x => x.SupplierId == supplierPurchaseOrder.SupplierId).ToList(); foreach (var day in daysLimit) { var dayAC = new DiscountDaysAC { CreatedDateTime = day.CreatedDateTime, Days = day.Days, Discount = day.Discount, SupplierId = day.SupplierId }; SupplierDaysLimit.Add(dayAC); } } var itemList = _supplierPOWorkListRepository.GetSupplierPOItemList(supplierPurchaseOrder.Id, supplierPurchaseOrder.PurchaseOrderNumber); var branchList = _supplierPOWorkListRepository.GetSPOBranchList(supplierPurchaseOrder.Id); SupplierPOAC supplierPO = new SupplierPOAC(); supplierPO.Id = supplierPurchaseOrder.Id; supplierPO.DueDate = supplierPurchaseOrder.DueDate; supplierPO.IsApproved = supplierPurchaseOrder.IsApproved; supplierPO.IsCashPO = isCashPO; supplierPO.IsConfirmed = supplierPurchaseOrder.IsConfirmed; supplierPO.IsRejected = supplierPurchaseOrder.IsRejected; supplierPO.IsCanceled = supplierPurchaseOrder.IsCanceled; supplierPO.IsSend = supplierPurchaseOrder.IsSend; supplierPO.IsPartiallyReceived = supplierPurchaseOrder.IsPartiallyReceived; supplierPO.IsCancelApproved = supplierPurchaseOrder.IsCancelApproved; supplierPO.PurchaseOrderNumber = supplierPurchaseOrder.PurchaseOrderNumber; supplierPO.IssueDate = supplierPurchaseOrder.CreatedDateTime; supplierPO.SupplierId = supplierPurchaseOrder.SupplierId; supplierPO.SupplierName = supplierPurchaseOrder.SupplierProfile.NameEn; supplierPO.SupplierCode = supplierPurchaseOrder.SupplierProfile.Code; supplierPO.SPOBranch = branchList; supplierPO.ParentRecordId = supplierPurchaseOrder.RecordId; if (SupplierDaysLimit.Count > 0) { supplierPO.TotalDaysLimit = supplierPurchaseOrder.SupplierProfile.TotalDaysLimit; supplierPO.DiscountDays = SupplierDaysLimit; } var spoReceiving = new SPOReceivingAC { POItem = itemList, SupplierPOAC = supplierPO, SPOBill = GetSPOBill(POId) }; return(spoReceiving); } else { return(null); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }