From 9ca4c73cb11d99d099bc619224a8d9de398a7402 Mon Sep 17 00:00:00 2001 From: yelinz Date: Fri, 12 Aug 2022 15:50:16 +0200 Subject: [PATCH] fix(export): improve regex for cost center name split --- frontend/app/subscriptions/list/controller.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/frontend/app/subscriptions/list/controller.js b/frontend/app/subscriptions/list/controller.js index fc3a1e0e..b885f8bd 100644 --- a/frontend/app/subscriptions/list/controller.js +++ b/frontend/app/subscriptions/list/controller.js @@ -87,18 +87,22 @@ export default class SubscriptionsListController extends Controller { const lines = this.projects .toArray() .map((project) => { - const costCenterFullName = project.get("costCenter.name").trim(); - // Cost center name always starts with 5 digits - const costCenterSplitName = costCenterFullName.split( - new RegExp("^(\\d{5})") - ); + // Example cost center name: 12345 EXPENSE + const costCenterFullName = project.get("costCenter.name"); + let costCenterSplitName = []; + if (costCenterFullName) { + costCenterSplitName = costCenterFullName + .trim() + .match(/^(\S*\d{5}\S*) (.+)$/); + } return [ project.get("customer.name"), project.get("name"), project.get("billingType.name"), - costCenterSplitName[1], - costCenterSplitName[2].trim(), + ...(costCenterFullName + ? [costCenterSplitName[1], costCenterSplitName[2].trim()] + : ["", ""]), formatDurationShort(project.get("purchasedTime")), formatDurationShort(project.get("spentTime")), formatDurationShort(project.get("totalTime")),