diff --git a/analysis/templates/analysis/reports/detail.html b/analysis/templates/analysis/reports/detail.html index 219ad46d..f90acdaf 100644 --- a/analysis/templates/analysis/reports/detail.html +++ b/analysis/templates/analysis/reports/detail.html @@ -10,7 +10,7 @@
{% include 'analysis/reports/includes/intervention/card_intervention.html' %} - {% include 'analysis/reports/includes/card_compensation.html' %} + {% include 'analysis/reports/includes/compensation/card_compensation.html' %} {% include 'analysis/reports/includes/card_eco_account.html' %} {% include 'analysis/reports/includes/card_old_interventions.html' %}
diff --git a/analysis/templates/analysis/reports/includes/compensation/amount.html b/analysis/templates/analysis/reports/includes/compensation/amount.html new file mode 100644 index 00000000..27b79f65 --- /dev/null +++ b/analysis/templates/analysis/reports/includes/compensation/amount.html @@ -0,0 +1,55 @@ +{% load i18n fontawesome_5 ksp_filters %} + +

{% trans 'Amount' %}

+ + {% blocktrans %} + Checked = Has been checked by the registration office according to LKompVzVo + {% endblocktrans %} +
+ {% blocktrans %} + Recorded = Has been checked and published by the conservation office + {% endblocktrans %} +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{% trans 'Area of responsibility' %}{% fa5_icon 'star' %} {% trans 'Checked' %}{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}{% trans 'Number single areas' %}{% trans 'Total' %}
{% trans 'Conservation office by law' %}{{report.compensation_report.queryset_registration_office_unb_checked.count|default_if_zero:"-"}}{{report.compensation_report.queryset_registration_office_unb_recorded.count|default_if_zero:"-"}}{{report.compensation_report.num_single_surfaces_total_unb|default_if_zero:"-"}}{{report.compensation_report.queryset_registration_office_unb.count|default_if_zero:"-"}}
{% trans 'Land-use planning' %}{{report.compensation_report.queryset_registration_office_tbp_checked.count|default_if_zero:"-"}}{{report.compensation_report.queryset_registration_office_tbp_recorded.count|default_if_zero:"-"}}{{report.compensation_report.num_single_surfaces_total_tbp|default_if_zero:"-"}}{{report.compensation_report.queryset_registration_office_tbp.count|default_if_zero:"-"}}
{% trans 'Other registration office' %}{{report.compensation_report.queryset_registration_office_other_checked.count|default_if_zero:"-"}}{{report.compensation_report.queryset_registration_office_other_recorded.count|default_if_zero:"-"}}{{report.compensation_report.num_single_surfaces_total_other|default_if_zero:"-"}}{{report.compensation_report.queryset_registration_office_other.count|default_if_zero:"-"}}
{% trans 'Total' %}{{report.compensation_report.queryset_checked.count|default_if_zero:"-"}}{{report.compensation_report.queryset_recorded.count|default_if_zero:"-"}}{{report.compensation_report.num_single_surfaces_total|default_if_zero:"-"}}{{report.compensation_report.queryset.count|default_if_zero:"-"}}
+
\ No newline at end of file diff --git a/analysis/templates/analysis/reports/includes/card_compensation.html b/analysis/templates/analysis/reports/includes/compensation/card_compensation.html similarity index 90% rename from analysis/templates/analysis/reports/includes/card_compensation.html rename to analysis/templates/analysis/reports/includes/compensation/card_compensation.html index 24d0eabf..8fe2eec4 100644 --- a/analysis/templates/analysis/reports/includes/card_compensation.html +++ b/analysis/templates/analysis/reports/includes/compensation/card_compensation.html @@ -15,7 +15,7 @@
- {% include 'form/table/generic_table_form_body.html' %} + {% include 'analysis/reports/includes/compensation/amount.html' %}
diff --git a/analysis/templates/analysis/reports/includes/intervention/amount.html b/analysis/templates/analysis/reports/includes/intervention/amount.html index 8ecbe018..e2b94a31 100644 --- a/analysis/templates/analysis/reports/includes/intervention/amount.html +++ b/analysis/templates/analysis/reports/includes/intervention/amount.html @@ -13,18 +13,18 @@
- - - - - + + + + + - - - - - + + + + +
{% trans 'Total' %}{% fa5_icon 'star' %} {% trans 'Checked' %}{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}
{% fa5_icon 'star' %} {% trans 'Checked' %}{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}{% trans 'Total' %}
{{report.intervention_report.queryset.count|default_if_zero:"-"}}{{report.intervention_report.queryset_checked.count|default_if_zero:"-"}}{{report.intervention_report.queryset_recorded.count|default_if_zero:"-"}}
{{report.intervention_report.queryset_checked.count|default_if_zero:"-"}}{{report.intervention_report.queryset_recorded.count|default_if_zero:"-"}}{{report.intervention_report.queryset.count|default_if_zero:"-"}}
\ No newline at end of file diff --git a/analysis/templates/analysis/reports/includes/intervention/compensated_by.html b/analysis/templates/analysis/reports/includes/intervention/compensated_by.html index 8608f113..c6be40cc 100644 --- a/analysis/templates/analysis/reports/includes/intervention/compensated_by.html +++ b/analysis/templates/analysis/reports/includes/intervention/compensated_by.html @@ -5,29 +5,29 @@ {% trans 'Compensation type' %} + {% fa5_icon 'star' %} {% trans 'Checked' %} + {% fa5_icon 'bookmark' %} {% trans 'Recorded' %} {% trans 'Total' %} - {% trans 'Checked' %} - {% trans 'Recorded' %} {% trans 'Compensation' %} - {{report.intervention_report.compensation_sum|default_if_zero:"-"}} {{report.intervention_report.compensation_sum_checked|default_if_zero:"-"}} {{report.intervention_report.compensation_sum_recorded|default_if_zero:"-"}} + {{report.intervention_report.compensation_sum|default_if_zero:"-"}} {% trans 'Payment' %} - {{report.intervention_report.payment_sum|default_if_zero:"-"}} {{report.intervention_report.payment_sum_checked|default_if_zero:"-"}} {{report.intervention_report.payment_sum_recorded|default_if_zero:"-"}} + {{report.intervention_report.payment_sum|default_if_zero:"-"}} {% trans 'Deductions' %} - {{report.intervention_report.deduction_sum|default_if_zero:"-"}} {{report.intervention_report.deduction_sum_checked|default_if_zero:"-"}} {{report.intervention_report.deduction_sum_recorded|default_if_zero:"-"}} + {{report.intervention_report.deduction_sum|default_if_zero:"-"}} diff --git a/analysis/templates/analysis/reports/includes/intervention/laws.html b/analysis/templates/analysis/reports/includes/intervention/laws.html index 8e04341c..e310197f 100644 --- a/analysis/templates/analysis/reports/includes/intervention/laws.html +++ b/analysis/templates/analysis/reports/includes/intervention/laws.html @@ -14,10 +14,10 @@ {% trans 'Law' %} - {% trans 'Checked' %} + {% fa5_icon 'star' %} {% trans 'Checked' %} - {% trans 'Recorded' %} + {% fa5_icon 'bookmark' %} {% trans 'Recorded' %} {% trans 'Total' %} diff --git a/analysis/utils/report.py b/analysis/utils/report.py index fbc88520..ce5d895a 100644 --- a/analysis/utils/report.py +++ b/analysis/utils/report.py @@ -5,12 +5,14 @@ Contact: michel.peltriaux@sgdnord.rlp.de Created on: 18.10.21 """ +from django.contrib.gis.db.models.functions import NumGeometries from django.db.models import Count, Sum, Q from codelist.models import KonovaCode from codelist.settings import CODELIST_LAW_ID from compensation.models import Compensation, Payment, EcoAccountDeduction from intervention.models import Intervention +from konova.models import Geometry class TimespanReport: @@ -122,6 +124,144 @@ class TimespanReport: self.deduction_sum_checked = deductions.filter(intervention__checked__isnull=False).count() self.deduction_sum_recorded = deductions.filter(intervention__recorded__isnull=False).count() + class CompensationReport: + queryset = Compensation.objects.none() + queryset_checked = Compensation.objects.none() + queryset_recorded = Compensation.objects.none() + + queryset_registration_office_unb = Compensation.objects.none() + queryset_registration_office_unb_checked = Compensation.objects.none() + queryset_registration_office_unb_recorded = Compensation.objects.none() + num_single_surfaces_total_unb = -1 + + queryset_registration_office_tbp = Compensation.objects.none() + queryset_registration_office_tbp_checked = Compensation.objects.none() + queryset_registration_office_tbp_recorded = Compensation.objects.none() + num_single_surfaces_total_tbp = -1 + + queryset_registration_office_other = Compensation.objects.none() + queryset_registration_office_other_checked = Compensation.objects.none() + queryset_registration_office_other_recorded = Compensation.objects.none() + num_single_surfaces_total_other = -1 + + num_single_surfaces_total = -1 + num_single_surfaces_recorded = -1 + + # Code list id for 'Träger der Bauleitplanung' parent + id_tbp = 1943695 + # Code list id for 'untere Naturschutzbehörde' + id_unb = 1943087 + # Code list id for 'obere Naturschutzbehörde' + id_onb = 1943084 + + def __init__(self, id: str): + self.queryset = Compensation.objects.filter( + intervention__responsible__conservation_office__id=id, + deleted=None, + ) + self.queryset_checked = self.queryset.filter( + intervention__checked__isnull=False + ) + self.queryset_recorded = self.queryset.filter( + intervention__recorded__isnull=False + ) + self._create_report() + + def _create_report(self): + """ Creates all report information + + Returns: + + """ + self._evaluate_compensation_responsibility() + self._evaluate_surfaces() + + def _evaluate_surfaces(self): + """ Evaluates the surfaces of compensation Multipolygon fields + + Returns: + + """ + # Evaluate all surfaces + ids = self.queryset.values_list("geometry_id") + self.num_single_surfaces_total = self._count_geometry_surfaces(ids) + + # Evaluate surfaces where the conservation office is the registration office as well + ids = self.queryset_registration_office_unb.values_list("geometry_id") + self.num_single_surfaces_total_unb = self._count_geometry_surfaces(ids) + + # Evaluates surfaces where the registration office is a Träger Bauleitplanung + ids = self.queryset_registration_office_tbp.values_list("geometry_id") + self.num_single_surfaces_total_tbp = self._count_geometry_surfaces(ids) + + # Evaluates surfaces where any other registration office is responsible + ids = self.queryset_registration_office_other.values_list("geometry_id") + self.num_single_surfaces_total_other = self._count_geometry_surfaces(ids) + + def _count_geometry_surfaces(self, ids: list): + """ Wraps counting of geometry surfaces from a given list of ids + + Args: + ids (list): List of geometry ids + + Returns: + + """ + # Now select all geometries matching the ids + # Then perform a ST_NumGeometries variant over all geometries + # Then sum up all of the calculated surface numbers + return Geometry.objects.filter( + id__in=ids + ).annotate( + num=NumGeometries("geom") + ).aggregate( + num_geoms=Sum("num") + )["num_geoms"] or 0 + + def _evaluate_compensation_responsibility(self): + """ Evaluates compensations based on different responsibility areas + + unb -> Untere Naturschutzbehörde + Holds entries where conservation_office and registration_office basically are the same + tbp -> Träger Bauleitplanung + Holds entries where registration_office is a Träger der Bauleitplanung + other -> Other registration offices + Holds all other entries + + Returns: + + """ + self.queryset_registration_office_unb = self.queryset.filter( + intervention__responsible__registration_office__parent__id=self.id_unb + ) + self.queryset_registration_office_unb_recorded = self.queryset_registration_office_unb.filter( + intervention__recorded__isnull=False, + ) + self.queryset_registration_office_unb_checked = self.queryset_registration_office_unb.filter( + intervention__checked__isnull=False, + ) + + self.queryset_registration_office_tbp = self.queryset.filter( + intervention__responsible__registration_office__parent__id=self.id_tbp + ) + self.queryset_registration_office_tbp_recorded = self.queryset_registration_office_tbp.filter( + intervention__recorded__isnull=False, + ) + self.queryset_registration_office_tbp_checked = self.queryset_registration_office_tbp.filter( + intervention__checked__isnull=False, + ) + + self.queryset_registration_office_other = self.queryset.exclude( + Q(id__in=self.queryset_registration_office_tbp) | Q(id__in=self.queryset_registration_office_unb) + ) + self.queryset_registration_office_other_recorded = self.queryset_registration_office_other.filter( + intervention__recorded__isnull=False, + ) + self.queryset_registration_office_other_checked = self.queryset_registration_office_other.filter( + intervention__checked__isnull=False, + ) + def __init__(self, office_id: str): self.office_id = office_id self.intervention_report = self.InterventionReport(self.office_id) + self.compensation_report = self.CompensationReport(self.office_id) diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index 9b21d9f7..1523b7ae 100644 Binary files a/locale/de/LC_MESSAGES/django.mo and b/locale/de/LC_MESSAGES/django.mo differ diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index 7c47ddac..17306e74 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -19,7 +19,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-19 08:40+0200\n" +"POT-Creation-Date: 2021-10-19 13:23+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -37,13 +37,6 @@ msgstr "" msgid "Report" msgstr "Bericht" -#: analysis/templates/analysis/reports/includes/card_compensation.html:11 -#: compensation/tables.py:62 -#: intervention/templates/intervention/detail/includes/compensations.html:8 -#: intervention/templates/intervention/report/report.html:49 -msgid "Compensations" -msgstr "Kompensationen" - #: analysis/templates/analysis/reports/includes/card_eco_account.html:11 msgid "Eco-Accounts" msgstr "Ökokonten" @@ -56,6 +49,7 @@ msgstr "Altfälle" msgid "Before" msgstr "Vor" +#: analysis/templates/analysis/reports/includes/compensation/amount.html:3 #: analysis/templates/analysis/reports/includes/intervention/amount.html:3 #: compensation/forms/modalForms.py:351 #: compensation/templates/compensation/detail/eco_account/includes/deductions.html:34 @@ -63,6 +57,7 @@ msgstr "Vor" msgid "Amount" msgstr "Menge" +#: analysis/templates/analysis/reports/includes/compensation/amount.html:5 #: analysis/templates/analysis/reports/includes/intervention/amount.html:5 msgid "" "\n" @@ -74,6 +69,7 @@ msgstr "" " Geprüft = Wurde von der zuständigen Zulassungsbehörde überprüft\n" " " +#: analysis/templates/analysis/reports/includes/compensation/amount.html:9 #: analysis/templates/analysis/reports/includes/intervention/amount.html:9 msgid "" "\n" @@ -81,9 +77,53 @@ msgid "" " " msgstr "" "\n" -" Verzeichnet = Wurde von der Eintragungsstelle überprüft und veröffentlicht\n" +" Verzeichnet = Wurde von der Eintragungsstelle überprüft und " +"veröffentlicht\n" " " +#: analysis/templates/analysis/reports/includes/compensation/amount.html:17 +msgid "Area of responsibility" +msgstr "Zuständigkeitsbereich" + +#: analysis/templates/analysis/reports/includes/compensation/amount.html:18 +#: analysis/templates/analysis/reports/includes/compensation/card_compensation.html:11 +#: compensation/tables.py:62 +#: intervention/templates/intervention/detail/includes/compensations.html:8 +#: intervention/templates/intervention/report/report.html:49 +msgid "Compensations" +msgstr "Kompensationen" + +#: analysis/templates/analysis/reports/includes/compensation/amount.html:19 +#: analysis/templates/analysis/reports/includes/intervention/amount.html:19 +#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:10 +#: analysis/templates/analysis/reports/includes/intervention/laws.html:20 +#: compensation/tables.py:41 compensation/tables.py:181 +#: compensation/templates/compensation/detail/compensation/view.html:57 +#: compensation/templates/compensation/detail/eco_account/includes/deductions.html:31 +#: compensation/templates/compensation/detail/eco_account/view.html:44 +#: ema/tables.py:38 ema/templates/ema/detail/view.html:28 +#: intervention/tables.py:39 +#: intervention/templates/intervention/detail/view.html:82 user/models.py:49 +msgid "Recorded" +msgstr "Verzeichnet" + +#: analysis/templates/analysis/reports/includes/compensation/amount.html:20 +msgid "Number single areas" +msgstr "Einzelflächen" + +#: analysis/templates/analysis/reports/includes/compensation/amount.html:25 +msgid "Conservation office by law" +msgstr "Naturschutzbehörde (§17 Abs.3 BNatSchG)" + +#: analysis/templates/analysis/reports/includes/compensation/amount.html:31 +msgid "Other registration office" +msgstr "Andere Zulassungsbehörden" + +#: analysis/templates/analysis/reports/includes/compensation/amount.html:37 +msgid "Land-use planning" +msgstr "Träger Bauleitplanung" + +#: analysis/templates/analysis/reports/includes/compensation/amount.html:43 #: analysis/templates/analysis/reports/includes/intervention/amount.html:17 #: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:8 #: analysis/templates/analysis/reports/includes/intervention/laws.html:23 @@ -103,19 +143,6 @@ msgstr "Insgesamt" msgid "Checked" msgstr "Geprüft" -#: analysis/templates/analysis/reports/includes/intervention/amount.html:19 -#: analysis/templates/analysis/reports/includes/intervention/compensated_by.html:10 -#: analysis/templates/analysis/reports/includes/intervention/laws.html:20 -#: compensation/tables.py:41 compensation/tables.py:181 -#: compensation/templates/compensation/detail/compensation/view.html:57 -#: compensation/templates/compensation/detail/eco_account/includes/deductions.html:31 -#: compensation/templates/compensation/detail/eco_account/view.html:44 -#: ema/tables.py:38 ema/templates/ema/detail/view.html:28 -#: intervention/tables.py:39 -#: intervention/templates/intervention/detail/view.html:82 user/models.py:49 -msgid "Recorded" -msgstr "Verzeichnet" - #: analysis/templates/analysis/reports/includes/intervention/card_intervention.html:10 #: intervention/tables.py:66 msgid "Interventions" @@ -158,8 +185,9 @@ msgid "" " " msgstr "" "\n" -" Beachten Sie: Ein Eingriff kann mehreren Gesetzen zugeordnet worden sein. Diese Tabelle zählt daher nicht die Eingriffe selbst " -", sondern wie oft ein Gesetz Anwendung fand.\n" +" Beachten Sie: Ein Eingriff kann mehreren Gesetzen zugeordnet worden " +"sein. Diese Tabelle zählt daher nicht die Eingriffe selbst , sondern wie oft " +"ein Gesetz Anwendung fand.\n" " " #: analysis/templates/analysis/reports/includes/intervention/laws.html:14