nullable api params and tenancy mapping

This commit is contained in:
Wolfgang Hottgenroth 2021-09-11 17:07:39 +02:00
parent df4adecda1
commit 05823a1829
Signed by: wn
GPG Key ID: E49AF3B9EF6DD469
4 changed files with 204 additions and 10 deletions

View File

@ -1519,26 +1519,37 @@ components:
type: integer type: integer
salutation: salutation:
type: string type: string
nullable: true
firstname: firstname:
type: string type: string
nullable: true
lastname: lastname:
type: string type: string
nullable: true
address1: address1:
type: string type: string
nullable: true
address2: address2:
type: string type: string
nullable: true
address3: address3:
type: string type: string
nullable: true
zip: zip:
type: string type: string
nullable: true
city: city:
type: string type: string
nullable: true
phone1: phone1:
type: string type: string
nullable: true
phone2: phone2:
type: string type: string
nullable: true
iban: iban:
type: string type: string
nullable: true
account: account:
type: integer type: integer
premise: premise:
@ -1549,6 +1560,7 @@ components:
type: integer type: integer
description: description:
type: string type: string
nullable: true
street: street:
type: string type: string
zip: zip:
@ -1563,12 +1575,15 @@ components:
type: integer type: integer
description: description:
type: string type: string
nullable: true
premise: premise:
type: integer type: integer
nullable: true
area: area:
type: number type: number
flat_no: flat_no:
type: integer type: integer
nullable: true
overhead_advance: overhead_advance:
description: overhead_advance description: overhead_advance
type: object type: object
@ -1577,12 +1592,15 @@ components:
type: integer type: integer
description: description:
type: string type: string
nullable: true
amount: amount:
type: number type: number
startdate: startdate:
type: string type: string
nullable: true
enddate: enddate:
type: string type: string
nullable: true
overhead_advance_flat_mapping: overhead_advance_flat_mapping:
description: overhead_advance_flat_mapping description: overhead_advance_flat_mapping
type: object type: object
@ -1601,8 +1619,10 @@ components:
type: integer type: integer
description: description:
type: string type: string
nullable: true
premise: premise:
type: integer type: integer
nullable: true
commercial_premise: commercial_premise:
description: commercial_premise description: commercial_premise
type: object type: object
@ -1611,8 +1631,10 @@ components:
type: integer type: integer
description: description:
type: string type: string
nullable: true
premise: premise:
type: integer type: integer
nullable: true
tenancy: tenancy:
description: tenancy description: tenancy
type: object type: object
@ -1621,18 +1643,23 @@ components:
type: integer type: integer
description: description:
type: string type: string
nullable: true
tenant: tenant:
type: integer type: integer
flat: flat:
type: integer type: integer
nullable: true
parking: parking:
type: integer type: integer
nullable: true
commercial_premise: commercial_premise:
type: integer type: integer
nullable: true
startdate: startdate:
type: string type: string
enddate: enddate:
type: string type: string
nullable: true
fee: fee:
description: fee description: fee
type: object type: object
@ -1641,14 +1668,17 @@ components:
type: integer type: integer
description: description:
type: string type: string
nullable: true
amount: amount:
type: number type: number
fee_type: fee_type:
type: string type: string
startdate: startdate:
type: string type: string
nullable: true
enddate: enddate:
type: string type: string
nullable: true
tenancy_fee_mapping: tenancy_fee_mapping:
description: tenancy_fee_mapping description: tenancy_fee_mapping
type: object type: object

View File

@ -151,5 +151,8 @@ components:
#for $column in $table.columns #for $column in $table.columns
$column.name: $column.name:
type: $column.apitype type: $column.apitype
#if (('notnull' not in $column) or (not $column.notnull))
nullable: true
#end if
#end for #end for
#end for #end for

View File

@ -98,7 +98,8 @@
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content>
<mat-accordion> <mat-accordion>
<mat-expansion-panel (opened)="collapseTenancies = true" <mat-expansion-panel #panelTenancies
(opened)="collapseTenancies = true"
(closed)="collapseTenancies = false"> (closed)="collapseTenancies = false">
<mat-expansion-panel-header> <mat-expansion-panel-header>
<mat-panel-title *ngIf="!collapseTenancies"> <mat-panel-title *ngIf="!collapseTenancies">
@ -138,6 +139,54 @@
</table> </table>
</div> </div>
</mat-expansion-panel> </mat-expansion-panel>
<mat-expansion-panel #panelAddMapping
(opened)="openTenancyMapping()"
(closed)="closeTenancyMapping()">
<mat-expansion-panel-header>
<mat-panel-title *ngIf="!collapseTenancyMapping">
Mietverhältnis hinzufügen
</mat-panel-title>
<mat-panel-description>
</mat-panel-description>
</mat-expansion-panel-header>
<div>
<form (ngSubmit)="addTenancyToTenant()">
<div>
<mat-form-field appearance="outline" id="setenddatefield">
<mat-label>Beginn</mat-label>
<input matInput name="startdate" [(ngModel)]="newTenancy.startdate" [matDatepicker]="newtenancystartdatepicker"/>
<mat-datepicker-toggle matSuffix [for]="newtenancystartdatepicker"></mat-datepicker-toggle>
<mat-datepicker #newtenancystartdatepicker></mat-datepicker>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Beschreibung</mat-label>
<input matInput name="description" [(ngModel)]="newTenancy.description"/>
</mat-form-field>
</div><div>
<mat-form-field appearance="outline">
<mat-select #mapSelect [(ngModel)]="newTenancy.flat" name="flat" (selectionChange)="flatSelected()">
<mat-label>Wohnung</mat-label>
<mat-option *ngFor="let p of allFlats" [value]="p.rawFlat.id">{{p.rawFlat.description}} {{p.premise}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Garage</mat-label>
<mat-select #mapSelect [(ngModel)]="newTenancy.parking" name="parking" (selectionChange)="parkingSelected()">
<mat-option *ngFor="let p of allParkings" [value]="p.rawParking.id">{{p.rawParking.description}} {{p.premise}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Büro</mat-label>
<mat-select #mapSelect [(ngModel)]="newTenancy.commercial_premise" name="commercial_premise" (selectionChange)="commercialPremiseSelected()">
<mat-option *ngFor="let p of allCommercialPremises" [value]="p.rawCommercialPremise.id">{{p.rawCommercialPremise.description}} {{p.premise}}</mat-option>
</mat-select>
</mat-form-field>
</div>
<button #addTenancyToTenantButton type="submit" mat-raised-button color="primary">Anlegen</button>
</form>
</div>
</mat-expansion-panel>
</mat-accordion> </mat-accordion>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>

View File

@ -6,6 +6,7 @@ import { MessageService } from '../message.service';
import { MatButton } from '@angular/material/button'; import { MatButton } from '@angular/material/button';
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from '@angular/material/table';
import { ExtApiService } from '../ext-data-object-service'; import { ExtApiService } from '../ext-data-object-service';
import { MatExpansionPanel } from '@angular/material/expansion';
interface DN_Tenancy { interface DN_Tenancy {
@ -15,6 +16,21 @@ interface DN_Tenancy {
commercialPremise: string commercialPremise: string
} }
interface DN_Flat {
rawFlat: Flat
premise: string
}
interface DN_Parking {
rawParking: Parking
premise: string
}
interface DN_CommercialPremise {
rawCommercialPremise: CommercialPremise
premise: string
}
@Component({ @Component({
selector: 'app-tenant-details', selector: 'app-tenant-details',
templateUrl: './tenant-details.component.html', templateUrl: './tenant-details.component.html',
@ -27,12 +43,15 @@ export class TenantDetailsComponent implements OnInit {
account: Account = NULL_Account account: Account = NULL_Account
premisesMap: Map<number, Premise>
tenancies: DN_Tenancy[] tenancies: DN_Tenancy[]
tenancyDataSource: MatTableDataSource<DN_Tenancy> tenancyDataSource: MatTableDataSource<DN_Tenancy>
tenancyDisplayColumns: string[] = [ "description", "flat", "parking", "commercial_premise", "startdate", "enddate" ] tenancyDisplayColumns: string[] = [ "description", "flat", "parking", "commercial_premise", "startdate", "enddate" ]
collapseTenantDetails: boolean = false collapseTenantDetails: boolean = false
collapseTenancies: boolean = false collapseTenancies: boolean = false
collapseTenancyMapping: boolean = false
selectedTenancy: Tenancy = undefined selectedTenancy: Tenancy = undefined
mappedFees: Fee[] mappedFees: Fee[]
@ -41,9 +60,15 @@ export class TenantDetailsComponent implements OnInit {
allFees: Fee[] allFees: Fee[]
selectedFee: number selectedFee: number
newTenancy: Tenancy = NULL_Tenancy
allFlats: DN_Flat[]
allParkings: DN_Parking[]
allCommercialPremises: DN_CommercialPremise[]
@ViewChild('submitButton') submitButton: MatButton @ViewChild('submitButton') submitButton: MatButton
@ViewChild('mapFeeButton') mapFeeButton: MatButton @ViewChild('mapFeeButton') mapFeeButton: MatButton
@ViewChild('panelTenancies') panelTenancies: MatExpansionPanel
@ViewChild('panelAddMapping') panelAddMapping: MatExpansionPanel
constructor( constructor(
private tenantService: TenantService, private tenantService: TenantService,
@ -78,20 +103,16 @@ export class TenantDetailsComponent implements OnInit {
async getTenancies(): Promise<void> { async getTenancies(): Promise<void> {
try { try {
this.tenancies = [] this.tenancies = []
const premises: Premise[] = await this.premiseService.getPremises() await this.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)) { 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 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 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 const commercialPremise: CommercialPremise = (t.commercial_premise) ? await this.commercialPremiseService.getCommercialPremise(t.commercial_premise) : NULL_CommercialPremise
this.tenancies.push({ this.tenancies.push({
rawTenancy: t, rawTenancy: t,
flat: (flat != NULL_Flat) ? `${flat.description} (${premisesDict.get(flat.premise).description})` : '', flat: (flat != NULL_Flat) ? `${flat.description} (${this.premisesMap.get(flat.premise).description})` : '',
parking: (parking != NULL_Parking) ? `${parking.description} (${premisesDict.get(parking.premise).description})` : '', parking: (parking != NULL_Parking) ? `${parking.description} (${this.premisesMap.get(parking.premise).description})` : '',
commercialPremise: (commercialPremise != NULL_CommercialPremise) ? `${commercialPremise.description} (${premisesDict.get(commercialPremise.premise).description})` : '' commercialPremise: (commercialPremise != NULL_CommercialPremise) ? `${commercialPremise.description} (${this.premisesMap.get(commercialPremise.premise).description})` : ''
}) })
} }
this.tenancyDataSource = new MatTableDataSource<DN_Tenancy>(this.tenancies) this.tenancyDataSource = new MatTableDataSource<DN_Tenancy>(this.tenancies)
@ -156,7 +177,25 @@ export class TenantDetailsComponent implements OnInit {
} }
} }
async addFee() { async getPremises(): Promise<void> {
if ((! this.premisesMap) || (this.premisesMap.size == 0)) {
try {
this.messageService.add("Trying to load premises")
const premises = await this.premiseService.getPremises()
this.premisesMap = new Map<number, Premise>()
for (let p of premises) {
this.premisesMap.set(p.id, p)
}
this.messageService.add("Premises loaded")
} catch (err) {
this.messageService.add(`Error in getPremises: ${ JSON.stringify(err, undefined, 4) }`)
}
} else {
this.messageService.add("Premises already loaded")
}
}
async addFee(): Promise<void> {
try { try {
this.mapFeeButton.disabled = true this.mapFeeButton.disabled = true
this.messageService.add(`fee: ${ JSON.stringify(this.selectedFee, undefined, 4) }`) this.messageService.add(`fee: ${ JSON.stringify(this.selectedFee, undefined, 4) }`)
@ -174,6 +213,79 @@ export class TenantDetailsComponent implements OnInit {
} }
} }
async openTenancyMapping(): Promise<void> {
this.messageService.add("TenancyMapping opened")
this.collapseTenancyMapping = true
await this.getPremises()
if (! this.allFlats) {
let flats = await this.flatService.getFlats()
this.allFlats = []
for (let p of flats) {
this.allFlats.push({
rawFlat: p,
premise: this.premisesMap.get(p.premise).description
})
}
}
if (! this.allParkings) {
let parkings = await this.parkingService.getParkings()
this.allParkings = []
for (let p of parkings) {
this.allParkings.push({
rawParking: p,
premise: this.premisesMap.get(p.premise).description
})
}
}
if (! this.allCommercialPremises) {
let commercialPremises = await this.commercialPremiseService.getCommercialPremises()
this.allCommercialPremises = []
for (let p of commercialPremises) {
this.allCommercialPremises.push({
rawCommercialPremise: p,
premise: this.premisesMap.get(p.premise).description
})
}
}
}
async closeTenancyMapping(): Promise<void> {
this.messageService.add("TenancyMapping closed")
this.collapseTenancyMapping = false
}
flatSelected(): void {
this.newTenancy.parking = null
this.newTenancy.commercial_premise = null
}
parkingSelected(): void {
this.newTenancy.flat = null
this.newTenancy.commercial_premise = null
}
commercialPremiseSelected(): void {
this.newTenancy.parking = null
this.newTenancy.flat = null
}
async addTenancyToTenant(): Promise<void> {
try {
this.messageService.add(`Going to mapping ${JSON.stringify(this.newTenancy, undefined, 4)}`)
this.newTenancy.tenant = this.tenant.id
this.messageService.add(`new tenancy is ${JSON.stringify(this.newTenancy, undefined, 4)}`)
this.newTenancy = await this.tenancyService.postTenancy(this.newTenancy)
this.messageService.add(`New tenancy added with id ${this.newTenancy.id}`)
this.panelAddMapping.close()
this.panelTenancies.open()
this.getTenancies()
} catch (err) {
this.messageService.add(`Error in addTenancyToTenant: ${ JSON.stringify(err, undefined, 4)}`)
}
}
ngOnInit(): void { ngOnInit(): void {
this.getTenant() this.getTenant()
this.getFees() this.getFees()