minus_area in premise, calculation of areas and factors
This commit is contained in:
@ -23,7 +23,8 @@ def perform(dbh, params):
|
||||
select sum(ae.amount) as sum,
|
||||
aec.description as category,
|
||||
p.id as house_id,
|
||||
p.description as house
|
||||
p.description as house,
|
||||
aec.considerminusarea as considerminusarea
|
||||
from account_t a,
|
||||
premise_t p,
|
||||
account_entry_t ae,
|
||||
@ -32,14 +33,15 @@ def perform(dbh, params):
|
||||
ae.account = a.id and
|
||||
aec.overhead_relevant = 't' and
|
||||
ae.account_entry_category = aec.id and
|
||||
created_at between %(startDate)s and %(endDate)s and
|
||||
ae.fiscal_year = %(year)s and
|
||||
p.id in %(premises)s
|
||||
group by house_id, house, category
|
||||
group by house_id, house, category, considerminusarea
|
||||
union
|
||||
select 0 as sum,
|
||||
aec.description as category,
|
||||
p.id as house_id,
|
||||
p.description as house
|
||||
p.description as house,
|
||||
aec.considerminusarea as considerminusarea
|
||||
from account_t a,
|
||||
premise_t p,
|
||||
account_entry_t ae,
|
||||
@ -48,28 +50,28 @@ def perform(dbh, params):
|
||||
ae.account = a.id and
|
||||
aec.overhead_relevant = 't' and
|
||||
aec.id not in (select distinct account_entry_category from account_entry_t) and
|
||||
created_at between %(startDate)s and %(endDate)s and
|
||||
ae.fiscal_year = %(year)s and
|
||||
p.id in %(premises)s
|
||||
group by house_id, house, category
|
||||
group by house_id, house, category, considerminusarea
|
||||
union
|
||||
select 120 as sum,
|
||||
'Waschmaschine' as category,
|
||||
id as house_id,
|
||||
description as house
|
||||
description as house,
|
||||
false as considerminusarea
|
||||
from premise_t
|
||||
where id in %(premises)s
|
||||
order by house_id, category
|
||||
""",
|
||||
"params": {
|
||||
"startDate": startDate,
|
||||
"endDate": endDate,
|
||||
"year": year,
|
||||
"premises": premises
|
||||
}
|
||||
}
|
||||
)
|
||||
# logger.info(f"{overheadSums=}")
|
||||
for overheadSum in overheadSums:
|
||||
logger.info(f"house: {overheadSum['house']}, category: {overheadSum['category']}, sum: {overheadSum['sum']}")
|
||||
logger.info(f"house: {overheadSum['house']}, considerMinusArea: {overheadSum['considerminusarea']}, category: {overheadSum['category']}, sum: {overheadSum['sum']}")
|
||||
|
||||
subtotal = {}
|
||||
for premise in premises:
|
||||
@ -79,6 +81,94 @@ def perform(dbh, params):
|
||||
logger.info(f"{subtotal=}")
|
||||
|
||||
|
||||
# get areas and factors
|
||||
totalAreas = {}
|
||||
flatAreas = dbGetMany(
|
||||
dbh,
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
select
|
||||
p.id as house_id,
|
||||
p.description as house,
|
||||
sum(f.area) as flat_area
|
||||
from
|
||||
premise_t p,
|
||||
flat_t f
|
||||
where
|
||||
f.premise = p.id and
|
||||
p.id in %(premises)s
|
||||
group by house_id
|
||||
""",
|
||||
"params": {
|
||||
"premises": premises
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
for area in flatAreas:
|
||||
logger.info(f"{area['house']=}, {area['flat_area']=}")
|
||||
totalAreas[area['house_id']] = { 'flat_area': area['flat_area'] }
|
||||
|
||||
commercialAreas = dbGetMany(
|
||||
dbh,
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
select
|
||||
p.id as house_id,
|
||||
p.description as house,
|
||||
coalesce(sum(c.area), 0) as commercial_area
|
||||
from
|
||||
premise_t p full outer join commercial_premise_t c on c.premise = p.id
|
||||
where
|
||||
p.id in %(premises)s
|
||||
group by house_id
|
||||
""",
|
||||
"params": {
|
||||
"premises": premises
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
for area in commercialAreas:
|
||||
logger.info(f"{area['house']=}, {area['commercial_area']=}")
|
||||
totalAreas[area['house_id']] |= { 'commercial_area': area['commercial_area'] }
|
||||
|
||||
minusAreas = dbGetMany(
|
||||
dbh,
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
select
|
||||
p.id as house_id,
|
||||
p.description as house,
|
||||
p.minus_area as minus_area
|
||||
from
|
||||
premise_t p
|
||||
where
|
||||
p.id in %(premises)s
|
||||
group by house_id
|
||||
""",
|
||||
"params": {
|
||||
"premises": premises
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
for area in minusAreas:
|
||||
logger.info(f"{area['house']=}, {area['minus_area']=}")
|
||||
totalAreas[area['house_id']] |= { 'minus_area': area['minus_area'] }
|
||||
|
||||
for premise in premises:
|
||||
totalAreas[premise]['other_area'] = totalAreas[premise]['commercial_area'] + totalAreas[premise]['minus_area']
|
||||
totalAreas[premise]['total_area'] = totalAreas[premise]['flat_area'] + totalAreas[premise]['other_area']
|
||||
totalAreas[premise]['flat_factor'] = totalAreas[premise]['flat_area'] / totalAreas[premise]['total_area']
|
||||
totalAreas[premise]['other_factor'] = totalAreas[premise]['other_area'] / totalAreas[premise]['total_area']
|
||||
totalAreas[premise]['factor_check'] = totalAreas[premise]['flat_factor'] + totalAreas[premise]['other_factor']
|
||||
logger.info(f"{totalAreas=}")
|
||||
|
||||
|
||||
|
||||
|
||||
# get flat tenants by object and timespan with paid overhead and due overhead
|
||||
@ -130,12 +220,11 @@ def perform(dbh, params):
|
||||
FROM account_entry_t
|
||||
WHERE account = %(account)s AND
|
||||
account_entry_category = 2 AND
|
||||
due_at BETWEEN %(startDate)s AND %(endDate)s
|
||||
fiscal_year = %(year)s
|
||||
""",
|
||||
"params": {
|
||||
"account": tenant['tenant_account'],
|
||||
"startDate": startDate,
|
||||
"endDate": endDate
|
||||
"year": year
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -149,12 +238,11 @@ def perform(dbh, params):
|
||||
FROM account_entry_t
|
||||
WHERE account = %(account)s AND
|
||||
account_entry_category = 3 AND
|
||||
due_at BETWEEN %(startDate)s AND %(endDate)s
|
||||
fiscal_year = %(year)s
|
||||
""",
|
||||
"params": {
|
||||
"account": tenant['tenant_account'],
|
||||
"startDate": startDate,
|
||||
"endDate": endDate
|
||||
"year": year
|
||||
}
|
||||
}
|
||||
)
|
||||
|
Reference in New Issue
Block a user