diff --git a/js/app.js b/js/app.js index ea26d65..4fcd219 100644 --- a/js/app.js +++ b/js/app.js @@ -487,12 +487,16 @@ const TimeTrack = { this.tickets.forEach((ticket) => { ticket.history.forEach((historyEntry) => { if (moment(historyEntry.trackingStarted).format("MMM Do YY") === day) { - historyEntry.ticket = ticket.number; + let newEntry = {}; + Object.assign(newEntry, historyEntry); + newEntry.ticket = ticket.number; - if (collection[ticket.number]) { - collection[ticket.number] += historyEntry.minutes; + let existingEntry = this.getCollectionItemWithValue(collection, 'ticket', ticket.number); + + if (existingEntry) { + existingEntry.minutes = Number(existingEntry.minutes) + Number(newEntry.minutes); } else { - collection[ticket.number] = historyEntry; + collection.push(newEntry); } } }); @@ -501,15 +505,35 @@ const TimeTrack = { this.archive.forEach((ticket) => { ticket.history.forEach((historyEntry) => { if (moment(historyEntry.trackingStarted).format("MMM Do YY") === day) { - historyEntry.ticket = ticket.number; - historyEntry.archive = true; - collection.push(historyEntry); + let newEntry = {}; + Object.assign(newEntry, historyEntry); + newEntry.ticket = ticket.number; + + let existingEntry = this.getCollectionItemWithValue(collection, 'ticket', ticket.number); + + if (existingEntry) { + existingEntry.minutes = Number(existingEntry.minutes) + Number(newEntry.minutes); + } else { + collection.push(newEntry); + } } }); }); + console.log(collection); return collection; }, + getCollectionItemWithValue(collection, property, value) { + let found = false; + + collection.forEach((item) => { + if (item[property] === value) { + found = item; + } + }) + + return found; + }, sendPortalChangeRequest() { let vue = this; let publicDBParam = this.publicDB ? '&publicDB=1' : '';