Skip to content

Commit

Permalink
Added check for yearly (column) totals
Browse files Browse the repository at this point in the history
  • Loading branch information
geertplaisier committed May 30, 2024
1 parent ddef175 commit ee97e55
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PlantypeEnum } from '../models';

export class PlantypeHelper {
export class ColorHelper {

private static PLAN_TYPE_COLORS = {
[PlantypeEnum.PAND_TRANSFORMATIE]: '#aa00ff',
Expand All @@ -17,15 +17,15 @@ export class PlantypeHelper {
wonenEnZorg: '#0daee5',
flexwoningen: '#ff8753',
betaalbaarheid: '#ffbf3e',
sloop: '#f04bfe',
sloop: '#00b4c5',
};

public static getPlantypeColor(plantype: PlantypeEnum | null): string {
return PlantypeHelper.PLAN_TYPE_COLORS[plantype || PlantypeEnum.UITBREIDING_UITLEG];
return ColorHelper.PLAN_TYPE_COLORS[plantype || PlantypeEnum.UITBREIDING_UITLEG];
}

public static getGroupColor(group: keyof typeof PlantypeHelper.GROUP_COLORS): string {
return PlantypeHelper.GROUP_COLORS[group] || PlantypeHelper.GROUP_COLORS.nieuwbouw;
public static getGroupColor(group: keyof typeof ColorHelper.GROUP_COLORS): string {
return ColorHelper.GROUP_COLORS[group] || ColorHelper.GROUP_COLORS.nieuwbouw;
}

}
67 changes: 67 additions & 0 deletions projects/planmonitor-wonen/src/lib/helpers/column.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { YearColumn } from '../models/year-table-column.model';

export class ColumnHelper {

public static allYears: YearColumn[] = [
'year_2024',
'year_2025',
'year_2026',
'year_2027',
'year_2028',
'year_2029',
'year_2030',
'year_2031',
'year_2032',
'year_2033',
'year_2034',
'year_2035',
'year_2036',
'year_2037',
'year_2038',
'year_2039',
'year_2040',
'year_2041',
'year_2042',
'year_2043',
'year_2034_2038',
'year_2039_2043',
];

public static categorieColumns: string[] = [
'label',
'groeplabel',
'totalen',
'total_check',
'gerealiseerd',
'restcapaciteit',
'year_2024',
'year_2025',
'year_2026',
'year_2027',
'year_2028',
'year_2029',
'year_2030',
'year_2031',
'year_2032',
'year_2033',
'year_2034_2038',
'year_2039_2043',
'years_check',
];

public static expandedCategorieColumns = [
...ColumnHelper.categorieColumns.slice(0, -3),
'year_2034',
'year_2035',
'year_2036',
'year_2037',
'year_2038',
'year_2039',
'year_2040',
'year_2041',
'year_2042',
'year_2043',
'years_check',
];

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { PlanregistratieModel } from '../models';
import { CategorieTableModel } from '../models/categorie-table.model';

export class PlanValidationHelper {

public static validatePlan(planRegistratie: PlanregistratieModel) {
public static validatePlan(planRegistratie: PlanregistratieModel, categorieTable: CategorieTableModel) {
if (
PlanValidationHelper.hasEmptyValue(planRegistratie.planNaam)
|| PlanValidationHelper.hasEmptyValue(planRegistratie.provincie)
Expand All @@ -21,7 +22,8 @@ export class PlanValidationHelper {
) {
return false;
}
return true;
return categorieTable.rows.every(row => row.valid)
&& categorieTable.yearColumns.every(column => column.valid);
}

private static hasInvalidValue(value: number | string | boolean | null | undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,31 @@ import { BetaalbaarheidEnum, DetailplanningModel, PlancategorieModel, WonenEnZor
import { NieuwbouwEnum } from '../models/nieuwbouw.enum';
import { FlexwoningenEnum } from '../models/flexwoningen.enum';
import { SloopEnum } from '../models/sloop.enum';
import { CategorieTableRowModel } from '../models/categorie-table-row.model';
import { CategorieGroepField, CategorieTableRowModel } from '../models/categorie-table-row.model';
import { YearColumn, YearColumnModel } from '../models/year-table-column.model';
import { CategorieTableModel } from '../models/categorie-table.model';
import { ColumnHelper } from './column.helper';


export interface CategorieRowModel {
id: string;
label: string;
groepnaam: string;
field: keyof PlancategorieModel;
field: CategorieGroepField;
fieldValue: string;
extraCls?: string;
}

export class PlancategorieHelper {
interface YearTotal {
nieuwbouw: number;
woningType: number;
wonenEnZorg: number;
flexwoningen: number;
betaalbaarheid: number;
sloop: number;
}

public static categorieColumns: string[] = [
'label',
'groeplabel',
'totalen',
'total_check',
'gerealiseerd',
'restcapaciteit',
'year_2024',
'year_2025',
'year_2026',
'year_2027',
'year_2028',
'year_2029',
'year_2030',
'year_2031',
'year_2032',
'year_2033',
'year_2034_2038',
'year_2039_2043',
'years_check',
];

public static expandedCategorieColumns = [
...PlancategorieHelper.categorieColumns.slice(0, -3),
'year_2034',
'year_2035',
'year_2036',
'year_2037',
'year_2038',
'year_2039',
'year_2040',
'year_2041',
'year_2042',
'year_2043',
'years_check',
];
export class PlancategorieTableHelper {

public static categorieen: CategorieRowModel[] = [
{ id: 'nieuwbouw-nieuwbouw', label: 'Nieuwbouw', groepnaam: 'nieuwbouw', field: "nieuwbouw", fieldValue: NieuwbouwEnum.NIEUWBOUW, extraCls: 'line-below' },
Expand Down Expand Up @@ -78,17 +54,15 @@ export class PlancategorieHelper {
{ id: 'sloop-sloop', label: 'Sloop', groepnaam: 'sloop', field: 'sloop', fieldValue: SloopEnum.SLOOP },
];



public static getPlancategorieTable(
planCategorieen: PlancategorieModel[],
detailPlanningen: DetailplanningModel[],
): CategorieTableRowModel[] {
const nieuwbouwCategorie = PlancategorieHelper.getNieuwbouwCategorie(planCategorieen);
): CategorieTableModel {
const nieuwbouwCategorie = PlancategorieTableHelper.getNieuwbouwCategorie(planCategorieen);
const nieuwbouwTotal = nieuwbouwCategorie?.totaalGepland || 0;
const groupTotals = new Map<string, number>();
const rows = PlancategorieHelper.categorieen.map(categorieRow => {
const planCategorie = PlancategorieHelper.getPlanCategorie(categorieRow, planCategorieen);
const rows = PlancategorieTableHelper.categorieen.map(categorieRow => {
const planCategorie = PlancategorieTableHelper.getPlanCategorie(categorieRow, planCategorieen);
const totalen = planCategorie?.totaalGepland || 0;
const gerealiseerd = planCategorie?.totaalGerealiseerd || 0;
const restcapaciteit = totalen - gerealiseerd;
Expand All @@ -113,26 +87,26 @@ export class PlancategorieHelper {
total_check: 0,
gerealiseerd,
restcapaciteit,
year_2024: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2024, detailPlanningen) ?? '',
year_2025: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2025, detailPlanningen) ?? '',
year_2026: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2026, detailPlanningen) ?? '',
year_2027: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2027, detailPlanningen) ?? '',
year_2028: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2028, detailPlanningen) ?? '',
year_2029: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2029, detailPlanningen) ?? '',
year_2030: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2030, detailPlanningen) ?? '',
year_2031: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2031, detailPlanningen) ?? '',
year_2032: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2032, detailPlanningen) ?? '',
year_2033: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2033, detailPlanningen) ?? '',
year_2034: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2034, detailPlanningen) ?? '',
year_2035: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2035, detailPlanningen) ?? '',
year_2036: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2036, detailPlanningen) ?? '',
year_2037: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2037, detailPlanningen) ?? '',
year_2038: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2038, detailPlanningen) ?? '',
year_2039: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2039, detailPlanningen) ?? '',
year_2040: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2040, detailPlanningen) ?? '',
year_2041: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2041, detailPlanningen) ?? '',
year_2042: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2042, detailPlanningen) ?? '',
year_2043: PlancategorieHelper.getDetailplanningGeplandForYear(planCategorie, 2043, detailPlanningen) ?? '',
year_2024: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2024, detailPlanningen) ?? '',
year_2025: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2025, detailPlanningen) ?? '',
year_2026: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2026, detailPlanningen) ?? '',
year_2027: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2027, detailPlanningen) ?? '',
year_2028: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2028, detailPlanningen) ?? '',
year_2029: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2029, detailPlanningen) ?? '',
year_2030: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2030, detailPlanningen) ?? '',
year_2031: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2031, detailPlanningen) ?? '',
year_2032: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2032, detailPlanningen) ?? '',
year_2033: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2033, detailPlanningen) ?? '',
year_2034: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2034, detailPlanningen) ?? '',
year_2035: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2035, detailPlanningen) ?? '',
year_2036: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2036, detailPlanningen) ?? '',
year_2037: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2037, detailPlanningen) ?? '',
year_2038: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2038, detailPlanningen) ?? '',
year_2039: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2039, detailPlanningen) ?? '',
year_2040: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2040, detailPlanningen) ?? '',
year_2041: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2041, detailPlanningen) ?? '',
year_2042: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2042, detailPlanningen) ?? '',
year_2043: PlancategorieTableHelper.getDetailplanningGeplandForYear(planCategorie, 2043, detailPlanningen) ?? '',
year_2034_2038: 0,
year_2039_2043: 0,
years_check: 0,
Expand All @@ -142,38 +116,49 @@ export class PlancategorieHelper {
if (row.groep === 'sloop') {
return row;
}
const rowTotaal = PlancategorieHelper.getTotalForRow(row);
const rowTotaal = PlancategorieTableHelper.getTotalForRow(row);
row.years_check = restcapaciteit - rowTotaal;
row.year_2034_2038 = PlancategorieHelper.getTotalFor20342038(row);
row.year_2039_2043 = PlancategorieHelper.getTotalFor20392043(row);
row.year_2034_2038 = PlancategorieTableHelper.getTotalFor20342038(row);
row.year_2039_2043 = PlancategorieTableHelper.getTotalFor20392043(row);
groupTotals.set(categorieRow.field, (groupTotals.get(categorieRow.field) || 0) + totalen);
return row;
});
return rows.map(row => {
const categorieGroups: CategorieGroepField[] = [ 'woningType', 'wonenEnZorg', 'flexwoningen', 'betaalbaarheid' ];
const yearColumns: YearColumnModel[] = ColumnHelper.allYears.map<YearColumnModel>(year => {
const yearlyTotal = PlancategorieTableHelper.getYearTotal(year, rows);
if (!yearlyTotal) {
return { year, valid: false };
}
const nieuwbouwYearTotal = yearlyTotal.nieuwbouw || 0;
const valid = categorieGroups.every(group => nieuwbouwYearTotal === yearlyTotal[group]);
return { year, valid };
});
const validatedRows = rows.map(row => {
const totalCheck = nieuwbouwTotal - (groupTotals.get(row.groep) || 0);
return {
...row,
total_check: row.groep === 'sloop' ? 0 : totalCheck,
valid: row.groep === 'sloop' ? true : row.years_check === 0 && totalCheck === 0,
};
});
return { rows: validatedRows, yearColumns };
}

public static getNieuwbouwCategorie(planCategorien: PlancategorieModel[]) {
return PlancategorieHelper.getPlanCategorie(
private static getNieuwbouwCategorie(planCategorien: PlancategorieModel[]) {
return PlancategorieTableHelper.getPlanCategorie(
{ field: "nieuwbouw", fieldValue: NieuwbouwEnum.NIEUWBOUW },
planCategorien,
);
}

public static getPlanCategorie(categorieRow: Pick<CategorieRowModel, 'field' | 'fieldValue'>, planCategorien: PlancategorieModel[]): PlancategorieModel | null {
private static getPlanCategorie(categorieRow: Pick<CategorieRowModel, 'field' | 'fieldValue'>, planCategorien: PlancategorieModel[]): PlancategorieModel | null {
return planCategorien.find(categorie => {
const value = categorie[categorieRow.field];
return value === categorieRow.fieldValue;
}) || null;
}

public static getDetailplanningForYear(
private static getDetailplanningForYear(
planCategorie: PlancategorieModel | null,
year: number,
detailPlanningen : DetailplanningModel[],
Expand All @@ -184,12 +169,12 @@ export class PlancategorieHelper {
return detailPlanningen.find(d => d.plancategorieId === planCategorie.id && d.jaartal === year);
}

public static getDetailplanningGeplandForYear(
private static getDetailplanningGeplandForYear(
planCategorie: PlancategorieModel | null,
year: number,
detailPlanningen : DetailplanningModel[],
) {
const detail = PlancategorieHelper.getDetailplanningForYear(planCategorie, year, detailPlanningen);
const detail = PlancategorieTableHelper.getDetailplanningForYear(planCategorie, year, detailPlanningen);
return detail ? detail.aantalGepland : undefined;
}

Expand All @@ -204,8 +189,8 @@ export class PlancategorieHelper {
(typeof row.year_2031 === 'number' ? row.year_2031 : 0) +
(typeof row.year_2032 === 'number' ? row.year_2032 : 0) +
(typeof row.year_2033 === 'number' ? row.year_2033 : 0) +
PlancategorieHelper.getTotalFor20342038(row) +
PlancategorieHelper.getTotalFor20392043(row);
PlancategorieTableHelper.getTotalFor20342038(row) +
PlancategorieTableHelper.getTotalFor20392043(row);
}

private static getTotalFor20342038(row: CategorieTableRowModel) {
Expand All @@ -224,4 +209,25 @@ export class PlancategorieHelper {
(typeof row.year_2043 === 'number' ? row.year_2043 : 0);
}

private static getYearTotal(year: YearColumn, rows: CategorieTableRowModel[]): YearTotal {
return rows.reduce<YearTotal>((curTotal, row) => {
const rowTotal = row[year];
const group = row.groep;
if (typeof rowTotal === 'number') {
return {
...curTotal,
[group]: curTotal[group] + rowTotal,
};
}
return curTotal;
}, {
nieuwbouw: 0,
woningType: 0,
wonenEnZorg: 0,
flexwoningen: 0,
betaalbaarheid: 0,
sloop: 0,
});
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as ExcelJS from 'exceljs';
import { PlancategorieHelper } from './plancategorie.helper';
import { FileHelper } from '@tailormap-viewer/shared';
import { CategorieTableRowModel } from '../models/categorie-table-row.model';
import { PlantypeHelper } from './plantype.helper';
import { ColorHelper } from './color.helper';
import { ColumnHelper } from './column.helper';

const getColor = (groepNaam: keyof typeof PlantypeHelper.GROUP_COLORS) => {
const color = PlantypeHelper.getGroupColor(groepNaam);
const getColor = (groepNaam: keyof typeof ColorHelper.GROUP_COLORS) => {
const color = ColorHelper.getGroupColor(groepNaam);
return `FF${color.substring(1)}`;
};

Expand Down Expand Up @@ -124,7 +124,7 @@ export class PlanregistratieExportHelper {
// Setup page
sheet.pageSetup.paperSize = ExcelJS.PaperSize.A4;
// Setup columns
sheet.columns = PlancategorieHelper.categorieColumns.map(key => {
sheet.columns = ColumnHelper.categorieColumns.map(key => {
const config = COLUMN_CONFIG.get(key);
return { header: config?.label || '', key, width: config?.width || 5.71 };
});
Expand Down
Loading

0 comments on commit ee97e55

Please sign in to comment.