Ejemplo n.º 1
0
        private List <FilterTaskModel> CreateFilterTaskModel(SPListItemCollection itemCollection, int approvalStatusId)
        {
            List <FilterTaskModel> result = new List <FilterTaskModel>();

            foreach (SPListItem item in itemCollection)
            {
                var taskListModel = new FilterTaskModel();
                taskListModel.ItemId          = Convert.ToInt32(item["ListItemID"]);
                taskListModel.ItemApprovalUrl = Convert.ToString(item["ListItemApprovalUrl"]);
                taskListModel.Description     = Convert.ToString(item["ListItemDescription"]);
                taskListModel.CreatedDateTime = (DateTime)item["ListItemCreatedDate"];
                taskListModel.CreatedDate     = taskListModel.CreatedDateTime.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);

                DateTime dueDateTime;
                if (DateTime.TryParse(Convert.ToString(item["ListItemDueDate"]), out dueDateTime))
                {
                    taskListModel.DueDateTime = dueDateTime;
                    taskListModel.DueDate     = taskListModel.DueDateTime.Value.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
                }

                taskListModel.AssignedToName   = new SPFieldLookupValue(item["AssignedTo"] as String).LookupValue;
                taskListModel.RequesterName    = new SPFieldLookupValue(item["Requester"] as String).LookupValue;
                taskListModel.DepartmentId     = new SPFieldLookupValue(item["DepartmentEN"] as String).LookupId;
                taskListModel.DepartmentName   = new SPFieldLookupValue(item["DepartmentEN"] as String).LookupValue;
                taskListModel.ModuleId         = new SPFieldLookupValue(item["ModuleNameEN"] as String).LookupId;
                taskListModel.ApprovalStatusId = approvalStatusId;

                result.Add(taskListModel);
            }

            return(result);
        }
Ejemplo n.º 2
0
 public IEnumerable <WorkOrderTaskView> GetFilteredTasks([FromBody] FilterTaskModel value)
 {
     try
     {
         return(db.SelectFilteredTasks(value));
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetFilteredTaskReport([FromBody] FilterTaskModel model)
        {
            try
            {
                var result = await api.Post <FilterTaskModel, IEnumerable <WorkOrderTaskView> >("WorkOrder/GetFilteredTasks", model);

                return(PartialView("_TaskReport", result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        //if (filter.CreatedFrom.HasValue) query.Append($"and date(Timestamp) > '{filter.CreatedFrom.Value.ToString("yyyy/MM/dd")}' ");
        //if (filter.CreatedTo.HasValue) query.Append($"and date(Timestamp) < '{filter.CreatedTo.Value.ToString("yyyy/MM/dd")}' ");

        public IEnumerable <WorkOrderTaskView> SelectFilteredTasks(FilterTaskModel model)
        {
            var query = WorkOrderQueries.SelectFilteredTasks;

            if (model.WorkOrderId.HasValue)
            {
                query += ($" and T.WorkOrderId = {model.WorkOrderId}");
            }
            if ((model.EmployeeId.HasValue) && (model.EmployeeId > 0))
            {
                query += ($" and EmployeeId = {model.EmployeeId}");
            }
            if (model.TargetDateFrom.HasValue)
            {
                query += ($" and date(t.targetdate) >= '{model.TargetDateFrom.Value.ToString("yyyy-MM-dd")}'");
            }
            if (model.TargetDateTo.HasValue)
            {
                query += ($" and date(t.targetdate) <= '{model.TargetDateTo.Value.ToString("yyyy-MM-dd")}'");
            }
            var parameters = DataHelper.ExtractParameters(model);

            return(dbContext.GetList <WorkOrderTaskView>(query, parameters));
        }
Ejemplo n.º 5
0
        public IEnumerable <FilterTaskModel> GetTaskByCondition(string condition, string currentUserADId, string currentUserInfoId, string approverFullName)
        {
            int  userADId;
            bool currentUserADIdResult = Int32.TryParse(currentUserADId, out userADId);

            if (currentUserADIdResult)
            {
                // Get Delegation list:
                int  userInfoId;
                bool currentUserInfoIdResult     = Int32.TryParse(currentUserInfoId, out userInfoId);
                List <Delegation> delegationList = _delegationDAL.GetDelegationApprovalList(SPContext.Current.Web, userInfoId);
                switch (condition)
                {
                case TaskCondition.WaitingApproval:
                    var waitingApprovalVisitor = new WaitingApprovalVisitor(userADId, userInfoId, _webUrl);
                    waitingApprovalVisitor.DelegationList = delegationList;
                    foreach (var dal in _listDAL)
                    {
                        dal.Accept(waitingApprovalVisitor);
                    }

                    return(waitingApprovalVisitor.FilterTaskList.OrderBy(i => i.CreatedDate).Select(r => FilterTaskModel.FromDTO(r)));

                case TaskCondition.InProcess:
                    var inProcessVisitor = new InProcessVisitor(userADId, userInfoId, _webUrl);
                    inProcessVisitor.DelegationList = delegationList;
                    foreach (var dal in _listDAL)
                    {
                        dal.Accept(inProcessVisitor);
                    }

                    return(inProcessVisitor.FilterTaskList.OrderBy(i => i.CreatedDate).Select(r => FilterTaskModel.FromDTO(r)));

                case TaskCondition.WaitingApprovalToday:
                    var waitingApprovalTodayVisitor = new WaitingApprovalTodayVisitor(userADId, userInfoId, this._webUrl);
                    waitingApprovalTodayVisitor.DelegationList = delegationList;
                    foreach (var dal in _listDAL)
                    {
                        dal.Accept(waitingApprovalTodayVisitor);
                    }

                    return(waitingApprovalTodayVisitor.FilterTaskList.Select(r => FilterTaskModel.FromDTO(r)));

                case TaskCondition.ApprovedToday:
                    var approvedTodayVisitor = new ApprovedTodayVisitor(userADId, userInfoId, _webUrl);
                    approvedTodayVisitor.ApproverFullName = approverFullName;
                    // Approved: Dont need to load Delegation
                    foreach (var dal in _listDAL)
                    {
                        dal.Accept(approvedTodayVisitor);
                    }

                    return(approvedTodayVisitor.FilterTaskList.OrderBy(i => i.CreatedDate).Select(r => FilterTaskModel.FromDTO(r)));

                default:
                    return(Enumerable.Empty <FilterTaskModel>());
                }
            }

            return(Enumerable.Empty <FilterTaskModel>());
        }
Ejemplo n.º 6
0
        private void CreateListItem(FilterTaskModel model, string listName, bool isOverride)
        {
            using (SPSite spSite = new SPSite(_webUrl))
            {
                using (SPWeb web = spSite.OpenWeb())
                {
                    try
                    {
                        web.AllowUnsafeUpdates = true;

                        SPList list = web.TryGetSPList($"{web.Url}/Lists/{listName}");

                        // Begin DELETE
                        if (isOverride)
                        {
                            var query   = $@"<Where>
                                        <And>
                                            <And>
                                                <And>
                                                    <Eq>
                                                        <FieldRef Name='DataSourceID' />
                                                        <Value Type='Number'>{1}</Value>
                                                    </Eq>
                                                    <Eq>
                                                        <FieldRef Name='ListItemID' />
                                                        <Value Type='Number'>{model.ItemId}</Value>
                                                    </Eq>
                                                </And>
                                                <Eq>
                                                    <FieldRef Name='ModuleNameEN' LookupId='TRUE'/>
                                                    <Value Type='Lookup'>{model.ModuleId}</Value>
                                                </Eq>
                                            </And>
                                            <Eq>
                                                <FieldRef Name='AssignedTo' LookupId='TRUE'/>
                                                <Value Type='Lookup'>{model.AssignedToId}</Value>
                                            </Eq>
                                        </And>
                                    </Where>";
                            var spQuery = new SPQuery
                            {
                                ViewFields     = "<FieldRef Name='ID'/>",
                                Query          = query,
                                ViewAttributes = "Scope=\"RecursiveAll\"",
                                ViewFieldsOnly = true,
                            };


                            var itemCollection = list.GetItems(spQuery);
                            if (itemCollection != null && itemCollection.Count > 0)
                            {
                                // Delete
                                StringBuilder sbDelete = new StringBuilder();
                                sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");
                                string stringcommand = "<Method><SetList Scope=\"Request\">" + list.ID + "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
                                foreach (SPListItem item in itemCollection)
                                {
                                    //result.Add(item.ID);
                                    sbDelete.Append(string.Format(stringcommand, item.ID));
                                }

                                sbDelete.Append("</Batch>");
                                web.ProcessBatchData(sbDelete.ToString());
                            }
                        }
                        // End DELETE

                        var      folderName = EmployeeLookup[model.AssignedToId]; // model.AssignedToId.ToString();
                        var      folderUrl  = $"{web.Url}/Lists/{listName}/{folderName}";
                        SPFolder folder     = web.GetFolder(folderUrl);
                        if (!folder.Exists)
                        {
                            // Create folder
                            SPListItem newFolder = list.Items.Add(list.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder);
                            if (newFolder != null)
                            {
                                newFolder["Title"] = folderName;
                                newFolder["Name"]  = folderName;
                                newFolder.Update();
                            }
                        }

                        SPListItem newItem = list.Items.Add(folderUrl, SPFileSystemObjectType.Folder, null);

                        // Bind model -> item
                        newItem["ListItemID"]          = model.ItemId;
                        newItem["ListItemApprovalUrl"] = model.ItemApprovalUrl;
                        newItem["ListItemDescription"] = model.Description;
                        newItem["ListItemCreatedDate"] = model.CreatedDateTime;
                        newItem["ListItemDueDate"]     = model.DueDateTime;
                        // item["ListURL"] = model.;
                        newItem["AssignedTo"]       = model.AssignedToId;
                        newItem["Requester"]        = model.RequesterId;
                        newItem["DepartmentEN"]     = model.DepartmentId;
                        newItem["LocationEN"]       = 2; // NM2 - TODO
                        newItem["ModuleNameEN"]     = model.ModuleId;
                        newItem["ApprovalStatusEN"] = model.ApprovalStatusId;
                        newItem["DataSourceID"]     = 1; // Old Data
                                                         // item["CategoryEN"] = model.; // TODO

                        newItem.Update();
                    }
                    catch { }
                    finally
                    {
                        web.AllowUnsafeUpdates = false;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void MigrateDelegation(bool isOverride, List <string> moduleNames, int departmentId)
        {
            DelegationModulesDAL delegationModulesDAL = new DelegationModulesDAL(SPContext.Current.Web.Url);

            var employeeDelegationList = new List <Delegation>();

            StringBuilder sbItem = new StringBuilder();

            foreach (var moduleName in moduleNames)
            {
                sbItem.Append($@"<Value Type='Text'>{moduleName}</Value>");
            }
            var delegationQuery = $@"
                                    <Where>
                                        <And>
                                            <Eq>
                                                <FieldRef Name='Department' LookupId='TRUE'/>
                                                <Value Type='Lookup'>{departmentId}</Value>
                                            </Eq>
                                            <In>
                                                <FieldRef Name='ModuleName' />
                                                <Values>
                                                    {sbItem.ToString()}
                                                </Values>                        
                                            </In>
                                        </And>
                                    </Where>";

            List <Delegation> delegationList = _delegationDAL.GetByQuery(delegationQuery);

            var toEmployeeList = delegationList.SelectMany(d => d.ToEmployee);
            var toEmployeeIds  = toEmployeeList.Select(e => e.LookupId).Distinct().ToList();

            foreach (var employeeId in toEmployeeIds)
            {
                employeeDelegationList.AddRange(_delegationDAL.GetDelegationApprovalListByModule(SPContext.Current.Web, employeeId, sbItem.ToString()));
            }

            foreach (var delegation in employeeDelegationList)
            {
                foreach (var assignedTo in delegation.ToEmployee)
                {
                    var taskListModel = new FilterTaskModel();
                    taskListModel.ItemId          = delegation.ListItemID;
                    taskListModel.ItemApprovalUrl = delegation.ListItemApprovalUrl;
                    taskListModel.Description     = delegation.ListItemDescription;
                    taskListModel.CreatedDateTime = delegation.Created;
                    taskListModel.DueDateTime     = RetrieveRequestDueDate(delegation.ListUrl, delegation.ListItemID); // Get DueDate
                    taskListModel.AssignedToId    = assignedTo.LookupId;
                    taskListModel.RequesterId     = delegation.Requester.LookupId;
                    taskListModel.DepartmentId    = delegation.Department.LookupId;
                    var delegationModule = delegationModulesDAL.GetByListUrl(delegation.ListUrl);
                    if (delegationModule != null)
                    {
                        taskListModel.ModuleId = delegationModule.ID;
                    }
                    taskListModel.ApprovalStatusId = 1; // In - Progress

                    CreateListItem(taskListModel, TO_DO_LIST_NAME, isOverride);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Migrate Task
        /// </summary>
        /// <param name="isOverride"></param>
        /// <param name="moduleNames"></param>
        /// <returns>String to describe the duplicated employee's fullname</returns>
        private string MigrateTask(bool isOverride, List <string> moduleNames, int departmentId)
        {
            var waitingApprovalMigrationVisitor      = new WaitingApprovalMigrationVisitor(_webUrl, departmentId);
            var waitingApprovalTodayMigrationVisitor = new WaitingApprovalTodayMigrationVisitor(_webUrl, departmentId);
            var inProcessMigrationVisitor            = new InProcessMigrationVisitor(_webUrl, departmentId);
            var approvedTodayMigrationVisitor        = new ApprovedTodayMigrationVisitor(_webUrl, departmentId);

            _listDAL = new List <IFilterTaskManager>();
            foreach (var module in moduleNames)
            {
                switch (module)
                {
                case "Shift Management":     // 1
                    _listDAL.Add(new ShiftManagementDAL(_webUrl));
                    break;

                case "Change Shift Management":     // 2
                    _listDAL.Add(new ChangeShiftManagementDAL(_webUrl));
                    break;

                case "Overtime Management":     // 3
                    _listDAL.Add(new OverTimeManagementDAL(_webUrl));
                    break;

                case "Leave Of Absence Management":     // 4
                    _listDAL.Add(new NotOvertimeManagementDAL(_webUrl));
                    break;

                case "Leave Management":     // 5
                    _listDAL.Add(new LeaveManagementDAL(_webUrl));
                    break;

                case "Vehicle Registration Management":     // 6
                    _listDAL.Add(new VehicleManagementDAL(_webUrl));
                    break;

                case "Requests Management":     // 7
                    _listDAL.Add(new RequestsDAL(_webUrl));
                    break;

                case "Freight Management":     // 8
                    _listDAL.Add(new FreightManagementDAL(_webUrl));
                    break;

                case "Recruitment Management":     // 9
                    _listDAL.Add(new EmployeeRequirementSheetDAL(_webUrl));
                    break;

                case "Request For Diploma Supply Management":     // 10
                    _listDAL.Add(new RequestForDiplomaSupplyDAL(_webUrl));
                    break;

                case "Business Trip Management":     // 11
                    _listDAL.Add(new BusinessTripManagementDAL(_webUrl));
                    break;
                }
            }

            foreach (var dal in _listDAL)
            {
                dal.Accept(waitingApprovalMigrationVisitor);
                dal.Accept(waitingApprovalTodayMigrationVisitor);
                dal.Accept(inProcessMigrationVisitor);
                dal.Accept(approvedTodayMigrationVisitor);
            }

            // Check if exists duplicated employee's fullname -> return false -> manual update data
            if (approvedTodayMigrationVisitor.FilterTaskList != null && approvedTodayMigrationVisitor.FilterTaskList.Any())
            {
                var duplicatedFullNames = approvedTodayMigrationVisitor.FilterTaskList.Where(item => item.IsDuplicatedEmployeeFullName).Select(item => $"{item.Department.LookupValue}{item.AssignedTo.LookupValue}").ToList();
                if (duplicatedFullNames != null && duplicatedFullNames.Any())
                {
                    return(string.Join(";", duplicatedFullNames));
                }
            }

            var waitingApprovalList      = waitingApprovalMigrationVisitor.FilterTaskList.Select(r => FilterTaskModel.FromDTO(r));
            var waitingApprovalTodayList = waitingApprovalTodayMigrationVisitor.FilterTaskList.Select(r => FilterTaskModel.FromDTO(r));
            var inProcessList            = inProcessMigrationVisitor.FilterTaskList.Select(r => FilterTaskModel.FromDTO(r));
            var approvedTodayList        = approvedTodayMigrationVisitor.FilterTaskList.Select(r => FilterTaskModel.FromDTO(r));


            var todoList = waitingApprovalList.Union(waitingApprovalTodayList).Union(inProcessList);

            foreach (var model in todoList)
            {
                CreateListItem(model, TO_DO_LIST_NAME, isOverride);
            }

            foreach (var model in approvedTodayList)
            {
                CreateListItem(model, DONE_LIST_NAME, isOverride);
            }

            return(string.Empty);
        }