-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: full pdf summary of applications (HL-708, HL-903) (#2524)
* feat: new function to change test seeds * feat: application HTML/PDF print view * feat: add 'print application' link as button * chore: skip flaky handler browser test
- Loading branch information
Showing
28 changed files
with
1,286 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/benefit/applications/services/app_generated_files.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pdfkit | ||
from django.template import loader | ||
|
||
|
||
def get_context_for_summary_context(application): | ||
def count_version_number(number_of_versions): | ||
# Minimum version 1.0, increase by 0.1 for each version | ||
version = max(number_of_versions + 1, 10) / 10.0 | ||
return str(version).replace(",", ".") | ||
|
||
def total_de_minimis_amount(application): | ||
de_minimis_amount = 0 | ||
if application.de_minimis_aid_set.count(): | ||
for aid in application.de_minimis_aid_set.all(): | ||
de_minimis_amount = de_minimis_amount + float(aid.amount) | ||
return ( | ||
"{:20,.2f}".format(de_minimis_amount) | ||
.replace(",", " ") | ||
.replace(".", ",") | ||
) | ||
return de_minimis_amount | ||
|
||
return { | ||
"application": application, | ||
"attachments": application.attachments.all(), | ||
"de_minimis_amount": total_de_minimis_amount(application), | ||
"de_minimis_aid_set": application.de_minimis_aid_set.all(), | ||
"versions": { | ||
"application": count_version_number(len(application.history.all())) | ||
}, | ||
} | ||
|
||
|
||
def generate_application_summary_file(application, request=None) -> bytes: | ||
def generate_summary_pdf(context) -> bytes: | ||
template = loader.get_template("application.html") | ||
rendered_template = template.render(context, request) | ||
return pdfkit.from_string(rendered_template, False, None) | ||
|
||
context = get_context_for_summary_context(application) | ||
return generate_summary_pdf(context) |
179 changes: 99 additions & 80 deletions
179
backend/benefit/applications/services/pdf_templates/benefit_template.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,105 @@ | ||
{% extends "base.html" %} | ||
{% extends "base.html" %} {% block content %} | ||
<p>{{ title }}</p> | ||
|
||
{% block content %} | ||
<p>{{ title }}</p> | ||
<table aria-label="AHJO report" style="border: 1px solid black"> | ||
<tr> | ||
<th scope="col">Hakemusnumero</th> | ||
<th scope="col">Hakija</th> | ||
<th scope="col">Y-tunnus</th> | ||
{% if show_employee_names %} | ||
<th scope="col">Työllistetty</th> | ||
{% endif %} | ||
<th scope="col">Aika</th> | ||
<th scope="col">Tukimuoto</th> | ||
{% if show_sums %} | ||
<th class="text-right" scope="col">Summa/kk</th> | ||
<th class="text-right" scope="col">Yhteensä</th> | ||
{% endif %} | ||
</tr> | ||
{% for app in apps %} | ||
{% if not show_ahjo_rows or app.ahjo_rows.count() == 0 %} | ||
<tr> | ||
<td>{{ app.ahjo_application_number }}</td> | ||
<td>{{ app.company_name }}</td> | ||
<td>{{ app.company.business_id }}</td> | ||
{% if show_employee_names %} | ||
<td>{{ app.employee.first_name }} {{ app.employee.last_name }}</td> | ||
{% endif %} | ||
<td>{{ app.start_date.strftime("%d.%m.%Y") }} - {{ app.end_date.strftime("%d.%m.%Y")}}</td> | ||
<td>{{ app.get_benefit_type_display() }}</td> | ||
{% if show_sums and app.calculated_benefit_amount and app.calculation.duration_in_months %} | ||
<td class="text-right">{{ "%.0f €" | format(app.calculated_benefit_amount/(app.calculation.duration_in_months | round(2)))}} </td> | ||
<td class="text-right"><strong>{{ "%.0f €" | format(app.calculated_benefit_amount)}}</strong></td> | ||
{% elif show_sums %} | ||
<td class="text-right">0 €</td> | ||
<td class="text-right"><strong>0 €</strong></td> | ||
{% endif %} | ||
</tr> | ||
{% else %} | ||
{% for ahjo_row in app.ahjo_rows %} | ||
<tr> | ||
<td>{{ app.ahjo_application_number }}</td> | ||
<td>{{ app.company_name }}</td> | ||
<td>{{ app.company.business_id }}</td> | ||
{% if show_employee_names %} | ||
<td>{{ app.employee.first_name }} {{ app.employee.last_name }}</td> | ||
{% endif %} | ||
<td>{{ ahjo_row.start_date.strftime("%d.%m.%Y") }} - {{ ahjo_row.end_date.strftime("%d.%m.%Y")}}</td> | ||
<td>{{ app.get_benefit_type_display() }}</td> | ||
{% if show_sums %} | ||
<td class="text-right">{{ "%.0f €" | format(ahjo_row.amount/(ahjo_row.duration_in_months | round(2)))}}</td> | ||
<td class="text-right"><strong>{{ "%.0f €" | format(ahjo_row.amount)}}</strong></td> | ||
{% endif %} | ||
</tr> | ||
{% endfor %} | ||
{% endif %} | ||
{% endfor %} | ||
<style> | ||
{% if is_private %} | ||
tr th, tr:last-child td { | ||
background: firebrick !important; | ||
} | ||
{% endif %} | ||
</style> | ||
|
||
<table aria-label="AHJO report" style="border: 1px solid black"> | ||
<tr> | ||
<th scope="col">Hakemusnumero</th> | ||
<th scope="col">Hakija</th> | ||
<th scope="col">Y-tunnus</th> | ||
{% if show_employee_names %} | ||
<th scope="col">Työllistetty</th> | ||
{% endif %} | ||
<th scope="col">Aika</th> | ||
<th scope="col">Tukimuoto</th> | ||
{% if show_sums %} | ||
{% set benefit = namespace(amounts=0) %} | ||
{% for app in apps %} | ||
{% if app.calculated_benefit_amount is not none %} | ||
{% set benefit.amounts = benefit.amounts + app.calculated_benefit_amount %} | ||
{% endif %} | ||
{% endfor %} | ||
<tr> | ||
<td colspan="8" class="footer text-right"> Kaikki yhteensä | ||
<strong> | ||
{{ "%.0f €" | format(benefit.amounts) }} | ||
</strong> | ||
</td> | ||
</tr> | ||
<th class="text-right" scope="col">Summa/kk</th> | ||
<th class="text-right" scope="col">Yhteensä</th> | ||
{% endif %} | ||
</table> | ||
|
||
{% if show_de_minimis_aid_footer %} | ||
<p style="color: #999898; padding: 0px 50px; text-align: center">Tämän päätöksen suoma tuki myönnetään vähämerkityksisenä eli ns. de | ||
minimis -tukena. | ||
Tuen myöntämisessä noudatetaan komission asetusta (EU) 1407/2013, 24.12.2013, perustamissopimuksen 107 ja 108 artiklan soveltamisesta vähämerkityksiseen tukeen (EUVL nro L352, 24.12.2013).</p> | ||
</tr> | ||
{% for app in apps %} {% if not show_ahjo_rows or app.ahjo_rows.count() == 0 | ||
%} | ||
<tr> | ||
<td>{{ app.ahjo_application_number }}</td> | ||
<td>{{ app.company_name }}</td> | ||
<td>{{ app.company.business_id }}</td> | ||
{% if show_employee_names %} | ||
<td>{{ app.employee.first_name }} {{ app.employee.last_name }}</td> | ||
{% endif %} | ||
<td> | ||
{{ app.start_date.strftime("%d.%m.%Y") }} - {{ | ||
app.end_date.strftime("%d.%m.%Y")}} | ||
</td> | ||
<td>{{ app.get_benefit_type_display() }}</td> | ||
{% if show_sums and app.calculated_benefit_amount and | ||
app.calculation.duration_in_months %} | ||
<td class="text-right"> | ||
{{ "%.0f €" | | ||
format(app.calculated_benefit_amount/(app.calculation.duration_in_months | ||
| round(2)))}} | ||
</td> | ||
<td class="text-right"> | ||
<strong | ||
>{{ "%.0f €" | format(app.calculated_benefit_amount)}}</strong | ||
> | ||
</td> | ||
{% elif show_sums %} | ||
<td class="text-right">0 €</td> | ||
<td class="text-right"><strong>0 €</strong></td> | ||
{% endif %} | ||
</tr> | ||
{% else %} {% for ahjo_row in app.ahjo_rows %} | ||
<tr> | ||
<td>{{ app.ahjo_application_number }}</td> | ||
<td>{{ app.company_name }}</td> | ||
<td>{{ app.company.business_id }}</td> | ||
{% if show_employee_names %} | ||
<td>{{ app.employee.first_name }} {{ app.employee.last_name }}</td> | ||
{% endif %} | ||
<td> | ||
{{ ahjo_row.start_date.strftime("%d.%m.%Y") }} - {{ | ||
ahjo_row.end_date.strftime("%d.%m.%Y")}} | ||
</td> | ||
<td>{{ app.get_benefit_type_display() }}</td> | ||
{% if show_sums %} | ||
<td class="text-right"> | ||
{{ "%.0f €" | format(ahjo_row.amount/(ahjo_row.duration_in_months | | ||
round(2)))}} | ||
</td> | ||
<td class="text-right"> | ||
<strong>{{ "%.0f €" | format(ahjo_row.amount)}}</strong> | ||
</td> | ||
{% endif %} | ||
</tr> | ||
{% endfor %} {% endif %} {% endfor %} {% if show_sums %} {% set benefit = | ||
namespace(amounts=0) %} {% for app in apps %} {% if | ||
app.calculated_benefit_amount is not none %} {% set benefit.amounts = | ||
benefit.amounts + app.calculated_benefit_amount %} {% endif %} {% endfor %} | ||
<tr> | ||
<td colspan="8" class="footer text-right"> | ||
Kaikki yhteensä | ||
<strong> {{ "%.0f €" | format(benefit.amounts) }} </strong> | ||
</td> | ||
</tr> | ||
{% endif %} | ||
</table> | ||
|
||
{% if not show_employee_names %} | ||
<p style="color: #999898; padding: 0px 50px; text-align: center">Työllistettyjen nimet poistettu. JulkL 24§ 1 mom | ||
25 k.</p> | ||
{% endif %} | ||
{% endblock %} | ||
{% if show_de_minimis_aid_footer %} | ||
<p style="color: #999898; padding: 0px 50px; text-align: center"> | ||
Tämän päätöksen suoma tuki myönnetään vähämerkityksisenä eli ns. de minimis | ||
-tukena. Tuen myöntämisessä noudatetaan komission asetusta (EU) 1407/2013, | ||
24.12.2013, perustamissopimuksen 107 ja 108 artiklan soveltamisesta | ||
vähämerkityksiseen tukeen (EUVL nro L352, 24.12.2013). | ||
</p> | ||
{% endif %} {% if not show_employee_names %} | ||
<p style="color: #999898; padding: 0px 50px; text-align: center"> | ||
Työllistettyjen nimet poistettu. JulkL 24§ 1 mom 25 k. | ||
</p> | ||
{% endif %} {% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% extends "base.html" %} {% block content %} {% include "style.html" %} | ||
<div class="wrapper"> | ||
<main>{{ _("Not found") }}</main> | ||
</div> | ||
{%endblock%} |
Oops, something went wrong.