commercial unit area and overhead stuff
This commit is contained in:
parent
cb632e9e8e
commit
0e4fd12238
@ -813,6 +813,7 @@ SELECT
|
|||||||
id
|
id
|
||||||
,description
|
,description
|
||||||
,premise
|
,premise
|
||||||
|
,area
|
||||||
FROM commercial_premise_t
|
FROM commercial_premise_t
|
||||||
ORDER BY
|
ORDER BY
|
||||||
premise
|
premise
|
||||||
@ -827,21 +828,25 @@ def insert_commercial_premise(user, token_info, **args):
|
|||||||
body = args["body"]
|
body = args["body"]
|
||||||
v_description = body["description"]
|
v_description = body["description"]
|
||||||
v_premise = body["premise"]
|
v_premise = body["premise"]
|
||||||
|
v_area = body["area"]
|
||||||
return dbInsert(user, token_info, {
|
return dbInsert(user, token_info, {
|
||||||
"statement": """
|
"statement": """
|
||||||
INSERT INTO commercial_premise_t
|
INSERT INTO commercial_premise_t
|
||||||
(
|
(
|
||||||
description
|
description
|
||||||
,premise
|
,premise
|
||||||
|
,area
|
||||||
) VALUES (
|
) VALUES (
|
||||||
%s
|
%s
|
||||||
,%s
|
,%s
|
||||||
|
,%s
|
||||||
)
|
)
|
||||||
RETURNING *
|
RETURNING *
|
||||||
""",
|
""",
|
||||||
"params": [
|
"params": [
|
||||||
v_description
|
v_description
|
||||||
,v_premise
|
,v_premise
|
||||||
|
,v_area
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
@ -856,6 +861,7 @@ SELECT
|
|||||||
id
|
id
|
||||||
,description
|
,description
|
||||||
,premise
|
,premise
|
||||||
|
,area
|
||||||
FROM commercial_premise_t
|
FROM commercial_premise_t
|
||||||
WHERE id = %s
|
WHERE id = %s
|
||||||
""",
|
""",
|
||||||
@ -868,18 +874,21 @@ def update_commercial_premise(user, token_info, commercial_premiseId=None, **arg
|
|||||||
body = args["body"]
|
body = args["body"]
|
||||||
v_description = body["description"]
|
v_description = body["description"]
|
||||||
v_premise = body["premise"]
|
v_premise = body["premise"]
|
||||||
|
v_area = body["area"]
|
||||||
return dbUpdate(user, token_info, {
|
return dbUpdate(user, token_info, {
|
||||||
"statement": """
|
"statement": """
|
||||||
UPDATE commercial_premise_t
|
UPDATE commercial_premise_t
|
||||||
SET
|
SET
|
||||||
description = %s
|
description = %s
|
||||||
,premise = %s
|
,premise = %s
|
||||||
|
,area = %s
|
||||||
WHERE id = %s
|
WHERE id = %s
|
||||||
RETURNING *
|
RETURNING *
|
||||||
""",
|
""",
|
||||||
"params": [
|
"params": [
|
||||||
v_description,
|
v_description,
|
||||||
v_premise,
|
v_premise,
|
||||||
|
v_area,
|
||||||
commercial_premiseId
|
commercial_premiseId
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@ -895,6 +904,7 @@ SELECT
|
|||||||
id
|
id
|
||||||
,description
|
,description
|
||||||
,premise
|
,premise
|
||||||
|
,area
|
||||||
FROM commercial_premise_t
|
FROM commercial_premise_t
|
||||||
WHERE premise = %s
|
WHERE premise = %s
|
||||||
ORDER BY
|
ORDER BY
|
||||||
|
@ -1714,6 +1714,9 @@ components:
|
|||||||
premise:
|
premise:
|
||||||
type: integer
|
type: integer
|
||||||
nullable: true
|
nullable: true
|
||||||
|
area:
|
||||||
|
type: number
|
||||||
|
nullable: true
|
||||||
tenancy:
|
tenancy:
|
||||||
description: tenancy
|
description: tenancy
|
||||||
type: object
|
type: object
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from db import dbGetMany
|
from db import dbGetMany, dbGetOne
|
||||||
import datetime
|
import datetime
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
from decimal import *
|
||||||
|
|
||||||
def perform(dbh, params):
|
def perform(dbh, params):
|
||||||
try:
|
try:
|
||||||
@ -12,42 +13,6 @@ def perform(dbh, params):
|
|||||||
premises = (1, 2)
|
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
|
# get overhead sums by object, category and timespan
|
||||||
overheadSums = dbGetMany(
|
overheadSums = dbGetMany(
|
||||||
@ -86,6 +51,13 @@ def perform(dbh, params):
|
|||||||
created_at between %(startDate)s and %(endDate)s and
|
created_at between %(startDate)s and %(endDate)s and
|
||||||
p.id in %(premises)s
|
p.id in %(premises)s
|
||||||
group by house_id, house, category
|
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
|
order by house_id, category
|
||||||
""",
|
""",
|
||||||
"params": {
|
"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)})")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ def execDatabaseOperation(dbh, func, params):
|
|||||||
|
|
||||||
|
|
||||||
def _opGetMany(cursor, params):
|
def _opGetMany(cursor, params):
|
||||||
logger.warning(f"{params=}")
|
#logger.warning(f"{params=}")
|
||||||
items = []
|
items = []
|
||||||
cursor.execute(params["statement"], params["params"])
|
cursor.execute(params["statement"], params["params"])
|
||||||
for itemObj in cursor:
|
for itemObj in cursor:
|
||||||
|
@ -79,7 +79,8 @@
|
|||||||
"name": "commercial_premise",
|
"name": "commercial_premise",
|
||||||
"columns": [
|
"columns": [
|
||||||
{ "name": "description", "sqltype": "varchar(128)", "selector": 1 },
|
{ "name": "description", "sqltype": "varchar(128)", "selector": 1 },
|
||||||
{ "name": "premise", "sqltype": "integer", "foreignkey": true, "selector": 0 }
|
{ "name": "premise", "sqltype": "integer", "foreignkey": true, "selector": 0 },
|
||||||
|
{ "name": "area", "sqltype": "numeric(10,2)", "notnull": false }
|
||||||
],
|
],
|
||||||
"tableConstraints": [
|
"tableConstraints": [
|
||||||
"unique(description, premise)"
|
"unique(description, premise)"
|
||||||
|
@ -91,6 +91,7 @@ CREATE TABLE commercial_premise_t (
|
|||||||
id serial not null primary key
|
id serial not null primary key
|
||||||
,description varchar(128)
|
,description varchar(128)
|
||||||
,premise integer references premise_t (id)
|
,premise integer references premise_t (id)
|
||||||
|
,area numeric(10,2)
|
||||||
,unique(description, premise)
|
,unique(description, premise)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
<mat-option *ngFor="let p of premises" [value]="p.id">{{p.description}}</mat-option>
|
<mat-option *ngFor="let p of premises" [value]="p.id">{{p.description}}</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Fläche</mat-label>
|
||||||
|
<input type="number" matInput name="area" [(ngModel)]="commercialPremise.area"/>
|
||||||
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<button #submitButton type="submit" mat-raised-button color="primary">Speichern</button>
|
<button #submitButton type="submit" mat-raised-button color="primary">Speichern</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -119,11 +119,13 @@ export interface CommercialPremise {
|
|||||||
id: number
|
id: number
|
||||||
description: string
|
description: string
|
||||||
premise: number
|
premise: number
|
||||||
|
area: number
|
||||||
}
|
}
|
||||||
export const NULL_CommercialPremise: CommercialPremise = {
|
export const NULL_CommercialPremise: CommercialPremise = {
|
||||||
id: 0
|
id: 0
|
||||||
,description: ''
|
,description: ''
|
||||||
,premise: undefined
|
,premise: undefined
|
||||||
|
,area: undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Tenancy {
|
export interface Tenancy {
|
||||||
|
@ -19,8 +19,13 @@
|
|||||||
<th mat-header-cell *matHeaderCellDef>Haus</th>
|
<th mat-header-cell *matHeaderCellDef>Haus</th>
|
||||||
<td mat-cell *matCellDef="let element">{{element.premise.description}}</td>
|
<td mat-cell *matCellDef="let element">{{element.premise.description}}</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
<ng-container matColumnDef="area">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Fläche</th>
|
||||||
|
<td mat-cell *matCellDef="let element">{{element.commercialPremise.area | number:'1.2-2'}}</td>
|
||||||
|
</ng-container>
|
||||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="['/commercialunit/', row.commercialPremise.id]"></tr>
|
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="['/commercialunit/', row.commercialPremise.id]"></tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
|
@ -21,7 +21,7 @@ export class MyCommercialUnitsComponent implements OnInit {
|
|||||||
dnCommercialPremises: DN_CommercialPremise[] = []
|
dnCommercialPremises: DN_CommercialPremise[] = []
|
||||||
|
|
||||||
dataSource: MatTableDataSource<DN_CommercialPremise>
|
dataSource: MatTableDataSource<DN_CommercialPremise>
|
||||||
displayedColumns: string[] = ["description", "premise"]
|
displayedColumns: string[] = ["description", "premise", "area"]
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private commercialPremiseService: CommercialPremiseService,
|
private commercialPremiseService: CommercialPremiseService,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user