tenant overview added
This commit is contained in:
@ -4,8 +4,8 @@ from loguru import logger
|
||||
from decimal import *
|
||||
from utils import getParam
|
||||
from Cheetah.Template import Template
|
||||
|
||||
|
||||
import xlsxwriter
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
EPSILON = Decimal('0.000000001')
|
||||
|
||||
@ -190,6 +190,7 @@ def perform(dbh, params):
|
||||
|
||||
|
||||
|
||||
|
||||
# get flat tenants by object and timespan with paid overhead and due overhead
|
||||
tenants = dbGetMany(
|
||||
dbh,
|
||||
@ -212,17 +213,23 @@ def perform(dbh, params):
|
||||
p.description as house,
|
||||
ty.startdate as startdate,
|
||||
ty.enddate as enddate,
|
||||
t.account as tenant_account
|
||||
t.account as tenant_account,
|
||||
fe.amount as fee,
|
||||
fe.fee_type as fee_type
|
||||
from tenant_t t,
|
||||
premise_t p,
|
||||
flat_t f,
|
||||
tenancy_t ty
|
||||
tenancy_t ty,
|
||||
tenancy_fee_mapping_t tyfm,
|
||||
fee_t fe
|
||||
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
|
||||
p.id in %(premises)s and
|
||||
tyfm.tenancy = ty.id and
|
||||
tyfm.fee = fe.id
|
||||
order by house_id, tenant_id
|
||||
""",
|
||||
"params": {
|
||||
@ -242,8 +249,7 @@ def perform(dbh, params):
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
SELECT sum(amount) AS sum,
|
||||
count(id) AS cnt
|
||||
SELECT sum(amount) AS sum
|
||||
FROM account_entry_t
|
||||
WHERE account = %(account)s AND
|
||||
account_entry_category = 2 AND
|
||||
@ -262,8 +268,7 @@ def perform(dbh, params):
|
||||
{
|
||||
"statement":
|
||||
"""
|
||||
SELECT sum(amount) * -1 AS sum ,
|
||||
count(id) AS cnt
|
||||
SELECT sum(amount) * -1 AS sum
|
||||
FROM account_entry_t
|
||||
WHERE account = %(account)s AND
|
||||
account_entry_category = 3 AND
|
||||
@ -276,7 +281,9 @@ def perform(dbh, params):
|
||||
}
|
||||
)
|
||||
tenant['receivable_fee'] = receivableFee['sum']
|
||||
tenant['rent_time'] = receivableFee['cnt']
|
||||
|
||||
delta = relativedelta((tenant['enddate'] or datetime.date(year, 12, 31)), (tenant['startdate'] if (tenant['startdate'].year == year) else datetime.date(year, 1, 1)))
|
||||
tenant['rent_time'] = delta.months if delta.days == 0 else delta.months + 1
|
||||
|
||||
tenant['paid_overhead'] = paidTotal['sum'] - receivableFee['sum']
|
||||
|
||||
@ -307,8 +314,49 @@ def perform(dbh, params):
|
||||
with open(outputFile, 'w') as f:
|
||||
f.write(str(tmpl))
|
||||
|
||||
if printOverviews:
|
||||
tenantsOverviewPrefix = getParam(params, 'tenantsOverviewPrefix', 'tenantsOverview')
|
||||
tenantsOverviewSuffix = getParam(params, 'tenantsOverviewSuffix', 'xlsx')
|
||||
|
||||
logger.debug(f"Processing letters: {letters}")
|
||||
outputFile = f"./output/{tenantsOverviewPrefix}-{year}.{tenantsOverviewSuffix}"
|
||||
|
||||
workbook = xlsxwriter.Workbook(outputFile)
|
||||
worksheet = workbook.add_worksheet()
|
||||
|
||||
worksheet.write(0, 0, 'id')
|
||||
worksheet.write(0, 1, 'lastname')
|
||||
worksheet.write(0, 2, 'firstname')
|
||||
worksheet.write(0, 3, 'house')
|
||||
worksheet.write(0, 4, 'overhead_part_by_montharea')
|
||||
worksheet.write(0, 5, 'flat')
|
||||
worksheet.write(0, 6, 'flat_area')
|
||||
worksheet.write(0, 7, 'fee')
|
||||
worksheet.write(0, 8, 'rent_time')
|
||||
worksheet.write(0, 9, 'paid_total')
|
||||
worksheet.write(0, 10, 'receivable_fee')
|
||||
worksheet.write(0, 11, 'paid_overhead')
|
||||
worksheet.write(0, 12, 'receivable_overhead')
|
||||
worksheet.write(0, 13, 'unbalanced_overhead')
|
||||
|
||||
row = 1
|
||||
|
||||
for entry in letters:
|
||||
worksheet.write(row, 0, entry['tenant']['tenant_id'])
|
||||
worksheet.write(row, 1, entry['tenant']['tenant_lastname'])
|
||||
worksheet.write(row, 2, entry['tenant']['tenant_firstname'])
|
||||
worksheet.write(row, 3, entry['tenant']['house'])
|
||||
worksheet.write(row, 4, houses[entry['tenant']['house_id']]['part_by_montharea'])
|
||||
worksheet.write(row, 5, entry['tenant']['flat'])
|
||||
worksheet.write(row, 6, entry['tenant']['flat_area'])
|
||||
worksheet.write(row, 7, entry['tenant']['fee'])
|
||||
worksheet.write(row, 8, entry['tenant']['rent_time'])
|
||||
worksheet.write(row, 9, entry['tenant']['paid_total'])
|
||||
worksheet.write(row, 10, entry['tenant']['receivable_fee'])
|
||||
worksheet.write(row, 11, entry['tenant']['paid_overhead'])
|
||||
worksheet.write(row, 12, entry['receivable_overhead'])
|
||||
worksheet.write(row, 13, entry['unbalanced_overhead'])
|
||||
row += 1
|
||||
|
||||
workbook.close()
|
||||
|
||||
|
Reference in New Issue
Block a user