Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
d297eb60b3
|
|||
5744e84842
|
|||
b8083ec41e
|
|||
f559aba317
|
|||
97dfcbe2fb
|
|||
76255efbe9
|
|||
797cbb4b65
|
|||
4a54190b00
|
|||
3977685915
|
|||
66283bb533
|
|||
966ad7aee8
|
|||
2ec6311ca9
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,5 @@ __pycache__/
|
||||
ENV
|
||||
api/config/dbconfig.ini
|
||||
api/config/authservice.pub
|
||||
cli/config/dbconfig.ini
|
||||
|
||||
|
30
api/additional_components.yaml
Normal file
30
api/additional_components.yaml
Normal file
@ -0,0 +1,30 @@
|
||||
# -------------------------------------------------------------------
|
||||
# ATTENTION: This file will not be parsed by Cheetah
|
||||
# Use plain openapi/yaml syntax, no Cheetah
|
||||
# escaping
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
tenant_with_saldo:
|
||||
description: tenant with saldo
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
salutation:
|
||||
type: string
|
||||
nullable: true
|
||||
firstname:
|
||||
type: string
|
||||
nullable: true
|
||||
lastname:
|
||||
type: string
|
||||
nullable: true
|
||||
address1:
|
||||
type: string
|
||||
nullable: true
|
||||
saldo:
|
||||
type: number
|
||||
nullable: true
|
||||
|
@ -72,4 +72,20 @@
|
||||
type: number
|
||||
security:
|
||||
- jwt: ['secret']
|
||||
/v1/tenants/saldo:
|
||||
get:
|
||||
tags: [ "tenant", "account" ]
|
||||
summary: Return tenant with saldo of the account
|
||||
operationId: additional_methods.get_tenant_with_saldo
|
||||
responses:
|
||||
'200':
|
||||
description: get_tenant_with_saldo
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/tenant_with_saldo'
|
||||
security:
|
||||
- jwt: ['secret']
|
||||
|
||||
|
@ -31,4 +31,15 @@ def get_account_saldo(user, token_info, accountId=None):
|
||||
"statement": "SELECT sum(amount) as saldo FROM account_entry_t WHERE account=%s",
|
||||
"params": (accountId, )
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def get_tenant_with_saldo(user, token_info):
|
||||
return dbGetMany(user, token_info, {
|
||||
"statement": """
|
||||
SELECT t.id, t.firstname, t.lastname, t.address1, sum(a.amount) AS saldo
|
||||
FROM tenant_t t LEFT OUTER JOIN account_entry_t a ON a.account = t.account
|
||||
GROUP BY t.id, t.firstname, t.lastname, t.address1
|
||||
""",
|
||||
"params": ()
|
||||
}
|
||||
)
|
||||
|
@ -1493,6 +1493,22 @@ paths:
|
||||
type: number
|
||||
security:
|
||||
- jwt: ['secret']
|
||||
/v1/tenants/saldo:
|
||||
get:
|
||||
tags: [ "tenant", "account" ]
|
||||
summary: Return tenant with saldo of the account
|
||||
operationId: additional_methods.get_tenant_with_saldo
|
||||
responses:
|
||||
'200':
|
||||
description: get_tenant_with_saldo
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/tenant_with_saldo'
|
||||
security:
|
||||
- jwt: ['secret']
|
||||
|
||||
|
||||
components:
|
||||
@ -1727,3 +1743,34 @@ components:
|
||||
type: integer
|
||||
note:
|
||||
type: string
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# ATTENTION: This file will not be parsed by Cheetah
|
||||
# Use plain openapi/yaml syntax, no Cheetah
|
||||
# escaping
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
tenant_with_saldo:
|
||||
description: tenant with saldo
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
salutation:
|
||||
type: string
|
||||
nullable: true
|
||||
firstname:
|
||||
type: string
|
||||
nullable: true
|
||||
lastname:
|
||||
type: string
|
||||
nullable: true
|
||||
address1:
|
||||
type: string
|
||||
nullable: true
|
||||
saldo:
|
||||
type: number
|
||||
nullable: true
|
||||
|
@ -156,3 +156,5 @@ components:
|
||||
#end if
|
||||
#end for
|
||||
#end for
|
||||
|
||||
#include raw "./api/additional_components.yaml"
|
||||
|
126
cli/ConsistencyCheck.py
Normal file
126
cli/ConsistencyCheck.py
Normal file
@ -0,0 +1,126 @@
|
||||
from db import dbGetMany
|
||||
from loguru import logger
|
||||
|
||||
errorCnt = 0
|
||||
|
||||
def perform(dbh, params):
|
||||
global errorCnt
|
||||
checkTenant(dbh, params)
|
||||
checkFlats(dbh, params)
|
||||
checkParkings(dbh, params)
|
||||
checkCommercialPremise(dbh, params)
|
||||
|
||||
if (errorCnt > 0):
|
||||
logger.error(f"Total error count: {errorCnt}")
|
||||
|
||||
def checkTenant(dbh, params):
|
||||
global errorCnt
|
||||
tenants = dbGetMany(dbh, { "statement": "SELECT * FROM tenant_t", "params": () })
|
||||
for tenant in tenants:
|
||||
outPre = f"Tenant: {tenant['firstname']} {tenant['lastname']}"
|
||||
logger.info(outPre)
|
||||
|
||||
# check tenancies
|
||||
tenancyCnt = 0
|
||||
flatTenancyCnt = 0
|
||||
tenancies = dbGetMany(dbh, {
|
||||
"statement": "SELECT * FROM tenancy_t WHERE tenant = %s AND startdate < now() AND (enddate > now() or enddate is null)",
|
||||
"params": (tenant['id'], )
|
||||
}
|
||||
)
|
||||
for tenancy in tenancies:
|
||||
tenancyCnt += 1
|
||||
if (tenancy['flat']):
|
||||
flatTenancyCnt += 1
|
||||
logger.info(f"{outPre}: Flat tenancy: {tenancy['id']}, start: {tenancy['startdate']}, end: {tenancy['enddate']}")
|
||||
if (tenancy['parking']):
|
||||
logger.info(f"{outPre}: Garage tenancy: {tenancy['id']}, start: {tenancy['startdate']}, end: {tenancy['enddate']}")
|
||||
if (tenancy['commercial_premise']):
|
||||
logger.info(f"{outPre}: Commercial premise tenancy: {tenancy['id']}, start: {tenancy['startdate']}, end: {tenancy['enddate']}")
|
||||
|
||||
if (flatTenancyCnt == 0):
|
||||
logger.warning(f"{outPre}: no flat tenancy")
|
||||
if (flatTenancyCnt > 1):
|
||||
logger.warning(f"{outPre}: more than one flat tenancy ({flatTenancyCnt})")
|
||||
if (tenancyCnt == 0):
|
||||
logger.error(f"{outPre}: no tenancy at all")
|
||||
errorCnt += 1
|
||||
noCurrentTenancies = dbGetMany(dbh, {
|
||||
"statement": "SELECT * FROM tenancy_t WHERE tenant = %s",
|
||||
"params": (tenant['id'], )
|
||||
}
|
||||
)
|
||||
for noCurrentTenancy in noCurrentTenancies:
|
||||
logger.error(f"{outPre}: but: flat {noCurrentTenancy['flat']}, parking: {noCurrentTenancy['parking']}, commercial premise: {noCurrentTenancy['commercial_premise']}, start: {noCurrentTenancy['startdate']}, end: {noCurrentTenancy['enddate']}")
|
||||
|
||||
def _checkRentals(dbh, params, rentalType):
|
||||
global errorCnt
|
||||
table = f"{rentalType}_t"
|
||||
rentals = dbGetMany(dbh, {
|
||||
"statement": f"SELECT * FROM {table}",
|
||||
"params": ()
|
||||
}
|
||||
)
|
||||
for rental in rentals:
|
||||
outPre = f"{rentalType}: {rental['description']}, premise: {rental['premise']}"
|
||||
logger.info(outPre)
|
||||
|
||||
if (rentalType == 'flat'):
|
||||
overheadMappingCnt = 0
|
||||
overheadMappings = dbGetMany(dbh, {
|
||||
"statement": "SELECT * FROM overhead_advance_flat_mapping_t WHERE flat = %s",
|
||||
"params": (rental['id'], )
|
||||
}
|
||||
)
|
||||
for overheadMapping in overheadMappings:
|
||||
overheadMappingCnt += 1
|
||||
logger.info(f"{outPre}: overhead mapping: {overheadMapping['id']}")
|
||||
if (overheadMappingCnt == 0):
|
||||
errorCnt += 1
|
||||
logger.error(f"{outPre}: no overhead mapping available")
|
||||
if (overheadMappingCnt > 1):
|
||||
errorCnt += 1
|
||||
logger.error(f"{outPre}: more than one overhead mapping available")
|
||||
|
||||
tenancyCnt = 0
|
||||
tenancies = dbGetMany(dbh, {
|
||||
"statement": f"SELECT * FROM tenancy_t WHERE {rentalType} = %s AND startdate < now() AND (enddate > now() or enddate is null)",
|
||||
"params": (rental['id'], )
|
||||
}
|
||||
)
|
||||
for tenancy in tenancies:
|
||||
tenancyCnt += 1
|
||||
logger.info(f"{outPre}: tenant: {tenancy['tenant']}, start: {tenancy['startdate']}, end: {tenancy['enddate']}")
|
||||
|
||||
feeMappingCnt = 0
|
||||
feeMappings = dbGetMany(dbh, {
|
||||
"statement": "SELECT * FROM tenancy_fee_mapping_t where tenancy = %s",
|
||||
"params": (tenancy['id'], )
|
||||
}
|
||||
)
|
||||
for feeMapping in feeMappings:
|
||||
feeMappingCnt += 1
|
||||
logger.info(f"{outPre}: fee mapping: {feeMapping['id']}")
|
||||
if (feeMappingCnt == 0):
|
||||
errorCnt += 1
|
||||
logger.error(f"{outPre}: no fee mapping available")
|
||||
if (feeMappingCnt > 1):
|
||||
errorCnt += 1
|
||||
logger.error(f"{outPre}: more than one fee mapping available")
|
||||
|
||||
if (tenancyCnt == 0):
|
||||
errorCnt += 1
|
||||
logger.error(f"{outPre}: vacant")
|
||||
if (tenancyCnt > 1):
|
||||
errorCnt += 1
|
||||
logger.error(f"{outPre}: overbooked")
|
||||
|
||||
|
||||
def checkFlats(dbh, params):
|
||||
_checkRentals(dbh, params, "flat")
|
||||
|
||||
def checkParkings(dbh, params):
|
||||
_checkRentals(dbh, params, "parking")
|
||||
|
||||
def checkCommercialPremise(dbh, params):
|
||||
_checkRentals(dbh, params, "commercial_premise")
|
109
cli/MonthlyPaymentRequests.py
Normal file
109
cli/MonthlyPaymentRequests.py
Normal file
@ -0,0 +1,109 @@
|
||||
from db import dbGetMany, dbGetOne
|
||||
from loguru import logger
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
def perform(dbh, params):
|
||||
try:
|
||||
createdAt = params['created_at']
|
||||
except KeyError:
|
||||
createdAt = datetime.datetime.today().strftime("%Y-%m-%d")
|
||||
|
||||
tenants = dbGetMany(dbh, { "statement": "SELECT * FROM tenant_t", "params": () })
|
||||
for tenant in tenants:
|
||||
logger.info(f"Tenant: {tenant['firstname']} {tenant['lastname']}")
|
||||
|
||||
# check tenancies
|
||||
tenancies = dbGetMany(dbh, {
|
||||
"statement": "SELECT * FROM tenancy_t WHERE tenant = %s AND startdate < now() AND (enddate > now() or enddate is null)",
|
||||
"params": (tenant['id'], )
|
||||
}
|
||||
)
|
||||
requests = []
|
||||
for tenancy in tenancies:
|
||||
fee = dbGetOne(dbh, {
|
||||
"statement": """
|
||||
SELECT f.amount, f.fee_type
|
||||
FROM fee_t f, tenancy_fee_mapping_t t
|
||||
WHERE t.tenancy = %s AND
|
||||
f.id = t.fee AND
|
||||
f.startdate < now() AND
|
||||
(f.enddate > now() OR f.enddate is null)
|
||||
""",
|
||||
"params": (tenancy['id'], )
|
||||
}
|
||||
)
|
||||
if (tenancy['flat']):
|
||||
logger.debug(f" Flat tenancy: {tenancy['id']}, Fee: {fee['amount']}, Fee_Type: {fee['fee_type']}")
|
||||
flat = dbGetOne(dbh, { "statement": "SELECT area FROM flat_t WHERE id = %s", "params": (tenancy['flat'], ) })
|
||||
logger.debug(f" Area: {flat['area']}")
|
||||
if (fee['fee_type'] == 'per_area'):
|
||||
feeRequest = flat['area'] * fee['amount']
|
||||
else:
|
||||
feeRequest = fee['amount']
|
||||
feeRequest = feeRequest.quantize(Decimal('1.00'))
|
||||
requests.append({
|
||||
'description': f"Miete {tenancy['description']}",
|
||||
'account': tenant['account'],
|
||||
'created_at': createdAt,
|
||||
'amount': feeRequest,
|
||||
'category': 'Mietforderung'
|
||||
})
|
||||
overheadAdvance = dbGetOne(dbh, {
|
||||
"statement": """
|
||||
SELECT o.amount
|
||||
FROM overhead_advance_t o, overhead_advance_flat_mapping_t m
|
||||
WHERE m.flat = %s AND
|
||||
o.id = m.overhead_advance AND
|
||||
o.startdate < now() AND
|
||||
(o.enddate > now() OR o.enddate is null)
|
||||
""",
|
||||
"params": (tenancy['flat'], )
|
||||
}
|
||||
)
|
||||
overheadAdvanceRequest = flat['area'] * overheadAdvance['amount']
|
||||
overheadAdvanceRequest = overheadAdvanceRequest.quantize(Decimal('1.00'))
|
||||
requests.append({
|
||||
'description': f"Betriebskosten {tenancy['description']}",
|
||||
'account': tenant['account'],
|
||||
'created_at': createdAt,
|
||||
'amount': overheadAdvanceRequest,
|
||||
'category': 'Betriebskostenforderung'
|
||||
})
|
||||
if (tenancy['parking']):
|
||||
logger.debug(f" Garage tenancy: {tenancy['id']}, Fee: {fee['amount']}, Fee_Type: {fee['fee_type']}")
|
||||
feeRequest = fee['amount']
|
||||
feeRequest = feeRequest.quantize(Decimal('1.00'))
|
||||
requests.append({
|
||||
'description': f"Miete {tenancy['description']}",
|
||||
'account': tenant['account'],
|
||||
'created_at': createdAt,
|
||||
'amount': feeRequest,
|
||||
'category': 'Mietforderung'
|
||||
})
|
||||
if (tenancy['commercial_premise']):
|
||||
logger.debug(f" Commercial premise tenancy: {tenancy['id']}, Fee: {fee['amount']}, Fee_Type: {fee['fee_type']}")
|
||||
feeRequest = fee['amount']
|
||||
feeRequest = feeRequest.quantize(Decimal('1.00'))
|
||||
requests.append({
|
||||
'description': f"Miete {tenancy['description']}",
|
||||
'account': tenant['account'],
|
||||
'created_at': createdAt,
|
||||
'amount': feeRequest,
|
||||
'category': 'Mietforderung'
|
||||
})
|
||||
|
||||
for request in requests:
|
||||
request['amount'] = Decimal('-1.0') * request['amount']
|
||||
logger.info(f" {request['description']}, {request['account']}, {request['created_at']}, {request['amount']}, {request['category']}")
|
||||
accountEntry = dbGetOne(dbh, {
|
||||
"statement": """
|
||||
INSERT INTO account_entry_t
|
||||
(description, account, created_at, amount, account_entry_category)
|
||||
VALUES (%s, %s, %s, %s, (SELECT id FROM account_entry_category_t WHERE description = %s))
|
||||
RETURNING id
|
||||
""",
|
||||
"params": (request['description'], request['account'], request['created_at'], request['amount'], request['category'])
|
||||
}
|
||||
)
|
||||
logger.info(f" account entry entered with id {accountEntry['id']}")
|
46
cli/db.py
Normal file
46
cli/db.py
Normal file
@ -0,0 +1,46 @@
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class NoDataFoundException(Exception): pass
|
||||
|
||||
class TooMuchDataFoundException(Exception): pass
|
||||
|
||||
|
||||
def execDatabaseOperation(dbh, func, params):
|
||||
cur = None
|
||||
try:
|
||||
with dbh.cursor(cursor_factory = psycopg2.extras.RealDictCursor) as cur:
|
||||
params["params"] = [ v if not v=='' else None for v in params["params"] ]
|
||||
logger.debug("edo: {}".format(str(params)))
|
||||
return func(cur, params)
|
||||
except psycopg2.Error as err:
|
||||
raise Exception("Error when working on cursor: {}".format(err))
|
||||
|
||||
|
||||
|
||||
def _opGetMany(cursor, params):
|
||||
items = []
|
||||
cursor.execute(params["statement"], params["params"])
|
||||
for itemObj in cursor:
|
||||
logger.debug("item received {}".format(str(itemObj)))
|
||||
items.append(itemObj)
|
||||
return items
|
||||
|
||||
def dbGetMany(dbh, params):
|
||||
return execDatabaseOperation(dbh, _opGetMany, params)
|
||||
|
||||
def _opGetOne(cursor, params):
|
||||
cursor.execute(params["statement"], params["params"])
|
||||
itemObj = cursor.fetchone()
|
||||
logger.debug(f"item received: {itemObj}")
|
||||
if not itemObj:
|
||||
raise NoDataFoundException
|
||||
dummyObj = cursor.fetchone()
|
||||
if dummyObj:
|
||||
raise TooMuchDataFoundException
|
||||
return itemObj
|
||||
|
||||
def dbGetOne(dbh, params):
|
||||
return execDatabaseOperation(dbh, _opGetOne, params)
|
77
cli/hv2cli.py
Normal file
77
cli/hv2cli.py
Normal file
@ -0,0 +1,77 @@
|
||||
import psycopg2
|
||||
import psycopg2.extras
|
||||
from loguru import logger
|
||||
import os
|
||||
import configparser
|
||||
import json
|
||||
import argparse
|
||||
import importlib
|
||||
import sys
|
||||
|
||||
DB_USER = ""
|
||||
DB_PASS = ""
|
||||
DB_HOST = ""
|
||||
DB_NAME = ""
|
||||
try:
|
||||
DB_USER = os.environ["DB_USER"]
|
||||
DB_PASS = os.environ["DB_PASS"]
|
||||
DB_HOST = os.environ["DB_HOST"]
|
||||
DB_NAME = os.environ["DB_NAME"]
|
||||
except KeyError:
|
||||
config = configparser.ConfigParser()
|
||||
config.read('./config/dbconfig.ini')
|
||||
DB_USER = config["database"]["user"]
|
||||
DB_PASS = config["database"]["pass"]
|
||||
DB_HOST = config["database"]["host"]
|
||||
DB_NAME = config["database"]["name"]
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description="hv2cli.py")
|
||||
parser.add_argument('--operation', '-o',
|
||||
help='Operation to perform.',
|
||||
required=True)
|
||||
parser.add_argument('--params', '-p',
|
||||
help='JSON string with parameter for the selected operation, default: {}',
|
||||
required=False,
|
||||
default="{}")
|
||||
parser.add_argument('--verbosity', '-v',
|
||||
help='Minimal log level for output: DEBUG, INFO, WARNING, ..., default: DEBUG',
|
||||
required=False,
|
||||
default="DEBUG")
|
||||
parser.add_argument('--nocolorize', '-n',
|
||||
help='disable colored output (for cron)',
|
||||
required=False,
|
||||
action='store_true',
|
||||
default=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
operation = args.operation
|
||||
params = json.loads(args.params)
|
||||
logLevel = args.verbosity
|
||||
noColorize = args.nocolorize
|
||||
|
||||
|
||||
logger.remove()
|
||||
logger.add(sys.stderr, colorize=(not noColorize), level=logLevel)
|
||||
|
||||
|
||||
dbh = None
|
||||
try:
|
||||
opMod = importlib.import_module(operation)
|
||||
|
||||
dbh = psycopg2.connect(user = DB_USER, password = DB_PASS,
|
||||
host = DB_HOST, database = DB_NAME,
|
||||
sslmode = 'require')
|
||||
dbh.autocommit = False
|
||||
|
||||
with dbh:
|
||||
opMod.perform(dbh, params)
|
||||
except psycopg2.Error as err:
|
||||
raise Exception("Error when working on the database: {}".format(err))
|
||||
except Exception as err:
|
||||
raise err
|
||||
finally:
|
||||
if dbh:
|
||||
dbh.close()
|
||||
|
||||
|
5
cli/listTenants.py
Normal file
5
cli/listTenants.py
Normal file
@ -0,0 +1,5 @@
|
||||
from db import dbGetMany
|
||||
|
||||
def perform(dbh, params):
|
||||
tenants = dbGetMany(dbh, { "statement": "SELECT * FROM tenant_t", "params": () })
|
||||
print(tenants)
|
@ -133,7 +133,7 @@
|
||||
"name": "account_entry",
|
||||
"immutable": true,
|
||||
"columns": [
|
||||
{ "name": "description", "sqltype": "varchar(128)", "notnull": true },
|
||||
{ "name": "description", "sqltype": "varchar(1024)", "notnull": true },
|
||||
{ "name": "account", "sqltype": "integer", "notnull": true, "foreignkey": true },
|
||||
{ "name": "created_at", "sqltype": "timestamp", "notnull": true, "default": "now()" },
|
||||
{ "name": "amount", "sqltype": "numeric(10,2)", "notnull": true, "selector": 0 },
|
||||
|
@ -18,6 +18,7 @@ import { OverheadAdvanceDetailsComponent } from './overhead-advance-details/over
|
||||
import { FeeListComponent } from './fee-list/fee-list.component';
|
||||
import { FeeDetailsComponent } from './fee-details/fee-details.component';
|
||||
import { EnterPaymentComponent } from './enter-payment/enter-payment.component';
|
||||
import { HomeComponent } from './home/home.component';
|
||||
|
||||
|
||||
const routes: Routes = [
|
||||
@ -43,8 +44,10 @@ const routes: Routes = [
|
||||
{ path: 'fee/:id', component: FeeDetailsComponent, canActivate: [ AuthGuardService ] },
|
||||
{ path: 'fee', component: FeeDetailsComponent, canActivate: [ AuthGuardService ] },
|
||||
{ path: 'enterPayment', component: EnterPaymentComponent, canActivate: [ AuthGuardService ] },
|
||||
{ path: 'home', component: HomeComponent },
|
||||
{ path: 'logout', component: LogoutComponent },
|
||||
{ path: 'login', component: LoginComponent }
|
||||
{ path: 'login', component: LoginComponent },
|
||||
{ path: '', pathMatch: 'full', redirectTo: 'home' }
|
||||
]
|
||||
|
||||
@NgModule({
|
||||
|
@ -46,7 +46,8 @@ import { MatExpansionModule } from '@angular/material/expansion';
|
||||
import { AccountComponent } from './account/account.component';
|
||||
import { NoteComponent } from './note/note.component'
|
||||
import { MatMomentDateModule, MAT_MOMENT_DATE_ADAPTER_OPTIONS } from '@angular/material-moment-adapter';
|
||||
import { EnterPaymentComponent } from './enter-payment/enter-payment.component'
|
||||
import { EnterPaymentComponent } from './enter-payment/enter-payment.component';
|
||||
import { HomeComponent } from './home/home.component'
|
||||
|
||||
registerLocaleData(localeDe)
|
||||
|
||||
@ -74,7 +75,8 @@ registerLocaleData(localeDe)
|
||||
FeeDetailsComponent,
|
||||
AccountComponent,
|
||||
NoteComponent,
|
||||
EnterPaymentComponent
|
||||
EnterPaymentComponent,
|
||||
HomeComponent
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
|
@ -7,7 +7,7 @@ import { serviceBaseUrl } from './config';
|
||||
|
||||
|
||||
import { Fee, OverheadAdvance } from './data-objects';
|
||||
import { Saldo } from './ext-data-objects';
|
||||
import { Saldo, Tenant_with_Saldo } from './ext-data-objects';
|
||||
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@ -28,4 +28,9 @@ export class ExtApiService {
|
||||
this.messageService.add(`ExtApiService: get saldo for account ${id}`);
|
||||
return this.http.get<Saldo>(`${serviceBaseUrl}/v1/account/saldo/${id}`).toPromise()
|
||||
}
|
||||
|
||||
async getTenantsWithSaldo(): Promise<Tenant_with_Saldo[]> {
|
||||
this.messageService.add("ExtApiService: get tenants with saldo");
|
||||
return this.http.get<Tenant_with_Saldo[]>(`${serviceBaseUrl}/v1/tenants/saldo`).toPromise()
|
||||
}
|
||||
}
|
||||
|
@ -2,4 +2,11 @@
|
||||
export interface Saldo {
|
||||
saldo: number
|
||||
}
|
||||
|
||||
|
||||
export interface Tenant_with_Saldo {
|
||||
id: number
|
||||
firstname: string
|
||||
lastname: string
|
||||
address1: string
|
||||
saldo: number
|
||||
}
|
0
ui/hv2-ui/src/app/home/home.component.css
Normal file
0
ui/hv2-ui/src/app/home/home.component.css
Normal file
1
ui/hv2-ui/src/app/home/home.component.html
Normal file
1
ui/hv2-ui/src/app/home/home.component.html
Normal file
@ -0,0 +1 @@
|
||||
<p>home works!</p>
|
25
ui/hv2-ui/src/app/home/home.component.spec.ts
Normal file
25
ui/hv2-ui/src/app/home/home.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { HomeComponent } from './home.component';
|
||||
|
||||
describe('HomeComponent', () => {
|
||||
let component: HomeComponent;
|
||||
let fixture: ComponentFixture<HomeComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ HomeComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(HomeComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
15
ui/hv2-ui/src/app/home/home.component.ts
Normal file
15
ui/hv2-ui/src/app/home/home.component.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
templateUrl: './home.component.html',
|
||||
styleUrls: ['./home.component.css']
|
||||
})
|
||||
export class HomeComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
}
|
@ -22,6 +22,10 @@
|
||||
<th mat-header-cell *matHeaderCellDef>Adresse 1</th>
|
||||
<td mat-cell *matCellDef="let element">{{element.address1}}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="saldo">
|
||||
<th mat-header-cell *matHeaderCellDef>Saldo</th>
|
||||
<td mat-cell *matCellDef="let element">{{element.saldo | number:'1.2-2'}} €</td>
|
||||
</ng-container>
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="['/tenant/', row.id]"></tr>
|
||||
</table>
|
||||
|
@ -3,6 +3,9 @@ import { MessageService } from '../message.service';
|
||||
import { TenantService } from '../data-object-service';
|
||||
import { Tenant } from '../data-objects';
|
||||
import { MatTableDataSource } from '@angular/material/table'
|
||||
import { Tenant_with_Saldo } from '../ext-data-objects';
|
||||
import { ExtApiService } from '../ext-data-object-service';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-my-tenants',
|
||||
@ -11,19 +14,22 @@ import { MatTableDataSource } from '@angular/material/table'
|
||||
})
|
||||
export class MyTenantsComponent implements OnInit {
|
||||
|
||||
tenants: Tenant[]
|
||||
dataSource: MatTableDataSource<Tenant>
|
||||
displayedColumns: string[] = ["lastname", "firstname", "address1"]
|
||||
tenants: Tenant_with_Saldo[]
|
||||
dataSource: MatTableDataSource<Tenant_with_Saldo>
|
||||
displayedColumns: string[] = ["lastname", "firstname", "address1", "saldo"]
|
||||
|
||||
constructor(private tenantService: TenantService, private messageService: MessageService) { }
|
||||
constructor(
|
||||
private extApiService: ExtApiService,
|
||||
private messageService: MessageService
|
||||
) { }
|
||||
|
||||
async getTenants(): Promise<void> {
|
||||
try {
|
||||
this.messageService.add("Trying to load tenants")
|
||||
this.tenants = await this.tenantService.getTenants()
|
||||
this.tenants = await this.extApiService.getTenantsWithSaldo()
|
||||
this.messageService.add("Tenants loaded")
|
||||
|
||||
this.dataSource = new MatTableDataSource<Tenant>(this.tenants)
|
||||
this.dataSource = new MatTableDataSource<Tenant_with_Saldo>(this.tenants)
|
||||
} catch (err) {
|
||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
||||
}
|
||||
|
@ -90,11 +90,18 @@ export class TenantDetailsComponent implements OnInit {
|
||||
async getTenant(): Promise<void> {
|
||||
try {
|
||||
const id = +this.route.snapshot.paramMap.get('id')
|
||||
this.messageService.add(`getTenant, id=${id}`)
|
||||
if (id != 0) {
|
||||
this.messageService.add("getTenant, not-0-branch")
|
||||
this.tenantId = id
|
||||
this.tenant = await this.tenantService.getTenant(id)
|
||||
this.account = await this.accountService.getAccount(this.tenant.account)
|
||||
this.getTenancies()
|
||||
} else {
|
||||
this.messageService.add("getTenant, 0-branch")
|
||||
this.tenant = NULL_Tenant
|
||||
this.account = NULL_Account
|
||||
this.tenancies = []
|
||||
}
|
||||
} catch (err) {
|
||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
||||
|
Reference in New Issue
Block a user