Skip to content

Commit

Permalink
Merge pull request #340 from adfinis/fix-cost-center-split
Browse files Browse the repository at this point in the history
fix(export): improve regex for cost center name split
  • Loading branch information
Yelinz authored Aug 17, 2022
2 parents b649116 + 9ca4c73 commit c3b57a8
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions frontend/app/subscriptions/list/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down

0 comments on commit c3b57a8

Please sign in to comment.