some changes about fee and tenancy mapping
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
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 { AccountService, CommercialPremiseService, FeeService, FlatService, ParkingService, PremiseService, TenancyFeeMappingService, TenancyService, TenantService } from '../data-object-service';
|
||||
import { Account, CommercialPremise, Fee, Flat, NULL_Account, NULL_CommercialPremise, NULL_Flat, NULL_Parking, NULL_Tenancy, NULL_Tenant, Parking, Premise, Tenancy, TenancyFeeMapping, Tenant } from '../data-objects';
|
||||
import { MessageService } from '../message.service';
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { ExtApiService } from '../ext-data-object-service';
|
||||
|
||||
|
||||
interface DN_Tenancy {
|
||||
@ -25,14 +26,23 @@ export class TenantDetailsComponent implements OnInit {
|
||||
|
||||
account: Account = NULL_Account
|
||||
|
||||
tenancies: DN_Tenancy[] = []
|
||||
tenancies: DN_Tenancy[]
|
||||
tenancyDataSource: MatTableDataSource<DN_Tenancy>
|
||||
tenancyDisplayColumns: string[] = [ "description", "flat", "parking", "commercial_premise", "startdate", "enddate" ]
|
||||
|
||||
collapseTenantDetails: boolean = false
|
||||
collapseTenancies: boolean = false
|
||||
|
||||
selectedTenancy: Tenancy = undefined
|
||||
mappedFees: Fee[]
|
||||
mappedFeesDataSource: MatTableDataSource<Fee>
|
||||
mappedFeesDisplayedColumns: string[] = [ "description", "amount", "fee_type", "startdate", "enddate" ]
|
||||
allFees: Fee[]
|
||||
selectedFee: number
|
||||
|
||||
|
||||
@ViewChild('submitButton') submitButton: MatButton
|
||||
@ViewChild('mapFeeButton') mapFeeButton: MatButton
|
||||
|
||||
constructor(
|
||||
private tenantService: TenantService,
|
||||
@ -41,6 +51,9 @@ export class TenantDetailsComponent implements OnInit {
|
||||
private flatService: FlatService,
|
||||
private parkingService: ParkingService,
|
||||
private commercialPremiseService: CommercialPremiseService,
|
||||
private tenancyFeeMappingService: TenancyFeeMappingService,
|
||||
private feeService: FeeService,
|
||||
private extApiService: ExtApiService,
|
||||
private premiseService: PremiseService,
|
||||
private messageService: MessageService,
|
||||
private route: ActivatedRoute,
|
||||
@ -53,31 +66,39 @@ 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)
|
||||
this.getTenancies()
|
||||
}
|
||||
} catch (err) {
|
||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
||||
}
|
||||
}
|
||||
|
||||
async saveTenant() {
|
||||
async getTenancies(): Promise<void> {
|
||||
try {
|
||||
this.tenancies = []
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
async saveTenant(): Promise<void> {
|
||||
try {
|
||||
this.submitButton.disabled = true
|
||||
this.messageService.add("saveTenant")
|
||||
@ -103,8 +124,54 @@ export class TenantDetailsComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
async setSelectedTenancy(selectedTenancy: Tenancy): Promise<void> {
|
||||
this.selectedTenancy = selectedTenancy
|
||||
this.getMappedFees()
|
||||
}
|
||||
|
||||
async getMappedFees(): Promise<void> {
|
||||
this.mappedFees = await this.extApiService.getFeeByTenancies(this.selectedTenancy.id)
|
||||
this.messageService.add(`setSelectedTenancy: mappedFees: ${JSON.stringify(this.mappedFees, undefined, 4)}`)
|
||||
this.mappedFeesDataSource = new MatTableDataSource<Fee>(this.mappedFees)
|
||||
this.messageService.add("mappedFeesDataSource set")
|
||||
}
|
||||
|
||||
clearSelectedTenancy(): void {
|
||||
this.selectedTenancy = undefined
|
||||
}
|
||||
|
||||
|
||||
async getFees(): Promise<void> {
|
||||
try {
|
||||
this.messageService.add("Trying to load fees")
|
||||
this.allFees = await this.feeService.getFees()
|
||||
this.messageService.add("fees loaded")
|
||||
} catch (err) {
|
||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
||||
}
|
||||
}
|
||||
|
||||
async addFee() {
|
||||
try {
|
||||
this.mapFeeButton.disabled = true
|
||||
this.messageService.add(`fee: ${ JSON.stringify(this.selectedFee, undefined, 4) }`)
|
||||
let newMapping: TenancyFeeMapping = {
|
||||
'tenancy': this.selectedTenancy.id,
|
||||
'fee': this.selectedFee,
|
||||
'id': 0
|
||||
}
|
||||
newMapping = await this.tenancyFeeMappingService.postTenancyFeeMapping(newMapping)
|
||||
this.messageService.add(`New fee tenancy mapping created: ${newMapping.id}`)
|
||||
this.selectedFee = undefined
|
||||
this.getMappedFees()
|
||||
} finally {
|
||||
this.mapFeeButton.disabled = false
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getTenant()
|
||||
this.getFees()
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user