Пример #1
0
        public virtual void Script10Execute()
        {
            var subject  = Functions.ActionItemExecutionTask.GetActionItemExecutionSubject(_obj, ActionItemExecutionTasks.Resources.TaskSubject);
            var document = _obj.DocumentsGroup.OfficialDocuments.FirstOrDefault();

            Docflow.PublicFunctions.Module.SynchronizeAddendaAndAttachmentsGroup(_obj.AddendaGroup, document);

            // Задания соисполнителям.
            if (_obj.CoAssignees != null && _obj.CoAssignees.Count > 0)
            {
                var performer = _obj.CoAssignees.FirstOrDefault(ca => ca.AssignmentCreated != true);

                var parentAssignment = ActionItemExecutionAssignments.GetAll()
                                       .Where(j => Equals(j.Task, _obj))
                                       .Where(j => j.Status == Workflow.AssignmentBase.Status.InProcess)
                                       .Where(j => Equals(j.Performer, _obj.Assignee))
                                       .Where(j => Equals(_obj.StartId, j.TaskStartId))
                                       .FirstOrDefault();
                var actionItemExecution = ActionItemExecutionTasks.CreateAsSubtask(parentAssignment);
                actionItemExecution.Importance     = _obj.Importance;
                actionItemExecution.ActionItemType = ActionItemType.Additional;

                // Синхронизировать вложения и выдать права.
                if (document != null)
                {
                    actionItemExecution.DocumentsGroup.OfficialDocuments.Add(document);
                }

                foreach (var addInformation in _obj.OtherGroup.All)
                {
                    actionItemExecution.OtherGroup.All.Add(addInformation);
                }

                // Задать текст.
                actionItemExecution.Texts.Last().IsAutoGenerated = true;

                // Задать поручение.
                actionItemExecution.ActionItem = _obj.ActionItem;

                // Задать тему.
                actionItemExecution.Subject = subject;

                // Задать исполнителя, ответственного, контролера и инициатора.
                actionItemExecution.Assignee       = performer.Assignee;
                actionItemExecution.IsUnderControl = true;
                actionItemExecution.Supervisor     = _obj.Assignee;
                actionItemExecution.AssignedBy     = _obj.Assignee;

                // Задать срок.
                actionItemExecution.Deadline    = _obj.Deadline;
                actionItemExecution.MaxDeadline = _obj.Deadline;

                actionItemExecution.Start();

                performer.AssignmentCreated = true;
            }

            // Составное поручение.
            if (_obj.ActionItemParts != null && _obj.ActionItemParts.Count > 0)
            {
                var job = _obj.ActionItemParts.FirstOrDefault(aip => aip.AssignmentCreated != true);

                var actionItemExecution = ActionItemExecutionTasks.CreateAsSubtask(_obj);
                actionItemExecution.Importance     = _obj.Importance;
                actionItemExecution.ActionItemType = ActionItemType.Component;

                // Синхронизировать вложения и выдать права.
                if (document != null)
                {
                    actionItemExecution.DocumentsGroup.OfficialDocuments.Add(document);
                }

                foreach (var addInformation in _obj.OtherGroup.All)
                {
                    actionItemExecution.OtherGroup.All.Add(addInformation);
                }

                // Задать поручение и текст.
                actionItemExecution.ActionItem = string.IsNullOrWhiteSpace(job.ActionItemPart) ? _obj.ActionItem : job.ActionItemPart;

                // Задать тему.
                actionItemExecution.Subject       = Functions.ActionItemExecutionTask.GetActionItemExecutionSubject(actionItemExecution, ActionItemExecutionTasks.Resources.TaskSubject);
                actionItemExecution.ThreadSubject = Sungero.RecordManagement.ActionItemExecutionTasks.Resources.ActionItemWithNumberThreadSubject;

                // Задать исполнителя, ответственного, контролера и инициатора.
                actionItemExecution.Assignee       = job.Assignee;
                actionItemExecution.IsUnderControl = _obj.IsUnderControl;
                actionItemExecution.Supervisor     = _obj.Supervisor;
                actionItemExecution.Author         = _obj.Author;
                actionItemExecution.AssignedBy     = _obj.AssignedBy;

                // Задать срок.
                var actionItemDeadline = job.Deadline.HasValue ? job.Deadline : _obj.FinalDeadline;
                actionItemExecution.Deadline    = actionItemDeadline;
                actionItemExecution.MaxDeadline = actionItemDeadline;

                actionItemExecution.Start();

                // Добавить составные подзадачи в исходящее.
                if (actionItemExecution.Status == Sungero.Workflow.Task.Status.InProcess)
                {
                    Sungero.Workflow.SpecialFolders.GetOutbox(_obj.StartedBy).Items.Add(actionItemExecution);
                }

                // Записать ссылку на поручение в составное поручение.
                job.ActionItemPartExecutionTask = actionItemExecution;

                job.AssignmentCreated = true;
            }
        }