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

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

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

просмотр истории страницы
<link href="/static/css/for_printer.css" type="text/css" media="all" rel="stylesheet" />
{% endblock %}{code}
# h5. Отчет по входящему интернет-трафику юридических лиц за выбранный период месяц
Отчет расчитан на использование тарифов типа лестница с некоторым объёмом трафика включенного в абонентскую плату, по исчерпании которого начисляется помегабайтная оплата.
По каждому абоненту отражены тарифы назначенные абоненту за период, суммарное потребление трафика по тарифу и отдельно трафик сверх включенного, а так же его стоимость.
{code}select
aid,
' ',
s_id,
'   УСЛУГА: ' || serv "Тариф/Услуга",
coalesce(price,'') "Цена МБ",
'' "Включено МБ",
sum(mb_count) "МБ по усл./тарифу",
'' "Всего МБ",
sum(traf_cost) "Сумма руб."
from
(select distinct
ab.id as aid,
ab.name as fio,
t.id as tar,
t.name as tid,
usl.name as serv,
usl.id as s_id,
tar_cost.in_price as price,
uslpreord.mbinc,
coalesce(tfc.p_in/10000000000.00,0) as traf_cost,
round(tfc.v_in / cast((1048576) as numeric(18,5)), 2) as mb_count

from
traf_counters as tfc
join abonents ab on tfc.abonent_id=ab.id
join users_usluga as uu on tfc.users_usluga_id=uu.id
join usluga usl on uu.usluga_id=usl.id
left join tarif t on uu.tarif_id=t.id
join (select tuu.tarif_id as tar, sum(tu.max_mb_in_m) as mbinc
from tarif_users_usluga tuu
join usluga tu on tuu.usluga_id=tu.id
where tu.max_mb_in_m is not null and tu.max_mb_in_m<>0
group by tuu.tarif_id
) uslpreord on uu.tarif_id=uslpreord.tar
left join (select distinct tuu.tarif_id as tar, tu.id as serv, tu.in_price/10000000000.00 as in_price
from tarif_users_usluga tuu
join usluga tu on tuu.usluga_id=tu.id and tu.in_price<>0
) tar_cost on uu.tarif_id=tar_cost.tar and uu.usluga_id=tar_cost.serv
where
tfc.MONTH_NUMBER = (':Месяц|choices[1^]Январь^[2^]Февраль^[3^]Март^[4^]Апрель^[5^]Май^[6^]Июнь^[7^]Июль^[8^]Август^[9^]Сентябрь^[10^]Октябрь^[11^]Ноябрь^[12^]Декабрь]$')
and tfc.year_number = (':Год|choices[2019^]2019^[2018^]2018^[2017^]2017^[2016^]2016^[2015^]2015^[2014^]2014]$')
and ab.company = 1
and (usl.max_mb_in_m>0 or usl.in_price>0)
--and ab.id in (1172,2575)
)
where
(traf_cost<>0 and price<>0)
group by 1,3,4,5,6
union all
select
aid,
' ',
tid,
'ТАРИФ: ' || tar "Тариф",
' ',
cast(mbinc as varchar(16)) "Включено МБ",
cast(sum(mb_count) as varchar(16)),
cast(iif((sum(mb_count)-mbinc)>0, sum(mb_count)-mbinc, null) as varchar(32)) "МБ по услуге",
iif(sum(traf_cost)>0,sum(traf_cost), null) "Сумма руб."
from
(select distinct
ab.id as aid,
ab.name as fio,
t.id as tid,
t.name as tar,
tar_cost.in_price as price,
uslpreord.mbinc,
coalesce(tfc.p_in/10000000000.00,0) as traf_cost,
round(tfc.v_in / cast((1048576) as numeric(18,5)), 2) as mb_count

from
traf_counters as tfc
join abonents ab on tfc.abonent_id=ab.id
join users_usluga as uu on tfc.users_usluga_id=uu.id
join usluga usl on uu.usluga_id=usl.id
left join tarif t on uu.tarif_id=t.id
join (select tuu.tarif_id as tar, sum(tu.max_mb_in_m) as mbinc
from tarif_users_usluga tuu
join usluga tu on tuu.usluga_id=tu.id
where tu.max_mb_in_m is not null and tu.max_mb_in_m<>0
group by tuu.tarif_id
) uslpreord on uu.tarif_id=uslpreord.tar
left join (select distinct tuu.tarif_id as tar, tu.id as serv, tu.in_price/10000000000.00 as in_price
from tarif_users_usluga tuu
join usluga tu on tuu.usluga_id=tu.id and tu.in_price<>0
) tar_cost on uu.tarif_id=tar_cost.tar and uu.usluga_id=tar_cost.serv
where
tfc.MONTH_NUMBER = (':Месяц|choices[1^]Январь^[2^]Февраль^[3^]Март^[4^]Апрель^[5^]Май^[6^]Июнь^[7^]Июль^[8^]Август^[9^]Сентябрь^[10^]Октябрь^[11^]Ноябрь^[12^]Декабрь]$')
and tfc.year_number = (':Год|choices[2019^]2019^[2018^]2018^[2017^]2017^[2016^]2016^[2015^]2015^[2014^]2014]$')
and ab.company = 1
and (usl.max_mb_in_m>0 or usl.in_price>0)
--and ab.id in (1172,2575)
)
where
(traf_cost<>0 and price<>0) or (traf_cost=0 and price is null)
group by 1,2,3,4,mbinc
union all
select distinct
aid,
fio,
null,
'       ',
'       ',
'       ',
'       ',
'       ',
null
from
(select distinct
ab.id as aid,
ab.name as fio,
t.id as tid,
t.name as tar,
tar_cost.in_price as price,
uslpreord.mbinc,
coalesce(tfc.p_in/10000000000.00,0) as traf_cost,
round(tfc.v_in / cast((1048576) as numeric(18,5)), 2) as mb_count

from
traf_counters as tfc
join abonents ab on tfc.abonent_id=ab.id
join users_usluga as uu on tfc.users_usluga_id=uu.id
join usluga usl on uu.usluga_id=usl.id
left join tarif t on uu.tarif_id=t.id
join (select tuu.tarif_id as tar, sum(tu.max_mb_in_m) as mbinc
from tarif_users_usluga tuu
join usluga tu on tuu.usluga_id=tu.id
where tu.max_mb_in_m is not null and tu.max_mb_in_m<>0
group by tuu.tarif_id
) uslpreord on uu.tarif_id=uslpreord.tar
left join (select distinct tuu.tarif_id as tar, tu.id as serv, tu.in_price/10000000000.00 as in_price
from tarif_users_usluga tuu
join usluga tu on tuu.usluga_id=tu.id and tu.in_price<>0
) tar_cost on uu.tarif_id=tar_cost.tar and uu.usluga_id=tar_cost.serv
where
tfc.MONTH_NUMBER = (':Месяц|choices[1^]Январь^[2^]Февраль^[3^]Март^[4^]Апрель^[5^]Май^[6^]Июнь^[7^]Июль^[8^]Август^[9^]Сентябрь^[10^]Октябрь^[11^]Ноябрь^[12^]Декабрь]$')
and tfc.year_number = (':Год|choices[2019^]2019^[2018^]2018^[2017^]2017^[2016^]2016^[2015^]2015^[2014^]2014]$')
and ab.company = 1
and (usl.max_mb_in_m>0 or usl.in_price>0)
--and ab.id in (1172,2575)
)
order by 1,2,4{code}
Шаблон отчета:
{code}{% extends "form_list.html" %}
{% load field_type %}
{% block content %}
<form method="POST">
<div id="params">
{% csrf_token %}{% load mathfilters %}
<input type='hidden' name='unique_form_post_id' value='{{ unique_form_post_id }}' />
{% if form %}
<div class="row-fluid">
<div class="span6">
<legend><h2>Заполните поля запроса</h2></legend>
{{ form }}
</div>
</div>
{% endif %}
<div class="row-fluid">
<div class="down_toolbar">
<button type="submit" value="Выполнить запрос" class="default btn btn-success">
<i class="icon-ok icon-white"></i> Выполнить запрос
</button>
{% if data %}
<div class="btn-group">
<a class="default btn dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-print icon-white"></i>
Выгрузка
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><button type="submit" name="csv" value="True">CSV</button></li>
<li><button type="submit" name="dbf" value="True">DBF</button></li>
</ul>
</div>
<button class="default btn btn-success" onclick="window.print();" ><i class="icon-print icon-white"></i>Печать</button>
{% endif %}
</div>
</div>
</div>
</form>
{% block subcontent %}
{% if execute %}
<h2>{{inst.name}}</h2>
{% if error %}
{{ error }}<br/><br/>
{% endif %}

{% if data %}
<table bordercolor="#AAAAAA" id="print" class="mysqldata" border="1" style="text-align: left;" cellpadding="3">
<tr>
<th>ФИО</th>
<th>Тариф</th>
<th>Цена за МБ</th>
<th>Объем предоплаченного трафика</th>
<th>Объем трафика по тарифу/услуге</th>
<th>Объем трафика сверх предоплаченного</th>
<th>Переплата</th>
</tr>
{% for row in data %}
{% if row.1 != ' ' %}
<tr>
<td bgcolor="#F5F5F5"> </td>
<td bgcolor="#F5F5F5"> </td>
<td bgcolor="#F5F5F5"> </td>
<td bgcolor="#F5F5F5"> </td>
<td bgcolor="#F5F5F5"> </td>
<td bgcolor="#F5F5F5"> </td>
<td bgcolor="#F5F5F5"> </td>
</tr>
{% endif %}
{% if row.1 != ' ' and row.2 != ' ' %}
<tr>
<td><a href="/admin/Abonents/Abonents/{{ row.0 }}/" target="_blank">{{ row.1 }}</a></td>
</tr>
{% else %}
<tr>
<td> </td>
<td>{% if row.4 != ' ' %} <a href="/admin/tarifs/Usluga/{{ row.2 }}/" target="_blank">{{ row.3 }}</a> {% else %} <a href="/admin/tarifs/Tarif/{{ row.2 }}/" target="_blank">{{ row.3 }}</a> {% endif %}</td>
<td style="text-align: right;">{% if row.4 != ' ' %} {{ row.4 }} руб. {% else %} {% endif %}</td>
<td style="text-align: right;">{% if row.5 %} {{ row.5|floatformat:2 }} Мб {% else %} {% endif %}</td>
<td style="text-align: right;">{% if row.6 %} {{ row.6|floatformat:2 }} Мб {% else %} {% endif %}</td>
<td style="text-align: right;">{% if row.7 %} {{ row.7|floatformat:2 }} Мб {% else %} {% endif %}</td>
<td style="text-align: right;">{% if row.8 %} {{ row.8|floatformat:2 }} руб. {% else %} {% endif %}</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% else %}
<h3>Ничего не найдено.</h3>
{% endif %}
{% endif %}
{% endblock %}
{% endblock %}
{% block js_addon %}
<link href="/static/css/jqueryui/smoothness/jquery-ui-1.8.23.custom.css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/static/js/jqueryui/jquery-ui-1.8.23.custom.min.js"></script>
<script type="text/javascript" src="/static/js/jqueryui/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="/static/js/jqueryui/jquery-ui-sliderAccess.js"></script>
<script type="text/javascript" src="/static/js/makedatetime.js"></script>
<script type="text/javascript" src="/static/js/print.js"></script>
<link href="/static/css/for_printer.css" type="text/css" media="all" rel="stylesheet" />
{% endblock %}{code}