Skip to content

Commit c3b57a8

Browse files
authored
Merge pull request #340 from adfinis/fix-cost-center-split
fix(export): improve regex for cost center name split
2 parents b649116 + 9ca4c73 commit c3b57a8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

frontend/app/subscriptions/list/controller.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,22 @@ export default class SubscriptionsListController extends Controller {
8787
const lines = this.projects
8888
.toArray()
8989
.map((project) => {
90-
const costCenterFullName = project.get("costCenter.name").trim();
91-
// Cost center name always starts with 5 digits
92-
const costCenterSplitName = costCenterFullName.split(
93-
new RegExp("^(\\d{5})")
94-
);
90+
// Example cost center name: 12345 EXPENSE
91+
const costCenterFullName = project.get("costCenter.name");
92+
let costCenterSplitName = [];
93+
if (costCenterFullName) {
94+
costCenterSplitName = costCenterFullName
95+
.trim()
96+
.match(/^(\S*\d{5}\S*) (.+)$/);
97+
}
9598

9699
return [
97100
project.get("customer.name"),
98101
project.get("name"),
99102
project.get("billingType.name"),
100-
costCenterSplitName[1],
101-
costCenterSplitName[2].trim(),
103+
...(costCenterFullName
104+
? [costCenterSplitName[1], costCenterSplitName[2].trim()]
105+
: ["", ""]),
102106
formatDurationShort(project.get("purchasedTime")),
103107
formatDurationShort(project.get("spentTime")),
104108
formatDurationShort(project.get("totalTime")),

0 commit comments

Comments
 (0)