private static int GetHolidays(WorkflowContext context, DateTime dateFrom, DateTime dateTo, bool withLog = false)
        {
            holidayDates = "";
            var holidayDefId = new Guid("{22ECC24B-1770-467C-8F75-C79D69A2CF95}");
            var qb           = new QueryBuilder(holidayDefId, context.UserId);

            qb.Where("AnnualHolidays").IsNotNull().And("DateOfHolidays").IsNotNull();
            var query = context.CreateSqlQuery(qb.Def);

            query.AddAttribute("DateOfHolidays");
            int count = 0;

            using (var reader = context.CreateSqlReader(query))
            {
                while (reader.Read())
                {
                    var date        = reader.GetDateTime(0);
                    int defYear     = 0001;
                    var dateDef     = new DateTime(defYear, date.Month, date.Day);
                    var dateFromDef = new DateTime(defYear, dateFrom.Month, dateFrom.Day);
                    var dateToDef   = new DateTime(defYear, dateTo.Month, dateTo.Day);
                    if (dateFromDef > dateDef)
                    {
                        dateDef = dateDef.AddYears(1);
                    }
                    dateToDef = new DateTime(dateFrom.Year < dateTo.Year ? defYear + 1 : defYear, dateTo.Month, dateTo.Day);

                    if (dateDef >= dateFromDef && dateDef <= dateToDef)
                    {
                        count++;
                        if (withLog)
                        {
                            holidayDates += " [" + dateDef.ToShortDateString() + "] ";
                        }
                    }
                    else
                    {
                        if (withLog)
                        {
                            holidayDates += " !(" + dateDef.ToShortDateString() + " >= " + dateFromDef.ToShortDateString() + " && " + dateDef.ToShortDateString() + " <= " + dateToDef.ToShortDateString() + ") ";
                        }
                    }
                }
            }
            qb = new QueryBuilder(holidayDefId, context.UserId);
            qb.Where("AnnualHolidays").IsNull().And("DateOfHolidays").Ge(dateFrom).And("DateOfHolidays").Le(dateTo);
            query = context.CreateSqlQuery(qb.Def);
            query.AddAttribute("&Id", Intersoft.CISSA.DataAccessLayer.Model.Query.Sql.SqlQuerySummaryFunction.Count);
            using (var reader = context.CreateSqlReader(query))
            {
                if (reader.Read())
                {
                    count += reader.GetInt32(0);
                }
            }
            return(count);
        }
        private static readonly Guid TypePaysEnumId           = new Guid("{40F1C4F4-3BAA-4348-B881-AFD5F69B676F}"); //беременность/роды спр.
        private static decimal GetAmount(WorkflowContext context)
        {
            var today = DateTime.Today;
            var aqb   = new QueryBuilder(AmountRitualBenefitDefId);

            aqb.Where("From").Le(today).And("To").Gt(today).And("TypePays").Eq(TypePaysEnumId);
            using (var query = context.CreateSqlQuery(aqb.Def))
            {
                query.AddAttribute("Amount");
                query.AddOrderAttribute("From", false);
                using (var reader = context.CreateSqlReader(query))
                {
                    if (!reader.Read())
                    {
                        throw new ApplicationException("Размер пособия в справочнике не указан!");
                    }
                    return(reader.Reader.GetDecimal(0));
                }
            }
        }
        Guid GetLegalPerson(WorkflowContext context, LegalReportSection obj)
        {
            var LegalPersonDefId = new Guid("{61AF4CEA-D77A-4305-8F0A-81A001BE5CFD}");

            var qb    = new QueryBuilder(LegalPersonDefId, context.UserId);
            var query = context.CreateSqlQuery(qb.Def);

            query.AndCondition("PIN", ConditionOperation.Equal, obj.Company.INN);
            query.AndCondition("LegalName", ConditionOperation.Equal, obj.Company.Name);

            query.AddAttribute("&Id");
            using (var reader = context.CreateSqlReader(query))
            {
                if (reader.Read())
                {
                    return(reader.GetGuid(0));
                }
            }
            var docRepo        = context.Documents;
            var newLegalPerson = docRepo.New(LegalPersonDefId);

            newLegalPerson["PIN"]            = obj.Company.INN;
            newLegalPerson["LegalName"]      = obj.Company.Name;
            newLegalPerson["CodeOrg"]        = obj.Company.OKPO;
            newLegalPerson["LegalAddress"]   = obj.Company.Address;
            newLegalPerson["LegalPhone"]     = obj.Company.Telephone;
            newLegalPerson["Email"]          = obj.Company.Email;
            newLegalPerson["TypeOfActivity"] = obj.Company.ActivityType;
            newLegalPerson["BankName"]       = obj.Company.BankName;
            newLegalPerson["BankIdCode"]     = obj.Company.BIK;
            newLegalPerson["CheckAccount"]   = obj.Company.BankAccountNo;

            docRepo.Save(newLegalPerson);

            return(newLegalPerson.Id);
        }