@@ -11,7 +11,7 @@
|
||||
<div class="col-sm-12 col-md-12 col-lg-12">
|
||||
{% include 'analysis/reports/includes/intervention/card_intervention.html' %}
|
||||
{% include 'analysis/reports/includes/compensation/card_compensation.html' %}
|
||||
{% include 'analysis/reports/includes/card_eco_account.html' %}
|
||||
{% include 'analysis/reports/includes/eco_account/card_eco_account.html' %}
|
||||
{% include 'analysis/reports/includes/old_intervention/card_old_interventions.html' %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,32 @@
|
||||
{% load i18n fontawesome_5 ksp_filters %}
|
||||
|
||||
<h3>{% trans 'Amount' %}</h3>
|
||||
<strong>
|
||||
{% blocktrans %}
|
||||
Checked = Has been checked by the registration office according to LKompVzVo
|
||||
{% endblocktrans %}
|
||||
<br>
|
||||
{% blocktrans %}
|
||||
Recorded = Has been checked and published by the conservation office
|
||||
{% endblocktrans %}
|
||||
</strong>
|
||||
<div class="table-container">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{% trans 'Before' %} LKompVzVo</th>
|
||||
<th scope="col">{% trans 'After' %} LKompVzVo</th>
|
||||
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
||||
<th scope="col" class="w-25">{% trans 'Total' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{report.eco_account_report.queryset_old.count|default_if_zero:"-"}}</td>
|
||||
<td>{{report.eco_account_report.queryset.count|default_if_zero:"-"}}</td>
|
||||
<td>{{report.eco_account_report.queryset_recorded.count|default_if_zero:"-"}}</td>
|
||||
<td>{{report.eco_account_report.queryset_total.count|default_if_zero:"-"}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -15,7 +15,9 @@
|
||||
</div>
|
||||
<div id="ecoAccountsBody" class="collapse" aria-labelledby="ecoAccounts">
|
||||
<div class="card-body">
|
||||
{% include 'form/table/generic_table_form_body.html' %}
|
||||
{% include 'analysis/reports/includes/eco_account/amount.html' %}
|
||||
<hr>
|
||||
{% include 'analysis/reports/includes/eco_account/deductions.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,23 @@
|
||||
{% load i18n fontawesome_5 ksp_filters %}
|
||||
|
||||
<h3>{% trans 'Deductions' %}</h3>
|
||||
<div class="table-container">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %}</th>
|
||||
<th scope="col">{% fa5_icon 'bookmark' %} {% trans 'Recorded' %} {% trans 'Surface' %}</th>
|
||||
<th scope="col" class="w-25">{% trans 'Total' %}</th>
|
||||
<th scope="col" class="w-25">{% trans 'Total' %} {% trans 'Surface' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{report.eco_account_report.queryset_deductions_recorded.count|default_if_zero:"-"}}</td>
|
||||
<td>{{report.eco_account_report.recorded_deductions_sq_m|default_if_zero:"-"}}m²</td>
|
||||
<td>{{report.eco_account_report.queryset_deductions_recorded.count|default_if_zero:"-"}}</td>
|
||||
<td>{{report.eco_account_report.deductions_sq_m|default_if_zero:"-"}}m²</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -5,13 +5,16 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 18.10.21
|
||||
|
||||
"""
|
||||
from django.contrib.gis.db.models import MultiPolygonField
|
||||
from django.contrib.gis.db.models.functions import NumGeometries
|
||||
from django.contrib.gis.measure import Area
|
||||
from django.db.models import Count, Sum, Q
|
||||
from django.db.models.functions import Cast
|
||||
|
||||
from analysis.settings import LKOMPVZVO_PUBLISH_DATE
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_LAW_ID
|
||||
from compensation.models import Compensation, Payment, EcoAccountDeduction
|
||||
from compensation.models import Compensation, Payment, EcoAccountDeduction, EcoAccount
|
||||
from intervention.models import Intervention
|
||||
from konova.models import Geometry
|
||||
|
||||
@@ -217,7 +220,9 @@ class TimespanReport:
|
||||
return Geometry.objects.filter(
|
||||
id__in=ids
|
||||
).annotate(
|
||||
num=NumGeometries("geom")
|
||||
geom_cast=Cast("geom", MultiPolygonField())
|
||||
).annotate(
|
||||
num=NumGeometries("geom_cast")
|
||||
).aggregate(
|
||||
num_geoms=Sum("num")
|
||||
)["num_geoms"] or 0
|
||||
@@ -265,6 +270,61 @@ class TimespanReport:
|
||||
intervention__checked__isnull=False,
|
||||
)
|
||||
|
||||
class EcoAccountReport:
|
||||
queryset = EcoAccount.objects.none()
|
||||
queryset_recorded = EcoAccount.objects.none()
|
||||
queryset_old = EcoAccount.objects.none()
|
||||
queryset_deductions = EcoAccountDeduction.objects.none()
|
||||
queryset_deductions_recorded = EcoAccountDeduction.objects.none()
|
||||
queryset_has_deductions = EcoAccountDeduction.objects.none()
|
||||
|
||||
# Total size of deductions
|
||||
deductions_sq_m = -1
|
||||
recorded_deductions_sq_m = -1
|
||||
|
||||
def __init__(self, id: str):
|
||||
# First fetch all eco account for this office
|
||||
self.queryset_total = EcoAccount.objects.filter(
|
||||
responsible__conservation_office__id=id,
|
||||
deleted=None,
|
||||
)
|
||||
self.queryset_recorded = self.queryset_total.filter(
|
||||
recorded__isnull=False
|
||||
)
|
||||
# Then fetch the old ones (pre-LKompVzVo)
|
||||
self.queryset_old = self.queryset_total.filter(
|
||||
recorded__timestamp__lte=LKOMPVZVO_PUBLISH_DATE,
|
||||
)
|
||||
# Then fetch the default queryset with the new ones (post-LKompVzVo)
|
||||
self.queryset = self.queryset_total.filter(
|
||||
recorded__timestamp__gte=LKOMPVZVO_PUBLISH_DATE,
|
||||
)
|
||||
# Fetch all related deductions
|
||||
self.queryset_deductions = EcoAccountDeduction.objects.filter(
|
||||
account__id__in=self.queryset.values_list("id")
|
||||
)
|
||||
# Fetch deductions for interventions which are already recorded
|
||||
self.queryset_deductions_recorded = self.queryset_deductions.filter(
|
||||
intervention__recorded__isnull=False
|
||||
)
|
||||
self._create_report()
|
||||
|
||||
def _create_report(self):
|
||||
""" Creates all report information
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self._evaluate_deductions()
|
||||
|
||||
def _evaluate_deductions(self):
|
||||
self.deductions_sq_m = self.queryset_deductions.aggregate(
|
||||
sum=Sum("surface")
|
||||
)["sum"]
|
||||
self.recorded_deductions_sq_m = self.queryset_deductions_recorded.aggregate(
|
||||
sum=Sum("surface")
|
||||
)["sum"]
|
||||
|
||||
class OldInterventionReport:
|
||||
queryset = Compensation.objects.none()
|
||||
queryset_checked = Compensation.objects.none()
|
||||
@@ -287,4 +347,5 @@ class TimespanReport:
|
||||
self.office_id = office_id
|
||||
self.intervention_report = self.InterventionReport(self.office_id)
|
||||
self.compensation_report = self.CompensationReport(self.office_id)
|
||||
self.eco_account_report = self.EcoAccountReport(self.office_id)
|
||||
self.old_intervention_report = self.OldInterventionReport(self.office_id)
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Count, Q, Sum
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
|
||||
from analysis.utils.report import TimespanReport
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_LAW_ID
|
||||
from compensation.models import EcoAccount, Compensation
|
||||
from ema.models import Ema
|
||||
from intervention.models import Intervention
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import conservation_office_group_required
|
||||
|
||||
|
||||
Reference in New Issue
Block a user