commercial unit area and overhead stuff
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
from db import dbGetMany
|
||||
from db import dbGetMany, dbGetOne
|
||||
import datetime
|
||||
from loguru import logger
|
||||
from decimal import *
|
||||
|
||||
def perform(dbh, params):
|
||||
try:
|
||||
@ -12,42 +13,6 @@ def perform(dbh, params):
|
||||
premises = (1, 2)
|
||||
|
||||
|
||||
# get flat tenants by object and timespan with paid overhead and due overhead
|
||||
tenants = dbGetMany(
|
||||
dbh,
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
select t.id as tenant_id,
|
||||
t.firstname as tenant_firstname,
|
||||
t.lastname as tenant_lastname,
|
||||
f.id as flat_id,
|
||||
f.description as flat,
|
||||
p.id as house_id,
|
||||
p.description as house,
|
||||
ty.startdate as startdate,
|
||||
ty.enddate as enddate
|
||||
from tenant_t t,
|
||||
premise_t p,
|
||||
flat_t f,
|
||||
tenancy_t ty
|
||||
where ty.tenant = t.id and
|
||||
ty.flat = f.id and
|
||||
ty.startdate >= %(startDate)s and
|
||||
(ty.enddate <= %(endDate)s or ty.enddate is null) and
|
||||
f.premise = p.id and
|
||||
p.id in %(premises)s
|
||||
order by house_id, tenant_id
|
||||
""",
|
||||
"params": {
|
||||
"startDate": startDate,
|
||||
"endDate": endDate,
|
||||
"premises": premises
|
||||
}
|
||||
}
|
||||
)
|
||||
logger.info(f"{tenants=}")
|
||||
|
||||
|
||||
# get overhead sums by object, category and timespan
|
||||
overheadSums = dbGetMany(
|
||||
@ -86,6 +51,13 @@ def perform(dbh, params):
|
||||
created_at between %(startDate)s and %(endDate)s and
|
||||
p.id in %(premises)s
|
||||
group by house_id, house, category
|
||||
union
|
||||
select 120 as sum,
|
||||
'Waschmaschine' as category,
|
||||
id as house_id,
|
||||
description as house
|
||||
from premise_t
|
||||
where id in %(premises)s
|
||||
order by house_id, category
|
||||
""",
|
||||
"params": {
|
||||
@ -95,7 +67,106 @@ def perform(dbh, params):
|
||||
}
|
||||
}
|
||||
)
|
||||
logger.info(f"{overheadSums=}")
|
||||
# logger.info(f"{overheadSums=}")
|
||||
for overheadSum in overheadSums:
|
||||
logger.info(f"house: {overheadSum['house']}, category: {overheadSum['category']}, sum: {overheadSum['sum']}")
|
||||
|
||||
subtotal = {}
|
||||
for premise in premises:
|
||||
v = [ x['sum'] for x in overheadSums if x['house_id'] == premise ]
|
||||
logger.info(f"{v=}")
|
||||
subtotal[premise] = sum(v)
|
||||
logger.info(f"{subtotal=}")
|
||||
|
||||
|
||||
|
||||
|
||||
# get flat tenants by object and timespan with paid overhead and due overhead
|
||||
tenants = dbGetMany(
|
||||
dbh,
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
select t.id as tenant_id,
|
||||
t.firstname as tenant_firstname,
|
||||
t.lastname as tenant_lastname,
|
||||
f.id as flat_id,
|
||||
f.description as flat,
|
||||
p.id as house_id,
|
||||
p.description as house,
|
||||
ty.startdate as startdate,
|
||||
ty.enddate as enddate,
|
||||
t.account as tenant_account
|
||||
from tenant_t t,
|
||||
premise_t p,
|
||||
flat_t f,
|
||||
tenancy_t ty
|
||||
where ty.tenant = t.id and
|
||||
ty.flat = f.id and
|
||||
ty.startdate <= %(startDate)s and
|
||||
(ty.enddate >= %(endDate)s or ty.enddate is null) and
|
||||
f.premise = p.id and
|
||||
p.id in %(premises)s
|
||||
order by house_id, tenant_id
|
||||
""",
|
||||
"params": {
|
||||
"startDate": startDate,
|
||||
"endDate": endDate,
|
||||
"premises": premises
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
for tenant in tenants:
|
||||
logger.info(f"firstname: {tenant['tenant_firstname']}, lastname: {tenant['tenant_lastname']}, house: {tenant['house']}, account: {tenant['tenant_account']}")
|
||||
|
||||
paidTotal = dbGetOne(
|
||||
dbh,
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
SELECT sum(amount) AS sum,
|
||||
count(id) AS cnt
|
||||
FROM account_entry_t
|
||||
WHERE account = %(account)s AND
|
||||
account_entry_category = 2 AND
|
||||
due_at BETWEEN %(startDate)s AND %(endDate)s
|
||||
""",
|
||||
"params": {
|
||||
"account": tenant['tenant_account'],
|
||||
"startDate": startDate,
|
||||
"endDate": endDate
|
||||
}
|
||||
}
|
||||
)
|
||||
receivableFee = dbGetOne(
|
||||
dbh,
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
SELECT sum(amount) * -1 AS sum ,
|
||||
count(id) AS cnt
|
||||
FROM account_entry_t
|
||||
WHERE account = %(account)s AND
|
||||
account_entry_category = 3 AND
|
||||
due_at BETWEEN %(startDate)s AND %(endDate)s
|
||||
""",
|
||||
"params": {
|
||||
"account": tenant['tenant_account'],
|
||||
"startDate": startDate,
|
||||
"endDate": endDate
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
logger.info(f"Payments: cnt: {paidTotal['cnt']}, sum: {paidTotal['sum']}")
|
||||
logger.info(f"Receivable fees: cnt: {receivableFee['cnt']}, sum: {receivableFee['sum']}")
|
||||
|
||||
paidOverheadAdvance = paidTotal['sum'] - receivableFee['sum']
|
||||
logger.info(f"Paid overhead: {paidOverheadAdvance} (by month: {paidOverheadAdvance / Decimal(12)})")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user