public static void FillContractFromLeadingDocument(Docflow.IOfficialDocument convertedDoc, Docflow.IContractualDocumentBase contract) { if (ContractualDocuments.Is(contract) && IncomingInvoices.Is(convertedDoc)) { IncomingInvoices.As(convertedDoc).Contract = ContractualDocuments.As(contract); } }
/// <summary> /// Получить договорной документ игнорируя права доступа. /// </summary> /// <param name="documentId">ИД документа.</param> /// <returns>Договорной документ.</returns> public static IContractualDocument GetIgnoreAccessRights(int documentId) { // HACK Котегов: использование внутренней сессии для обхода прав доступа. Logger.DebugFormat("GetIgnoreAccessRights: contractId {0}", documentId); using (var session = new Sungero.Domain.Session()) { var innerSession = (Sungero.Domain.ISession)session.GetType() .GetField("InnerSession", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(session); return(ContractualDocuments.As((Sungero.Domain.Shared.IEntity)innerSession.Get(typeof(IContractualDocument), documentId))); } }
public virtual IEmployee GetPerformerContractResponsible(IOfficialDocument document) { if (ContractualDocuments.Is(document)) { return(ContractualDocuments.As(document).ResponsibleEmployee); } else if (Docflow.AccountingDocumentBases.Is(document)) { return(Docflow.AccountingDocumentBases.As(document).ResponsibleEmployee); } return(null); }
/// <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(); } } } }