Конструктор отчетов

Ключ
Эта строка удалена.
Это слово было удалено. Это слово было добавлено.
Эта строка добавлена.

Изменения (1)

просмотр истории страницы
and uu.usluga_id!=-170000
{code}
# h5. Отчёт по наличным/безналичным приходам с группировкой по тарифам абонентов.
{code}
select
t.name as "Тариф",
(
select
sum(round(u.SUMMA / cast((select CONST_VALUE from VPN_CONST where CONST_ID = 1) as numeric(18,5)), 2))
FROM TARIF t1
LEFT JOIN TARIF_USERS_USLUGA tus ON tus.TARIF_ID=t.ID
LEFT JOIN USLUGA u ON u.ID=tus.USLUGA_ID
WHERE t1.id = t.ID
) as "Абон. плата",
(
select distinct
count(*)
from abonents a1
left join tarif t2 on t2.id=a1.tarif_id
left join finance_operations fo1 on fo1.abonent_id=a1.id
where t2.id=t.id
and fo1.OP_DATE between (':1 Дата|date$') and (':2 Дата|date$')
) as "Количество",
(
select
sum(round(fo2.OP_SUMMA / cast((select CONST_VALUE from VPN_CONST where CONST_ID = 1) as numeric(18,5)), 2))
from finance_operations fo2
left join abonents a on a.id=fo2.abonent_id
where a.tarif_id=t.id
and fo2.OP_DATE between (':1 Дата|date$') and (':2 Дата|date$')
and fo2.is_cash=1
)as "Наличные",
(
select
sum(round(fo3.OP_SUMMA / cast((select CONST_VALUE from VPN_CONST where CONST_ID = 1) as numeric(18,5)), 2))
from finance_operations fo3
left join abonents a on a.id=fo3.abonent_id
where a.tarif_id=t.id
and fo3.OP_DATE between (':1 Дата|date$') and (':2 Дата|date$')
and fo3.is_cash=0
)as "Безналичные",
(
select
sum(round(fo.OP_SUMMA / cast((select CONST_VALUE from VPN_CONST where CONST_ID = 1) as numeric(18,5)), 2))
from finance_operations fo
left join abonents a on a.id=fo.abonent_id
where a.tarif_id=t.id
and fo.OP_DATE between (':1 Дата|date$') and (':2 Дата|date$')
)as "Сумма"
from tarif t
where t.ARCHIVED=0
{code}