diff --git a/src/models/hasTimes.js b/src/models/hasTimes.js index 095dd30..8d0b300 100755 --- a/src/models/hasTimes.js +++ b/src/models/hasTimes.js @@ -15,6 +15,7 @@ class hasTimes extends Base { constructor(config) { super(config); this.times = []; + this.timesWarnings = []; } /** @@ -58,6 +59,7 @@ class hasTimes extends Base { */ getTimes() { let times = [], + timesWarnings = [], timeSpent = 0, totalTimeSpent = 0, timeUsers = {}, @@ -127,18 +129,22 @@ class hasTimes extends Base { !(created.isSameOrAfter(moment(this.config.get('from'))) && created.isSameOrBefore(moment(this.config.get('to')))) ) return resolve(); + // warn about difference, but do not correct as gitlab API + // stats forget the times after an issue is moved to another project. let difference = this.data.time_stats.total_time_spent - totalTimeSpent, note = Object.assign({noteable_type: this._typeSingular}, this.data); - - times.unshift(new Time(Time.toHumanReadable(difference, this.config.get('hoursPerDay')), null, note, this, this.config)); - + note.timeWarning = {}; + note.timeWarning['stats'] = this.data.time_stats.total_time_spent; + note.timeWarning['notes'] = totalTimeSpent; + timesWarnings.push(new Time(Time.toHumanReadable(difference, this.config.get('hoursPerDay')), null, note, this, this.config)); resolve(); })); promise.then(() => { _.each(timeUsers, (time, name) => this[`time_${name}`] = Time.toHumanReadable(time, this.config.get('hoursPerDay'), timeFormat)); this.timeSpent = timeSpent; - this.times = times + this.times = times; + this.timesWarnings = timesWarnings; }); return promise; diff --git a/src/output/base.js b/src/output/base.js index b1bdd2f..1884c40 100755 --- a/src/output/base.js +++ b/src/output/base.js @@ -38,6 +38,14 @@ class base { this.write(this.formats.headline(string)); } + /** + * print a headline for warnings + * @param string + */ + warningHeadline(string) { + if (this.config.get('noWarnings')) return; + this.headline(string); + } /** * print a warning * @param string @@ -104,6 +112,7 @@ class base { let users = {}; let projects = {}; let times = []; + let timesWarnings = []; let spentFreeLabels = this.config.get('freeLabels'); if(undefined === spentFreeLabels) { @@ -132,6 +141,7 @@ class base { } times.push(time); }); + issue.timesWarnings.forEach(warning => timesWarnings.push(warning)); totalEstimate += parseInt(issue.stats.time_estimate); totalSpent += parseInt(issue.stats.total_time_spent); @@ -164,6 +174,7 @@ class base { this.spent = spent; this.spentFree = spentFree; this.totalSpent = totalSpent; + this.timesWarnings = timesWarnings; } /** diff --git a/src/output/invoice.js b/src/output/invoice.js index dec18bf..13d0561 100644 --- a/src/output/invoice.js +++ b/src/output/invoice.js @@ -89,7 +89,21 @@ ${closing}



Stundenrapport

`; this.headline('Total'); - this.write(stats.substr(1)); + //this.write(stats.substr(1)); + this.write(this.config.toHumanReadable(this.spent, 'stats')); + this.write(this.config.toHumanReadable(this.spentFree, 'statsFree')); + + // warnings + let warnings = ''; + + this.timesWarnings.forEach( warning => { + let stats = this.config.toHumanReadable(warning.data.timeWarning.stats, 'stats'); + let notes = this.config.toHumanReadable(warning.data.timeWarning.notes, 'stats'); + warnings += `\n* ${warning.data.iid} ${warning.data.title}: Difference between stats and notes of ${warning.time}.`; + warnings += `
Stats: ${stats}, Notes: ${notes}` + }); + this.warningHeadline('Warnings'); + this.warning(warnings+'\n'); } makeIssues() {