public virtual void Script5Execute()
        {
            // Если родительское задание прекращено, то срок не продлять.
            if (_obj.ParentAssignment.Status != Workflow.AssignmentBase.Status.InProcess)
            {
                return;
            }

            var desiredDeadline = _obj.NewDeadline;

            if (RecordManagement.ActionItemExecutionAssignments.As(_obj.ParentAssignment) != null)
            {
                // Обновить срок у задания.
                var actionItemAssignment = RecordManagement.ActionItemExecutionAssignments.Get(_obj.ParentAssignment.Id);
                actionItemAssignment.Deadline      = desiredDeadline;
                actionItemAssignment.ScheduledDate = desiredDeadline;

                // Обновить срок у задачи.
                var actionItemExecution = RecordManagement.ActionItemExecutionTasks.Get(actionItemAssignment.Task.Id);
                actionItemExecution.Deadline    = desiredDeadline;
                actionItemExecution.MaxDeadline = desiredDeadline;

                // Обновить срок у составной задачи.
                if (actionItemExecution.ActionItemType == RecordManagement.ActionItemExecutionTask.ActionItemType.Component)
                {
                    var component  = RecordManagement.ActionItemExecutionTasks.Get(actionItemExecution.ParentTask.Id);
                    var actionItem = component.ActionItemParts.FirstOrDefault(j => Equals(j.Assignee, actionItemExecution.Assignee) &&
                                                                              (Equals(j.ActionItemPart, actionItemExecution.ActionItem) || string.IsNullOrEmpty(j.ActionItemPart)) &&
                                                                              (j.Deadline == _obj.CurrentDeadline || j.Deadline == null));
                    if (actionItem != null)
                    {
                        actionItem.Deadline = desiredDeadline;
                    }
                }

                // Продлить сроки соисполнителей.
                foreach (var performer in actionItemExecution.CoAssignees)
                {
                    var subTasks = RecordManagement.ActionItemExecutionTasks.GetAll(t => Equals(t.MainTask, actionItemExecution) &&
                                                                                    t.Status == Sungero.Workflow.Task.Status.InProcess &&
                                                                                    Equals(t.Assignee, performer.Assignee));
                    foreach (var subTask in subTasks)
                    {
                        subTask.Deadline    = desiredDeadline;
                        subTask.MaxDeadline = desiredDeadline;

                        // Продлить срок у активного задания соисполнителя.
                        var assignment = RecordManagement.ActionItemExecutionAssignments.GetAll()
                                         .FirstOrDefault(a => Equals(a.Task, subTask) && a.Status == Sungero.Workflow.AssignmentBase.Status.InProcess);

                        if (assignment != null)
                        {
                            assignment.Deadline      = desiredDeadline;
                            assignment.ScheduledDate = desiredDeadline;
                        }
                    }
                }
            }
            else if (RecordManagement.ReportRequestAssignments.Is(_obj.ParentAssignment))
            {
                // Обновить срок у задания.
                _obj.ParentAssignment.Deadline = desiredDeadline;
                // Обновить срок у задачи.
                var reportRequestTask = RecordManagement.StatusReportRequestTasks.Get(_obj.ParentAssignment.Task.Id);
                reportRequestTask.MaxDeadline = desiredDeadline;
            }
            else if (FreeApprovalAssignments.Is(_obj.ParentAssignment))
            {
                // Обновить срок у задания.
                var freeApprovalAssignment = FreeApprovalAssignments.Get(_obj.ParentAssignment.Id);
                freeApprovalAssignment.Deadline = desiredDeadline;

                // Обновить срок у задачи.
                var freeApprovalTask = FreeApprovalTasks.Get(_obj.ParentAssignment.Task.Id);
                if (Functions.Module.CheckDeadline(desiredDeadline, freeApprovalTask.MaxDeadline))
                {
                    freeApprovalTask.MaxDeadline = desiredDeadline;
                }
            }
            else if (ApprovalCheckReturnAssignments.Is(_obj.ParentAssignment))
            {
                // Обновить срок у задания.
                var checkReturnAssignment = ApprovalCheckReturnAssignments.As(_obj.ParentAssignment);
                checkReturnAssignment.Deadline = desiredDeadline;

                // Обновить срок на вкладке "Выдача" документа.
                if (checkReturnAssignment.DocumentGroup.OfficialDocuments.Any())
                {
                    var document = checkReturnAssignment.DocumentGroup.OfficialDocuments.FirstOrDefault();
                    ((Domain.Shared.IExtendedEntity)document).Params[Docflow.Constants.Module.DeadlineExtentsionTaskCallContext] = true;
                    var tracks = document.Tracking.Where(t => Equals(t.ReturnTask, checkReturnAssignment.Task) &&
                                                         t.ReturnResult == null && t.ReturnDeadline != null);
                    foreach (var track in tracks)
                    {
                        track.ReturnDeadline = desiredDeadline;
                    }
                }
            }
            else if (CheckReturnAssignments.Is(_obj.ParentAssignment))
            {
                // Обновить срок у задания.
                var checkReturnAssignment = CheckReturnAssignments.As(_obj.ParentAssignment);
                checkReturnAssignment.Deadline = desiredDeadline;
                if (CheckReturnTasks.Is(checkReturnAssignment.Task))
                {
                    var checkReturnTask = CheckReturnTasks.As(checkReturnAssignment.Task);
                    checkReturnTask.MaxDeadline = desiredDeadline;
                }
                // Обновить срок на вкладке "Выдача" документа.
                if (checkReturnAssignment.DocumentGroup.OfficialDocuments.Any())
                {
                    var document = checkReturnAssignment.DocumentGroup.OfficialDocuments.FirstOrDefault();
                    ((Domain.Shared.IExtendedEntity)document).Params[Docflow.Constants.Module.DeadlineExtentsionTaskCallContext] = true;
                    var tracks = document.Tracking.Where(t => Equals(t.ReturnTask, checkReturnAssignment.Task) &&
                                                         t.ReturnResult == null && t.ReturnDeadline != null);
                    foreach (var track in tracks)
                    {
                        track.ReturnDeadline = desiredDeadline;
                    }
                }
            }
            else
            {
                // Обновить срок у задания.
                _obj.ParentAssignment.Deadline = desiredDeadline;
            }

            // Обновить срок у задач.
            var parentAssignment = _obj.ParentAssignment;

            if (ApprovalTasks.Is(parentAssignment.MainTask))
            {
                var approvalTask = ApprovalTasks.As(parentAssignment.MainTask);
                approvalTask.MaxDeadline = Functions.ApprovalTask.GetExpectedDate(approvalTask);
            }
            else if (RecordManagement.AcquaintanceTasks.Is(parentAssignment.MainTask))
            {
                var acquaintanceTask = RecordManagement.AcquaintanceTasks.As(parentAssignment.MainTask);
                if (Functions.Module.CheckDeadline(desiredDeadline, acquaintanceTask.Deadline))
                {
                    acquaintanceTask.Deadline = desiredDeadline;
                }
            }
        }
예제 #2
0
        public virtual IQueryable <Sungero.Workflow.IAssignmentBase> OnDocumentProcessingDataQuery(IQueryable <Sungero.Workflow.IAssignmentBase> query)
        {
            // Фильтр по типу.
            var typeFilterEnabled = _filter != null && (_filter.ProcessResolution ||
                                                        _filter.ConfirmSigning ||
                                                        _filter.SendActionItem ||
                                                        _filter.Send ||
                                                        _filter.CheckReturn ||
                                                        _filter.Other);

            var stageTypes = new List <Sungero.Core.Enumeration>();

            if (!typeFilterEnabled || _filter.ProcessResolution)
            {
                stageTypes.Add(Docflow.ApprovalReviewAssignmentCollapsedStagesTypesRe.StageType.ReviewingResult);
            }
            if (!typeFilterEnabled || _filter.ConfirmSigning)
            {
                stageTypes.Add(Docflow.ApprovalReviewAssignmentCollapsedStagesTypesRe.StageType.ConfirmSign);
            }
            if (!typeFilterEnabled || _filter.SendActionItem)
            {
                stageTypes.Add(Docflow.ApprovalReviewAssignmentCollapsedStagesTypesRe.StageType.Execution);
            }
            if (!typeFilterEnabled || _filter.Send)
            {
                stageTypes.Add(Docflow.ApprovalReviewAssignmentCollapsedStagesTypesRe.StageType.Sending);
            }

            var showExecution   = !typeFilterEnabled || _filter.SendActionItem;
            var showCheckReturn = !typeFilterEnabled || _filter.CheckReturn;
            var showOther       = !typeFilterEnabled || _filter.Other;

            var result = query.Where(q =>
                                     // Рассмотрение.
                                     ApprovalReviewAssignments.Is(q) && ApprovalReviewAssignments.As(q).CollapsedStagesTypesRe.Any(s => stageTypes.Contains(s.StageType.Value)) ||
                                     // Подписание.
                                     ApprovalSigningAssignments.Is(q) && ApprovalSigningAssignments.As(q).CollapsedStagesTypesSig.Any(s => stageTypes.Contains(s.StageType.Value)) ||
                                     // Создание поручений.
                                     (ApprovalExecutionAssignments.Is(q) && ApprovalExecutionAssignments.As(q).CollapsedStagesTypesExe.Any(s => stageTypes.Contains(s.StageType.Value)) ||
                                      showExecution && ReviewResolutionAssignments.Is(q)) ||
                                     // Подготовка проекта резолюции.
                                     showExecution && PreparingDraftResolutionAssignments.Is(q) ||
                                     // Регистрация.
                                     ApprovalRegistrationAssignments.Is(q) && ApprovalRegistrationAssignments.As(q).CollapsedStagesTypesReg.Any(s => stageTypes.Contains(s.StageType.Value)) ||
                                     // Печать.
                                     ApprovalPrintingAssignments.Is(q) && ApprovalPrintingAssignments.As(q).CollapsedStagesTypesPr.Any(s => stageTypes.Contains(s.StageType.Value)) ||
                                     // Отправка контрагенту.
                                     ApprovalSendingAssignments.Is(q) && ApprovalSendingAssignments.As(q).CollapsedStagesTypesSen.Any(s => stageTypes.Contains(s.StageType.Value)) ||
                                     // Контроль возврата.
                                     showCheckReturn && ApprovalCheckReturnAssignments.Is(q) ||
                                     // Прочие задания.
                                     showOther && (ApprovalSimpleAssignments.Is(q) || ApprovalCheckingAssignments.Is(q)));

            // Запрос непрочитанных без фильтра.
            if (_filter == null)
            {
                return(RecordManagement.PublicFunctions.Module.ApplyCommonSubfolderFilters(result));
            }

            // Фильтры по статусу, замещению и периоду.
            result = RecordManagement.PublicFunctions.Module.ApplyCommonSubfolderFilters(result, _filter.InProcess,
                                                                                         _filter.Last30Days, _filter.Last90Days, _filter.Last180Days, false);
            return(result);
        }