public override List <Sungero.Docflow.IApprovalRuleBase> GetApprovalRules()
 {
     return(base.GetApprovalRules()
            .Select(r => ContractsApprovalRules.As(r))
            .Where(r => r != null)
            .OrderByDescending(r => r.Priority)
            .ToList <Sungero.Docflow.IApprovalRuleBase>());
 }
        public override List <IApprovalRuleBase> GetApprovalRules()
        {
            var rules = base.GetApprovalRules().OrderByDescending(r => r.Priority).ToList();

            // Если заполнен договор - добавить его правила для выбора.
            if (_obj.LeadingDocument != null)
            {
                var allContractRules = Docflow.PublicFunctions.OfficialDocument.Remote.GetApprovalRules(_obj.LeadingDocument);

                // #57673 Регламенты для доп. соглашений приоритетнее договорных.
                // Если регламент подходит для обоих видов, то явное указание вида приоритетнее неявного.
                var intersect = rules.Intersect(allContractRules).ToList();
                rules = rules.Except(allContractRules).ToList();
                var supAgreementKinds = Docflow.PublicFunctions.DocumentKind.GetAvailableDocumentKinds(typeof(ISupAgreement)).ToList();
                rules.AddRange(intersect.Where(r => r.DocumentKinds.Any(k => supAgreementKinds.Contains(k.DocumentKind))));
                rules = rules.OrderByDescending(r => r.Priority).ToList();

                allContractRules = allContractRules.Except(rules).ToList();
                rules.AddRange(allContractRules.Select(r => ContractsApprovalRules.As(r)).Where(r => r != null).OrderByDescending(r => r.Priority).ToList());
            }
            return(rules);
        }
Beispiel #3
0
        public static IContractsApprovalRule CreateDefaultRule(string ruleName, Enumeration documentFlow, List <Enumeration> stages)
        {
            var hasNotDefaultRule = Docflow.ApprovalRuleBases.GetAll().Any(r => r.IsDefaultRule != true);
            var hasDefaultRule    = Docflow.ApprovalRuleBases.GetAll().Any(r => r.DocumentFlow == documentFlow &&
                                                                           (!r.DocumentKinds.Any() || r.DocumentKinds.Any(d => d.DocumentKind.DocumentType.DocumentTypeGuid == Contract.ClassTypeGuid.ToString() ||
                                                                                                                          d.DocumentKind.DocumentType.DocumentTypeGuid == SupAgreement.ClassTypeGuid.ToString())));

            if (hasNotDefaultRule || hasDefaultRule)
            {
                return(null);
            }

            var rule = ContractsApprovalRules.Create();

            rule.Status        = Sungero.Docflow.ApprovalRuleBase.Status.Active;
            rule.Name          = ruleName;
            rule.DocumentFlow  = documentFlow;
            rule.IsDefaultRule = true;

            Docflow.PublicInitializationFunctions.Module.SetRuleStages(rule, stages);
            Docflow.PublicFunctions.ApprovalRuleBase.CreateAutoTransitions(rule);
            rule.Save();
            return(rule);
        }