Files
payg/contragent_rpt.cfm
T
2026-04-28 13:28:26 +03:00

482 lines
15 KiB
Plaintext

<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:silent silent="No">
<cffunction name="plain2HtmClean">
<cfargument name="s" type="string"/>
<cfreturn request.plain2htm(request.cleanHtm(s))/>
</cffunction>
<cffunction name="cleanInput">
<cfargument name="s" type="string"/>
<cfreturn htmlEditFormat(s)/>
</cffunction>
<m:prepare_detail entity="contragent" accessObject="" key="__id" pageInfoOut="pageInfo"/>
<d:bean readonly=true table="elma.companies" datasource="#request.DS#" output="d" status="status">
<d:param field="__id" type="uuid" key/>
<d:param field="__name" type="varchar" size="255" preprocessor=#cleanInput# forNull=""/>
<d:param field="_inn" type="varchar" size="255" preprocessor=#cleanInput# forNull=""/>
<d:param field="_kpp" type="varchar" size="255" preprocessor=#cleanInput# forNull=""/>
<d:param field="id_klienta" type="varchar" size="255" preprocessor=#cleanInput# forNull=""/>
<!--- *** билдер показывает... <d:param field="wz_id" type="varchar" size="255" preprocessor=#cleanInput# forNull=""/> --->
<!--- <d:param field="code_inn" type="varchar" size="255" preprocessor=#cleanInput# forNull=""/>
<d:param field="code_kpp" type="varchar" size="255" preprocessor=#cleanInput# forNull=""/> --->
</d:bean>
<m:dispatch_detail
usePRG="No"<!---*** --->
pageInfo=#pageInfo#
id="#d.__id#"
status=#pageInfo.status#
trackOut="tr"
idAttributesOut="id"
/>
<!--- decoration --->
<!--- <cfquery name="qDecoration" datasource="#request.DS#">
select
a.login as creator, a.shortname as creator_shortname, m.login as updater, m.shortname as updater_shortname
from contragent g
left outer join usr a on (g.creator_id=a.usr_id)
left outer join usr m on (g.updater_id=m.usr_id)
where g.contragent_id=<cfqueryparam attributeCollection=#id#/>
</cfquery> --->
</m:silent><!---
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
---><layout:page section="header" pageInfo=#pageInfo#>
<layout:attribute name="title">
<cfoutput>
Отчет по контрагенту
<cfif len(d.__id)>
<b>#d.__name#</b>
[#d.__id#]
</cfif>
</cfoutput>
</layout:attribute>
</layout:page>
<!--- <cfif status.errorState GT 0>
<cfoutput><div class="err">#status.errorMessage#</div></cfoutput>
</cfif>
--->
<cfoutput>
<input type="hidden" name="__id" value="#d.__id#"/>
<input type="hidden" name="track" value="#tr.self#"/>
<input type="hidden" name="pass" value=""/><!--- pass marker to prevent save on submit --->
<div class="detail">
<div class="tr">
<div class="th">ID</div>
<div class="td">#d.__id#</div>
</div>
<div class="tr">
<div class="th">Контрагент</div>
<div class="td">#d.__name# <a href="contragent.cfm?__id=#d.__id#&#tr.fwx#">подробнее (из Элмы)...</a></div>
</div>
<div class="tr">
<div class="th">ИНН</div>
<div class="td">#d._inn#</div>
</div>
<div class="tr">
<div class="th">КПП</div>
<div class="td">#d._kpp#</div>
</div>
<div class="tr">
<div class="th">WZ</div>
<div class="td">#d.id_klienta#</div>
</div>
</div>
</cfoutput>
<layout:page section="extension" closeForm="Yes"/>
<cfif len(d.__id)>
<cfquery name="qService">
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_expanded
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
,siv.modifier_code
,siv.abstractive_service_code
,siv.__index AS siv_index
,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
,s.probability_pc
,a.__id AS additional_agreement_uid
,a.contract_uid
,a.is_actual AS additional_agreement_is_actual
,a.deal_uid
,a.__name AS additional_agreement
,d.__name AS deal
,d.__status_status AS deal_status_id
,siv.user_description --
,siv.params
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 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 s.probability_pc >= 50
--and a.is_actual *** возможно схема версионности противоречива
AND siv.type IN (2, 3)
AND d._companies = <cfqueryparam cfsqltype="cf_sql_other" value=#d.__id#/><!--- '019503f2-5774-7768-b5c9-566a71daedaa' --->
)
,component
AS (
SELECT cnt
,code
,__id
,price
,ed_izm
,discount
,name
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
,COALESCE((
LEAD(dt_from) OVER (
PARTITION BY line_key ORDER BY dt_from
,deal_index
)
), (
SELECT CURRENT_TIMESTAMP + INTERVAL '1 day'
)) dt_next
FROM line_expanded
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 )
)
SELECT d.siv_uid::text as siv_uid
,d.siv_index
,d.deal
,d.user_description
,d.discount
,d.cnt
,d.modifier_code
,d.abstractive_service_code
,d.additional_agreement_is_actual
,d.line_pricing_model_id
,d.line_key
,d.deal_index
,d.dt_from
,d.dt_to
,d.dt_next
,d.is_simple
,d.additional_agreement_uid::text as additional_agreement_uid
,d.additional_agreement
,d.deal_index
,d.deal_uid::text as deal_uid
,s.probability_pc
,s.status_id
,s.STATUS
,p.price
,p.cnt as p_cnt
,p.ed_izm
,p.code
,p.discount as p_discount
,p.__id::text as p_uid
,p.name
FROM stair d
JOIN status s ON (d.deal_status_id = s.status_id)
LEFT JOIN LATERAL unnest(d.params) AS arr(param_id) ON TRUE
JOIN component p ON (p.__id = arr.param_id)
WHERE d.dt_from <= CURRENT_TIMESTAMP AND (CURRENT_TIMESTAMP < d.dt_next)
</cfquery>
<!--- <cfdump var=#qService#/> --->
<cfoutput>
<h3>Услуги по данным CRM (версии строк спецификации, только актуальные на сегодня, сделки с вероятностью от 50% (начиная с тестирования) <!--- (#qService.recordCount#) ---></h3>
</cfoutput>
<table class="worktable">
<thead>
<tr>
<th width="3%">__index</th>
<th width="5%">Код</th>
<th width="20%">Пользовательское наименование</th>
<th width="30%">Компоненты</th>
<th width="3%">Кол-во</th>
<th width="5%">Сумма</th>
<th width="3%">Модель оплаты</th>
<th width="5%">Дата НОУ</th>
<th width="5%">date_end</th>
<th width="5%">Вер.%</th>
<th width="10%">Дополнительное соглашение</th>
<th width="5%">Ключ строки</th>
</tr>
</thead>
<cfoutput query="qService" group="siv_uid">
<tr<cfif NOT left(abstractive_service_code,4) EQ "iaas"> class="gray"</cfif>>
<td class="c"><a href="deal_service.cfm?__id=#siv_uid#&#tr.fwx#">#siv_index#</a></td>
<td class="l">#abstractive_service_code#<cfif len(modifier_code)>.#modifier_code#</cfif></td>
<td class="l">#user_description#</td>
<td style="padding:0; vertical-align:bottom;">
<table class="wide" style="height:100%">
<cfset cost=0/>
<cfoutput group="p_uid">
<cfif p_cnt NEQ 0>
<tr>
<td class="nw">#code#</td>
<td>#name#</td>
<td class="r">#p_cnt#</td>
<td class="c">#ed_izm#</td>
<td class="r">#nFmt(price*p_cnt*(100-(isNumeric(p_discount)?p_discount:0))/100, 2)#</td>
</tr>
<cfset cost+=price*p_cnt*(100-(isNumeric(p_discount)?p_discount:0))/100 />
</cfif>
</cfoutput>
</table>
</td>
<td class="c">#cnt#</td>
<td class="r">#nFmt(cost*cnt*(100-(isNumeric(discount)?discount:0))/100)#</td>
<td class="c">
<cfswitch expression=#line_pricing_model_id#>
<cfcase value=1>install</cfcase>
<cfcase value=2>fix</cfcase>
<cfcase value=3>payg</cfcase>
</cfswitch> (#line_pricing_model_id#)
</td>
<!--- <td class="c">#is_actual#</td>
<td class="c">#__index#</td> --->
<td class="c">#dateFormat(dt_from,'YYYY-MM-DD')#</td>
<td class="c<cfif isDate(dt_to) AND dt_to LT Now()> err</cfif>">#dateFormat(dt_to,'YYYY-MM-DD')#</td>
<td class="c">#probability_pc#</td>
<td class="c"><a href="additional_agreement.cfm?__id=#additional_agreement_uid#&#tr.fwx#">#additional_agreement#</a> (#status_id# #status#)</td>
<td class="c">#line_key#</td>
</tr>
</cfoutput>
</table>
<!--- <i>отображаются позиции сделок, начиная с тестирования</i> --->
<cfquery name="qCompute">
select
c."Organization_UUID"::text
,c."Organization"
,c."VDC"
,c."VDC_CPU_Reserv"
,"Cluster"
, 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
, round(avg(c."VDC_CPU_Speed")::numeric,1) as ghz
FROM vmreports.compute c
WHERE ts=(select max(ts) from vmreports.compute)
AND lower(c."WZ")=lower(<cfqueryparam cfsqltype="cf_sql_varchar" value="#d.id_klienta#"/>)
GROUP BY c."Organization_UUID", c."Organization", c."VDC", c."VDC_CPU_Reserv", c."Cluster"
</cfquery>
<cfquery name="qCompute_total" dbtype="query">
select
sum(ram) as ram
,sum(ram_on) as ram_on
,sum(cpu) as cpu
,sum(cpu_on) as cpu_on
FROM qCompute
</cfquery>
<h3>Compute факт</h3>
<table class="worktable">
<thead>
<tr>
<th width="10%">Организация</th>
<th width="10%">VDC</th>
<th width="3%">Резерв %</th>
<th width="10%">Кластер</th>
<th width="3%">GHz</th>
<th width="5%">CPU cores</th>
<th width="5%">CPU_ON cores</th>
<th width="5%">RAM GB</th>
<th width="5%">RAM_ON GB</th>
</tr>
</thead>
<cfoutput query="qCompute">
<tr>
<td>#Organization#</td>
<td>#VDC#</td>
<td class="c">#VDC_CPU_Reserv#</td>
<td>#qCompute.Cluster#</td>
<td class="c">#ghz#</td>
<td class="r">#cpu#</td>
<td class="r">#cpu_on#</td>
<td class="r">#ram#</td>
<td class="r">#ram_on#</td>
</tr>
</cfoutput>
<cfoutput query="qCompute_total">
<tr>
<td colspan="5" class="r b">Итого:</td>
<td class="r b">#cpu#</td>
<td class="r b">#cpu_on#</td>
<td class="r b">#ram#</td>
<td class="r b">#ram_on#</td>
</tr>
</cfoutput>
</table>
<cfquery name="qStorage">
select
"Organization_UUID"::text
,"Organization"
,"VDC"
,"Cluster"
,"Storage_Policy"
, round(sum(c."Disk_Allocated")) as disk_alloc
, round(sum(c."Disk_Used")) as disk_used
FROM vmreports.storage c
WHERE ts=(select max(ts) from vmreports.storage)
AND lower(c."WZ")=lower(<cfqueryparam cfsqltype="cf_sql_varchar" value="#d.id_klienta#"/>)
GROUP BY c."Organization_UUID",c."Organization",c."VDC",c."Cluster",c."Storage_Policy"
</cfquery>
<cfquery name="qStorage_total" dbtype="query">
select
sum(disk_alloc) as disk_alloc
,sum(disk_used) as disk_used
FROM qStorage
</cfquery>
<h3>Storage факт</h3>
<table class="worktable">
<thead>
<tr>
<th width="10%">Организация</th>
<!--- <th width="10%">Статус организации</th> --->
<th width="10%">VDC</th>
<th width="10%">Кластер</th>
<th width="10%">Политика хранения</th>
<th width="5%">Выделено GB</th>
<th width="5%">Используется GB</th>
</tr>
</thead>
<cfoutput query="qStorage">
<tr>
<td>#Organization#</td>
<td>#VDC#</td>
<td>#qCompute.Cluster#</td>
<td>#Storage_Policy#</td>
<td class="r">#disk_alloc#</td>
<td class="r">#disk_used#</td>
</tr>
</cfoutput>
<cfoutput query="qStorage_total">
<tr>
<td colspan="4" class="r b">Итого:</td>
<td class="r b">#disk_alloc#</td>
<td class="r b">#disk_used#</td>
</tr>
</cfoutput>
</table>
<cfquery name="qGpu">
select
"Object_UUID"::text
,"Org"
,"OrgStatus"
,"OrgVDC"
,(select STRING_AGG(DISTINCT "Cluster",',') FROM vmreports.compute c
WHERE ts=(select max(ts) from vmreports.compute)
AND g."Org"=c."Organization") as org_cluster
,"Name"
,"GPU"
FROM vmreports.vm_gpu g
WHERE ts=(select max(ts) from vmreports.vm_gpu)
AND lower(g."ClientID")=lower(<cfqueryparam cfsqltype="cf_sql_varchar" value="#d.id_klienta#"/>)
</cfquery>
<h3>GPU факт</h3>
<table class="worktable">
<thead>
<tr>
<th width="10%">Организация</th>
<th width="10%">Статус организации</th>
<th width="10%">VDC</th>
<th width="10%">Кластер</th>
<th width="10%">VM</th>
<th width="5%">GPU</th>
</tr>
</thead>
<cfoutput query="qGpu">
<tr>
<td>#Org#</td>
<td>#OrgStatus#</td>
<td>#OrgVDC#</td>
<td>#org_cluster#</td>
<td>#Name#</td>
<td>#GPU#</td>
</tr>
</cfoutput>
</table>
<!--- ----------------------------------------------------------------- --->
<!--- ----------------------------------------------------------------- --->
<!--- ----------------------------------------------------------------- --->
<!--- <cfdump var=#qCompute#/>
<cfdump var=#qStorage#/> --->
</cfif><!--- len(d.__id) --->
<br/><br/>
добавить реестр GPU и VDC для поиска потеряшек
<layout:page section="footer"/>