public static IQueryable <IContractBase> GetDuplicates(IContractBase contract, Sungero.Company.IBusinessUnit businessUnit, string registrationNumber, DateTime?registrationDate, Sungero.Parties.ICounterparty counterparty) { return(ContractBases.GetAll() .Where(l => Equals(contract.DocumentKind, l.DocumentKind)) .Where(l => Equals(businessUnit, l.BusinessUnit)) .Where(l => registrationDate == l.RegistrationDate) .Where(l => registrationNumber == l.RegistrationNumber) .Where(l => Equals(counterparty, l.Counterparty)) .Where(l => !Equals(contract, l))); }
/// <summary> /// Агент рассылки уведомления об окончании срока действия договоров. /// </summary> public virtual void SendNotificationForExpiringContracts() { var command = Queries.Module.CreateTableForExpiringContracts; Sungero.Docflow.PublicFunctions.Module.ExecuteSQLCommand(command); var notifyParams = Docflow.PublicFunctions.Module.GetDefaultExpiringDocsNotificationParams(Constants.Module.NotificationDatabaseKey, Constants.Module.ExpiringContractTableName); var alreadySentDocs = Docflow.PublicFunctions.Module.GetDocumentsWithSendedTask(notifyParams.ExpiringDocTableName); var contractIds = ContractBases.GetAll() .Where(c => !alreadySentDocs.Contains(c.Id)) .Where(c => c.LifeCycleState == Sungero.Contracts.ContractBase.LifeCycleState.Active || c.LifeCycleState == Sungero.Contracts.ContractBase.LifeCycleState.Draft) .Where(c => c.ResponsibleEmployee != null || c.Author != null) .Where(c => notifyParams.LastNotificationReserve.AddDays(c.DaysToFinishWorks.HasValue ? c.DaysToFinishWorks.Value : 0) < c.ValidTill && c.ValidTill <= notifyParams.TodayReserve.AddDays(c.DaysToFinishWorks.HasValue ? c.DaysToFinishWorks.Value : 0)) .Where(c => c.DaysToFinishWorks == null || c.DaysToFinishWorks <= Docflow.PublicConstants.Module.MaxDaysToFinish) .Select(c => c.Id) .ToList(); Logger.DebugFormat("Contracts to send notification count = {0}.", contractIds.Count()); for (int i = 0; i < contractIds.Count(); i = i + notifyParams.BatchCount) { var result = Transactions.Execute( () => { var contractsPart = ContractBases.GetAll(c => contractIds.Contains(c.Id)).Skip(i).Take(notifyParams.BatchCount).ToList(); contractsPart = contractsPart.Where(c => notifyParams.LastNotification.ToUserTime(c.ResponsibleEmployee ?? c.Author).AddDays(c.DaysToFinishWorks.HasValue ? c.DaysToFinishWorks.Value : 0) < c.ValidTill && c.ValidTill <= Calendar.GetUserToday(c.ResponsibleEmployee ?? c.Author).AddDays(c.DaysToFinishWorks.HasValue ? c.DaysToFinishWorks.Value : 0)) .ToList(); if (!contractsPart.Any()) { return; } Docflow.PublicFunctions.Module.ClearIdsFromExpiringDocsTable(notifyParams.ExpiringDocTableName, contractsPart.Select(x => x.Id).ToList()); Docflow.PublicFunctions.Module.AddExpiringDocumentsToTable(notifyParams.ExpiringDocTableName, contractsPart.Select(x => x.Id).ToList()); foreach (var contract in contractsPart) { var subject = Docflow.PublicFunctions.Module.TrimQuotes( contract.IsAutomaticRenewal == true ? Resources.AutomaticRenewalContractExpiresFormat(contract.DisplayValue) : Resources.ExpiringContractsSubjectFormat(contract.DisplayValue)); if (subject.Length > Workflow.SimpleTasks.Info.Properties.Subject.Length) { subject = subject.Substring(0, Workflow.SimpleTasks.Info.Properties.Subject.Length); } var activeText = Docflow.PublicFunctions.Module.TrimQuotes( contract.IsAutomaticRenewal == true ? Resources.ExpiringContractsRenewalTextFormat(contract.ValidTill.Value.ToShortDateString(), contract.DisplayValue) : Resources.ExpiringContractsTextFormat(contract.ValidTill.Value.ToShortDateString(), contract.DisplayValue)); var performers = Functions.Module.GetNotificationPerformers(contract); performers = performers.Where(p => p != null).Distinct().ToList(); var attachments = new List <IElectronicDocument>(); attachments.Add(contract); var related = contract.Relations.GetRelated(Constants.Module.SupAgreementRelationName).ToList(); attachments.AddRange(related); notifyParams.TaskParams.Document = contract; notifyParams.TaskParams.Subject = subject; notifyParams.TaskParams.ActiveText = activeText; notifyParams.TaskParams.Performers = performers; notifyParams.TaskParams.Attachments = attachments; Docflow.PublicFunctions.Module.TrySendExpiringDocNotifications(notifyParams); } }); } if (Docflow.PublicFunctions.Module.IsAllNotificationsStarted(notifyParams.ExpiringDocTableName)) { Docflow.PublicFunctions.Module.UpdateLastNotificationDate(notifyParams); Docflow.PublicFunctions.Module.ClearExpiringTable(notifyParams.ExpiringDocTableName, false); } }