· 7 years ago · Dec 13, 2018, 02:32 PM
1drop table if exists test.tt_result;
2create table test.tt_result
3as
4select distinct on (c.reg_num) row_number() over (order by c.sign_date) as "â„–",
5 org.factual_address__region__full_name "Регион",
6 coalesce(c.customer__full_name, c.customer__short_name) as "ОрганизациÑ-заказчик",
7 c.reg_num as "РегиÑтрационный номер контракта",
8 fn.purchase_object_info as "Ðаименование контракта",
9 spider.get_status_contract
10 (
11 cp.current_contract_stage :: character varying(100),
12 cp.executions__final_stage_execution :: boolean,
13 cp.termination__reason__code :: int
14 ) "Ð¡Ñ‚Ð°Ð´Ð¸Ñ ÐºÐ¾Ð½Ñ‚Ñ€Ð°ÐºÑ‚Ð°",
15 case when po.protocol_lotid is not null then 1 else 0 end "ПЗ. Контракт Ñ 1 заÑвкой",
16 null "N ПЗ. КоличеÑтво критериев отбора",
17 --fn.procedure_info__collecting__end_date - fn.procedure_info__collecting__start_date "ПЗ. ДлительноÑть периода раÑÑÐ¼Ð¾Ñ‚Ñ€ÐµÐ½Ð¸Ñ Ð·Ð°Ñвок",
18 case when pfo.protocol_lotid is not null then 1 else 0 end "РЗ. ИÑключены вÑе, кроме одного заÑвителÑ",
19 -- null "N РЗ. Ð’ÐµÑ Ð½ÐµÑ†ÐµÐ½Ð¾Ð²Ñ‹Ñ… критериев",
20 case when fpp.id is not null then 1 else 0 end "РЗ. Продление периода раÑÑморениÑ",
21 --null "N РЗ. ДлительноÑть периода принÑÑ‚Ð¸Ñ Ñ€ÐµÑˆÐµÐ½Ð¸Ñ Ð¿Ð¾ контракту",
22 case when tcp.old_id is not null then 1 else 0 end "Продление контракта",
23 case when tcp.new_price_info__price - tcp.old_price_info__price > 0 then 1 else 0 end "Увеличение ÑтоимоÑти контракта",
24 case when (tcp.old_price_info__price is not null and tcp.old_price_info__price != 0) and tcp.new_price_info__price - tcp.old_price_info__price > 0 then tcp.old_price_info__price else null end "УСК. ÐÐ°Ñ‡Ð°Ð»ÑŒÐ½Ð°Ñ ÑтоимоÑть",
25 case when (tcp.old_price_info__price is not null and tcp.old_price_info__price != 0) and tcp.new_price_info__price - tcp.old_price_info__price > 0 then tcp.new_price_info__price else null end "УСК. ÐžÐºÐ¾Ð½Ñ‡Ð°Ñ‚ÐµÐ»ÑŒÐ½Ð°Ñ ÑтоимоÑть",
26 --case when (tcp.old_price_info__price is not null and tcp.old_price_info__price != 0) and tcp.new_price_info__price - tcp.old_price_info__price > 0 then (tcp.new_price_info__price ::real - tcp.old_price_info__price::real)/tcp.old_price_info__price ::real else null end "УСК. Изменение в ÑтоимоÑти контракта/первоначальную ÑтоимоÑть контракта",
27
28
29 c.price_info__price "Сумма контракта",
30 fn.procedure_info__collecting__start_date "Дата начала подачи заÑвок",
31 fn.procedure_info__collecting__end_date "Дата Ð¾ÐºÐ¾Ð½Ñ‡Ð°Ð½Ð¸Ñ Ð¿Ð¾Ð´Ð°Ñ‡Ð¸ заÑвок",
32 coalesce(fn.procedure_info__selecting__date, fn.procedure_info__scoring__date) "Дата Ð¿Ð¾Ð´Ð²ÐµÐ´ÐµÐ½Ð¸Ñ Ð¸Ñ‚Ð¾Ð³Ð¾Ð² конкурÑа",
33 c.sign_date "Дата Ð·Ð°ÐºÐ»ÑŽÑ‡ÐµÐ½Ð¸Ñ Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ€Ð°",
34 c.protocol_date "Дата Ð¿Ð¾Ð´Ð²ÐµÐ´ÐµÐ½Ð¸Ñ Ð¸Ñ‚Ð¾Ð³Ð¾Ð² закупки",
35 c.execution_period__start_date "Дата начала иÑÐ¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ€Ð°",
36 c.execution_period__end_date "Дата Ð¾ÐºÐ¾Ð½Ñ‡Ð°Ð½Ð¸Ñ Ð¸ÑÐ¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ€Ð°",
37 c.protocol_date "Дата Ð¾Ð³Ð»Ð°ÑˆÐµÐ½Ð¸Ñ Ñ€ÐµÐ·ÑƒÐ»ÑŒÑ‚Ð°Ñ‚Ð¾Ð² раÑÑмотрениÑ",
38 null "N Признак «Договором предуÑмотрено ",
39 null "N Дата Ñ€Ð°Ð·Ð¼ÐµÑ‰ÐµÐ½Ð¸Ñ Ñведений об иÑпол",
40 null "N Признак «ИÑполнение завершено»",
41 null "N Признак отмены Ñведений",
42 null "N ÐеуÑтойка",
43 case when tcp.old_execution_period__end_date != tcp.old_execution_period__start_date and tcp.new_execution_period__end_date::date - tcp.old_execution_period__end_date::date > 0 then tcp.new_execution_period__start_date else null end "Дата начала контракта ПОСЛЕ изменениÑ",
44 case when tcp.old_execution_period__end_date != tcp.old_execution_period__start_date and tcp.new_execution_period__end_date::date - tcp.old_execution_period__end_date::date > 0 then tcp.old_execution_period__start_date else null end "Дата начала контракта ДО изменениÑ",
45 case when tcp.old_execution_period__end_date != tcp.old_execution_period__start_date and tcp.new_execution_period__end_date::date - tcp.old_execution_period__end_date::date > 0 then tcp.new_execution_period__end_date else null end "Дата Ð¾ÐºÐ¾Ð½Ñ‡Ð°Ð½Ð¸Ñ ÐºÐ¾Ð½Ñ‚Ñ€Ð°ÐºÑ‚Ð° ПОСЛЕ изменениÑ",
46 case when tcp.old_execution_period__end_date != tcp.old_execution_period__start_date and tcp.new_execution_period__end_date::date - tcp.old_execution_period__end_date::date > 0 then tcp.old_execution_period__end_date else null end "Дата Ð¾ÐºÐ¾Ð½Ñ‡Ð°Ð½Ð¸Ñ ÐºÐ¾Ð½Ñ‚Ñ€Ð°ÐºÑ‚Ð° ДО изменнениÑ",
47 null "N Цена контракта ПОСЛЕ изменениÑ",
48 null "N Цена контракта ДО изменениÑ",
49 fn.placing_way__name "Тип процедуры закупки",
50 null "N Общее количеÑтво критериев оценки",
51 null "N Признак повторного запуÑка закупки",
52 null "N Индикатор Ð¸Ð·Ð¼ÐµÐ½ÐµÐ½Ð¸Ñ ÑƒÑловий контракта",
53 case when coalesce(fnc1.id, fnc2.id) is null then 0 else 1 end "Признак отмены закупки",
54 c.customer__inn "ИÐРзаказчика",
55 c.customer__kpp "КПП заказчика",
56 customer__legal_form__singular_name "Ð¡Ñ‚Ð°Ñ‚ÑƒÑ Ð¾Ñ€Ð³Ð°Ð½Ð¸Ð·Ð°Ñ†Ð¸Ð¸ заказчика",
57 customer__legal_form__code "Код ÑтатуÑа организации закачика",
58
59 coalesce(
60 supplier3.full_name, supplier3.short_name,
61 supplier4.full_name, supplier4.short_name,
62 supplier1.last_name || ' ' || supplier1.first_name || ' ' || supplier1.middle_name,
63 supplier2.last_name || ' ' || supplier2.first_name || ' ' || supplier2.middle_name
64 ) "Ðаименование поÑтавщика",
65 case when supplier1.id is not null then supplier1.register_in_rf_tax_bodies__inn
66 when supplier2.id is not null then supplier2.inn
67 when supplier3.id is not null then supplier3.register_in_rf_tax_bodies__inn
68 when supplier4.id is not null then supplier4.inn
69 else null
70 end "Уникальный номер поÑтавщика. ИÐР",
71 case when supplier3.id is not null then supplier3.register_in_rf_tax_bodies__kpp
72 when supplier4.id is not null then supplier4.kpp
73 else null
74 end "Уникальный номер поÑтавщика. КПП "
75
76from spider.contract c
77 join spider.nsi_organization org on org.reg_number = c.customer__reg_num
78 join test.tt_pcn_lot cc on cc.contractid = c.id
79 join spider.fcs_notification fn on fn.id = cc.notificationid
80 join spider.lot l on cc.lotid = l.id
81 join spider.fcs_protocol fp on fp.id = cc.protocolid
82 join spider.fcs_protocol_lot fpl on fpl.id = cc.protocol_lotid
83 left join spider.fcs_purchase_prolongation fpp on fpp.purchase_number = fp.purchase_number
84 left join test.tt_protocol_one po on po.protocol_lotid = cc.protocol_lotid
85 left join test.tt_protocol_fine_one pfo on pfo.protocol_lotid = cc.protocol_lotid
86 left join test.tt_contract_prolon tcp on tcp.reg_num = c.reg_num
87 left join spider.individual_person_foreign_state supplier1 on supplier1.contract_id = c.id
88 left join spider.individual_person_rf supplier2 on supplier2.contract_id = c.id
89 left join spider.legal_entity_foreign_state supplier3 on supplier3.contract_id = c.id
90 left join spider.legal_entity_rf supplier4 on supplier4.contract_id = c.id
91 left join spider.contract_procedure cp on cp.id = cc.contract_procid
92 left join spider.fcs_notification_cancel fnc1 on fnc1.purchase_number = fn.purchase_number
93 left join spider.fcs_notification_cancel_failure fnc2 on fnc2.purchase_number = fn.purchase_number;
94
95--Проверка
96select count(*) from test.tt_result