/// <summary> /// allow to approve and rejected /// </summary> /// <param name="input"></param> /// <returns></returns> public bool AllowApproveAndReject(WorkflowAllowApproveAndRejectInput input) { if (input.CreatedUser == input.CurrentUser) { return(false); } //need approve by POA only if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval || input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval2) { if (input.UserRole != Enums.UserRole.POA) { return(false); } //created user need to as user //if (_poabll.GetUserRole(input.CreatedUser) != Enums.UserRole.User) // return false; //if document was rejected then must approve by poa that rejected //var rejectedPoa = _workflowHistoryBll.GetApprovedRejectedPoaByDocumentNumber(input.DocumentNumber); var rejectedPoa = _workflowHistoryBll.GetDtoApprovedRejectedPoaByDocumentNumber(input.DocumentNumber); if (rejectedPoa != null) { //delegate if (!IsPoaAllowedDelegate(input.DocumentNumber, input.CurrentUser)) { return(false); } //end delegate //if (input.CurrentUser != rejectedPoa) // return false; } if (input.FormType == Enums.FormType.PBCK3) { var rejectedSourcePoa = _workflowHistoryBll.GetApprovedRejectedPoaByDocumentNumber(input.DocumentNumberSource); if (rejectedSourcePoa != "" && rejectedSourcePoa != input.CreatedUser) { //if (input.CurrentUser != rejectedSourcePoa) // return false; //delegate if (!IsPoaAllowedDelegate(input.DocumentNumberSource, input.CurrentUser)) { return(false); } //end delegate } } else if (input.FormType == Enums.FormType.PBCK1) { var lisPoa = _poabll.GetPoaByNppbkcIdAndMainPlant(input.NppbkcId); //add delegate poa too List <string> listUser = lisPoa.Select(c => c.POA_ID).Distinct().ToList(); var listPoaDelegate = _poaDelegationServices.GetListPoaDelegateByDate(listUser, DateTime.Now); listUser.AddRange(listPoaDelegate); return(listUser.Contains(input.CurrentUser)); } //poa must be active var poa = _poabll.GetActivePoaById(input.CurrentUser); if (poa == null) { return(false); } var isPoaCreatedUser = _poabll.GetActivePoaById(input.CreatedUser); if (isPoaCreatedUser != null) { //created user is poa, let's check isOneNppbkc with current user or not return(IsOneNppbkc(input.NppbkcId, input.CurrentUser)); } return(input.PlantId != null?IsOnePlant(input.PlantId, input.CurrentUser) : IsOneNppbkc(input.NppbkcId, input.CurrentUser)); } if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApprovalController) { if (input.UserRole != Enums.UserRole.Controller) { return(false); } //get poa id by document number in workflow history //var poaId = _workflowHistoryBll.GetPoaByDocumentNumber(input.DocumentNumber); //if (string.IsNullOrEmpty(poaId)) // return false; //var managerId = _poabll.GetManagerIdByPoaId(poaId); //return managerId == input.CurrentUser; return(true); } return(false); }
private WorkflowHistoryDto CreateWaitingApprovalRecord(GetByFormNumberInput input) { var newRecord = new WorkflowHistoryDto(); newRecord.FORM_NUMBER = input.FormNumber; if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval2) { newRecord.ACTION = Enums.ActionType.WaitingForApproval2; } else { newRecord.ACTION = Enums.ActionType.WaitingForApproval; } string displayUserId = ""; if (input.IsRejected) { displayUserId = input.RejectedBy; newRecord.ROLE = Enums.UserRole.POA; } else { if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval || input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval2) { List <POADto> listPoa; if (input.FormType == Enums.FormType.PBCK1) { listPoa = _poaBll.GetPoaByNppbkcIdAndMainPlant(input.NppbkcId).Distinct().ToList(); if (listPoa.Count > 0) { listPoa = listPoa.Where(c => c.POA_ID != input.DocumentCreator).Distinct().ToList(); } displayUserId = listPoa.Aggregate("", (current, poaDto) => current + (poaDto.POA_ID + ",")); } else { var isPoaCreatedUser = _poaBll.GetActivePoaById(input.DocumentCreator); if (isPoaCreatedUser != null) { //created user is poa, let's get poa list in one Nppbkc listPoa = _poaBll.GetPoaActiveByNppbkcId(input.NppbkcId).Distinct().ToList(); if (listPoa.Count > 0) { listPoa = listPoa.Where(c => c.POA_ID != isPoaCreatedUser.POA_ID).Distinct().ToList(); } } else { listPoa = !string.IsNullOrEmpty(input.PlantId) ? _poaBll.GetPoaActiveByPlantId(input.PlantId).Distinct().ToList() : _poaBll.GetPoaActiveByNppbkcId(input.NppbkcId).Distinct().ToList(); } //old code //displayUserId = listPoa.Aggregate("", (current, poaMapDto) => current + (poaMapDto.POA_ID + ",")); } //add delegate poa List <string> listUser = listPoa.Select(c => c.POA_ID).ToList(); var listPoaDelegate = _poaDelegationServices.GetListPoaDelegateByDate(listUser, DateTime.Now); listUser.AddRange(listPoaDelegate); displayUserId = string.Join(",", listUser.Distinct()); //if (displayUserId.Length > 0) // displayUserId = displayUserId.Substring(0, displayUserId.Length - 1); newRecord.ROLE = Enums.UserRole.POA; } else if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApprovalController) { //get action by poa //var poaId = GetPoaByDocumentNumber(input.FormNumber); //displayUserId = _poaBll.GetManagerIdByPoaId(poaId); var controllerList = _userBll.GetControllers(); displayUserId = string.Join(",", controllerList.Select(c => c.USER_ID).Distinct()); newRecord.ROLE = Enums.UserRole.Controller; } } newRecord.UserId = displayUserId; return(newRecord); }