diff --git a/docs/Admin manuals/Настройка правил поиска для ЖСД/index.md b/docs/Admin manuals/Настройка правил поиска для ЖСД/index.md index ef2748c..caf08f3 100644 --- a/docs/Admin manuals/Настройка правил поиска для ЖСД/index.md +++ b/docs/Admin manuals/Настройка правил поиска для ЖСД/index.md @@ -7,7 +7,7 @@ Откроется новая форма. -![alt text](media/image-4.png) +![alt text](media/image-6.png) При нажатии на кнопку **"Показать подсказки"** в верхней части раскрываются рекомендации по работе с данной формой: @@ -19,19 +19,19 @@ * **Не используется** - при включенной функции данная настройка не будет отображаться в журнале состояния документов. -![Не используется](media/neIspol.png) +![alt text](media/image-7.png) ![Фильтр](media/filtr.png) * **№ / Пользовательское наименование** - указывается порядковый номер и наименование настройки для отображения в журнале состояния документов. -![alt text](media/image-1.png) +![alt text](media/image-9.png) ![Наименование](media/polNam2.png) * **Служебное наименование** - указывается служебное наименование по которому фильтруется реестр документов. Служебное наименование должно быть **уникальным** в системе. -![alt text](media/image-2.png) +![alt text](media/image-10.png) * **Показывать в форме** - указывается служебное наименование формы, в которой необходимо отображать данную настройку, например, в личном кабинете HR. Если поле незаполнено то данная настройка отображается во всех формах. @@ -43,6 +43,8 @@ * **рассчитывать просрочку в документах** - рассчитывает количество дней по нарушением сроков обработки в столбце "Просрочено (дней)" +* **Работа России** - отображает кнопку ["Отправить в РР"](https://ecm-user-manuals.readthedocs.io/ru/latest/User%20manuals/%D0%A0%D0%B0%D0%B1%D0%BE%D1%82%D0%B0%20%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B8/) в журнале. + ### Скрыть столбцы * **Подразделение инициатора** - скрывает колонку "Подразделение инициатора"; @@ -65,7 +67,9 @@ * **Решение** - скрывает колонку "Решение"; -* **Вложения** - скрывает колонку "Вложения". +* **Вложения** - скрывает колонку "Вложения"; + +* **Документ** - скрывает колонку "Документ". ### Добавить группировку @@ -109,36 +113,56 @@ В данном блоке указывается часть с динамическим запросом, содержащим непосредственно запроса для отображения документов. -!!! 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 цвет +В запросе возможно настроить цветовое отображение полей документов в зависимости от условий. Для этого в запросе необходимо указать поле "Colors" и заполнить его одним из следующих значений: `1 - colors.gray 2 - colors.orange 3 - colors.yellow 4 - colors.green 5 - colors.blue 6 - colors.indigo 7 -colors.violet`. -!!! note - Для того чтобы запрос фильтровался по заданному количеству документов, которое указывается в поле **Кол-во строк/Период (с/по):** необзодимо в конце запроса добавить строку `_topcount` , например: ```left join "tmp_workers_for_documentStatusJournalProc" w2 on w2."VCode" = t."IdWorker" _topcount;``` +!!! example "Пример:" + + В запросе: **Все документы** данное значение указано в конце запроса: + + ```sql + (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 цвет + + +Для того чтобы запрос фильтровался по заданному количеству документов, которое указывается в поле **Кол-во строк/Период (с/по):** необходимо в конце запроса добавить строку `_topcount` + +!!! example "Пример:" + ```sql + left join "tmp_workers_for_documentStatusJournalProc" w2 on w2."VCode" = t."IdWorker" _topcount; + ``` ### Примеры запросов -**Просроченные документы** - в реестре отображаются документы, по которым были нарушены сроки обработки: +#### Просроченные документы -Основной запрос: +В реестре отображаются документы, по которым были нарушены сроки обработки -Итоговая выборка: -```sql -insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" +??? note "Запрос" + + Основной запрос: + + Итоговая выборка: + + ```sql + 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" + 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."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" + 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" , @@ -146,23 +170,28 @@ from ( 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 ; -``` + 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 ; + ``` -**Зависшие документы у инициатора** - в реестре отображаются документы, которые были инициированы сотрудником, но не запущены далее по маршруту согласования. +#### Зависшие документы у инициатора -Основной запрос: +В реестре отображаются документы, которые были инициированы сотрудником, но не запущены далее по маршруту согласования. -Итоговая выборка: -```sql -insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" +??? note "Запрос" + + Основной запрос: + + Итоговая выборка: + + ```sql + insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" , "orgId" , "DocumentDate" , "DocumentNumber" , "VirtualCUser" , "DateOfExecution" , "DateControl" , "RouteVCode" , "RouteStatusId" , "RouteStatusName" , "DocName" , "DocSubject" , "expired" , "StageNumber" , "BeginDate" , "ActionDate" @@ -176,20 +205,25 @@ insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeNa 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 + 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 -) ; -``` + t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate + ) ; + ``` -**Поступят к hr в ближайшее время** - в реестре отображаются документы, которые в данный момент находятся на стадии согласования у руководителя сотрудника, и после этого поступят в HR службу. +#### Поступят к hr в ближайшее время -Основной запрос: +В реестре отображаются документы, которые в данный момент находятся на стадии согласования у руководителя сотрудника, и после этого поступят в HR службу. -Итоговая выборка: -```sql -insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" +??? note "Запрос" + + Основной запрос: + + Итоговая выборка: + + ```sql + insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" , "orgId" , "DocumentDate" , "DocumentNumber" , "VirtualCUser" , "DateOfExecution" , "DateControl" , "RouteVCode" , "RouteStatusId" , "RouteStatusName" , "DocName" , "DocSubject" , "expired" , "StageNumber" , "BeginDate" , "ActionDate" @@ -203,28 +237,33 @@ insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeNa 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') + 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 + 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 -) ; -``` + t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate + ) ; + ``` -**Сейчас в работе у hr** - в реестре отображаются документы, которые в данный момент находятся в HR службе в работе +#### Сейчас в работе у hr -Основной запрос: +В реестре отображаются документы, которые в данный момент находятся в HR службе в работе -Итоговая выборка: -```sql +??? note "Запрос" + + Основной запрос: + + Итоговая выборка: + + ```sql insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" , "orgId" , "DocumentDate" , "DocumentNumber" , "VirtualCUser" , "DateOfExecution" , "DateControl" , "RouteVCode" , "RouteStatusId" , "RouteStatusName" , "DocName" @@ -240,27 +279,32 @@ insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeNa , 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') + 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 -) ; -``` + t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate + ) ; + ``` -**Обработано службой HR сегодня** - в реестре отображаются документы, которые были обработаны сегодня службой HR сегодня. +#### Обработано службой HR сегодня -Основной запрос: +В реестре отображаются документы, которые были обработаны сегодня службой HR сегодня. -Итоговая выборка: -```sql - insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" +??? note "Запрос" + + Основной запрос: + + Итоговая выборка: + + ```sql + 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" + 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" , @@ -268,56 +312,61 @@ insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeNa 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 -) ; -``` + 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 + ) ; + ``` -**Все документы** +#### Все документы -Основной запрос: -```sql -do $myQ$ -declare _str text; -begin -_str := 'INSERT INTO "tmp_calcWithBaseParams_for_documentStatusJournalProc"( +??? note "Запрос" + + Основной запрос: + + ```sql + do $myQ$ + declare _str text; + begin + _str := 'INSERT INTO "tmp_calcWithBaseParams_for_documentStatusJournalProc"( "DocCode", "DocType", "DocForm", "DocTypeName", "SettingsId", "orgId", "DocumentDate", "DocumentNumber", - "VirtualCUser", "DateOfExecution", "DateControl","DocumentSubtype", "Department", + "VirtualCUser", "DateOfExecution", "DateControl","DocumentSubtype", "Department", "IdWorker", "DocumentCategory" -) -SELECT distinct e."VCode" AS "DocCode", s."DocType", s."DocForm", s."DocName" AS "DocTypeName", s."VCode" AS "SettingsId", e."COrg" AS "orgId", e."DocumentDate", e."DocumentNumber" - , e."VirtualCUser", e."DateOfExecution", e."DateControl", e."DocumentSubtype", e."Department", - e."IdWorker", (select u."DocumentCategory" from dfd."UniversalDocument" u where u."VCode" = e."VCode") /*u."DocumentCategory"*/ -FROM comdoc."DocflowExists" AS e - JOIN comdoc."DocflowDocumentSettings" AS s ON s."DocType" = e."TypeName" - -- left join dfd."UniversalDocument" u on u."VCode" = e."VCode" -WHERE 1 = 1 ' -|| case when coalesce("orgParam",-1111)=-1111 then '' else ' and e."COrg" = '||_orgid::text end -|| case when EXISTS(SELECT 1 FROM "tmp_docTypes_for_documentStatusJournalProc" t) then ' - and EXISTS( - SELECT 1 FROM "tmp_docTypes_for_documentStatusJournalProc" AS t WHERE t."DocType" = e."TypeName" -)' else '' end -|| case when exists(select 1 from "tmp_docSubTypes_for_documentStatusJournalProc" ) then ' -AND EXISTS( - SELECT 1 FROM "tmp_docSubTypes_for_documentStatusJournalProc" AS t WHERE comdoc.try_cast_bigint(t."DocSubType") = e."DocumentSubtype" -) ' else '' end||' - and coalesce( e."DocumentDate",'''||_bdate||''') between '''||_bdate||''' and '''||_edate||''' - and e."TypeName" not in (''ServiceDesk'');' ; --- }} Выборка по основным атрибутам документа -execute _str; -end; -$myQ$; -``` + ) + SELECT distinct e."VCode" AS "DocCode", s."DocType", s."DocForm", s."DocName" AS "DocTypeName", s."VCode" AS "SettingsId", e."COrg" AS "orgId", e."DocumentDate", e."DocumentNumber" + , e."VirtualCUser", e."DateOfExecution", e."DateControl", e."DocumentSubtype", e."Department", + e."IdWorker", (select u."DocumentCategory" from dfd."UniversalDocument" u where u."VCode" = e."VCode") /*u."DocumentCategory"*/ + FROM comdoc."DocflowExists" AS e + JOIN comdoc."DocflowDocumentSettings" AS s ON s."DocType" = e."TypeName" + -- left join dfd."UniversalDocument" u on u."VCode" = e."VCode" + WHERE 1 = 1 ' + || case when coalesce("orgParam",-1111)=-1111 then '' else ' and e."COrg" = '||_orgid::text end + || case when EXISTS(SELECT 1 FROM "tmp_docTypes_for_documentStatusJournalProc" t) then ' + and EXISTS( + SELECT 1 FROM "tmp_docTypes_for_documentStatusJournalProc" AS t WHERE t."DocType" = e."TypeName" + )' else '' end + || case when exists(select 1 from "tmp_docSubTypes_for_documentStatusJournalProc" ) then ' + AND EXISTS( + SELECT 1 FROM "tmp_docSubTypes_for_documentStatusJournalProc" AS t WHERE comdoc.try_cast_bigint(t."DocSubType") = e."DocumentSubtype" + ) ' else '' end||' + and coalesce( e."DocumentDate",'''||_bdate||''') between '''||_bdate||''' and '''||_edate||''' + and e."TypeName" not in (''ServiceDesk'');' ; + -- }} Выборка по основным атрибутам документа + execute _str; + end; + $myQ$; + ``` -Итоговая выборка: -```sql -IF NOT comdoc."isTableExists"('tmp_addAtribute_for_documentStatusJournalProc', 'temp') THEN - CREATE TEMP TABLE "tmp_addAtribute_for_documentStatusJournalProc"( + + Итоговая выборка: + + ```sql + IF NOT comdoc."isTableExists"('tmp_addAtribute_for_documentStatusJournalProc', 'temp') THEN + CREATE TEMP TABLE "tmp_addAtribute_for_documentStatusJournalProc"( "PCode" bigint NOT NULL, worker bigint, bdate text, @@ -332,24 +381,24 @@ IF NOT comdoc."isTableExists"('tmp_addAtribute_for_documentStatusJournalProc', ' kolvo_new2 text,*/ TypeName varchar(255) - );-- ON COMMIT DROP; - end if; + );-- ON COMMIT DROP; + end if; - IF NOT comdoc."isTableExists"('tmp_workers_for_documentStatusJournalProc', 'temp') THEN - CREATE TEMP TABLE "tmp_workers_for_documentStatusJournalProc"( + IF NOT comdoc."isTableExists"('tmp_workers_for_documentStatusJournalProc', 'temp') THEN + CREATE TEMP TABLE "tmp_workers_for_documentStatusJournalProc"( "VCode" bigint NOT NULL, "Login" varchar(255), "NumTab" varchar(255), "NameFull" varchar(255) - ) ;-- ON COMMIT DROP; - end if; + ) ;-- ON COMMIT DROP; + end if; - insert into "tmp_addAtribute_for_documentStatusJournalProc" -select daa1."PCode", max(case when bd."ColumnName" = '#Worker#' then daa1."BigIntValue" end) as Worker, -max(case when bd."ColumnName" = '#bdate#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as bdate, -max(case when bd."ColumnName" = '#edate#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as edate, -max(case when bd."ColumnName" = '#kolvo#' then daa1."BigIntValue"::text end) as kolvo, -string_agg(case when bd."ColumnName" not in ('#bdate#', '#edate#', '#kolvo#','#bdate_new1#', '#edate_new1#', '#kolvo_new1#') then bd."Name" || ':' || (case + insert into "tmp_addAtribute_for_documentStatusJournalProc" + select daa1."PCode", max(case when bd."ColumnName" = '#Worker#' then daa1."BigIntValue" end) as Worker, + max(case when bd."ColumnName" = '#bdate#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as bdate, + max(case when bd."ColumnName" = '#edate#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as edate, + max(case when bd."ColumnName" = '#kolvo#' then daa1."BigIntValue"::text end) as kolvo, + string_agg(case when bd."ColumnName" not in ('#bdate#', '#edate#', '#kolvo#','#bdate_new1#', '#edate_new1#', '#kolvo_new1#') then bd."Name" || ':' || (case when coalesce(bd."AttributeType",'') = 'string' and coalesce(daa1."Value",'') <> '' then daa1."Value" when coalesce(bd."AttributeType",'') = 'string' and coalesce(daa1."Value",'') = '' then ' ' @@ -396,49 +445,49 @@ string_agg(case when bd."ColumnName" not in ('#bdate#', '#edate#', '#kolvo#','#b when coalesce(bd."AttributeType",'') = 'bool' and coalesce(daa1."BigIntValue"::integer,0) = 1 then substring(coalesce(daa1."Value",'|'),0, position('|' in coalesce(daa1."Value",'|'))) end) end , '; ') as other, -/*max(case when bd."ColumnName" = '#bdate_new1#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as bdate_new1, -max(case when bd."ColumnName" = '#edate_new1#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as edate_new1, -max(case when bd."ColumnName" = '#kolvo_new1#' then daa1."BigIntValue"::text end) as kolvo_new1, -max(case when bd."ColumnName" = '#bdate_new2#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as bdate_new2, -max(case when bd."ColumnName" = '#edate_new2#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as edate_new2, -max(case when bd."ColumnName" = '#kolvo_new2#' then daa1."BigIntValue"::text end) as kolvo_new2,*/ -max(a."DocType") as TypeName -from dfd."DocumentAdditionalAttribute" daa1 -join dfd."DocumentCategoryAttributeType" bd on daa1."CategoryAttributeType" = bd."VCode" -join "tmp_calcWithBaseParams_for_documentStatusJournalProc_distinctVC" a on daa1."PCode" = a."DocCode" -where a."DocType" in ('DocumentForSigining','UniversalDocument', 'EmployeeStatement') -group by daa1."PCode"; + /*max(case when bd."ColumnName" = '#bdate_new1#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as bdate_new1, + max(case when bd."ColumnName" = '#edate_new1#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as edate_new1, + max(case when bd."ColumnName" = '#kolvo_new1#' then daa1."BigIntValue"::text end) as kolvo_new1, + max(case when bd."ColumnName" = '#bdate_new2#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as bdate_new2, + max(case when bd."ColumnName" = '#edate_new2#' then to_char(daa1."DateValue", 'DD.MM.YYYY') end) as edate_new2, + max(case when bd."ColumnName" = '#kolvo_new2#' then daa1."BigIntValue"::text end) as kolvo_new2,*/ + max(a."DocType") as TypeName + from dfd."DocumentAdditionalAttribute" daa1 + join dfd."DocumentCategoryAttributeType" bd on daa1."CategoryAttributeType" = bd."VCode" + join "tmp_calcWithBaseParams_for_documentStatusJournalProc_distinctVC" a on daa1."PCode" = a."DocCode" + where a."DocType" in ('DocumentForSigining','UniversalDocument', 'EmployeeStatement') + group by daa1."PCode"; -insert into "tmp_workers_for_documentStatusJournalProc" -select w."VCode", max(pc."Code") as "Login", max(w."NumTab") as "NumTab", max(w."NameFull") as "NameFull" -from rp."RP_Worker" w -left join rp."RP_PersonContact" AS pc on pc."Pcode" = w."IdPerson" AND pc."IdTypeContact" = 6 -left join rp."RP_WorkerMove" mov on mov."IdWorker" = w."VCode" -group by w."VCode" ; + insert into "tmp_workers_for_documentStatusJournalProc" + select w."VCode", max(pc."Code") as "Login", max(w."NumTab") as "NumTab", max(w."NameFull") as "NameFull" + from rp."RP_Worker" w + left join rp."RP_PersonContact" AS pc on pc."Pcode" = w."IdPerson" AND pc."IdTypeContact" = 6 + left join rp."RP_WorkerMove" mov on mov."IdWorker" = w."VCode" + group by w."VCode" ; -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") + 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 w."Login" else t."VirtualCUser" end) , - null/*t."DateOfExecution"*/ - , t."DateControl", t."RouteVCode", t."RouteStatusId", t."RouteStatusName", t."DocName" - , t."DocSubject", null/* coalesce(t."expired", case when coalesce(t."eDate", t."ActionDate", _now) 1 and exists (select 1 from comdoc."RouteStage" rs where rs."PCode" = t."RouteVCode" and rs."IsMarked" is not true and rs."StageName" in ( 'Исполнить') @@ -451,41 +500,44 @@ select t."DocCode", t."DocType", t."DocForm", t."DocTypeName", t."SettingsId" and exists (select 1 from comdoc."RouteStage" rs join comdoc."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" + , ( SELECT DISTINCT string_agg(u."Initials"|| '(' || ds."Name"|| ')' , '; ') AS "x" FROM comdoc."RouteStage" as rs join comdoc."StageItem" AS i on i."PCode" = rs."VCode" join comdoc."VUserMeta" AS u ON u."VCode" = i."StageUser" join comdoc."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 w."NumTab" else w2."NumTab" end as "AnyColumnM" - , case when t."DocType" in ('UniversalDocument','DocumentForSigning') then w."NameFull" else w2."NameFull" end as "AnyColumnN" - , (select wr."VCode" from rp."RP_Worker" wr join rp."RP_PersonContact" pc on wr."IdPerson"= pc."Pcode" and pc."IdTypeContact" = 6 and pc."Code" = t."StageUser" where wr."COrg" = 1 order by wr."DateBeg" limit 1) as "EmailRecipient" - , (select wr."VCode" from rp."RP_Worker" wr join rp."RP_PersonContact" pc on wr."IdPerson"= pc."Pcode" and pc."IdTypeContact" = 6 and pc."Code" = t."StageUser" where wr."COrg" = 1 order by wr."DateBeg" limit 1) as "AnyColumnO" - , 3 -from "tmp_preresult" t -left join "tmp_addAtribute_for_documentStatusJournalProc" addit on addit."PCode" = t."DocCode" --and addit.TypeName = "DocType" -left join "tmp_workers_for_documentStatusJournalProc" w on w."VCode" = addit.worker -left join "tmp_workers_for_documentStatusJournalProc" w2 on w2."VCode" = t."IdWorker" -_topcount; -drop table "tmp_addAtribute_for_documentStatusJournalProc"; -drop table "tmp_workers_for_documentStatusJournalProc"; -``` + , case when t."DocType" in ('UniversalDocument','DocumentForSigning') then w."NumTab" else w2."NumTab" end as "AnyColumnM" + , case when t."DocType" in ('UniversalDocument','DocumentForSigning') then w."NameFull" else w2."NameFull" end as "AnyColumnN" + , (select wr."VCode" from rp."RP_Worker" wr join rp."RP_PersonContact" pc on wr."IdPerson"= pc."Pcode" and pc."IdTypeContact" = 6 and pc."Code" = t."StageUser" where wr."COrg" = 1 order by wr."DateBeg" limit 1) as "EmailRecipient" + , (select wr."VCode" from rp."RP_Worker" wr join rp."RP_PersonContact" pc on wr."IdPerson"= pc."Pcode" and pc."IdTypeContact" = 6 and pc."Code" = t."StageUser" where wr."COrg" = 1 order by wr."DateBeg" limit 1) as "AnyColumnO" + , 3 + from "tmp_preresult" t + left join "tmp_addAtribute_for_documentStatusJournalProc" addit on addit."PCode" = t."DocCode" --and addit.TypeName = "DocType" + left join "tmp_workers_for_documentStatusJournalProc" w on w."VCode" = addit.worker + left join "tmp_workers_for_documentStatusJournalProc" w2 on w2."VCode" = t."IdWorker" + _topcount; + drop table "tmp_addAtribute_for_documentStatusJournalProc"; + drop table "tmp_workers_for_documentStatusJournalProc"; + ``` -**Документы на подписание, просроченные работниками** +#### Документы на подписание, просроченные работниками -Основной запрос: +??? note "Запрос" -Итоговая выборка: -```sql - insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" + Основной запрос: + + Итоговая выборка: + + ```sql + 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" ) + "AnyColumnA" , "AnyColumnB" , "AnyColumnC" , "AnyColumnD" , "AnyColumnE" ) -select t."DocCode" , t."DocType" , t."DocForm" , t."DocTypeName" , t."SettingsId" + 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" , @@ -496,172 +548,171 @@ select t."DocCode" , t."DocType" , t."DocForm" , t."DocTypeName" , t."Se t."DocTypeName" as "AnyColumnA" , p."Family" || ' '|| p."Name" || ' '|| p."Father" as "AnyColumnB" , t."DocCode" as "AnyColumnC", t."AnyColumnD" , t."AnyColumnE" -from "tmp_preresult" t - inner join comdoc."Route" r on t."RouteVCode" = r."VCode" - inner join comdoc."RouteStage" rs on r."VCode" = rs."PCode" and t."StageNumber"= rs."StageNumber" -left join rp."RP_PersonContact" pc on pc."Code" = t."StageUser" and pc."IdTypeContact" = 6 - left join rp."RP_Person" p on pc."Pcode" = p."VCode" -where coalesce(t."RouteStatusId",0) in (2) and t."StageItemStatus"= 2 and t."IsMarked" is not true - and rs."StageName" ilike '%работник%' - and coalesce(t."ActionDate",t."DocumentDate") BETWEEN _bdate AND _edate - ; -``` + from "tmp_preresult" t + inner join comdoc."Route" r on t."RouteVCode" = r."VCode" + inner join comdoc."RouteStage" rs on r."VCode" = rs."PCode" and t."StageNumber"= rs."StageNumber" + left join rp."RP_PersonContact" pc on pc."Code" = t."StageUser" and pc."IdTypeContact" = 6 + left join rp."RP_Person" p on pc."Pcode" = p."VCode" + where coalesce(t."RouteStatusId",0) in (2) and t."StageItemStatus"= 2 and t."IsMarked" is not true + and rs."StageName" ilike '%работник%' + and coalesce(t."ActionDate",t."DocumentDate") BETWEEN _bdate AND _edate + ; + ``` -**Договоры и доп. соглашения** +#### Договоры и доп. соглашения -Основной запрос: -```sql -do $newQ$ -declare _str text; -begin -_str := ' -INSERT INTO "tmp_calcWithBaseParams_for_documentStatusJournalProc"( +??? note "Запрос" + + Основной запрос: + + ```sql + do $newQ$ + declare _str text; + begin + _str := ' + INSERT INTO "tmp_calcWithBaseParams_for_documentStatusJournalProc"( "DocCode", "DocType", "DocForm", "DocTypeName", "SettingsId", "orgId", "DocumentDate", "DocumentNumber", - "VirtualCUser", "Department", "IdWorker" - )a - SELECT e."VCode" AS "DocCode", s."DocType", s."DocForm", s."DocName" AS "DocTypeName", s."VCode" AS "SettingsId", e."COrg" AS "orgId", e."DateContract", e."VhodNumber" + "VirtualCUser", "Department", "IdWorker" + )a + SELECT e."VCode" AS "DocCode", s."DocType", s."DocForm", s."DocName" AS "DocTypeName", s."VCode" AS "SettingsId", e."COrg" AS "orgId", e."DateContract", e."VhodNumber" , e."CUser", e."CuratorDepartmentSpr", e."Manager" - FROM contract."Contract" AS e - JOIN comdoc."DocflowDocumentSettings" AS s ON s."DocType" = e."TypeName" - WHERE 1 = 1 - '||case when coalesce("orgParam",-1111)=-1111 then '' else ' and e."COrg" = '||_orgid::text end ||' - and EXISTS( SELECT 1 FROM "tmp_docTypes_for_documentStatusJournalProc" AS t WHERE t."DocType" = e."TypeName" ) - '|| case when _contractor is null then '' else ' and e."Contractor" = '||_contractor::text end - || case when _contract is null then '' else ' and e."VCode" = '||_contract::text end - || case when _manager is null then '' else ' and e."Manager" = '||_manager::text end - || ' and e."DateContract" between '_bdate' and '_edate' - union all - SELECT e."VCode" AS "DocCode", s."DocType", s."DocForm", s."DocName" AS "DocTypeName", s."VCode" AS "SettingsId", e."COrg" AS "orgId", e."DateContract", e."Number" + FROM contract."Contract" AS e + JOIN comdoc."DocflowDocumentSettings" AS s ON s."DocType" = e."TypeName" + WHERE 1 = 1 + '||case when coalesce("orgParam",-1111)=-1111 then '' else ' and e."COrg" = '||_orgid::text end ||' + and EXISTS( SELECT 1 FROM "tmp_docTypes_for_documentStatusJournalProc" AS t WHERE t."DocType" = e."TypeName" ) + '|| case when _contractor is null then '' else ' and e."Contractor" = '||_contractor::text end + || case when _contract is null then '' else ' and e."VCode" = '||_contract::text end + || case when _manager is null then '' else ' and e."Manager" = '||_manager::text end + || ' and e."DateContract" between '_bdate' and '_edate' + union all + SELECT e."VCode" AS "DocCode", s."DocType", s."DocForm", s."DocName" AS "DocTypeName", s."VCode" AS "SettingsId", e."COrg" AS "orgId", e."DateContract", e."Number" , e."CUser", e."CuratorDepartmentSpr", e."Manager" - FROM contract."AdditionalContract" AS e - JOIN comdoc."DocflowDocumentSettings" AS s ON s."DocType" = e."TypeName" - WHERE 1= 1 - '||case when coalesce("orgParam",-1111)=-1111 then '' else ' and e."COrg" = '||_orgid::text end ||' - and EXISTS( SELECT 1 FROM "tmp_docTypes_for_documentStatusJournalProc" AS t WHERE t."DocType" = e."TypeName" ) - '|| case when _contractor is null then '' else ' and e."Contractor" = '||_contractor::text end - || case when _contract is null then '' else ' and e."Contract" = '||_contract::text end - || case when _addcontract is null then '' else ' and e."VCode" = '||_addcontract::text end - || case when _manager is null then '' else ' and e."Manager" = '||_manager::text end - || ' and e."DateContract" between '_bdate' and '_edate';'; + FROM contract."AdditionalContract" AS e + JOIN comdoc."DocflowDocumentSettings" AS s ON s."DocType" = e."TypeName" + WHERE 1= 1 + '||case when coalesce("orgParam",-1111)=-1111 then '' else ' and e."COrg" = '||_orgid::text end ||' + and EXISTS( SELECT 1 FROM "tmp_docTypes_for_documentStatusJournalProc" AS t WHERE t."DocType" = e."TypeName" ) + '|| case when _contractor is null then '' else ' and e."Contractor" = '||_contractor::text end + || case when _contract is null then '' else ' and e."Contract" = '||_contract::text end + || case when _addcontract is null then '' else ' and e."VCode" = '||_addcontract::text end + || case when _manager is null then '' else ' and e."Manager" = '||_manager::text end + || ' and e."DateContract" between '_bdate' and '_edate';'; - execute (_str); -end; -$newQ$; -``` + execute (_str); + end; + $newQ$; + ``` -Итоговая выборка: -```sql + Итоговая выборка: -do -$$ -begin - - --CREATE INDEX IF NOT EXISTS "idx_tr1_tmp_CategoryAttributeType" ON "tmp_CategoryAttributeType"("PCode" ); + ```sql + do + $$ + begin + --CREATE INDEX IF NOT EXISTS "idx_tr1_tmp_CategoryAttributeType" ON "tmp_CategoryAttributeType"("PCode" ); - if not comdoc."isTableExists"('tmp_UserRole','temp') then + if not comdoc."isTableExists"('tmp_UserRole','temp') then create temp table "tmp_UserRole" ( "login" character varying(255), "Role" character varying(255) ) - --on commit drop -; -end if; + --on commit drop + ; + end if; -insert into "tmp_UserRole" ("login", "Role") -select distinct au."UserName" as login,"Role" -FROM lex."UserMeta" au + insert into "tmp_UserRole" ("login", "Role") + select distinct au."UserName" as login,"Role" + FROM lex."UserMeta" au JOIN lex."OrganizationUser" ou ON au."Id" = ou."User" left join lex."OrganizationUserRole" ur on ou."Id" = ur."OrganizationUser" -where "Role" in ('bh_purchasing_department', 'bh_legal_department', 'bh_contract_administrator', 'bh_financial_services') -or "Role" like '%ddc%' -; + where "Role" in ('bh_purchasing_department', 'bh_legal_department', 'bh_contract_administrator', 'bh_financial_services') + or "Role" like '%ddc%' + ; - if not comdoc."isTableExists"('tmp_CuserChief','temp') then + if not comdoc."isTableExists"('tmp_CuserChief','temp') then create temp table "tmp_CuserChief" ( "VirtualCUser" character varying(255), "chief" character varying(255) ) - --on commit drop -; -end if; + --on commit drop + ; + end if; -insert into "tmp_CuserChief" ("VirtualCUser","chief") - select "VirtualCUser", chief."chief" - from (select distinct t."DocCode",t."DocType" , t."orgId", t."VirtualCUser" from "tmp_preresult" t where t."DocType" in ('Base.Contract','Base.AdditionalContract')) t - left join lateral comdoc."getProjectTemplateMember"(t."DocCode",t."DocType" , t."orgId", t."VirtualCUser", 'Service.Chief') chief on true - ; + insert into "tmp_CuserChief" ("VirtualCUser","chief") + select "VirtualCUser", chief."chief" + from (select distinct t."DocCode",t."DocType" , t."orgId", t."VirtualCUser" from "tmp_preresult" t where t."DocType" in ('Base.Contract','Base.AdditionalContract')) t + left join lateral comdoc."getProjectTemplateMember"(t."DocCode",t."DocType" , t."orgId", t."VirtualCUser", 'Service.Chief') chief on true + ; - if not comdoc."isTableExists"('tmp_ExpiredRole','temp') then + if not comdoc."isTableExists"('tmp_ExpiredRole','temp') then create temp table "tmp_ExpiredRole" ( "DocCode" bigint, "Role" character varying(255), "maxexpired" int ) - --on commit drop -; -end if; + --on commit drop + ; + end if; - insert into "tmp_ExpiredRole" ("DocCode","Role", "maxexpired") -select a."DocCode", a."Role", max(a."expired") as "maxexpired" - from - ( - select t."DocCode", t."StageUser", -- ur."Role", coalesce(ch.ф"chief",'') as "chief", + insert into "tmp_ExpiredRole" ("DocCode","Role", "maxexpired") + select a."DocCode", a."Role", max(a."expired") as "maxexpired" + from + ( + select t."DocCode", t."StageUser", -- ur."Role", coalesce(ch.ф"chief",'') as "chief", case when coalesce(ch."chief",'') <>'' then 'chief_role' else ur."Role" end as "Role", -round(comdoc."dfwcGetDuration"(t."eDate", COALESCE(t."ActionDate", _now::date), false, t."orgId", null, _dayoff1, _dayoff2, null)/60.0/60.0/9, 0) as "expired" + round(comdoc."dfwcGetDuration"(t."eDate", COALESCE(t."ActionDate", _now::date), false, t."orgId", null, _dayoff1, _dayoff2, null)/60.0/60.0/9, 0) as "expired" - from (select distinct "DocCode", t."StageUser", t."eDate", t."ActionDate",t."orgId" from "tmp_preresult" t where t."DocType" in ('Base.Contract','Base.AdditionalContract')) t - left join "tmp_UserRole" ur on t."StageUser"= ur."login" - left join "tmp_CuserChief" ch on t."StageUser" = ch."chief" + from (select distinct "DocCode", t."StageUser", t."eDate", t."ActionDate",t."orgId" from "tmp_preresult" t where t."DocType" in ('Base.Contract','Base.AdditionalContract')) t + left join "tmp_UserRole" ur on t."StageUser"= ur."login" + left join "tmp_CuserChief" ch on t."StageUser" = ch."chief" - ) a - where coalesce(a."expired", 0) > 0 - group by a."DocCode", a."Role"; - - - end; - $$; - - -insert into "tmp_finresult"( "DocCode" , "DocType" , "DocForm" , "DocTypeName" , "SettingsId" + ) a + where coalesce(a."expired", 0) > 0 + group by a."DocCode", a."Role"; + end; + $$; + + 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" -, "AnyColumnF" , "AnyColumnG" , "AnyColumnH" , "AnyColumnI" , "AnyColumnJ" -, "AnyColumnK" , "AnyColumnL" , "AnyColumnM" , "AnyColumnN" , "AnyColumnO" -, "AnyColumnP", "AnyColumnQ" , "AnyColumnR" , "AnyColumnS" , "AnyColumnT" -, "AnyColumnU" , "AnyColumnV" , "AnyColumnW" , "AnyColumnX" , "AnyColumnY" -, "AnyColumnZ" , "AnyColumnAA" , "AnyColumnAB" , "AnyColumnAC" , "AnyColumnAD" , "AnyColumnAE" , "AnyColumnAF" - , "AnyColumnAG" , "AnyColumnAH" , "AnyColumnAI" , "AnyColumnAJ" , "AnyColumnAK" , "AnyColumnAL" , "AnyColumnAM" -, "Colors", "attFilter" -) + , "AnyColumnA" , "AnyColumnB" , "AnyColumnC" , "AnyColumnD" , "AnyColumnE" + , "AnyColumnF" , "AnyColumnG" , "AnyColumnH" , "AnyColumnI" , "AnyColumnJ" + , "AnyColumnK" , "AnyColumnL" , "AnyColumnM" , "AnyColumnN" , "AnyColumnO" + , "AnyColumnP", "AnyColumnQ" , "AnyColumnR" , "AnyColumnS" , "AnyColumnT" + , "AnyColumnU" , "AnyColumnV" , "AnyColumnW" , "AnyColumnX" , "AnyColumnY" + , "AnyColumnZ" , "AnyColumnAA" , "AnyColumnAB" , "AnyColumnAC" , "AnyColumnAD" , "AnyColumnAE" , "AnyColumnAF" + , "AnyColumnAG" , "AnyColumnAH" , "AnyColumnAI" , "AnyColumnAJ" , "AnyColumnAK" , "AnyColumnAL" , "AnyColumnAM" + , "Colors", "attFilter" + ) -select distinct 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", null::bigint , null::int as "StageNumber" , null::date as "BeginDate" , null::date as "ActionDate" - , null::int as "DocumentAction" ,null::int as "DocumentStatus" , null as"FromMessage" , null::date as "eDate", t."Department" - , null as "StageUser", null::int as "StageItemStatus" , null::int as "StageStatus", null::int as "StageItemAction", t."DocumentSubtype", -"Number" as "AnyColumnA", -"VhodNumber" as "AnyColumnB", -to_char("DateContract", 'DD.MM.YYYY' ) as "AnyColumnC", -to_char("DateBegin", 'DD.MM.YYYY' ) as "AnyColumnD", -to_char("DateEnd", 'DD.MM.YYYY' ) as "AnyColumnE", -null as "AnyColumnF", -case when coalesce("IsDocument",false) = true then 'Да' else 'Нет' end as "AnyColumnG", -"StatusOfContract" as "AnyColumnH", -"Contractor" as "AnyColumnI", -"VTypeContract" as "AnyColumnJ", -"ContractKind1" as "AnyColumnK", -null as "AnyColumnL", -"SumContract" as "AnyColumnM", -"TypePayment" as "AnyColumnN", -"SubjectOfContract" as "AnyColumnO", -null as "AnyColumnP", -to_char("DateAutolong", 'DD.MM.YYYY' ) as "AnyColumnQ", -null as "AnyColumnR", -null as "AnyColumnS", -null as "AnyColumnT", -COALESCE(rst."RouteStatusNm", 'Не запущен') as "AnyColumnU" -, ( SELECT string_agg(r_info."x", ';') FROM + select distinct 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", null::bigint , null::int as "StageNumber" , null::date as "BeginDate" , null::date as "ActionDate" + , null::int as "DocumentAction" ,null::int as "DocumentStatus" , null as"FromMessage" , null::date as "eDate", t."Department" + , null as "StageUser", null::int as "StageItemStatus" , null::int as "StageStatus", null::int as "StageItemAction", t."DocumentSubtype", + "Number" as "AnyColumnA", + "VhodNumber" as "AnyColumnB", + to_char("DateContract", 'DD.MM.YYYY' ) as "AnyColumnC", + to_char("DateBegin", 'DD.MM.YYYY' ) as "AnyColumnD", + to_char("DateEnd", 'DD.MM.YYYY' ) as "AnyColumnE", + null as "AnyColumnF", + case when coalesce("IsDocument",false) = true then 'Да' else 'Нет' end as "AnyColumnG", + "StatusOfContract" as "AnyColumnH", + "Contractor" as "AnyColumnI", + "VTypeContract" as "AnyColumnJ", + "ContractKind1" as "AnyColumnK", + null as "AnyColumnL", + "SumContract" as "AnyColumnM", + "TypePayment" as "AnyColumnN", + "SubjectOfContract" as "AnyColumnO", + null as "AnyColumnP", + to_char("DateAutolong", 'DD.MM.YYYY' ) as "AnyColumnQ", + null as "AnyColumnR", + null as "AnyColumnS", + null as "AnyColumnT", + COALESCE(rst."RouteStatusNm", 'Не запущен') as "AnyColumnU" + , ( SELECT string_agg(r_info."x", ';') FROM ( SELECT 'Этап '||s."StageNumber"||' '||du."Initials"||COALESCE(' '||ds."Name", '')||COALESCE(' '||i."FromMessage", '') AS "x" FROM comdoc."Route" AS r JOIN comdoc."RouteStage" AS s ON s."PCode" = r."VCode" @@ -673,22 +724,22 @@ COALESCE(rst."RouteStatusNm", 'Не запущен') as "AnyColumnU" AND r."RouteStatus" <> 4 ORDER BY s."StageNumber" ASC, i."VCode" ASC ) as r_info ) as "AnyColumnV", -null as "AnyColumnW", --бренд -null as "AnyColumnX", --парал импорт -null as "AnyColumnY", -- с НДС -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnZ",--просрочено рук -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_financial_services') as "AnyColumnAA",--просрочено фин -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_legal_department') as "AnyColumnAB",--просрочено прав деп -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_purchasing_department') as "AnyColumnAC",--просрочено закупки -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role" like '%ddc%') as "AnyColumnAD", --просрочено ДДЦ -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_contract_administrator') as "AnyColumnAE", --просрочен админ дог -t."DocCode" as "AnyColumnAF" + null as "AnyColumnW", --бренд + null as "AnyColumnX", --парал импорт + null as "AnyColumnY", -- с НДС + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnZ",--просрочено рук + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_financial_services') as "AnyColumnAA",--просрочено фин + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_legal_department') as "AnyColumnAB",--просрочено прав деп + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_purchasing_department') as "AnyColumnAC",--просрочено закупки + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role" like '%ddc%') as "AnyColumnAD", --просрочено ДДЦ + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_contract_administrator') as "AnyColumnAE", --просрочен админ дог + t."DocCode" as "AnyColumnAF" ---надо найти зама -, (SELECT DISTINCT string_agg(x."UserName", ',') FROM + --надо найти зама + , (SELECT DISTINCT string_agg(x."UserName", ',') FROM (select m."LastName" || ' ' || m."FirstName" || ' ' || m. "MiddleName" as "UserName" ---m."UserName", m1."UserName" as "UserName1" + --m."UserName", m1."UserName" as "UserName1" from lex."UserMeta" as m join lex."OrganizationUser" as ou on m."Id" = ou."User" and coalesce(ou."IsBlocked",false) = false join lex."Replacement" as rep on ou."Id" = rep."Replacer" @@ -698,92 +749,94 @@ t."DocCode" as "AnyColumnAF" join lex."UserMeta" as m1 on ou1."User" = m1."Id" where m1."UserName" = t."VirtualCUser" group by m."LastName" || ' ' || m."FirstName" || ' ' || m. "MiddleName" --- m."UserName", m1."UserName" + -- m."UserName", m1."UserName" ) as x ) ::character varying(1000) AS "AnyColumnAG" ---надо найти руководителя по штатке - , + --надо найти руководителя по штатке + , - (select um."LastName" || ' ' ||um."FirstName" || ' ' ||um."MiddleName" as "UserName" - from comdoc."Department" dep + (select um."LastName" || ' ' ||um."FirstName" || ' ' ||um."MiddleName" as "UserName" + from comdoc."Department" dep join rp."RP_Worker" w on dep."Manager" = w."VCode" join rp."RP_PersonContact" pers on w."IdPerson" = pers."Pcode" and pers."IdTypeContact" = 6 -join lex."UserMeta" um on um."UserName" = pers."Code" -where dep."VCode" = (select "Department" from comdoc."DocflowExists" where "VCode" = t."DocCode" and "TypeName" = t."DocType" limit 1) ) -AS "AnyColumnAH" -, wi."Dpost" AS "AnyColumnAI", wi."Duvl" AS "AnyColumnAJ" - , c."PaymentMethod" as "AnyColumnAK" , null as "AnyColumnAL" , -case when coalesce(c."DateAutolong",c."DateEnd",'20701231')::date between now()::date and now()::date + 30::integer -then 'yellow' -when coalesce(c."DateAutolong",c."DateEnd",'20701231') 4 ORDER BY s."StageNumber" ASC, i."VCode" ASC ) as r_info ) as "AnyColumnV", -c."BrendName" as "AnyColumnW", --бренд -c."ParalelImportName" as "AnyColumnX", --парал импорт -case when coalesce(c."WithNDS",false) = true then 'С НДС' else 'Без НДС' end as "AnyColumnY", -- с НДС -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnZ",--просрочено рук -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnAA",--просрочено фин -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_legal_department') as "AnyColumnAB",--просрочено прав деп -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnAC",--просрочено закупки -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnAD", --просрочено ДДЦ -(select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_contract_administrator') as "AnyColumnAE", --просрочен админ дог -t."DocCode" as "AnyColumnAF" - --надо найти зама -, (SELECT DISTINCT string_agg(x."UserName", ',') FROM + c."BrendName" as "AnyColumnW", --бренд + c."ParalelImportName" as "AnyColumnX", --парал импорт + case when coalesce(c."WithNDS",false) = true then 'С НДС' else 'Без НДС' end as "AnyColumnY", -- с НДС + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnZ",--просрочено рук + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnAA",--просрочено фин + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_legal_department') as "AnyColumnAB",--просрочено прав деп + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnAC",--просрочено закупки + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='chief_role') as "AnyColumnAD", --просрочено ДДЦ + (select "maxexpired" from "tmp_ExpiredRole" er where t."DocCode" = er."DocCode" and "Role"='bh_contract_administrator') as "AnyColumnAE", --просрочен админ дог + t."DocCode" as "AnyColumnAF" + --надо найти зама + , (SELECT DISTINCT string_agg(x."UserName", ',') FROM (select m."LastName" || ' ' || m."FirstName" || ' ' || m. "MiddleName" as "UserName" ---m."UserName", m1."UserName" as "UserName1" + --m."UserName", m1."UserName" as "UserName1" from lex."UserMeta" as m join lex."OrganizationUser" as ou on m."Id" = ou."User" and coalesce(ou."IsBlocked",false) = false join lex."Replacement" as rep on ou."Id" = rep."Replacer" @@ -819,45 +872,298 @@ t."DocCode" as "AnyColumnAF" join lex."UserMeta" as m1 on ou1."User" = m1."Id" where m1."UserName" = t."VirtualCUser" group by m."LastName" || ' ' || m."FirstName" || ' ' || m. "MiddleName" --- m."UserName", m1."UserName" + -- m."UserName", m1."UserName" ) as x ) ::character varying(1000) AS "AnyColumnAG" ---надо найти руководителя по штатке - , + --надо найти руководителя по штатке + , - (select um."LastName" || ' ' ||um."FirstName" || ' ' ||um."MiddleName" as "UserName" - from comdoc."Department" dep + (select um."LastName" || ' ' ||um."FirstName" || ' ' ||um."MiddleName" as "UserName" + from comdoc."Department" dep join rp."RP_Worker" w on dep."Manager" = w."VCode" join rp."RP_PersonContact" pers on w."IdPerson" = pers."Pcode" and pers."IdTypeContact" = 6 -join lex."UserMeta" um on um."UserName" = pers."Code" -where dep."VCode" = (select "Department" from comdoc."DocflowExists" where "VCode" = t."DocCode" and "TypeName" = t."DocType" limit 1) ) -AS "AnyColumnAH" -, wi."Dpost" AS "AnyColumnAI", wi."Duvl" AS "AnyColumnAJ" - , c."PaymentMethod" as "AnyColumnAK" , c."SumAddContractWithoutVAT" as "AnyColumnAL" , -null as "AnyColumnAM" -, null as "Colors" -from (select distinct 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", t."Department", t."DocumentSubtype", t."DocumentCategory" -from "tmp_preresult" t + join lex."UserMeta" um on um."UserName" = pers."Code" + where dep."VCode" = (select "Department" from comdoc."DocflowExists" where "VCode" = t."DocCode" and "TypeName" = t."DocType" limit 1) ) + AS "AnyColumnAH" + , wi."Dpost" AS "AnyColumnAI", wi."Duvl" AS "AnyColumnAJ" + , c."PaymentMethod" as "AnyColumnAK" , c."SumAddContractWithoutVAT" as "AnyColumnAL" , + null as "AnyColumnAM" + , null as "Colors" + from (select distinct 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", t."Department", t."DocumentSubtype", t."DocumentCategory" + from "tmp_preresult" t where t."DocType" in ('Base.AdditionalContract') - ) t - inner join contract."VAdditionalContractRegistry" ds on t."DocCode" =ds."VCode" - inner join contract."VContractRegistry" c on ds."Contract" = c."VCode" - LEFT JOIN ( SELECT w."VCode", w."lexLogin", dep."VCode" AS "DepartmentVCode", dep."Name" AS "Department", pos."Name" AS "Position" ,to_char(w."DateBeg",'DD.MM.YYYY') as "Dpost",to_char(w."DateEnd",'DD.MM.YYYY') as "Duvl" - FROM rp."VLookupWorker" AS w - JOIN rp."RP_WorkerMove" AS m ON m."IdWorker" = w."VCode" - LEFT JOIN comdoc."Department" AS dep ON dep."VCode" = m."IdDepartment" - LEFT JOIN rp."RP_Post" AS pos ON pos."VCode" = m."IdPost" - WHERE w."lexLogin" IS NOT NULL - ORDER BY ROW_NUMBER() OVER( - PARTITION BY w."lexLogin" - ORDER BY COALESCE(m."DateEnd", w."DateEnd", '2070-01-01'::date) DESC, m."VCode" DESC - ) - FETCH FIRST 1 ROWS WITH TIES ) --as "workers" - AS wi ON wi."lexLogin" = t."VirtualCUser" - LEFT JOIN LATERAL comdoc."getDocRouteCurrentStatus"(t."DocCode", t."DocType") AS rst ON true --- where c."DateContract" BETWEEN _bdate AND _edate + ) t + inner join contract."VAdditionalContractRegistry" ds on t."DocCode" =ds."VCode" + inner join contract."VContractRegistry" c on ds."Contract" = c."VCode" + LEFT JOIN ( SELECT w."VCode", w."lexLogin", dep."VCode" AS "DepartmentVCode", dep."Name" AS "Department", pos."Name" AS "Position" ,to_char(w."DateBeg",'DD.MM.YYYY') as "Dpost",to_char(w."DateEnd",'DD.MM.YYYY') as "Duvl" + FROM rp."VLookupWorker" AS w + JOIN rp."RP_WorkerMove" AS m ON m."IdWorker" = w."VCode" + LEFT JOIN comdoc."Department" AS dep ON dep."VCode" = m."IdDepartment" + LEFT JOIN rp."RP_Post" AS pos ON pos."VCode" = m."IdPost" + WHERE w."lexLogin" IS NOT NULL + ORDER BY ROW_NUMBER() OVER( + PARTITION BY w."lexLogin" + ORDER BY COALESCE(m."DateEnd", w."DateEnd", '2070-01-01'::date) DESC, m."VCode" DESC + ) + FETCH FIRST 1 ROWS WITH TIES ) --as "workers" + AS wi ON wi."lexLogin" = t."VirtualCUser" + LEFT JOIN LATERAL comdoc."getDocRouteCurrentStatus"(t."DocCode", t."DocType") AS rst ON true + -- where c."DateContract" BETWEEN _bdate AND _edate + */ + ``` -*/ -``` \ No newline at end of file +#### Документы в работе у подчиненных + +??? note "Запрос" + + Основной запрос: + + Итоговая выборка: + + ```sql + 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" , "DocumentSubtype" , + "AnyColumnA" ,"AnyColumnB" , "AnyColumnC","AnyColumnD" , + "AnyColumnE" , + "AnyColumnF", "AnyColumnG" , "AnyColumnH" , "AnyColumnI", "AnyColumnJ","AnyColumnK") + 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 pc."Code" from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_Worker" w on w."VCode" = daa1."BigIntValue" + join rp."RP_PersonContact" AS pc ON pc."Pcode" = w."IdPerson" AND pc."IdTypeContact" = 6 + where t."DocumentCategory" = bd."PCode" limit 1) + else t."VirtualCUser" end, + + 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."StageUser" , t."StageItemStatus" , t."StageStatus" , t."StageItemAction", t."DocumentSubtype", t."AnyColumnA" , + case when t."DocType" in ('DocumentForSigining','UniversalDocument') then (select coalesce(w."ID_RP",'') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_WorkerMove" w on w."IdWorker" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) + else (select coalesce(m."ID_RP",'') from rp."RP_WorkerMove" AS m where m."IdWorker" = t."IdWorker" limit 1) end as "AnyColumnB" , + case when t."DocType" in ('DocumentForSigining','UniversalDocument') then (select coalesce(w."RP_Txt",'') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_WorkerMove" w on w."IdWorker" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) else (select coalesce(m."RP_Txt",'') from rp."RP_WorkerMove" AS m where m."IdWorker" = t."IdWorker" limit 1) end as "AnyColumnC", + case when t."DocType" in ('DocumentForSigining','UniversalDocument') then (select coalesce(w."ID_ER",'') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_WorkerMove" w on w."IdWorker" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) else (select coalesce(m."ID_ER",'') from rp."RP_WorkerMove" AS m where m."IdWorker" = t."IdWorker" limit 1) end as "AnyColumnD" , + t."AnyColumnE", + (select to_char(daa1."DateValue", 'DD.MM.YYYY') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#bdate#' where t."DocumentCategory" = bd."PCode" limit 1) as "AnyColumnF" , + (select to_char(daa1."DateValue", 'DD.MM.YYYY') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#edate#' where t."DocumentCategory" = bd."PCode" limit 1) as "AnyColumnG" , + (select daa1."BigIntValue"::text from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" ='#kolvo#' where t."DocumentCategory" = bd."PCode" limit 1) 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 dfd."DocumentAdditionalAttribute" atr + join dfd."DocumentCategoryAttributeType" dca on atr."CategoryAttributeType" = dca."VCode" + where t."DocCode" = atr."PCode" and dca."ColumnName" not in ('#bdate#', '#edate#', '#kolvo#')) as "AnyColumnI", + case when t."DocType" in ('UniversalDocument','DocumentForSigning') then (select w."NumTab" from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_Worker" w on w."VCode" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) + else (select r."NumTab" from rp."RP_Worker" as r where r."VCode" = t."IdWorker") end , + case when t."DocType" in ('UniversalDocument','DocumentForSigning') then (select w."NameFull" from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_Worker" w on w."VCode" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) + else (select r."NameFull" from rp."RP_Worker" as r where r."VCode" = t."IdWorker") end + 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 comdoc."getWorkerChiefStructure"(null::bigint,lex."getVirtualLogin"(),1) s + join rp."RP_Worker" r on s."VCode" = r."VCode" + join rp."RP_PersonContact" c on r."IdPerson" = c."Pcode" and c."IdTypeContact" = 6 + where c."Code" = coalesce(t."StageUser",'') ) + AND ( + t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate + ) and t."DocType" not in ('ServiceDesk', 'CancellationAct') ; + + ``` + +#### Универсальные документы подчиненных + +??? note "Запрос" + + Основной запрос: + + Итоговая выборка: + + ```sql + 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" , "DocumentSubtype" , + "AnyColumnA" ,"AnyColumnB" , "AnyColumnC","AnyColumnD" , + "AnyColumnE" , + "AnyColumnF", "AnyColumnG" , "AnyColumnH" , "AnyColumnI", "AnyColumnJ","AnyColumnK") + select distinct 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 pc."Code" from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_Worker" w on w."VCode" = daa1."BigIntValue" + join rp."RP_PersonContact" AS pc ON pc."Pcode" = w."IdPerson" AND pc."IdTypeContact" = 6 + where t."DocumentCategory" = bd."PCode" limit 1) + else t."VirtualCUser" end, + + 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."StageUser" , t."StageItemStatus" , t."StageStatus" , t."StageItemAction", t."DocumentSubtype", t."AnyColumnA" , + case when t."DocType" in ('DocumentForSigining','UniversalDocument') then (select coalesce(w."ID_RP",'') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_WorkerMove" w on w."IdWorker" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) + else (select coalesce(m."ID_RP",'') from rp."RP_WorkerMove" AS m where m."IdWorker" = t."IdWorker" limit 1) end as "AnyColumnB" , + case when t."DocType" in ('DocumentForSigining','UniversalDocument') then (select coalesce(w."RP_Txt",'') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_WorkerMove" w on w."IdWorker" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) else (select coalesce(m."RP_Txt",'') from rp."RP_WorkerMove" AS m where m."IdWorker" = t."IdWorker" limit 1) end as "AnyColumnC", + case when t."DocType" in ('DocumentForSigining','UniversalDocument') then (select coalesce(w."ID_ER",'') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_WorkerMove" w on w."IdWorker" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) else (select coalesce(m."ID_ER",'') from rp."RP_WorkerMove" AS m where m."IdWorker" = t."IdWorker" limit 1) end as "AnyColumnD" , + t."AnyColumnE", + (select to_char(daa1."DateValue", 'DD.MM.YYYY') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#bdate#' where t."DocumentCategory" = bd."PCode" limit 1) as "AnyColumnF" , + (select to_char(daa1."DateValue", 'DD.MM.YYYY') from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#edate#' where t."DocumentCategory" = bd."PCode" limit 1) as "AnyColumnG" , + (select daa1."BigIntValue"::text from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" ='#kolvo#' where t."DocumentCategory" = bd."PCode" limit 1) 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 dfd."DocumentAdditionalAttribute" atr + join dfd."DocumentCategoryAttributeType" dca on atr."CategoryAttributeType" = dca."VCode" + where t."DocCode" = atr."PCode" and dca."ColumnName" not in ('#bdate#', '#edate#', '#kolvo#')) as "AnyColumnI", + case when t."DocType" in ('UniversalDocument','DocumentForSigning') then (select w."NumTab" from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_Worker" w on w."VCode" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) + else (select r."NumTab" from rp."RP_Worker" as r where r."VCode" = t."IdWorker") end , + case when t."DocType" in ('UniversalDocument','DocumentForSigning') then (select w."NameFull" from dfd."DocumentCategoryAttributeType" bd + join dfd."DocumentAdditionalAttribute" daa1 on t."DocCode" = daa1."PCode" and daa1."CategoryAttributeType" = bd."VCode" and bd."ColumnName" = '#Worker#' + join rp."RP_Worker" w on w."VCode" = daa1."BigIntValue" + where t."DocumentCategory" = bd."PCode" limit 1) + else (select r."NameFull" from rp."RP_Worker" as r where r."VCode" = t."IdWorker") end + from "tmp_preresult" t + where t."IsMarked" is not true and + exists (select 1 + from comdoc."getWorkerChiefStructure"(null::bigint,lex."getVirtualLogin"(),1) s + join rp."RP_Worker" r on s."VCode" = r."VCode" + join rp."RP_PersonContact" c on r."IdPerson" = c."Pcode" and c."IdTypeContact" = 6 + where c."Code" = coalesce(t."StageUser",'') ) + AND ( + t."DocumentDate" IS NULL OR t."DocumentDate" BETWEEN _bdate AND _edate + ) and t."DocType" in ('UniversalDocument') ; + ``` \ No newline at end of file diff --git a/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-10.png b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-10.png new file mode 100644 index 0000000..516ace6 Binary files /dev/null and b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-10.png differ diff --git a/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-6.png b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-6.png new file mode 100644 index 0000000..583596a Binary files /dev/null and b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-6.png differ diff --git a/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-7.png b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-7.png new file mode 100644 index 0000000..479b69a Binary files /dev/null and b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-7.png differ diff --git a/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-8.png b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-8.png new file mode 100644 index 0000000..f9df07d Binary files /dev/null and b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-8.png differ diff --git a/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-9.png b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-9.png new file mode 100644 index 0000000..b000f31 Binary files /dev/null and b/docs/Admin manuals/Настройка правил поиска для ЖСД/media/image-9.png differ