public IHttpActionResult IncidentReportApproval(PosIncidentReportAc incidentReportDetails) { try { if (MerchantContext.Permission.IsAllowToReview) { if (incidentReportDetails.RecordId != null && _iWorkFlowDetailsRepository.CheckLastActionPerform(Convert.ToInt32(incidentReportDetails.RecordId), StringConstants.Initiate, MerchantContext.UserDetails.RoleId)) { return(Ok(new { status = StringConstants.AlreadyActivityProcessed })); } if (MerchantContext.Permission.IsAllowRecovery && incidentReportDetails.IsStatus) { _incidentReportRepository.UpdateIncidentReportDetails(incidentReportDetails); } var incidentReportDetail = _incidentReportRepository.IncidentReportApproval(incidentReportDetails, MerchantContext.UserDetails, MerchantContext.CompanyDetails); return(Ok(new { status = incidentReportDetail })); } else { return(Ok(new { status = "Not Allow Permission" })); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public IHttpActionResult ReviewIncidentReportDetails(PosIncidentReportAc incidentReportDetails) { try { if (MerchantContext.Permission.IsAllowToReview) { if (MerchantContext.Permission.IsAllowRecovery) { _incidentReportRepository.UpdateIncidentReportDetails(incidentReportDetails); } var incidentReportDetail = _incidentReportRepository.ReviewIncidentReportDetails(incidentReportDetails, MerchantContext.UserDetails, MerchantContext.CompanyDetails); return(Ok(new { status = incidentReportDetail })); } else { return(Ok(new { status = "Not Allow Permission" })); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public IHttpActionResult SubmitIncidentReport(PosIncidentReportAc incidentReportDetails) { try { if (MerchantContext.Permission.IsAllowedToInitiateIncidentReport) { var incidentReportDetail = _incidentReportRepository.SubmitIncidentReport(incidentReportDetails, MerchantContext.UserDetails, MerchantContext.CompanyDetails); return(Ok(new { status = incidentReportDetail })); } else { return(Ok(new { status = "Not Allow Permission" })); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// this method is used to update incide report details. /// </summary> /// <param name="incidentReportDetail"></param> public void UpdateIncidentReportDetails(PosIncidentReportAc incidentReportDetail) { try { var incidentdetails = _posIncidentReportDataRepository.FirstOrDefault( x => x.Id == incidentReportDetail.PosIncidentReportId); if (incidentdetails != null) { incidentdetails.CommitedQuantity = incidentReportDetail.CommitedQuantity; incidentdetails.CommittedGainValue = incidentReportDetail.CommittedGainValue; incidentdetails.CommittedLossValue = incidentReportDetail.CommittedLossValue; incidentdetails.ModifiedDateTime = DateTime.UtcNow; _posIncidentReportDataRepository.Update(incidentdetails); _posIncidentReportDataRepository.SaveChanges(); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
private PosIncidentReportAc MapPosIncidentReportAc(DomainModel.Models.IncidentReport.PosIncidentReport incidentReportDetails) { try { var incidentAc = new PosIncidentReportAc(); incidentAc = ApplicationClassHelper.ConvertType <DomainModel.Models.IncidentReport.PosIncidentReport, PosIncidentReportAc>(incidentReportDetails); if (incidentReportDetails.RecordId != null) { var parentRecredDetails = _parentRecordContext.FirstOrDefault(x => x.Id == incidentReportDetails.RecordId); if (parentRecredDetails != null) { var workFlowStatusDetails = _workFLowLogContext.Fetch(x => x.RecordId == parentRecredDetails.Id).ToList().Last(); if (workFlowStatusDetails != null) { incidentAc.WorkFlowStatus = workFlowStatusDetails.Action; } } } incidentAc.PosIncidentReportId = incidentReportDetails.Id; incidentAc.IncidentTypeName = incidentReportDetails.IncidentTypes.ValueEn; incidentAc.LossValue = incidentReportDetails.CommittedLossValue; incidentAc.GainValue = incidentReportDetails.CommittedGainValue; incidentAc.ResolveQuantity = incidentReportDetails.CommitedQuantity; incidentAc.ItemName = incidentReportDetails.ItemProfile.ItemNameEn; incidentAc.BranchName = incidentReportDetails.BranchDetail.Name; incidentAc.BranchId = (int)incidentReportDetails.BranchId; incidentAc.CostPrice = incidentReportDetails.ItemProfile.CostPrice; incidentAc.IncidentDate = incidentReportDetails.CreatedDateTime.ToString("dd/MM/yyyy hh:mm"); return(incidentAc); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// this method is used to either approve or reject the incident request by the id. /// </summary> /// <param name="incidentReportDetails"></param> /// <param name="userDetails"></param> /// <param name="companyDetails"></param> /// <returns></returns> public string IncidentReportApproval(PosIncidentReportAc incidentReportDetails, UserDetail userDetails, CompanyDetail companyDetails) { try { var incidentReportInfo = _posIncidentReportDataRepository.FirstOrDefault(x => x.Id == incidentReportDetails.PosIncidentReportId); if (incidentReportInfo != null) { var workFLowLastDetails = _workFLowLogContext.Fetch(x => x.RecordId == incidentReportInfo.RecordId).ToList().Last(); var workFlowCollection = _workFlowDetailContext.Fetch(x => x.ParentActivityId == workFLowLastDetails.WorkFlowId).ToList(); if (workFlowCollection.Count() != 0) { WorkFlowDetail currentWorkFlowDetails; if (incidentReportDetails.IsStatus) { currentWorkFlowDetails = workFlowCollection.FirstOrDefault(x => x.IsApprovePanel); if (currentWorkFlowDetails != null) { var workFlowLogDetails = SaveWorkFlowDetails(currentWorkFlowDetails, incidentReportInfo, userDetails, incidentReportDetails.Comment, StringConstants.ApprovAction); if (currentWorkFlowDetails.NextActivity.IsClosed && workFlowLogDetails.Id != 0) { UpdateItemCommitQuantity(incidentReportInfo); incidentReportInfo.IsActive = true; if (incidentReportInfo.IsReject) { incidentReportInfo.IsReject = false; } incidentReportInfo.ModifiedDateTime = DateTime.UtcNow; _posIncidentReportDataRepository.Update(incidentReportInfo); _posIncidentReportDataRepository.SaveChanges(); } return("Work Flow Created"); } } else { currentWorkFlowDetails = workFlowCollection.FirstOrDefault(x => x.IsRejectPanel); if (currentWorkFlowDetails != null) { var workFlowLogDetails = SaveWorkFlowDetails(currentWorkFlowDetails, incidentReportInfo, userDetails, incidentReportDetails.Comment, StringConstants.RejectAction); if (!currentWorkFlowDetails.NextActivity.IsClosed && workFlowLogDetails.Id != 0) { incidentReportInfo.IsReject = true; incidentReportInfo.ModifiedDateTime = DateTime.UtcNow; _posIncidentReportDataRepository.Update(incidentReportInfo); _posIncidentReportDataRepository.SaveChanges(); } return("Work Flow Created"); } } return("Work Flow Created"); } else { return("Work Flow Not Created"); } } else { return("No Record Found"); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// this method is used to review the incident report request by the id. /// </summary> /// <param name="incidentReportDetails"></param> /// <param name="userDetails"></param> /// <param name="companyDetails"></param> /// <returns></returns> public string ReviewIncidentReportDetails(PosIncidentReportAc incidentReportDetails, UserDetail userDetails, CompanyDetail companyDetails) { try { var incidentReportInfo = _posIncidentReportDataRepository.FirstOrDefault(x => x.Id == incidentReportDetails.PosIncidentReportId); if (incidentReportInfo != null) { var workFLowLastDetails = _workFLowLogContext.Fetch(x => x.RecordId == incidentReportInfo.RecordId).ToList().Last(); WorkFlowDetail workFlowCurrentDetails; if (incidentReportInfo.IsReject) { workFlowCurrentDetails = _workFlowDetailContext.FirstOrDefault(x => x.Id == workFLowLastDetails.WorkFlowDetail.ParentActivityId); if (workFlowCurrentDetails != null) { var workFlowLogDetails = SaveWorkFlowDetails(workFlowCurrentDetails, incidentReportInfo, userDetails, incidentReportDetails.Comment, StringConstants.ReviewAction); if (workFlowLogDetails.Id != 0) { incidentReportInfo.IsReject = false; incidentReportInfo.ModifiedDateTime = DateTime.UtcNow; _posIncidentReportDataRepository.Update(incidentReportInfo); _posIncidentReportDataRepository.SaveChanges(); } return("Work Flow Created"); } else { return("Work Flow Not Created"); } } else { workFlowCurrentDetails = _workFlowDetailContext.FirstOrDefault(x => x.ParentActivityId == workFLowLastDetails.WorkFlowId); if (workFlowCurrentDetails != null) { if (workFlowCurrentDetails.IsCondition) { var workLFowCollection = _workFlowDetailContext.Fetch(x => x.ParentActivityId == workFlowCurrentDetails.Id) .ToList(); var conditionalCollection = GetListOfConditionalOperator(workFlowCurrentDetails.Id); StringBuilder finalExpression = new StringBuilder(""); if (conditionalCollection.Any()) { foreach (var condition in conditionalCollection) { string condtionOperation = null; if (condition.Condition != null) { switch (condition.Condition) { case "AND": condtionOperation = "&&"; break; case "OR": condtionOperation = "||"; break; } } string expressions = GetExpression(condition.Variable1, incidentReportInfo); finalExpression.Append(condtionOperation).Append(expressions); } } string expression = finalExpression.ToString(); Expression e = new Expression(expression); var finalResult = e.Evaluate(); if (Convert.ToBoolean(finalResult)) { workFlowCurrentDetails = workLFowCollection.FirstOrDefault(x => x.ParentActivityId == workFlowCurrentDetails.Id && x.IsApprovePanel); } else { workFlowCurrentDetails = workLFowCollection.FirstOrDefault(x => x.ParentActivityId == workFlowCurrentDetails.Id && x.IsRejectPanel); } var workFlowLogDetails = SaveWorkFlowDetails(workFlowCurrentDetails, incidentReportInfo, userDetails, incidentReportDetails.Comment, StringConstants.ReviewAction); if (workFlowCurrentDetails != null && workFlowCurrentDetails.NextActivity.IsClosed) { if (workFlowLogDetails.Id != 0) { incidentReportInfo.IsActive = true; var itemQuantityDetails = _itemQuantityContext.FirstOrDefault(x => x.ItemId == incidentReportInfo.ItemId && x.BranchId == incidentReportInfo.BranchId); if (itemQuantityDetails != null) { itemQuantityDetails.ActualQuantity = incidentReportInfo.CommitedQuantity; itemQuantityDetails.ModifiedDateTime = DateTime.UtcNow; _itemQuantityContext.Update(itemQuantityDetails); _itemQuantityContext.SaveChanges(); } incidentReportInfo.ModifiedDateTime = DateTime.UtcNow; _posIncidentReportDataRepository.Update(incidentReportInfo); _posIncidentReportDataRepository.SaveChanges(); } return("Work Flow Created"); } else { return("Work Flow Not Created"); } } else { var workFlowLogDetails = SaveWorkFlowDetails(workFlowCurrentDetails, incidentReportInfo, userDetails, incidentReportDetails.Comment, StringConstants.ReviewAction); if (workFlowCurrentDetails.NextActivity.IsClosed && workFlowLogDetails.Id != 0) { UpdateItemCommitQuantity(incidentReportInfo); incidentReportInfo.IsActive = true; incidentReportInfo.ModifiedDateTime = DateTime.UtcNow; _posIncidentReportDataRepository.Update(incidentReportInfo); _posIncidentReportDataRepository.SaveChanges(); } return("Work Flow Created"); } } else { return("Work Flow Not Created"); } } } else { return("No Record Found"); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// this method is used to submit the incident report. /// </summary> /// <param name="incidentReportDetails"></param> /// <param name="userDetail"></param> /// <param name="companyDetail"></param> /// <returns></returns> public string SubmitIncidentReport(PosIncidentReportAc incidentReportDetails, UserDetail userDetail, CompanyDetail companyDetail) { try { string condtionOperation = ""; var workDetailCollection = _workFlowDetailContext.Fetch(x => x.ParentPermission.Name == StringConstants.IncidentReport && x.CompanyId == companyDetail.Id).ToList(); var incidentReportInfo = _posIncidentReportDataRepository.FirstOrDefault(x => x.Id == incidentReportDetails.PosIncidentReportId); incidentReportInfo.ShelfQuantity = incidentReportDetails.ShelfQuantity; incidentReportInfo.ItemOverQuantity = incidentReportDetails.ItemOverQuantity; if (workDetailCollection.Count == 0) { return("Work Flow Not Created"); } else { var activityWorkFlow = workDetailCollection.FirstOrDefault(x => x.InitiatorId == userDetail.RoleId && x.IsParentAction && x.Activity.Name == StringConstants.InitiateIcr); if (activityWorkFlow != null) { if (activityWorkFlow.IsCondition) { var conditionalCollection = GetListOfConditionalOperator(activityWorkFlow.Id); string finalExpression = ""; if (conditionalCollection.Any()) { foreach (var condition in conditionalCollection) { if (condition.Condition != null) { switch (condition.Condition) { case "AND": condtionOperation = "&&"; break; case "OR": condtionOperation = "||"; break; } } string expression = GetExpression(condition.Variable1, incidentReportInfo); finalExpression = string.Concat(string.Concat(finalExpression, condtionOperation), expression); } } Expression e = new Expression(finalExpression); var finalResult = e.Evaluate(); if (Convert.ToBoolean(finalResult)) { activityWorkFlow = workDetailCollection.FirstOrDefault(x => x.ParentActivityId == activityWorkFlow.Id && x.IsApprovePanel); } else { activityWorkFlow = workDetailCollection.FirstOrDefault(x => x.ParentActivityId == activityWorkFlow.Id && x.IsRejectPanel); } SaveIncidentReportDetails(incidentReportInfo, activityWorkFlow, incidentReportDetails.Comment, userDetail); return("Work Flow Created"); } else { var reportInformation = SaveIncidentReportDetails(incidentReportInfo, activityWorkFlow, incidentReportDetails.Comment, userDetail); if (activityWorkFlow.NextActivity.IsClosed && reportInformation != null) { var reportDetails = _posIncidentReportDataRepository.FirstOrDefault(x => x.Id == reportInformation.Id); reportDetails.IsActive = true; UpdateItemCommitQuantity(reportDetails); reportDetails.ModifiedDateTime = DateTime.UtcNow; _posIncidentReportDataRepository.Update(reportDetails); _posIncidentReportDataRepository.SaveChanges(); } return("Work Flow Created"); } } else { return("Work Flow Not Created"); } } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// this method is used to get incident report details by id. /// </summary> /// <param name="incidentId"></param> /// <param name="userDetail"></param> /// <returns></returns> public PosIncidentReportAc GetIncidentReportDetailsById(int incidentId, UserDetail userDetail, bool isAllowToAccessAllBranch) { try { var incidentReportDetail = _posIncidentReportDataRepository.FirstOrDefault(x => x.Id == incidentId); var incidentAc = new PosIncidentReportAc(); incidentAc = ApplicationClassHelper.ConvertType <DomainModel.Models.IncidentReport.PosIncidentReport, PosIncidentReportAc>(incidentReportDetail); incidentAc.PosIncidentReportId = incidentReportDetail.Id; incidentAc.IncidentTypeName = incidentReportDetail.IncidentTypes.ValueEn; incidentAc.LossValue = incidentReportDetail.CommittedLossValue; incidentAc.GainValue = incidentReportDetail.CommittedGainValue; incidentAc.ResolveQuantity = incidentReportDetail.CommitedQuantity; incidentAc.ItemName = incidentReportDetail.ItemProfile.ItemNameEn; incidentAc.BranchName = incidentReportDetail.BranchDetail.Name; incidentAc.IsDisabledInfo = true; incidentAc.CostPrice = incidentReportDetail.ItemProfile.CostPrice; incidentAc.IncidentDate = incidentReportDetail.CreatedDateTime.ToString("dd/MM/yyyy hh:mm"); incidentAc.SellPrice = incidentReportDetail.ItemProfile.SellPrice; var itemQuantityDetails = _itemQuantityContext.FirstOrDefault(x => x.ItemId == incidentReportDetail.ItemId && x.BranchId == incidentReportDetail.BranchId); if (itemQuantityDetails != null) { incidentAc.CurrentSystemQuantity = itemQuantityDetails.ActualQuantity; } var itemOfferDetail = new ItemOfferDetailAC { ItemId = incidentReportDetail.ItemId, Barcode = incidentReportDetail.ItemProfile.Barcode, ItemNameEn = incidentReportDetail.ItemProfile.ItemNameEn, FlavourEn = incidentReportDetail.ItemProfile.FlavourEn, ItemCode = incidentReportDetail.ItemProfile.Code, SellPriceA = incidentReportDetail.ItemProfile.SellPriceA, SellPrice = incidentReportDetail.ItemProfile.SellPrice, SellPriceB = incidentReportDetail.ItemProfile.SellPriceB, SellPriceC = incidentReportDetail.ItemProfile.SellPriceC, SellPriceD = incidentReportDetail.ItemProfile.SellPriceD, UnitType = incidentReportDetail.ItemProfile.SystemParameter.ValueEn, BaseUnitCount = incidentReportDetail.ItemProfile.BaseUnit, CostPrice = incidentReportDetail.ItemProfile.CostPrice, ItemNameAr = incidentReportDetail.ItemProfile.ItemNameSl, FlavourAr = incidentReportDetail.ItemProfile.FlavourSl, ItemType = incidentReportDetail.ItemProfile.Category.BrandParamType.ValueEn + "-" + incidentReportDetail.ItemProfile.Category.GroupParamType.ValueEn, IsOfferItem = incidentReportDetail.ItemProfile.IsOfferItem == true ? "Yes" : "No", PreviousCostPrice = incidentReportDetail.ItemProfile.PreviousCostPrice, AverageCostPrice = incidentReportDetail.ItemProfile.AverageCostPrice, IsActiveItem = incidentReportDetail.ItemProfile.IsActive == true ? "Yes" : "No" }; incidentAc.ItemDetails = itemOfferDetail; if (isAllowToAccessAllBranch) { incidentAc.IsCurrentUser = true; } else { if (incidentReportDetail.BranchId == userDetail.BranchId) { incidentAc.IsCurrentUser = true; } } var workflowCollection = new List <WorkFlowActionAc>(); if (incidentReportDetail.RecordId != null) { foreach (var workflowInfo in _workFLowLogContext.Fetch(x => x.RecordId == incidentReportDetail.RecordId).ToList()) { var workFlowActionAc = new WorkFlowActionAc(); workFlowActionAc.Stage = workflowInfo.Stage; workFlowActionAc.Action = workflowInfo.Action; workFlowActionAc.WorkFlowActionId = workflowInfo.Id; workFlowActionAc.RoleName = workflowInfo.RoleDetails.RoleName; workFlowActionAc.Comment = workflowInfo.Comments; workFlowActionAc.ActionDate = workflowInfo.CreatedDateTime.ToString("dd/MM/yyyy hh:mm");; var userNames = _userDetailContext.FirstOrDefault(x => x.UserId == workflowInfo.UserId); if (userNames != null) { workFlowActionAc.UserName = userNames.UserName; } workflowCollection.Add(workFlowActionAc); } incidentAc.WorkFlowAction = workflowCollection.OrderBy(x => x.WorkFlowActionId); var workFLowLastDetails = _workFLowLogContext.Fetch(x => x.RecordId == incidentReportDetail.RecordId).ToList().Last(); if (incidentReportDetail.IsReject) { var workFlowCurrentDetails = _workFlowDetailContext.FirstOrDefault(x => x.Id == workFLowLastDetails.WorkFlowDetail.ParentActivityId); if (workFlowCurrentDetails != null) { WorkFlowDetail workDetailsById = _workFlowDetailContext.FirstOrDefault(x => x.Id == workFlowCurrentDetails.ParentActivityId && x.AssignedId == userDetail.RoleId); if (workDetailsById != null) { incidentAc.IsReview = workDetailsById.IsReview; incidentAc.IsApproval = workDetailsById.IsApproval; } } } else { var workFlowCurrentDetails = _workFlowDetailContext.FirstOrDefault(x => x.Id == workFLowLastDetails.WorkFlowId && x.AssignedId == userDetail.RoleId); if (workFlowCurrentDetails != null) { incidentAc.IsReview = workFlowCurrentDetails.IsReview; incidentAc.IsApproval = workFlowCurrentDetails.IsApproval; } } } return(incidentAc); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }