public static string GetJobTitle(IEmployee employee, Sungero.Core.DeclensionCase declensionCase)
        {
            if (employee == null)
            {
                return(string.Empty);
            }

            if (employee.JobTitle == null)
            {
                return(string.Empty);
            }

            return(CaseConverter.ConvertJobTitleToTargetDeclension(employee.JobTitle.Name,
                                                                   declensionCase));
        }
Exemple #2
0
        /// <summary>
        /// Агент создания задач по завершению контрольных точек договоров.
        /// </summary>
        public virtual void SendTaskForContractMilestones()
        {
            var contracts = ContractualDocuments.GetAll().Where(c => c.Milestones.Any());

            foreach (var contract in contracts)
            {
                if (!Locks.GetLockInfo(contract).IsLocked)
                {
                    foreach (var milestone in contract.Milestones)
                    {
                        // Создание задач.
                        var daysToFinishWorks = milestone.DaysToFinishWorks != null ? milestone.DaysToFinishWorks.Value : 3;
                        if (milestone.IsCompleted == false && milestone.Deadline < Calendar.Now.AddWorkingDays(milestone.Performer, daysToFinishWorks) &&
                            (milestone.Task == null || milestone.Task.Status == Workflow.SimpleTask.Status.Aborted || milestone.Task.Status == Workflow.SimpleTask.Status.Suspended))
                        {
                            var subject = string.Format(Sungero.Contracts.Resources.ContractMilestoneTaskSubject, milestone.Name, contract.Name);
                            if (subject.Length > Workflow.SimpleTasks.Info.Properties.Subject.Length)
                            {
                                subject = subject.Substring(0, Workflow.SimpleTasks.Info.Properties.Subject.Length);
                            }
                            subject = Docflow.PublicFunctions.Module.TrimQuotes(subject);

                            var attachments = new List <IContractualDocument>()
                            {
                                contract
                            };
                            if (SupAgreements.Is(contract))
                            {
                                attachments.Add(ContractualDocuments.As(contract.LeadingDocument));
                            }

                            var milestoneDeadline = milestone.Deadline.Value.Date < Calendar.GetUserToday(milestone.Performer) ? Calendar.Now.AddWorkingDays(milestone.Performer, 1) : milestone.Deadline.Value;
                            var task = Workflow.SimpleTasks.Create(subject, milestoneDeadline, new IUser[] { milestone.Performer }, attachments);
                            task.NeedsReview = false;

                            var contractTypeName = contract.DocumentKind.DocumentType.Name.ToLower();
                            task.ActiveText = Sungero.Contracts.Resources.ContractMilestoneTaskTextFormat(CaseConverter.ConvertJobTitleToTargetDeclension(contractTypeName, DeclensionCase.Dative));

                            if (!string.IsNullOrEmpty(milestone.Note))
                            {
                                task.ActiveText += "\n" + string.Format(Sungero.Contracts.Resources.ContractMilestoneTaskTextNote, milestone.Note);
                            }

                            var observers = new List <IUser>();
                            // Проверка на наличие дублей наблюдателей.
                            if (contract.ResponsibleEmployee != null && !Equals(contract.ResponsibleEmployee, milestone.Performer))
                            {
                                if (Docflow.PublicFunctions.PersonalSetting.GetPersonalSettings(contract.ResponsibleEmployee).MyContractsNotification == true)
                                {
                                    observers.Add(contract.ResponsibleEmployee);
                                }
                                var responsibleManager = Docflow.PublicFunctions.Module.Remote.GetManager(contract.ResponsibleEmployee);
                                if (responsibleManager != null && !Equals(responsibleManager, milestone.Performer) && !Equals(responsibleManager, contract.ResponsibleEmployee) &&
                                    Docflow.PublicFunctions.PersonalSetting.GetPersonalSettings(responsibleManager).MySubordinatesContractsNotification == true)
                                {
                                    observers.Add(responsibleManager);
                                }
                            }
                            var performerManager = Docflow.PublicFunctions.Module.Remote.GetManager(milestone.Performer);
                            if (performerManager != null && !Equals(performerManager, milestone.Performer) &&
                                Docflow.PublicFunctions.PersonalSetting.GetPersonalSettings(performerManager).MySubordinatesContractsNotification == true &&
                                !observers.Contains(performerManager))
                            {
                                observers.Add(performerManager);
                            }

                            foreach (var observer in observers)
                            {
                                task.Observers.AddNew().Observer = observer;
                            }

                            foreach (var attachment in attachments)
                            {
                                if (!attachment.AccessRights.IsGrantedDirectly(DefaultAccessRightsTypes.Read, milestone.Performer))
                                {
                                    attachment.AccessRights.Grant(milestone.Performer, DefaultAccessRightsTypes.Read);
                                }
                                if (performerManager != null && !attachment.AccessRights.IsGrantedDirectly(DefaultAccessRightsTypes.Read, performerManager))
                                {
                                    attachment.AccessRights.Grant(performerManager, DefaultAccessRightsTypes.Read);
                                }
                            }

                            task.Save();
                            task.Start();
                            milestone.Task = task;
                        }

                        if (milestone.Task != null)
                        {
                            // Проставление признака завершенности.
                            if (milestone.Task.Status == Workflow.SimpleTask.Status.Completed)
                            {
                                milestone.IsCompleted = true;
                            }

                            // Актуализация сроков заданий.
                            if (milestone.Deadline > milestone.Task.Deadline)
                            {
                                milestone.Task.Deadline = milestone.Deadline;
                                var assignment = Workflow.SimpleAssignments.GetAll().Where(a => Equals(a.Task, milestone.Task)).FirstOrDefault();
                                if (assignment != null)
                                {
                                    assignment.Deadline = milestone.Deadline;
                                }
                                assignment.Save();
                            }

                            // Прекращение задачи
                            if (milestone.IsCompleted == true)
                            {
                                milestone.Task.Abort();
                                milestone.Task = null;
                            }
                        }
                    }
                    if (contract.State.IsChanged)
                    {
                        contract.Save();
                    }
                }
            }
        }
Exemple #3
0
    public static string GetAddressees(IOutgoingDocumentBase document)
    {
      var result = string.Empty;
      if (document.Addressees.Count() > 4)
        result = OutgoingDocumentBases.Resources.ToManyAddressees;
      else
      {
        foreach (var addresse in document.Addressees.OrderBy(a => a.Number))
        {
          var person = Sungero.Parties.People.As(addresse.Correspondent);
          // Не выводить должность для персоны.
          if (person == null)
          {
            // Должность адресата в дательном падеже.
            var jobTitle = string.Format("<{0}>", OutgoingDocumentBases.Resources.JobTitle);
            if (addresse.Addressee != null && !string.IsNullOrEmpty(addresse.Addressee.JobTitle))
              jobTitle = CaseConverter.ConvertJobTitleToTargetDeclension(addresse.Addressee.JobTitle, Sungero.Core.DeclensionCase.Dative);

            result += jobTitle;
            result += Environment.NewLine;
          }
          
          // Организация адресата/ФИО Персоны.
          if (person == null)
            result += addresse.Correspondent.Name;
          else
          {
            var personName = CommonLibrary.PersonFullName.Create(person.LastName, person.FirstName, person.MiddleName, CommonLibrary.PersonFullNameDisplayFormat.LastNameAndInitials);
            result += CaseConverter.ConvertPersonFullNameToTargetDeclension(personName, Sungero.Core.DeclensionCase.Dative);
          }
          
          result += Environment.NewLine;
          
          // Не выводить ФИО адресата для персоны.
          if (person == null)
          {
            var addresseName = string.Format("<{0}>", OutgoingDocumentBases.Resources.InitialsAndLastName);
            // И.О. Фамилия адресата в дательном падеже.
            if (addresse.Addressee != null)
            {
              addresseName = addresse.Addressee.Name;
              if (addresse.Addressee.Person != null)
              {
                var personFullName = CommonLibrary.PersonFullName.Create(addresse.Addressee.Person.LastName,
                                                                         addresse.Addressee.Person.FirstName,
                                                                         addresse.Addressee.Person.MiddleName,
                                                                         CommonLibrary.PersonFullNameDisplayFormat.InitialsAndLastName);
                addresseName = CaseConverter.ConvertPersonFullNameToTargetDeclension(personFullName, Sungero.Core.DeclensionCase.Dative);
              }
            }
            result += addresseName;
            result += Environment.NewLine;
          }
          
          // Адрес доставки.
          var postalAddress = string.Format("<{0}>", OutgoingDocumentBases.Resources.PostalAddress);
          if (!string.IsNullOrEmpty(addresse.Correspondent.PostalAddress))
            postalAddress = addresse.Correspondent.PostalAddress;
          result += postalAddress;
          result += Environment.NewLine;
          result += Environment.NewLine;
        }
      }
      return result.Trim();
    }