231 lines
7.1 KiB
Python
231 lines
7.1 KiB
Python
# coding=utf-8
|
|
|
|
from django.db.models import Sum
|
|
from decimal import Decimal
|
|
from .models import (
|
|
Transaction,
|
|
TransactionType,
|
|
Patrimony,
|
|
PatrimonyType,
|
|
RightEngagementType,
|
|
RightEngagement,
|
|
)
|
|
|
|
|
|
def get_transaction_and_sum_ooo(year, param):
|
|
lines = (
|
|
Transaction.objects.filter(registrationDate__year=year)
|
|
.filter(transaction_type__transaction_type=param)
|
|
.order_by("registrationDate")
|
|
)
|
|
sum_BkAmount = 0
|
|
sum_BxAmount = 0
|
|
sum_TotalAmount = 0
|
|
|
|
for line in lines:
|
|
sum_BkAmount = sum_BkAmount + line.bkAmount
|
|
sum_BxAmount = sum_BxAmount + line.bxAmount
|
|
sum_TotalAmount = sum_TotalAmount + line.totalAmount
|
|
|
|
return {
|
|
"lines": lines,
|
|
"sum_BkAmount": sum_BkAmount,
|
|
"sum_BxAmount": sum_BxAmount,
|
|
"sum_TotalAmount": sum_TotalAmount,
|
|
}
|
|
|
|
|
|
def get_transaction_and_sum_sxs(year, param):
|
|
"""
|
|
On va chercher tous les types de transactions qui existent.
|
|
|
|
Ensuite, pour chacun d'eux, on va sélectionner toutes les transactions appartenant à ce
|
|
type de transactions et qui sont `effectuées` et `non simulées` ; et on additionne le
|
|
montant total de la transaction.
|
|
"""
|
|
|
|
i = 0
|
|
transaction_sum = []
|
|
transaction_type_list = TransactionType.objects.filter(
|
|
transaction_type=param, parent=None
|
|
).order_by("order")
|
|
|
|
for transaction_type in transaction_type_list:
|
|
j = 0
|
|
|
|
sum_value = list(
|
|
Transaction.objects.filter(
|
|
registrationDate__year=year,
|
|
transaction_type=transaction_type,
|
|
is_simulated=False,
|
|
is_done=True,
|
|
)
|
|
.aggregate(Sum("totalAmount"))
|
|
.values()
|
|
)[0]
|
|
|
|
transaction_sum.append(
|
|
[
|
|
# le label de mon `type de transaction`
|
|
transaction_type.label,
|
|
# la catégorie du type de transaction (e.g. Machandise, Service, Cotisation, …)
|
|
transaction_type.category,
|
|
# le parent du type de transaction (ou None)
|
|
None, # transaction_type.parent,
|
|
sum_value if sum_value is not None else Decimal(0.00),
|
|
transaction_type.id, # l'ID du type de transaction
|
|
]
|
|
)
|
|
|
|
# print(transaction_sum[-1][4])
|
|
# Cela affiche ce qu'il faut, dans l'ordre ou il faut. L'information est donc présente ici.
|
|
# print(str(transaction_sum.count()) + ' : ' + transaction_sum[-1][4])
|
|
|
|
transaction_subtype = TransactionType.objects.filter(
|
|
parent=transaction_type
|
|
).order_by("order")
|
|
|
|
for subtype in transaction_subtype:
|
|
subtype_sum_value = list(
|
|
Transaction.objects.filter(
|
|
registrationDate__year=year,
|
|
transaction_type=subtype,
|
|
is_simulated=False,
|
|
is_done=True,
|
|
)
|
|
.aggregate(Sum("totalAmount"))
|
|
.values()
|
|
)[0]
|
|
transaction_sum.append(
|
|
[
|
|
subtype.label,
|
|
subtype.category,
|
|
subtype.parent,
|
|
subtype_sum_value if sum_value is not None else Decimal(0.00),
|
|
subtype.id,
|
|
]
|
|
)
|
|
|
|
if subtype_sum_value is not None:
|
|
transaction_sum[i][3] += subtype_sum_value
|
|
j += 1
|
|
|
|
i = i + j + 1
|
|
|
|
# print('______________________________________________')
|
|
# for transaction_line in transaction_sum:
|
|
# print(transaction_line) # ICI L'INFORMATION N'EST ***PLUS*** PRESENTE !!!
|
|
|
|
total_transaction = 0
|
|
for depense in transaction_sum:
|
|
if depense[2] is None and depense[3] is not None:
|
|
total_transaction += depense[3]
|
|
|
|
return {"sum": transaction_sum, "total": total_transaction}
|
|
|
|
|
|
def get_transaction_and_sum_spf(year, param):
|
|
"""
|
|
"""
|
|
|
|
transaction_sum = []
|
|
transaction_type_list = TransactionType.objects.filter(
|
|
transaction_type=param, parent=None
|
|
).order_by("order")
|
|
for transaction_type in transaction_type_list:
|
|
sum_value = 0
|
|
# Somme du père
|
|
tmp = list(
|
|
Transaction.objects.filter(
|
|
registrationDate__year=year,
|
|
transaction_type=transaction_type,
|
|
is_simulated=False,
|
|
is_done=True,
|
|
)
|
|
.aggregate(Sum("totalAmount"))
|
|
.values()
|
|
)[0]
|
|
if tmp is not None:
|
|
sum_value = tmp
|
|
|
|
# Selection des fils
|
|
compta_subtype_list = TransactionType.objects.filter(
|
|
parent=transaction_type
|
|
).order_by("order")
|
|
for subtype in compta_subtype_list:
|
|
# Somme des fils
|
|
# , is_done = False, is_simulated = False ??
|
|
tmp = list(
|
|
Transaction.objects.filter(
|
|
registrationDate__year=year,
|
|
transaction_type=subtype,
|
|
is_simulated=False,
|
|
is_done=True,
|
|
)
|
|
.aggregate(Sum("totalAmount"))
|
|
.values()
|
|
)[0]
|
|
|
|
if tmp is not None:
|
|
sum_value += tmp
|
|
|
|
transaction_sum.append(
|
|
[
|
|
transaction_type.label,
|
|
sum_value if sum_value is not None else Decimal(0.00),
|
|
transaction_type.category,
|
|
]
|
|
)
|
|
|
|
total_transaction = 0
|
|
for transaction in transaction_sum:
|
|
if transaction[1] is not None:
|
|
total_transaction += transaction[1]
|
|
|
|
# print(transaction_sum)
|
|
|
|
return {"sum": transaction_sum, "total": total_transaction}
|
|
|
|
|
|
def get_right_engagement_and_sump_spf(year, category):
|
|
"""
|
|
Va chercher tous les types de droits et d'engagements. Pour chacun de ces types, va chercher
|
|
l'ensemble lignes correspondantes et sommes les montants.
|
|
"""
|
|
|
|
line_sum = []
|
|
right_engagement_list = RightEngagementType.objects.filter(
|
|
category=category
|
|
).order_by("order")
|
|
for line in right_engagement_list:
|
|
tmp = list(
|
|
RightEngagement.objects.filter(registrationDate__year=year, r_e_type=line)
|
|
.aggregate(Sum("amount"))
|
|
.values()
|
|
)[0]
|
|
line_sum.append([line.label, tmp if tmp is not None else Decimal(0.00)])
|
|
return line_sum
|
|
|
|
|
|
def get_asset_liability_and_sump_spf(year, category):
|
|
"""
|
|
Va chercher tous les types de droits et dettes. Pour chacun de ces types, va chercher
|
|
l'ensemble lignes correspondantes et sommes les montants.
|
|
"""
|
|
|
|
line_sum = []
|
|
asset_liability_list = PatrimonyType.objects.filter(category=category).order_by(
|
|
"order"
|
|
)
|
|
# print(asset_liability_list)
|
|
for line in asset_liability_list:
|
|
# print(line)
|
|
tmp = list(
|
|
Patrimony.objects.filter(registrationDate__year=year, patrimony_type=line)
|
|
.aggregate(Sum("totalAmount"))
|
|
.values()
|
|
)[0]
|
|
line_sum.append([line.label, tmp if tmp is not None else Decimal(0.00)])
|
|
# print(line_sum)
|
|
return line_sum
|