This commit is contained in:
2021-09-08 18:13:59 +02:00
parent c6e865eca1
commit 0ae59c644e
6 changed files with 113 additions and 38 deletions

View File

@ -1,9 +1,18 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AccountService, TenantService } from '../data-object-service';
import { Account, Tenant } from '../data-objects';
import { AccountService, CommercialPremiseService, FlatService, ParkingService, PremiseService, TenancyService, TenantService } from '../data-object-service';
import { Account, CommercialPremise, Flat, NULL_Account, NULL_CommercialPremise, NULL_Flat, NULL_Parking, NULL_Tenant, Parking, Premise, Tenancy, Tenant } from '../data-objects';
import { MessageService } from '../message.service';
import { MatButton } from '@angular/material/button';
import { MatTableDataSource } from '@angular/material/table';
interface DN_Tenancy {
rawTenancy: Tenancy
flat: string
parking: string
commercialPremise: string
}
@Component({
selector: 'app-tenant-details',
@ -12,32 +21,28 @@ import { MatButton } from '@angular/material/button';
})
export class TenantDetailsComponent implements OnInit {
tenant: Tenant = {
id: 0,
salutation: '',
firstname: '',
lastname: '',
address1: '',
address2: '',
address3: '',
zip: '',
city: '',
phone1: '',
phone2: '',
iban: '',
account: 0
}
tenant: Tenant = NULL_Tenant
account: Account = {
id: 0,
description: ''
}
account: Account = NULL_Account
tenancies: DN_Tenancy[] = []
tenancyDataSource: MatTableDataSource<DN_Tenancy>
tenancyDisplayColumns: string[] = [ "description", "flat", "parking", "commercial_premise", "startdate", "enddate" ]
collapseTenantDetails: boolean = false
collapseTenancies: boolean = false
@ViewChild('submitButton') submitButton: MatButton
constructor(
private tenantService: TenantService,
private accountService: AccountService,
private tenancyService: TenancyService,
private flatService: FlatService,
private parkingService: ParkingService,
private commercialPremiseService: CommercialPremiseService,
private premiseService: PremiseService,
private messageService: MessageService,
private route: ActivatedRoute,
private router: Router
@ -49,6 +54,24 @@ export class TenantDetailsComponent implements OnInit {
if (id != 0) {
this.tenant = await this.tenantService.getTenant(id)
this.account = await this.accountService.getAccount(this.tenant.account)
const premises: Premise[] = await this.premiseService.getPremises()
const premisesDict = new Map<number, Premise>()
for (let p of premises) {
premisesDict.set(p.id, p)
}
for (let t of await this.tenancyService.getTenancysByTenant(this.tenant.id)) {
const flat: Flat = (t.flat) ? await this.flatService.getFlat(t.flat) : NULL_Flat
const parking: Parking = (t.parking) ? await this.parkingService.getParking(t.parking) : NULL_Parking
const commercialPremise: CommercialPremise = (t.commercial_premise) ? await this.commercialPremiseService.getCommercialPremise(t.commercial_premise) : NULL_CommercialPremise
this.tenancies.push({
rawTenancy: t,
flat: (flat != NULL_Flat) ? `${flat.description} (${premisesDict.get(flat.premise).description})` : '',
parking: (parking != NULL_Parking) ? `${parking.description} (${premisesDict.get(parking.premise).description})` : '',
commercialPremise: (commercialPremise != NULL_CommercialPremise) ? `${commercialPremise.description} (${premisesDict.get(commercialPremise.premise).description})` : ''
})
}
this.tenancyDataSource = new MatTableDataSource<DN_Tenancy>(this.tenancies)
}
} catch (err) {
this.messageService.add(JSON.stringify(err, undefined, 4))