2023-11-16 16:04:14 +05:00

29 KiB
Raw Blame History

Настройка правил поиска для ЖСД

В данной форме настраиваются правила поиска документа для журнала состояния документов. Чтобы открыть данную форму необходимо перейти в Меню - Администрирование - Документооборот - СЭД - Настройка правил поиска для ЖСД.

Для создания нового правила в панели инструментов необходимо нажать "Создать".

Откроется новая форма.

Форма

Вкладка "Настройки"

На данной вкладке задаются основные настройки поиска документов.

  • Не используется - при включенной функции данная настройка не будет отображаться в журнале состояния документов.

Не используется

Фильтр

  • № / Пользовательское наименование - указывается порядковый номер и наименование настройки для отображения в журнале состояния документов.

Наименование

Наименование

  • Служебное наименование - указывается служебное наименование по которому фильтруется реестр документов. Служебное наименование должно быть уникальным в системе.

Служ.наименование

  • Показывать в форме - указывается служебное наименование формы, в которой необходимо отображать данную настройку, например, в личном кабинете HR. Если поле незаполнено то данная настройка отображается во всех формах.

Показывать

Форма

  • Скрыть кол. Подразделение инициатора - скрывает колонку "Подразделение инициатора";

  • Скрыть кол. Плановая дата обработки - скрывает колонку "Плановая дата обработки";

  • Скрыть кол. Просрочено - скрывает колонку "Просрочено";

  • Скрыть кол. Задача - скрывает колонку "Задача";

  • Скрыть кол. Факт дата обработки - скрывает колонку "Фактическая дата обработки";

  • Скрыть кол. Инициатор - скрывает колонку "Инициатор";

  • Скрыть кол. Дата поступления - скрывает колонку "Дата поступления";

  • Скрыть кол. Решение - скрывает колонку "Решение";

  • Скрыть кол. Участник - скрывает колонку "Участник";

  • Добавить группирировку по Родит.подразд. - добавляет группировку в журнале по родительскому подразделению;

  • Добавить группировку по подразд. - добавляет группировку в журнале по подразделению;

  • Добавить группировку по типу документа - добавляет групп по типу документа;

  • Скрыть кол. Комментарии - скрывает колонку "Комментарии";

  • Скрыть кол. Вложения - скрывает колонку "Вложения".

Дополнительные колонки

В данном блоке можно добавить дополнительные колонки для отображения в журнале. Наименование колонок может быть произвольным. Информация в дополнительных колонках отображается в зависимости от указанных в запросе условий.

Дополнительная колонка

Вкладка "Запрос"

В данном блоке указывается часть с динамическим запросом, содержащим непосредственно запроса для отображения документов.

!!! note В запросе возможно настроить цветовое отображение полей документов в зависимости от условий. Для этого в запросе необходимо указать поле "Colors" и заполнить его одним из следующих значений: 1 - colors.gray 2 - colors.orange 3 - colors.yellow 4 - colors.green 5 - colors.blue 6 - colors.indigo 7 -colors.violet. Например в запросе: Все документы данное значение указано в конце запроса: (select top 1 wr."VCode" from "RP_Worker" wr join "RP_PersonContact" pc on wr."IdPerson"= pc."Pcode" and pc."IdTypeContact" = 6 and pc."Code" = t."StageUser" where wr."COrg" = 4 order by wr."DateBeg" ) as "AnyColumnO" , 2, где цифра 2 цвет

Примеры запросов:

Просроченные документы - в реестре отображаются документы, по которым были нарушены сроки обработки:

insert into "tmp_finresult"( "DocCode"   , "DocType"   , "DocForm"  , "DocTypeName"    , "SettingsId"     
  							   , "orgId" , "DocumentDate" , "DocumentNumber"  , "VirtualCUser"  , "DateOfExecution" 
							   , "DateControl"     , "RouteVCode"  , "RouteStatusId"   , "RouteStatusName"  , "DocName"     
							    , "DocSubject"  	  , "expired" , "StageNumber"  	   , "BeginDate"     , "ActionDate"    
								, "DocumentAction" , "DocumentStatus"  , "FromMessage"      , "eDate", "Department"           
	   							, "StageUser"           , "StageItemStatus"  , "StageStatus"      , "StageItemAction" , "DocumentSubtype"   , "AnyColumnA" , "AnyColumnB" , "AnyColumnC" 	, "AnyColumnD" 	, "AnyColumnE")
select dd."DocCode"   , dd."DocType"   , dd."DocForm"  , dd."DocTypeName"    , dd."SettingsId"     
  							   , dd."orgId" , dd."DocumentDate" , dd."DocumentNumber"  , dd."VirtualCUser"  , dd."DateOfExecution" 
							   , dd."DateControl"     , dd."RouteVCode"  , dd."RouteStatusId"   , dd."RouteStatusName"  , dd."DocName"     
							    , dd."DocSubject"  	  ,    dd."expired", 
				dd."StageNumber"  	   , dd."BeginDate"     , dd."ActionDate"    
								, dd."DocumentAction" , dd."DocumentStatus"  , dd."FromMessage"      , dd."eDate", dd."Department"
	   							, dd."StageUser"           , dd."StageItemStatus"  , dd."StageStatus"      , dd."StageItemAction", dd."DocumentSubtype", dd."AnyColumnA" , dd."AnyColumnB" , dd."AnyColumnC" 	, dd."AnyColumnD" 	, dd."AnyColumnE" 
from (
	select t."DocCode"   , t."DocType"   , t."DocForm"  , t."DocTypeName"    , t."SettingsId"     
  							   , t."orgId" , t."DocumentDate" , t."DocumentNumber"  , t."VirtualCUser"  , t."DateOfExecution" 
							   , t."DateControl"     , t."RouteVCode"  , t."RouteStatusId"   , t."RouteStatusName"  , t."DocName"     
							    , t."DocSubject"  	  ,   
					comdoc."dfwcGetDuration"(t."eDate", COALESCE(t."ActionDate", _now), false, t."orgId", null, _dayoff1, _dayoff2, null)  as  "expired", 
				t."StageNumber"  	   , t."BeginDate"     , t."ActionDate"    
								, t."DocumentAction" , t."DocumentStatus"  , t."FromMessage"      , t."eDate", t."Department"
	   							, t."StageUser"           , t."StageItemStatus"  , t."StageStatus"      , t."StageItemAction", t."DocumentSubtype", t."AnyColumnA" , t."AnyColumnB" , t."AnyColumnC" 	, t."AnyColumnD" 	, t."AnyColumnE" 
  from "tmp_preresult" t
  where coalesce(t."RouteStatusId",0) = 2  and t."IsMarked" is not true
    and t."StageItemStatus"= 2
	 AND (
  t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate
)  ) dd
where 
coalesce(dd."expired", 0) <> 0 ;

Зависшие документы у инициатора - в реестре отображаются документы, которые были инициированы сотрудником, но не запущены далее по маршруту согласования.

insert into "tmp_finresult"( "DocCode"   , "DocType"   , "DocForm"  , "DocTypeName"    , "SettingsId"     
  							   , "orgId" , "DocumentDate" , "DocumentNumber"  , "VirtualCUser"  , "DateOfExecution" 
							   , "DateControl"     , "RouteVCode"  , "RouteStatusId"   , "RouteStatusName"  , "DocName"     
							    , "DocSubject"  	  , "expired" , "StageNumber"  	   , "BeginDate"     , "ActionDate"    
								, "DocumentAction" , "DocumentStatus"  , "FromMessage"      , "eDate", "Department"
	   							, "StageUser"           , "StageItemStatus"  , "StageStatus"      , "StageItemAction" , "DocumentSubtype", "AnyColumnA" , "AnyColumnB" , "AnyColumnC" 	, "AnyColumnD" 	, "AnyColumnE")
	select t."DocCode"   , t."DocType"   , t."DocForm"  , t."DocTypeName"    , t."SettingsId"     
  							   , t."orgId" , t."DocumentDate" , t."DocumentNumber"  , t."VirtualCUser"  , t."DateOfExecution" 
							   , t."DateControl"     , t."RouteVCode"  , t."RouteStatusId"   , t."RouteStatusName"  , t."DocName"     
							    , t."DocSubject"  	  , 
									comdoc."dfwcGetDuration"(t."eDate", COALESCE(t."ActionDate", _now), false, t."orgId", 1, _dayoff1, _dayoff2, null) , 
								t."StageNumber"  	   , t."BeginDate"     , t."ActionDate"    
								, t."DocumentAction" , t."DocumentStatus"  , t."FromMessage"      , t."eDate", t."Department"
	   							, t."StageUser"           , t."StageItemStatus"  , t."StageStatus"      , t."StageItemAction", t."DocumentSubtype"	, t."AnyColumnA" , t."AnyColumnB" , t."AnyColumnC" 	, t."AnyColumnD" 	, t."AnyColumnE" 
  from "tmp_preresult" t
  where coalesce(t."RouteStatusId",0) in ( 2 ) and t."StageItemStatus"= 2 and t."IsMarked" is not true
  	and t."StageNumber" = 1 AND (
  t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate
) ;

Поступят к hr в ближайшее время - в реестре отображаются документы, которые в данный момент находятся на стадии согласования у руководителя сотрудника, и после этого поступят в HR службу.

insert into "tmp_finresult"( "DocCode"   , "DocType"   , "DocForm"  , "DocTypeName"    , "SettingsId"     
  							   , "orgId" , "DocumentDate" , "DocumentNumber"  , "VirtualCUser"  , "DateOfExecution" 
							   , "DateControl"     , "RouteVCode"  , "RouteStatusId"   , "RouteStatusName"  , "DocName"     
							    , "DocSubject"  	  , "expired" , "StageNumber"  	   , "BeginDate"     , "ActionDate"    
								, "DocumentAction" , "DocumentStatus"  , "FromMessage"      , "eDate", "Department"           
	   							, "StageUser"           , "StageItemStatus"  , "StageStatus"      , "StageItemAction" , "DocumentSubtype"   , "AnyColumnA" , "AnyColumnB" , "AnyColumnC" 	, "AnyColumnD" 	, "AnyColumnE")
	select t."DocCode"   , t."DocType"   , t."DocForm"  , t."DocTypeName"    , t."SettingsId"     
  							   , t."orgId" , t."DocumentDate" , t."DocumentNumber"  , t."VirtualCUser"  , t."DateOfExecution" 
							   , t."DateControl"     , t."RouteVCode"  , t."RouteStatusId"   , t."RouteStatusName"  , t."DocName"     
							    , t."DocSubject"  	  ,   
					comdoc."dfwcGetDuration"(t."eDate", COALESCE(t."ActionDate", _now), false, t."orgId", 1, _dayoff1, _dayoff2, null) , 
				t."StageNumber"  	   , t."BeginDate"     , t."ActionDate"    
								, t."DocumentAction" , t."DocumentStatus"  , t."FromMessage"      , t."eDate", t."Department"
	   							, t."StageUser"           , t."StageItemStatus"  , t."StageStatus"      , t."StageItemAction", t."DocumentSubtype", t."AnyColumnA" , t."AnyColumnB" , t."AnyColumnC" 	, t."AnyColumnD" 	, t."AnyColumnE" 
  from "tmp_preresult" t
  where coalesce(t."RouteStatusId",0) = 2  and t."IsMarked" is not true
    and t."StageItemStatus"= 2
	and exists (select 1 from "tmp_userRole" where "Role" not in ( 'hr_docflow_hr', 'hr_director_hr')
				and coalesce(t."StageUser",'') = coalesce("DocflowUser",'') )
	and exists (select 1 from  comdoc."RouteStage" rs 
				join comdoc."StageItem" si on rs."VCode" = si."PCode"
				where  rs."PCode" = t."RouteVCode" 
				and si."StageItemStatus" = 1
				and rs."IsMarked" is not true
				and si."StageUser" in (select "DocflowUser" from "tmp_userRole" where "Role" = 'hr_docflow_hr' ))
	 AND (
  t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate
) ;

Сейчас в работе у hr - в реестре отображаются документы, которые в данный момент находятся в HR службе в работе

	insert into "tmp_finresult"( "DocCode"   , "DocType"   , "DocForm"  , "DocTypeName"    , "SettingsId"     
  							   , "orgId" , "DocumentDate" , "DocumentNumber"  , "VirtualCUser"  , "DateOfExecution" 
							   , "DateControl"     , "RouteVCode"  , "RouteStatusId"   , "RouteStatusName"  , "DocName"     
							    , "DocSubject"  	  , "expired" , "StageNumber"  	   , "BeginDate"     , "ActionDate"    
								, "DocumentAction" , "DocumentStatus"  , "FromMessage"      , "eDate", "Department"
	   							, "StageUser"           , "StageItemStatus"  , "StageStatus"      , "StageItemAction" , "IsMarked", "DocumentSubtype"   , "AnyColumnA" , "AnyColumnB" , "AnyColumnC" 	, "AnyColumnD" 	, "AnyColumnE")
	select t."DocCode"   , t."DocType"   , t."DocForm"  , t."DocTypeName"    , t."SettingsId"     
  							   , t."orgId" , t."DocumentDate" , t."DocumentNumber"  , t."VirtualCUser"  , t."DateOfExecution" 
							   , t."DateControl"     , t."RouteVCode"  , t."RouteStatusId"   , t."RouteStatusName"  , t."DocName"     
							    , t."DocSubject"  	  ,   comdoc."dfwcGetDuration"(
                t."eDate", COALESCE(t."ActionDate", _now), false, t."orgId", 1, _dayoff1, _dayoff2, null
            ) 
			, t."StageNumber"  	   , t."BeginDate"     , t."ActionDate"    
								, t."DocumentAction" , t."DocumentStatus"  , t."FromMessage"      , t."eDate", t."Department"
	   							, t."StageUser"           , t."StageItemStatus"  , t."StageStatus"      , t."StageItemAction", t."IsMarked", t."DocumentSubtype"	, t."AnyColumnA" , t."AnyColumnB" , t."AnyColumnC" 	, t."AnyColumnD" 	, t."AnyColumnE" 
  from "tmp_preresult" t
   where  coalesce(t."RouteStatusId",0) = 2 and t."StageItemStatus"= 2
 	and coalesce(t."StageUser",'') in (select coalesce("DocflowUser",'') from "tmp_userRole" where "Role" = 'hr_docflow_hr')
	 AND (
  t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate
) ;

Обработано службой HR сегодня - в реестре отображаются документы, которые были обработаны сегодня службой HR сегодня.

	insert into "tmp_finresult"( "DocCode"   , "DocType"   , "DocForm"  , "DocTypeName"    , "SettingsId"     
  							   , "orgId" , "DocumentDate" , "DocumentNumber"  , "VirtualCUser"  , "DateOfExecution" 
							   , "DateControl"     , "RouteVCode"  , "RouteStatusId"   , "RouteStatusName"  , "DocName"     
							    , "DocSubject"  	  , "expired" , "StageNumber"  	   , "BeginDate"     , "ActionDate"    
								, "DocumentAction" , "DocumentStatus"  , "FromMessage"      , "eDate", "Department"
	   							, "StageUser"           , "StageItemStatus"  , "StageStatus"      , "StageItemAction", "DocumentSubtype" , "AnyColumnA" , "AnyColumnB" , "AnyColumnC" 	, "AnyColumnD" 	, "AnyColumnE"  )
	select t."DocCode"   , t."DocType"   , t."DocForm"  , t."DocTypeName"    , t."SettingsId"     
  							   , t."orgId" , t."DocumentDate" , t."DocumentNumber"  , t."VirtualCUser"  , t."DateOfExecution" 
							   , t."DateControl"     , t."RouteVCode"  , t."RouteStatusId"   , t."RouteStatusName"  , t."DocName"     
							    , t."DocSubject"  	  , 
									comdoc."dfwcGetDuration"(t."eDate", COALESCE(t."ActionDate", _now), false, t."orgId", 1, _dayoff1, _dayoff2, null) , 
								 t."StageNumber"  	   , t."BeginDate"     , t."ActionDate"    
								, t."DocumentAction" , t."DocumentStatus"  , t."FromMessage"      , t."eDate", t."Department"
	   							, t."StageUser"           , t."StageItemStatus"  , t."StageStatus"      , t."StageItemAction", t."DocumentSubtype", t."AnyColumnA" , t."AnyColumnB" , t."AnyColumnC" 	, t."AnyColumnD" 	, t."AnyColumnE" 
  from "tmp_preresult" t
  where coalesce(t."RouteStatusId",0) in ( 2,3 ) and t."StageItemStatus"= 3 and t."IsMarked" is not true
  	and t."DocumentStatus" not in (19,22,23,32,33,51,99)
	and t."ActionDate"::date = now()::date
	and exists (select 1 from "tmp_userRole" where "Role" = 'hr_docflow_hr' and coalesce(t."StageUser",'') = coalesce("DocflowUser",'') ) 
	AND (
  t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate
) ;

Все документы

insert into #tmp_finresult( "DocCode"   , "DocType"   , "DocForm"  , "DocTypeName"    , "SettingsId"     
  							   , "orgId" , "DocumentDate" , "DocumentNumber"  , "VirtualCUser"  , "DateOfExecution" 
							   , "DateControl"     , "RouteVCode"  , "RouteStatusId"   , "RouteStatusName"  , "DocName"     
							    , "DocSubject"  	  , "expired" , "StageNumber"  	   , "BeginDate"     , "ActionDate"    
								, "DocumentAction" , "DocumentStatus"  , "FromMessage"      , "eDate"           
	   							, "StageUser"           , "StageItemStatus"  , "StageStatus"      , "StageItemAction" , "IsMarked", "DocumentSubtype"   , "AnyColumnA" , "AnyColumnB" , "AnyColumnC" 	, "AnyColumnD" 	, "AnyColumnE", 
                                            "AnyColumnF", "AnyColumnG" , "AnyColumnH" 	, "AnyColumnI", "AnyColumnJ", "AnyColumnK","AnyColumnL", "AnyColumnM","AnyColumnN", "EmailRecipient","AnyColumnO", "Colors")

select t."DocCode"   , t."DocType"   , t."DocForm"  , t."DocTypeName"    , t."SettingsId"     
  							   , t."orgId" , t."DocumentDate" , t."DocumentNumber"  ,      
(case when    t."DocType"  in ('UniversalDocument','DocumentForSigning') then (select top 1 pc."Code"   from "DocumentCategoryAttributeType" bd 
                                                                        join "DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#'
                                                                      join "RP_Worker" w on w."VCode" = daa1."BigIntValue"
                                                                      join "RP_PersonContact" AS pc ON pc."Pcode" = w."IdPerson" AND pc."IdTypeContact" = 6
                                                                        where  t."DocumentCategory" = bd."PCode") 
            else   t."VirtualCUser"  end)  ,
 null/*t."DateOfExecution"*/	   , t."DateControl"     , t."RouteVCode"  , t."RouteStatusId"   , t."RouteStatusName"  , t."DocName"     
							    , t."DocSubject"  	  ,  
null/* comdoc."dfwcGetDuration"(
                t."eDate", COALESCE(t."ActionDate", _now), false, t."orgId", 1, _dayoff1, _dayoff2, null
            ) */
			, null/* t."StageNumber"  */	   ,  null/*t."BeginDate" */    ,  null/*t."ActionDate"   */ 
								,null/* t."DocumentAction"*/ ,  null/*t."DocumentStatus" */ ,  null /*t."FromMessage" */     ,  null /*t."eDate"*/
	   							, null /*t."StageUser"  */         , null /*t."StageItemStatus"*/  , null/*t."StageStatus"  */    , null/*t."StageItemAction"*/, t."IsMarked", t."DocumentSubtype"	, t."AnyColumnA" , 
null as  "AnyColumnB" ,
null as "AnyColumnC", 
null as "AnyColumnD"  ,  t."AnyColumnE" ,
(select top 1  convert(varchar,daa1."DateValue",104)   from "DocumentCategoryAttributeType" bd 
 join "DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#bdate#' where  t."DocumentCategory" = bd."PCode" )  as "AnyColumnF" ,
(select top 1 convert(varchar,daa1."DateValue",104)    from "DocumentCategoryAttributeType" bd 
 join "DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#edate#' where  t."DocumentCategory" = bd."PCode")   as "AnyColumnG" ,
(select top 1 daa1."BigIntValue" from "DocumentCategoryAttributeType" bd 
 join "DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" ='#kolvo#' where  t."DocumentCategory" = bd."PCode")  as "AnyColumnH",
/* (select string_agg(dca."Name" || ':' || (case 
				when coalesce(dca."AttributeType",'')  = 'string' and  coalesce(atr."Value",'') <> '' then atr."Value"
				when coalesce(dca."AttributeType",'')  = 'string' and coalesce(atr."Value",'') = '' then ' '
				
				when coalesce(dca."AttributeType",'')  = 'bigint' and atr."BigIntValue" is not null then cast(atr."BigIntValue" as varchar(255))
				when coalesce(dca."AttributeType",'')  = 'bigint' and atr."BigIntValue" is null then ' '
				
				when coalesce(dca."AttributeType",'')  = 'string' and atr."BigIntValue" is not null then cast(atr."BigIntValue" as varchar(255))
				when coalesce(dca."AttributeType",'')  = 'string' and atr."BigIntValue" is null then ' '

				when coalesce(dca."AttributeType",'') = 'Base.Unispr' and atr."BigIntValue" is null and coalesce(atr."Value",'') = '' then ' '
				when coalesce(dca."AttributeType",'') = 'Base.Unispr' and atr."BigIntValue" is not null and coalesce(atr."Value",'') <> '' then coalesce(atr."Value",' ')

				when coalesce(dca."AttributeType",'') = 'Base.Post' and atr."BigIntValue" is null and coalesce(atr."Value",'') = '' then ' '
				when coalesce(dca."AttributeType",'') = 'Base.Post' and atr."BigIntValue" is not null and coalesce(atr."Value",'') <> '' then coalesce(atr."Value",' ')

				when coalesce(dca."AttributeType",'') = 'Base.RP_Worker' and atr."BigIntValue" is null and coalesce(atr."Value",'') = '' then ' '
				when coalesce(dca."AttributeType",'') = 'Base.RP_Worker' and atr."BigIntValue" is not null and coalesce(atr."Value",'') <> '' then coalesce(atr."Value",' ')

				when coalesce(dca."AttributeType",'') = 'Base.Contract' and atr."BigIntValue" is null and coalesce(atr."Value",'') = '' then ' '
				when coalesce(dca."AttributeType",'') = 'Base.Contract' and atr."BigIntValue" is not null and coalesce(atr."Value",'') <> '' then coalesce(atr."Value",' ')

				when coalesce(dca."AttributeType",'') = 'Base.Contractor' and atr."BigIntValue" is null and coalesce(atr."Value",'') = '' then ' '
				when coalesce(dca."AttributeType",'') = 'Base.Contractor' and atr."BigIntValue" is not null and coalesce(atr."Value",'') <> '' then coalesce(atr."Value",' ')

				when coalesce(dca."AttributeType",'') = 'Base.Department' and atr."BigIntValue" is null and coalesce(atr."Value",'') = '' then ' '
				when coalesce(dca."AttributeType",'') = 'Base.Department' and atr."BigIntValue" is not null and coalesce(atr."Value",'') <> '' then coalesce(atr."Value",' ')

				when coalesce(dca."AttributeType",'') = 'money' and atr."MoneyValue"  is not null then cast(atr."MoneyValue" as varchar(255))
				when coalesce(dca."AttributeType",'') = 'money' and atr."MoneyValue"  is  null then ' '

				when coalesce(dca."AttributeType",'') = 'Date' and atr."DateValue"  is not null then to_char(atr."DateValue", 'DD.MM.YYYY')
				when coalesce(dca."AttributeType",'') = 'Date' and atr."DateValue"  is null then ' '

        		when coalesce(dca."AttributeType",'') = 'DateTime' and atr."DateTimeValue"  is not null then to_char(atr."DateValue", 'DD.MM.YYYY')
				when coalesce(dca."AttributeType",'') = 'DateTime' and atr."DateTimeValue"  is null then ' '
			
				when coalesce(dca."AttributeType",'')  = 'double' and atr."DoubleValue"  is not null then cast(atr."DoubleValue" as varchar(255))
				when coalesce(dca."AttributeType",'')  = 'double' and atr."DoubleValue"  is null then ' '

				when coalesce(dca."AttributeType",'')  = 'ServiceWord' and coalesce(atr."Value",'') <> '' then coalesce(atr."Value",' ') 
				when coalesce(dca."AttributeType",'')  = 'ServiceWord' and coalesce(atr."Value",'') = '' then ' '

       	 		when coalesce(dca."AttributeType",'')  = 'bool' and coalesce("BigIntValue"::integer,0) = 0 then substring(coalesce("Value",'|'),	position('|' in coalesce("Value",'|'))+1,char_length(coalesce("Value",'|')))
				when coalesce(dca."AttributeType",'')  = 'bool' and coalesce("BigIntValue"::integer,0) = 1 then substring(coalesce("Value",'|'),0,	position('|' in coalesce("Value",'|')))
								
			end), '; ') AS "x"
				    from   "DocumentAdditionalAttribute" atr 
          			    join "DocumentCategoryAttributeType" dca on atr."CategoryAttributeType" = dca."VCode"
				    where  t."DocCode" = atr."PCode" and dca."ColumnName" not in ('#bdate#', '#edate#', '#kolvo#')) 
*/ null as "AnyColumnI",
null/*sii."Name"*/,
case  when coalesce(t."RouteStatusId",0) = 2 and exists (select 1 from "RouteStage" rs 
                                                                                where rs."PCode" = t."RouteVCode" and rs."StageNumber" = 1 and rs."Status" = 2  ) then 'Не запущен'
  when coalesce(t."RouteStatusId",0) = 2  and t."StageItemStatus"= 2  and t."StageNumber" > 1 
	              and exists (select 1 from  "RouteStage" rs 
				where  rs."PCode" = t."RouteVCode" 
				and isnull(rs."IsMarked",0) = 1
				and rs."StageName"  in ( 'Исполнить')
                           and rs."Status"=1) then 'На согласовании / на согл у рук-ля'
            when coalesce(t."RouteStatusId",0) =  3  
                       and not exists (select 1 from  "RouteStage" rs 
				                  join "StageItem" si on rs."VCode" = si."PCode"
				                   where  rs."PCode" = t."RouteVCode" 
				                    and si."DocumentStatus" in (19,23))  then 'Завершен'
           when coalesce(t."RouteStatusId",0) =  3  and       exists (select 1 from  "RouteStage" rs 
				                  join "StageItem" si on rs."VCode" = si."PCode"
				                   where  rs."PCode" = t."RouteVCode" 
				                    and si."DocumentStatus" in (19,23)) then 'Отклонен'
end as "AnyColumnK",
/*( SELECT DISTINCT string_agg(u."Initials"|| '(' || ds."Name"|| ')' , '; ')  AS "x"
         FROM "RouteStage" as rs
           join  "StageItem" AS i on i."PCode" = rs."VCode"
           join "VUserMeta" AS u ON u."VCode" = i."StageUser"
          join "DocumentStatus" AS ds ON ds."VCode" = i."DocumentStatus"
         WHERE rs."PCode" = t."RouteVCode"
           AND i."StageItemStatus" = 3
          and coalesce(i."DocumentStatus",0) <> 0
     ) */ '' as "AnyColumnL",

case when  t."DocType"  in ('UniversalDocument','DocumentForSigning')  then  (select top 1  w."NumTab"  from "DocumentCategoryAttributeType" bd 
                                                                        join "DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#'
                                                                      join "RP_Worker" w on w."VCode" = daa1."BigIntValue"
                                                                        where  t."DocumentCategory" = bd."PCode")
            else (select r."NumTab" from "RP_Worker" as r where r."VCode" = t."IdWorker")  end as "AnyColumnM",

case when  t."DocType"  in ('UniversalDocument','DocumentForSigning')  then  (select top 1 w."NameFull"  from "DocumentCategoryAttributeType" bd 
                                                                        join "DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#'
                                                                      join "RP_Worker" w on w."VCode" = daa1."BigIntValue"
                                                                        where  t."DocumentCategory" = bd."PCode" )
            else (select r."NameFull" from "RP_Worker" as r where r."VCode" = t."IdWorker")  end as "AnyColumnN",
(select  top 1 wr."VCode" from "RP_Worker" wr join "RP_PersonContact" pc on wr."IdPerson"= pc."Pcode" and pc."IdTypeContact" = 6 and pc."Code" = t."StageUser" where wr."COrg" = 4 order by wr."DateBeg" ) as "EmailRecipient",
(select  top 1 wr."VCode" from "RP_Worker" wr join "RP_PersonContact" pc on wr."IdPerson"= pc."Pcode" and pc."IdTypeContact" = 6 and pc."Code" = t."StageUser" where wr."COrg" = 4 order by wr."DateBeg" ) as "AnyColumnO"
, 2
from #tmp_preresult t
   where  t."DocType" not in ('ServiceDesk')  and 
 (
  t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN @_bdate AND @_edate
)
   and t."DocType" not in ('ServiceDesk') ;