Beispiel #1
0
        /// <summary>
        /// Отфильтровать шаблоны по критериям.
        /// </summary>
        /// <param name="documentTemplates">Коллекция шаблонов.</param>
        /// <param name="document">Документ, который создается из шаблона.</param>
        /// <param name="documentKind">Вид документа.</param>
        /// <param name="businessUnit">Наша организация.</param>
        /// <param name="department">Подразделение.</param>
        /// <param name="isCalledFromDocument">True - вызывается из документа, false - вызывается из списка.</param>
        /// <returns>Коллекция отфильтрованных шаблонов.</returns>
        public static IQueryable <T> FilterTemplatesByCriteria(IQueryable <T> documentTemplates,
                                                               IOfficialDocument document,
                                                               IDocumentKind documentKind,
                                                               Company.IBusinessUnit businessUnit,
                                                               Company.IDepartment department,
                                                               bool isCalledFromDocument)
        {
            // Вид документа.
            var allDocumentTypeGuid = Guid.Parse(Docflow.PublicConstants.DocumentTemplate.AllDocumentTypeGuid);

            if (documentKind != null)
            {
                var typeGuid = Guid.Parse(documentKind.DocumentType.DocumentTypeGuid);
                documentTemplates = documentTemplates.Where(d => !d.DocumentKinds.Any() &&
                                                            (d.DocumentType == allDocumentTypeGuid ||
                                                             d.DocumentType == typeGuid) ||
                                                            d.DocumentKinds.Any(k => Equals(k.DocumentKind, documentKind)));
            }
            else if (isCalledFromDocument)
            {
                var typeGuid       = document.TypeDiscriminator;
                var availableKinds = PublicFunctions.DocumentKind.GetAvailableDocumentKinds(document);
                documentTemplates = documentTemplates.Where(d => !d.DocumentKinds.Any() &&
                                                            (d.DocumentType == allDocumentTypeGuid ||
                                                             d.DocumentType == typeGuid) ||
                                                            availableKinds.Any(x => string.Equals(x.DocumentType.DocumentTypeGuid,
                                                                                                  typeGuid.ToString(),
                                                                                                  StringComparison.InvariantCultureIgnoreCase)));
            }

            // НОР.
            if (businessUnit != null)
            {
                documentTemplates = documentTemplates.Where(d => !d.BusinessUnits.Any() || d.BusinessUnits.Any(t => Equals(t.BusinessUnit, businessUnit)));
            }
            else if (isCalledFromDocument)
            {
                documentTemplates = documentTemplates.Where(d => !d.BusinessUnits.Any());
            }

            // Подразделение.
            if (department != null)
            {
                documentTemplates = documentTemplates.Where(d => !d.Departments.Any() || d.Departments.Any(t => Equals(t.Department, department)));
            }
            else if (isCalledFromDocument)
            {
                documentTemplates = documentTemplates.Where(d => !d.Departments.Any());
            }

            return(documentTemplates);
        }
Beispiel #2
0
 public static IQueryable <IIncomingLetter> GetDuplicates(IIncomingLetter letter,
                                                          Docflow.IDocumentKind documentKind,
                                                          Company.IBusinessUnit businessUnit,
                                                          string inNumber,
                                                          DateTime?dated,
                                                          Parties.ICounterparty correspondent)
 {
     return(IncomingLetters.GetAll()
            .Where(l => documentKind != null && Equals(documentKind, l.DocumentKind))
            .Where(l => dated.HasValue && dated == l.Dated)
            .Where(l => businessUnit != null && Equals(businessUnit, l.BusinessUnit))
            .Where(l => !string.IsNullOrWhiteSpace(inNumber) && inNumber == l.InNumber)
            .Where(l => correspondent != null && Equals(correspondent, l.Correspondent))
            .Where(l => !Equals(letter, l)));
 }
        public static void UpdateBusinessUnitSetting(Company.IBusinessUnit unit)
        {
            var settings = SignatureSettings.GetAll()
                           .Where(s => s.IsSystem == true && s.Status == CoreEntities.DatabookEntry.Status.Active &&
                                  s.BusinessUnits.Any(u => Equals(u.BusinessUnit, unit)))
                           .ToList();

            if (settings.Count > 2)
            {
                Logger.DebugFormat("UpdateBusinessUnitSetting: Has {0} SignatureSettings for BusinessUnit {1}. Must have max 2.", settings.Count, unit.Id);
            }

            var isCeoChanged = !Equals(unit.State.Properties.CEO.OriginalValue, unit.CEO);

            if (unit.CEO != null && unit.Status == CoreEntities.DatabookEntry.Status.Active &&
                isCeoChanged && (!settings.Any() || !settings.Any(s => Equals(s.Recipient, unit.CEO))))
            {
                var setting = SignatureSettings.Create();
                setting.BusinessUnits.AddNew().BusinessUnit = unit;
                setting.Recipient = unit.CEO;
                setting.Reason    = Docflow.SignatureSetting.Reason.Duties;
                setting.IsSystem  = true;

                setting.Note = SignatureSettings.Resources.DefaultSignatureSettingNote;
            }

            if (settings.Any(s => Equals(s.Recipient, unit.CEO)) && unit.Status == CoreEntities.DatabookEntry.Status.Active)
            {
                foreach (var setting in settings.Where(s => Equals(s.Recipient, unit.CEO)))
                {
                    Sungero.Docflow.PublicFunctions.SignatureSetting.UpdateSigningRole(setting, false);
                }
            }

            var oldSettings = settings;

            if (unit.Status == CoreEntities.DatabookEntry.Status.Active)
            {
                oldSettings = oldSettings.Where(s => !Equals(s.Recipient, unit.CEO)).ToList();
            }
            foreach (var setting in oldSettings)
            {
                setting.Status = CoreEntities.DatabookEntry.Status.Closed;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Проверить письмо на дубликаты.
        /// </summary>
        /// <param name="letter">Входящее письмо.</param>
        /// <param name="documentKind">Вид документа.</param>
        /// <param name="businessUnit">Наша организация.</param>
        /// <param name="correspondentNumber">Номер корреспондента.</param>
        /// <param name="dated">Дата письма.</param>
        /// <param name="correspondent">Корреспондент.</param>
        /// <returns>True, если дубликаты имеются, иначе - false.</returns>
        public static bool HaveDuplicates(IIncomingLetter letter,
                                          Sungero.Docflow.IDocumentKind documentKind,
                                          Company.IBusinessUnit businessUnit,
                                          string correspondentNumber,
                                          DateTime?dated,
                                          Parties.ICounterparty correspondent)
        {
            if (documentKind == null ||
                businessUnit == null ||
                string.IsNullOrEmpty(correspondentNumber) ||
                !dated.HasValue ||
                correspondent == null)
            {
                return(false);
            }

            return(Functions.IncomingLetter.Remote.GetDuplicates(letter, documentKind, businessUnit, correspondentNumber, dated, correspondent).Any());
        }