some additions
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
drop materialized view if exists elma.mv_line cascade;
|
||||
create materialized view elma.mv_line as (
|
||||
with status(status, status_id, probability_pc) as (VALUES
|
||||
('Закрыта неуспешно',7,0),('Закрыта успешно',6,100),('Договор подписан',5,100),('Договор на подписании',15,90),('Договор на согласовании',12,70),
|
||||
('Тестирование',8,50),('Отправлено ТКП',10,20),('Внутреннее согласование',37,10),('Проработка решения',4,10),('Сбор потребностей',1,0)
|
||||
)
|
||||
select siv.__id as siv_uid, siv.discount, siv.type as line_pricing_model_id--, siv.params
|
||||
,siv.hash as line_key, /*siv.user_description,*/ siv.is_actual as siv_is_actual
|
||||
,siv.version::int as line_version
|
||||
,a.index as agreement_version, GREATEST(siv.date_nop,d."_plannedDueDate")::date as dt_from, siv.date_end::date as dt_to
|
||||
,siv.is_easy as is_simple, siv.cnt as quantity -- maybe should mutliply
|
||||
, a.__id as agreement_uid, a.contract_uid, a.is_actual as agreement_is_actual, a.deal_uid
|
||||
,d."_plannedDueDate", d.__name as deal, d.__status_status as deal_status_id
|
||||
,c.__name as contract
|
||||
,s.probability_pc
|
||||
from elma.deals_services siv
|
||||
left outer join elma.additional_agreements a on (a.__id = ANY(siv.additional_agreement)) /*это только потому, что массив'*/
|
||||
left outer join elma.deals d on (d.__id = ANY(siv.deal))
|
||||
left outer join elma.aggrements c on (a.contract_uid = c.__id)
|
||||
left outer join status s on (d.__status_status=s.status_id)
|
||||
where siv.is_actual
|
||||
);
|
||||
CREATE UNIQUE INDEX UX_mv_line_id on elma.mv_line (siv_uid);
|
||||
CREATE INDEX IX_mv_line_m on elma.mv_line (line_key,dt_from,line_version,agreement_version,siv_uid);
|
||||
|
||||
drop materialized view if exists elma.mv_component cascade;
|
||||
create materialized view elma.mv_component as (
|
||||
select siv.__id as siv_uid
|
||||
,p.__id as component_uid
|
||||
,p.code, p.price, p.cnt as param_quantity, p.discount as param_discount, p.name as sku
|
||||
,p.price*p.cnt*(100-p.discount)/100 as cost
|
||||
from elma.deals_services siv
|
||||
join elma.service_parametrs p on (p.__id = ANY(siv.params))
|
||||
where siv.is_actual
|
||||
);
|
||||
CREATE UNIQUE INDEX UX_mv_component_id on elma.mv_component (component_uid);
|
||||
CREATE INDEX IX_mv_component_siv on elma.mv_component (siv_uid);
|
||||
--select * from elma.mv_component;
|
||||
|
||||
drop materialized view if exists elma.mv_dt cascade;
|
||||
create materialized view elma.mv_dt AS
|
||||
SELECT dd::date as dt
|
||||
, DATE_PART('days', DATE_TRUNC('month', dd) + '1 MONTH'::INTERVAL - '1 DAY'::INTERVAL) monthdays
|
||||
FROM generate_series(
|
||||
'2023-01-01'::timestamp
|
||||
,'2026-01-01'::timestamp
|
||||
,'1 day'::interval) dd;
|
||||
CREATE UNIQUE INDEX UX_mv_dt on elma.mv_dt(dt);
|
||||
Reference in New Issue
Block a user