@@ -536,4 +538,32 @@
-
\ No newline at end of file
+
+
+
+string function gaussianRoundSafe(any num, numeric precision = 0, string default="") {
+ return (isNumeric(arguments.num)) ? gaussianRound(arguments.num, arguments.precision) : arguments.default;
+}
+
+function gaussianRound(numeric number, numeric precision = 0) {
+ var factor = 10 ^ precision;
+ var scaledNumber = number * factor;
+ var absScaled = abs(scaledNumber);
+ var sign = sgn(scaledNumber);
+ var floored = int(absScaled);
+
+ // If it's not ending in exactly .5, use standard rounding or precision scaling
+ if (absScaled - floored != 0.5) {
+ return round(number * factor) / factor;
+ }
+
+ // If it is exactly .5, round towards the nearest even number
+ if (floored % 2 != 0) {
+ // Nearest even is UP
+ return (floored + 1) * sign / factor;
+ } else {
+ // Nearest even is DOWN
+ return floored * sign / factor;
+ }
+}
+
\ No newline at end of file
diff --git a/payg.cfm b/payg.cfm
index 8606176..9ebfc4e 100644
--- a/payg.cfm
+++ b/payg.cfm
@@ -7,27 +7,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ --->и
-
-
-
-
-
-
-
- --->
-
-
-
-
-
select distinct p.code
@@ -64,11 +71,13 @@
AS (VALUES
('Закрыта неуспешно',7,0),('Закрыта успешно',6,100),('Договор подписан',5,100),('Договор на подписании',15,90),('Договор на согласовании',12,70),
('Тестирование',8,50),('Отправлено ТКП',10,20),('Внутреннее согласование',37,10),('Проработка решения',4,10),('Сбор потребностей',1,0)
- )
- select upper(trim(k.id_klienta)) as wz,
+ ),
+ line as (
+ select
+ upper(trim(k.id_klienta)) as wz,
k.__id::text as contragent_uid,
p.code,
- SUBSTRING(p.code FROM 1 FOR LENGTH(p.code) - 2) as sku_code,
+ SUBSTRING(p.code FROM 1 FOR LENGTH(p.code) - 2) as sku_code, --оказывается, есть ошибки в данных, когда суффикс потерян, на этот случай надо парсить код
p.price,
p.discount as component_discount,
k.__name as contragent,
@@ -76,6 +85,7 @@
a.__id::text as contract_uid,
d.__name as deal,
d.__id::text as deal_uid,
+ d.__index AS deal_index,
siv.abstractive_service as abstract_service,
siv.modifier, siv.user_description,
siv.hash as line_key
@@ -83,30 +93,24 @@
siv.date_end as serviceEnd,
siv.discount as service_discount,
siv.cnt as service_quantity
- /*,p.__name as line_key*/, p.ed_izm, p.name as component, p.type, p.cnt*coalesce(siv.cnt,1) as component_quantity,
+ , p.ed_izm, p.name as component, p.type, p.cnt*coalesce(siv.cnt,1) as component_quantity,
aa.__name as additional_agreement, aa.__id::text as additional_agreement_uid
- --, aa.is_actual
,siv.end_customer::text as end_customer_uid
,z.id_klienta as end_customer_wz
,z.__name as end_customer_name
- --,ft.free_tier
,s.probability_pc
,siv.__id::text as siv_uid
- ,coalesce(siv.cnt*(100.-siv.discount)/100.*p.price*(100.-p.discount)/100., 0.) as discounted_price
+ ,CASE WHEN p.type=3 THEN coalesce(siv.cnt*(100.-siv.discount)/100.*p.price*(100.-p.discount)/100., 0.) ELSE NULL END as discounted_price
from elma.deals d
JOIN STATUS s ON (d.__status_status = s.status_id)
join elma.deals_services siv on (d.__id=ANY(siv.deal))
- --join elma.service_parametrs p on (p.__id = ANY(siv.params))
LEFT JOIN LATERAL unnest(siv.params) AS arr(param_id) ON TRUE
JOIN elma.service_parametrs p ON (p.__id = arr.param_id)
join elma.companies k on (d._companies=k.__id)
join elma.additional_agreements aa on (aa.__id = ANY(siv.additional_agreement))
join elma.aggrements a on (aa.contract_uid = a.__id)
- left outer join elma.companies z on (siv.end_customer=z.__id)
-
- where p.type IN (2,3) AND aa.is_actual
- AND siv.date_nop <
- AND (siv.date_end > OR siv.date_end IS NULL)/*****/
+ LEFT OUTER JOIN elma.companies z on (siv.end_customer=z.__id)
+ WHERE p.type IN (2,3) AND aa.is_actual
AND aa."__deletedAt" IS NULL
AND a."__deletedAt" IS NULL
AND d."__deletedAt" IS NULL
@@ -119,19 +123,42 @@
AND p.code like
-
+
AND p.type=3
- --AND k.id_klienta='WZ01031'
- --AND k.id_klienta='WZ01112'
- order by k.id_klienta, p.code
+ ),
+ stair
+ AS (
+ SELECT *
+ FROM (
+ SELECT *
+ ,MIN(serviceStart) OVER (
+ PARTITION BY line_key ORDER BY deal_index DESC
+ ) running_min_dt
+ ,COALESCE((
+ LEAD(serviceStart) OVER (
+ PARTITION BY line_key ORDER BY serviceStart
+ ,deal_index
+ )
+ ), (
+ SELECT CURRENT_TIMESTAMP + INTERVAL '1 day' --*** not sure
+ )) dt_next
+ FROM line
+ WHERE probability_pc = 100
+ ) t
+ WHERE t.serviceStart = t.running_min_dt
+ )
+ select d.* from stair d
+ WHERE d.serviceStart <
+ AND (d.serviceEnd > OR d.serviceEnd IS NULL)
+ order by wz, type DESC, code
qSpec:#getTickCount()-request.startTickCount#
-
+
@@ -180,7 +207,7 @@ select * from elma.deals_services where __id='019edf9c-c23d-7ad6-a990-643dd09579
qComputing:#getTickCount()-request.startTickCount#
-
+
@@ -237,7 +264,7 @@ select * from elma.deals_services where __id='019edf9c-c23d-7ad6-a990-643dd09579
qStorage:#getTickCount()-request.startTickCount#
-
+
@@ -280,7 +307,7 @@ HOT_FREE_LIMIT 1 10 1 100
qS3Vol:#getTickCount()-request.startTickCount#
-
+
@@ -351,7 +378,7 @@ select
qS3OpsTrf:#getTickCount()-request.startTickCount#
-
+
@@ -376,7 +403,7 @@ select
qS3User:#getTickCount()-request.startTickCount#
-
+
@@ -416,7 +443,7 @@ select
qGpu:#getTickCount()-request.startTickCount#
-
+
@@ -502,7 +529,7 @@ select
qUnifiedMetric:#getTickCount()-request.startTickCount#
-
+
@@ -647,7 +674,7 @@ SELECT
FROM metric m
-
+
INNER
FULL
@@ -680,7 +707,7 @@ ORDER BY coalesce(coalesce(c.wz, m.wz), s.wz), coalesce(s.code, m.code)
qCharge:#getTickCount()-request.startTickCount#
-
+
@@ -711,18 +738,18 @@ ORDER BY coalesce(coalesce(c.wz, m.wz), s.wz), coalesce(s.code, m.code)
Даты актуальности пока проверять вручную. Обращать внимание на замножение строк.
-/>
- checked/>
+ checked/>
+ checked/>
WZ по вхождению, с регистром
Код по вхождению
-
-
+
+
Часов в периоде: #hours# Строк в отчете: #qCharge.recordCount#
Актуальность данных:
@@ -735,9 +762,9 @@ S3 операции и трафик: --->
-
+
-
+(перед выгрузкой отчета на произвольную дату или с параметрами сначала просмотрите его в браузере) серая строка - нет метрик; красное число в поле "Кол-во специф." - для PAYG в спецификации кол-во не 1
@@ -883,7 +910,7 @@ S3 операции и трафик: #current_price#