mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 00:33:58 -04:00
Merge pull request #3101 from alphagov/billing-for-all-services-report
Usage for all services
This commit is contained in:
@@ -8,6 +8,7 @@ from notifications_python_client.errors import HTTPError
|
||||
from requests import RequestException
|
||||
|
||||
from app import (
|
||||
billing_api_client,
|
||||
complaint_api_client,
|
||||
format_date_numeric,
|
||||
letter_jobs_client,
|
||||
@@ -292,6 +293,37 @@ def notifications_sent_by_service():
|
||||
return render_template('views/platform-admin/notifications_by_service.html', form=form)
|
||||
|
||||
|
||||
@main.route("/platform-admin/reports/usage-for-all-services", methods=['GET', 'POST'])
|
||||
@user_is_platform_admin
|
||||
def usage_for_all_services():
|
||||
form = RequiredDateFilterForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
start_date = form.start_date.data
|
||||
end_date = form.end_date.data
|
||||
headers = ["organisation_id", "organisation_name", "service_id", "service_name",
|
||||
"sms_cost", "sms_fragments", "letter_cost", "letter_breakdown"]
|
||||
|
||||
result = billing_api_client.get_usage_for_all_services(start_date, end_date)
|
||||
rows = [
|
||||
[
|
||||
r['organisation_id'], r["organisation_name"], r["service_id"], r["service_name"],
|
||||
r["sms_cost"], r['sms_fragments'], r["letter_cost"], r["letter_breakdown"].strip()
|
||||
]
|
||||
for r in result
|
||||
]
|
||||
if rows:
|
||||
return Spreadsheet.from_rows([headers] + rows).as_csv_data, 200, {
|
||||
'Content-Type': 'text/csv; charset=utf-8',
|
||||
'Content-Disposition': 'attachment; filename="Usage for all services from {} to {}.csv"'.format(
|
||||
start_date, end_date
|
||||
)
|
||||
}
|
||||
else:
|
||||
flash('No results for dates')
|
||||
return render_template('views/platform-admin/usage_for_all_services.html', form=form)
|
||||
|
||||
|
||||
@main.route("/platform-admin/complaints")
|
||||
@user_is_platform_admin
|
||||
def platform_admin_list_complaints():
|
||||
|
||||
@@ -92,6 +92,7 @@ class HeaderNavigation(Navigation):
|
||||
'live_services_csv',
|
||||
'notifications_sent_by_service',
|
||||
'performance_platform_xlsx',
|
||||
'usage_for_all_services',
|
||||
'platform_admin',
|
||||
'platform_admin_letter_validation_preview',
|
||||
'platform_admin_list_complaints',
|
||||
@@ -578,6 +579,7 @@ class MainNavigation(Navigation):
|
||||
'two_factor_email_sent',
|
||||
'update_email_branding',
|
||||
'update_letter_branding',
|
||||
'usage_for_all_services',
|
||||
'user_information',
|
||||
'user_profile',
|
||||
'user_profile_email',
|
||||
@@ -853,6 +855,7 @@ class CaseworkNavigation(Navigation):
|
||||
'update_letter_branding',
|
||||
'uploads',
|
||||
'usage',
|
||||
'usage_for_all_services',
|
||||
'user_information',
|
||||
'user_profile',
|
||||
'user_profile_email',
|
||||
@@ -1129,6 +1132,7 @@ class OrgNavigation(Navigation):
|
||||
'update_letter_branding',
|
||||
'uploads',
|
||||
'usage',
|
||||
'usage_for_all_services',
|
||||
'user_information',
|
||||
'user_profile',
|
||||
'user_profile_email',
|
||||
|
||||
@@ -34,5 +34,12 @@ class BillingAPIClient(NotifyAdminAPIClient):
|
||||
data=data
|
||||
)
|
||||
|
||||
def get_usage_for_all_services(self, start_date, end_date):
|
||||
return self.get(url='/platform-stats/usage-for-all-services',
|
||||
params={
|
||||
'start_date': str(start_date),
|
||||
'end_date': str(end_date),
|
||||
})
|
||||
|
||||
|
||||
billing_api_client = BillingAPIClient()
|
||||
|
||||
@@ -21,4 +21,7 @@
|
||||
<p>
|
||||
<a href="{{ url_for('main.notifications_sent_by_service') }}">Monthly notification statuses for live services</a>
|
||||
<p>
|
||||
<p>
|
||||
<a href="{{ url_for('main.usage_for_all_services') }}">Usage for all services</a>
|
||||
</p>
|
||||
{% endblock %}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
{% extends "views/platform-admin/_base_template.html" %}
|
||||
{% from "components/form.html" import form_wrapper %}
|
||||
|
||||
{% block per_page_title %}
|
||||
Usage for all services
|
||||
{% endblock %}
|
||||
|
||||
{% block platform_admin_content %}
|
||||
|
||||
<h1 class="heading-large">
|
||||
Usage for all services
|
||||
</h1>
|
||||
|
||||
{% call form_wrapper() %}
|
||||
{{ textbox(form.start_date, hint="Enter start date in format YYYY-MM-DD") }}
|
||||
{{ textbox(form.end_date, hint="Enter end date in format YYYY-MM-DD") }}
|
||||
{{ page_footer('Download report') }}
|
||||
{% endcall %}
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user