示例#1
0
        public List <WorkflowHistoryDto> GetByFormId(GetByFormNumberInput input)
        {
            var dbData =
                _repository.Get(c => c.FORM_ID == input.FormId && c.FORM_TYPE_ID == input.FormType, null, includeTables)
                .ToList();
            var result = Mapper.Map <List <WorkflowHistoryDto> >(dbData);

            if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval)
            {
                //find history that approve or rejected by POA
                var rejected = dbData.FirstOrDefault(c => c.ACTION == Enums.ActionType.Reject || c.ACTION == Enums.ActionType.Approve && c.ROLE == Enums.UserRole.POA);

                if (rejected != null)
                {
                    //was rejected
                    input.IsRejected = true;
                    input.RejectedBy = rejected.ACTION_BY;
                }

                result.Add(CreateWaitingApprovalRecord(input));
            }
            else if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApprovalController)
            {
                result.Add(CreateWaitingApprovalRecord(input));
            }

            return(result);
        }
示例#2
0
        private WorkflowHistoryDto CreateWaitingWasteApprovalRecord(GetByFormNumberInput input)
        {
            var newRecord = new WorkflowHistoryDto();

            newRecord.FORM_NUMBER = input.FormNumber;
            newRecord.ACTION      = Enums.ActionType.WaitingForWasteApproval;
            string displayUserId = "";

            var listUserDisposal = _wasteRoleServices.GetUserWasteApproverByPlant(input.PlantId);

            displayUserId  = String.Join(", ", listUserDisposal.ToArray());
            newRecord.ROLE = Enums.UserRole.User;

            newRecord.UserId = displayUserId;
            return(newRecord);
        }
示例#3
0
        private WorkflowHistoryDto CreateWaitingDisposalRecord(GetByFormNumberInput input)
        {
            var newRecord = new WorkflowHistoryDto();

            newRecord.FORM_NUMBER = input.FormNumber;
            newRecord.ACTION      = Enums.ActionType.WaitingForWasteDisposal;
            string displayUserId = "";

            var listUserDisposal = _wasteRoleServices.GetUserDisposalTeamByPlant(input.PlantId);

            var poaDelegate = _poaDelegationServices.GetListPoaDelegateByDate(listUserDisposal, DateTime.Now);

            listUserDisposal.AddRange(poaDelegate);


            displayUserId  = String.Join(", ", listUserDisposal.ToArray());
            newRecord.ROLE = Enums.UserRole.User;

            newRecord.UserId = displayUserId;
            return(newRecord);
        }
示例#4
0
        public List <WorkflowHistoryDto> GetByFormNumber(GetByFormNumberInput input)
        {
            var dbData =
                _repository.Get(c => c.FORM_NUMBER == input.FormNumber, null, includeTables).OrderBy(c => c.ACTION_DATE)
                .ToList();
            var result = Mapper.Map <List <WorkflowHistoryDto> >(dbData);

            if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval || input.DocumentStatus == Enums.DocumentStatus.WaitingForApproval2)
            {
                //find history that approve or rejected by POA
                var rejected = dbData.FirstOrDefault(c => c.ACTION == Enums.ActionType.Reject || c.ACTION == Enums.ActionType.Approve && c.ROLE == Enums.UserRole.POA);

                if (rejected != null)
                {
                    //was rejected
                    input.IsRejected = true;

                    //delegated
                    string originalPoa;
                    var    listUser = new List <string>();
                    //is the rejected original or delegated
                    if (!string.IsNullOrEmpty(rejected.COMMENT) &&
                        rejected.COMMENT.Contains(Constans.LabelDelegatedBy))
                    {
                        //rejected by delegated
                        //find the original
                        originalPoa = rejected.COMMENT.Substring(rejected.COMMENT.IndexOf(Constans.LabelDelegatedBy, System.StringComparison.Ordinal));
                        originalPoa = originalPoa.Replace(Constans.LabelDelegatedBy, "");
                        originalPoa = originalPoa.Replace("]", "");
                    }
                    else
                    {
                        originalPoa = rejected.ACTION_BY;
                    }

                    listUser.Add(originalPoa);
                    var poaDelegate = _poaDelegationServices.GetPoaDelegationToByPoaFromAndDate(originalPoa, DateTime.Now);

                    listUser.AddRange(poaDelegate);

                    input.RejectedBy = string.Join(",", listUser);

                    //end delegated


                    //input.RejectedBy = rejected.ACTION_BY;
                }
                else
                {
                    if (input.FormType == Enums.FormType.PBCK3)
                    {
                        //get from pbck7 or ck5 market return form number
                        //find from source FormNumberSource
                        var dbDataSource =
                            _repository.Get(c => c.FORM_NUMBER == input.FormNumberSource, null, includeTables).OrderBy(c => c.ACTION_DATE).ToList();
                        var rejectedSource = dbDataSource.FirstOrDefault(c => c.ACTION == Enums.ActionType.Reject || c.ACTION == Enums.ActionType.Approve &&
                                                                         c.ROLE == Enums.UserRole.POA);
                        if (rejectedSource != null && rejectedSource.ACTION_BY != input.DocumentCreator)
                        {
                            //was rejected
                            input.IsRejected = true;
                            //input.RejectedBy = rejectedSource.ACTION_BY;

                            //delegated
                            string originalPoa;
                            var    listUser = new List <string>();
                            //is the rejected original or delegated
                            if (!string.IsNullOrEmpty(rejectedSource.COMMENT) &&
                                rejectedSource.COMMENT.Contains(Constans.LabelDelegatedBy))
                            {
                                //rejected by delegated
                                //find the original
                                originalPoa = rejectedSource.COMMENT.Substring(rejectedSource.COMMENT.IndexOf(Constans.LabelDelegatedBy, System.StringComparison.Ordinal));
                                originalPoa = originalPoa.Replace(Constans.LabelDelegatedBy, "");
                                originalPoa = originalPoa.Replace("]", "");
                            }
                            else
                            {
                                originalPoa = rejectedSource.ACTION_BY;
                            }

                            listUser.Add(originalPoa);
                            var poaDelegate = _poaDelegationServices.GetPoaDelegationToByPoaFromAndDate(originalPoa, DateTime.Now);

                            listUser.AddRange(poaDelegate);

                            input.RejectedBy = string.Join(",", listUser);

                            //end delegated
                        }
                    }
                }

                result.Add(CreateWaitingApprovalRecord(input));
            }
            else if (input.DocumentStatus == Enums.DocumentStatus.WaitingForApprovalController)
            {
                result.Add(CreateWaitingApprovalRecord(input));
            }
            else if (input.DocumentStatus == Enums.DocumentStatus.WasteDisposal)
            {
                result.Add(CreateWaitingDisposalRecord(input));
            }
            else if (input.DocumentStatus == Enums.DocumentStatus.WasteApproval)
            {
                result.Add(CreateWaitingWasteApprovalRecord(input));
            }
            return(result);
        }
示例#5
0
        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);
        }