Files
payg/contragent.cfm
T

539 lines
21 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: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"/>
<cfif isDefined("id_klienta") AND NOT isDefined("__id")>
<cfquery name="qResolveUid">
select __id::text as __id from elma.companies where id_klienta=<cfqueryparam cfsqltype="cf_sql_varchar" value="#id_klienta#"/>
</cfquery>
<cfif qResolveUid.recordCount>
<cfset __id=qResolveUid.__id/>
</cfif>
</cfif>
<!--- <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='"__createdAt"' type="timestamp"/>
<d:param field='"__updatedAt"' type="timestamp"/>
<d:param field='"__deletedAt"' type="timestamp"/>
</d:bean> --->
<!--- column ["__createdAt"] not found in query, columns are [__ID,__NAME,_INN,_KPP,ID_KLIENTA,__CREATEDAT,__UPDATEDAT,__DELETEDAT] --->
<cfparam name="__id" default=""/>
<cfquery name="d">
select
__id, __name, _inn, _kpp, id_klienta, "__createdAt","__updatedAt","__deletedAt"
from elma.companies
where __id=<cfqueryparam cfSqlType="cf_sql_other" value=#__id# null=#!isValid("guid",__id)#/>
</cfquery>
<!--- исторически сэкономил некоторые телодвижения, использовав bean. Но он не поддерживает имена колонок, чувствительные к регистру.
Теперь уже можно было бы и в один запрос все упаковать - все равно это форма ReadOnly --->
<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 c.__name as responsible, c.email as responsible_email, c.__status_status as responsible_status
from elma.companies g
LEFT OUTER JOIN elma.comp_users_ext c on (g.responsible=c.__id)
where g.__id=<cfqueryparam cfSqlType="cf_sql_other" value=#d.__id# null=#!isValid("guid",d.__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">__name</div>
<div class="td">#d.__name# <a href="contragent_rpt.cfm?__id=#d.__id#&#tr.fwx#">Сводка по потреблению</a></div>
</div>
<div class="tr">
<div class="th">_inn</div>
<div class="td">#d._inn#</div>
</div>
<div class="tr">
<div class="th">_kpp</div>
<div class="td">#d._kpp#</div>
</div>
<div class="tr">
<div class="th">id_klienta</div>
<div class="td">#d.id_klienta#</div>
</div>
<div class="tr">
<div class="th">Ответственный</div>
<div class="td<cfif qDecoration.responsible_status NEQ 2> err</cfif>">#qDecoration.responsible# <a href="mailto:#qDecoration.responsible_email#">#qDecoration.responsible_email#</a> статус:#qDecoration.responsible_status#<cfswitch expression=#qDecoration.responsible_status#><cfcase value="2"> (paботает)</cfcase><cfcase value="3"> (уволен)</cfcase></cfswitch></div>
</div>
<div class="tr">
<div class="th">Создан</div>
<div class="td">#dateFormat(d.__createdAt,"YYYY-MM-DD")#</div>
</div>
<div class="tr">
<div class="th">Изменен</div>
<div class="td">#dateFormat(d.__updatedAt,"YYYY-MM-DD")#</div>
</div>
<div class="tr">
<div class="th">Удален</div>
<div class="td">#dateFormat(d.__deletedAt,"YYYY-MM-DD")#</div>
</div>
</div>
</cfoutput>
<layout:page section="extension" closeForm="Yes"/>
<cfif len(d.__id)>
<a href="#agreements" class="i">Договоры, допники, сделки - внизу</a>
<!--- ----------------------------------------------------- --->
<!--- ----------------------------------------------------- --->
<!--- ----------------------------------------------------- --->
<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)
)
select
siv.__id
,siv.__name
,siv.user_description
,siv.discount
,siv.cnt
,siv.modifier_code
,siv.abstractive_service_code
,siv.is_actual
,siv.type
,siv.hash
,siv.version
,siv.name_version
,siv.date_accept
,siv.__index as siv_index
,siv.date_nop
,siv.date_end
,siv.is_easy
,siv.params::text
,a.__id::text as additional_agreement_uid
,a.__name as additional_agreement
,p.price
,p.cnt as p_cnt
,p.ed_izm
,p.code
,p.discount as p_discount
,p.__id as p_uid
,p.name
,s.probability_pc
,d.__index as deal_index
,d.__id as deal_uid
,siv.end_customer as end_customer_uid
,z.id_klienta as end_customer_wz
,z.__name as end_customer_name
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)
join elma.service_parametrs p ON (p.__id = ANY (siv.params) AND p."__deletedAt" IS NULL)
left outer join elma.companies z on (siv.end_customer=z.__id)
left outer join elma.additional_agreements a on (a.__id=ANY(siv.additional_agreement))
where d._companies=<cfqueryparam cfsqltype="cf_sql_other" value="#d.__id#" null=#!isValid("guid",d.__id)#/>
AND siv.is_actual
--AND a.is_actual
AND s.probability_pc > 0
order by d.__index, siv.__index, p.__id, version::int
</cfquery>
<cfoutput>
<h4>Услуги (версии строк спецификации, только актуальные) <!--- (#qService.recordCount#) ---></h4>
</cfoutput>
<!--- <layout:render_query query=#qService#/> --->
<table class="worktable">
<thead>
<tr>
<th>deal index</th>
<!--- <th>__name</th> --->
<th width="20%">user description</th>
<th width="25%">Компоненты</th>
<th>Кол-во</th>
<th>Скидка%</th>
<th width="5%">Сумма</th>
<th>Код</th>
<th>type</th>
<th>is actual</th>
<th>hash</th>
<th>version</th>
<th>name version</th>
<th>date accept</th>
<th>line version index</th>
<th width="5%">НОУ</th>
<th width="5%">КОУ</th>
<th>is easy</th>
<th width="2%">Вер.%</th>
<th width="10%">Дополнительное соглашение</th>
<th width="5%">Конечник</th>
</tr>
</thead>
<cfoutput query="qService" group="deal_index"> <!--- не оч понятно, какой из индексов брать --->
<tr>
<td class="c"><a href="deal_service.cfm?__id=#__id#&#tr.fwx#" title="__id">#deal_index#</a></td>
<!--- <td class="c">#__name#</td> --->
<td class="l">#user_description#</td>
<td>
<table class="wide">
<cfset cost=0/>
<cfoutput group="p_uid">
<cfif p_cnt NEQ 0>
<tr>
<td class="nw">#code#</td>
<td>#name#</td>
<td>#p_cnt#</td>
<td>#ed_izm#</td>
<td class="r nw">#nFmt(price,3)#</td>
<td class="r">#p_discount#%</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="c">#discount#%</td>
<td class="r">#nFmt(cost*cnt*(100-(isNumeric(discount)?discount:0))/100)#</td>
<td class="l">
#abstractive_service_code#.#modifier_code#<!--- <cfswitch expression=#type#>
<cfcase value=1>-i</cfcase>
<cfcase value=2>-f</cfcase>
<cfcase value=3>-m</cfcase>
</cfswitch> --->
</td>
<td class="c"<cfif type EQ 3> style="background:lightgreen"</cfif>>#type#</td>
<td class="c">#is_actual#</td>
<td class="c">#hash#</td>
<td class="c">#version#</td>
<td class="c">#name_version#</td>
<td class="c">#date_accept#</td>
<td class="c">#siv_index#</td>
<td class="c">#dateFormat(date_nop,'YYYY-MM-DD')#</td>
<td class="c<cfif isDate(date_end) AND date_end LT Now()> err</cfif>">#dateFormat(date_end,'YYYY-MM-DD')#</td>
<td class="c">#is_easy#</td>
<td class="c">#probability_pc#</td>
<!--- <td class="c">#additional_agreement_uid#</td> --->
<td class="c"><a href="additional_agreement.cfm?__id=#additional_agreement_uid#&#tr.fwx#">#additional_agreement#</a></td>
<td class="c"><a href="contragent.cfm?__id=#end_customer_uid#&#tr.fwx#" title="#replace(end_customer_name,'"','&quot;','ALL')#">#end_customer_wz#</a></td><!--- *** надо эскейпить кавычки в имени --->
</tr>
</cfoutput>
</table>
<!--- ----------------------------------------------------------------- --->
<!--- ----------------------------------------------------------------- --->
<!--- ----------------------------------------------------------------- --->
<cfquery name="qContract">
select
<d:field_set titleMapOut="titleMap" lengthOut="fieldCount">
<d:field title="ID" cfSqlType="CF_SQL_OTHER">d.__id</d:field>
<d:field title="Внут.номер">d.agreement_id</d:field>
<d:field title="Договор">d.__name</d:field>
<d:field title="company_uid">d.company_uid</d:field>
<d:field title="Дата договора">d.date_of_aggrement</d:field>
<d:field title="Дата окончания">d.date_end_aggrement</d:field>
<d:field title="Тип договора">d.type_of_agreement</d:field>
<d:field title="__index">d.__index</d:field>
</d:field_set>
from elma.aggrements d
where d.company_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#d.__id#" null=#!isValid('guid',d.__id)#/>
</cfquery>
<cfoutput>
<h4><a name="agreements">Договоры</a> (#qContract.recordCount#)</h4>
</cfoutput>
<table class="worktable">
<thead>
<tr>
<th>__id</th>
<th>Номер</th>
<th>Внут. номер</th>
<th>Дата</th>
<th>Дата оконч.</th>
<th>Тип договора</th>
</tr>
</thead>
<cfoutput query="qContract">
<tr>
<td><a href="contract.cfm?__id=#__id#&#tr.fwx#">#__id#</a></td>
<td>#__name#</td>
<td>#agreement_id#</td>
<td>#dateFormat(date_of_aggrement,"YYYY-MM-DD")#</td>
<td>#dateFormat(date_end_aggrement,"YYYY-MM-DD")#</td>
<td class="c">#type_of_agreement#</td>
</tr>
</cfoutput>
</table>
<cfquery name="qAdditionalAgreement">
with
s(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)
),
component as (select siv.deal as deal_uids, siv.type, (siv.cnt*(100-COALESCE(siv.discount,0))/100*p.price*p.cnt*(100-COALESCE(p.discount,0))) as param_cost
from elma.deals_services siv
join elma.service_parametrs p on (p.__id = ANY(siv.params))
where p."__deletedAt" IS NULL AND siv."__deletedAt" IS NULL AND siv.is_actual
)
select
a.__id::text
,a.__name as additional_agreement
,a.__index
,a.contract_uid::text
,a.is_actual
,a.last_aa
,a.deal_uid::text
,c.__name as contract
,c.agreement_id
,c.date_of_aggrement
,d.__id as deal_uid
,d.__name as deal
,d.__status_status
,s.status
,s.probability_pc
,u.__name as owner
,(select sum(param_cost)
from component p
where d.__id = p.deal_uids[1] AND p.type IN (1)
) as install
,(select sum(param_cost)
from component p
where d.__id = p.deal_uids[1] AND p.type IN (2)
) as periodical
,(select sum(param_cost)
from component p
where d.__id = p.deal_uids[1] AND p.type IN (3)
) as metered
from elma.additional_agreements a
join elma.aggrements c on (a.contract_uid=c.__id)
join elma.deals d on (a.deal_uid=d.__id)
left outer join s on (d.__status_status=s.status_id)
left outer join elma.comp_users_ext u on (d._owner=c.__id)
where c.company_uid=<cfqueryparam cfsqltype="cf_sql_other" value=#d.__id# null=#!isValid("guid",d.__id)#/>
AND s.probability_pc > 0
order by a.__index
</cfquery>
<cfoutput>
<h4>Доп. соглашения (#qAdditionalAgreement.recordCount#)
- исключены соглашения, сделки которых имеют нулевую вероятность
</h4>
</cfoutput>
<table class="worktable">
<thead>
<tr>
<th>__id</th>
<th>__index</th>
<th>Доп. соглашение</th>
<th>Внут. н-р дог.</th>
<th>Дата договора</th>
<th>Сделка</th>
<th>Статус сделки</th>
<th>Вер-ть %</th>
<th>Ответственный</th>
<th>Инсталл</th>
<th>Ежемес</th>
<th>Тариф.</th>
</tr>
</thead>
<cfoutput query="qAdditionalAgreement">
<tr>
<td><a href="additional_agreement.cfm?__id=#__id#&#tr.fwx#">#__id#</a></td>
<td><a href="additional_agreement.cfm?__id=#__id#&#tr.fwx#">#__index#</a></td>
<td>#additional_agreement#</td>
<td><a href="contract.cfm?__id=#contract_uid#&#tr.fwx#">#agreement_id#</a></td>
<td>#dateFormat(date_of_aggrement,"YYYY-MM-DD")#</td>
<td><a href="deal.cfm?__id=#deal_uid#&#tr.fwx#">#deal#</a></td>
<td>#status#</td>
<td>#probability_pc#</td>
<td>#owner#</td>
<td class="r nw">#nFmt(install)#</td>
<td class="r nw">#nFmt(periodical)#</td>
<td class="r nw">#nFmt(metered)#</td>
</tr>
</cfoutput>
</table>
<!--- ----------------------------------------------------------------- --->
<!--- ----------------------------------------------------------------- --->
<!--- ----------------------------------------------------------------- --->
<cfquery name="qDeal">
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)
),
component as (select siv.deal as deal_uids, siv.type, (siv.cnt*(100-COALESCE(siv.discount,0))/100*p.price*p.cnt*(100-COALESCE(p.discount,0))) as param_cost
from elma.deals_services siv
join elma.service_parametrs p on (p.__id = ANY(siv.params))
where p."__deletedAt" IS NULL AND siv."__deletedAt" IS NULL AND siv.is_actual
)
select
<d:field_set titleMapOut="titleMap" lengthOut="fieldCount">
<d:field title="ID" cfSqlType="CF_SQL_OTHER">d.__id</d:field>
<d:field title="index" cfSqlType="CF_SQL_INTEGER">d.__index</d:field>
<d:field title="Название">d.__name</d:field>
<d:field title="company_uid">d._companies</d:field>
<d:field title="Создана">d."__createdAt" as __createdAt</d:field><!--- *** косяк d:field, если взять в кавычки имя поля, оно не попадает в массив полей --->
<d:field title="Контрагент">k.__name as contragent</d:field>
<d:field title="Контрагент">k.__id as contragent_uid</d:field>
<d:field title="WZ">k.id_klienta as wz</d:field>
<d:field title="status_id">d.__status_status</d:field>
<d:field title="Статус">s.status</d:field>
<d:field title="Вероятность%">s.probability_pc</d:field>
<d:field title="Ответственный">c.__name as owner</d:field>
<d:field title="Допник">a.__name as additional_agreement</d:field>
<d:field title="Допник">a.__id as additional_agreement_uid</d:field>
<d:field title="Договор">g.__name as contract</d:field>
<d:field title="Договор">g.__id as contract_uid</d:field>
<d:field title="Договор">g.date_of_aggrement</d:field>
<d:field title="Договор">g.agreement_id</d:field>
<d:field title="Дата дог.">g.date_of_aggrement as dt_contract</d:field>
<d:field>(select sum(param_cost)
from component
where d.__id = ANY(component.deal_uids) AND component.type IN (1)
) as install
</d:field>
<d:field>(select sum(param_cost)
from component
where d.__id = ANY(component.deal_uids) AND component.type IN (2)
) as periodical
</d:field>
<d:field>(select sum(param_cost)
from component
where d.__id = ANY(component.deal_uids) AND component.type IN (3)
) as metered
</d:field>
</d:field_set>
from elma.deals d
left outer join elma.companies k on (d._companies=k.__id)
left outer join status s on (d.__status_status=s.status_id)
left outer join elma.comp_users_ext c on (d._owner=c.__id)
left outer join elma.additional_agreements a on (d.__id=a.deal_uid)
left outer join elma.aggrements g on (a.contract_uid = g.__id)
where d._companies=<cfqueryparam cfsqltype="cf_sql_other" value="#d.__id#" null=#!isValid('guid',d.__id)#/>
AND s.probability_pc > 0
order by d.__index
</cfquery>
<cfoutput>
<h4>Сделки (#qDeal.recordCount#) - исключены сделки с нулевой вероятностью</h4>
</cfoutput>
<table class="worktable">
<thead>
<tr>
<th>__id</th>
<th>__index</th>
<th>Сделка</th>
<th>Статус сделки</th>
<th>Вер-ть %</th>
<th>Ответственный</th>
<th>Допник</th>
<th>Договор</th>
<th>Внут. н-р дог.</th>
<th>Дата договора</th>
<th>Инсталл</th>
<th>Ежемес</th>
<th>Тариф.</th>
</tr>
</thead>
<cfoutput query="qDeal">
<tr>
<td><a href="deal.cfm?__id=#__id#&#tr.fwx#">#__id#</a></td>
<td>#__index#</td>
<td><a href="deal.cfm?__id=#__id#&#tr.fwx#">#__name#</a></td>
<td>#status#</td>
<td>#probability_pc#</td>
<td>#owner#</td>
<td>#additional_agreement#</td>
<td>#contract#</td>
<td><a href="contract.cfm?__id=#contract_uid#&#tr.fwx#">#agreement_id#</a></td>
<td>#dateFormat(date_of_aggrement,"YYYY-MM-DD")#</td>
<td class="r nw">#nFmt(install)#</td>
<td class="r nw">#nFmt(periodical)#</td>
<td class="r nw">#nFmt(metered)#</td>
</tr>
</cfoutput>
</table>
</cfif><!--- len(d.__id) --->
<layout:page section="footer"/>