forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinvoice.js
More file actions
143 lines (110 loc) · 5.19 KB
/
invoice.js
File metadata and controls
143 lines (110 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const _ = require('underscore');
const Table = require('markdown-table');
const Base = require('./base');
const format = {
headline: h => `\n### ${h}\n`,
warning: w => `${w}`
};
/**
* invoice, code heavily based on markdown.js
*/
class invoice extends Base {
constructor(config, report) {
super(config, report);
this.format = format;
this.invoiceCurrency = this.config.get('invoiceCurrency');
this.invoiceCurrencyPerHour = this.config.get('invoiceCurrencyPerHour');
this.invoiceVAT = this.config.get('invoiceVAT');
this.invoiceCurrencyMaxUnit = this.config.get('invoiceCurrencyMaxUnit');
this.totalhForInvoice = (this.spent-this.spentFree) / 3600.0;
this.totalForInvoiceExkl = this.totalhForInvoice * this.invoiceCurrencyPerHour;
this.totalForInvoiceMwst = this.totalForInvoiceExkl * this.invoiceVAT;
this.totalForInvoice = this.totalForInvoiceExkl + this.totalForInvoiceMwst;
// round
this.totalForInvoice = Math.round(this.totalForInvoice/this.invoiceCurrencyMaxUnit)*this.invoiceCurrencyMaxUnit;
}
concat(data, separator) {
if(null == data) {
return "";
}
if(!Array.isArray(data)) {
return data.replace(/_/g, " ");
}
let data2 = [];
data.forEach(el => data2.push(this.concat(el, separator)));
return data2.join(separator);
}
makeStats() {
let stats = '';
_.each(this.stats, (time, name) => stats += `\n* **${name}**: ${time}`);
stats += `\n`;
if (this.projects.length > 1) {
_.each(this.projects, (time, name) => stats += `\n* **${name.red}**: ${time}`);
stats += `\n`;
}
// REMOVE
// _.each(this.users, (time, name) => stats += `\n* **${name}**: ${time}`);
let to = this.concat(this.config.get('invoiceAddress'), '</br>');
let from = this.concat(this.config.get('invoiceSettings').from, '</br>');
let opening = this.concat(this.config.get('invoiceSettings').opening, '</br>');
let closing = this.concat(this.config.get('invoiceSettings').closing, '</br>');
let positionText = this.concat(this.config.get('invoiceSettings').positionText, '</br>');
this.out +=
`<div class="senderBox">${from}</div>
<div class="addressBox">
<div class="addressFrom">${this.config.get('invoiceSettings').fromShort}</div>
<div class="addressTo">${to}</div>
</div>
<div class="dateBox">${this.config.get('invoiceDate')}</div>
# ${this.config.get('invoiceTitle')}
${opening}
<div class="positionBox">
<div class="positionDesc">${positionText} (${this.totalhForInvoice.toFixed(2)} Stunden zu ${this.invoiceCurrencyPerHour} ${this.invoiceCurrency})</div>
<div class="positionValue">${this.invoiceCurrency} ${this.totalForInvoiceExkl.toFixed(2)}</div>
<div class="positionDesc">MWST (${this.invoiceVAT*100}%)</div>
<div class="positionValue">${this.invoiceCurrency} ${this.totalForInvoiceMwst.toFixed(2)}</div>
<div class="positionDescTot">Rechnungsbetrag inkl. MWST</div>
<div class="positionValueTot">${this.invoiceCurrency} ${this.totalForInvoice.toFixed(2)}</div>
</div>
${this.config.get('invoiceSettings').bankAccount}
${closing}
<h1 style="page-break-before: always;"><br/><br/>Stundenrapport</h1>`;
this.headline('Total');
//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 += `<br/>Stats: ${stats}, Notes: ${notes}`
});
this.warningHeadline('Warnings');
this.warning(warnings+'\n');
}
makeIssues() {
this.headline('Issues');
if (this.report.issues.length === 0)
return this.warning('No issues found');
let issues = [this.config.get('issueColumns').map(c => c.replace('_', ' '))];
this.report.issues.forEach(issue => issues.push(this.prepare(issue, this.config.get('issueColumns'))));
this.write(Table(issues));
}
makeMergeRequests() {
this.headline('Merge Requests');
if (this.report.mergeRequests.length === 0)
return this.warning('No merge requests found');
let mergeRequests = [this.config.get('mergeRequestColumns').map(c => c.replace('_', ' '))];
this.report.mergeRequests.forEach(mergeRequest => mergeRequests.push(this.prepare(mergeRequest, this.config.get('mergeRequestColumns'))));
this.write(Table(mergeRequests));
}
makeRecords() {
this.headline('Details');
let times = [this.config.get('recordColumns').map(c => c.replace('_', ' '))];
this.times.forEach(time => times.push(this.prepare(time, this.config.get('recordColumns'))));
this.write(Table(times));
}
}
module.exports = invoice;