Files
payg/crm2cloud.cfm
T

273 lines
11 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<cfsilent>
<cfimport prefix="m" taglib="lib"/>
<cfimport prefix="c" taglib="lib/controls"/>
<cfimport prefix="d" taglib="lib/data"/>
<cfimport prefix="layout" taglib="layout"/>
</cfsilent>
<m:prepare_ls entity="crm2cloud" accessObject="" pageInfoOut="pageInfo" trackOut="tr"/>
<cfquery name="qReconciliation">
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)
),
line as (
SELECT siv.__id as siv_uid, siv.discount, siv.type as line_pricing_model_id
,siv.hash as line_key, siv.is_actual as siv_is_actual
,siv.version::numeric as line_version
,d.__index as deal_index
,d._companies
,a.index as agreement_version
,siv.date_nop::date as dt_from
,siv.date_end::date as dt_to
,siv.is_easy as is_simple
,siv.cnt -- should mutiliply
,s.probability_pc
,a.__id as agreement_uid, a.contract_uid, a.is_actual as agreement_is_actual, a.deal_uid
,d.__name as deal, d.__status_status as deal_status_id
--,c.__name as contract
,siv.user_description
,siv.params
--,(SELECT sum(p.price*p.cnt*(100.0-COALESCE(p.discount,0.0))/100.0) FROM elma.service_parametrs p WHERE(p.__id = ANY (siv.params))) as cost
FROM elma.deals_services siv
JOIN elma.deals d on (d.__id = ANY(siv.deal))
JOIN status s on (d.__status_status=s.status_id)
LEFT OUTER JOIN elma.additional_agreements a on (a.__id = ANY(siv.additional_agreement))
WHERE siv.is_actual AND siv."__deletedAt" IS NULL AND d."__deletedAt" IS NULL AND a."__deletedAt" IS NULL
AND a.is_actual
AND siv.type IN (2,3)
),
component as (
SELECT
price*cnt*(100.0-COALESCE(discount,0))/100.0 as cost
,price
,cnt
,code
,__id
FROM elma.service_parametrs
where "__deletedAt" IS NULL
),
stair as ( -- рабочая лесенка (инстансы строк, имеющие нетривиальную вероятность)
select * FROM (
SELECT *,
MIN(dt_from) OVER (PARTITION BY line_key ORDER BY deal_index desc) running_min_dt
FROM line --WHERE probability_pc > 0
) t
WHERE t.dt_from = t.running_min_dt
AND t.dt_to > CURRENT_TIMESTAMP OR t.dt_to IS NULL
),
alloc as (select c."WZ" as wz
, round(sum(c."VM_RAM_Allocated")) as ram
, round(sum(CASE WHEN "VM_is_ON" > 0 THEN c."VM_RAM_Allocated" ELSE 0 END)) as ram_on
, round(sum(c."VM_vCPU_count")) as cpu
, round(sum(CASE WHEN "VM_is_ON" > 0 THEN c."VM_vCPU_count" ELSE 0 END)) as cpu_on
from vmreports.compute c
where ts=(select max(ts) from vmreports.compute)
group by c."WZ"
),
disk_alloc as (select c."WZ" as wz
, round(sum(c."Disk_Allocated")) as disk_alloc
from vmreports.storage c
where ts=(select max(ts) from vmreports.storage)
group by c."WZ"
),
sold_ram as (SELECT
z.id_klienta as WZ, z.__name as client, z.__id as company_uid, round(sum(c.cnt*o.cnt)) as quantity
,count(*) as lines, STRING_AGG(c.code,', ') as codes
/*,o.line_key, o.probability_pc, dt_next, o.deal_uid, o.deal, o.agreement_uid, o.line_pricing_model_id,o.dt_from, o.dt_to*/
FROM stair o
JOIN elma.companies z on (o._companies=z.__id)
LEFT OUTER JOIN component c on (c.__id = ANY (o.params))
WHERE c.code LIKE 'iaas.ngc.%.ram-_'
GROUP BY z.id_klienta, z.__id, z.__name
),
sold_cpu as (SELECT
z.id_klienta as WZ, z.__name as client, z.__id as company_uid, round(sum(c.cnt*o.cnt)) as quantity
,count(*) as lines, STRING_AGG(c.code,', ') as codes
/*,o.line_key, o.probability_pc, dt_next, o.deal_uid, o.deal, o.agreement_uid, o.line_pricing_model_id,o.dt_from, o.dt_to*/
FROM stair o
JOIN elma.companies z on (o._companies=z.__id)
LEFT OUTER JOIN component c on (c.__id = ANY (o.params))
WHERE c.code LIKE 'iaas.ngc.%.vcpu%-_'
GROUP BY z.id_klienta, z.__id, z.__name
),
sold_disk as (SELECT
z.id_klienta as WZ, z.__name as client, z.__id as company_uid, round(sum(c.cnt*o.cnt)) as quantity
,count(*) as lines, STRING_AGG(c.code,', ') as codes
/*,o.line_key, o.probability_pc, dt_next, o.deal_uid, o.deal, o.agreement_uid, o.line_pricing_model_id,o.dt_from, o.dt_to*/
FROM stair o
JOIN elma.companies z on (o._companies=z.__id)
LEFT OUTER JOIN component c on (c.__id = ANY (o.params))
WHERE c.code SIMILAR TO 'iaas.ngc.%.(ssd|fstssd|sata)-_'
GROUP BY z.id_klienta, z.__id, z.__name
),
deal_stat as (
select STRING_AGG(distinct deal_status_id::text,', ') as status_ids
, z.id_klienta as WZ
from line o join elma.companies z on (o._companies=z.__id)
GROUP BY z.id_klienta
)
select
<d:field_set titleMapOut="titleMap" lengthOut="fieldCount">
<d:field title="WZ Elma">r.wz as wz_sold</d:field>
<d:field title="Клиент">r.client as client_sold</d:field>
<d:field>r.company_uid</d:field>
<d:field title="WZ Cloud">a.wz as wz_alloc</d:field>
<d:field title="Статусы">ds.status_ids</d:field>
<d:field title="Коды RAM">r.codes as ram_codes</d:field>
<d:field title="RAM GB Elma">r.quantity as ram_sold</d:field>
<d:field title="RAM Cloud">a.ram as ram_alloc</d:field>
<d:field title="RAM Cloud ON">a.ram_on as ram_alloc_on</d:field>
<d:field title="Коды CPU">c.codes as cpu_codes</d:field>
<d:field title="CPU Elma">c.quantity as cpu_sold</d:field>
<d:field title="CPU Cloud">a.cpu as cpu_alloc</d:field>
<d:field title="CPU Cloud ON">a.cpu_on as cpu_alloc_on</d:field>
<d:field title="Коды Дисков">d.quantity as disk_sold</d:field>
<d:field title="Диски GB Elma">da.disk_alloc</d:field>
<d:field title="Диски Cloud">d.codes as disk_codes</d:field>
</d:field_set>
from sold_ram r
join deal_stat ds on (r.wz=ds.wz)
join sold_cpu c on (r.wz=c.wz)
left join sold_disk d on (r.wz=d.wz)
full join alloc a on (r.wz=a.wz)
left join disk_alloc da on (a.wz=da.wz)
order by 1,3
</cfquery>
<!--- QoQ does not support join syntax, at least of Lucee 5.4--->
<cfif isDefined("output_xls")>
<layout:xml qRead=#qReconciliation# titleMap=#titleMap# filename="#pageInfo.entity#.xml"/>
<cfabort/>
</cfif><cfif isDefined("output_json")>
<layout:json qRead=#qReconciliation# titleMap=#titleMap# filename="#pageInfo.entity#.json"/>
<cfabort/>
</cfif><!---
---><layout:page section="header" pageInfo=#pageInfo#>
<layout:attribute name="title">
<cfoutput><b>Сверка CRM - Cloud</b></cfoutput>
</layout:attribute>
<layout:attribute name="controls">
<!---skip filter link, filter is not implemented--->
<!---<layout:language_switch/>--->
</layout:attribute>
</layout:page>
<!--- <cfdump var=#qReconciliation# abort=true/> --->
<cfoutput>
<!--- <form method="post" action="">
Период с <input type="text" name="dt_start" value="#dateFormat(dt_start,'YYYY-MM-DD')#"/>
по <input type="text" name="dt_finish" value="#dateFormat(dt_finish,'YYYY-MM-DD')#"/>
<input type="submit" style="cursor:pointer;"/>
<input type="submit" name="DEBUG" value="DEBUG" style="cursor:pointer;"/>
</form> --->
<!--- Часов в периоде: <b>#hours#</b> Строк в отчете: <b>#qCharge.recordCount#</b><br/>
Актуальность данных:
VCD Computing: <b>#dateFormat(qComputingAge.dt_load,'YYYY-MM-DD')# #timeFormat(qComputingAge.dt_load,'HH:MM:SS')#</b>
VCD Storage: <b>#dateFormat(qStorageAge.dt_load,'YYYY-MM-DD')# #timeFormat(qStorageAge.dt_load,'HH:MM:SS')#</b>
S3 хранение: <b>#dateFormat(qS3VolAge.dt_load,'YYYY-MM-DD')# #timeFormat(qS3VolAge.dt_load,'HH:MM:SS')#</b>
S3 операции и трафик: <b>#dateFormat(qS3OpsTrfAge.dt_load,'YYYY-MM-DD')# #timeFormat(qS3OpsTrfAge.dt_load,'HH:MM:SS')#</b>
--->
<br/>
<a href="#request.thisPage#?output_xls" title="экспорт в Excel" style="margin-left:.5em; height:100%;" target="_blank"><img src="img/xls.gif" style="vertical-align:text-bottom;"/></a>
<a href="#request.thisPage#?output_json" title="экспорт в json" style="margin-left:.5em; height:100%;" target="_blank"><img src="img/json.svg" style="vertical-align:text-bottom;" width="13" height="13"/></a>
</cfoutput>
<table class="worktable">
<thead>
<layout:grid_head titleMap=#titleMap# sortArray=#pageInfo.settings.sort.sortArray#>
<th width="7%"><layout:column_head name="wz_sold"/></th>
<th width="10%"><layout:column_head name="client_sold"/></th>
<th width="7%"><layout:column_head name="wz_alloc"/></th>
<th width="3%"><layout:column_head name="status_ids"/></th>
<th width="15%"><layout:column_head name="ram_codes"/></th>
<th width="3%"><layout:column_head name="ram_sold"/></th>
<th width="3%"><layout:column_head name="ram_alloc"/></th>
<th width="3%"><layout:column_head name="ram_alloc_on"/></th>
<th width="15%"><layout:column_head name="cpu_codes"/></th>
<th width="3%"><layout:column_head name="cpu_sold"/></th>
<th width="3%"><layout:column_head name="cpu_alloc"/></th>
<th width="3%"><layout:column_head name="cpu_alloc_on"/></th>
<th width="15%"><layout:column_head name="disk_codes"/></th>
<th width="3%"><layout:column_head name="disk_sold"/></th>
<th width="3%"><layout:column_head name="disk_alloc"/></th>
</layout:grid_head>
</thead>
<cfflush/>
<cfoutput query="qReconciliation">
<tr>
<td>#wz_sold#</td>
<td><a href="contragent.cfm?__id=#company_uid#&#tr.fwx#">#client_sold#</a></td>
<td>#wz_alloc#</td>
<td>#status_ids#</td>
<td>#ram_codes#</td>
<td>#ram_sold#</td>
<td>#ram_alloc#</td>
<td>#ram_alloc_on#</td>
<td>#cpu_codes#</td>
<td>#cpu_sold#</td>
<td>#cpu_alloc#</td>
<td>#cpu_alloc_on#</td>
<td>#disk_codes#</td>
<td>#disk_sold#</td>
<td>#disk_alloc#</td>
</tr>
<!---
<td class="r" style="font-size:120%; padding:0 1em;">#chargeable_metric#</td>
<td class="c" style="font-size:90%;">#ed_izm#</td>
<td class="r">#discounted_price#</td>
<td class="r">#charge#</td>
<td></td>
<td>#abstract_service# #modifier#</td>
<td>#component#</td>
<td>#user_description#</td>
<td class="r">#price#</td>
<td class="r">#discount#</td>
<td class="r">#dateFormat(dt_from,'YYYY-MM-DD')#</td>
<td class="r">#dateFormat(dt_to,'YYYY-MM-DD')#</td>
<td class="r">#line_key#</td>
<td class="r" style="color:##bbb">#raw_metric#</td>
<td class="r">#metric#</td>
<td><a href="contract.cfm?__id=#contract_uid#&#tr.fwx#">#contract#</a></td>
<td><a href="additional_agreement.cfm?__id=#additional_agreement_uid#&#tr.fwx#">#additional_agreement#</a></td>
<td><a href="deal.cfm?__id=#deal_uid#&#tr.fwx#">#deal#</a></td>
</tr> --->
</cfoutput>
</table>
<!--- <cfdump var=#qCharge#/> --->
<layout:page section="footer"/>